git.delta.rocks / unique-network / refs/commits / 19616c6c3dee

difftreelog

fix collectionSponsoringTests

Maksandre2022-10-05parent: #44c4cc8.patch.diff
in: master

1 file changed

modifiedtests/src/eth/collectionSponsoring.test.tsdiffbeforeafterboth
1import {collectionIdToAddress, normalizeEvents} from './util/helpers';1import {usingPlaygrounds} from './../util/playgrounds/index';
2import {evmToAddress} from '@polkadot/util-crypto';2import {IKeyringPair} from '@polkadot/types/types';
3import {normalizeEvents} from './util/helpers';
3import {itEth, expect} from '../eth/util/playgrounds';4import {itEth, expect} from '../eth/util/playgrounds';
45
5describe('evm collection sponsoring', () => {6describe('evm collection sponsoring', () => {
7 let donor: IKeyringPair;
8 let alice: IKeyringPair;
9 let nominal: bigint;
10
11 before(async () => {
12 await usingPlaygrounds(async (helper, privateKey) => {
13 donor = privateKey('//Alice');
14 nominal = helper.balance.getOneTokenNominal();
15 });
16 });
17
18 beforeEach(async () => {
19 await usingPlaygrounds(async (helper) => {
20 [alice] = await helper.arrange.createAccounts([1000n], donor);
21 });
22 });
23
6 itEth('sponsors mint transactions', async ({helper, privateKey}) => {24 itEth('sponsors mint transactions', async ({helper}) => {
7 const alice = privateKey('//Alice');
8
9 const collection = await helper.nft.mintCollection(alice, {tokenPrefix: 'spnr', permissions: {mintMode: true}});25 const collection = await helper.nft.mintCollection(alice, {tokenPrefix: 'spnr', permissions: {mintMode: true}});
10 await collection.setSponsor(alice, alice.address);26 await collection.setSponsor(alice, alice.address);
13 const minter = helper.eth.createAccount();29 const minter = helper.eth.createAccount();
14 expect(await helper.balance.getEthereum(minter)).to.equal(0n);30 expect(await helper.balance.getEthereum(minter)).to.equal(0n);
1531
16 const address = helper.ethAddress.fromCollectionId(collection.collectionId);32 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
17 const contract = helper.ethNativeContract.collection(address, 'nft', minter);33 const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', minter);
1834
19 await collection.addToAllowList(alice, {Ethereum: minter});35 await collection.addToAllowList(alice, {Ethereum: minter});
2036
24 const events = normalizeEvents(result.events);40 const events = normalizeEvents(result.events);
25 expect(events).to.be.deep.equal([41 expect(events).to.be.deep.equal([
26 {42 {
27 address,43 address: collectionAddress,
28 event: 'Transfer',44 event: 'Transfer',
29 args: {45 args: {
30 from: '0x0000000000000000000000000000000000000000',46 from: '0x0000000000000000000000000000000000000000',
56 // expect(bigIntToSub(api, BigInt(sponsorTuple[1]))).to.be.eq(sponsor.address);72 // expect(bigIntToSub(api, BigInt(sponsorTuple[1]))).to.be.eq(sponsor.address);
57 // });73 // });
5874
59 itEth('Remove sponsor', async ({helper, privateKey}) => {75 itEth('Remove sponsor', async ({helper}) => {
60 const alice = privateKey('//Alice');
61
62 const owner = await helper.eth.createAccountWithBalance(alice);76 const owner = await helper.eth.createAccountWithBalance(donor);
63 const collectionHelpers = helper.ethNativeContract.collectionHelpers(owner);77 const collectionHelpers = helper.ethNativeContract.collectionHelpers(owner);
6478
65 let result = await collectionHelpers.methods.createNonfungibleCollection('Sponsor collection', '1', '1').send();79 let result = await collectionHelpers.methods.createNonfungibleCollection('Sponsor collection', '1', '1').send({value: Number(2n * nominal)});
66 const collectionIdAddress = helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);80 const collectionIdAddress = helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);
67 const sponsor = await helper.eth.createAccountWithBalance(alice);81 const sponsor = await helper.eth.createAccountWithBalance(donor);
68 const collectionEvm = helper.ethNativeContract.collection(collectionIdAddress, 'nft', owner);82 const collectionEvm = helper.ethNativeContract.collection(collectionIdAddress, 'nft', owner);
6983
70 expect(await collectionEvm.methods.hasCollectionPendingSponsor().call({from: owner})).to.be.false;84 expect(await collectionEvm.methods.hasCollectionPendingSponsor().call({from: owner})).to.be.false;
81 });95 });
8296
83 itEth('Sponsoring collection from evm address via access list', async ({helper, privateKey}) => {97 itEth('Sponsoring collection from evm address via access list', async ({helper, privateKey}) => {
84 const alice = privateKey('//Alice');
85
86 const owner = await helper.eth.createAccountWithBalance(alice);98 const owner = await helper.eth.createAccountWithBalance(donor);
87 const collectionHelpers = helper.ethNativeContract.collectionHelpers(owner);99 const collectionHelpers = helper.ethNativeContract.collectionHelpers(owner);
88100
89 let result = await collectionHelpers.methods.createNonfungibleCollection('Sponsor collection', '1', '1').send();101 let result = await collectionHelpers.methods.createNonfungibleCollection('Sponsor collection', '1', '1').send({value: Number(2n * nominal)});
90 const collectionIdAddress = helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);102 const collectionIdAddress = helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);
91 const collectionId = helper.ethAddress.extractCollectionId(collectionIdAddress);103 const collectionId = helper.ethAddress.extractCollectionId(collectionIdAddress);
92 const collection = helper.nft.getCollectionObject(collectionId);104 const collection = helper.nft.getCollectionObject(collectionId);
93 const sponsor = await helper.eth.createAccountWithBalance(alice);105 const sponsor = await helper.eth.createAccountWithBalance(donor);
94 const collectionEvm = await helper.ethNativeContract.collection(collectionIdAddress, 'nft', owner);106 const collectionEvm = helper.ethNativeContract.collection(collectionIdAddress, 'nft', owner);
95107
96 result = await collectionEvm.methods.setCollectionSponsor(sponsor).send({from: owner});108 result = await collectionEvm.methods.setCollectionSponsor(sponsor).send({from: owner});
97 let collectionData = (await collection.getData())!;109 let collectionData = (await collection.getData())!;
98 const ss58Format = helper.chain.getChainProperties().ss58Format;110 const ss58Format = helper.chain.getChainProperties().ss58Format;
99 expect(collectionData.raw.sponsorship.Unconfirmed).to.be.eq(evmToAddress(sponsor, Number(ss58Format)));111 expect(collectionData.raw.sponsorship.Unconfirmed).to.be.eq(helper.address.ethToSubstrate(sponsor));
100 await expect(collectionEvm.methods.confirmCollectionSponsorship().call()).to.be.rejectedWith('caller is not set as sponsor');112 await expect(collectionEvm.methods.confirmCollectionSponsorship().call()).to.be.rejectedWith('caller is not set as sponsor');
101113
102 await collectionEvm.methods.confirmCollectionSponsorship().send({from: sponsor});114 await collectionEvm.methods.confirmCollectionSponsorship().send({from: sponsor});
103 collectionData = (await collection.getData())!;115 collectionData = (await collection.getData())!;
104 expect(collectionData.raw.sponsorship.Confirmed).to.be.eq(evmToAddress(sponsor, Number(ss58Format)));116 expect(collectionData.raw.sponsorship.Confirmed).to.be.eq(helper.address.ethToSubstrate(sponsor));
105117
106 const user = helper.eth.createAccount();118 const user = helper.eth.createAccount();
107 const nextTokenId = await collectionEvm.methods.nextTokenId().call();119 const nextTokenId = await collectionEvm.methods.nextTokenId().call();
119 expect(newPermissions.mintMode).to.be.true;131 expect(newPermissions.mintMode).to.be.true;
120 expect(newPermissions.access).to.be.equal('AllowList');132 expect(newPermissions.access).to.be.equal('AllowList');
121133
122 const ownerBalanceBefore = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(owner));134 const ownerBalanceBefore = await helper.balance.getSubstrate(helper.address.ethToSubstrate(owner));
123 const sponsorBalanceBefore = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(sponsor));135 const sponsorBalanceBefore = await helper.balance.getSubstrate(helper.address.ethToSubstrate(sponsor));
124136
125 {137 {
126 const nextTokenId = await collectionEvm.methods.nextTokenId().call();138 const nextTokenId = await collectionEvm.methods.nextTokenId().call();
210 // });222 // });
211223
212 itEth('Check that transaction via EVM spend money from sponsor address', async ({helper, privateKey}) => {224 itEth('Check that transaction via EVM spend money from sponsor address', async ({helper, privateKey}) => {
213 const alice = privateKey('//Alice');
214
215 const owner = await helper.eth.createAccountWithBalance(alice);225 const owner = await helper.eth.createAccountWithBalance(donor);
216 const collectionHelpers = helper.ethNativeContract.collectionHelpers(owner);226 const collectionHelpers = helper.ethNativeContract.collectionHelpers(owner);
217227
218 let result = await collectionHelpers.methods.createNonfungibleCollection('Sponsor collection', '1', '1').send();228 let result = await collectionHelpers.methods.createNonfungibleCollection('Sponsor collection', '1', '1').send({value: Number(2n * nominal)});
219 const collectionIdAddress = helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);229 const collectionIdAddress = helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);
220 const collectionId = helper.ethAddress.extractCollectionId(collectionIdAddress);230 const collectionId = helper.ethAddress.extractCollectionId(collectionIdAddress);
221 const collection = helper.nft.getCollectionObject(collectionId);231 const collection = helper.nft.getCollectionObject(collectionId);
222 const sponsor = await helper.eth.createAccountWithBalance(alice);232 const sponsor = await helper.eth.createAccountWithBalance(donor);
223 const collectionEvm = helper.ethNativeContract.collection(collectionIdAddress, 'nft', owner);233 const collectionEvm = helper.ethNativeContract.collection(collectionIdAddress, 'nft', owner);
224234
225 result = await collectionEvm.methods.setCollectionSponsor(sponsor).send();235 result = await collectionEvm.methods.setCollectionSponsor(sponsor).send();
226 let collectionData = (await collection.getData())!;236 let collectionData = (await collection.getData())!;
227 const ss58Format = helper.chain.getChainProperties().ss58Format;
228 expect(collectionData.raw.sponsorship.Unconfirmed).to.be.eq(evmToAddress(sponsor, Number(ss58Format)));237 expect(collectionData.raw.sponsorship.Unconfirmed).to.be.eq(helper.address.ethToSubstrate(sponsor));
229 await expect(collectionEvm.methods.confirmCollectionSponsorship().call()).to.be.rejectedWith('caller is not set as sponsor');238 await expect(collectionEvm.methods.confirmCollectionSponsorship().call()).to.be.rejectedWith('caller is not set as sponsor');
230239
231 const sponsorCollection = helper.ethNativeContract.collection(collectionIdAddress, 'nft', sponsor);240 const sponsorCollection = helper.ethNativeContract.collection(collectionIdAddress, 'nft', sponsor);
232 await sponsorCollection.methods.confirmCollectionSponsorship().send();241 await sponsorCollection.methods.confirmCollectionSponsorship().send();
233 collectionData = (await collection.getData())!;242 collectionData = (await collection.getData())!;
234 expect(collectionData.raw.sponsorship.Confirmed).to.be.eq(evmToAddress(sponsor, Number(ss58Format)));243 expect(collectionData.raw.sponsorship.Confirmed).to.be.eq(helper.address.ethToSubstrate(sponsor));
235244
236 const user = helper.eth.createAccount();245 const user = helper.eth.createAccount();
237 await collectionEvm.methods.addCollectionAdmin(user).send();246 await collectionEvm.methods.addCollectionAdmin(user).send();
238 247
239 const ownerBalanceBefore = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(owner));248 const ownerBalanceBefore = await helper.balance.getSubstrate(helper.address.ethToSubstrate(owner));
240 const sponsorBalanceBefore = await helper.balance.getSubstrate(await helper.address.ethToSubstrate(sponsor));249 const sponsorBalanceBefore = await helper.balance.getSubstrate(helper.address.ethToSubstrate(sponsor));
241250
242 const userCollectionEvm = helper.ethNativeContract.collection(collectionIdAddress, 'nft', user);251 const userCollectionEvm = helper.ethNativeContract.collection(collectionIdAddress, 'nft', user);
243 const nextTokenId = await userCollectionEvm.methods.nextTokenId().call();252 const nextTokenId = await userCollectionEvm.methods.nextTokenId().call();
249 ).send();258 ).send();
250259
251 const events = normalizeEvents(result.events);260 const events = normalizeEvents(result.events);
252 const address = collectionIdToAddress(collectionId);261 const address = helper.ethAddress.fromCollectionId(collectionId);
253262
254 expect(events).to.be.deep.equal([263 expect(events).to.be.deep.equal([
255 {264 {