git.delta.rocks / unique-network / refs/commits / 49ce5073fa4a

difftreelog

Add reassign sponsor test

Max Andreev2022-12-07parent: #06a1c73.patch.diff
in: master

1 file changed

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);
124 125
125 // Set collection sponsor:126 // Set collection sponsor:
126 await collectionEvm.methods[testCase](testCase === 'setCollectionSponsor' ? sponsorEth : sponsorCrossEth).send({from: owner});127 await collectionEvm.methods[testCase](testCase === 'setCollectionSponsor' ? sponsorEth : sponsorCrossEth).send({from: owner});
127 let collectionData = (await collectionSub.getData())!;128 let sponsorship = (await collectionSub.getData())!.raw.sponsorship;
128 expect(collectionData.raw.sponsorship.Unconfirmed).to.be.eq(helper.address.ethToSubstrate(sponsorEth, true));129 expect(sponsorship.Unconfirmed).to.be.eq(helper.address.ethToSubstrate(sponsorEth, true));
129 // Account cannot confirm sponsorship if it is not set as a sponsor130 // Account cannot confirm sponsorship if it is not set as a sponsor
130 await expect(collectionEvm.methods.confirmCollectionSponsorship().call()).to.be.rejectedWith('caller is not set as sponsor');131 await expect(collectionEvm.methods.confirmCollectionSponsorship().call()).to.be.rejectedWith('caller is not set as sponsor');
131 132
132 // Sponsor can confirm sponsorship:133 // Sponsor can confirm sponsorship:
133 await collectionEvm.methods.confirmCollectionSponsorship().send({from: sponsorEth});134 await collectionEvm.methods.confirmCollectionSponsorship().send({from: sponsorEth});
134 collectionData = (await collectionSub.getData())!;135 sponsorship = (await collectionSub.getData())!.raw.sponsorship;
135 expect(collectionData.raw.sponsorship.Confirmed).to.be.eq(helper.address.ethToSubstrate(sponsorEth, true));136 expect(sponsorship.Confirmed).to.be.eq(helper.address.ethToSubstrate(sponsorEth, true));
136 137
137 // Create user with no balance:138 // Create user with no balance:
138 const user = helper.eth.createAccount();139 const user = helper.eth.createAccount();
259 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));
260 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');
261 262
262 const sponsorCollection = helper.ethNativeContract.collection(collectionAddress, 'nft', sponsor);
263 await sponsorCollection.methods.confirmCollectionSponsorship().send();263 await collectionEvm.methods.confirmCollectionSponsorship().send({from: sponsor});
264 collectionData = (await collectionSub.getData())!;264 collectionData = (await collectionSub.getData())!;
265 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));
266 266
271 const ownerBalanceBefore = await helper.balance.getSubstrate(helper.address.ethToSubstrate(owner));271 const ownerBalanceBefore = await helper.balance.getSubstrate(helper.address.ethToSubstrate(owner));
272 const sponsorBalanceBefore = await helper.balance.getSubstrate(helper.address.ethToSubstrate(sponsor));272 const sponsorBalanceBefore = await helper.balance.getSubstrate(helper.address.ethToSubstrate(sponsor));
273 273
274 const userCollectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', user);
275
276 const result = await userCollectionEvm.methods.mintWithTokenURI(user, 'Test URI').send();274 const mintingResult = await collectionEvm.methods.mintWithTokenURI(user, 'Test URI').send({from: user});
277 const tokenId = result.events.Transfer.returnValues.tokenId;275 const tokenId = mintingResult.events.Transfer.returnValues.tokenId;
278 276
279 const events = helper.eth.normalizeEvents(result.events);277 const events = helper.eth.normalizeEvents(mintingResult.events);
280 const address = helper.ethAddress.fromCollectionId(collectionId);278 const address = helper.ethAddress.fromCollectionId(collectionId);
281 279
282 expect(events).to.be.deep.equal([280 expect(events).to.be.deep.equal([
290 },288 },
291 },289 },
292 ]);290 ]);
293 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');
294 292
295 const ownerBalanceAfter = await helper.balance.getSubstrate(helper.address.ethToSubstrate(owner));293 const ownerBalanceAfter = await helper.balance.getSubstrate(helper.address.ethToSubstrate(owner));
296 expect(ownerBalanceAfter).to.be.eq(ownerBalanceBefore);294 expect(ownerBalanceAfter).to.be.eq(ownerBalanceBefore);
297 const sponsorBalanceAfter = await helper.balance.getSubstrate(helper.address.ethToSubstrate(sponsor));295 const sponsorBalanceAfter = await helper.balance.getSubstrate(helper.address.ethToSubstrate(sponsor));
298 expect(sponsorBalanceAfter < sponsorBalanceBefore).to.be.true;296 expect(sponsorBalanceAfter < sponsorBalanceBefore).to.be.true;
299 }));297 }));
298
299 itEth('Can reassign collection sponsor', async ({helper}) => {
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);
305
306 const {collectionAddress, collectionId} = await helper.eth.createERC721MetadataCompatibleNFTCollection(owner,'Sponsor collection', '1', '1', '');
307 const collectionSub = helper.nft.getCollectionObject(collectionId);
308 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
309
310 // Set and confirm sponsor:
311 await collectionEvm.methods.setCollectionSponsorCross(sponsorCrossEth).send({from: owner});
312 await collectionEvm.methods.confirmCollectionSponsorship().send({from: sponsorEth});
313
314 // Can reassign sponsor:
315 await collectionEvm.methods.setCollectionSponsorCross(sponsorCrossSub).send({from: owner});
316 const collectionSponsor = (await collectionSub.getData())?.raw.sponsorship;
317 expect(collectionSponsor).to.deep.eq({Unconfirmed: sponsorSub.address});
318 });
300});319});
301320