difftreelog
Can set multiple properties
in: master
2 files changed
tests/src/eth/tokenProperties.test.tsdiffbeforeafterboth49 }49 }50 });50 });515152 [53 {54 method: 'setProperties',55 methodParams: [[{key: 'testKey1', value: Buffer.from('testValue1')}, {key: 'testKey2', value: Buffer.from('testValue2')}]],56 expectedProps: [{key: 'testKey1', value: 'testValue1'}, {key: 'testKey2', value: 'testValue2'}],57 },58 {59 method: 'setProperty' /*Soft-deprecated*/, 60 methodParams: ['testKey1', Buffer.from('testValue1')],61 expectedProps: [{key: 'testKey1', value: 'testValue1'}],62 },63 ].map(testCase => 52 itEth('Can be set', async({helper}) => {64 itEth(`[${testCase.method}] Can be set`, async({helper}) => {53 const caller = await helper.eth.createAccountWithBalance(donor);65 const caller = await helper.eth.createAccountWithBalance(donor);54 const collection = await helper.nft.mintCollection(alice, {66 const collection = await helper.nft.mintCollection(alice, {55 tokenPropertyPermissions: [{67 tokenPropertyPermissions: [{56 key: 'testKey',68 key: 'testKey1',57 permission: {69 permission: {58 collectionAdmin: true,70 collectionAdmin: true,59 },71 },60 }],72 }, {73 key: 'testKey2',74 permission: {75 collectionAdmin: true,76 },77 }],61 });78 });62 const token = await collection.mintToken(alice);637964 await collection.addAdmin(alice, {Ethereum: caller});80 await collection.addAdmin(alice, {Ethereum: caller});6566 const address = helper.ethAddress.fromCollectionId(collection.collectionId);81 const token = await collection.mintToken(alice);82 67 const contract = helper.ethNativeContract.collection(address, 'nft', caller);83 const collectionEvm = helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller, testCase.method === 'setProperty');6884 69 await contract.methods.setProperties(token.tokenId, [{key: 'testKey', value: Buffer.from('testValue')}]).send({from: caller});85 await collectionEvm.methods[testCase.method](token.tokenId, ...testCase.methodParams).send({from: caller});7086 71 const [{value}] = await token.getProperties(['testKey']);87 const properties = await token.getProperties();72 expect(value).to.equal('testValue');88 expect(properties).to.deep.equal(testCase.expectedProps);73 });89 }));7490 75 // Soft-deprecated76 itEth('Property can be set', async({helper}) => {77 const caller = await helper.eth.createAccountWithBalance(donor);78 const collection = await helper.nft.mintCollection(alice, {79 tokenPropertyPermissions: [{80 key: 'testKey',81 permission: {82 collectionAdmin: true,83 },84 }],85 });86 const token = await collection.mintToken(alice);8788 await collection.addAdmin(alice, {Ethereum: caller});8990 const address = helper.ethAddress.fromCollectionId(collection.collectionId);91 const contract = helper.ethNativeContract.collection(address, 'nft', caller, true);9293 await contract.methods.setProperty(token.tokenId, 'testKey', Buffer.from('testValue')).send({from: caller});9495 const [{value}] = await token.getProperties(['testKey']);96 expect(value).to.equal('testValue');97 });98 99 async function checkProps(helper: EthUniqueHelper, mode: TCollectionMode) {91 async function checkProps(helper: EthUniqueHelper, mode: TCollectionMode) {100 const caller = await helper.eth.createAccountWithBalance(donor);92 const caller = await helper.eth.createAccountWithBalance(donor);tests/src/eth/util/playgrounds/unique.dev.tsdiffbeforeafterboth129 return new web3.eth.Contract(abi as any, address, {gas: this.helper.eth.DEFAULT_GAS, ...(caller ? {from: caller} : {})});129 return new web3.eth.Contract(abi as any, address, {gas: this.helper.eth.DEFAULT_GAS, ...(caller ? {from: caller} : {})});130 }130 }131131132 collectionById(collectionId: number, mode: 'nft' | 'rft' | 'ft', caller?: string): Contract {132 collectionById(collectionId: number, mode: 'nft' | 'rft' | 'ft', caller?: string, mergeDeprecated = false): Contract {133 return this.collection(this.helper.ethAddress.fromCollectionId(collectionId), mode, caller);133 return this.collection(this.helper.ethAddress.fromCollectionId(collectionId), mode, caller, mergeDeprecated);134 }134 }135135136 rftToken(address: string, caller?: string): Contract {136 rftToken(address: string, caller?: string): Contract {