difftreelog
Check collection properties for each collection mode
in: master
1 file changed
tests/src/eth/collectionProperties.test.tsdiffbeforeafterboth26 before(async function() {26 before(async function() {27 await usingEthPlaygrounds(async (_helper, privateKey) => {27 await usingEthPlaygrounds(async (_helper, privateKey) => {28 donor = await privateKey({filename: __filename});28 donor = await privateKey({filename: __filename});29 [alice] = await _helper.arrange.createAccounts([20n], donor);29 [alice] = await _helper.arrange.createAccounts([50n], donor);30 });30 });31 });31 });323233 // Soft-deprecated: setCollectionProperty33 // Soft-deprecated: setCollectionProperty34 [34 [35 {method: 'setCollectionProperties', methodParams: [[{key: 'testKey1', value: Buffer.from('testValue1')}, {key: 'testKey2', value: Buffer.from('testValue2')}]], expectedProps: [{key: 'testKey1', value: 'testValue1'}, {key: 'testKey2', value: 'testValue2'}]}, 35 {method: 'setCollectionProperties', mode: 'nft' as const, methodParams: [[{key: 'testKey1', value: Buffer.from('testValue1')}, {key: 'testKey2', value: Buffer.from('testValue2')}]], expectedProps: [{key: 'testKey1', value: 'testValue1'}, {key: 'testKey2', value: 'testValue2'}]}, 36 {method: 'setCollectionProperties', mode: 'rft' as const, methodParams: [[{key: 'testKey1', value: Buffer.from('testValue1')}, {key: 'testKey2', value: Buffer.from('testValue2')}]], expectedProps: [{key: 'testKey1', value: 'testValue1'}, {key: 'testKey2', value: 'testValue2'}]}, 37 {method: 'setCollectionProperties', mode: 'ft' as const, methodParams: [[{key: 'testKey1', value: Buffer.from('testValue1')}, {key: 'testKey2', value: Buffer.from('testValue2')}]], expectedProps: [{key: 'testKey1', value: 'testValue1'}, {key: 'testKey2', value: 'testValue2'}]}, 36 {method: 'setCollectionProperty', methodParams: ['testKey', Buffer.from('testValue')], expectedProps: [{key: 'testKey', value: 'testValue'}]},38 {method: 'setCollectionProperty', mode: 'nft' as const, methodParams: ['testKey', Buffer.from('testValue')], expectedProps: [{key: 'testKey', value: 'testValue'}]},37 ].map(testCase => 39 ].map(testCase => 38 itEth(`Collection properties can be set: ${testCase.method}`, async({helper}) => {40 itEth.ifWithPallets(`Collection properties can be set: ${testCase.method}() for ${testCase.mode}`, testCase.mode === 'rft' ? [Pallets.ReFungible] : [], async({helper}) => {39 const caller = await helper.eth.createAccountWithBalance(donor);41 const caller = await helper.eth.createAccountWithBalance(donor);40 const collection = await helper.nft.mintCollection(alice, {name: 'name', description: 'test', tokenPrefix: 'test', properties: []});42 const collection = await helper[testCase.mode].mintCollection(alice, {name: 'name', description: 'test', tokenPrefix: 'test', properties: []});41 await collection.addAdmin(alice, {Ethereum: caller});43 await collection.addAdmin(alice, {Ethereum: caller});4244 43 const address = helper.ethAddress.fromCollectionId(collection.collectionId);45 const address = helper.ethAddress.fromCollectionId(collection.collectionId);44 const contract = helper.ethNativeContract.collection(address, 'nft', caller, testCase.method === 'setCollectionProperty');46 const collectionEvm = helper.ethNativeContract.collection(address, 'nft', caller, testCase.method === 'setCollectionProperty');4748 // collectionProperties returns an empty array if no properties: 49 expect(await collectionEvm.methods.collectionProperties([]).call()).to.be.like([]);50 expect(await collectionEvm.methods.collectionProperties(['NonExistingKey']).call()).to.be.like([]);455146 await contract.methods[testCase.method](...testCase.methodParams).send({from: caller});52 await collectionEvm.methods[testCase.method](...testCase.methodParams).send({from: caller});475348 const raw = (await collection.getData())?.raw;54 const raw = (await collection.getData())?.raw;49 expect(raw.properties).to.deep.equal(testCase.expectedProps);55 expect(raw.properties).to.deep.equal(testCase.expectedProps);5657 // collectionProperties returns properties: 58 expect(await collectionEvm.methods.collectionProperties([]).call()).to.be.like(testCase.expectedProps.map(prop => helper.ethProperty.property(prop.key, prop.value)));50 }));59 }));516052 itEth('Cannot set invalid properties', async({helper}) => {61 itEth('Cannot set invalid properties', async({helper}) => {687769 // Soft-deprecated: deleteCollectionProperty78 // Soft-deprecated: deleteCollectionProperty70 [79 [71 {method: 'deleteCollectionProperties', methodParams: [['testKey1', 'testKey2']], expectedProps: [{key: 'testKey3', value: 'testValue3'}]},80 {method: 'deleteCollectionProperties', mode: 'nft' as const, methodParams: [['testKey1', 'testKey2']], expectedProps: [{key: 'testKey3', value: 'testValue3'}]},81 {method: 'deleteCollectionProperties', mode: 'rft' as const, methodParams: [['testKey1', 'testKey2']], expectedProps: [{key: 'testKey3', value: 'testValue3'}]},82 {method: 'deleteCollectionProperties', mode: 'ft' as const, methodParams: [['testKey1', 'testKey2']], expectedProps: [{key: 'testKey3', value: 'testValue3'}]},72 {method: 'deleteCollectionProperty', methodParams: ['testKey1'], expectedProps: [{key: 'testKey2', value: 'testValue2'}, {key: 'testKey3', value: 'testValue3'}]}, 83 {method: 'deleteCollectionProperty', mode: 'nft' as const, methodParams: ['testKey1'], expectedProps: [{key: 'testKey2', value: 'testValue2'}, {key: 'testKey3', value: 'testValue3'}]}, 73 ].map(testCase => 84 ].map(testCase => 74 itEth(`Collection properties can be deleted: ${testCase.method}()`, async({helper}) => {85 itEth(`Collection properties can be deleted: ${testCase.method}() for ${testCase.mode}`, async({helper}) => {75 const properties = [86 const properties = [76 {key: 'testKey1', value: 'testValue1'},87 {key: 'testKey1', value: 'testValue1'},77 {key: 'testKey2', value: 'testValue2'},88 {key: 'testKey2', value: 'testValue2'},78 {key: 'testKey3', value: 'testValue3'}];89 {key: 'testKey3', value: 'testValue3'}];79 const caller = await helper.eth.createAccountWithBalance(donor);90 const caller = await helper.eth.createAccountWithBalance(donor);80 const collection = await helper.nft.mintCollection(alice, {name: 'name', description: 'test', tokenPrefix: 'test', properties});91 const collection = await helper[testCase.mode].mintCollection(alice, {name: 'name', description: 'test', tokenPrefix: 'test', properties});81 92 82 await collection.addAdmin(alice, {Ethereum: caller});93 await collection.addAdmin(alice, {Ethereum: caller});83 94 275 }286 }276 287 277 {288 {278 const expectProperties = [289 const expectedProperties = [279 helper.ethProperty.property(keys[0], 'value0'),290 helper.ethProperty.property(keys[0], 'value0'),280 helper.ethProperty.property(keys[1], 'value1'),291 helper.ethProperty.property(keys[1], 'value1'),281 ];292 ];282 293 283 await contract.methods.deleteCollectionProperties([keys[2], keys[3]]).send();294 await contract.methods.deleteCollectionProperties([keys[2], keys[3]]).send();284 const readProperties = await contract.methods.collectionProperties([]).call();295 const readProperties = await contract.methods.collectionProperties([]).call();285 expect(readProperties).to.be.like(expectProperties);296 expect(readProperties).to.be.like(expectedProperties);286 }297 }287 }));298 }));288});299});