From 5a7505aa2f8fc598aeef85ba6a691b4ad1f414cc Mon Sep 17 00:00:00 2001 From: Trubnikov Sergey Date: Thu, 08 Sep 2022 15:05:29 +0000 Subject: [PATCH] refactor: Move tests to playgrounds. --- --- a/tests/src/eth/allowlist.test.ts +++ b/tests/src/eth/allowlist.test.ts @@ -14,8 +14,9 @@ // You should have received a copy of the GNU General Public License // along with Unique Network. If not, see . +import {IKeyringPair} from '@polkadot/types/types'; import {expect} from 'chai'; -import {isAllowlisted} from '../util/helpers'; +import {isAllowlisted, normalizeAccountId} from '../util/helpers'; import { contractHelpers, createEthAccount, @@ -26,6 +27,7 @@ getCollectionAddressFromResult, itWeb3, } from './util/helpers'; +import {itEth, usingEthPlaygrounds} from './util/playgrounds'; describe('EVM contract allowlist', () => { itWeb3('Contract allowlist can be toggled', async ({api, web3, privateKeyWrapper}) => { @@ -70,14 +72,20 @@ }); describe('EVM collection allowlist', () => { - itWeb3('Collection allowlist can be added and removed by [eth] address', async ({api, web3, privateKeyWrapper}) => { - const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper); - const user = createEthAccount(web3); + let donor: IKeyringPair; + + before(async function() { + await usingEthPlaygrounds(async (_helper, privateKey) => { + donor = privateKey('//Alice'); + }); + }); + + itEth('Collection allowlist can be added and removed by [eth] address', async ({helper}) => { + const owner = await helper.eth.createAccountWithBalance(donor); + const user = helper.eth.createAccount(); - const collectionHelpers = evmCollectionHelpers(web3, owner); - const result = await collectionHelpers.methods.createNonfungibleCollection('Sponsor collection', '1', '1').send(); - const {collectionIdAddress} = await getCollectionAddressFromResult(api, result); - const collectionEvm = evmCollection(web3, owner, collectionIdAddress); + const {collectionAddress} = await helper.eth.createNonfungibleCollection(owner, 'A', 'B', 'C'); + const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner); expect(await collectionEvm.methods.allowed(user).call({from: owner})).to.be.false; await collectionEvm.methods.addToCollectionAllowList(user).send({from: owner}); @@ -87,32 +95,28 @@ expect(await collectionEvm.methods.allowed(user).call({from: owner})).to.be.false; }); - itWeb3('Collection allowlist can be added and removed by [sub] address', async ({api, web3, privateKeyWrapper}) => { - const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper); - const user = privateKeyWrapper('//Alice'); + itEth('Collection allowlist can be added and removed by [sub] address', async ({helper}) => { + const owner = await helper.eth.createAccountWithBalance(donor); + const user = donor; - const collectionHelpers = evmCollectionHelpers(web3, owner); - const result = await collectionHelpers.methods.createNonfungibleCollection('Sponsor collection', '1', '1').send(); - const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result); - const collectionEvm = evmCollection(web3, owner, collectionIdAddress); + const {collectionAddress, collectionId} = await helper.eth.createNonfungibleCollection(owner, 'A', 'B', 'C'); + const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner); - expect(await isAllowlisted(api, collectionId, user)).to.be.false; + expect(await helper.collection.allowed(collectionId, {Substrate: user.address})).to.be.false; await collectionEvm.methods.addToCollectionAllowListSubstrate(user.addressRaw).send({from: owner}); - expect(await isAllowlisted(api, collectionId, user)).to.be.true; - + expect(await helper.collection.allowed(collectionId, {Substrate: user.address})).to.be.true; + await collectionEvm.methods.removeFromCollectionAllowListSubstrate(user.addressRaw).send({from: owner}); - expect(await isAllowlisted(api, collectionId, user)).to.be.false; + expect(await helper.collection.allowed(collectionId, {Substrate: user.address})).to.be.false; }); - itWeb3('Collection allowlist can not be add and remove [eth] address by not owner', async ({api, web3, privateKeyWrapper}) => { - const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper); - const notOwner = await createEthAccountWithBalance(api, web3, privateKeyWrapper); - const user = createEthAccount(web3); + itEth('Collection allowlist can not be add and remove [eth] address by not owner', async ({helper}) => { + const owner = await helper.eth.createAccountWithBalance(donor); + const notOwner = await helper.eth.createAccountWithBalance(donor); + const user = helper.eth.createAccount(); - const collectionHelpers = evmCollectionHelpers(web3, owner); - const result = await collectionHelpers.methods.createNonfungibleCollection('Sponsor collection', '1', '1').send(); - const {collectionIdAddress} = await getCollectionAddressFromResult(api, result); - const collectionEvm = evmCollection(web3, owner, collectionIdAddress); + const {collectionAddress} = await helper.eth.createNonfungibleCollection(owner, 'A', 'B', 'C'); + const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner); expect(await collectionEvm.methods.allowed(user).call({from: owner})).to.be.false; await expect(collectionEvm.methods.addToCollectionAllowList(user).call({from: notOwner})).to.be.rejectedWith('NoPermission'); @@ -124,23 +128,21 @@ expect(await collectionEvm.methods.allowed(user).call({from: owner})).to.be.true; }); - itWeb3('Collection allowlist can not be add and remove [sub] address by not owner', async ({api, web3, privateKeyWrapper}) => { - const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper); - const notOwner = await createEthAccountWithBalance(api, web3, privateKeyWrapper); - const user = privateKeyWrapper('//Alice'); + itEth('Collection allowlist can not be add and remove [sub] address by not owner', async ({helper}) => { + const owner = await helper.eth.createAccountWithBalance(donor); + const notOwner = await helper.eth.createAccountWithBalance(donor); + const user = donor; - const collectionHelpers = evmCollectionHelpers(web3, owner); - const result = await collectionHelpers.methods.createNonfungibleCollection('Sponsor collection', '1', '1').send(); - const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result); - const collectionEvm = evmCollection(web3, owner, collectionIdAddress); + const {collectionAddress, collectionId} = await helper.eth.createNonfungibleCollection(owner, 'A', 'B', 'C'); + const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner); - expect(await isAllowlisted(api, collectionId, user)).to.be.false; + expect(await helper.collection.allowed(collectionId, {Substrate: user.address})).to.be.false; await expect(collectionEvm.methods.addToCollectionAllowListSubstrate(user.addressRaw).call({from: notOwner})).to.be.rejectedWith('NoPermission'); - expect(await isAllowlisted(api, collectionId, user)).to.be.false; + expect(await helper.collection.allowed(collectionId, {Substrate: user.address})).to.be.false; await collectionEvm.methods.addToCollectionAllowListSubstrate(user.addressRaw).send({from: owner}); - expect(await isAllowlisted(api, collectionId, user)).to.be.true; + expect(await helper.collection.allowed(collectionId, {Substrate: user.address})).to.be.true; await expect(collectionEvm.methods.removeFromCollectionAllowListSubstrate(user.addressRaw).call({from: notOwner})).to.be.rejectedWith('NoPermission'); - expect(await isAllowlisted(api, collectionId, user)).to.be.true; + expect(await helper.collection.allowed(collectionId, {Substrate: user.address})).to.be.true; }); }); --- 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 { + 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 -- gitstuff