difftreelog
Merge pull request #835 from UniqueNetwork/tests/generalization
in: master
20 files changed
tests/src/apiConsts.test.tsdiffbeforeafterboth--- a/tests/src/apiConsts.test.ts
+++ b/tests/src/apiConsts.test.ts
@@ -15,7 +15,7 @@
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
import {ApiPromise} from '@polkadot/api';
-import {usingPlaygrounds, itSub, expect} from './util';
+import {usingPlaygrounds, itSub, expect, COLLECTION_HELPER, CONTRACT_HELPER} from './util';
const MAX_COLLECTION_DESCRIPTION_LENGTH = 256n;
@@ -40,9 +40,6 @@
ownerCanDestroy: true,
transfersEnabled: true,
};
-
-const EVM_COLLECTION_HELPERS_ADDRESS = '0x6c4e9fe1ae37a41e93cee429e8e1881abdcbb54f';
-const HELPERS_CONTRACT_ADDRESS = '0x842899ECF380553E8a4de75bF534cdf6fBF64049';
describe('integration test: API UNIQUE consts', () => {
let api: ApiPromise;
@@ -106,11 +103,11 @@
});
itSub('HELPERS_CONTRACT_ADDRESS', () => {
- expect(api.consts.evmContractHelpers.contractAddress.toString().toLowerCase()).to.be.equal(HELPERS_CONTRACT_ADDRESS.toLowerCase());
+ expect(api.consts.evmContractHelpers.contractAddress.toString().toLowerCase()).to.be.equal(CONTRACT_HELPER.toLowerCase());
});
itSub('EVM_COLLECTION_HELPERS_ADDRESS', () => {
- expect(api.consts.common.contractAddress.toString().toLowerCase()).to.be.equal(EVM_COLLECTION_HELPERS_ADDRESS.toLowerCase());
+ expect(api.consts.common.contractAddress.toString().toLowerCase()).to.be.equal(COLLECTION_HELPER.toLowerCase());
});
});
tests/src/burnItem.test.tsdiffbeforeafterboth--- a/tests/src/burnItem.test.ts
+++ b/tests/src/burnItem.test.ts
@@ -45,32 +45,6 @@
await collection.burnTokens(alice, 1n);
expect(await collection.getBalance({Substrate: alice.address})).to.eq(9n);
});
-
- itSub.ifWithPallets('Burn item in ReFungible collection', [Pallets.ReFungible], async function({helper}) {
- const collection = await helper.rft.mintCollection(alice);
- const token = await collection.mintToken(alice, 100n);
-
- await token.burn(alice, 90n);
- expect(await token.getBalance({Substrate: alice.address})).to.eq(10n);
-
- await token.burn(alice, 10n);
- expect(await token.getBalance({Substrate: alice.address})).to.eq(0n);
- });
-
- itSub.ifWithPallets('Burn owned portion of item in ReFungible collection', [Pallets.ReFungible], async function({helper}) {
- const collection = await helper.rft.mintCollection(alice);
- const token = await collection.mintToken(alice, 100n);
-
- await token.transfer(alice, {Substrate: bob.address}, 1n);
-
- expect(await token.getBalance({Substrate: alice.address})).to.eq(99n);
- expect(await token.getBalance({Substrate: bob.address})).to.eq(1n);
-
- await token.burn(bob, 1n);
-
- expect(await token.getBalance({Substrate: alice.address})).to.eq(99n);
- expect(await token.getBalance({Substrate: bob.address})).to.eq(0n);
- });
});
describe('integration test: ext. burnItem() with admin permissions:', () => {
@@ -104,16 +78,6 @@
await collection.burnTokensFrom(bob, {Substrate: alice.address}, 1n);
expect(await collection.getBalance({Substrate: alice.address})).to.eq(9n);
});
-
- itSub.ifWithPallets('Burn item in ReFungible collection', [Pallets.ReFungible], async function({helper}) {
- const collection = await helper.rft.mintCollection(alice);
- await collection.setLimits(alice, {ownerCanTransfer: true});
- await collection.addAdmin(alice, {Substrate: bob.address});
- const token = await collection.mintToken(alice, 100n);
-
- await token.burnFrom(bob, {Substrate: alice.address}, 100n);
- expect(await token.doesExist()).to.be.false;
- });
});
describe('Negative integration test: ext. burnItem():', () => {
@@ -138,31 +102,6 @@
const token = await collection.mintToken(alice);
await expect(token.burn(bob)).to.be.rejectedWith('common.NoPermission');
- });
-
- itSub.ifWithPallets('RFT: cannot burn non-owned token pieces', [Pallets.ReFungible], async ({helper}) => {
- const collection = await helper.rft.mintCollection(alice);
- const aliceToken = await collection.mintToken(alice, 10n, {Substrate: alice.address});
- const bobToken = await collection.mintToken(alice, 10n, {Substrate: bob.address});
-
- // 1. Cannot burn non-owned token:
- await expect(bobToken.burn(alice, 0n)).to.be.rejectedWith('common.TokenValueTooLow');
- await expect(bobToken.burn(alice, 5n)).to.be.rejectedWith('common.TokenValueTooLow');
- // 2. Cannot burn non-existing token:
- await expect(helper.rft.burnToken(alice, 99999, 10)).to.be.rejectedWith('common.CollectionNotFound');
- await expect(helper.rft.burnToken(alice, collection.collectionId, 99999)).to.be.rejectedWith('common.TokenValueTooLow');
- // 3. Can burn zero amount of owned tokens (EIP-20)
- await aliceToken.burn(alice, 0n);
-
- // 4. Storage is not corrupted:
- expect(await aliceToken.getTop10Owners()).to.deep.eq([{Substrate: alice.address}]);
- expect(await bobToken.getTop10Owners()).to.deep.eq([{Substrate: bob.address}]);
-
- // 4.1 Tokens can be transfered:
- await aliceToken.transfer(alice, {Substrate: bob.address}, 10n);
- await bobToken.transfer(bob, {Substrate: alice.address}, 10n);
- expect(await aliceToken.getTop10Owners()).to.deep.eq([{Substrate: bob.address}]);
- expect(await bobToken.getTop10Owners()).to.deep.eq([{Substrate: alice.address}]);
});
itSub('Transfer a burned token', async ({helper}) => {
tests/src/eth/collectionHelperAddress.test.tsdiffbeforeafterboth--- a/tests/src/eth/collectionHelperAddress.test.ts
+++ b/tests/src/eth/collectionHelperAddress.test.ts
@@ -16,9 +16,7 @@
import {itEth, usingEthPlaygrounds, expect} from './util';
import {IKeyringPair} from '@polkadot/types/types';
-import {Pallets} from '../util';
-
-const EVM_COLLECTION_HELPERS_ADDRESS = '0x6c4e9fe1ae37a41e93cee429e8e1881abdcbb54f';
+import {COLLECTION_HELPER, Pallets} from '../util';
describe('[eth]CollectionHelperAddress test: ERC20/ERC721 ', () => {
let donor: IKeyringPair;
@@ -36,7 +34,7 @@
const nftCollection = await helper.ethNativeContract.collection(nftCollectionAddress, 'nft', owner);
expect((await nftCollection.methods.collectionHelperAddress().call())
- .toString().toLowerCase()).to.be.equal(EVM_COLLECTION_HELPERS_ADDRESS);
+ .toString().toLowerCase()).to.be.equal(COLLECTION_HELPER);
});
itEth.ifWithPallets('RFT ', [Pallets.ReFungible], async ({helper}) => {
@@ -46,7 +44,7 @@
const rftCollection = await helper.ethNativeContract.collection(rftCollectionAddress, 'rft', owner);
expect((await rftCollection.methods.collectionHelperAddress().call())
- .toString().toLowerCase()).to.be.equal(EVM_COLLECTION_HELPERS_ADDRESS);
+ .toString().toLowerCase()).to.be.equal(COLLECTION_HELPER);
});
itEth('FT', async ({helper}) => {
@@ -56,7 +54,7 @@
const collection = await helper.ethNativeContract.collection(collectionAddress, 'ft', owner);
expect((await collection.methods.collectionHelperAddress().call())
- .toString().toLowerCase()).to.be.equal(EVM_COLLECTION_HELPERS_ADDRESS);
+ .toString().toLowerCase()).to.be.equal(COLLECTION_HELPER);
});
itEth('[collectionHelpers] convert collectionId into address', async ({helper}) => {
tests/src/eth/createNFTCollection.test.tsdiffbeforeafterboth--- a/tests/src/eth/createNFTCollection.test.ts
+++ b/tests/src/eth/createNFTCollection.test.ts
@@ -18,6 +18,7 @@
import {IKeyringPair} from '@polkadot/types/types';
import {expect, itEth, usingEthPlaygrounds} from './util';
import {CollectionLimitField} from './util/playgrounds/types';
+import {COLLECTION_HELPER} from '../util';
describe('Create NFT collection from EVM', () => {
tests/src/eth/fungible.test.tsdiffbeforeafterboth--- a/tests/src/eth/fungible.test.ts
+++ b/tests/src/eth/fungible.test.ts
@@ -17,38 +17,6 @@
import {expect, itEth, usingEthPlaygrounds} from './util';
import {IKeyringPair} from '@polkadot/types/types';
-describe('Fungible: Information getting', () => {
- let donor: IKeyringPair;
- let alice: IKeyringPair;
-
- before(async function() {
- await usingEthPlaygrounds(async (helper, privateKey) => {
- donor = await privateKey({filename: __filename});
- [alice] = await helper.arrange.createAccounts([20n], donor);
- });
- });
-
- itEth('totalSupply', async ({helper}) => {
- const caller = await helper.eth.createAccountWithBalance(donor);
- const collection = await helper.ft.mintCollection(alice);
- await collection.mint(alice, 200n);
-
- const contract = await helper.ethNativeContract.collectionById(collection.collectionId, 'ft', caller);
- const totalSupply = await contract.methods.totalSupply().call();
- expect(totalSupply).to.equal('200');
- });
-
- itEth('balanceOf', async ({helper}) => {
- const caller = await helper.eth.createAccountWithBalance(donor);
- const collection = await helper.ft.mintCollection(alice);
- await collection.mint(alice, 200n, {Ethereum: caller});
-
- const contract = await helper.ethNativeContract.collectionById(collection.collectionId, 'ft', caller);
- const balance = await contract.methods.balanceOf(caller).call();
- expect(balance).to.equal('200');
- });
-});
-
describe('Fungible: Plain calls', () => {
let donor: IKeyringPair;
let alice: IKeyringPair;
@@ -59,24 +27,6 @@
donor = await privateKey({filename: __filename});
[alice, owner] = await helper.arrange.createAccounts([30n, 20n], donor);
});
- });
-
- itEth('Can perform mint()', async ({helper}) => {
- const owner = await helper.eth.createAccountWithBalance(donor);
- const receiver = helper.eth.createAccount();
- const collection = await helper.ft.mintCollection(alice);
- await collection.addAdmin(alice, {Ethereum: owner});
-
- const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
- const contract = await helper.ethNativeContract.collection(collectionAddress, 'ft', owner);
-
- const result = await contract.methods.mint(receiver, 100).send();
-
- const event = result.events.Transfer;
- expect(event.address).to.equal(collectionAddress);
- expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');
- expect(event.returnValues.to).to.equal(receiver);
- expect(event.returnValues.value).to.equal('100');
});
[
tests/src/eth/getCode.test.tsdiffbeforeafterboth--- /dev/null
+++ b/tests/src/eth/getCode.test.ts
@@ -0,0 +1,53 @@
+// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
+// This file is part of Unique Network.
+
+// Unique Network is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// Unique Network is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
+
+import {expect, itEth, usingEthPlaygrounds} from './util';
+import {IKeyringPair} from '@polkadot/types/types';
+import {COLLECTION_HELPER, CONTRACT_HELPER} from '../util';
+
+describe('RPC eth_getCode', () => {
+ let donor: IKeyringPair;
+
+ before(async function() {
+ await usingEthPlaygrounds(async (helper, privateKey) => {
+ donor = await privateKey({filename: __filename});
+ });
+ });
+
+ [
+ {address: COLLECTION_HELPER},
+ {address: CONTRACT_HELPER},
+ ].map(testCase => {
+ itEth(`returns value for native contract: ${testCase.address}`, async ({helper}) => {
+ const contractCodeSub = (await helper.callRpc('api.rpc.eth.getCode', [testCase.address])).toJSON();
+ const contractCodeEth = (await helper.getWeb3().eth.getCode(testCase.address));
+
+ expect(contractCodeSub).to.has.length.greaterThan(4);
+ expect(contractCodeEth).to.has.length.greaterThan(4);
+ });
+ });
+
+ itEth('returns value for custom contract', async ({helper}) => {
+ const signer = await helper.eth.createAccountWithBalance(donor);
+ const flipper = await helper.eth.deployFlipper(signer);
+
+ const contractCodeSub = (await helper.callRpc('api.rpc.eth.getCode', [flipper.options.address])).toJSON();
+ const contractCodeEth = (await helper.getWeb3().eth.getCode(flipper.options.address));
+
+ expect(contractCodeSub).to.has.length.greaterThan(4);
+ expect(contractCodeEth).to.has.length.greaterThan(4);
+ });
+});
tests/src/eth/nonFungible.test.tsdiffbeforeafterboth--- a/tests/src/eth/nonFungible.test.ts
+++ b/tests/src/eth/nonFungible.test.ts
@@ -19,68 +19,6 @@
import {Contract} from 'web3-eth-contract';
import {ITokenPropertyPermission} from '../util/playgrounds/types';
-
-describe('NFT: Information getting', () => {
- let donor: IKeyringPair;
- let alice: IKeyringPair;
-
- before(async function() {
- await usingEthPlaygrounds(async (helper, privateKey) => {
- donor = await privateKey({filename: __filename});
- [alice] = await helper.arrange.createAccounts([10n], donor);
- });
- });
-
- itEth('totalSupply', async ({helper}) => {
- const collection = await helper.nft.mintCollection(alice, {});
- await collection.mintToken(alice);
-
- const caller = await helper.eth.createAccountWithBalance(donor);
-
- const contract = await helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);
- const totalSupply = await contract.methods.totalSupply().call();
-
- expect(totalSupply).to.equal('1');
- });
-
- itEth('balanceOf', async ({helper}) => {
- const collection = await helper.nft.mintCollection(alice, {});
- const caller = await helper.eth.createAccountWithBalance(donor);
-
- await collection.mintToken(alice, {Ethereum: caller});
- await collection.mintToken(alice, {Ethereum: caller});
- await collection.mintToken(alice, {Ethereum: caller});
-
- const contract = await helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);
- const balance = await contract.methods.balanceOf(caller).call();
-
- expect(balance).to.equal('3');
- });
-
- itEth('ownerOf', async ({helper}) => {
- const collection = await helper.nft.mintCollection(alice, {});
- const caller = await helper.eth.createAccountWithBalance(donor);
-
- const token = await collection.mintToken(alice, {Ethereum: caller});
-
- const contract = await helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);
-
- const owner = await contract.methods.ownerOf(token.tokenId).call();
-
- expect(owner).to.equal(caller);
- });
-
- itEth('name/symbol is available regardless of ERC721Metadata support', async ({helper}) => {
- const collection = await helper.nft.mintCollection(alice, {name: 'test', tokenPrefix: 'TEST'});
- const caller = helper.eth.createAccount();
-
- const contract = await helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);
-
- expect(await contract.methods.name().call()).to.equal('test');
- expect(await contract.methods.symbol().call()).to.equal('TEST');
- });
-});
-
describe('Check ERC721 token URI for NFT', () => {
let donor: IKeyringPair;
@@ -148,30 +86,6 @@
donor = await privateKey({filename: __filename});
[minter, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);
});
- });
-
- itEth('Can perform mint() & get crossOwner()', async ({helper}) => {
- const owner = await helper.eth.createAccountWithBalance(donor);
- const receiver = helper.eth.createAccount();
-
- const {collectionAddress} = await helper.eth.createERC721MetadataCompatibleNFTCollection(owner, 'Mint collection', '6', '6', '');
- const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
-
- const result = await contract.methods.mintWithTokenURI(receiver, 'Test URI').send();
- const tokenId = result.events.Transfer.returnValues.tokenId;
- expect(tokenId).to.be.equal('1');
-
- const event = result.events.Transfer;
- expect(event.address).to.be.equal(collectionAddress);
- expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');
- expect(event.returnValues.to).to.be.equal(receiver);
-
- expect(await contract.methods.tokenURI(tokenId).call()).to.be.equal('Test URI');
- expect(await contract.methods.crossOwnerOf(tokenId).call()).to.be.like([receiver, '0']);
- // TODO: this wont work right now, need release 919000 first
- // await helper.methods.setOffchainSchema(collectionIdAddress, 'https://offchain-service.local/token-info/{id}').send();
- // const tokenUri = await contract.methods.tokenURI(nextTokenId).call();
- // expect(tokenUri).to.be.equal(`https://offchain-service.local/token-info/${nextTokenId}`);
});
// TODO combine all minting tests in one place
tests/src/eth/reFungible.test.tsdiffbeforeafterboth--- a/tests/src/eth/reFungible.test.ts
+++ b/tests/src/eth/reFungible.test.ts
@@ -19,90 +19,6 @@
import {IKeyringPair} from '@polkadot/types/types';
import {ITokenPropertyPermission} from '../util/playgrounds/types';
-describe('Refungible: Information getting', () => {
- let donor: IKeyringPair;
-
- before(async function() {
- await usingEthPlaygrounds(async (helper, privateKey) => {
- requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);
-
- donor = await privateKey({filename: __filename});
- });
- });
-
- itEth('totalSupply', async ({helper}) => {
- const caller = await helper.eth.createAccountWithBalance(donor);
- const {collectionAddress} = await helper.eth.createRFTCollection(caller, 'TotalSupply', '6', '6');
- const contract = await helper.ethNativeContract.collection(collectionAddress, 'rft', caller);
-
- await contract.methods.mint(caller).send();
-
- const totalSupply = await contract.methods.totalSupply().call();
- expect(totalSupply).to.equal('1');
- });
-
- itEth('balanceOf', async ({helper}) => {
- const caller = await helper.eth.createAccountWithBalance(donor);
- const {collectionAddress} = await helper.eth.createRFTCollection(caller, 'BalanceOf', '6', '6');
- const contract = await helper.ethNativeContract.collection(collectionAddress, 'rft', caller);
-
- await contract.methods.mint(caller).send();
- await contract.methods.mint(caller).send();
- await contract.methods.mint(caller).send();
-
- const balance = await contract.methods.balanceOf(caller).call();
- expect(balance).to.equal('3');
- });
-
- itEth('ownerOf', async ({helper}) => {
- const caller = await helper.eth.createAccountWithBalance(donor);
- const {collectionAddress} = await helper.eth.createRFTCollection(caller, 'OwnerOf', '6', '6');
- const contract = await helper.ethNativeContract.collection(collectionAddress, 'rft', caller);
-
- const result = await contract.methods.mint(caller).send();
- const tokenId = result.events.Transfer.returnValues.tokenId;
-
- const owner = await contract.methods.ownerOf(tokenId).call();
- expect(owner).to.equal(caller);
- });
-
- itEth('ownerOf after burn', async ({helper}) => {
- const caller = await helper.eth.createAccountWithBalance(donor);
- const receiver = helper.eth.createAccount();
- const {collectionId, collectionAddress} = await helper.eth.createRFTCollection(caller, 'OwnerOf-AfterBurn', '6', '6');
- const contract = await helper.ethNativeContract.collection(collectionAddress, 'rft', caller);
-
- const result = await contract.methods.mint(caller).send();
- const tokenId = result.events.Transfer.returnValues.tokenId;
- const tokenContract = await helper.ethNativeContract.rftTokenById(collectionId, tokenId, caller, true);
-
- await tokenContract.methods.repartition(2).send();
- await tokenContract.methods.transfer(receiver, 1).send();
-
- await tokenContract.methods.burnFrom(caller, 1).send();
-
- const owner = await contract.methods.ownerOf(tokenId).call();
- expect(owner).to.equal(receiver);
- });
-
- itEth('ownerOf for partial ownership', async ({helper}) => {
- const caller = await helper.eth.createAccountWithBalance(donor);
- const receiver = helper.eth.createAccount();
- const {collectionId, collectionAddress} = await helper.eth.createRFTCollection(caller, 'Partial-OwnerOf', '6', '6');
- const contract = await helper.ethNativeContract.collection(collectionAddress, 'rft', caller);
-
- const result = await contract.methods.mint(caller).send();
- const tokenId = result.events.Transfer.returnValues.tokenId;
- const tokenContract = await helper.ethNativeContract.rftTokenById(collectionId, tokenId, caller);
-
- await tokenContract.methods.repartition(2).send();
- await tokenContract.methods.transfer(receiver, 1).send();
-
- const owner = await contract.methods.ownerOf(tokenId).call();
- expect(owner).to.equal('0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF');
- });
-});
-
describe('Refungible: Plain calls', () => {
let donor: IKeyringPair;
let minter: IKeyringPair;
@@ -116,25 +32,6 @@
donor = await privateKey({filename: __filename});
[minter, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);
});
- });
-
- itEth('Can perform mint() & crossOwnerOf()', async ({helper}) => {
- const owner = await helper.eth.createAccountWithBalance(donor);
- const receiver = helper.eth.createAccount();
- const {collectionAddress} = await helper.eth.createERC721MetadataCompatibleRFTCollection(owner, 'Minty', '6', '6', '');
- const contract = await helper.ethNativeContract.collection(collectionAddress, 'rft', owner);
-
- const result = await contract.methods.mintWithTokenURI(receiver, 'Test URI').send();
-
- const event = result.events.Transfer;
- expect(event.address).to.equal(collectionAddress);
- expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');
- expect(event.returnValues.to).to.equal(receiver);
- const tokenId = event.returnValues.tokenId;
- expect(tokenId).to.be.equal('1');
-
- expect(await contract.methods.crossOwnerOf(tokenId).call()).to.be.like([receiver, '0']);
- expect(await contract.methods.tokenURI(tokenId).call()).to.be.equal('Test URI');
});
[
tests/src/eth/reFungibleToken.test.tsdiffbeforeafterboth--- a/tests/src/eth/reFungibleToken.test.ts
+++ b/tests/src/eth/reFungibleToken.test.ts
@@ -19,51 +19,6 @@
import {IKeyringPair} from '@polkadot/types/types';
import {Contract} from 'web3-eth-contract';
-
-describe('Refungible token: Information getting', () => {
- let donor: IKeyringPair;
- let alice: IKeyringPair;
-
- before(async function() {
- await usingEthPlaygrounds(async (helper, privateKey) => {
- requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);
-
- donor = await privateKey({filename: __filename});
- [alice] = await helper.arrange.createAccounts([20n], donor);
- });
- });
-
- itEth('totalSupply', async ({helper}) => {
- const caller = await helper.eth.createAccountWithBalance(donor);
- const collection = await helper.rft.mintCollection(alice, {tokenPrefix: 'MUON'});
- const {tokenId} = await collection.mintToken(alice, 200n, {Ethereum: caller});
-
- const contract = await helper.ethNativeContract.rftTokenById(collection.collectionId, tokenId, caller);
- const totalSupply = await contract.methods.totalSupply().call();
- expect(totalSupply).to.equal('200');
- });
-
- itEth('balanceOf', async ({helper}) => {
- const caller = await helper.eth.createAccountWithBalance(donor);
- const collection = await helper.rft.mintCollection(alice, {tokenPrefix: 'MUON'});
- const {tokenId} = await collection.mintToken(alice, 200n, {Ethereum: caller});
-
- const contract = await helper.ethNativeContract.rftTokenById(collection.collectionId, tokenId, caller);
- const balance = await contract.methods.balanceOf(caller).call();
- expect(balance).to.equal('200');
- });
-
- itEth('decimals', async ({helper}) => {
- const caller = await helper.eth.createAccountWithBalance(donor);
- const collection = await helper.rft.mintCollection(alice, {tokenPrefix: 'MUON'});
- const {tokenId} = await collection.mintToken(alice, 200n, {Ethereum: caller});
-
- const contract = await helper.ethNativeContract.rftTokenById(collection.collectionId, tokenId, caller);
- const decimals = await contract.methods.decimals().call();
- expect(decimals).to.equal('0');
- });
-});
-
// FIXME: Need erc721 for ReFubgible.
describe('Check ERC721 token URI for ReFungible', () => {
let donor: IKeyringPair;
tests/src/eth/tokens/callMethodsERC20.test.tsdiffbeforeafterboth--- /dev/null
+++ b/tests/src/eth/tokens/callMethodsERC20.test.ts
@@ -0,0 +1,91 @@
+// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
+// This file is part of Unique Network.
+
+// Unique Network is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// Unique Network is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
+
+import {Pallets, requirePalletsOrSkip} from '../../util';
+import {expect, itEth, usingEthPlaygrounds} from '../util';
+import {IKeyringPair} from '@polkadot/types/types';
+
+[
+ {mode: 'ft' as const, requiredPallets: []},
+ {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},
+].map(testCase => {
+ describe(`${testCase.mode.toUpperCase()}: ERC-20 call methods`, () => {
+ let donor: IKeyringPair;
+
+ before(async function() {
+ await usingEthPlaygrounds(async (helper, privateKey) => {
+ requirePalletsOrSkip(this, helper, testCase.requiredPallets);
+ donor = await privateKey({filename: __filename});
+ });
+ });
+
+ itEth('totalSupply', async ({helper}) => {
+ const caller = await helper.eth.createAccountWithBalance(donor);
+ const mintingParams = testCase.mode === 'ft' ? [caller, 200n] : [caller];
+
+ const {collection, collectionId} = await helper.eth.createCollection(testCase.mode, caller, 'TotalSupply', '6', '6');
+ if (testCase.mode === 'rft') await collection.methods.mint(caller).send({from: caller});
+
+ // Use collection contract for FT or token contract for RFT:
+ const contract = testCase.mode === 'ft'
+ ? collection
+ : await helper.ethNativeContract.rftTokenById(collectionId, 1, caller);
+
+ // Mint tokens:
+ testCase.mode === 'ft'
+ ? await contract.methods.mint(...mintingParams).send({from: caller})
+ : await contract.methods.repartition(200).send({from: caller});
+
+ const totalSupply = await contract.methods.totalSupply().call();
+ expect(totalSupply).to.equal('200');
+ });
+
+ itEth('balanceOf', async ({helper}) => {
+ const caller = await helper.eth.createAccountWithBalance(donor);
+ const mintingParams = testCase.mode === 'ft' ? [caller, 200n] : [caller];
+
+ const {collection, collectionId} = await helper.eth.createCollection(testCase.mode, caller, 'BalanceOf', 'Descroption', 'Prefix');
+ if (testCase.mode === 'rft') await collection.methods.mint(caller).send({from: caller});
+
+ // Use collection contract for FT or token contract for RFT:
+ const contract = testCase.mode === 'ft'
+ ? collection
+ : await helper.ethNativeContract.rftTokenById(collectionId, 1, caller);
+
+ // Mint tokens:
+ testCase.mode === 'ft'
+ ? await contract.methods.mint(...mintingParams).send({from: caller})
+ : await contract.methods.repartition(200).send({from: caller});
+
+ const balance = await contract.methods.balanceOf(caller).call();
+ expect(balance).to.equal('200');
+ });
+
+ itEth('decimals', async ({helper}) => {
+ const caller = await helper.eth.createAccountWithBalance(donor);
+ const {collection, collectionId} = await helper.eth.createCollection(testCase.mode, caller, 'BalanceOf', 'Descroption', 'Prefix');
+ if (testCase.mode === 'rft') await collection.methods.mint(caller).send({from: caller});
+
+ // Use collection contract for FT or token contract for RFT:
+ const contract = testCase.mode === 'ft'
+ ? collection
+ : await helper.ethNativeContract.rftTokenById(collectionId, 1, caller);
+
+ const decimals = await contract.methods.decimals().call();
+ expect(decimals).to.equal(testCase.mode === 'rft' ? '0' : '18');
+ });
+ });
+});
\ No newline at end of file
tests/src/eth/tokens/callMethodsERC721.test.tsdiffbeforeafterboth--- /dev/null
+++ b/tests/src/eth/tokens/callMethodsERC721.test.ts
@@ -0,0 +1,143 @@
+// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
+// This file is part of Unique Network.
+
+// Unique Network is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// Unique Network is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
+
+import {Pallets} from '../../util';
+import {expect, itEth, usingEthPlaygrounds} from '../util';
+import {IKeyringPair} from '@polkadot/types/types';
+
+
+describe('ERC-721 call methods', () => {
+ let donor: IKeyringPair;
+
+ before(async function() {
+ await usingEthPlaygrounds(async (helper, privateKey) => {
+ donor = await privateKey({filename: __filename});
+ });
+ });
+
+ [
+ {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},
+ {mode: 'nft' as const, requiredPallets: []},
+ ].map(testCase => {
+ itEth.ifWithPallets(`${testCase.mode.toUpperCase()}: name/symbol/description`, testCase.requiredPallets, async ({helper}) => {
+ const callerEth = await helper.eth.createAccountWithBalance(donor);
+ const [callerSub] = await helper.arrange.createAccounts([100n], donor);
+ const [name, description, tokenPrefix] = ['Name', 'Description', 'Symbol'];
+
+ const {collection: collectionEth} = await helper.eth.createCollection(testCase.mode, callerEth, name, description, tokenPrefix);
+ await collectionEth.methods.mint(callerEth).send({from: callerEth});
+ const {collectionId} = await helper[testCase.mode].mintCollection(callerSub, {name, description, tokenPrefix});
+ const collectionSub = await helper.ethNativeContract.collectionById(collectionId, testCase.mode, callerEth);
+
+ // Can get name/symbol/description for Eth collection
+ expect(await collectionEth.methods.name().call()).to.eq(name);
+ expect(await collectionEth.methods.symbol().call()).to.eq(tokenPrefix);
+ expect(await collectionEth.methods.description().call()).to.eq(description);
+ // Can get name/symbol/description for Sub collection
+ expect(await collectionSub.methods.name().call()).to.eq(name);
+ expect(await collectionSub.methods.symbol().call()).to.eq(tokenPrefix);
+ expect(await collectionSub.methods.description().call()).to.eq(description);
+ });
+ });
+
+ [
+ {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},
+ {mode: 'nft' as const, requiredPallets: []},
+ ].map(testCase => {
+ itEth.ifWithPallets(`${testCase.mode.toUpperCase()}: totalSupply`, testCase.requiredPallets, async ({helper}) => {
+ const caller = await helper.eth.createAccountWithBalance(donor);
+
+ const {collection} = await helper.eth.createCollection(testCase.mode, caller, 'TotalSupply', '6', '6');
+ await collection.methods.mint(caller).send({from: caller});
+
+ const totalSupply = await collection.methods.totalSupply().call();
+ expect(totalSupply).to.equal('1');
+ });
+ });
+
+ [
+ {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},
+ {mode: 'nft' as const, requiredPallets: []},
+ ].map(testCase => {
+ itEth.ifWithPallets(`${testCase.mode.toUpperCase()}: balanceOf`, testCase.requiredPallets, async ({helper}) => {
+ const caller = await helper.eth.createAccountWithBalance(donor);
+
+ const {collection} = await helper.eth.createCollection(testCase.mode, caller, 'BalanceOf', 'Descroption', 'Prefix');
+ await collection.methods.mint(caller).send({from: caller});
+ await collection.methods.mint(caller).send({from: caller});
+ await collection.methods.mint(caller).send({from: caller});
+
+ const balance = await collection.methods.balanceOf(caller).call();
+ expect(balance).to.equal('3');
+ });
+ });
+
+ [
+ {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},
+ {mode: 'nft' as const, requiredPallets: []},
+ ].map(testCase => {
+ itEth.ifWithPallets(`${testCase.mode.toUpperCase()}: ownerOf`, testCase.requiredPallets, async ({helper}) => {
+ const caller = await helper.eth.createAccountWithBalance(donor);
+ const {collection} = await helper.eth.createCollection(testCase.mode, caller, 'OwnerOf', '6', '6');
+
+ const result = await collection.methods.mint(caller).send();
+ const tokenId = result.events.Transfer.returnValues.tokenId;
+
+ const owner = await collection.methods.ownerOf(tokenId).call();
+ expect(owner).to.equal(caller);
+ });
+ });
+
+ [
+ {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},
+ // TODO {mode: 'nft' as const, requiredPallets: []},
+ ].map(testCase => {
+ itEth.ifWithPallets(`${testCase.mode.toUpperCase()}: ownerOf after burn`, testCase.requiredPallets, async ({helper}) => {
+ const caller = await helper.eth.createAccountWithBalance(donor);
+ const receiver = helper.eth.createAccount();
+ const {collection, collectionId} = await helper.eth.createCollection(testCase.mode, caller, 'OwnerOf-AfterBurn', '6', '6');
+
+ const result = await collection.methods.mint(caller).send();
+ const tokenId = result.events.Transfer.returnValues.tokenId;
+ const tokenContract = await helper.ethNativeContract.rftTokenById(collectionId, tokenId, caller, true);
+
+ await tokenContract.methods.repartition(2).send();
+ await tokenContract.methods.transfer(receiver, 1).send();
+
+ await tokenContract.methods.burnFrom(caller, 1).send();
+
+ const owner = await collection.methods.ownerOf(tokenId).call();
+ expect(owner).to.equal(receiver);
+ });
+ });
+
+ itEth.ifWithPallets('RFT: ownerOf for partial ownership', [Pallets.ReFungible], async ({helper}) => {
+ const caller = await helper.eth.createAccountWithBalance(donor);
+ const receiver = helper.eth.createAccount();
+ const {collectionId, collectionAddress} = await helper.eth.createRFTCollection(caller, 'Partial-OwnerOf', '6', '6');
+ const contract = await helper.ethNativeContract.collection(collectionAddress, 'rft', caller);
+
+ const result = await contract.methods.mint(caller).send();
+ const tokenId = result.events.Transfer.returnValues.tokenId;
+ const tokenContract = await helper.ethNativeContract.rftTokenById(collectionId, tokenId, caller);
+
+ await tokenContract.methods.repartition(2).send();
+ await tokenContract.methods.transfer(receiver, 1).send();
+
+ const owner = await contract.methods.ownerOf(tokenId).call();
+ expect(owner).to.equal('0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF');
+ });
+});
tests/src/eth/tokens/minting.test.tsdiffbeforeafterboth--- /dev/null
+++ b/tests/src/eth/tokens/minting.test.ts
@@ -0,0 +1,167 @@
+// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
+// This file is part of Unique Network.
+
+// Unique Network is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// Unique Network is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
+
+import {IKeyringPair} from '@polkadot/types/types';
+import {Pallets} from '../../util';
+import {expect, itEth, usingEthPlaygrounds} from '../util';
+
+
+describe('Minting tokens', () => {
+ let donor: IKeyringPair;
+ let alice: IKeyringPair;
+
+ before(async function() {
+ await usingEthPlaygrounds(async (helper, privateKey) => {
+ donor = await privateKey({filename: __filename});
+ [alice] = await helper.arrange.createAccounts([30n, 20n], donor);
+ });
+ });
+
+ [
+ {mode: 'nft' as const, requiredPallets: []},
+ {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},
+ {mode: 'ft' as const, requiredPallets: []},
+ ].map(testCase => {
+ itEth.ifWithPallets(`${testCase.mode.toUpperCase()}: Can mint() for Substrate collection`, testCase.requiredPallets, async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const receiver = helper.eth.createAccount();
+ const mintingParams = testCase.mode === 'ft' ? [receiver, 100] : [receiver];
+
+ const collection = await helper[testCase.mode].mintCollection(alice);
+ await collection.addAdmin(alice, {Ethereum: owner});
+
+ const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
+ const contract = await helper.ethNativeContract.collection(collectionAddress, testCase.mode, owner);
+
+ const result = await contract.methods.mint(...mintingParams).send({from: owner});
+
+ // Check events:
+ const event = result.events.Transfer;
+ expect(event.address).to.equal(collectionAddress);
+ expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');
+ expect(event.returnValues.to).to.equal(receiver);
+ if (testCase.mode === 'ft')
+ expect(event.returnValues.value).to.equal('100');
+
+ // Check token exist:
+ if(testCase.mode === 'ft') {
+ expect(await helper.ft.getBalance(collection.collectionId, {Ethereum: receiver})).to.eq(100n);
+ } else {
+ const tokenId = event.returnValues.tokenId;
+ expect(tokenId).to.be.equal('1');
+ expect(await helper.collection.getLastTokenId(collection.collectionId)).to.eq(1);
+ expect(await contract.methods.crossOwnerOf(tokenId).call()).to.be.like([receiver, '0']);
+ }
+ });
+ });
+
+ [
+ {mode: 'nft' as const, requiredPallets: []},
+ {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},
+ {mode: 'ft' as const, requiredPallets: []},
+ ].map(testCase => {
+ itEth.ifWithPallets(`${testCase.mode.toUpperCase()}: Can mint() for Ethereum collection`, testCase.requiredPallets, async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const receiver = helper.eth.createAccount();
+ const mintingParams = testCase.mode === 'ft' ? [receiver, 100] : [receiver];
+
+ const {collection, collectionAddress, collectionId} = await helper.eth.createCollection(testCase.mode, owner, 'Name', 'Desc', 'Prefix');
+
+ const result = await collection.methods.mint(...mintingParams).send({from: owner});
+
+ // Check events:
+ const event = result.events.Transfer;
+ expect(event.address).to.equal(collectionAddress);
+ expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');
+ expect(event.returnValues.to).to.equal(receiver);
+ if (testCase.mode === 'ft')
+ expect(event.returnValues.value).to.equal('100');
+
+ // Check token exist:
+ if(testCase.mode === 'ft') {
+ expect(await helper.ft.getBalance(collectionId, {Ethereum: receiver})).to.eq(100n);
+ } else {
+ const tokenId = event.returnValues.tokenId;
+ expect(tokenId).to.be.equal('1');
+ expect(await helper.collection.getLastTokenId(collectionId)).to.eq(1);
+ expect(await collection.methods.crossOwnerOf(tokenId).call()).to.be.like([receiver, '0']);
+ }
+ });
+ });
+
+ [
+ {mode: 'nft' as const, requiredPallets: []},
+ {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},
+ {mode: 'ft' as const, requiredPallets: []},
+ ].map(testCase => {
+ itEth.ifWithPallets(`${testCase.mode.toUpperCase()}: Can mint() for Ethereum collection`, testCase.requiredPallets, async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const receiver = helper.eth.createAccount();
+ const mintingParams = testCase.mode === 'ft' ? [receiver, 100] : [receiver];
+
+ const {collection, collectionAddress, collectionId} = await helper.eth.createCollection(testCase.mode, owner, 'Name', 'Desc', 'Prefix');
+
+ const result = await collection.methods.mint(...mintingParams).send({from: owner});
+
+ // Check events:
+ const event = result.events.Transfer;
+ expect(event.address).to.equal(collectionAddress);
+ expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');
+ expect(event.returnValues.to).to.equal(receiver);
+ if (testCase.mode === 'ft')
+ expect(event.returnValues.value).to.equal('100');
+
+ // Check token exist:
+ if(testCase.mode === 'ft') {
+ expect(await helper.ft.getBalance(collectionId, {Ethereum: receiver})).to.eq(100n);
+ } else {
+ const tokenId = event.returnValues.tokenId;
+ expect(tokenId).to.be.equal('1');
+ expect(await helper.collection.getLastTokenId(collectionId)).to.eq(1);
+ expect(await collection.methods.crossOwnerOf(tokenId).call()).to.be.like([receiver, '0']);
+ }
+ });
+ });
+
+ [
+ {mode: 'nft' as const, requiredPallets: []},
+ {mode: 'rft' as const, requiredPallets: [Pallets.ReFungible]},
+ ].map(testCase => {
+ itEth.ifWithPallets(`${testCase.mode.toUpperCase()}: Can mintWithTokenURI() for Ethereum collection`, testCase.requiredPallets, async ({helper}) => {
+ const owner = await helper.eth.createAccountWithBalance(donor);
+ const receiver = helper.eth.createAccount();
+
+ const {collectionAddress} = await helper.eth.createERC721MetadataCompatibleNFTCollection(owner, 'Mint collection', '6', '6', '');
+ const contract = await helper.ethNativeContract.collection(collectionAddress, testCase.mode, owner);
+
+ const result = await contract.methods.mintWithTokenURI(receiver, 'Test URI').send();
+ const tokenId = result.events.Transfer.returnValues.tokenId;
+ expect(tokenId).to.be.equal('1');
+
+ const event = result.events.Transfer;
+ expect(event.address).to.be.equal(collectionAddress);
+ expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');
+ expect(event.returnValues.to).to.be.equal(receiver);
+
+ expect(await contract.methods.tokenURI(tokenId).call()).to.be.equal('Test URI');
+ expect(await contract.methods.crossOwnerOf(tokenId).call()).to.be.like([receiver, '0']);
+ // TODO: this wont work right now, need release 919000 first
+ // await helper.methods.setOffchainSchema(collectionIdAddress, 'https://offchain-service.local/token-info/{id}').send();
+ // const tokenUri = await contract.methods.tokenURI(nextTokenId).call();
+ // expect(tokenUri).to.be.equal(`https://offchain-service.local/token-info/${nextTokenId}`);
+ });
+ });
+});
\ No newline at end of file
tests/src/eth/util/playgrounds/unique.dev.tsdiffbeforeafterboth--- a/tests/src/eth/util/playgrounds/unique.dev.ts
+++ b/tests/src/eth/util/playgrounds/unique.dev.ts
@@ -257,7 +257,7 @@
}
}
- async createCollection(mode: TCollectionMode, signer: string, name: string, description: string, tokenPrefix: string, decimals = 18): Promise<{ collectionId: number, collectionAddress: string, events: NormalizedEvent[] }> {
+ async createCollection(mode: TCollectionMode, signer: string, name: string, description: string, tokenPrefix: string, decimals = 18, mergeDeprecated = false): Promise<{ collectionId: number, collectionAddress: string, events: NormalizedEvent[], collection: Contract }> {
const collectionCreationPrice = this.helper.balance.getCollectionCreationPrice();
const collectionHelper = await this.helper.ethNativeContract.collectionHelpers(signer);
const functionName: string = this.createCollectionMethodName(mode);
@@ -268,8 +268,9 @@
const collectionAddress = this.helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);
const collectionId = this.helper.ethAddress.extractCollectionId(collectionAddress);
const events = this.helper.eth.normalizeEvents(result.events);
+ const collection = await this.helper.ethNativeContract.collectionById(collectionId, mode, signer, mergeDeprecated);
- return {collectionId, collectionAddress, events};
+ return {collectionId, collectionAddress, events, collection};
}
createNFTCollection(signer: string, name: string, description: string, tokenPrefix: string): Promise<{ collectionId: number, collectionAddress: string, events: NormalizedEvent[] }> {
tests/src/nesting/nest.test.tsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import {IKeyringPair} from '@polkadot/types/types';18import {expect, itSub, Pallets, usingPlaygrounds} from '../util';1920describe('Integration Test: Composite nesting tests', () => {21 let alice: IKeyringPair;22 let bob: IKeyringPair;2324 before(async () => {25 await usingPlaygrounds(async (helper, privateKey) => {26 const donor = await privateKey({filename: __filename});27 [alice, bob] = await helper.arrange.createAccounts([50n, 10n], donor);28 });29 });3031 itSub('Performs the full suite: bundles a token, transfers, and unnests', async ({helper}) => {32 const collection = await helper.nft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true}}});33 const targetToken = await collection.mintToken(alice);3435 // Create an immediately nested token36 const nestedToken = await collection.mintToken(alice, targetToken.nestingAccount());37 expect(await nestedToken.getTopmostOwner()).to.be.deep.equal({Substrate: alice.address});38 expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());3940 // Create a token to be nested41 const newToken = await collection.mintToken(alice);4243 // Nest44 await newToken.nest(alice, targetToken);45 expect(await newToken.getTopmostOwner()).to.be.deep.equal({Substrate: alice.address});46 expect(await newToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());4748 // Move bundle to different user49 await targetToken.transfer(alice, {Substrate: bob.address});50 expect(await nestedToken.getTopmostOwner()).to.be.deep.equal({Substrate: bob.address});51 expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());52 expect(await newToken.getTopmostOwner()).to.be.deep.equal({Substrate: bob.address});53 expect(await newToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());5455 // Unnest56 await newToken.unnest(bob, targetToken, {Substrate: bob.address});57 expect(await newToken.getTopmostOwner()).to.be.deep.equal({Substrate: bob.address});58 expect(await newToken.getOwner()).to.be.deep.equal({Substrate: bob.address});59 });6061 itSub('Transfers an already bundled token', async ({helper}) => {62 const collection = await helper.nft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true}}});63 const tokenA = await collection.mintToken(alice);64 const tokenB = await collection.mintToken(alice);6566 // Create a nested token67 const tokenC = await collection.mintToken(alice, tokenA.nestingAccount());68 expect(await tokenC.getOwner()).to.be.deep.equal(tokenA.nestingAccount().toLowerCase());6970 // Transfer the nested token to another token71 await expect(tokenC.transferFrom(alice, tokenA.nestingAccount(), tokenB.nestingAccount())).to.be.fulfilled;72 expect(await tokenC.getTopmostOwner()).to.be.deep.equal({Substrate: alice.address});73 expect(await tokenC.getOwner()).to.be.deep.equal(tokenB.nestingAccount().toLowerCase());74 });7576 itSub('Checks token children', async ({helper}) => {77 const collectionA = await helper.nft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true}}});78 const collectionB = await helper.ft.mintCollection(alice);7980 const targetToken = await collectionA.mintToken(alice);81 expect((await targetToken.getChildren()).length).to.be.equal(0, 'Children length check at creation');8283 // Create a nested NFT token84 const tokenA = await collectionA.mintToken(alice, targetToken.nestingAccount());85 expect(await targetToken.getChildren()).to.have.deep.members([86 {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},87 ], 'Children contents check at nesting #1').and.be.length(1, 'Children length check at nesting #1');8889 // Create then nest90 const tokenB = await collectionA.mintToken(alice);91 await tokenB.nest(alice, targetToken);92 expect(await targetToken.getChildren()).to.have.deep.members([93 {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},94 {tokenId: tokenB.tokenId, collectionId: collectionA.collectionId},95 ], 'Children contents check at nesting #2').and.be.length(2, 'Children length check at nesting #2');9697 // Move token B to a different user outside the nesting tree98 await tokenB.unnest(alice, targetToken, {Substrate: bob.address});99 expect(await targetToken.getChildren()).to.be.have.deep.members([100 {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},101 ], 'Children contents check at nesting #3 (unnesting)').and.be.length(1, 'Children length check at nesting #3 (unnesting)');102103 // Create a fungible token in another collection and then nest104 await collectionB.mint(alice, 10n);105 await collectionB.transfer(alice, targetToken.nestingAccount(), 2n);106 expect(await targetToken.getChildren()).to.be.have.deep.members([107 {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},108 {tokenId: 0, collectionId: collectionB.collectionId},109 ], 'Children contents check at nesting #4 (from another collection)')110 .and.be.length(2, 'Children length check at nesting #4 (from another collection)');111112 // Move part of the fungible token inside token A deeper in the nesting tree113 await collectionB.transferFrom(alice, targetToken.nestingAccount(), tokenA.nestingAccount(), 1n);114 expect(await targetToken.getChildren()).to.be.have.deep.members([115 {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},116 {tokenId: 0, collectionId: collectionB.collectionId},117 ], 'Children contents check at nesting #5 (deeper)').and.be.length(2, 'Children length check at nesting #5 (deeper)');118 expect(await tokenA.getChildren()).to.be.have.deep.members([119 {tokenId: 0, collectionId: collectionB.collectionId},120 ], 'Children contents check at nesting #5.5 (deeper)').and.be.length(1, 'Children length check at nesting #5.5 (deeper)');121122 // Move the remaining part of the fungible token inside token A deeper in the nesting tree123 await collectionB.transferFrom(alice, targetToken.nestingAccount(), tokenA.nestingAccount(), 1n);124 expect(await targetToken.getChildren()).to.be.have.deep.members([125 {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},126 ], 'Children contents check at nesting #6 (deeper)').and.be.length(1, 'Children length check at nesting #6 (deeper)');127 expect(await tokenA.getChildren()).to.be.have.deep.members([128 {tokenId: 0, collectionId: collectionB.collectionId},129 ], 'Children contents check at nesting #6.5 (deeper)').and.be.length(1, 'Children length check at nesting #6.5 (deeper)');130 });131});132133describe('Integration Test: Various token type nesting', () => {134 let alice: IKeyringPair;135 let bob: IKeyringPair;136 let charlie: IKeyringPair;137138 before(async () => {139 await usingPlaygrounds(async (helper, privateKey) => {140 const donor = await privateKey({filename: __filename});141 [alice, bob, charlie] = await helper.arrange.createAccounts([50n, 10n, 10n], donor);142 });143 });144145 itSub('Admin (NFT): allows an Admin to nest a token', async ({helper}) => {146 const collection = await helper.nft.mintCollection(alice, {permissions: {nesting: {collectionAdmin: true}}});147 await collection.addAdmin(alice, {Substrate: bob.address});148 const targetToken = await collection.mintToken(alice, {Substrate: charlie.address});149150 // Create an immediately nested token151 const nestedToken = await collection.mintToken(bob, targetToken.nestingAccount());152 expect(await nestedToken.getTopmostOwner()).to.be.deep.equal({Substrate: charlie.address});153 expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());154155 // Create a token to be nested and nest156 const newToken = await collection.mintToken(bob);157 await newToken.nest(bob, targetToken);158 expect(await newToken.getTopmostOwner()).to.be.deep.equal({Substrate: charlie.address});159 expect(await newToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());160 });161162 itSub('Admin (NFT): Admin and Token Owner can operate together', async ({helper}) => {163 const collection = await helper.nft.mintCollection(alice, {permissions: {nesting: {collectionAdmin: true, tokenOwner: true}}});164 await collection.addAdmin(alice, {Substrate: bob.address});165 const targetToken = await collection.mintToken(alice, {Substrate: charlie.address});166167 // Create an immediately nested token by an administrator168 const nestedToken = await collection.mintToken(bob, targetToken.nestingAccount());169 expect(await nestedToken.getTopmostOwner()).to.be.deep.equal({Substrate: charlie.address});170 expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());171172 // Create a token to be nested and nest173 const newToken = await collection.mintToken(alice, {Substrate: charlie.address});174 await newToken.nest(charlie, targetToken);175 expect(await newToken.getTopmostOwner()).to.be.deep.equal({Substrate: charlie.address});176 expect(await newToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());177 });178179 itSub('Admin (NFT): allows an Admin to nest a token (Restricted nesting)', async ({helper}) => {180 const collectionA = await helper.nft.mintCollection(alice);181 await collectionA.addAdmin(alice, {Substrate: bob.address});182 const collectionB = await helper.nft.mintCollection(alice);183 await collectionB.addAdmin(alice, {Substrate: bob.address});184 await collectionA.setPermissions(alice, {nesting: {collectionAdmin: true, restricted:[collectionB.collectionId]}});185 const targetToken = await collectionA.mintToken(alice, {Substrate: charlie.address});186187 // Create an immediately nested token188 const nestedToken = await collectionB.mintToken(bob, targetToken.nestingAccount());189 expect(await nestedToken.getTopmostOwner()).to.be.deep.equal({Substrate: charlie.address});190 expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());191192 // Create a token to be nested and nest193 const newToken = await collectionB.mintToken(bob);194 await newToken.nest(bob, targetToken);195 expect(await newToken.getTopmostOwner()).to.be.deep.equal({Substrate: charlie.address});196 expect(await newToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());197 });198199 // ---------- Non-Fungible ----------200201 itSub('NFT: allows an Owner to nest/unnest their token', async ({helper}) => {202 const collection = await helper.nft.mintCollection(alice, {permissions: {access: 'AllowList', mintMode: true, nesting: {tokenOwner: true}}});203 await collection.addToAllowList(alice, {Substrate: charlie.address});204 const targetToken = await collection.mintToken(charlie);205 await collection.addToAllowList(alice, targetToken.nestingAccount());206207 // Create an immediately nested token208 const nestedToken = await collection.mintToken(charlie, targetToken.nestingAccount());209 expect(await nestedToken.getTopmostOwner()).to.be.deep.equal({Substrate: charlie.address});210 expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());211212 // Create a token to be nested and nest213 const newToken = await collection.mintToken(charlie);214 await newToken.nest(charlie, targetToken);215 expect(await newToken.getTopmostOwner()).to.be.deep.equal({Substrate: charlie.address});216 expect(await newToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());217 });218219 itSub('NFT: allows an Owner to nest/unnest their token (Restricted nesting)', async ({helper}) => {220 const collectionA = await helper.nft.mintCollection(alice);221 const collectionB = await helper.nft.mintCollection(alice);222 //await collectionB.addAdmin(alice, {Substrate: bob.address});223 const targetToken = await collectionA.mintToken(alice, {Substrate: charlie.address});224225 await collectionA.setPermissions(alice, {access: 'AllowList', mintMode: true, nesting: {tokenOwner: true, restricted:[collectionB.collectionId]}});226 await collectionA.addToAllowList(alice, {Substrate: charlie.address});227 await collectionA.addToAllowList(alice, targetToken.nestingAccount());228229 await collectionB.setPermissions(alice, {access: 'AllowList', mintMode: true});230 await collectionB.addToAllowList(alice, {Substrate: charlie.address});231 await collectionB.addToAllowList(alice, targetToken.nestingAccount());232233 // Create an immediately nested token234 const nestedToken = await collectionB.mintToken(charlie, targetToken.nestingAccount());235 expect(await nestedToken.getTopmostOwner()).to.be.deep.equal({Substrate: charlie.address});236 expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());237238 // Create a token to be nested and nest239 const newToken = await collectionB.mintToken(charlie);240 await newToken.nest(charlie, targetToken);241 expect(await newToken.getTopmostOwner()).to.be.deep.equal({Substrate: charlie.address});242 expect(await newToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());243 });244245 // ---------- Fungible ----------246247 itSub('Fungible: allows an Owner to nest/unnest their token', async ({helper}) => {248 const collectionNFT = await helper.nft.mintCollection(alice, {permissions: {access: 'AllowList', mintMode: true, nesting: {tokenOwner: true}}});249 const collectionFT = await helper.ft.mintCollection(alice);250 const targetToken = await collectionNFT.mintToken(alice, {Substrate: charlie.address});251252 await collectionNFT.addToAllowList(alice, {Substrate: charlie.address});253 await collectionNFT.addToAllowList(alice, targetToken.nestingAccount());254255 await collectionFT.setPermissions(alice, {access: 'AllowList', mintMode: true});256 await collectionFT.addToAllowList(alice, {Substrate: charlie.address});257 await collectionFT.addToAllowList(alice, targetToken.nestingAccount());258259 // Create an immediately nested token260 await collectionFT.mint(charlie, 5n, targetToken.nestingAccount());261 expect(await collectionFT.getBalance(targetToken.nestingAccount())).to.be.equal(5n);262263 // Create a token to be nested and nest264 await collectionFT.mint(charlie, 5n);265 await collectionFT.transfer(charlie, targetToken.nestingAccount(), 2n);266 expect(await collectionFT.getBalance(targetToken.nestingAccount())).to.be.equal(7n);267 });268269 itSub('Fungible: allows an Owner to nest/unnest their token (Restricted nesting)', async ({helper}) => {270 const collectionNFT = await helper.nft.mintCollection(alice);271 const collectionFT = await helper.ft.mintCollection(alice);272 const targetToken = await collectionNFT.mintToken(alice, {Substrate: charlie.address});273274 await collectionNFT.setPermissions(alice, {access: 'AllowList', mintMode: true, nesting: {tokenOwner: true, restricted:[collectionFT.collectionId]}});275 await collectionNFT.addToAllowList(alice, {Substrate: charlie.address});276 await collectionNFT.addToAllowList(alice, targetToken.nestingAccount());277278 await collectionFT.setPermissions(alice, {access: 'AllowList', mintMode: true});279 await collectionFT.addToAllowList(alice, {Substrate: charlie.address});280 await collectionFT.addToAllowList(alice, targetToken.nestingAccount());281282 // Create an immediately nested token283 await collectionFT.mint(charlie, 5n, targetToken.nestingAccount());284 expect(await collectionFT.getBalance(targetToken.nestingAccount())).to.be.equal(5n);285286 // Create a token to be nested and nest287 await collectionFT.mint(charlie, 5n);288 await collectionFT.transfer(charlie, targetToken.nestingAccount(), 2n);289 expect(await collectionFT.getBalance(targetToken.nestingAccount())).to.be.equal(7n);290 });291292 // ---------- Re-Fungible ----------293294 itSub.ifWithPallets('ReFungible: allows an Owner to nest/unnest their token', [Pallets.ReFungible], async ({helper}) => {295 const collectionNFT = await helper.nft.mintCollection(alice, {permissions: {access: 'AllowList', mintMode: true, nesting: {tokenOwner: true}}});296 const collectionRFT = await helper.rft.mintCollection(alice);297 const targetToken = await collectionNFT.mintToken(alice, {Substrate: charlie.address});298299 await collectionNFT.addToAllowList(alice, {Substrate: charlie.address});300 await collectionNFT.addToAllowList(alice, targetToken.nestingAccount());301302 await collectionRFT.setPermissions(alice, {access: 'AllowList', mintMode: true});303 await collectionRFT.addToAllowList(alice, {Substrate: charlie.address});304 await collectionRFT.addToAllowList(alice, targetToken.nestingAccount());305306 // Create an immediately nested token307 const nestedToken = await collectionRFT.mintToken(charlie, 5n, targetToken.nestingAccount());308 expect(await nestedToken.getBalance(targetToken.nestingAccount())).to.be.equal(5n);309310 // Create a token to be nested and nest311 const newToken = await collectionRFT.mintToken(charlie, 5n);312 await newToken.transfer(charlie, targetToken.nestingAccount(), 2n);313 expect(await newToken.getBalance(targetToken.nestingAccount())).to.be.equal(2n);314 });315316 itSub.ifWithPallets('ReFungible: allows an Owner to nest/unnest their token (Restricted nesting)', [Pallets.ReFungible], async ({helper}) => {317 const collectionNFT = await helper.nft.mintCollection(alice);318 const collectionRFT = await helper.rft.mintCollection(alice);319 const targetToken = await collectionNFT.mintToken(alice, {Substrate: charlie.address});320321 await collectionNFT.setPermissions(alice, {access: 'AllowList', mintMode: true, nesting: {tokenOwner: true, restricted:[collectionRFT.collectionId]}});322 await collectionNFT.addToAllowList(alice, {Substrate: charlie.address});323 await collectionNFT.addToAllowList(alice, targetToken.nestingAccount());324325 await collectionRFT.setPermissions(alice, {access: 'AllowList', mintMode: true});326 await collectionRFT.addToAllowList(alice, {Substrate: charlie.address});327 await collectionRFT.addToAllowList(alice, targetToken.nestingAccount());328329 // Create an immediately nested token330 const nestedToken = await collectionRFT.mintToken(charlie, 5n, targetToken.nestingAccount());331 expect(await nestedToken.getBalance(targetToken.nestingAccount())).to.be.equal(5n);332333 // Create a token to be nested and nest334 const newToken = await collectionRFT.mintToken(charlie, 5n);335 await newToken.transfer(charlie, targetToken.nestingAccount(), 2n);336 expect(await newToken.getBalance(targetToken.nestingAccount())).to.be.equal(2n);337 });338});339340describe('Negative Test: Nesting', () => {341 let alice: IKeyringPair;342 let bob: IKeyringPair;343344 before(async () => {345 await usingPlaygrounds(async (helper, privateKey) => {346 const donor = await privateKey({filename: __filename});347 [alice, bob] = await helper.arrange.createAccounts([100n, 50n], donor);348 });349 });350351 itSub('Disallows excessive token nesting', async ({helper}) => {352 const collection = await helper.nft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true}}});353 let token = await collection.mintToken(alice);354355 const maxNestingLevel = 5;356357 // Create a nested-token matryoshka358 for (let i = 0; i < maxNestingLevel; i++) {359 token = await collection.mintToken(alice, token.nestingAccount());360 }361362 // The nesting depth is limited by `maxNestingLevel`363 await expect(collection.mintToken(alice, token.nestingAccount()))364 .to.be.rejectedWith(/structure\.DepthLimit/);365 expect(await token.getTopmostOwner()).to.be.deep.equal({Substrate: alice.address});366 expect(await token.getChildren()).to.be.length(0);367 });368369 // ---------- Admin ------------370371 itSub('Admin (NFT): disallows an Admin to operate nesting when only TokenOwner is allowed', async ({helper}) => {372 const collection = await helper.nft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true}}});373 await collection.addAdmin(alice, {Substrate: bob.address});374 const targetToken = await collection.mintToken(alice);375376 // Try to create an immediately nested token as collection admin when it's disallowed377 await expect(collection.mintToken(bob, targetToken.nestingAccount()))378 .to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);379380 // Try to create a token to be nested and nest381 const newToken = await collection.mintToken(bob);382 await expect(newToken.nest(bob, targetToken))383 .to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);384385 expect(await targetToken.getChildren()).to.be.length(0);386 expect(await newToken.getOwner()).to.be.deep.equal({Substrate: bob.address});387 });388389 itSub('Admin (NFT): disallows a Token Owner to operate nesting when only Admin is allowed', async ({helper}) => {390 const collection = await helper.nft.mintCollection(alice, {permissions: {access: 'AllowList', mintMode: true, nesting: {collectionAdmin: true}}});391 const targetToken = await collection.mintToken(alice, {Substrate: bob.address});392 await collection.addToAllowList(alice, {Substrate: bob.address});393 await collection.addToAllowList(alice, targetToken.nestingAccount());394395 // Try to create a nested token as token owner when it's disallowed396 await expect(collection.mintToken(bob, targetToken.nestingAccount()))397 .to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);398399 // Try to create a token to be nested and nest400 const newToken = await collection.mintToken(bob);401 await expect(newToken.nest(bob, targetToken))402 .to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);403404 expect(await targetToken.getChildren()).to.be.length(0);405 expect(await newToken.getOwner()).to.be.deep.equal({Substrate: bob.address});406 });407408 itSub('Admin (NFT): disallows an Admin to unnest someone else\'s token', async ({helper}) => {409 const collection = await helper.nft.mintCollection(alice, {limits: {ownerCanTransfer: true}, permissions: {access: 'AllowList', mintMode: true, nesting: {collectionAdmin: true}}});410 //await collection.addAdmin(alice, {Substrate: bob.address});411 const targetToken = await collection.mintToken(alice, {Substrate: bob.address});412 await collection.addToAllowList(alice, {Substrate: bob.address});413 await collection.addToAllowList(alice, targetToken.nestingAccount());414415 // Try to nest somebody else's token416 const newToken = await collection.mintToken(bob);417 await expect(newToken.nest(alice, targetToken))418 .to.be.rejectedWith(/common\.NoPermission/);419420 // Try to unnest a token belonging to someone else as collection admin421 const nestedToken = await collection.mintToken(alice, targetToken.nestingAccount());422 await expect(nestedToken.unnest(alice, targetToken, {Substrate: bob.address}))423 .to.be.rejectedWith(/common\.AddressNotInAllowlist/);424425 expect(await targetToken.getChildren()).to.be.length(1);426 expect(await nestedToken.getTopmostOwner()).to.be.deep.equal({Substrate: bob.address});427 expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());428 });429430 itSub('Admin (NFT): disallows an Admin to nest a token from an unlisted collection (Restricted nesting)', async ({helper}) => {431 const collectionA = await helper.nft.mintCollection(alice);432 const collectionB = await helper.nft.mintCollection(alice);433 await collectionA.setPermissions(alice, {nesting: {collectionAdmin: true, restricted: [collectionA.collectionId]}});434 const targetToken = await collectionA.mintToken(alice);435436 // Try to create a nested token from another collection437 await expect(collectionB.mintToken(alice, targetToken.nestingAccount()))438 .to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);439440 // Create a token in another collection yet to be nested and try to nest441 const newToken = await collectionB.mintToken(alice);442 await expect(newToken.nest(alice, targetToken))443 .to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);444445 expect(await targetToken.getChildren()).to.be.length(0);446 expect(await newToken.getOwner()).to.be.deep.equal({Substrate: alice.address});447 });448449 // ---------- Non-Fungible ----------450451 itSub('NFT: disallows to nest token if nesting is disabled', async ({helper}) => {452 // Collection is implicitly not allowed nesting at creation453 const collection = await helper.nft.mintCollection(alice);454 const targetToken = await collection.mintToken(alice);455456 // Try to create a nested token as token owner when it's disallowed457 await expect(collection.mintToken(alice, targetToken.nestingAccount()))458 .to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);459460 // Try to create a token to be nested and nest461 const newToken = await collection.mintToken(alice);462 await expect(newToken.nest(alice, targetToken))463 .to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);464465 expect(await targetToken.getChildren()).to.be.length(0);466 expect(await newToken.getOwner()).to.be.deep.equal({Substrate: alice.address});467 });468469 itSub('NFT: disallows a non-Owner to nest someone else\'s token', async ({helper}) => {470 const collection = await helper.nft.mintCollection(alice);471 const targetToken = await collection.mintToken(alice);472473 await collection.setPermissions(alice, {access: 'AllowList', mintMode: true, nesting: {tokenOwner: true}});474 await collection.addToAllowList(alice, {Substrate: bob.address});475 await collection.addToAllowList(alice, targetToken.nestingAccount());476477 // Try to create a token to be nested and nest478 const newToken = await collection.mintToken(alice);479 await expect(newToken.nest(bob, targetToken)).to.be.rejectedWith(/common\.NoPermission/);480481 expect(await targetToken.getChildren()).to.be.length(0);482 expect(await newToken.getOwner()).to.be.deep.equal({Substrate: alice.address});483 });484485 itSub('NFT: disallows a non-Owner to nest someone else\'s token (Restricted nesting)', async ({helper}) => {486 const collection = await helper.nft.mintCollection(alice);487 const targetToken = await collection.mintToken(alice);488489 await collection.setPermissions(alice, {access: 'AllowList', mintMode: true, nesting: {tokenOwner: true}});490 await collection.addToAllowList(alice, {Substrate: bob.address});491 await collection.addToAllowList(alice, targetToken.nestingAccount());492493 const collectionB = await helper.nft.mintCollection(alice, {permissions: {access: 'AllowList', mintMode: true}});494 await collectionB.addToAllowList(alice, {Substrate: bob.address});495 await collectionB.addToAllowList(alice, targetToken.nestingAccount());496497 // Try to create a token to be nested and nest498 const newToken = await collectionB.mintToken(alice);499 await expect(newToken.nest(bob, targetToken)).to.be.rejectedWith(/common\.NoPermission/);500501 expect(await targetToken.getChildren()).to.be.length(0);502 expect(await newToken.getOwner()).to.be.deep.equal({Substrate: alice.address});503 });504505 itSub('NFT: disallows to nest token in an unlisted collection', async ({helper}) => {506 // Create collection with restricted nesting -- even self is not allowed507 const collection = await helper.nft.mintCollection(alice, {permissions: {access: 'AllowList', mintMode: true, nesting: {tokenOwner: true, restricted: []}}});508 const targetToken = await collection.mintToken(alice, {Substrate: bob.address});509510 await collection.addToAllowList(alice, {Substrate: bob.address});511 await collection.addToAllowList(alice, targetToken.nestingAccount());512513 // Try to mint in own collection after allowlisting the accounts514 await expect(collection.mintToken(bob, targetToken.nestingAccount()))515 .to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);516 });517518 // ---------- Fungible ----------519520 itSub('Fungible: disallows to nest token if nesting is disabled', async ({helper}) => {521 const collectionNFT = await helper.nft.mintCollection(alice);522 const collectionFT = await helper.ft.mintCollection(alice);523 const targetToken = await collectionNFT.mintToken(alice);524525 // Try to create an immediately nested token526 await expect(collectionFT.mint(alice, 5n, targetToken.nestingAccount()))527 .to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);528529 // Try to create a token to be nested and nest530 await collectionFT.mint(alice, 5n);531 await expect(collectionFT.transfer(alice, targetToken.nestingAccount(), 2n))532 .to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);533 expect(await collectionFT.getBalance({Substrate: alice.address})).to.be.equal(5n);534 });535536 itSub('Fungible: disallows a non-Owner to unnest someone else\'s token', async ({helper}) => {537 const collectionNFT = await helper.nft.mintCollection(alice, {permissions: {nesting: {collectionAdmin: true, tokenOwner: true}}});538 const collectionFT = await helper.ft.mintCollection(alice);539 const targetToken = await collectionNFT.mintToken(alice, {Substrate: bob.address});540541 // Nest some tokens as Alice into Bob's token542 await collectionFT.mint(alice, 5n, targetToken.nestingAccount());543544 // Try to pull it out545 await expect(collectionFT.transferFrom(alice, targetToken.nestingAccount(), {Substrate: bob.address}, 1n))546 .to.be.rejectedWith(/common\.ApprovedValueTooLow/);547 expect(await collectionFT.getBalance(targetToken.nestingAccount())).to.be.equal(5n);548 });549550 itSub('Fungible: disallows a non-Owner to unnest someone else\'s token (Restricted nesting)', async ({helper}) => {551 const collectionNFT = await helper.nft.mintCollection(alice);552 const collectionFT = await helper.ft.mintCollection(alice);553 const targetToken = await collectionNFT.mintToken(alice, {Substrate: bob.address});554555 await collectionNFT.setPermissions(alice, {nesting: {collectionAdmin: true, tokenOwner: true, restricted: [collectionFT.collectionId]}});556557 // Nest some tokens as Alice into Bob's token558 await collectionFT.mint(alice, 5n, targetToken.nestingAccount());559560 // Try to pull it out as Alice still561 await expect(collectionFT.transferFrom(alice, targetToken.nestingAccount(), {Substrate: bob.address}, 1n))562 .to.be.rejectedWith(/common\.ApprovedValueTooLow/);563 expect(await collectionFT.getBalance(targetToken.nestingAccount())).to.be.equal(5n);564 });565566 itSub('Fungible: disallows to nest token in an unlisted collection', async ({helper}) => {567 const collectionNFT = await helper.nft.mintCollection(alice, {permissions: {nesting: {collectionAdmin: true, tokenOwner: true, restricted: []}}});568 const collectionFT = await helper.ft.mintCollection(alice);569 const targetToken = await collectionNFT.mintToken(alice);570571 // Try to mint an immediately nested token572 await expect(collectionFT.mint(alice, 5n, targetToken.nestingAccount()))573 .to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);574575 // Mint a token and try to nest it576 await collectionFT.mint(alice, 5n);577 await expect(collectionFT.transfer(alice, targetToken.nestingAccount(), 1n))578 .to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);579580 expect(await collectionFT.getBalance(targetToken.nestingAccount())).to.be.equal(0n);581 expect(await collectionFT.getBalance({Substrate: alice.address})).to.be.equal(5n);582 });583584 // ---------- Re-Fungible ----------585586 itSub.ifWithPallets('ReFungible: disallows to nest token if nesting is disabled', [Pallets.ReFungible], async ({helper}) => {587 const collectionNFT = await helper.nft.mintCollection(alice);588 const collectionRFT = await helper.rft.mintCollection(alice);589 const targetToken = await collectionNFT.mintToken(alice);590591 // Try to create an immediately nested token592 await expect(collectionRFT.mintToken(alice, 5n, targetToken.nestingAccount()))593 .to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);594595 // Try to create a token to be nested and nest596 const token = await collectionRFT.mintToken(alice, 5n);597 await expect(token.transfer(alice, targetToken.nestingAccount(), 2n))598 .to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);599 expect(await token.getBalance({Substrate: alice.address})).to.be.equal(5n);600 });601602 itSub.ifWithPallets('ReFungible: disallows a non-Owner to nest someone else\'s token', [Pallets.ReFungible], async ({helper}) => {603 const collectionNFT = await helper.nft.mintCollection(alice);604 const collectionRFT = await helper.rft.mintCollection(alice);605 const targetToken = await collectionNFT.mintToken(alice);606607 await collectionNFT.setPermissions(alice, {access: 'AllowList', mintMode: true, nesting: {tokenOwner: true}});608 await collectionNFT.addToAllowList(alice, {Substrate: bob.address});609 await collectionNFT.addToAllowList(alice, targetToken.nestingAccount());610611 // Try to create a token to be nested and nest612 const newToken = await collectionRFT.mintToken(alice);613 await expect(newToken.transfer(bob, targetToken.nestingAccount())).to.be.rejectedWith(/common\.TokenValueTooLow/);614615 expect(await targetToken.getChildren()).to.be.length(0);616 expect(await newToken.getBalance({Substrate: alice.address})).to.be.equal(1n);617618 // Nest some tokens as Alice into Bob's token619 await newToken.transfer(alice, targetToken.nestingAccount());620621 // Try to pull it out622 await expect(newToken.transferFrom(bob, targetToken.nestingAccount(), {Substrate: alice.address}, 1n))623 .to.be.rejectedWith(/common\.ApprovedValueTooLow/);624 expect(await newToken.getBalance(targetToken.nestingAccount())).to.be.equal(1n);625 });626627 itSub.ifWithPallets('ReFungible: disallows a non-Owner to nest someone else\'s token (Restricted nesting)', [Pallets.ReFungible], async ({helper}) => {628 const collectionNFT = await helper.nft.mintCollection(alice);629 const collectionRFT = await helper.rft.mintCollection(alice);630 const targetToken = await collectionNFT.mintToken(alice);631632 await collectionNFT.setPermissions(alice, {access: 'AllowList', mintMode: true, nesting: {tokenOwner: true, restricted: [collectionRFT.collectionId]}});633 await collectionNFT.addToAllowList(alice, {Substrate: bob.address});634 await collectionNFT.addToAllowList(alice, targetToken.nestingAccount());635636 // Try to create a token to be nested and nest637 const newToken = await collectionRFT.mintToken(alice);638 await expect(newToken.transfer(bob, targetToken.nestingAccount())).to.be.rejectedWith(/common\.TokenValueTooLow/);639640 expect(await targetToken.getChildren()).to.be.length(0);641 expect(await newToken.getBalance({Substrate: alice.address})).to.be.equal(1n);642643 // Nest some tokens as Alice into Bob's token644 await newToken.transfer(alice, targetToken.nestingAccount());645646 // Try to pull it out647 await expect(newToken.transferFrom(bob, targetToken.nestingAccount(), {Substrate: alice.address}, 1n))648 .to.be.rejectedWith(/common\.ApprovedValueTooLow/);649 expect(await newToken.getBalance(targetToken.nestingAccount())).to.be.equal(1n);650 });651652 itSub.ifWithPallets('ReFungible: disallows to nest token to an unlisted collection', [Pallets.ReFungible], async ({helper}) => {653 const collectionNFT = await helper.nft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true, restricted: []}}});654 const collectionRFT = await helper.rft.mintCollection(alice);655 const targetToken = await collectionNFT.mintToken(alice);656657 // Try to create an immediately nested token658 await expect(collectionRFT.mintToken(alice, 5n, targetToken.nestingAccount()))659 .to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);660661 // Try to create a token to be nested and nest662 const token = await collectionRFT.mintToken(alice, 5n);663 await expect(token.transfer(alice, targetToken.nestingAccount(), 2n))664 .to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);665 expect(await token.getBalance({Substrate: alice.address})).to.be.equal(5n);666 });667});1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import {IKeyringPair} from '@polkadot/types/types';18import {expect, itSub, usingPlaygrounds} from '../util';1920describe('Integration Test: Composite nesting tests', () => {21 let alice: IKeyringPair;22 let bob: IKeyringPair;2324 before(async () => {25 await usingPlaygrounds(async (helper, privateKey) => {26 const donor = await privateKey({filename: __filename});27 [alice, bob] = await helper.arrange.createAccounts([50n, 10n], donor);28 });29 });3031 itSub('Performs the full suite: bundles a token, transfers, and unnests', async ({helper}) => {32 const collection = await helper.nft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true}}});33 const targetToken = await collection.mintToken(alice);3435 // Create an immediately nested token36 const nestedToken = await collection.mintToken(alice, targetToken.nestingAccount());37 expect(await nestedToken.getTopmostOwner()).to.be.deep.equal({Substrate: alice.address});38 expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());3940 // Create a token to be nested41 const newToken = await collection.mintToken(alice);4243 // Nest44 await newToken.nest(alice, targetToken);45 expect(await newToken.getTopmostOwner()).to.be.deep.equal({Substrate: alice.address});46 expect(await newToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());4748 // Move bundle to different user49 await targetToken.transfer(alice, {Substrate: bob.address});50 expect(await nestedToken.getTopmostOwner()).to.be.deep.equal({Substrate: bob.address});51 expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());52 expect(await newToken.getTopmostOwner()).to.be.deep.equal({Substrate: bob.address});53 expect(await newToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());5455 // Unnest56 await newToken.unnest(bob, targetToken, {Substrate: bob.address});57 expect(await newToken.getTopmostOwner()).to.be.deep.equal({Substrate: bob.address});58 expect(await newToken.getOwner()).to.be.deep.equal({Substrate: bob.address});59 });6061 itSub('Transfers an already bundled token', async ({helper}) => {62 const collection = await helper.nft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true}}});63 const tokenA = await collection.mintToken(alice);64 const tokenB = await collection.mintToken(alice);6566 // Create a nested token67 const tokenC = await collection.mintToken(alice, tokenA.nestingAccount());68 expect(await tokenC.getOwner()).to.be.deep.equal(tokenA.nestingAccount().toLowerCase());6970 // Transfer the nested token to another token71 await expect(tokenC.transferFrom(alice, tokenA.nestingAccount(), tokenB.nestingAccount())).to.be.fulfilled;72 expect(await tokenC.getTopmostOwner()).to.be.deep.equal({Substrate: alice.address});73 expect(await tokenC.getOwner()).to.be.deep.equal(tokenB.nestingAccount().toLowerCase());74 });7576 itSub('Checks token children', async ({helper}) => {77 const collectionA = await helper.nft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true}}});78 const collectionB = await helper.ft.mintCollection(alice);7980 const targetToken = await collectionA.mintToken(alice);81 expect((await targetToken.getChildren()).length).to.be.equal(0, 'Children length check at creation');8283 // Create a nested NFT token84 const tokenA = await collectionA.mintToken(alice, targetToken.nestingAccount());85 expect(await targetToken.getChildren()).to.have.deep.members([86 {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},87 ], 'Children contents check at nesting #1').and.be.length(1, 'Children length check at nesting #1');8889 // Create then nest90 const tokenB = await collectionA.mintToken(alice);91 await tokenB.nest(alice, targetToken);92 expect(await targetToken.getChildren()).to.have.deep.members([93 {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},94 {tokenId: tokenB.tokenId, collectionId: collectionA.collectionId},95 ], 'Children contents check at nesting #2').and.be.length(2, 'Children length check at nesting #2');9697 // Move token B to a different user outside the nesting tree98 await tokenB.unnest(alice, targetToken, {Substrate: bob.address});99 expect(await targetToken.getChildren()).to.be.have.deep.members([100 {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},101 ], 'Children contents check at nesting #3 (unnesting)').and.be.length(1, 'Children length check at nesting #3 (unnesting)');102103 // Create a fungible token in another collection and then nest104 await collectionB.mint(alice, 10n);105 await collectionB.transfer(alice, targetToken.nestingAccount(), 2n);106 expect(await targetToken.getChildren()).to.be.have.deep.members([107 {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},108 {tokenId: 0, collectionId: collectionB.collectionId},109 ], 'Children contents check at nesting #4 (from another collection)')110 .and.be.length(2, 'Children length check at nesting #4 (from another collection)');111112 // Move part of the fungible token inside token A deeper in the nesting tree113 await collectionB.transferFrom(alice, targetToken.nestingAccount(), tokenA.nestingAccount(), 1n);114 expect(await targetToken.getChildren()).to.be.have.deep.members([115 {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},116 {tokenId: 0, collectionId: collectionB.collectionId},117 ], 'Children contents check at nesting #5 (deeper)').and.be.length(2, 'Children length check at nesting #5 (deeper)');118 expect(await tokenA.getChildren()).to.be.have.deep.members([119 {tokenId: 0, collectionId: collectionB.collectionId},120 ], 'Children contents check at nesting #5.5 (deeper)').and.be.length(1, 'Children length check at nesting #5.5 (deeper)');121122 // Move the remaining part of the fungible token inside token A deeper in the nesting tree123 await collectionB.transferFrom(alice, targetToken.nestingAccount(), tokenA.nestingAccount(), 1n);124 expect(await targetToken.getChildren()).to.be.have.deep.members([125 {tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},126 ], 'Children contents check at nesting #6 (deeper)').and.be.length(1, 'Children length check at nesting #6 (deeper)');127 expect(await tokenA.getChildren()).to.be.have.deep.members([128 {tokenId: 0, collectionId: collectionB.collectionId},129 ], 'Children contents check at nesting #6.5 (deeper)').and.be.length(1, 'Children length check at nesting #6.5 (deeper)');130 });131});132133describe('Integration Test: Various token type nesting', () => {134 let alice: IKeyringPair;135 let bob: IKeyringPair;136 let charlie: IKeyringPair;137138 before(async () => {139 await usingPlaygrounds(async (helper, privateKey) => {140 const donor = await privateKey({filename: __filename});141 [alice, bob, charlie] = await helper.arrange.createAccounts([50n, 10n, 10n], donor);142 });143 });144145 itSub('Admin (NFT): allows an Admin to nest a token', async ({helper}) => {146 const collection = await helper.nft.mintCollection(alice, {permissions: {nesting: {collectionAdmin: true}}});147 await collection.addAdmin(alice, {Substrate: bob.address});148 const targetToken = await collection.mintToken(alice, {Substrate: charlie.address});149150 // Create an immediately nested token151 const nestedToken = await collection.mintToken(bob, targetToken.nestingAccount());152 expect(await nestedToken.getTopmostOwner()).to.be.deep.equal({Substrate: charlie.address});153 expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());154155 // Create a token to be nested and nest156 const newToken = await collection.mintToken(bob);157 await newToken.nest(bob, targetToken);158 expect(await newToken.getTopmostOwner()).to.be.deep.equal({Substrate: charlie.address});159 expect(await newToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());160 });161162 itSub('Admin (NFT): Admin and Token Owner can operate together', async ({helper}) => {163 const collection = await helper.nft.mintCollection(alice, {permissions: {nesting: {collectionAdmin: true, tokenOwner: true}}});164 await collection.addAdmin(alice, {Substrate: bob.address});165 const targetToken = await collection.mintToken(alice, {Substrate: charlie.address});166167 // Create an immediately nested token by an administrator168 const nestedToken = await collection.mintToken(bob, targetToken.nestingAccount());169 expect(await nestedToken.getTopmostOwner()).to.be.deep.equal({Substrate: charlie.address});170 expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());171172 // Create a token to be nested and nest173 const newToken = await collection.mintToken(alice, {Substrate: charlie.address});174 await newToken.nest(charlie, targetToken);175 expect(await newToken.getTopmostOwner()).to.be.deep.equal({Substrate: charlie.address});176 expect(await newToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());177 });178179 itSub('Admin (NFT): allows an Admin to nest a token (Restricted nesting)', async ({helper}) => {180 const collectionA = await helper.nft.mintCollection(alice);181 await collectionA.addAdmin(alice, {Substrate: bob.address});182 const collectionB = await helper.nft.mintCollection(alice);183 await collectionB.addAdmin(alice, {Substrate: bob.address});184 await collectionA.setPermissions(alice, {nesting: {collectionAdmin: true, restricted:[collectionB.collectionId]}});185 const targetToken = await collectionA.mintToken(alice, {Substrate: charlie.address});186187 // Create an immediately nested token188 const nestedToken = await collectionB.mintToken(bob, targetToken.nestingAccount());189 expect(await nestedToken.getTopmostOwner()).to.be.deep.equal({Substrate: charlie.address});190 expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());191192 // Create a token to be nested and nest193 const newToken = await collectionB.mintToken(bob);194 await newToken.nest(bob, targetToken);195 expect(await newToken.getTopmostOwner()).to.be.deep.equal({Substrate: charlie.address});196 expect(await newToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());197 });198199 // ---------- Non-Fungible ----------200201 itSub('NFT: allows an Owner to nest/unnest their token', async ({helper}) => {202 const collection = await helper.nft.mintCollection(alice, {permissions: {access: 'AllowList', mintMode: true, nesting: {tokenOwner: true}}});203 await collection.addToAllowList(alice, {Substrate: charlie.address});204 const targetToken = await collection.mintToken(charlie);205 await collection.addToAllowList(alice, targetToken.nestingAccount());206207 // Create an immediately nested token208 const nestedToken = await collection.mintToken(charlie, targetToken.nestingAccount());209 expect(await nestedToken.getTopmostOwner()).to.be.deep.equal({Substrate: charlie.address});210 expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());211212 // Create a token to be nested and nest213 const newToken = await collection.mintToken(charlie);214 await newToken.nest(charlie, targetToken);215 expect(await newToken.getTopmostOwner()).to.be.deep.equal({Substrate: charlie.address});216 expect(await newToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());217 });218219 itSub('NFT: allows an Owner to nest/unnest their token (Restricted nesting)', async ({helper}) => {220 const collectionA = await helper.nft.mintCollection(alice);221 const collectionB = await helper.nft.mintCollection(alice);222 //await collectionB.addAdmin(alice, {Substrate: bob.address});223 const targetToken = await collectionA.mintToken(alice, {Substrate: charlie.address});224225 await collectionA.setPermissions(alice, {access: 'AllowList', mintMode: true, nesting: {tokenOwner: true, restricted:[collectionB.collectionId]}});226 await collectionA.addToAllowList(alice, {Substrate: charlie.address});227 await collectionA.addToAllowList(alice, targetToken.nestingAccount());228229 await collectionB.setPermissions(alice, {access: 'AllowList', mintMode: true});230 await collectionB.addToAllowList(alice, {Substrate: charlie.address});231 await collectionB.addToAllowList(alice, targetToken.nestingAccount());232233 // Create an immediately nested token234 const nestedToken = await collectionB.mintToken(charlie, targetToken.nestingAccount());235 expect(await nestedToken.getTopmostOwner()).to.be.deep.equal({Substrate: charlie.address});236 expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());237238 // Create a token to be nested and nest239 const newToken = await collectionB.mintToken(charlie);240 await newToken.nest(charlie, targetToken);241 expect(await newToken.getTopmostOwner()).to.be.deep.equal({Substrate: charlie.address});242 expect(await newToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());243 });244245 // ---------- Fungible ----------246247 itSub('Fungible: allows an Owner to nest/unnest their token', async ({helper}) => {248 const collectionNFT = await helper.nft.mintCollection(alice, {permissions: {access: 'AllowList', mintMode: true, nesting: {tokenOwner: true}}});249 const collectionFT = await helper.ft.mintCollection(alice);250 const targetToken = await collectionNFT.mintToken(alice, {Substrate: charlie.address});251252 await collectionNFT.addToAllowList(alice, {Substrate: charlie.address});253 await collectionNFT.addToAllowList(alice, targetToken.nestingAccount());254255 await collectionFT.setPermissions(alice, {access: 'AllowList', mintMode: true});256 await collectionFT.addToAllowList(alice, {Substrate: charlie.address});257 await collectionFT.addToAllowList(alice, targetToken.nestingAccount());258259 // Create an immediately nested token260 await collectionFT.mint(charlie, 5n, targetToken.nestingAccount());261 expect(await collectionFT.getBalance(targetToken.nestingAccount())).to.be.equal(5n);262263 // Create a token to be nested and nest264 await collectionFT.mint(charlie, 5n);265 await collectionFT.transfer(charlie, targetToken.nestingAccount(), 2n);266 expect(await collectionFT.getBalance(targetToken.nestingAccount())).to.be.equal(7n);267 });268269 itSub('Fungible: allows an Owner to nest/unnest their token (Restricted nesting)', async ({helper}) => {270 const collectionNFT = await helper.nft.mintCollection(alice);271 const collectionFT = await helper.ft.mintCollection(alice);272 const targetToken = await collectionNFT.mintToken(alice, {Substrate: charlie.address});273274 await collectionNFT.setPermissions(alice, {access: 'AllowList', mintMode: true, nesting: {tokenOwner: true, restricted:[collectionFT.collectionId]}});275 await collectionNFT.addToAllowList(alice, {Substrate: charlie.address});276 await collectionNFT.addToAllowList(alice, targetToken.nestingAccount());277278 await collectionFT.setPermissions(alice, {access: 'AllowList', mintMode: true});279 await collectionFT.addToAllowList(alice, {Substrate: charlie.address});280 await collectionFT.addToAllowList(alice, targetToken.nestingAccount());281282 // Create an immediately nested token283 await collectionFT.mint(charlie, 5n, targetToken.nestingAccount());284 expect(await collectionFT.getBalance(targetToken.nestingAccount())).to.be.equal(5n);285286 // Create a token to be nested and nest287 await collectionFT.mint(charlie, 5n);288 await collectionFT.transfer(charlie, targetToken.nestingAccount(), 2n);289 expect(await collectionFT.getBalance(targetToken.nestingAccount())).to.be.equal(7n);290 });291});292293describe('Negative Test: Nesting', () => {294 let alice: IKeyringPair;295 let bob: IKeyringPair;296297 before(async () => {298 await usingPlaygrounds(async (helper, privateKey) => {299 const donor = await privateKey({filename: __filename});300 [alice, bob] = await helper.arrange.createAccounts([100n, 50n], donor);301 });302 });303304 itSub('Disallows excessive token nesting', async ({helper}) => {305 const collection = await helper.nft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true}}});306 let token = await collection.mintToken(alice);307308 const maxNestingLevel = 5;309310 // Create a nested-token matryoshka311 for (let i = 0; i < maxNestingLevel; i++) {312 token = await collection.mintToken(alice, token.nestingAccount());313 }314315 // The nesting depth is limited by `maxNestingLevel`316 await expect(collection.mintToken(alice, token.nestingAccount()))317 .to.be.rejectedWith(/structure\.DepthLimit/);318 expect(await token.getTopmostOwner()).to.be.deep.equal({Substrate: alice.address});319 expect(await token.getChildren()).to.be.length(0);320 });321322 // ---------- Admin ------------323324 itSub('Admin (NFT): disallows an Admin to operate nesting when only TokenOwner is allowed', async ({helper}) => {325 const collection = await helper.nft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true}}});326 await collection.addAdmin(alice, {Substrate: bob.address});327 const targetToken = await collection.mintToken(alice);328329 // Try to create an immediately nested token as collection admin when it's disallowed330 await expect(collection.mintToken(bob, targetToken.nestingAccount()))331 .to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);332333 // Try to create a token to be nested and nest334 const newToken = await collection.mintToken(bob);335 await expect(newToken.nest(bob, targetToken))336 .to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);337338 expect(await targetToken.getChildren()).to.be.length(0);339 expect(await newToken.getOwner()).to.be.deep.equal({Substrate: bob.address});340 });341342 itSub('Admin (NFT): disallows a Token Owner to operate nesting when only Admin is allowed', async ({helper}) => {343 const collection = await helper.nft.mintCollection(alice, {permissions: {access: 'AllowList', mintMode: true, nesting: {collectionAdmin: true}}});344 const targetToken = await collection.mintToken(alice, {Substrate: bob.address});345 await collection.addToAllowList(alice, {Substrate: bob.address});346 await collection.addToAllowList(alice, targetToken.nestingAccount());347348 // Try to create a nested token as token owner when it's disallowed349 await expect(collection.mintToken(bob, targetToken.nestingAccount()))350 .to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);351352 // Try to create a token to be nested and nest353 const newToken = await collection.mintToken(bob);354 await expect(newToken.nest(bob, targetToken))355 .to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);356357 expect(await targetToken.getChildren()).to.be.length(0);358 expect(await newToken.getOwner()).to.be.deep.equal({Substrate: bob.address});359 });360361 itSub('Admin (NFT): disallows an Admin to unnest someone else\'s token', async ({helper}) => {362 const collection = await helper.nft.mintCollection(alice, {limits: {ownerCanTransfer: true}, permissions: {access: 'AllowList', mintMode: true, nesting: {collectionAdmin: true}}});363 //await collection.addAdmin(alice, {Substrate: bob.address});364 const targetToken = await collection.mintToken(alice, {Substrate: bob.address});365 await collection.addToAllowList(alice, {Substrate: bob.address});366 await collection.addToAllowList(alice, targetToken.nestingAccount());367368 // Try to nest somebody else's token369 const newToken = await collection.mintToken(bob);370 await expect(newToken.nest(alice, targetToken))371 .to.be.rejectedWith(/common\.NoPermission/);372373 // Try to unnest a token belonging to someone else as collection admin374 const nestedToken = await collection.mintToken(alice, targetToken.nestingAccount());375 await expect(nestedToken.unnest(alice, targetToken, {Substrate: bob.address}))376 .to.be.rejectedWith(/common\.AddressNotInAllowlist/);377378 expect(await targetToken.getChildren()).to.be.length(1);379 expect(await nestedToken.getTopmostOwner()).to.be.deep.equal({Substrate: bob.address});380 expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());381 });382383 itSub('Admin (NFT): disallows an Admin to nest a token from an unlisted collection (Restricted nesting)', async ({helper}) => {384 const collectionA = await helper.nft.mintCollection(alice);385 const collectionB = await helper.nft.mintCollection(alice);386 await collectionA.setPermissions(alice, {nesting: {collectionAdmin: true, restricted: [collectionA.collectionId]}});387 const targetToken = await collectionA.mintToken(alice);388389 // Try to create a nested token from another collection390 await expect(collectionB.mintToken(alice, targetToken.nestingAccount()))391 .to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);392393 // Create a token in another collection yet to be nested and try to nest394 const newToken = await collectionB.mintToken(alice);395 await expect(newToken.nest(alice, targetToken))396 .to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);397398 expect(await targetToken.getChildren()).to.be.length(0);399 expect(await newToken.getOwner()).to.be.deep.equal({Substrate: alice.address});400 });401402 // ---------- Non-Fungible ----------403404 itSub('NFT: disallows to nest token if nesting is disabled', async ({helper}) => {405 // Collection is implicitly not allowed nesting at creation406 const collection = await helper.nft.mintCollection(alice);407 const targetToken = await collection.mintToken(alice);408409 // Try to create a nested token as token owner when it's disallowed410 await expect(collection.mintToken(alice, targetToken.nestingAccount()))411 .to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);412413 // Try to create a token to be nested and nest414 const newToken = await collection.mintToken(alice);415 await expect(newToken.nest(alice, targetToken))416 .to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);417418 expect(await targetToken.getChildren()).to.be.length(0);419 expect(await newToken.getOwner()).to.be.deep.equal({Substrate: alice.address});420 });421422 itSub('NFT: disallows a non-Owner to nest someone else\'s token', async ({helper}) => {423 const collection = await helper.nft.mintCollection(alice);424 const targetToken = await collection.mintToken(alice);425426 await collection.setPermissions(alice, {access: 'AllowList', mintMode: true, nesting: {tokenOwner: true}});427 await collection.addToAllowList(alice, {Substrate: bob.address});428 await collection.addToAllowList(alice, targetToken.nestingAccount());429430 // Try to create a token to be nested and nest431 const newToken = await collection.mintToken(alice);432 await expect(newToken.nest(bob, targetToken)).to.be.rejectedWith(/common\.NoPermission/);433434 expect(await targetToken.getChildren()).to.be.length(0);435 expect(await newToken.getOwner()).to.be.deep.equal({Substrate: alice.address});436 });437438 itSub('NFT: disallows a non-Owner to nest someone else\'s token (Restricted nesting)', async ({helper}) => {439 const collection = await helper.nft.mintCollection(alice);440 const targetToken = await collection.mintToken(alice);441442 await collection.setPermissions(alice, {access: 'AllowList', mintMode: true, nesting: {tokenOwner: true}});443 await collection.addToAllowList(alice, {Substrate: bob.address});444 await collection.addToAllowList(alice, targetToken.nestingAccount());445446 const collectionB = await helper.nft.mintCollection(alice, {permissions: {access: 'AllowList', mintMode: true}});447 await collectionB.addToAllowList(alice, {Substrate: bob.address});448 await collectionB.addToAllowList(alice, targetToken.nestingAccount());449450 // Try to create a token to be nested and nest451 const newToken = await collectionB.mintToken(alice);452 await expect(newToken.nest(bob, targetToken)).to.be.rejectedWith(/common\.NoPermission/);453454 expect(await targetToken.getChildren()).to.be.length(0);455 expect(await newToken.getOwner()).to.be.deep.equal({Substrate: alice.address});456 });457458 itSub('NFT: disallows to nest token in an unlisted collection', async ({helper}) => {459 // Create collection with restricted nesting -- even self is not allowed460 const collection = await helper.nft.mintCollection(alice, {permissions: {access: 'AllowList', mintMode: true, nesting: {tokenOwner: true, restricted: []}}});461 const targetToken = await collection.mintToken(alice, {Substrate: bob.address});462463 await collection.addToAllowList(alice, {Substrate: bob.address});464 await collection.addToAllowList(alice, targetToken.nestingAccount());465466 // Try to mint in own collection after allowlisting the accounts467 await expect(collection.mintToken(bob, targetToken.nestingAccount()))468 .to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);469 });470471 // ---------- Fungible ----------472473 itSub('Fungible: disallows to nest token if nesting is disabled', async ({helper}) => {474 const collectionNFT = await helper.nft.mintCollection(alice);475 const collectionFT = await helper.ft.mintCollection(alice);476 const targetToken = await collectionNFT.mintToken(alice);477478 // Try to create an immediately nested token479 await expect(collectionFT.mint(alice, 5n, targetToken.nestingAccount()))480 .to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);481482 // Try to create a token to be nested and nest483 await collectionFT.mint(alice, 5n);484 await expect(collectionFT.transfer(alice, targetToken.nestingAccount(), 2n))485 .to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);486 expect(await collectionFT.getBalance({Substrate: alice.address})).to.be.equal(5n);487 });488489 itSub('Fungible: disallows a non-Owner to unnest someone else\'s token', async ({helper}) => {490 const collectionNFT = await helper.nft.mintCollection(alice, {permissions: {nesting: {collectionAdmin: true, tokenOwner: true}}});491 const collectionFT = await helper.ft.mintCollection(alice);492 const targetToken = await collectionNFT.mintToken(alice, {Substrate: bob.address});493494 // Nest some tokens as Alice into Bob's token495 await collectionFT.mint(alice, 5n, targetToken.nestingAccount());496497 // Try to pull it out498 await expect(collectionFT.transferFrom(alice, targetToken.nestingAccount(), {Substrate: bob.address}, 1n))499 .to.be.rejectedWith(/common\.ApprovedValueTooLow/);500 expect(await collectionFT.getBalance(targetToken.nestingAccount())).to.be.equal(5n);501 });502503 itSub('Fungible: disallows a non-Owner to unnest someone else\'s token (Restricted nesting)', async ({helper}) => {504 const collectionNFT = await helper.nft.mintCollection(alice);505 const collectionFT = await helper.ft.mintCollection(alice);506 const targetToken = await collectionNFT.mintToken(alice, {Substrate: bob.address});507508 await collectionNFT.setPermissions(alice, {nesting: {collectionAdmin: true, tokenOwner: true, restricted: [collectionFT.collectionId]}});509510 // Nest some tokens as Alice into Bob's token511 await collectionFT.mint(alice, 5n, targetToken.nestingAccount());512513 // Try to pull it out as Alice still514 await expect(collectionFT.transferFrom(alice, targetToken.nestingAccount(), {Substrate: bob.address}, 1n))515 .to.be.rejectedWith(/common\.ApprovedValueTooLow/);516 expect(await collectionFT.getBalance(targetToken.nestingAccount())).to.be.equal(5n);517 });518519 itSub('Fungible: disallows to nest token in an unlisted collection', async ({helper}) => {520 const collectionNFT = await helper.nft.mintCollection(alice, {permissions: {nesting: {collectionAdmin: true, tokenOwner: true, restricted: []}}});521 const collectionFT = await helper.ft.mintCollection(alice);522 const targetToken = await collectionNFT.mintToken(alice);523524 // Try to mint an immediately nested token525 await expect(collectionFT.mint(alice, 5n, targetToken.nestingAccount()))526 .to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);527528 // Mint a token and try to nest it529 await collectionFT.mint(alice, 5n);530 await expect(collectionFT.transfer(alice, targetToken.nestingAccount(), 1n))531 .to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);532533 expect(await collectionFT.getBalance(targetToken.nestingAccount())).to.be.equal(0n);534 expect(await collectionFT.getBalance({Substrate: alice.address})).to.be.equal(5n);535 });536});tests/src/refungible.test.tsdiffbeforeafterboth--- a/tests/src/refungible.test.ts
+++ b/tests/src/refungible.test.ts
@@ -88,20 +88,6 @@
expect((await token.getTop10Owners()).length).to.be.equal(10);
});
- itSub('Transfer token pieces', async ({helper}) => {
- const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
- const token = await collection.mintToken(alice, 100n);
-
- expect(await token.getBalance({Substrate: alice.address})).to.be.equal(100n);
- expect(await token.transfer(alice, {Substrate: bob.address}, 60n)).to.be.true;
-
- expect(await token.getBalance({Substrate: alice.address})).to.be.equal(40n);
- expect(await token.getBalance({Substrate: bob.address})).to.be.equal(60n);
-
- await expect(token.transfer(alice, {Substrate: bob.address}, 41n))
- .to.eventually.be.rejectedWith(/common\.TokenValueTooLow/);
- });
-
itSub('Create multiple tokens', async ({helper}) => {
const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
// TODO: fix mintMultipleTokens
@@ -118,56 +104,8 @@
const lastTokenId = await collection.getLastTokenId();
expect(lastTokenId).to.be.equal(3);
expect(await collection.getTokenBalance(lastTokenId, {Substrate: alice.address})).to.be.equal(100n);
- });
-
- itSub('Burn some pieces', async ({helper}) => {
- const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
- const token = await collection.mintToken(alice, 100n);
- expect(await collection.doesTokenExist(token.tokenId)).to.be.true;
- expect(await token.getBalance({Substrate: alice.address})).to.be.equal(100n);
- expect(await token.burn(alice, 99n)).to.be.true;
- expect(await collection.doesTokenExist(token.tokenId)).to.be.true;
- expect(await token.getBalance({Substrate: alice.address})).to.be.equal(1n);
});
- itSub('Burn all pieces', async ({helper}) => {
- const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
- const token = await collection.mintToken(alice, 100n);
-
- expect(await collection.doesTokenExist(token.tokenId)).to.be.true;
- expect(await token.getBalance({Substrate: alice.address})).to.be.equal(100n);
-
- expect(await token.burn(alice, 100n)).to.be.true;
- expect(await collection.doesTokenExist(token.tokenId)).to.be.false;
- });
-
- itSub('Burn some pieces for multiple users', async ({helper}) => {
- const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
- const token = await collection.mintToken(alice, 100n);
-
- expect(await collection.doesTokenExist(token.tokenId)).to.be.true;
-
- expect(await token.getBalance({Substrate: alice.address})).to.be.equal(100n);
- expect(await token.transfer(alice, {Substrate: bob.address}, 60n)).to.be.true;
-
- expect(await token.getBalance({Substrate: alice.address})).to.be.equal(40n);
- expect(await token.getBalance({Substrate: bob.address})).to.be.equal(60n);
-
- expect(await token.burn(alice, 40n)).to.be.true;
-
- expect(await collection.doesTokenExist(token.tokenId)).to.be.true;
- expect(await token.getBalance({Substrate: alice.address})).to.be.equal(0n);
-
- expect(await token.burn(bob, 59n)).to.be.true;
-
- expect(await token.getBalance({Substrate: bob.address})).to.be.equal(1n);
- expect(await collection.doesTokenExist(token.tokenId)).to.be.true;
-
- expect(await token.burn(bob, 1n)).to.be.true;
-
- expect(await collection.doesTokenExist(token.tokenId)).to.be.false;
- });
-
itSub('Set allowance for token', async ({helper}) => {
const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
const token = await collection.mintToken(alice, 100n);
@@ -183,68 +121,6 @@
expect(await token.getApprovedPieces({Substrate: alice.address}, {Substrate: bob.address})).to.be.equal(40n);
});
- itSub('Repartition', async ({helper}) => {
- const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
- const token = await collection.mintToken(alice, 100n);
-
- expect(await token.repartition(alice, 200n)).to.be.true;
- expect(await token.getBalance({Substrate: alice.address})).to.be.equal(200n);
- expect(await token.getTotalPieces()).to.be.equal(200n);
-
- expect(await token.transfer(alice, {Substrate: bob.address}, 110n)).to.be.true;
- expect(await token.getBalance({Substrate: alice.address})).to.be.equal(90n);
- expect(await token.getBalance({Substrate: bob.address})).to.be.equal(110n);
-
- await expect(token.repartition(alice, 80n))
- .to.eventually.be.rejectedWith(/refungible\.RepartitionWhileNotOwningAllPieces/);
-
- expect(await token.transfer(alice, {Substrate: bob.address}, 90n)).to.be.true;
- expect(await token.getBalance({Substrate: alice.address})).to.be.equal(0n);
- expect(await token.getBalance({Substrate: bob.address})).to.be.equal(200n);
-
- expect(await token.repartition(bob, 150n)).to.be.true;
- await expect(token.transfer(bob, {Substrate: alice.address}, 160n))
- .to.eventually.be.rejectedWith(/common\.TokenValueTooLow/);
- });
-
- itSub('Repartition with increased amount', async ({helper}) => {
- const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
- const token = await collection.mintToken(alice, 100n);
- await token.repartition(alice, 200n);
- const chainEvents = helper.chainLog.slice(-1)[0].events;
- const event = chainEvents.find((event: any) => event.section === 'common' && event.method === 'ItemCreated');
- expect(event).to.deep.include({
- section: 'common',
- method: 'ItemCreated',
- index: [66, 2],
- data: [
- collection.collectionId,
- token.tokenId,
- {substrate: alice.address},
- 100n,
- ],
- });
- });
-
- itSub('Repartition with decreased amount', async ({helper}) => {
- const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
- const token = await collection.mintToken(alice, 100n);
- await token.repartition(alice, 50n);
- const chainEvents = helper.chainLog.slice(-1)[0].events;
- const event = chainEvents.find((event: any) => event.section === 'common' && event.method === 'ItemDestroyed');
- expect(event).to.deep.include({
- section: 'common',
- method: 'ItemDestroyed',
- index: [66, 3],
- data: [
- collection.collectionId,
- token.tokenId,
- {substrate: alice.address},
- 50n,
- ],
- });
- });
-
itSub('Create new collection with properties', async ({helper}) => {
const properties = [{key: 'key1', value: 'val1'}];
const tokenPropertyPermissions = [{key: 'key1', permission: {tokenOwner: true, mutable: false, collectionAdmin: true}}];
@@ -252,46 +128,5 @@
const info = await collection.getData();
expect(info?.raw.properties).to.be.deep.equal(properties);
expect(info?.raw.tokenPropertyPermissions).to.be.deep.equal(tokenPropertyPermissions);
- });
-});
-
-describe('Refungible negative tests', () => {
- let donor: IKeyringPair;
- let alice: IKeyringPair;
- let bob: IKeyringPair;
- let charlie: IKeyringPair;
-
- before(async function() {
- await usingPlaygrounds(async (helper, privateKey) => {
- requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);
-
- donor = await privateKey({filename: __filename});
- [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);
- });
- });
-
- itSub('Cannot transfer incorrect amount of token pieces', async ({helper}) => {
- const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
- const tokenAlice = await collection.mintToken(alice, 10n, {Substrate: alice.address});
- const tokenBob = await collection.mintToken(alice, 10n, {Substrate: bob.address});
-
- // 1. Alice cannot transfer Bob's token:
- await expect(tokenBob.transfer(alice, {Substrate: charlie.address}, 0n)).to.be.rejectedWith('common.TokenValueTooLow');
- await expect(tokenBob.transfer(alice, {Substrate: charlie.address}, 1n)).to.be.rejectedWith('common.TokenValueTooLow');
- await expect(tokenBob.transfer(alice, {Substrate: charlie.address}, 10n)).to.be.rejectedWith('common.TokenValueTooLow');
- await expect(tokenBob.transfer(alice, {Substrate: charlie.address}, 100n)).to.be.rejectedWith('common.TokenValueTooLow');
-
- // 2. Alice cannot transfer non-existing token:
- await expect(collection.transferToken(alice, 100, {Substrate: charlie.address}, 0n)).to.be.rejectedWith('common.TokenValueTooLow');
- await expect(collection.transferToken(alice, 100, {Substrate: charlie.address}, 1n)).to.be.rejectedWith('common.TokenValueTooLow');
-
- // 3. Zero transfer allowed (EIP-20):
- await tokenAlice.transfer(alice, {Substrate: charlie.address}, 0n);
-
- expect(await tokenAlice.getTop10Owners()).to.deep.eq([{Substrate: alice.address}]);
- expect(await tokenBob.getTop10Owners()).to.deep.eq([{Substrate: bob.address}]);
- expect(await tokenAlice.getBalance({Substrate: alice.address})).to.eq(10n);
- expect(await tokenBob.getBalance({Substrate: bob.address})).to.eq(10n);
- expect(await tokenBob.getBalance({Substrate: charlie.address})).to.eq(0n);
});
});
tests/src/sub/refungible/burn.test.tsdiffbeforeafterboth--- /dev/null
+++ b/tests/src/sub/refungible/burn.test.ts
@@ -0,0 +1,127 @@
+// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
+// This file is part of Unique Network.
+
+// Unique Network is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// Unique Network is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
+
+import {IKeyringPair} from '@polkadot/types/types';
+import {itSub, Pallets, requirePalletsOrSkip, usingPlaygrounds, expect} from '../../util';
+
+describe('Refungible: burn', () => {
+ let donor: IKeyringPair;
+ let alice: IKeyringPair;
+ let bob: IKeyringPair;
+
+ before(async function() {
+ await usingPlaygrounds(async (helper, privateKey) => {
+ requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);
+
+ donor = await privateKey({filename: __filename});
+ [alice, bob] = await helper.arrange.createAccounts([100n, 10n], donor);
+ });
+ });
+
+ itSub('can burn some pieces', async ({helper}) => {
+ const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
+ const token = await collection.mintToken(alice, 100n);
+ expect(await collection.doesTokenExist(token.tokenId)).to.be.true;
+ expect(await token.getBalance({Substrate: alice.address})).to.be.equal(100n);
+ await token.burn(alice, 99n);
+ expect(await collection.doesTokenExist(token.tokenId)).to.be.true;
+ expect(await token.getBalance({Substrate: alice.address})).to.be.equal(1n);
+ });
+
+ itSub('can burn all pieces', async ({helper}) => {
+ const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
+ const token = await collection.mintToken(alice, 100n);
+
+ expect(await collection.doesTokenExist(token.tokenId)).to.be.true;
+ expect(await token.getBalance({Substrate: alice.address})).to.be.equal(100n);
+
+ await token.burn(alice, 100n);
+ expect(await collection.doesTokenExist(token.tokenId)).to.be.false;
+ });
+
+ itSub('burn pieces for multiple users', async ({helper}) => {
+ const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
+ const token = await collection.mintToken(alice, 100n);
+
+ await token.transfer(alice, {Substrate: bob.address}, 60n);
+
+ expect(await token.getBalance({Substrate: alice.address})).to.be.equal(40n);
+ expect(await token.getBalance({Substrate: bob.address})).to.be.equal(60n);
+
+ await token.burn(alice, 40n);
+
+ expect(await collection.doesTokenExist(token.tokenId)).to.be.true;
+ expect(await token.getBalance({Substrate: alice.address})).to.be.equal(0n);
+
+ await token.burn(bob, 59n);
+
+ expect(await token.getBalance({Substrate: bob.address})).to.be.equal(1n);
+ expect(await collection.doesTokenExist(token.tokenId)).to.be.true;
+
+ await token.burn(bob, 1n);
+
+ expect(await collection.doesTokenExist(token.tokenId)).to.be.false;
+ });
+
+ itSub('burn pieces by admin', async function({helper}) {
+ const collection = await helper.rft.mintCollection(alice);
+ await collection.setLimits(alice, {ownerCanTransfer: true});
+ await collection.addAdmin(alice, {Substrate: bob.address});
+ const token = await collection.mintToken(alice, 100n);
+
+ await token.burnFrom(bob, {Substrate: alice.address}, 100n);
+ expect(await token.doesExist()).to.be.false;
+ });
+});
+
+describe('Refungible: burn negative tests', () => {
+ let donor: IKeyringPair;
+ let alice: IKeyringPair;
+ let bob: IKeyringPair;
+
+ before(async function() {
+ await usingPlaygrounds(async (helper, privateKey) => {
+ requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);
+ donor = await privateKey({filename: __filename});
+ [alice, bob] = await helper.arrange.createAccounts([100n, 100n], donor);
+ });
+ });
+
+ itSub('cannot burn non-owned token pieces', async ({helper}) => {
+ const collection = await helper.rft.mintCollection(alice);
+ const aliceToken = await collection.mintToken(alice, 10n, {Substrate: alice.address});
+ const bobToken = await collection.mintToken(alice, 10n, {Substrate: bob.address});
+
+ // 1. Cannot burn non-owned token:
+ await expect(bobToken.burn(alice, 0n)).to.be.rejectedWith('common.TokenValueTooLow');
+ await expect(bobToken.burn(alice, 5n)).to.be.rejectedWith('common.TokenValueTooLow');
+ // 2. Cannot burn non-existing token:
+ await expect(helper.rft.burnToken(alice, 99999, 10)).to.be.rejectedWith('common.CollectionNotFound');
+ await expect(helper.rft.burnToken(alice, collection.collectionId, 99999)).to.be.rejectedWith('common.TokenValueTooLow');
+ // 3. Can burn zero amount of owned tokens (EIP-20)
+ await aliceToken.burn(alice, 0n);
+
+ // 4. Storage is not corrupted:
+ expect(await aliceToken.getTop10Owners()).to.deep.eq([{Substrate: alice.address}]);
+ expect(await bobToken.getTop10Owners()).to.deep.eq([{Substrate: bob.address}]);
+
+ // 4.1 Tokens can be transfered:
+ await aliceToken.transfer(alice, {Substrate: bob.address}, 10n);
+ await bobToken.transfer(bob, {Substrate: alice.address}, 10n);
+ expect(await aliceToken.getTop10Owners()).to.deep.eq([{Substrate: bob.address}]);
+ expect(await bobToken.getTop10Owners()).to.deep.eq([{Substrate: alice.address}]);
+ });
+});
tests/src/sub/refungible/nesting.test.tsdiffbeforeafterboth--- /dev/null
+++ b/tests/src/sub/refungible/nesting.test.ts
@@ -0,0 +1,180 @@
+// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
+// This file is part of Unique Network.
+
+// Unique Network is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// Unique Network is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
+
+import {IKeyringPair} from '@polkadot/types/types';
+import {expect, itSub, Pallets, requirePalletsOrSkip, usingPlaygrounds} from '../../util';
+
+describe('Refungible nesting', () => {
+ let alice: IKeyringPair;
+ let charlie: IKeyringPair;
+
+ before(async function() {
+ await usingPlaygrounds(async (helper, privateKey) => {
+ requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);
+ const donor = await privateKey({filename: __filename});
+ [alice, charlie] = await helper.arrange.createAccounts([50n, 10n], donor);
+ });
+ });
+
+ [
+ {restrictedMode: true},
+ {restrictedMode: false},
+ ].map(testCase => {
+ itSub(`Owner can nest their token${testCase.restrictedMode ? ': Restricted mode' : ''}`, async ({helper}) => {
+ const collectionNFT = await helper.nft.mintCollection(alice, {permissions: {access: 'AllowList', mintMode: true, nesting: {tokenOwner: true}}});
+ const collectionRFT = await helper.rft.mintCollection(alice);
+ const targetToken = await collectionNFT.mintToken(alice, {Substrate: charlie.address});
+
+ await collectionNFT.setPermissions(alice, {access: 'AllowList', mintMode: true, nesting: {tokenOwner: true, restricted: testCase.restrictedMode ? [collectionRFT.collectionId] : null}});
+ await collectionNFT.addToAllowList(alice, {Substrate: charlie.address});
+ await collectionNFT.addToAllowList(alice, targetToken.nestingAccount());
+
+ await collectionRFT.setPermissions(alice, {access: 'AllowList', mintMode: true});
+ await collectionRFT.addToAllowList(alice, {Substrate: charlie.address});
+ await collectionRFT.addToAllowList(alice, targetToken.nestingAccount());
+
+ // Create an immediately nested token
+ const nestedToken = await collectionRFT.mintToken(charlie, 5n, targetToken.nestingAccount());
+ expect(await nestedToken.getBalance(targetToken.nestingAccount())).to.be.equal(5n);
+
+ // Create a token to be nested and nest
+ const newToken = await collectionRFT.mintToken(charlie, 5n);
+ await newToken.transfer(charlie, targetToken.nestingAccount(), 2n);
+ expect(await newToken.getBalance(targetToken.nestingAccount())).to.be.equal(2n);
+ expect(await newToken.getBalance({Substrate: charlie.address})).to.be.equal(3n);
+ });
+ });
+
+ itSub('Owner can unnest nested token', async ({helper}) => {
+ const collection = await helper.nft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true}}});
+ const targetToken = await collection.mintToken(alice);
+
+ // Owner mints nested RFT token:
+ const collectionRFT = await helper.rft.mintCollection(alice);
+ const token = await collectionRFT.mintToken(alice, 10n, targetToken.nestingAccount());
+
+ // 1.1 Owner can partially unnest token pieces with transferFrom:
+ await token.transferFrom(alice, targetToken.nestingAccount(), {Substrate: alice.address}, 9n);
+ expect(await token.getBalance({Substrate: alice.address})).to.be.equal(9n);
+ expect(await token.getBalance(targetToken.nestingAccount())).to.be.equal(1n);
+
+ // 1.2 Owner can unnest all pieces:
+ await token.transferFrom(alice, targetToken.nestingAccount(), {Substrate: alice.address}, 1n);
+ expect(await token.getBalance({Substrate: alice.address})).to.be.equal(10n);
+ expect(await token.getBalance(targetToken.nestingAccount())).to.be.equal(0n);
+ });
+
+ itSub('Owner can burn nested token pieces', async ({helper}) => {
+ const collection = await helper.nft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true}}});
+ const targetToken = await collection.mintToken(alice);
+
+ // Owner mints nested RFT token:
+ const collectionRFT = await helper.rft.mintCollection(alice);
+ const token = await collectionRFT.mintToken(alice, 100n, {Substrate: alice.address});
+ await token.transfer(alice, targetToken.nestingAccount(), 30n);
+
+ // 1.1 Owner can partially burnFrom nested pieces:
+ await token.burnFrom(alice, targetToken.nestingAccount(), 10n);
+ expect(await token.getBalance({Substrate: alice.address})).to.be.equal(70n);
+ expect(await token.getBalance(targetToken.nestingAccount())).to.be.equal(20n);
+ expect(await targetToken.getChildren()).to.has.length(1);
+
+ // 1.1 Owner can burnFrom all nested pieces:
+ await token.burnFrom(alice, targetToken.nestingAccount(), 20n);
+ expect(await token.getBalance(targetToken.nestingAccount())).to.be.equal(0n);
+ expect(await targetToken.getChildren()).to.has.length(0);
+ expect(await token.doesExist()).to.be.true;
+
+ // 2. Target token does not contain any pieces and can be burnt:
+ await targetToken.burn(alice);
+ expect(await targetToken.doesExist()).to.be.false;
+ });
+});
+
+describe('Refungible nesting negative tests', () => {
+ let alice: IKeyringPair;
+ let bob: IKeyringPair;
+
+ before(async function() {
+ await usingPlaygrounds(async (helper, privateKey) => {
+ requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);
+ const donor = await privateKey({filename: __filename});
+ [alice, bob] = await helper.arrange.createAccounts([100n, 50n], donor);
+ });
+ });
+
+ itSub('cannot nest token if nesting is disabled', async ({helper}) => {
+ const collectionNFT = await helper.nft.mintCollection(alice);
+ const collectionRFT = await helper.rft.mintCollection(alice);
+ const targetToken = await collectionNFT.mintToken(alice);
+
+ // Try to create an immediately nested token
+ await expect(collectionRFT.mintToken(alice, 5n, targetToken.nestingAccount()))
+ .to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);
+
+ // Try to create a token to be nested and nest
+ const token = await collectionRFT.mintToken(alice, 5n);
+ await expect(token.transfer(alice, targetToken.nestingAccount(), 2n))
+ .to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);
+ expect(await token.getBalance({Substrate: alice.address})).to.be.equal(5n);
+ });
+
+ [
+ {restrictedMode: true},
+ {restrictedMode: false},
+ ].map(testCase => {
+ itSub(`non-Owner cannot nest someone else's token${testCase.restrictedMode ? ': Restricted mode' : ''}`, async ({helper}) => {
+ const collectionNFT = await helper.nft.mintCollection(alice);
+ const collectionRFT = await helper.rft.mintCollection(alice);
+ const targetToken = await collectionNFT.mintToken(alice);
+
+ await collectionNFT.setPermissions(alice, {access: 'AllowList', mintMode: true, nesting: {tokenOwner: true, restricted: testCase.restrictedMode ? [collectionRFT.collectionId] : null}});
+ await collectionNFT.addToAllowList(alice, {Substrate: bob.address});
+ await collectionNFT.addToAllowList(alice, targetToken.nestingAccount());
+
+ // Try to create a token to be nested and nest
+ const newToken = await collectionRFT.mintToken(alice);
+ await expect(newToken.transfer(bob, targetToken.nestingAccount())).to.be.rejectedWith(/common\.TokenValueTooLow/);
+
+ expect(await targetToken.getChildren()).to.be.length(0);
+ expect(await newToken.getBalance({Substrate: alice.address})).to.be.equal(1n);
+
+ // Nest some tokens as Alice into Bob's token
+ await newToken.transfer(alice, targetToken.nestingAccount());
+
+ // Try to pull it out
+ await expect(newToken.transferFrom(bob, targetToken.nestingAccount(), {Substrate: alice.address}, 1n))
+ .to.be.rejectedWith(/common\.ApprovedValueTooLow/);
+ expect(await newToken.getBalance(targetToken.nestingAccount())).to.be.equal(1n);
+ });
+ });
+
+ itSub('ReFungible: disallows to nest token to an unlisted collection', async ({helper}) => {
+ const collectionNFT = await helper.nft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true, restricted: []}}});
+ const collectionRFT = await helper.rft.mintCollection(alice);
+ const targetToken = await collectionNFT.mintToken(alice);
+
+ // Try to create an immediately nested token
+ await expect(collectionRFT.mintToken(alice, 5n, targetToken.nestingAccount()))
+ .to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);
+
+ // Try to create a token to be nested and nest
+ const token = await collectionRFT.mintToken(alice, 5n);
+ await expect(token.transfer(alice, targetToken.nestingAccount(), 2n))
+ .to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);
+ expect(await token.getBalance({Substrate: alice.address})).to.be.equal(5n);
+ });
+});
tests/src/sub/refungible/repartition.test.tsdiffbeforeafterboth--- /dev/null
+++ b/tests/src/sub/refungible/repartition.test.ts
@@ -0,0 +1,96 @@
+// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
+// This file is part of Unique Network.
+
+// Unique Network is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// Unique Network is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
+
+import {IKeyringPair} from '@polkadot/types/types';
+import {itSub, Pallets, requirePalletsOrSkip, usingPlaygrounds, expect} from '../../util';
+
+describe('integration test: Refungible functionality:', () => {
+ let donor: IKeyringPair;
+ let alice: IKeyringPair;
+ let bob: IKeyringPair;
+
+ before(async function() {
+ await usingPlaygrounds(async (helper, privateKey) => {
+ requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);
+
+ donor = await privateKey({filename: __filename});
+ [alice, bob] = await helper.arrange.createAccounts([100n, 10n], donor);
+ });
+ });
+
+ itSub('Repartition', async ({helper}) => {
+ const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
+ const token = await collection.mintToken(alice, 100n);
+
+ expect(await token.repartition(alice, 200n)).to.be.true;
+ expect(await token.getBalance({Substrate: alice.address})).to.be.equal(200n);
+ expect(await token.getTotalPieces()).to.be.equal(200n);
+
+ expect(await token.transfer(alice, {Substrate: bob.address}, 110n)).to.be.true;
+ expect(await token.getBalance({Substrate: alice.address})).to.be.equal(90n);
+ expect(await token.getBalance({Substrate: bob.address})).to.be.equal(110n);
+
+ await expect(token.repartition(alice, 80n))
+ .to.eventually.be.rejectedWith(/refungible\.RepartitionWhileNotOwningAllPieces/);
+
+ expect(await token.transfer(alice, {Substrate: bob.address}, 90n)).to.be.true;
+ expect(await token.getBalance({Substrate: alice.address})).to.be.equal(0n);
+ expect(await token.getBalance({Substrate: bob.address})).to.be.equal(200n);
+
+ expect(await token.repartition(bob, 150n)).to.be.true;
+ await expect(token.transfer(bob, {Substrate: alice.address}, 160n))
+ .to.eventually.be.rejectedWith(/common\.TokenValueTooLow/);
+ });
+
+ itSub('Repartition with increased amount', async ({helper}) => {
+ const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
+ const token = await collection.mintToken(alice, 100n);
+ await token.repartition(alice, 200n);
+ const chainEvents = helper.chainLog.slice(-1)[0].events;
+ const event = chainEvents.find((event: any) => event.section === 'common' && event.method === 'ItemCreated');
+ expect(event).to.deep.include({
+ section: 'common',
+ method: 'ItemCreated',
+ index: [66, 2],
+ data: [
+ collection.collectionId,
+ token.tokenId,
+ {substrate: alice.address},
+ 100n,
+ ],
+ });
+ });
+
+ itSub('Repartition with decreased amount', async ({helper}) => {
+ const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
+ const token = await collection.mintToken(alice, 100n);
+ await token.repartition(alice, 50n);
+ const chainEvents = helper.chainLog.slice(-1)[0].events;
+ const event = chainEvents.find((event: any) => event.section === 'common' && event.method === 'ItemDestroyed');
+ expect(event).to.deep.include({
+ section: 'common',
+ method: 'ItemDestroyed',
+ index: [66, 3],
+ data: [
+ collection.collectionId,
+ token.tokenId,
+ {substrate: alice.address},
+ 50n,
+ ],
+ });
+ });
+});
+
tests/src/sub/refungible/transfer.test.tsdiffbeforeafterboth--- /dev/null
+++ b/tests/src/sub/refungible/transfer.test.ts
@@ -0,0 +1,73 @@
+// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
+// This file is part of Unique Network.
+
+// Unique Network is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// Unique Network is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
+
+import {IKeyringPair} from '@polkadot/types/types';
+import {itSub, Pallets, requirePalletsOrSkip, usingPlaygrounds, expect} from '../../util';
+
+describe('Refungible transfer tests', () => {
+ let donor: IKeyringPair;
+ let alice: IKeyringPair;
+ let bob: IKeyringPair;
+ let charlie: IKeyringPair;
+
+ before(async function() {
+ await usingPlaygrounds(async (helper, privateKey) => {
+ requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);
+
+ donor = await privateKey({filename: __filename});
+ [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);
+ });
+ });
+
+ itSub('Can transfer token pieces', async ({helper}) => {
+ const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
+ const token = await collection.mintToken(alice, 100n);
+
+ expect(await token.transfer(alice, {Substrate: bob.address}, 60n)).to.be.true;
+ // 1. Can transfer less or equal than have:
+ expect(await token.getBalance({Substrate: alice.address})).to.be.equal(40n);
+ expect(await token.getBalance({Substrate: bob.address})).to.be.equal(60n);
+ });
+
+ itSub('Cannot transfer incorrect amount of token pieces', async ({helper}) => {
+ const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});
+ const tokenAlice = await collection.mintToken(alice, 10n, {Substrate: alice.address});
+ const tokenBob = await collection.mintToken(alice, 10n, {Substrate: bob.address});
+
+ // 1. Alice cannot transfer Bob's token:
+ await expect(tokenBob.transfer(alice, {Substrate: charlie.address}, 0n)).to.be.rejectedWith('common.TokenValueTooLow');
+ await expect(tokenBob.transfer(alice, {Substrate: charlie.address}, 1n)).to.be.rejectedWith('common.TokenValueTooLow');
+ await expect(tokenBob.transfer(alice, {Substrate: charlie.address}, 10n)).to.be.rejectedWith('common.TokenValueTooLow');
+ await expect(tokenBob.transfer(alice, {Substrate: charlie.address}, 100n)).to.be.rejectedWith('common.TokenValueTooLow');
+
+ // 2. Alice cannot transfer non-existing token:
+ await expect(collection.transferToken(alice, 100, {Substrate: charlie.address}, 0n)).to.be.rejectedWith('common.TokenValueTooLow');
+ await expect(collection.transferToken(alice, 100, {Substrate: charlie.address}, 1n)).to.be.rejectedWith('common.TokenValueTooLow');
+
+ // 3. Cannot transfer more than have:
+ await expect(tokenAlice.transfer(alice, {Substrate: bob.address}, 11n))
+ .to.eventually.be.rejectedWith(/common\.TokenValueTooLow/);
+
+ // 4. Zero transfer allowed (EIP-20):
+ await tokenAlice.transfer(alice, {Substrate: charlie.address}, 0n);
+
+ expect(await tokenAlice.getTop10Owners()).to.deep.eq([{Substrate: alice.address}]);
+ expect(await tokenBob.getTop10Owners()).to.deep.eq([{Substrate: bob.address}]);
+ expect(await tokenAlice.getBalance({Substrate: alice.address})).to.eq(10n);
+ expect(await tokenBob.getBalance({Substrate: bob.address})).to.eq(10n);
+ expect(await tokenBob.getBalance({Substrate: charlie.address})).to.eq(0n);
+ });
+});
\ No newline at end of file
tests/src/util/index.tsdiffbeforeafterboth--- a/tests/src/util/index.ts
+++ b/tests/src/util/index.ts
@@ -100,6 +100,9 @@
export const LOCKING_PERIOD = 12n; // 12 blocks of relay
export const UNLOCKING_PERIOD = 6n; // 6 blocks of parachain
+// Native contracts
+export const COLLECTION_HELPER = '0x6c4e9fe1ae37a41e93cee429e8e1881abdcbb54f';
+export const CONTRACT_HELPER = '0x842899ECF380553E8a4de75bF534cdf6fBF64049';
export enum Pallets {
Inflation = 'inflation',