git.delta.rocks / unique-network / refs/commits / c19d2408cea7

difftreelog

Can set multiple properties

Max Andreev2022-12-07parent: #49ce507.patch.diff
in: master

2 files changed

modifiedtests/src/eth/tokenProperties.test.tsdiffbeforeafterboth
49 }49 }
50 });50 });
5151
52 [
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);
6379
64 await collection.addAdmin(alice, {Ethereum: caller});80 await collection.addAdmin(alice, {Ethereum: caller});
65
66 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-deprecated
76 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);
87
88 await collection.addAdmin(alice, {Ethereum: caller});
89
90 const address = helper.ethAddress.fromCollectionId(collection.collectionId);
91 const contract = helper.ethNativeContract.collection(address, 'nft', caller, true);
92
93 await contract.methods.setProperty(token.tokenId, 'testKey', Buffer.from('testValue')).send({from: caller});
94
95 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);
modifiedtests/src/eth/util/playgrounds/unique.dev.tsdiffbeforeafterboth
--- a/tests/src/eth/util/playgrounds/unique.dev.ts
+++ b/tests/src/eth/util/playgrounds/unique.dev.ts
@@ -129,8 +129,8 @@
     return new web3.eth.Contract(abi as any, address, {gas: this.helper.eth.DEFAULT_GAS, ...(caller ? {from: caller} : {})});
   }
 
-  collectionById(collectionId: number, mode: 'nft' | 'rft' | 'ft', caller?: string): Contract {
-    return this.collection(this.helper.ethAddress.fromCollectionId(collectionId), mode, caller);
+  collectionById(collectionId: number, mode: 'nft' | 'rft' | 'ft', caller?: string, mergeDeprecated = false): Contract {
+    return this.collection(this.helper.ethAddress.fromCollectionId(collectionId), mode, caller, mergeDeprecated);
   }
 
   rftToken(address: string, caller?: string): Contract {