difftreelog
Make remove from allow list tests a bit more generic
in: master
1 file changed
tests/src/eth/allowlist.test.tsdiffbeforeafterboth161617import {IKeyringPair} from '@polkadot/types/types';17import {IKeyringPair} from '@polkadot/types/types';18import {Pallets} from '../util';18import {Pallets} from '../util';19import {itEth, usingEthPlaygrounds, expect} from './util';19import {itEth, usingEthPlaygrounds, expect, SponsoringMode} from './util';202021describe('EVM contract allowlist', () => {21describe('EVM contract allowlist', () => {22 let donor: IKeyringPair;22 let donor: IKeyringPair;98 {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},98 {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},99 {mode: 'ft' as const, requiredPallets: []},99 {mode: 'ft' as const, requiredPallets: []},100 ].map(testCase => 100 ].map(testCase => 101 itEth(`Collection allowlist can be added and removed by [cross] address fro ${testCase.mode}`, async ({helper}) => {101 itEth(`Collection allowlist can be added and removed by [cross] address for ${testCase.mode}`, async ({helper}) => {102 const owner = (await helper.eth.createAccountWithBalance(donor)).toLowerCase();102 const owner = (await helper.eth.createAccountWithBalance(donor)).toLowerCase();103 const [userSub] = await helper.arrange.createAccounts([10n], donor);103 const [userSub] = await helper.arrange.createAccounts([10n], donor);104 const userEth = await helper.eth.createAccountWithBalance(donor);104 const userEth = await helper.eth.createAccountWithBalance(donor);124 124 125 await collectionEvm.methods.mint(...mintParams).send({from: owner}); // token #1125 await collectionEvm.methods.mint(...mintParams).send({from: owner}); // token #1126 await collectionEvm.methods.mint(...mintParams).send({from: owner}); // token #2126 await collectionEvm.methods.mint(...mintParams).send({from: owner}); // token #2127 await collectionEvm.methods.setCollectionAccess(1 /* AllowList */).send({from: owner});127 await collectionEvm.methods.setCollectionAccess(SponsoringMode.Allowlisted).send({from: owner});128 128 129 // allowlisted account can transfer and transferCross from eth:129 // allowlisted account can transfer and transferCross from eth:130 await collectionEvm.methods.transfer(owner, 1).send({from: userEth});130 await collectionEvm.methods.transfer(owner, 1).send({from: userEth});157 }));157 }));158158159 // Soft-deprecated159 // Soft-deprecated160 itEth('Collection allowlist can not be add and remove [eth] address by not owner', async ({helper}) => {160 itEth('Collection allowlist cannot be added and removed [eth] address by not owner', async ({helper}) => {161 const owner = await helper.eth.createAccountWithBalance(donor);161 const owner = await helper.eth.createAccountWithBalance(donor);162 const notOwner = await helper.eth.createAccountWithBalance(donor);162 const notOwner = await helper.eth.createAccountWithBalance(donor);163 const user = helper.eth.createAccount();163 const user = helper.eth.createAccount();175 expect(await collectionEvm.methods.allowlistedCross(crossUser).call({from: owner})).to.be.true;175 expect(await collectionEvm.methods.allowlistedCross(crossUser).call({from: owner})).to.be.true;176 });176 });177177178 [179 // cross-methods180 {mode: 'nft' as const, cross: true, requiredPallets: []},181 {mode: 'rft' as const, cross: true, requiredPallets: [Pallets.ReFungible]},182 {mode: 'ft' as const, cross: true, requiredPallets: []},183 // soft-deprecated184 {mode: 'nft' as const, cross: false, requiredPallets: []},185 {mode: 'rft' as const, cross: false, requiredPallets: [Pallets.ReFungible]},186 {mode: 'ft' as const, cross: false, requiredPallets: []},187 ].map(testCase => 178 itEth('Collection allowlist can not be add and remove [cross] address by not owner', async ({helper}) => {188 itEth.only(`Collection allowlist can not be add and remove [cross] address by non-owner for ${testCase.mode}`, async ({helper}) => {189 // Select methods:190 const addToAllowList = testCase.cross ? 'addToCollectionAllowListCross' : 'addToCollectionAllowList';191 const removeFromAllowList = testCase.cross ? 'removeFromCollectionAllowListCross' : 'removeFromCollectionAllowList';192179 const owner = await helper.eth.createAccountWithBalance(donor);193 const owner = await helper.eth.createAccountWithBalance(donor);180 const notOwner = await helper.eth.createAccountWithBalance(donor);194 const notOwner = await helper.eth.createAccountWithBalance(donor);181 const user = donor;195 const userSub = donor;182 196 const userCrossSub = helper.ethCrossAccount.fromKeyringPair(userSub);197 const userEth = helper.eth.createAccount();198 const userCrossEth = helper.ethCrossAccount.fromAddress(userEth);199183 const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');200 const {collectionAddress, collectionId} = await helper.eth.createCollection(testCase.mode, owner, 'A', 'B', 'C');184 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);201 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, testCase.mode, owner, !testCase.cross);185 202 186 expect(await helper.collection.allowed(collectionId, {Substrate: user.address})).to.be.false;203 expect(await helper.collection.allowed(collectionId, {Substrate: userSub.address})).to.be.false;187 const userCross = helper.ethCrossAccount.fromKeyringPair(user);204 expect(await helper.collection.allowed(collectionId, {Ethereum: userEth})).to.be.false;205 206 // 1. notOwner cannot add to allow list:207 // 1.1 plain ethereum or cross address:188 await expect(collectionEvm.methods.addToCollectionAllowListCross(userCross).call({from: notOwner})).to.be.rejectedWith('NoPermission');208 await expect(collectionEvm.methods[addToAllowList](testCase.cross ? userCrossEth : userEth).call({from: notOwner})).to.be.rejectedWith('NoPermission');209 // 1.2 cross-substrate address:210 if (testCase.cross)189 expect(await helper.collection.allowed(collectionId, {Substrate: user.address})).to.be.false;211 await expect(collectionEvm.methods[addToAllowList](userCrossSub).call({from: notOwner})).to.be.rejectedWith('NoPermission');212213 // 2. owner can add to allow list:214 // 2.1 plain ethereum or cross address:190 await collectionEvm.methods.addToCollectionAllowListCross(userCross).send({from: owner});215 await collectionEvm.methods[addToAllowList](testCase.cross ? userCrossEth : userEth).send({from: owner});191 216 // 2.2 cross-substrate address:217 if (testCase.cross) {218 await collectionEvm.methods[addToAllowList](userCrossSub).send({from: owner});192 expect(await helper.collection.allowed(collectionId, {Substrate: user.address})).to.be.true;219 expect(await helper.collection.allowed(collectionId, {Substrate: userSub.address})).to.be.true;220 }221 expect(await helper.collection.allowed(collectionId, {Ethereum: userEth})).to.be.true;222 223 // 3. notOwner cannot remove from allow list:224 // 3.1 plain ethereum or cross address:193 await expect(collectionEvm.methods.removeFromCollectionAllowListCross(userCross).call({from: notOwner})).to.be.rejectedWith('NoPermission');225 await expect(collectionEvm.methods[removeFromAllowList](testCase.cross ? userCrossEth : userEth).call({from: notOwner})).to.be.rejectedWith('NoPermission');226 // 3.2 cross-substrate address:227 if (testCase.cross)194 expect(await helper.collection.allowed(collectionId, {Substrate: user.address})).to.be.true;228 await expect(collectionEvm.methods[removeFromAllowList](userCrossSub).call({from: notOwner})).to.be.rejectedWith('NoPermission');195 });229 }));196});230});197231