-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add benchmark DuckyGame minting * replace ERC721Enumerable with counter * rename duckies-mint to game-mint script * add meld benchmark --------- Co-authored-by: nksazonov <[email protected]>
- Loading branch information
Showing
6 changed files
with
243 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
import { assert } from 'chai'; | ||
|
||
import { | ||
GenerateAndMintGenomesFunctT, | ||
MintToFuncT, | ||
randomGenome, | ||
randomGenomes, | ||
setupGenerateAndMintGenomes, | ||
setupMintTo, | ||
} from '../../duckies/games/DuckyFamily/helpers'; | ||
import { | ||
Collections, | ||
DucklingGenes, | ||
FLOCK_SIZE, | ||
GeneDistrTypes, | ||
Rarities, | ||
ZombeakGenes, | ||
collectionsGeneValuesNum, | ||
} from '../../duckies/games/DuckyFamily/config'; | ||
import { setup } from '../../duckies/games/DuckyFamily/setup'; | ||
|
||
import type { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers'; | ||
import type { DucklingsV1, DuckyFamilyV1, TESTDuckyFamilyV1 } from '../../../typechain-types'; | ||
|
||
describe('Benchmark DuckyFamilyV1 melding', () => { | ||
let Someone: SignerWithAddress; | ||
let GenomeSetter: SignerWithAddress; | ||
|
||
let Ducklings: DucklingsV1; | ||
let Game: TESTDuckyFamilyV1; | ||
|
||
let GameAsSomeone: DuckyFamilyV1; | ||
|
||
let mintTo: MintToFuncT; | ||
let generateAndMintGenomes: GenerateAndMintGenomesFunctT; | ||
|
||
const isCollectionMutating = async (rarity: Rarities): Promise<boolean> => { | ||
const tx = await Game.isCollectionMutating(rarity); | ||
const receipt = await tx.wait(); | ||
const event = receipt.events?.find((e) => e.event === 'BoolReturned'); | ||
return event?.args?.returnedBool as boolean; | ||
}; | ||
|
||
const meldGenomes = async (genomes: bigint[]): Promise<bigint> => { | ||
const tx = await Game.meldGenomes(genomes); | ||
const receipt = await tx.wait(); | ||
const event = receipt.events?.find((e) => e.event === 'GenomeReturned'); | ||
return event?.args?.genome.toBigInt() as bigint; | ||
}; | ||
|
||
const meldGenes = async ( | ||
genomes: bigint[], | ||
gene: number, | ||
maxGeneValue: number, | ||
geneDistrType: GeneDistrTypes, | ||
): Promise<number> => { | ||
const tx = await Game.meldGenes(genomes, gene, maxGeneValue, geneDistrType); | ||
const receipt = await tx.wait(); | ||
const event = receipt.events?.find((e) => e.event === 'GeneReturned'); | ||
// gene is already a number | ||
return event?.args?.gene as number; | ||
}; | ||
|
||
beforeEach(async () => { | ||
({ Someone, GenomeSetter, Ducklings, Game, GameAsSomeone } = await setup()); | ||
|
||
mintTo = setupMintTo(Ducklings.connect(GenomeSetter)); | ||
generateAndMintGenomes = setupGenerateAndMintGenomes(mintTo, Someone.address); | ||
}); | ||
|
||
it('meld Common Ducklings', async () => { | ||
const { tokenIds } = await generateAndMintGenomes(Collections.Duckling, { | ||
[DucklingGenes.Rarity]: Rarities.Common, | ||
[DucklingGenes.Color]: 0, | ||
}); | ||
|
||
await GameAsSomeone.meldFlock(tokenIds); | ||
}); | ||
|
||
it('meld Common Zombeaks', async () => { | ||
const { tokenIds } = await generateAndMintGenomes(Collections.Zombeak, { | ||
[ZombeakGenes.Rarity]: Rarities.Common, | ||
[ZombeakGenes.Color]: 0, | ||
}); | ||
|
||
try { | ||
await GameAsSomeone.meldFlock(tokenIds); | ||
assert(true); | ||
} catch { | ||
assert(false); | ||
} | ||
}); | ||
|
||
it('meldGenomes', async () => { | ||
await Game.setCollectionMutationChances([0, 0, 0, 0]); | ||
|
||
const genomes = randomGenomes(Collections.Duckling, { | ||
amount: FLOCK_SIZE, | ||
[DucklingGenes.Rarity]: Rarities.Common, | ||
[DucklingGenes.Color]: 0, | ||
}); | ||
|
||
await meldGenomes(genomes); | ||
}); | ||
|
||
it('isCollectionMutating', async () => { | ||
await isCollectionMutating(Rarities.Common); | ||
}); | ||
|
||
it('meldGenes', async () => { | ||
const geneValuesNum = collectionsGeneValuesNum[Collections.Duckling]; | ||
const genomes = []; | ||
for (let i = 0; i < FLOCK_SIZE; i++) { | ||
const genome = randomGenome(Collections.Duckling, { | ||
[DucklingGenes.Head]: i, | ||
}); | ||
genomes.push(genome); | ||
} | ||
|
||
await meldGenes( | ||
genomes, | ||
DucklingGenes.Head, | ||
geneValuesNum[DucklingGenes.Head], | ||
GeneDistrTypes.Uneven, | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { setup } from '../../duckies/games/DuckyFamily/setup'; | ||
import { Collections, GeneDistrTypes } from '../../duckies/games/DuckyFamily/config'; | ||
|
||
import type { DuckyFamilyV1, TESTDuckyFamilyV1 } from '../../../typechain-types'; | ||
|
||
describe('Benchmark DuckyFamilyV1 minting', () => { | ||
let Game: TESTDuckyFamilyV1; | ||
let GameAsSomeone: DuckyFamilyV1; | ||
|
||
const generateGenome = async (collectionId: Collections): Promise<bigint> => { | ||
const tx = await Game.generateGenome(collectionId); | ||
const receipt = await tx.wait(); | ||
const event = receipt.events?.find((e) => e.event === 'GenomeReturned'); | ||
return event?.args?.genome.toBigInt() as bigint; | ||
}; | ||
const generateRarity = async (): Promise<number> => { | ||
const tx = await Game.generateRarity(); | ||
const receipt = await tx.wait(); | ||
const event = receipt.events?.find((e) => e.event === 'Uint8Returned'); | ||
return event?.args?.uint8 as number; | ||
}; | ||
|
||
const generateAndSetGenes = async ( | ||
genome: bigint, | ||
collectionId: Collections, | ||
): Promise<bigint> => { | ||
const tx = await Game.generateAndSetGenes(genome, collectionId); | ||
const receipt = await tx.wait(); | ||
const event = receipt.events?.find((e) => e.event === 'GenomeReturned'); | ||
return event?.args?.genome.toBigInt() as bigint; | ||
}; | ||
|
||
const generateAndSetGene = async ( | ||
genome: bigint, | ||
geneIx: number, | ||
geneValuesNum: number, | ||
distrType: GeneDistrTypes, | ||
): Promise<bigint> => { | ||
const tx = await Game.generateAndSetGene(genome, geneIx, geneValuesNum, distrType); | ||
const receipt = await tx.wait(); | ||
const event = receipt.events?.find((e) => e.event === 'GenomeReturned'); | ||
return event?.args?.genome.toBigInt() as bigint; | ||
}; | ||
|
||
beforeEach(async () => { | ||
({ Game, GameAsSomeone } = await setup()); | ||
await Game.setMintPrice(1); | ||
}); | ||
|
||
it('mint', async () => { | ||
await GameAsSomeone.mintPack(1); | ||
await GameAsSomeone.mintPack(1); | ||
}); | ||
|
||
it('generateGenome', async () => { | ||
await generateGenome(Collections.Duckling); | ||
}); | ||
|
||
it('generateRarity', async () => { | ||
await generateRarity(); | ||
}); | ||
|
||
it('generateAndSetGenes', async () => { | ||
await generateAndSetGenes(0n, Collections.Duckling); | ||
}); | ||
|
||
it('generateAndSetGene even', async () => { | ||
await generateAndSetGene(0n, 0, 2, GeneDistrTypes.Even); | ||
}); | ||
|
||
it('generateAndSetGene uneven', async () => { | ||
await generateAndSetGene(0n, 0, 2, GeneDistrTypes.Uneven); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters