difftreelog
Make allowlist tests a bit more generic
in: master
1 file changed
tests/src/eth/allowlist.test.tsdiffbeforeafterboth15// 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/>.161617import {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';192020describe('EVM contract allowlist', () => {21describe('EVM contract allowlist', () => {92 });93 });93949596 [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});118119 // 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 #1116 await collectionEvm.methods.mint(userEth).send(); // token #2126 await collectionEvm.methods.mint(...mintParams).send({from: owner}); // token #2117 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});132133 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 }140141 // 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 anymore134 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 }));137158138 // Soft-deprecated159 // Soft-deprecated139 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}) => {