git.delta.rocks / unique-network / refs/commits / 9668fc5ff8f9

difftreelog

Make allowlist tests a bit more generic

Max Andreev2022-12-16parent: #466ab31.patch.diff
in: master

1 file changed

modifiedtests/src/eth/allowlist.test.tsdiffbeforeafterboth
15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
1616
17import {IKeyringPair} from '@polkadot/types/types';17import {IKeyringPair} from '@polkadot/types/types';
18import {Pallets} from '../util';
18import {itEth, usingEthPlaygrounds, expect} from './util';19import {itEth, usingEthPlaygrounds, expect} from './util';
1920
20describe('EVM contract allowlist', () => {21describe('EVM contract allowlist', () => {
92 });93 });
9394
95
96 [
97 {mode: 'nft' as const, requiredPallets: []},
98 {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},
99 {mode: 'ft' as const, requiredPallets: []},
100 ].map(testCase =>
94 itEth('Collection allowlist can be added and removed by [cross] address', async ({helper}) => {101 itEth(`Collection allowlist can be added and removed by [cross] address fro ${testCase.mode}`, async ({helper}) => {
95 const owner = (await helper.eth.createAccountWithBalance(donor)).toLowerCase();102 const owner = (await helper.eth.createAccountWithBalance(donor)).toLowerCase();
96 const [userSub] = await helper.arrange.createAccounts([10n], donor);103 const [userSub] = await helper.arrange.createAccounts([10n], donor);
97 const userEth = await helper.eth.createAccountWithBalance(donor);104 const userEth = await helper.eth.createAccountWithBalance(donor);
98 105 const mintParams = testCase.mode === 'ft' ? [userEth, 100] : [userEth];
106
99 const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');107 const {collectionAddress, collectionId} = await helper.eth.createCollection(testCase.mode, owner, 'A', 'B', 'C');
100 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);108 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, testCase.mode, owner);
101 const userCrossSub = helper.ethCrossAccount.fromKeyringPair(userSub);109 const userCrossSub = helper.ethCrossAccount.fromKeyringPair(userSub);
102 const userCrossEth = helper.ethCrossAccount.fromAddress(userEth);110 const userCrossEth = helper.ethCrossAccount.fromAddress(userEth);
103 const ownerCrossEth = helper.ethCrossAccount.fromAddress(owner);111 const ownerCrossEth = helper.ethCrossAccount.fromAddress(owner);
108 await collectionEvm.methods.addToCollectionAllowListCross(userCrossEth).send({from: owner});116 await collectionEvm.methods.addToCollectionAllowListCross(userCrossEth).send({from: owner});
109 await collectionEvm.methods.addToCollectionAllowListCross(ownerCrossEth).send({from: owner});117 await collectionEvm.methods.addToCollectionAllowListCross(ownerCrossEth).send({from: owner});
118
119 // Accounts are in allowed list:
110 expect(await helper.collection.allowed(collectionId, {Substrate: userSub.address})).to.be.true;120 expect(await helper.collection.allowed(collectionId, {Substrate: userSub.address})).to.be.true;
111 expect(await helper.collection.allowed(collectionId, {Ethereum: userEth})).to.be.true;121 expect(await helper.collection.allowed(collectionId, {Ethereum: userEth})).to.be.true;
112 expect(await collectionEvm.methods.allowlistedCross(userCrossSub).call({from: owner})).to.be.true;122 expect(await collectionEvm.methods.allowlistedCross(userCrossSub).call({from: owner})).to.be.true;
113 expect(await collectionEvm.methods.allowlistedCross(userCrossEth).call({from: owner})).to.be.true;123 expect(await collectionEvm.methods.allowlistedCross(userCrossEth).call({from: owner})).to.be.true;
114124
115 await collectionEvm.methods.mint(userEth).send(); // token #1125 await collectionEvm.methods.mint(...mintParams).send({from: owner}); // token #1
116 await collectionEvm.methods.mint(userEth).send(); // token #2126 await collectionEvm.methods.mint(...mintParams).send({from: owner}); // token #2
117 await collectionEvm.methods.setCollectionAccess(1).send();127 await collectionEvm.methods.setCollectionAccess(1 /* AllowList */).send({from: owner});
118 128
119 // allowlisted account can transfer and transferCross:129 // allowlisted account can transfer and transferCross from eth:
120 await collectionEvm.methods.transfer(owner, 1).send({from: userEth});130 await collectionEvm.methods.transfer(owner, 1).send({from: userEth});
121 await collectionEvm.methods.transferCross(userCrossSub, 2).send({from: userEth});131 await collectionEvm.methods.transferCross(userCrossSub, 2).send({from: userEth});
132
133 if (testCase.mode === 'ft') {
134 expect(await helper.ft.getBalance(collectionId, {Ethereum: owner})).to.eq(1n);
135 expect(await helper.ft.getBalance(collectionId, {Substrate: userSub.address})).to.eq(2n);
136 } else {
122 expect(await helper.nft.getTokenOwner(collectionId, 1)).to.deep.eq({Ethereum: owner});137 expect(await helper.nft.getTokenOwner(collectionId, 1)).to.deep.eq({Ethereum: owner});
123 expect(await helper.nft.getTokenOwner(collectionId, 2)).to.deep.eq({Substrate: userSub.address});138 expect(await helper.nft.getTokenOwner(collectionId, 2)).to.deep.eq({Substrate: userSub.address});
124 139 }
140
141 // allowlisted cross substrate accounts can transfer from Substrate:
142 testCase.mode === 'ft'
143 ? await helper.ft.transfer(userSub, collectionId, {Ethereum: userEth}, 2n)
144 : await helper.collection.transferToken(userSub, collectionId, 2, {Ethereum: userEth});
145
125 // can removeFromCollectionAllowListCross:146 // can removeFromCollectionAllowListCross:
126 await collectionEvm.methods.removeFromCollectionAllowListCross(userCrossSub).send({from: owner});147 await collectionEvm.methods.removeFromCollectionAllowListCross(userCrossSub).send({from: owner});
131 expect(await collectionEvm.methods.allowlistedCross(userCrossEth).call({from: owner})).to.be.false;152 expect(await collectionEvm.methods.allowlistedCross(userCrossEth).call({from: owner})).to.be.false;
132153
133 // cannot transfer anymore154 // cannot transfer anymore
134 await collectionEvm.methods.mint(userEth).send();155 await collectionEvm.methods.mint(...mintParams).send({from: owner});
135 await expect(collectionEvm.methods.transfer(owner, 2).send({from: userEth})).to.be.rejectedWith(/Transaction has been reverted/);156 await expect(collectionEvm.methods.transfer(owner, 2).send({from: userEth})).to.be.rejectedWith(/Transaction has been reverted/);
136 });157 }));
137158
138 // Soft-deprecated159 // Soft-deprecated
139 itEth('Collection allowlist can not be add and remove [eth] address by not owner', async ({helper}) => {160 itEth('Collection allowlist can not be add and remove [eth] address by not owner', async ({helper}) => {