difftreelog
test Initial eth playgrounds
in: master
4 files changed
tests/package.jsondiffbeforeafterboth79 "testBlockProduction": "mocha --timeout 9999999 -r ts-node/register ./**/block-production.test.ts",79 "testBlockProduction": "mocha --timeout 9999999 -r ts-node/register ./**/block-production.test.ts",80 "testEnableDisableTransfers": "mocha --timeout 9999999 -r ts-node/register ./**/enableDisableTransfer.test.ts",80 "testEnableDisableTransfers": "mocha --timeout 9999999 -r ts-node/register ./**/enableDisableTransfer.test.ts",81 "testLimits": "mocha --timeout 9999999 -r ts-node/register ./**/limits.test.ts",81 "testLimits": "mocha --timeout 9999999 -r ts-node/register ./**/limits.test.ts",82 "testEthCreateNFTCollection": "mocha --timeout 9999999 -r ts-node/register ./**/eth/createNFTCollection.test.ts",82 "testEthCreateCollection": "mocha --timeout 9999999 -r ts-node/register ./**/eth/createCollection.test.ts",83 "testEthCreateRFTCollection": "mocha --timeout 9999999 -r ts-node/register ./**/eth/createRFTCollection.test.ts",83 "testRFT": "mocha --timeout 9999999 -r ts-node/register ./**/refungible.test.ts",84 "testRFT": "mocha --timeout 9999999 -r ts-node/register ./**/refungible.test.ts",84 "testFT": "mocha --timeout 9999999 -r ts-node/register ./**/fungible.test.ts",85 "testFT": "mocha --timeout 9999999 -r ts-node/register ./**/fungible.test.ts",85 "testRPC": "mocha --timeout 9999999 -r ts-node/register ./**/rpc.test.ts",86 "testRPC": "mocha --timeout 9999999 -r ts-node/register ./**/rpc.test.ts",tests/src/eth/nesting/nest.test.tsdiffbeforeafterboth1import {ApiPromise} from '@polkadot/api';1import {IKeyringPair} from '@polkadot/types/types';2import {Contract} from 'web3-eth-contract';2import {Contract} from 'web3-eth-contract';3import {expect} from 'chai';34import Web3 from 'web3';5import {createEthAccountWithBalance, evmCollectionHelpers, GAS_ARGS, getCollectionAddressFromResult, itWeb3, tokenIdToAddress} from '../../eth/util/helpers';4import {itEth, EthUniqueHelper, usingEthPlaygrounds, expect} from '../util/playgrounds'6import nonFungibleAbi from '../nonFungibleAbi.json';758const createNestingCollection = async (6const createNestingCollection = async (9 api: ApiPromise,7 helper: EthUniqueHelper,10 web3: Web3,11 owner: string,8 owner: string,12): Promise<{ collectionId: number, collectionAddress: string, contract: Contract }> => {9): Promise<{ collectionId: number, collectionAddress: string, contract: Contract }> => {13 const collectionHelper = evmCollectionHelpers(web3, owner);14 15 const result = await collectionHelper.methods10 const {collectionAddress, collectionId} = await helper.eth.createNonfungibleCollection(owner, 'A', 'B', 'C');16 .createNonfungibleCollection('A', 'B', 'C')17 .send();18 const {collectionIdAddress: collectionAddress, collectionId} = await getCollectionAddressFromResult(api, result);191120 const contract = new web3.eth.Contract(nonFungibleAbi as any, collectionAddress, {from: owner, ...GAS_ARGS});12 const contract = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);21 await contract.methods.setCollectionNesting(true).send({from: owner});13 await contract.methods.setCollectionNesting(true).send({from: owner});221423 return {collectionId, collectionAddress, contract};15 return {collectionId, collectionAddress, contract};24};16};251726describe('Integration Test: EVM Nesting', () => {27 itWeb3('NFT: allows an Owner to nest/unnest their token', async ({api, web3, privateKeyWrapper}) => {28 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);29 const {collectionId, contract} = await createNestingCollection(api, web3, owner);3031 // Create a token to be nested32 const targetNFTTokenId = await contract.methods.nextTokenId().call();33 await contract.methods.mint(34 owner,35 targetNFTTokenId,36 ).send({from: owner});3738 const targetNftTokenAddress = tokenIdToAddress(collectionId, targetNFTTokenId);3940 // Create a nested token41 const firstTokenId = await contract.methods.nextTokenId().call();42 await contract.methods.mint(43 targetNftTokenAddress,44 firstTokenId,45 ).send({from: owner});4647 expect(await contract.methods.ownerOf(firstTokenId).call()).to.be.equal(targetNftTokenAddress);4849 // Create a token to be nested and nest50 const secondTokenId = await contract.methods.nextTokenId().call();51 await contract.methods.mint(52 owner,53 secondTokenId,54 ).send({from: owner});5556 await contract.methods.transfer(targetNftTokenAddress, secondTokenId).send({from: owner});5758 expect(await contract.methods.ownerOf(secondTokenId).call()).to.be.equal(targetNftTokenAddress);5960 // Unnest token back61 await contract.methods.transferFrom(targetNftTokenAddress, owner, secondTokenId).send({from: owner});62 expect(await contract.methods.ownerOf(secondTokenId).call()).to.be.equal(owner);63 });6465 itWeb3('NFT: allows an Owner to nest/unnest their token (Restricted nesting)', async ({api, web3, privateKeyWrapper}) => {66 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);6768 const {collectionId: collectionIdA, collectionAddress: collectionAddressA, contract: contractA} = await createNestingCollection(api, web3, owner);69 const {collectionAddress: collectionAddressB, contract: contractB} = await createNestingCollection(api, web3, owner);70 await contractA.methods.setCollectionNesting(true, [collectionAddressA, collectionAddressB]).send({from: owner});7172 // Create a token to nest into73 const targetNftTokenId = await contractA.methods.nextTokenId().call();74 await contractA.methods.mint(75 owner,76 targetNftTokenId,77 ).send({from: owner});78 const nftTokenAddressA1 = tokenIdToAddress(collectionIdA, targetNftTokenId);7980 // Create a token for nesting in the same collection as the target81 const nftTokenIdA = await contractA.methods.nextTokenId().call();82 await contractA.methods.mint(83 owner,84 nftTokenIdA,85 ).send({from: owner});8687 // Create a token for nesting in a different collection88 const nftTokenIdB = await contractB.methods.nextTokenId().call();89 await contractB.methods.mint(90 owner,91 nftTokenIdB,92 ).send({from: owner});9394 // Nest95 await contractA.methods.transfer(nftTokenAddressA1, nftTokenIdA).send({from: owner});96 expect(await contractA.methods.ownerOf(nftTokenIdA).call()).to.be.equal(nftTokenAddressA1);9798 await contractB.methods.transfer(nftTokenAddressA1, nftTokenIdB).send({from: owner});99 expect(await contractB.methods.ownerOf(nftTokenIdB).call()).to.be.equal(nftTokenAddressA1);100 });101});10218103describe('Negative Test: EVM Nesting', async() => {19describe('EVM nesting tests group', () => {20 let donor: IKeyringPair;2122 before(async function() {23 await usingEthPlaygrounds(async (helper, privateKey) => {24 donor = privateKey('//Alice');25 });26 });2728 describe('Integration Test: EVM Nesting', () => {29 itEth('NFT: allows an Owner to nest/unnest their token', async ({helper}) => {30 const owner = await helper.eth.createAccountWithBalance(donor);31 const {collectionId, contract} = await createNestingCollection(helper, owner);32 33 // Create a token to be nested34 const targetNFTTokenId = await contract.methods.nextTokenId().call();35 await contract.methods.mint(36 owner,37 targetNFTTokenId,38 ).send({from: owner});39 40 const targetNftTokenAddress = helper.ethAddress.fromTokenId(collectionId, targetNFTTokenId);41 42 // Create a nested token43 const firstTokenId = await contract.methods.nextTokenId().call();44 await contract.methods.mint(45 targetNftTokenAddress,46 firstTokenId,47 ).send({from: owner});48 49 expect(await contract.methods.ownerOf(firstTokenId).call()).to.be.equal(targetNftTokenAddress);50 51 // Create a token to be nested and nest52 const secondTokenId = await contract.methods.nextTokenId().call();53 await contract.methods.mint(54 owner,55 secondTokenId,56 ).send({from: owner});57 58 await contract.methods.transfer(targetNftTokenAddress, secondTokenId).send({from: owner});59 60 expect(await contract.methods.ownerOf(secondTokenId).call()).to.be.equal(targetNftTokenAddress);61 62 // Unnest token back63 await contract.methods.transferFrom(targetNftTokenAddress, owner, secondTokenId).send({from: owner});64 expect(await contract.methods.ownerOf(secondTokenId).call()).to.be.equal(owner);65 });66 67 itEth('NFT: allows an Owner to nest/unnest their token (Restricted nesting)', async ({helper}) => {68 const owner = await helper.eth.createAccountWithBalance(donor);69 70 const {collectionId: collectionIdA, collectionAddress: collectionAddressA, contract: contractA} = await createNestingCollection(helper, owner);71 const {collectionAddress: collectionAddressB, contract: contractB} = await createNestingCollection(helper, owner);72 await contractA.methods.setCollectionNesting(true, [collectionAddressA, collectionAddressB]).send({from: owner});73 74 // Create a token to nest into75 const targetNftTokenId = await contractA.methods.nextTokenId().call();76 await contractA.methods.mint(77 owner,78 targetNftTokenId,79 ).send({from: owner});80 const nftTokenAddressA1 = helper.ethAddress.fromTokenId(collectionIdA, targetNftTokenId);81 82 // Create a token for nesting in the same collection as the target83 const nftTokenIdA = await contractA.methods.nextTokenId().call();84 await contractA.methods.mint(85 owner,86 nftTokenIdA,87 ).send({from: owner});88 89 // Create a token for nesting in a different collection90 const nftTokenIdB = await contractB.methods.nextTokenId().call();91 await contractB.methods.mint(92 owner,93 nftTokenIdB,94 ).send({from: owner});95 96 // Nest97 await contractA.methods.transfer(nftTokenAddressA1, nftTokenIdA).send({from: owner});98 expect(await contractA.methods.ownerOf(nftTokenIdA).call()).to.be.equal(nftTokenAddressA1);99 100 await contractB.methods.transfer(nftTokenAddressA1, nftTokenIdB).send({from: owner});101 expect(await contractB.methods.ownerOf(nftTokenIdB).call()).to.be.equal(nftTokenAddressA1);102 });103 });104105 describe('Negative Test: EVM Nesting', async() => {104 itWeb3('NFT: disallows to nest token if nesting is disabled', async ({api, web3, privateKeyWrapper}) => {106 itEth('NFT: disallows to nest token if nesting is disabled', async ({helper}) => {105 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);107 const owner = await helper.eth.createAccountWithBalance(donor);106108 107 const {collectionId, contract} = await createNestingCollection(api, web3, owner);109 const {collectionId, contract} = await createNestingCollection(helper, owner);108 await contract.methods.setCollectionNesting(false).send({from: owner});110 await contract.methods.setCollectionNesting(false).send({from: owner});109111 110 // Create a token to nest into112 // Create a token to nest into114 targetNftTokenId,116 targetNftTokenId,115 ).send({from: owner});117 ).send({from: owner});116118 117 const targetNftTokenAddress = tokenIdToAddress(collectionId, targetNftTokenId);119 const targetNftTokenAddress = helper.ethAddress.fromTokenId(collectionId, targetNftTokenId);118120 119 // Create a token to nest121 // Create a token to nest120 const nftTokenId = await contract.methods.nextTokenId().call();122 const nftTokenId = await contract.methods.nextTokenId().call();129 .call({from: owner})).to.be.rejectedWith('UserIsNotAllowedToNest');131 .call({from: owner})).to.be.rejectedWith('UserIsNotAllowedToNest');130 });132 });131133 132 itWeb3('NFT: disallows a non-Owner to nest someone else\'s token', async ({api, web3, privateKeyWrapper}) => {134 itEth('NFT: disallows a non-Owner to nest someone else\'s token', async ({helper}) => {133 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);135 const owner = await helper.eth.createAccountWithBalance(donor);134 const malignant = await createEthAccountWithBalance(api, web3, privateKeyWrapper);136 const malignant = await helper.eth.createAccountWithBalance(donor);135137 136 const {collectionId, contract} = await createNestingCollection(api, web3, owner);138 const {collectionId, contract} = await createNestingCollection(helper, owner);137139 138 // Mint a token140 // Mint a token139 const targetTokenId = await contract.methods.nextTokenId().call();141 const targetTokenId = await contract.methods.nextTokenId().call();140 await contract.methods.mint(142 await contract.methods.mint(141 owner,143 owner,142 targetTokenId,144 targetTokenId,143 ).send({from: owner});145 ).send({from: owner});144 const targetTokenAddress = tokenIdToAddress(collectionId, targetTokenId);146 const targetTokenAddress = helper.ethAddress.fromTokenId(collectionId, targetTokenId);145147 146 // Mint a token belonging to a different account148 // Mint a token belonging to a different account147 const tokenId = await contract.methods.nextTokenId().call();149 const tokenId = await contract.methods.nextTokenId().call();156 .call({from: malignant})).to.be.rejectedWith('UserIsNotAllowedToNest');158 .call({from: malignant})).to.be.rejectedWith('UserIsNotAllowedToNest');157 });159 });158160 159 itWeb3('NFT: disallows a non-Owner to nest someone else\'s token (Restricted nesting)', async ({api, web3, privateKeyWrapper}) => {161 itEth('NFT: disallows a non-Owner to nest someone else\'s token (Restricted nesting)', async ({helper}) => {160 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);162 const owner = await helper.eth.createAccountWithBalance(donor);161 const malignant = await createEthAccountWithBalance(api, web3, privateKeyWrapper);163 const malignant = await helper.eth.createAccountWithBalance(donor);162164 163 const {collectionId: collectionIdA, collectionAddress: collectionAddressA, contract: contractA} = await createNestingCollection(api, web3, owner);165 const {collectionId: collectionIdA, collectionAddress: collectionAddressA, contract: contractA} = await createNestingCollection(helper, owner);164 const {collectionAddress: collectionAddressB, contract: contractB} = await createNestingCollection(api, web3, owner);166 const {collectionAddress: collectionAddressB, contract: contractB} = await createNestingCollection(helper, owner);165167 166 await contractA.methods.setCollectionNesting(true, [collectionAddressA, collectionAddressB]).send({from: owner});168 await contractA.methods.setCollectionNesting(true, [collectionAddressA, collectionAddressB]).send({from: owner});167169 171 owner,173 owner,172 nftTokenIdA,174 nftTokenIdA,173 ).send({from: owner});175 ).send({from: owner});174 const nftTokenAddressA = tokenIdToAddress(collectionIdA, nftTokenIdA);176 const nftTokenAddressA = helper.ethAddress.fromTokenId(collectionIdA, nftTokenIdA);175177 176 // Create a token in another collection belonging to someone else178 // Create a token in another collection belonging to someone else177 const nftTokenIdB = await contractB.methods.nextTokenId().call();179 const nftTokenIdB = await contractB.methods.nextTokenId().call();186 .call({from: malignant})).to.be.rejectedWith('UserIsNotAllowedToNest');188 .call({from: malignant})).to.be.rejectedWith('UserIsNotAllowedToNest');187 });189 });188190 189 itWeb3('NFT: disallows to nest token in an unlisted collection', async ({api, web3, privateKeyWrapper}) => {191 itEth('NFT: disallows to nest token in an unlisted collection', async ({helper}) => {190 const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);192 const owner = await helper.eth.createAccountWithBalance(donor);191193 192 const {collectionId: collectionIdA, collectionAddress: collectionAddressA, contract: contractA} = await createNestingCollection(api, web3, owner);194 const {collectionId: collectionIdA, collectionAddress: collectionAddressA, contract: contractA} = await createNestingCollection(helper, owner);193 const {contract: contractB} = await createNestingCollection(api, web3, owner);195 const {contract: contractB} = await createNestingCollection(helper, owner);194196 195 await contractA.methods.setCollectionNesting(true, [collectionAddressA]).send({from: owner});197 await contractA.methods.setCollectionNesting(true, [collectionAddressA]).send({from: owner});196198 200 owner,202 owner,201 nftTokenIdA,203 nftTokenIdA,202 ).send({from: owner});204 ).send({from: owner});203 const nftTokenAddressA = tokenIdToAddress(collectionIdA, nftTokenIdA);205 const nftTokenAddressA = helper.ethAddress.fromTokenId(collectionIdA, nftTokenIdA);204206 205 // Create a token in another collection207 // Create a token in another collection206 const nftTokenIdB = await contractB.methods.nextTokenId().call();208 const nftTokenIdB = await contractB.methods.nextTokenId().call();214 .transfer(nftTokenAddressA, nftTokenIdB)216 .transfer(nftTokenAddressA, nftTokenIdB)215 .call()).to.be.rejectedWith('SourceCollectionIsNotAllowedToNest');217 .call()).to.be.rejectedWith('SourceCollectionIsNotAllowedToNest');216 });218 });217});219 });220});218221tests/src/eth/util/playgrounds/index.tsdiffbeforeafterbothno changes
tests/src/eth/util/playgrounds/unique.dev.tsdiffbeforeafterbothno changes