difftreelog
refactor Move tests to playgrounds.
in: master
2 files changed
tests/src/eth/allowlist.test.tsdiffbeforeafterboth14// You should have received a copy of the GNU General Public License14// You should have received a copy of the GNU General Public License15// 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 {expect} from 'chai';18import {expect} from 'chai';18import {isAllowlisted} from '../util/helpers';19import {isAllowlisted, normalizeAccountId} from '../util/helpers';19import {20import {20 contractHelpers,21 contractHelpers,21 createEthAccount,22 createEthAccount,26 getCollectionAddressFromResult,27 getCollectionAddressFromResult,27 itWeb3,28 itWeb3,28} from './util/helpers';29} from './util/helpers';30import {itEth, usingEthPlaygrounds} from './util/playgrounds';293130describe('EVM contract allowlist', () => {32describe('EVM contract allowlist', () => {31 itWeb3('Contract allowlist can be toggled', async ({api, web3, privateKeyWrapper}) => {33 itWeb3('Contract allowlist can be toggled', async ({api, web3, privateKeyWrapper}) => {70});72});717372describe('EVM collection allowlist', () => {74describe('EVM collection allowlist', () => {75 let donor: IKeyringPair;7677 before(async function() {78 await usingEthPlaygrounds(async (_helper, privateKey) => {79 donor = privateKey('//Alice');80 });81 });82 73 itWeb3('Collection allowlist can be added and removed by [eth] address', async ({api, web3, privateKeyWrapper}) => {83 itEth('Collection allowlist can be added and removed by [eth] address', async ({helper}) => {74 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);84 const owner = await helper.eth.createAccountWithBalance(donor);75 const user = createEthAccount(web3);85 const user = helper.eth.createAccount();76 86 77 const collectionHelpers = evmCollectionHelpers(web3, owner);78 const result = await collectionHelpers.methods.createNonfungibleCollection('Sponsor collection', '1', '1').send();87 const {collectionAddress} = await helper.eth.createNonfungibleCollection(owner, 'A', 'B', 'C');79 const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);80 const collectionEvm = evmCollection(web3, owner, collectionIdAddress);88 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);81 89 82 expect(await collectionEvm.methods.allowed(user).call({from: owner})).to.be.false;90 expect(await collectionEvm.methods.allowed(user).call({from: owner})).to.be.false;83 await collectionEvm.methods.addToCollectionAllowList(user).send({from: owner});91 await collectionEvm.methods.addToCollectionAllowList(user).send({from: owner});87 expect(await collectionEvm.methods.allowed(user).call({from: owner})).to.be.false;95 expect(await collectionEvm.methods.allowed(user).call({from: owner})).to.be.false;88 });96 });899790 itWeb3('Collection allowlist can be added and removed by [sub] address', async ({api, web3, privateKeyWrapper}) => {98 itEth('Collection allowlist can be added and removed by [sub] address', async ({helper}) => {91 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);99 const owner = await helper.eth.createAccountWithBalance(donor);92 const user = privateKeyWrapper('//Alice');100 const user = donor;93 101 94 const collectionHelpers = evmCollectionHelpers(web3, owner);95 const result = await collectionHelpers.methods.createNonfungibleCollection('Sponsor collection', '1', '1').send();102 const {collectionAddress, collectionId} = await helper.eth.createNonfungibleCollection(owner, 'A', 'B', 'C');96 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);97 const collectionEvm = evmCollection(web3, owner, collectionIdAddress);103 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);98 104 99 expect(await isAllowlisted(api, collectionId, user)).to.be.false;105 expect(await helper.collection.allowed(collectionId, {Substrate: user.address})).to.be.false;100 await collectionEvm.methods.addToCollectionAllowListSubstrate(user.addressRaw).send({from: owner});106 await collectionEvm.methods.addToCollectionAllowListSubstrate(user.addressRaw).send({from: owner});101 expect(await isAllowlisted(api, collectionId, user)).to.be.true;107 expect(await helper.collection.allowed(collectionId, {Substrate: user.address})).to.be.true;102108 103 await collectionEvm.methods.removeFromCollectionAllowListSubstrate(user.addressRaw).send({from: owner});109 await collectionEvm.methods.removeFromCollectionAllowListSubstrate(user.addressRaw).send({from: owner});104 expect(await isAllowlisted(api, collectionId, user)).to.be.false;110 expect(await helper.collection.allowed(collectionId, {Substrate: user.address})).to.be.false;105 });111 });106112107 itWeb3('Collection allowlist can not be add and remove [eth] address by not owner', async ({api, web3, privateKeyWrapper}) => {113 itEth('Collection allowlist can not be add and remove [eth] address by not owner', async ({helper}) => {108 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);114 const owner = await helper.eth.createAccountWithBalance(donor);109 const notOwner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);115 const notOwner = await helper.eth.createAccountWithBalance(donor);110 const user = createEthAccount(web3);116 const user = helper.eth.createAccount();111 117 112 const collectionHelpers = evmCollectionHelpers(web3, owner);113 const result = await collectionHelpers.methods.createNonfungibleCollection('Sponsor collection', '1', '1').send();118 const {collectionAddress} = await helper.eth.createNonfungibleCollection(owner, 'A', 'B', 'C');114 const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);115 const collectionEvm = evmCollection(web3, owner, collectionIdAddress);119 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);116 120 117 expect(await collectionEvm.methods.allowed(user).call({from: owner})).to.be.false;121 expect(await collectionEvm.methods.allowed(user).call({from: owner})).to.be.false;118 await expect(collectionEvm.methods.addToCollectionAllowList(user).call({from: notOwner})).to.be.rejectedWith('NoPermission');122 await expect(collectionEvm.methods.addToCollectionAllowList(user).call({from: notOwner})).to.be.rejectedWith('NoPermission');124 expect(await collectionEvm.methods.allowed(user).call({from: owner})).to.be.true;128 expect(await collectionEvm.methods.allowed(user).call({from: owner})).to.be.true;125 });129 });126130127 itWeb3('Collection allowlist can not be add and remove [sub] address by not owner', async ({api, web3, privateKeyWrapper}) => {131 itEth('Collection allowlist can not be add and remove [sub] address by not owner', async ({helper}) => {128 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);132 const owner = await helper.eth.createAccountWithBalance(donor);129 const notOwner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);133 const notOwner = await helper.eth.createAccountWithBalance(donor);130 const user = privateKeyWrapper('//Alice');134 const user = donor;131 135 132 const collectionHelpers = evmCollectionHelpers(web3, owner);133 const result = await collectionHelpers.methods.createNonfungibleCollection('Sponsor collection', '1', '1').send();136 const {collectionAddress, collectionId} = await helper.eth.createNonfungibleCollection(owner, 'A', 'B', 'C');134 const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);135 const collectionEvm = evmCollection(web3, owner, collectionIdAddress);137 const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);136 138 137 expect(await isAllowlisted(api, collectionId, user)).to.be.false;139 expect(await helper.collection.allowed(collectionId, {Substrate: user.address})).to.be.false;138 await expect(collectionEvm.methods.addToCollectionAllowListSubstrate(user.addressRaw).call({from: notOwner})).to.be.rejectedWith('NoPermission');140 await expect(collectionEvm.methods.addToCollectionAllowListSubstrate(user.addressRaw).call({from: notOwner})).to.be.rejectedWith('NoPermission');139 expect(await isAllowlisted(api, collectionId, user)).to.be.false;141 expect(await helper.collection.allowed(collectionId, {Substrate: user.address})).to.be.false;140 await collectionEvm.methods.addToCollectionAllowListSubstrate(user.addressRaw).send({from: owner});142 await collectionEvm.methods.addToCollectionAllowListSubstrate(user.addressRaw).send({from: owner});141 143 142 expect(await isAllowlisted(api, collectionId, user)).to.be.true;144 expect(await helper.collection.allowed(collectionId, {Substrate: user.address})).to.be.true;143 await expect(collectionEvm.methods.removeFromCollectionAllowListSubstrate(user.addressRaw).call({from: notOwner})).to.be.rejectedWith('NoPermission');145 await expect(collectionEvm.methods.removeFromCollectionAllowListSubstrate(user.addressRaw).call({from: notOwner})).to.be.rejectedWith('NoPermission');144 expect(await isAllowlisted(api, collectionId, user)).to.be.true;146 expect(await helper.collection.allowed(collectionId, {Substrate: user.address})).to.be.true;145 });147 });146});148});147149tests/src/util/playgrounds/unique.tsdiffbeforeafterboth--- a/tests/src/util/playgrounds/unique.ts
+++ b/tests/src/util/playgrounds/unique.ts
@@ -730,6 +730,18 @@
}
/**
+ * Check if user is in allow list.
+ *
+ * @param collectionId ID of collection
+ * @param user Account to check
+ * @example await getAdmins(1)
+ * @returns is user in allow list
+ */
+ async allowed(collectionId: number, user: ICrossAccountId): Promise<boolean> {
+ return (await this.helper.callRpc('api.rpc.unique.allowed', [collectionId, user])).toJSON();
+ }
+
+ /**
* Adds an address to allow list
* @param signer keyring of signer
* @param collectionId ID of collection