1234567891011121314151617import {IKeyringPair} from '@polkadot/types/types';18import {itEth, usingEthPlaygrounds, expect} from './util';1920describe('EVM contract allowlist', () => {21 let donor: IKeyringPair;2223 before(async function() {24 await usingEthPlaygrounds(async (_helper, privateKey) => {25 donor = await privateKey({filename: __filename});26 });27 });2829 itEth('Contract allowlist can be toggled', async ({helper}) => {30 const owner = await helper.eth.createAccountWithBalance(donor);31 const flipper = await helper.eth.deployFlipper(owner);32 const helpers = helper.ethNativeContract.contractHelpers(owner);3334 35 expect(await helpers.methods.allowlistEnabled(flipper.options.address).call()).to.be.false;3637 38 await helpers.methods.toggleAllowlist(flipper.options.address, true).send({from: owner});39 expect(await helpers.methods.allowlistEnabled(flipper.options.address).call()).to.be.true;4041 42 await helpers.methods.toggleAllowlist(flipper.options.address, false).send({from: owner});43 expect(await helpers.methods.allowlistEnabled(flipper.options.address).call()).to.be.false;44 });4546 itEth('Non-allowlisted user can\'t call contract with allowlist enabled', async ({helper}) => {47 const owner = await helper.eth.createAccountWithBalance(donor);48 const caller = await helper.eth.createAccountWithBalance(donor);49 const flipper = await helper.eth.deployFlipper(owner);50 const helpers = helper.ethNativeContract.contractHelpers(owner);5152 53 await flipper.methods.flip().send({from: caller});54 expect(await flipper.methods.getValue().call()).to.be.true;5556 57 await helpers.methods.toggleAllowlist(flipper.options.address, true).send({from: owner});58 await expect(flipper.methods.flip().send({from: caller})).to.rejected;59 expect(await flipper.methods.getValue().call()).to.be.true;6061 62 await helpers.methods.toggleAllowed(flipper.options.address, caller, true).send({from: owner});63 await flipper.methods.flip().send({from: caller});64 expect(await flipper.methods.getValue().call()).to.be.false;65 });66});6768describe('EVM collection allowlist', () => {69 let donor: IKeyringPair;7071 before(async function() {72 await usingEthPlaygrounds(async (_helper, privateKey) => {73 donor = await privateKey({filename: __filename});74 });75 });7677 itEth('Collection allowlist can be added and removed by [eth] address', async ({helper}) => {78 const owner = await helper.eth.createAccountWithBalance(donor);79 const user = helper.eth.createAccount();8081 const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');82 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);8384 expect(await collectionEvm.methods.allowed(user).call({from: owner})).to.be.false;85 await collectionEvm.methods.addToCollectionAllowList(user).send({from: owner});86 expect(await collectionEvm.methods.allowed(user).call({from: owner})).to.be.true;8788 await collectionEvm.methods.removeFromCollectionAllowList(user).send({from: owner});89 expect(await collectionEvm.methods.allowed(user).call({from: owner})).to.be.false;90 });9192 itEth('Collection allowlist can be added and removed by [cross] address', async ({helper}) => {93 const owner = await helper.eth.createAccountWithBalance(donor);94 const user = donor;95 96 const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');97 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);98 const userCross = helper.ethCrossAccount.fromKeyringPair(user);99 100 expect(await helper.collection.allowed(collectionId, {Substrate: user.address})).to.be.false;101 await collectionEvm.methods.addToCollectionAllowListCross(userCross).send({from: owner});102 expect(await helper.collection.allowed(collectionId, {Substrate: user.address})).to.be.true;103 104 await collectionEvm.methods.removeFromCollectionAllowListCross(userCross).send({from: owner});105 expect(await helper.collection.allowed(collectionId, {Substrate: user.address})).to.be.false;106 });107108 itEth('Collection allowlist can not be add and remove [eth] address by not owner', async ({helper}) => {109 const owner = await helper.eth.createAccountWithBalance(donor);110 const notOwner = await helper.eth.createAccountWithBalance(donor);111 const user = helper.eth.createAccount();112113 const {collectionAddress} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');114 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);115116 expect(await collectionEvm.methods.allowed(user).call({from: owner})).to.be.false;117 await expect(collectionEvm.methods.addToCollectionAllowList(user).call({from: notOwner})).to.be.rejectedWith('NoPermission');118 expect(await collectionEvm.methods.allowed(user).call({from: owner})).to.be.false;119 await collectionEvm.methods.addToCollectionAllowList(user).send({from: owner});120 expect(await collectionEvm.methods.allowed(user).call({from: owner})).to.be.true;121 await expect(collectionEvm.methods.removeFromCollectionAllowList(user).call({from: notOwner})).to.be.rejectedWith('NoPermission');122 expect(await collectionEvm.methods.allowed(user).call({from: owner})).to.be.true;123 });124125 itEth('Collection allowlist can not be add and remove [cross] address by not owner', async ({helper}) => {126 const owner = await helper.eth.createAccountWithBalance(donor);127 const notOwner = await helper.eth.createAccountWithBalance(donor);128 const user = donor;129 130 const {collectionAddress, collectionId} = await helper.eth.createNFTCollection(owner, 'A', 'B', 'C');131 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);132 133 expect(await helper.collection.allowed(collectionId, {Substrate: user.address})).to.be.false;134 const userCross = helper.ethCrossAccount.fromKeyringPair(user);135 await expect(collectionEvm.methods.addToCollectionAllowListCross(userCross).call({from: notOwner})).to.be.rejectedWith('NoPermission');136 expect(await helper.collection.allowed(collectionId, {Substrate: user.address})).to.be.false;137 await collectionEvm.methods.addToCollectionAllowListCross(userCross).send({from: owner});138 139 expect(await helper.collection.allowed(collectionId, {Substrate: user.address})).to.be.true;140 await expect(collectionEvm.methods.removeFromCollectionAllowListCross(userCross).call({from: notOwner})).to.be.rejectedWith('NoPermission');141 expect(await helper.collection.allowed(collectionId, {Substrate: user.address})).to.be.true;142 });143});