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

difftreelog

Merge pull request #753 from UniqueNetwork/tests/eth-helpers

ut-akuznetsov2022-12-08parents: #378b7f3 #6da0856.patch.diff
in: master
Tests/eth helpers

8 files changed

addedtests/src/eth/collectionLimits.test.tsdiffbeforeafterboth

no changes

modifiedtests/src/eth/collectionProperties.test.tsdiffbeforeafterboth
18import {Pallets} from '../util';18import {Pallets} from '../util';
19import {IProperty, ITokenPropertyPermission} from '../util/playgrounds/types';19import {IProperty, ITokenPropertyPermission} from '../util/playgrounds/types';
20import {IKeyringPair} from '@polkadot/types/types';20import {IKeyringPair} from '@polkadot/types/types';
21import {TCollectionMode} from '../util/playgrounds/types';
2221
23describe('EVM collection properties', () => {22describe('EVM collection properties', () => {
24 let donor: IKeyringPair;23 let donor: IKeyringPair;
31 });30 });
32 });31 });
32
33 // Soft-deprecated: setCollectionProperty
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'}]},
36 {method: 'setCollectionProperty', methodParams: ['testKey', Buffer.from('testValue')], expectedProps: [{key: 'testKey', value: 'testValue'}]},
37 ].map(testCase =>
38 itEth(`Collection properties can be set: ${testCase.method}`, async({helper}) => {
39 const caller = await helper.eth.createAccountWithBalance(donor);
40 const collection = await helper.nft.mintCollection(alice, {name: 'name', description: 'test', tokenPrefix: 'test', properties: []});
41 await collection.addAdmin(alice, {Ethereum: caller});
42
43 const address = helper.ethAddress.fromCollectionId(collection.collectionId);
44 const contract = helper.ethNativeContract.collection(address, 'nft', caller, testCase.method === 'setCollectionProperty');
45
46 await contract.methods[testCase.method](...testCase.methodParams).send({from: caller});
47
48 const raw = (await collection.getData())?.raw;
49 expect(raw.properties).to.deep.equal(testCase.expectedProps);
50 }));
3351
34 itEth('Can be set', async({helper}) => {52 itEth('Cannot set invalid properties', async({helper}) => {
35 const caller = await helper.eth.createAccountWithBalance(donor);53 const caller = await helper.eth.createAccountWithBalance(donor);
36 const collection = await helper.nft.mintCollection(alice, {name: 'name', description: 'test', tokenPrefix: 'test', properties: []});54 const collection = await helper.nft.mintCollection(alice, {name: 'name', description: 'test', tokenPrefix: 'test', properties: []});
37 await collection.addAdmin(alice, {Ethereum: caller});55 await collection.addAdmin(alice, {Ethereum: caller});
3856
39 const address = helper.ethAddress.fromCollectionId(collection.collectionId);57 const address = helper.ethAddress.fromCollectionId(collection.collectionId);
40 const contract = helper.ethNativeContract.collection(address, 'nft', caller);58 const contract = helper.ethNativeContract.collection(address, 'nft', caller);
4159
42 await contract.methods.setCollectionProperties([{key: 'testKey', value: Buffer.from('testValue')}]).send({from: caller});60 await expect(contract.methods.setCollectionProperties([{key: '', value: Buffer.from('val1')}]).send({from: caller})).to.be.rejected;
4361 await expect(contract.methods.setCollectionProperties([{key: 'déjà vu', value: Buffer.from('hmm...')}]).send({from: caller})).to.be.rejected;
62 await expect(contract.methods.setCollectionProperties([{key: 'a'.repeat(257), value: Buffer.from('val3')}]).send({from: caller})).to.be.rejected;
63 // TODO add more expects
44 const raw = (await collection.getData())?.raw;64 const raw = (await collection.getData())?.raw;
45
46 expect(raw.properties[0].value).to.equal('testValue');65 expect(raw.properties).to.deep.equal([]);
47 });66 });
4867
68
69 // Soft-deprecated: deleteCollectionProperty
70 [
71 {method: 'deleteCollectionProperties', methodParams: [['testKey1', 'testKey2']], expectedProps: [{key: 'testKey3', value: 'testValue3'}]},
72 {method: 'deleteCollectionProperty', methodParams: ['testKey1'], expectedProps: [{key: 'testKey2', value: 'testValue2'}, {key: 'testKey3', value: 'testValue3'}]},
73 ].map(testCase =>
49 itEth('Can be deleted', async({helper}) => {74 itEth(`Collection properties can be deleted: ${testCase.method}()`, async({helper}) => {
75 const properties = [
76 {key: 'testKey1', value: 'testValue1'},
77 {key: 'testKey2', value: 'testValue2'},
78 {key: 'testKey3', value: 'testValue3'}];
50 const caller = await helper.eth.createAccountWithBalance(donor);79 const caller = await helper.eth.createAccountWithBalance(donor);
51 const collection = await helper.nft.mintCollection(alice, {name: 'name', description: 'test', tokenPrefix: 'test', properties: [{key: 'testKey', value: 'testValue'}]});80 const collection = await helper.nft.mintCollection(alice, {name: 'name', description: 'test', tokenPrefix: 'test', properties});
5281
53 await collection.addAdmin(alice, {Ethereum: caller});82 await collection.addAdmin(alice, {Ethereum: caller});
5483
55 const address = helper.ethAddress.fromCollectionId(collection.collectionId);84 const address = helper.ethAddress.fromCollectionId(collection.collectionId);
56 const contract = helper.ethNativeContract.collection(address, 'nft', caller);85 const contract = helper.ethNativeContract.collection(address, 'nft', caller, testCase.method === 'deleteCollectionProperty');
5786
58 await contract.methods.deleteCollectionProperties(['testKey']).send({from: caller});87 await contract.methods[testCase.method](...testCase.methodParams).send({from: caller});
5988
60 const raw = (await collection.getData())?.raw;89 const raw = (await collection.getData())?.raw;
6190
62 expect(raw.properties.length).to.equal(0);91 expect(raw.properties.length).to.equal(testCase.expectedProps.length);
92 expect(raw.properties).to.deep.equal(testCase.expectedProps);
63 });93 }));
94
95
96 [
97 {method: 'deleteCollectionProperties', methodParams: [['testKey2']]},
98 {method: 'deleteCollectionProperty', methodParams: ['testKey2']},
99 ].map(testCase =>
100 itEth(`cannot ${testCase.method}() of non-owned collections`, async ({helper}) => {
101 const properties = [
102 {key: 'testKey1', value: 'testValue1'},
103 {key: 'testKey2', value: 'testValue2'},
104 ];
105 const caller = await helper.eth.createAccountWithBalance(donor);
106 const collection = await helper.nft.mintCollection(alice, {name: 'name', description: 'test', tokenPrefix: 'test', properties});
107
108 const address = helper.ethAddress.fromCollectionId(collection.collectionId);
109 const collectionEvm = helper.ethNativeContract.collection(address, 'nft', caller, testCase.method === 'deleteCollectionProperty');
110
111 await expect(collectionEvm.methods[testCase.method](...testCase.methodParams).send({from: caller})).to.be.rejected;
112 expect(await collection.getProperties()).to.deep.eq(properties);
113 }));
64114
65 itEth('Can be read', async({helper}) => {115 itEth('Can be read', async({helper}) => {
66 const caller = helper.eth.createAccount();116 const caller = helper.eth.createAccount();
73 expect(value).to.equal(helper.getWeb3().utils.toHex('testValue'));123 expect(value).to.equal(helper.getWeb3().utils.toHex('testValue'));
74 });124 });
75
76 // Soft-deprecated
77 itEth('Collection property can be set', async({helper}) => {
78 const caller = await helper.eth.createAccountWithBalance(donor);
79 const collection = await helper.nft.mintCollection(alice, {name: 'name', description: 'test', tokenPrefix: 'test', properties: []});
80 await collection.addAdmin(alice, {Ethereum: caller});
81
82 const address = helper.ethAddress.fromCollectionId(collection.collectionId);
83 const contract = helper.ethNativeContract.collection(address, 'nft', caller, true);
84
85 await contract.methods.setCollectionProperty('testKey', Buffer.from('testValue')).send();
86
87 const raw = (await collection.getData())?.raw;
88
89 expect(raw.properties[0].value).to.equal('testValue');
90 });
91
92 // Soft-deprecated
93 itEth('Collection property can be deleted', async({helper}) => {
94 const caller = await helper.eth.createAccountWithBalance(donor);
95 const collection = await helper.nft.mintCollection(alice, {name: 'name', description: 'test', tokenPrefix: 'test', properties: [{key: 'testKey', value: 'testValue'}]});
96
97 await collection.addAdmin(alice, {Ethereum: caller});
98
99 const address = helper.ethAddress.fromCollectionId(collection.collectionId);
100 const contract = helper.ethNativeContract.collection(address, 'nft', caller, true);
101
102 await contract.methods.deleteCollectionProperty('testKey').send({from: caller});
103
104 const raw = (await collection.getData())?.raw;
105
106 expect(raw.properties.length).to.equal(0);
107 });
108});125});
109126
110describe('Supports ERC721Metadata', () => {127describe('Supports ERC721Metadata', () => {
116 });133 });
117 });134 });
118135
136 [
119 const checkERC721Metadata = async (helper: EthUniqueHelper, mode: 'nft' | 'rft') => {137 {case: 'nft' as const},
138 {case: 'rft' as const, requiredPallets: [Pallets.ReFungible]},
139 ].map(testCase =>
140 itEth.ifWithPallets(`ERC721Metadata property can be set for ${testCase.case} collection`, testCase.requiredPallets || [], async ({helper}) => {
120 const caller = await helper.eth.createAccountWithBalance(donor);141 const caller = await helper.eth.createAccountWithBalance(donor);
121 const bruh = await helper.eth.createAccountWithBalance(donor);142 const bruh = await helper.eth.createAccountWithBalance(donor);
122143
125 const URI = 'uri1';146 const URI = 'uri1';
126147
127 const collectionHelpers = helper.ethNativeContract.collectionHelpers(caller);148 const collectionHelpers = helper.ethNativeContract.collectionHelpers(caller);
128 const creatorMethod = mode === 'rft' ? 'createRFTCollection' : 'createNFTCollection';149 const creatorMethod = testCase.case === 'rft' ? 'createRFTCollection' : 'createNFTCollection';
129150
130 const {collectionId, collectionAddress} = await helper.eth[creatorMethod](caller, 'n', 'd', 'p');151 const {collectionId, collectionAddress} = await helper.eth[creatorMethod](caller, 'n', 'd', 'p');
131 const bruhCross = helper.ethCrossAccount.fromAddress(bruh);152 const bruhCross = helper.ethCrossAccount.fromAddress(bruh);
132153
133 const contract = helper.ethNativeContract.collectionById(collectionId, mode, caller);154 const contract = helper.ethNativeContract.collectionById(collectionId, testCase.case, caller);
134 await contract.methods.addCollectionAdminCross(bruhCross).send(); // to check that admin will work too155 await contract.methods.addCollectionAdminCross(bruhCross).send(); // to check that admin will work too
135156
136 const collection1 = helper.nft.getCollectionObject(collectionId);157 const collection1 = helper.nft.getCollectionObject(collectionId);
186207
187 await contract.methods.setProperties(tokenId2, [{key: 'URISuffix', value: Buffer.from(SUFFIX)}]).send();208 await contract.methods.setProperties(tokenId2, [{key: 'URISuffix', value: Buffer.from(SUFFIX)}]).send();
188 expect(await contract.methods.tokenURI(tokenId2).call()).to.equal(BASE_URI + SUFFIX);209 expect(await contract.methods.tokenURI(tokenId2).call()).to.equal(BASE_URI + SUFFIX);
189 };210 }));
190
191 itEth('ERC721Metadata property can be set for NFT collection', async({helper}) => {
192 await checkERC721Metadata(helper, 'nft');
193 });
194
195 itEth.ifWithPallets('ERC721Metadata property can be set for RFT collection', [Pallets.ReFungible], async({helper}) => {
196 await checkERC721Metadata(helper, 'rft');
197 });
198});211});
199212
200describe('EVM collection property', () => {213describe('EVM collection property', () => {
206 });219 });
207 });220 });
208221
222 [
223 {case: 'nft' as const},
224 {case: 'rft' as const, requiredPallets: [Pallets.ReFungible]},
209 async function testSetReadProperties(helper: EthUniqueHelper, mode: TCollectionMode) {225 {case: 'ft' as const},
226 ].map(testCase =>
227 itEth.ifWithPallets(`can set/read properties ${testCase.case}`, testCase.requiredPallets || [], async ({helper}) => {
210 const collection = await helper[mode].mintCollection(donor, {name: 'A', description: 'B', tokenPrefix: 'C'});228 const collection = await helper[testCase.case].mintCollection(donor, {name: 'A', description: 'B', tokenPrefix: 'C'});
211229
212 const sender = await helper.eth.createAccountWithBalance(donor, 100n);230 const sender = await helper.eth.createAccountWithBalance(donor, 100n);
213 await collection.addAdmin(donor, {Ethereum: sender});231 await collection.addAdmin(donor, {Ethereum: sender});
214232
215 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);233 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
216 const contract = helper.ethNativeContract.collection(collectionAddress, mode, sender);234 const contract = helper.ethNativeContract.collection(collectionAddress, testCase.case, sender);
217235
218 const keys = ['key0', 'key1'];236 const keys = ['key0', 'key1'];
219237
225 await contract.methods.setCollectionProperties(writeProperties).send();243 await contract.methods.setCollectionProperties(writeProperties).send();
226 const readProperties = await contract.methods.collectionProperties([keys[0], keys[1]]).call();244 const readProperties = await contract.methods.collectionProperties([keys[0], keys[1]]).call();
227 expect(readProperties).to.be.like(writeProperties);245 expect(readProperties).to.be.like(writeProperties);
228 }246 }));
229247
230 itEth('Set/read properties ft', async ({helper}) => {248 [
231 await testSetReadProperties(helper, 'ft');249 {case: 'nft' as const},
232 });250 {case: 'rft' as const, requiredPallets: [Pallets.ReFungible]},
233 itEth.ifWithPallets('Set/read properties rft', [Pallets.ReFungible], async ({helper}) => {
234 await testSetReadProperties(helper, 'rft');
235 });
236 itEth('Set/read properties nft', async ({helper}) => {
237 await testSetReadProperties(helper, 'nft');
238 });
239
240 async function testDeleteProperties(helper: EthUniqueHelper, mode: TCollectionMode) {251 {case: 'ft' as const},
252 ].map(testCase =>
253 itEth.ifWithPallets(`can delete properties ${testCase.case}`, testCase.requiredPallets || [], async ({helper}) => {
241 const collection = await helper[mode].mintCollection(donor, {name: 'A', description: 'B', tokenPrefix: 'C'});254 const collection = await helper[testCase.case].mintCollection(donor, {name: 'A', description: 'B', tokenPrefix: 'C'});
242255
243 const sender = await helper.eth.createAccountWithBalance(donor, 100n);256 const sender = await helper.eth.createAccountWithBalance(donor, 100n);
244 await collection.addAdmin(donor, {Ethereum: sender});257 await collection.addAdmin(donor, {Ethereum: sender});
245258
246 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);259 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
247 const contract = helper.ethNativeContract.collection(collectionAddress, mode, sender);260 const contract = helper.ethNativeContract.collection(collectionAddress, testCase.case, sender);
248261
249 const keys = ['key0', 'key1', 'key2', 'key3'];262 const keys = ['key0', 'key1', 'key2', 'key3'];
250263
271 const readProperties = await contract.methods.collectionProperties([]).call();284 const readProperties = await contract.methods.collectionProperties([]).call();
272 expect(readProperties).to.be.like(expectProperties);285 expect(readProperties).to.be.like(expectProperties);
273 }286 }
274 }287 }));
275
276 itEth('Delete properties ft', async ({helper}) => {
277 await testDeleteProperties(helper, 'ft');
278 });
279 itEth.ifWithPallets('Delete properties rft', [Pallets.ReFungible], async ({helper}) => {
280 await testDeleteProperties(helper, 'rft');
281 });
282 itEth('Delete properties nft', async ({helper}) => {
283 await testDeleteProperties(helper, 'nft');
284 });
285
286});288});
287289
modifiedtests/src/eth/collectionSponsoring.test.tsdiffbeforeafterboth
31 });31 });
32 });32 });
33 33
34 // TODO: move to substrate tests
34 itEth('sponsors mint transactions', async ({helper}) => {35 itEth('sponsors mint transactions', async ({helper}) => {
35 const collection = await helper.nft.mintCollection(alice, {tokenPrefix: 'spnr', permissions: {mintMode: true}});36 const collection = await helper.nft.mintCollection(alice, {tokenPrefix: 'spnr', permissions: {mintMode: true}});
36 await collection.setSponsor(alice, alice.address);37 await collection.setSponsor(alice, alice.address);
81 // expect(bigIntToSub(api, BigInt(sponsorTuple[1]))).to.be.eq(sponsor.address);82 // expect(bigIntToSub(api, BigInt(sponsorTuple[1]))).to.be.eq(sponsor.address);
82 // });83 // });
8384
84 // Soft-deprecated85 [
86 'setCollectionSponsorCross',
87 'setCollectionSponsor', // Soft-deprecated
85 itEth('[eth] Remove sponsor', async ({helper}) => {88 ].map(testCase =>
89 itEth(`[${testCase}] can remove collection sponsor`, async ({helper}) => {
86 const owner = await helper.eth.createAccountWithBalance(donor);90 const owner = await helper.eth.createAccountWithBalance(donor);
87 const collectionHelpers = helper.ethNativeContract.collectionHelpers(owner);91 const collectionHelpers = helper.ethNativeContract.collectionHelpers(owner);
92
93 let result = await collectionHelpers.methods.createNFTCollection('Sponsor collection', '1', '1').send({value: Number(2n * nominal)});
94 const collectionIdAddress = helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);
95 const sponsor = await helper.eth.createAccountWithBalance(donor);
96 const sponsorCross = helper.ethCrossAccount.fromAddress(sponsor);
97 const collectionEvm = helper.ethNativeContract.collection(collectionIdAddress, 'nft', owner, testCase === 'setCollectionSponsor');
98
99 expect(await collectionEvm.methods.hasCollectionPendingSponsor().call({from: owner})).to.be.false;
100 result = await collectionEvm.methods[testCase](testCase === 'setCollectionSponsor' ? sponsor : sponsorCross).send({from: owner});
101 expect(await collectionEvm.methods.hasCollectionPendingSponsor().call({from: owner})).to.be.true;
102
103 await collectionEvm.methods.confirmCollectionSponsorship().send({from: sponsor});
104 expect(await collectionEvm.methods.hasCollectionPendingSponsor().call({from: owner})).to.be.false;
105
106 await collectionEvm.methods.removeCollectionSponsor().send({from: owner});
107
108 const sponsorTuple = await collectionEvm.methods.collectionSponsor().call({from: owner});
109 expect(sponsorTuple.field_0).to.be.eq('0x0000000000000000000000000000000000000000');
110 }));
88111
89 let result = await collectionHelpers.methods.createNFTCollection('Sponsor collection', '1', '1').send({value: Number(2n * nominal)});112 [
113 'setCollectionSponsorCross',
114 'setCollectionSponsor', // Soft-deprecated
115 ].map(testCase =>
116 itEth(`[${testCase}] Can sponsor from evm address via access list`, async ({helper}) => {
117 const owner = await helper.eth.createAccountWithBalance(donor);
118 const sponsorEth = await helper.eth.createAccountWithBalance(donor);
119 const sponsorCrossEth = helper.ethCrossAccount.fromAddress(sponsorEth);
120
121 const {collectionId, collectionAddress} = await helper.eth.createERC721MetadataCompatibleNFTCollection(owner, 'Sponsor collection', '1', '1', '');
122
123 const collectionSub = helper.nft.getCollectionObject(collectionId);
124 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, testCase === 'setCollectionSponsor');
125
126 // Set collection sponsor:
127 await collectionEvm.methods[testCase](testCase === 'setCollectionSponsor' ? sponsorEth : sponsorCrossEth).send({from: owner});
90 const collectionIdAddress = helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);128 let sponsorship = (await collectionSub.getData())!.raw.sponsorship;
129 expect(sponsorship.Unconfirmed).to.be.eq(helper.address.ethToSubstrate(sponsorEth, true));
91 const sponsor = await helper.eth.createAccountWithBalance(donor);130 // Account cannot confirm sponsorship if it is not set as a sponsor
131 await expect(collectionEvm.methods.confirmCollectionSponsorship().call()).to.be.rejectedWith('caller is not set as sponsor');
132
133 // Sponsor can confirm sponsorship:
134 await collectionEvm.methods.confirmCollectionSponsorship().send({from: sponsorEth});
135 sponsorship = (await collectionSub.getData())!.raw.sponsorship;
136 expect(sponsorship.Confirmed).to.be.eq(helper.address.ethToSubstrate(sponsorEth, true));
137
138 // Create user with no balance:
139 const user = helper.eth.createAccount();
92 const collectionEvm = helper.ethNativeContract.collection(collectionIdAddress, 'nft', owner, true);140 const userCross = helper.ethCrossAccount.fromAddress(user);
141 const nextTokenId = await collectionEvm.methods.nextTokenId().call();
142 expect(nextTokenId).to.be.equal('1');
143
144 // Set collection permissions:
145 const oldPermissions = (await collectionSub.getData())!.raw.permissions; // (await getDetailedCollectionInfo(api, collectionId))!.permissions.toHuman();
146 expect(oldPermissions.mintMode).to.be.false;
147 expect(oldPermissions.access).to.be.equal('Normal');
93148
94 expect(await collectionEvm.methods.hasCollectionPendingSponsor().call({from: owner})).to.be.false;149 await collectionEvm.methods.setCollectionAccess(1 /*'AllowList'*/).send({from: owner});
95 result = await collectionEvm.methods.setCollectionSponsor(sponsor).send({from: owner});150 await collectionEvm.methods.addToCollectionAllowListCross(userCross).send({from: owner});
96 expect(await collectionEvm.methods.hasCollectionPendingSponsor().call({from: owner})).to.be.true;151 await collectionEvm.methods.setCollectionMintMode(true).send({from: owner});
152
153 const newPermissions = (await collectionSub.getData())!.raw.permissions; // (await getDetailedCollectionInfo(api, collectionId))!.permissions.toHuman();
154 expect(newPermissions.mintMode).to.be.true;
155 expect(newPermissions.access).to.be.equal('AllowList');
156
157 const ownerBalanceBefore = await helper.balance.getSubstrate(helper.address.ethToSubstrate(owner));
158 const sponsorBalanceBefore = await helper.balance.getSubstrate(helper.address.ethToSubstrate(sponsorEth));
97159
98 await collectionEvm.methods.confirmCollectionSponsorship().send({from: sponsor});160 // User can mint token without balance:
99 expect(await collectionEvm.methods.hasCollectionPendingSponsor().call({from: owner})).to.be.false;161 {
100162 const result = await collectionEvm.methods.mintWithTokenURI(user, 'Test URI').send({from: user});
101 await collectionEvm.methods.removeCollectionSponsor().send({from: owner});163 const events = helper.eth.normalizeEvents(result.events);
102164
103 const sponsorTuple = await collectionEvm.methods.collectionSponsor().call({from: owner});165 expect(events).to.be.deep.equal([
104 expect(sponsorTuple.field_0).to.be.eq('0x0000000000000000000000000000000000000000');166 {
105 });167 address: collectionAddress,
106168 event: 'Transfer',
107 itEth('[cross] Remove sponsor', async ({helper}) => {169 args: {
108 const owner = await helper.eth.createAccountWithBalance(donor);170 from: '0x0000000000000000000000000000000000000000',
109 const collectionHelpers = helper.ethNativeContract.collectionHelpers(owner);171 to: user,
110172 tokenId: '1',
111 let result = await collectionHelpers.methods.createNFTCollection('Sponsor collection', '1', '1').send({value: Number(2n * nominal)});173 },
112 const collectionIdAddress = helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);
113 const sponsor = await helper.eth.createAccountWithBalance(donor);
114 const sponsorCross = helper.ethCrossAccount.fromAddress(sponsor);
115 const collectionEvm = helper.ethNativeContract.collection(collectionIdAddress, 'nft', owner);
116
117 expect(await collectionEvm.methods.hasCollectionPendingSponsor().call({from: owner})).to.be.false;
118 result = await collectionEvm.methods.setCollectionSponsorCross(sponsorCross).send({from: owner});
119 expect(await collectionEvm.methods.hasCollectionPendingSponsor().call({from: owner})).to.be.true;
120
121 await collectionEvm.methods.confirmCollectionSponsorship().send({from: sponsor});
122 expect(await collectionEvm.methods.hasCollectionPendingSponsor().call({from: owner})).to.be.false;
123
124 await collectionEvm.methods.removeCollectionSponsor().send({from: owner});
125
126 const sponsorTuple = await collectionEvm.methods.collectionSponsor().call({from: owner});
127 expect(sponsorTuple.field_0).to.be.eq('0x0000000000000000000000000000000000000000');
128 });
129
130 // Soft-deprecated
131 itEth('[eth] Sponsoring collection from evm address via access list', async ({helper}) => {
132 const owner = await helper.eth.createAccountWithBalance(donor);
133
134 const {collectionId, collectionAddress} = await helper.eth.createERC721MetadataCompatibleNFTCollection(owner, 'Sponsor collection', '1', '1', '');
135
136 const collection = helper.nft.getCollectionObject(collectionId);
137 const sponsor = await helper.eth.createAccountWithBalance(donor);
138 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);
139
140 await collectionEvm.methods.setCollectionSponsor(sponsor).send({from: owner});
141 let collectionData = (await collection.getData())!;
142 expect(collectionData.raw.sponsorship.Unconfirmed).to.be.eq(helper.address.ethToSubstrate(sponsor, true));
143 await expect(collectionEvm.methods.confirmCollectionSponsorship().call()).to.be.rejectedWith('caller is not set as sponsor');
144
145 await collectionEvm.methods.confirmCollectionSponsorship().send({from: sponsor});
146 collectionData = (await collection.getData())!;
147 expect(collectionData.raw.sponsorship.Confirmed).to.be.eq(helper.address.ethToSubstrate(sponsor, true));
148
149 const user = helper.eth.createAccount();
150 const nextTokenId = await collectionEvm.methods.nextTokenId().call();
151 expect(nextTokenId).to.be.equal('1');
152
153 const oldPermissions = (await collection.getData())!.raw.permissions; // (await getDetailedCollectionInfo(api, collectionId))!.permissions.toHuman();
154 expect(oldPermissions.mintMode).to.be.false;
155 expect(oldPermissions.access).to.be.equal('Normal');
156
157 await collectionEvm.methods.setCollectionAccess(1 /*'AllowList'*/).send({from: owner});
158 await collectionEvm.methods.addToCollectionAllowList(user).send({from: owner});
159 await collectionEvm.methods.setCollectionMintMode(true).send({from: owner});
160
161 const newPermissions = (await collection.getData())!.raw.permissions; // (await getDetailedCollectionInfo(api, collectionId))!.permissions.toHuman();
162 expect(newPermissions.mintMode).to.be.true;
163 expect(newPermissions.access).to.be.equal('AllowList');
164
165 const ownerBalanceBefore = await helper.balance.getSubstrate(helper.address.ethToSubstrate(owner));
166 const sponsorBalanceBefore = await helper.balance.getSubstrate(helper.address.ethToSubstrate(sponsor));
167
168 {
169 const result = await collectionEvm.methods.mintWithTokenURI(user, 'Test URI').send({from: user});
170 const events = helper.eth.normalizeEvents(result.events);
171
172 expect(events).to.be.deep.equal([
173 {
174 address: collectionAddress,
175 event: 'Transfer',
176 args: {
177 from: '0x0000000000000000000000000000000000000000',
178 to: user,
179 tokenId: '1',
180 },174 },
181 },175 ]);
182 ]);176
177 const ownerBalanceAfter = await helper.balance.getSubstrate(helper.address.ethToSubstrate(owner));
178 const sponsorBalanceAfter = await helper.balance.getSubstrate(helper.address.ethToSubstrate(sponsorEth));
179 const userBalanceAfter = await helper.balance.getSubstrate(helper.address.ethToSubstrate(user));
180
181 expect(await collectionEvm.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');
182 expect(ownerBalanceBefore).to.be.eq(ownerBalanceAfter);
183 expect(userBalanceAfter).to.be.eq(0n);
184 expect(sponsorBalanceBefore > sponsorBalanceAfter).to.be.true;
185 }
186 }));
183187
184 const ownerBalanceAfter = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(owner));
185 const sponsorBalanceAfter = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(sponsor));
186
187 expect(await collectionEvm.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');
188 expect(ownerBalanceBefore).to.be.eq(ownerBalanceAfter);
189 expect(sponsorBalanceBefore > sponsorBalanceAfter).to.be.true;
190 }
191 });
192
193 itEth('[cross] Sponsoring collection from evm address via access list', async ({helper}) => {
194 const owner = await helper.eth.createAccountWithBalance(donor);
195
196 const {collectionId, collectionAddress} = await helper.eth.createERC721MetadataCompatibleNFTCollection(owner, 'Sponsor collection', '1', '1', '');
197
198 const collection = helper.nft.getCollectionObject(collectionId);
199 const sponsor = await helper.eth.createAccountWithBalance(donor);
200 const sponsorCross = helper.ethCrossAccount.fromAddress(sponsor);
201 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
202
203 await collectionEvm.methods.setCollectionSponsorCross(sponsorCross).send({from: owner});
204 let collectionData = (await collection.getData())!;
205 expect(collectionData.raw.sponsorship.Unconfirmed).to.be.eq(helper.address.ethToSubstrate(sponsor, true));
206 await expect(collectionEvm.methods.confirmCollectionSponsorship().call()).to.be.rejectedWith('caller is not set as sponsor');
207
208 await collectionEvm.methods.confirmCollectionSponsorship().send({from: sponsor});
209 collectionData = (await collection.getData())!;
210 expect(collectionData.raw.sponsorship.Confirmed).to.be.eq(helper.address.ethToSubstrate(sponsor, true));
211
212 const user = helper.eth.createAccount();
213 const userCross = helper.ethCrossAccount.fromAddress(user);
214 const nextTokenId = await collectionEvm.methods.nextTokenId().call();
215 expect(nextTokenId).to.be.equal('1');
216
217 const oldPermissions = (await collection.getData())!.raw.permissions; // (await getDetailedCollectionInfo(api, collectionId))!.permissions.toHuman();
218 expect(oldPermissions.mintMode).to.be.false;
219 expect(oldPermissions.access).to.be.equal('Normal');
220
221 await collectionEvm.methods.setCollectionAccess(1 /*'AllowList'*/).send({from: owner});
222 await collectionEvm.methods.addToCollectionAllowListCross(userCross).send({from: owner});
223 await collectionEvm.methods.setCollectionMintMode(true).send({from: owner});
224
225 const newPermissions = (await collection.getData())!.raw.permissions; // (await getDetailedCollectionInfo(api, collectionId))!.permissions.toHuman();
226 expect(newPermissions.mintMode).to.be.true;
227 expect(newPermissions.access).to.be.equal('AllowList');
228
229 const ownerBalanceBefore = await helper.balance.getSubstrate(helper.address.ethToSubstrate(owner));
230 const sponsorBalanceBefore = await helper.balance.getSubstrate(helper.address.ethToSubstrate(sponsor));
231
232 {
233 const result = await collectionEvm.methods.mintWithTokenURI(user, 'Test URI').send({from: user});
234 const events = helper.eth.normalizeEvents(result.events);
235
236 expect(events).to.be.deep.equal([
237 {
238 address: collectionAddress,
239 event: 'Transfer',
240 args: {
241 from: '0x0000000000000000000000000000000000000000',
242 to: user,
243 tokenId: '1',
244 },
245 },
246 ]);
247
248 const ownerBalanceAfter = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(owner));
249 const sponsorBalanceAfter = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(sponsor));
250
251 expect(await collectionEvm.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');
252 expect(ownerBalanceBefore).to.be.eq(ownerBalanceAfter);
253 expect(sponsorBalanceBefore > sponsorBalanceAfter).to.be.true;
254 }
255 });
256
257 // TODO: Temprorary off. Need refactor188 // TODO: Temprorary off. Need refactor
258 // itWeb3('Sponsoring collection from substrate address via access list', async ({api, web3, privateKeyWrapper}) => {189 // itWeb3('Sponsoring collection from substrate address via access list', async ({api, web3, privateKeyWrapper}) => {
310 // }241 // }
311 // });242 // });
312243
313 // Soft-deprecated244 [
245 'setCollectionSponsorCross',
246 'setCollectionSponsor', // Soft-deprecated
314 itEth('[eth] Check that transaction via EVM spend money from sponsor address', async ({helper}) => {247 ].map(testCase =>
248 itEth(`[${testCase}] Check that transaction via EVM spend money from sponsor address`, async ({helper}) => {
315 const owner = await helper.eth.createAccountWithBalance(donor);249 const owner = await helper.eth.createAccountWithBalance(donor);
250 const sponsor = await helper.eth.createAccountWithBalance(donor);
251 const sponsorCross = helper.ethCrossAccount.fromAddress(sponsor);
252
253 const {collectionAddress, collectionId} = await helper.eth.createERC721MetadataCompatibleNFTCollection(owner,'Sponsor collection', '1', '1', '');
316254
317 const {collectionAddress, collectionId} = await helper.eth.createERC721MetadataCompatibleNFTCollection(owner,'Sponsor collection', '1', '1', '');255 const collectionSub = helper.nft.getCollectionObject(collectionId);
318 const collection = helper.nft.getCollectionObject(collectionId);
319 const sponsor = await helper.eth.createAccountWithBalance(donor);256 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, testCase === 'setCollectionSponsor');
320 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner, true);257 // Set collection sponsor:
321
322 await collectionEvm.methods.setCollectionSponsor(sponsor).send();258 await collectionEvm.methods[testCase](testCase === 'setCollectionSponsor' ? sponsor : sponsorCross).send();
323 let collectionData = (await collection.getData())!;259 let collectionData = (await collectionSub.getData())!;
324 expect(collectionData.raw.sponsorship.Unconfirmed).to.be.eq(helper.address.ethToSubstrate(sponsor, true));260 expect(collectionData.raw.sponsorship.Unconfirmed).to.be.eq(helper.address.ethToSubstrate(sponsor, true));
325 await expect(collectionEvm.methods.confirmCollectionSponsorship().call()).to.be.rejectedWith('caller is not set as sponsor');261 await expect(collectionEvm.methods.confirmCollectionSponsorship().call()).to.be.rejectedWith('caller is not set as sponsor');
326
327 const sponsorCollection = helper.ethNativeContract.collection(collectionAddress, 'nft', sponsor, true);262
328 await sponsorCollection.methods.confirmCollectionSponsorship().send();263 await collectionEvm.methods.confirmCollectionSponsorship().send({from: sponsor});
329 collectionData = (await collection.getData())!;264 collectionData = (await collectionSub.getData())!;
330 expect(collectionData.raw.sponsorship.Confirmed).to.be.eq(helper.address.ethToSubstrate(sponsor, true));265 expect(collectionData.raw.sponsorship.Confirmed).to.be.eq(helper.address.ethToSubstrate(sponsor, true));
331266
332 const user = helper.eth.createAccount();267 const user = helper.eth.createAccount();
333 await collectionEvm.methods.addCollectionAdmin(user).send();268 const userCross = helper.ethCrossAccount.fromAddress(user);
334269 await collectionEvm.methods.addCollectionAdminCross(userCross).send();
270
335 const ownerBalanceBefore = await helper.balance.getSubstrate(helper.address.ethToSubstrate(owner));271 const ownerBalanceBefore = await helper.balance.getSubstrate(helper.address.ethToSubstrate(owner));
336 const sponsorBalanceBefore = await helper.balance.getSubstrate(helper.address.ethToSubstrate(sponsor));272 const sponsorBalanceBefore = await helper.balance.getSubstrate(helper.address.ethToSubstrate(sponsor));
337
338 const userCollectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', user, true);273
339
340 const result = await userCollectionEvm.methods.mintWithTokenURI(user, 'Test URI').send();274 const mintingResult = await collectionEvm.methods.mintWithTokenURI(user, 'Test URI').send({from: user});
341 const tokenId = result.events.Transfer.returnValues.tokenId;275 const tokenId = mintingResult.events.Transfer.returnValues.tokenId;
342276
343 const events = helper.eth.normalizeEvents(result.events);277 const events = helper.eth.normalizeEvents(mintingResult.events);
344 const address = helper.ethAddress.fromCollectionId(collectionId);278 const address = helper.ethAddress.fromCollectionId(collectionId);
345279
346 expect(events).to.be.deep.equal([280 expect(events).to.be.deep.equal([
347 {281 {
348 address,282 address,
349 event: 'Transfer',283 event: 'Transfer',
350 args: {284 args: {
351 from: '0x0000000000000000000000000000000000000000',285 from: '0x0000000000000000000000000000000000000000',
352 to: user,286 to: user,
353 tokenId: '1',287 tokenId: '1',
288 },
354 },289 },
355 },290 ]);
356 ]);
357 expect(await userCollectionEvm.methods.tokenURI(tokenId).call()).to.be.equal('Test URI');291 expect(await collectionEvm.methods.tokenURI(tokenId).call({from: user})).to.be.equal('Test URI');
292
293 const ownerBalanceAfter = await helper.balance.getSubstrate(helper.address.ethToSubstrate(owner));
294 expect(ownerBalanceAfter).to.be.eq(ownerBalanceBefore);
295 const sponsorBalanceAfter = await helper.balance.getSubstrate(helper.address.ethToSubstrate(sponsor));
296 expect(sponsorBalanceAfter < sponsorBalanceBefore).to.be.true;
297 }));
358298
359 const ownerBalanceAfter = await helper.balance.getSubstrate(helper.address.ethToSubstrate(owner));299 itEth('Can reassign collection sponsor', async ({helper}) => {
360 expect(ownerBalanceAfter).to.be.eq(ownerBalanceBefore);
361 const sponsorBalanceAfter = await helper.balance.getSubstrate(helper.address.ethToSubstrate(sponsor));
362 expect(sponsorBalanceAfter < sponsorBalanceBefore).to.be.true;
363 });
364
365 itEth('[cross] Check that transaction via EVM spend money from sponsor address', async ({helper}) => {
366 const owner = await helper.eth.createAccountWithBalance(donor);300 const owner = await helper.eth.createAccountWithBalance(donor);
301 const sponsorEth = await helper.eth.createAccountWithBalance(donor);
302 const sponsorCrossEth = helper.ethCrossAccount.fromAddress(sponsorEth);
303 const [sponsorSub] = await helper.arrange.createAccounts([100n], donor);
304 const sponsorCrossSub = helper.ethCrossAccount.fromKeyringPair(sponsorSub);
367305
368 const {collectionAddress, collectionId} = await helper.eth.createERC721MetadataCompatibleNFTCollection(owner,'Sponsor collection', '1', '1', '');306 const {collectionAddress, collectionId} = await helper.eth.createERC721MetadataCompatibleNFTCollection(owner,'Sponsor collection', '1', '1', '');
369 const collection = helper.nft.getCollectionObject(collectionId);307 const collectionSub = helper.nft.getCollectionObject(collectionId);
370 const sponsor = await helper.eth.createAccountWithBalance(donor);
371 const sponsorCross = helper.ethCrossAccount.fromAddress(sponsor);
372 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);308 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
373309
374 await collectionEvm.methods.setCollectionSponsorCross(sponsorCross).send();310 // Set and confirm sponsor:
375 let collectionData = (await collection.getData())!;
376 expect(collectionData.raw.sponsorship.Unconfirmed).to.be.eq(helper.address.ethToSubstrate(sponsor, true));
377 await expect(collectionEvm.methods.confirmCollectionSponsorship().call()).to.be.rejectedWith('caller is not set as sponsor');311 await collectionEvm.methods.setCollectionSponsorCross(sponsorCrossEth).send({from: owner});
378
379 const sponsorCollection = helper.ethNativeContract.collection(collectionAddress, 'nft', sponsor);
380 await sponsorCollection.methods.confirmCollectionSponsorship().send();
381 collectionData = (await collection.getData())!;
382 expect(collectionData.raw.sponsorship.Confirmed).to.be.eq(helper.address.ethToSubstrate(sponsor, true));312 await collectionEvm.methods.confirmCollectionSponsorship().send({from: sponsorEth});
383
384 const user = helper.eth.createAccount();
385 const userCross = helper.ethCrossAccount.fromAddress(user);
386 await collectionEvm.methods.addCollectionAdminCross(userCross).send();
387
388 const ownerBalanceBefore = await helper.balance.getSubstrate(helper.address.ethToSubstrate(owner));
389 const sponsorBalanceBefore = await helper.balance.getSubstrate(helper.address.ethToSubstrate(sponsor));
390
391 const userCollectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', user);
392
393 const result = await userCollectionEvm.methods.mintWithTokenURI(user, 'Test URI').send();
394 const tokenId = result.events.Transfer.returnValues.tokenId;
395
396 const events = helper.eth.normalizeEvents(result.events);
397 const address = helper.ethAddress.fromCollectionId(collectionId);
398
399 expect(events).to.be.deep.equal([
400 {
401 address,
402 event: 'Transfer',
403 args: {
404 from: '0x0000000000000000000000000000000000000000',
405 to: user,
406 tokenId: '1',
407 },
408 },
409 ]);
410 expect(await userCollectionEvm.methods.tokenURI(tokenId).call()).to.be.equal('Test URI');
411313
412 const ownerBalanceAfter = await helper.balance.getSubstrate(helper.address.ethToSubstrate(owner));314 // Can reassign sponsor:
413 expect(ownerBalanceAfter).to.be.eq(ownerBalanceBefore);315 await collectionEvm.methods.setCollectionSponsorCross(sponsorCrossSub).send({from: owner});
414 const sponsorBalanceAfter = await helper.balance.getSubstrate(helper.address.ethToSubstrate(sponsor));316 const collectionSponsor = (await collectionSub.getData())?.raw.sponsorship;
415 expect(sponsorBalanceAfter < sponsorBalanceBefore).to.be.true;317 expect(collectionSponsor).to.deep.eq({Unconfirmed: sponsorSub.address});
416 });318 });
417});319});
418320
modifiedtests/src/eth/createFTCollection.test.tsdiffbeforeafterboth
79 expect(await collection.methods.description().call()).to.deep.equal(description);79 expect(await collection.methods.description().call()).to.deep.equal(description);
80 });80 });
81
82 itEth('Set limits', async ({helper}) => {
83 const owner = await helper.eth.createAccountWithBalance(donor);
84 const {collectionId, collectionAddress} = await helper.eth.createFungibleCollection(owner, 'Limits', DECIMALS, 'absolutely anything', 'INSI');
85 const limits = {
86 accountTokenOwnershipLimit: 1000,
87 sponsoredDataSize: 1024,
88 sponsoredDataRateLimit: 30,
89 tokenLimit: 1000000,
90 sponsorTransferTimeout: 6,
91 sponsorApproveTimeout: 6,
92 ownerCanTransfer: 0,
93 ownerCanDestroy: 0,
94 transfersEnabled: 0,
95 };
96
97 const expectedLimits = {
98 accountTokenOwnershipLimit: 1000,
99 sponsoredDataSize: 1024,
100 sponsoredDataRateLimit: 30,
101 tokenLimit: 1000000,
102 sponsorTransferTimeout: 6,
103 sponsorApproveTimeout: 6,
104 ownerCanTransfer: false,
105 ownerCanDestroy: false,
106 transfersEnabled: false,
107 };
108
109 const collection = helper.ethNativeContract.collection(collectionAddress, 'ft', owner);
110 await collection.methods.setCollectionLimit('accountTokenOwnershipLimit', limits.accountTokenOwnershipLimit).send();
111 await collection.methods.setCollectionLimit('sponsoredDataSize', limits.sponsoredDataSize).send();
112 await collection.methods.setCollectionLimit('sponsoredDataRateLimit', limits.sponsoredDataRateLimit).send();
113 await collection.methods.setCollectionLimit('tokenLimit', limits.tokenLimit).send();
114 await collection.methods.setCollectionLimit('sponsorTransferTimeout', limits.sponsorTransferTimeout).send();
115 await collection.methods.setCollectionLimit('sponsorApproveTimeout', limits.sponsorApproveTimeout).send();
116 await collection.methods.setCollectionLimit('ownerCanTransfer', limits.ownerCanTransfer).send();
117 await collection.methods.setCollectionLimit('ownerCanDestroy', limits.ownerCanDestroy).send();
118 await collection.methods.setCollectionLimit('transfersEnabled', limits.transfersEnabled).send();
119
120 const data = (await helper.rft.getData(collectionId))!;
121 expect(data.raw.limits.accountTokenOwnershipLimit).to.be.eq(expectedLimits.accountTokenOwnershipLimit);
122 expect(data.raw.limits.sponsoredDataSize).to.be.eq(expectedLimits.sponsoredDataSize);
123 expect(data.raw.limits.sponsoredDataRateLimit.blocks).to.be.eq(expectedLimits.sponsoredDataRateLimit);
124 expect(data.raw.limits.tokenLimit).to.be.eq(expectedLimits.tokenLimit);
125 expect(data.raw.limits.sponsorTransferTimeout).to.be.eq(expectedLimits.sponsorTransferTimeout);
126 expect(data.raw.limits.sponsorApproveTimeout).to.be.eq(expectedLimits.sponsorApproveTimeout);
127 expect(data.raw.limits.ownerCanTransfer).to.be.eq(expectedLimits.ownerCanTransfer);
128 expect(data.raw.limits.ownerCanDestroy).to.be.eq(expectedLimits.ownerCanDestroy);
129 expect(data.raw.limits.transfersEnabled).to.be.eq(expectedLimits.transfersEnabled);
130 });
13181
132 itEth('Collection address exist', async ({helper}) => {82 itEth('Collection address exist', async ({helper}) => {
133 const owner = await helper.eth.createAccountWithBalance(donor);83 const owner = await helper.eth.createAccountWithBalance(donor);
276 }226 }
277 });227 });
278
279 itEth('(!negative test!) Set limits', async ({helper}) => {
280
281 const invalidLimits = {
282 accountTokenOwnershipLimit: BigInt(Number.MAX_SAFE_INTEGER),
283 transfersEnabled: 3,
284 };
285
286 const owner = await helper.eth.createAccountWithBalance(donor);
287 const {collectionAddress} = await helper.eth.createFungibleCollection(owner, 'Limits', DECIMALS, 'absolutely anything', 'ISNI');
288 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'ft', owner);
289 await expect(collectionEvm.methods
290 .setCollectionLimit('badLimit', '1')
291 .call()).to.be.rejectedWith('unknown limit "badLimit"');
292
293 await expect(collectionEvm.methods
294 .setCollectionLimit(Object.keys(invalidLimits)[0], invalidLimits.accountTokenOwnershipLimit)
295 .call()).to.be.rejectedWith(`can't convert value to u32 "${invalidLimits.accountTokenOwnershipLimit}"`);
296
297 await expect(collectionEvm.methods
298 .setCollectionLimit(Object.keys(invalidLimits)[1], invalidLimits.transfersEnabled)
299 .call()).to.be.rejectedWith(`can't convert value to boolean "${invalidLimits.transfersEnabled}"`);
300 });
301
302
303
modifiedtests/src/eth/createNFTCollection.test.tsdiffbeforeafterboth
120 expect(await sponsorCollection.methods.description().call()).to.deep.equal(description);120 expect(await sponsorCollection.methods.description().call()).to.deep.equal(description);
121 });121 });
122
123 itEth('Set limits', async ({helper}) => {
124 const owner = await helper.eth.createAccountWithBalance(donor);
125 const {collectionId, collectionAddress} = await helper.eth.createNFTCollection(owner, 'Limits', 'absolutely anything', 'FLO');
126 const limits = {
127 accountTokenOwnershipLimit: 1000,
128 sponsoredDataSize: 1024,
129 sponsoredDataRateLimit: 30,
130 tokenLimit: 1000000,
131 sponsorTransferTimeout: 6,
132 sponsorApproveTimeout: 6,
133 ownerCanTransfer: 0,
134 ownerCanDestroy: 0,
135 transfersEnabled: 0,
136 };
137
138 const expectedLimits = {
139 accountTokenOwnershipLimit: 1000,
140 sponsoredDataSize: 1024,
141 sponsoredDataRateLimit: 30,
142 tokenLimit: 1000000,
143 sponsorTransferTimeout: 6,
144 sponsorApproveTimeout: 6,
145 ownerCanTransfer: false,
146 ownerCanDestroy: false,
147 transfersEnabled: false,
148 };
149
150 const collection = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
151 await collection.methods.setCollectionLimit('accountTokenOwnershipLimit', limits.accountTokenOwnershipLimit).send();
152 await collection.methods.setCollectionLimit('sponsoredDataSize', limits.sponsoredDataSize).send();
153 await collection.methods.setCollectionLimit('sponsoredDataRateLimit', limits.sponsoredDataRateLimit).send();
154 await collection.methods.setCollectionLimit('tokenLimit', limits.tokenLimit).send();
155 await collection.methods.setCollectionLimit('sponsorTransferTimeout', limits.sponsorTransferTimeout).send();
156 await collection.methods.setCollectionLimit('sponsorApproveTimeout', limits.sponsorApproveTimeout).send();
157 await collection.methods.setCollectionLimit('ownerCanTransfer', limits.ownerCanTransfer).send();
158 await collection.methods.setCollectionLimit('ownerCanDestroy', limits.ownerCanDestroy).send();
159 await collection.methods.setCollectionLimit('transfersEnabled', limits.transfersEnabled).send();
160
161 const data = (await helper.rft.getData(collectionId))!;
162 expect(data.raw.limits.accountTokenOwnershipLimit).to.be.eq(expectedLimits.accountTokenOwnershipLimit);
163 expect(data.raw.limits.sponsoredDataSize).to.be.eq(expectedLimits.sponsoredDataSize);
164 expect(data.raw.limits.sponsoredDataRateLimit.blocks).to.be.eq(expectedLimits.sponsoredDataRateLimit);
165 expect(data.raw.limits.tokenLimit).to.be.eq(expectedLimits.tokenLimit);
166 expect(data.raw.limits.sponsorTransferTimeout).to.be.eq(expectedLimits.sponsorTransferTimeout);
167 expect(data.raw.limits.sponsorApproveTimeout).to.be.eq(expectedLimits.sponsorApproveTimeout);
168 expect(data.raw.limits.ownerCanTransfer).to.be.eq(expectedLimits.ownerCanTransfer);
169 expect(data.raw.limits.ownerCanDestroy).to.be.eq(expectedLimits.ownerCanDestroy);
170 expect(data.raw.limits.transfersEnabled).to.be.eq(expectedLimits.transfersEnabled);
171 });
172122
173 itEth('Collection address exist', async ({helper}) => {123 itEth('Collection address exist', async ({helper}) => {
174 const owner = await helper.eth.createAccountWithBalance(donor);124 const owner = await helper.eth.createAccountWithBalance(donor);
287 }237 }
288 });238 });
289
290 itEth('(!negative test!) Set limits', async ({helper}) => {
291 const invalidLimits = {
292 accountTokenOwnershipLimit: BigInt(Number.MAX_SAFE_INTEGER),
293 transfersEnabled: 3,
294 };
295
296 const owner = await helper.eth.createAccountWithBalance(donor);
297 const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'Limits', 'absolutely anything', 'OLF');
298 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
299
300 await expect(collectionEvm.methods
301 .setCollectionLimit(Object.keys(invalidLimits)[0], invalidLimits.accountTokenOwnershipLimit)
302 .call()).to.be.rejectedWith(`can't convert value to u32 "${invalidLimits.accountTokenOwnershipLimit}"`);
303
304 await expect(collectionEvm.methods
305 .setCollectionLimit(Object.keys(invalidLimits)[1], invalidLimits.transfersEnabled)
306 .call()).to.be.rejectedWith(`can't convert value to boolean "${invalidLimits.transfersEnabled}"`);
307 });
308239
309 itEth('destroyCollection', async ({helper}) => {240 itEth('destroyCollection', async ({helper}) => {
310 const owner = await helper.eth.createAccountWithBalance(donor);241 const owner = await helper.eth.createAccountWithBalance(donor);
modifiedtests/src/eth/createRFTCollection.test.tsdiffbeforeafterboth
152 expect(data.raw.sponsorship.Confirmed).to.be.equal(evmToAddress(sponsor, Number(ss58Format)));152 expect(data.raw.sponsorship.Confirmed).to.be.equal(evmToAddress(sponsor, Number(ss58Format)));
153 });153 });
154
155 itEth('Set limits', async ({helper}) => {
156 const owner = await helper.eth.createAccountWithBalance(donor);
157 const {collectionId, collectionAddress} = await helper.eth.createRFTCollection(owner, 'Limits', 'absolutely anything', 'INSI');
158 const limits = {
159 accountTokenOwnershipLimit: 1000,
160 sponsoredDataSize: 1024,
161 sponsoredDataRateLimit: 30,
162 tokenLimit: 1000000,
163 sponsorTransferTimeout: 6,
164 sponsorApproveTimeout: 6,
165 ownerCanTransfer: 0,
166 ownerCanDestroy: 0,
167 transfersEnabled: 0,
168 };
169
170 const expectedLimits = {
171 accountTokenOwnershipLimit: 1000,
172 sponsoredDataSize: 1024,
173 sponsoredDataRateLimit: 30,
174 tokenLimit: 1000000,
175 sponsorTransferTimeout: 6,
176 sponsorApproveTimeout: 6,
177 ownerCanTransfer: false,
178 ownerCanDestroy: false,
179 transfersEnabled: false,
180 };
181
182 const collection = helper.ethNativeContract.collection(collectionAddress, 'rft', owner);
183 await collection.methods.setCollectionLimit('accountTokenOwnershipLimit', limits.accountTokenOwnershipLimit).send();
184 await collection.methods.setCollectionLimit('sponsoredDataSize', limits.sponsoredDataSize).send();
185 await collection.methods.setCollectionLimit('sponsoredDataRateLimit', limits.sponsoredDataRateLimit).send();
186 await collection.methods.setCollectionLimit('tokenLimit', limits.tokenLimit).send();
187 await collection.methods.setCollectionLimit('sponsorTransferTimeout', limits.sponsorTransferTimeout).send();
188 await collection.methods.setCollectionLimit('sponsorApproveTimeout', limits.sponsorApproveTimeout).send();
189 await collection.methods.setCollectionLimit('ownerCanTransfer', limits.ownerCanTransfer).send();
190 await collection.methods.setCollectionLimit('ownerCanDestroy', limits.ownerCanDestroy).send();
191 await collection.methods.setCollectionLimit('transfersEnabled', limits.transfersEnabled).send();
192
193 const data = (await helper.rft.getData(collectionId))!;
194 expect(data.raw.limits.accountTokenOwnershipLimit).to.be.eq(expectedLimits.accountTokenOwnershipLimit);
195 expect(data.raw.limits.sponsoredDataSize).to.be.eq(expectedLimits.sponsoredDataSize);
196 expect(data.raw.limits.sponsoredDataRateLimit.blocks).to.be.eq(expectedLimits.sponsoredDataRateLimit);
197 expect(data.raw.limits.tokenLimit).to.be.eq(expectedLimits.tokenLimit);
198 expect(data.raw.limits.sponsorTransferTimeout).to.be.eq(expectedLimits.sponsorTransferTimeout);
199 expect(data.raw.limits.sponsorApproveTimeout).to.be.eq(expectedLimits.sponsorApproveTimeout);
200 expect(data.raw.limits.ownerCanTransfer).to.be.eq(expectedLimits.ownerCanTransfer);
201 expect(data.raw.limits.ownerCanDestroy).to.be.eq(expectedLimits.ownerCanDestroy);
202 expect(data.raw.limits.transfersEnabled).to.be.eq(expectedLimits.transfersEnabled);
203 });
204154
205 itEth('Collection address exist', async ({helper}) => {155 itEth('Collection address exist', async ({helper}) => {
206 const owner = await helper.eth.createAccountWithBalance(donor);156 const owner = await helper.eth.createAccountWithBalance(donor);
319 }269 }
320 });270 });
321271
322 itEth('(!negative test!) Set limits', async ({helper}) => {
323 const invalidLimits = {
324 accountTokenOwnershipLimit: BigInt(Number.MAX_SAFE_INTEGER),
325 transfersEnabled: 3,
326 };
327
328 const owner = await helper.eth.createAccountWithBalance(donor);
329 const {collectionAddress} = await helper.eth.createRFTCollection(owner, 'Limits', 'absolutely anything', 'ISNI');
330 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'rft', owner);
331
332 await expect(collectionEvm.methods
333 .setCollectionLimit(Object.keys(invalidLimits)[0], invalidLimits.accountTokenOwnershipLimit)
334 .call()).to.be.rejectedWith(`can't convert value to u32 "${invalidLimits.accountTokenOwnershipLimit}"`);
335
336 await expect(collectionEvm.methods
337 .setCollectionLimit(Object.keys(invalidLimits)[1], invalidLimits.transfersEnabled)
338 .call()).to.be.rejectedWith(`can't convert value to boolean "${invalidLimits.transfersEnabled}"`);
339 });
340
341 itEth('destroyCollection', async ({helper}) => {272 itEth('destroyCollection', async ({helper}) => {
342 const owner = await helper.eth.createAccountWithBalance(donor);273 const owner = await helper.eth.createAccountWithBalance(donor);
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
129 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 }
131131
132 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 }
135135
136 rftToken(address: string, caller?: string): Contract {136 rftToken(address: string, caller?: string): Contract {