difftreelog
Merge pull request #1014 from UniqueNetwork/fix/max-multiple-items
in: master
2 files changed
primitives/data-structs/src/lib.rsdiffbeforeafterboth135135136/// How much items can be created per single136/// How much items can be created per single137/// create_many call.137/// create_many call.138pub const MAX_ITEMS_PER_BATCH: u32 = 200;138pub const MAX_ITEMS_PER_BATCH: u32 = 120;139139140/// Used for limit bounded types of token custom data.140/// Used for limit bounded types of token custom data.141pub type CustomDataLimit = ConstU32<CUSTOM_DATA_LIMIT>;141pub type CustomDataLimit = ConstU32<CUSTOM_DATA_LIMIT>;tests/src/performance.seq.test.tsdiffbeforeafterboth222223describe('Performace tests', () => {23describe('Performace tests', () => {24 let alice: IKeyringPair;24 let alice: IKeyringPair;25 const MAX_TOKENS_TO_MINT = 200;25 const MAX_TOKENS_TO_MINT = 120;262627 before(async () => {27 before(async () => {28 await usingPlaygrounds(async (helper, privateKey) => {28 await usingPlaygrounds(async (helper, privateKey) => {43 });43 });44444546 const results = [];47 const step = 1_000;45 const step = 1_000;48 const sizeOfKey = sizeOfEncodedStr(propertyKey);46 const sizeOfKey = sizeOfEncodedStr(propertyKey);49 let currentSize = step;47 let currentSize = step;57 minterFunc = tryMintExplicit;55 minterFunc = tryMintExplicit;58 }56 }5759 results.push({propertySize: 0, tokens: startCount});58 expect(startCount).to.be.equal(MAX_TOKENS_TO_MINT);605961 while(currentSize <= 32_000) {60 while(currentSize <= 32_000) {62 const property = {key: propertyKey, value: 'A'.repeat(currentSize - sizeOfKey - sizeOfInt(currentSize))};61 const property = {key: propertyKey, value: 'A'.repeat(currentSize - sizeOfKey - sizeOfInt(currentSize))};63 const maxTokens = Math.ceil(results.map(x => x.tokens).reduce((a, b) => a + b) / results.length);64 const tokens = await minterFunc(helper, alice, maxTokens, collection.collectionId, {Substrate: alice.address}, property);62 const tokens = await minterFunc(helper, alice, MAX_TOKENS_TO_MINT, collection.collectionId, {Substrate: alice.address}, property);65 results.push({propertySize: sizeOfProperty(property), tokens});63 expect(tokens).to.be.equal(MAX_TOKENS_TO_MINT);6466 currentSize += step;65 currentSize += step;67 await helper.wait.newBlocks(2);66 await helper.wait.newBlocks(2);68 }67 }6970 expect(results).to.be.deep.equal([71 {propertySize: 0, tokens: 200},72 {propertySize: 1000, tokens: 149},73 {propertySize: 2000, tokens: 149},74 {propertySize: 3000, tokens: 149},75 {propertySize: 4000, tokens: 149},76 {propertySize: 5000, tokens: 149},77 {propertySize: 6000, tokens: 149},78 {propertySize: 7000, tokens: 149},79 {propertySize: 8000, tokens: 149},80 {propertySize: 9000, tokens: 149},81 {propertySize: 10000, tokens: 149},82 {propertySize: 11000, tokens: 149},83 {propertySize: 12000, tokens: 149},84 {propertySize: 13000, tokens: 149},85 {propertySize: 14000, tokens: 149},86 {propertySize: 15000, tokens: 149},87 {propertySize: 16000, tokens: 149},88 {propertySize: 17000, tokens: 149},89 {propertySize: 18000, tokens: 149},90 {propertySize: 19000, tokens: 149},91 {propertySize: 20000, tokens: 149},92 {propertySize: 21000, tokens: 149},93 {propertySize: 22000, tokens: 149},94 {propertySize: 23000, tokens: 149},95 {propertySize: 24000, tokens: 149},96 {propertySize: 25000, tokens: 149},97 {propertySize: 26000, tokens: 149},98 {propertySize: 27000, tokens: 145},99 {propertySize: 28000, tokens: 140},100 {propertySize: 29000, tokens: 135},101 {propertySize: 30000, tokens: 130},102 {propertySize: 31000, tokens: 126},103 {propertySize: 32000, tokens: 122},104 ]);105 });68 });106});69});10770142 return tokensCount;105 return tokensCount;143};106};144145function sizeOfProperty(prop: IProperty) {146 return sizeOfEncodedStr(prop.key) + sizeOfEncodedStr(prop.value!);147}148107149function sizeOfInt(i: number) {108function sizeOfInt(i: number) {150 if(i < 0 || i > 0xffffffff) throw new Error('out of range');109 if(i < 0 || i > 0xffffffff) throw new Error('out of range');