difftreelog
Merge pull request #835 from UniqueNetwork/tests/generalization
in: master
20 files changed
tests/src/apiConsts.test.tsdiffbeforeafterboth15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.161617import {ApiPromise} from '@polkadot/api';17import {ApiPromise} from '@polkadot/api';18import {usingPlaygrounds, itSub, expect} from './util';18import {usingPlaygrounds, itSub, expect, COLLECTION_HELPER, CONTRACT_HELPER} from './util';1919202021const MAX_COLLECTION_DESCRIPTION_LENGTH = 256n;21const MAX_COLLECTION_DESCRIPTION_LENGTH = 256n;41 transfersEnabled: true,41 transfersEnabled: true,42};42};4344const EVM_COLLECTION_HELPERS_ADDRESS = '0x6c4e9fe1ae37a41e93cee429e8e1881abdcbb54f';45const HELPERS_CONTRACT_ADDRESS = '0x842899ECF380553E8a4de75bF534cdf6fBF64049';464347describe('integration test: API UNIQUE consts', () => {44describe('integration test: API UNIQUE consts', () => {48 let api: ApiPromise;45 let api: ApiPromise;106 });103 });107104108 itSub('HELPERS_CONTRACT_ADDRESS', () => {105 itSub('HELPERS_CONTRACT_ADDRESS', () => {109 expect(api.consts.evmContractHelpers.contractAddress.toString().toLowerCase()).to.be.equal(HELPERS_CONTRACT_ADDRESS.toLowerCase());106 expect(api.consts.evmContractHelpers.contractAddress.toString().toLowerCase()).to.be.equal(CONTRACT_HELPER.toLowerCase());110 });107 });111108112 itSub('EVM_COLLECTION_HELPERS_ADDRESS', () => {109 itSub('EVM_COLLECTION_HELPERS_ADDRESS', () => {113 expect(api.consts.common.contractAddress.toString().toLowerCase()).to.be.equal(EVM_COLLECTION_HELPERS_ADDRESS.toLowerCase());110 expect(api.consts.common.contractAddress.toString().toLowerCase()).to.be.equal(COLLECTION_HELPER.toLowerCase());114 });111 });115});112});116113tests/src/burnItem.test.tsdiffbeforeafterboth46 expect(await collection.getBalance({Substrate: alice.address})).to.eq(9n);46 expect(await collection.getBalance({Substrate: alice.address})).to.eq(9n);47 });47 });4849 itSub.ifWithPallets('Burn item in ReFungible collection', [Pallets.ReFungible], async function({helper}) {50 const collection = await helper.rft.mintCollection(alice);51 const token = await collection.mintToken(alice, 100n);5253 await token.burn(alice, 90n);54 expect(await token.getBalance({Substrate: alice.address})).to.eq(10n);5556 await token.burn(alice, 10n);57 expect(await token.getBalance({Substrate: alice.address})).to.eq(0n);58 });5960 itSub.ifWithPallets('Burn owned portion of item in ReFungible collection', [Pallets.ReFungible], async function({helper}) {61 const collection = await helper.rft.mintCollection(alice);62 const token = await collection.mintToken(alice, 100n);6364 await token.transfer(alice, {Substrate: bob.address}, 1n);6566 expect(await token.getBalance({Substrate: alice.address})).to.eq(99n);67 expect(await token.getBalance({Substrate: bob.address})).to.eq(1n);6869 await token.burn(bob, 1n);7071 expect(await token.getBalance({Substrate: alice.address})).to.eq(99n);72 expect(await token.getBalance({Substrate: bob.address})).to.eq(0n);73 });74});48});754976describe('integration test: ext. burnItem() with admin permissions:', () => {50describe('integration test: ext. burnItem() with admin permissions:', () => {105 expect(await collection.getBalance({Substrate: alice.address})).to.eq(9n);79 expect(await collection.getBalance({Substrate: alice.address})).to.eq(9n);106 });80 });107108 itSub.ifWithPallets('Burn item in ReFungible collection', [Pallets.ReFungible], async function({helper}) {109 const collection = await helper.rft.mintCollection(alice);110 await collection.setLimits(alice, {ownerCanTransfer: true});111 await collection.addAdmin(alice, {Substrate: bob.address});112 const token = await collection.mintToken(alice, 100n);113114 await token.burnFrom(bob, {Substrate: alice.address}, 100n);115 expect(await token.doesExist()).to.be.false;116 });117});81});11882119describe('Negative integration test: ext. burnItem():', () => {83describe('Negative integration test: ext. burnItem():', () => {140 await expect(token.burn(bob)).to.be.rejectedWith('common.NoPermission');104 await expect(token.burn(bob)).to.be.rejectedWith('common.NoPermission');141 });105 });142143 itSub.ifWithPallets('RFT: cannot burn non-owned token pieces', [Pallets.ReFungible], async ({helper}) => {144 const collection = await helper.rft.mintCollection(alice);145 const aliceToken = await collection.mintToken(alice, 10n, {Substrate: alice.address});146 const bobToken = await collection.mintToken(alice, 10n, {Substrate: bob.address});147148 // 1. Cannot burn non-owned token:149 await expect(bobToken.burn(alice, 0n)).to.be.rejectedWith('common.TokenValueTooLow');150 await expect(bobToken.burn(alice, 5n)).to.be.rejectedWith('common.TokenValueTooLow');151 // 2. Cannot burn non-existing token:152 await expect(helper.rft.burnToken(alice, 99999, 10)).to.be.rejectedWith('common.CollectionNotFound');153 await expect(helper.rft.burnToken(alice, collection.collectionId, 99999)).to.be.rejectedWith('common.TokenValueTooLow');154 // 3. Can burn zero amount of owned tokens (EIP-20)155 await aliceToken.burn(alice, 0n);156157 // 4. Storage is not corrupted:158 expect(await aliceToken.getTop10Owners()).to.deep.eq([{Substrate: alice.address}]);159 expect(await bobToken.getTop10Owners()).to.deep.eq([{Substrate: bob.address}]);160161 // 4.1 Tokens can be transfered:162 await aliceToken.transfer(alice, {Substrate: bob.address}, 10n);163 await bobToken.transfer(bob, {Substrate: alice.address}, 10n);164 expect(await aliceToken.getTop10Owners()).to.deep.eq([{Substrate: bob.address}]);165 expect(await bobToken.getTop10Owners()).to.deep.eq([{Substrate: alice.address}]);166 });167106168 itSub('Transfer a burned token', async ({helper}) => {107 itSub('Transfer a burned token', async ({helper}) => {169 const collection = await helper.nft.mintCollection(alice);108 const collection = await helper.nft.mintCollection(alice);tests/src/eth/collectionHelperAddress.test.tsdiffbeforeafterboth161617import {itEth, usingEthPlaygrounds, expect} from './util';17import {itEth, usingEthPlaygrounds, expect} from './util';18import {IKeyringPair} from '@polkadot/types/types';18import {IKeyringPair} from '@polkadot/types/types';19import {Pallets} from '../util';19import {COLLECTION_HELPER, Pallets} from '../util';2021const EVM_COLLECTION_HELPERS_ADDRESS = '0x6c4e9fe1ae37a41e93cee429e8e1881abdcbb54f';222023describe('[eth]CollectionHelperAddress test: ERC20/ERC721 ', () => {21describe('[eth]CollectionHelperAddress test: ERC20/ERC721 ', () => {24 let donor: IKeyringPair;22 let donor: IKeyringPair;36 const nftCollection = await helper.ethNativeContract.collection(nftCollectionAddress, 'nft', owner);34 const nftCollection = await helper.ethNativeContract.collection(nftCollectionAddress, 'nft', owner);373538 expect((await nftCollection.methods.collectionHelperAddress().call())36 expect((await nftCollection.methods.collectionHelperAddress().call())39 .toString().toLowerCase()).to.be.equal(EVM_COLLECTION_HELPERS_ADDRESS);37 .toString().toLowerCase()).to.be.equal(COLLECTION_HELPER);40 });38 });413942 itEth.ifWithPallets('RFT ', [Pallets.ReFungible], async ({helper}) => {40 itEth.ifWithPallets('RFT ', [Pallets.ReFungible], async ({helper}) => {464447 const rftCollection = await helper.ethNativeContract.collection(rftCollectionAddress, 'rft', owner);45 const rftCollection = await helper.ethNativeContract.collection(rftCollectionAddress, 'rft', owner);48 expect((await rftCollection.methods.collectionHelperAddress().call())46 expect((await rftCollection.methods.collectionHelperAddress().call())49 .toString().toLowerCase()).to.be.equal(EVM_COLLECTION_HELPERS_ADDRESS);47 .toString().toLowerCase()).to.be.equal(COLLECTION_HELPER);50 });48 });514952 itEth('FT', async ({helper}) => {50 itEth('FT', async ({helper}) => {56 const collection = await helper.ethNativeContract.collection(collectionAddress, 'ft', owner);54 const collection = await helper.ethNativeContract.collection(collectionAddress, 'ft', owner);575558 expect((await collection.methods.collectionHelperAddress().call())56 expect((await collection.methods.collectionHelperAddress().call())59 .toString().toLowerCase()).to.be.equal(EVM_COLLECTION_HELPERS_ADDRESS);57 .toString().toLowerCase()).to.be.equal(COLLECTION_HELPER);60 });58 });615962 itEth('[collectionHelpers] convert collectionId into address', async ({helper}) => {60 itEth('[collectionHelpers] convert collectionId into address', async ({helper}) => {tests/src/eth/createNFTCollection.test.tsdiffbeforeafterboth18import {IKeyringPair} from '@polkadot/types/types';18import {IKeyringPair} from '@polkadot/types/types';19import {expect, itEth, usingEthPlaygrounds} from './util';19import {expect, itEth, usingEthPlaygrounds} from './util';20import {CollectionLimitField} from './util/playgrounds/types';20import {CollectionLimitField} from './util/playgrounds/types';21import {COLLECTION_HELPER} from '../util';2122222323describe('Create NFT collection from EVM', () => {24describe('Create NFT collection from EVM', () => {tests/src/eth/fungible.test.tsdiffbeforeafterboth17import {expect, itEth, usingEthPlaygrounds} from './util';17import {expect, itEth, usingEthPlaygrounds} from './util';18import {IKeyringPair} from '@polkadot/types/types';18import {IKeyringPair} from '@polkadot/types/types';1920describe('Fungible: Information getting', () => {21 let donor: IKeyringPair;22 let alice: IKeyringPair;2324 before(async function() {25 await usingEthPlaygrounds(async (helper, privateKey) => {26 donor = await privateKey({filename: __filename});27 [alice] = await helper.arrange.createAccounts([20n], donor);28 });29 });3031 itEth('totalSupply', async ({helper}) => {32 const caller = await helper.eth.createAccountWithBalance(donor);33 const collection = await helper.ft.mintCollection(alice);34 await collection.mint(alice, 200n);3536 const contract = await helper.ethNativeContract.collectionById(collection.collectionId, 'ft', caller);37 const totalSupply = await contract.methods.totalSupply().call();38 expect(totalSupply).to.equal('200');39 });4041 itEth('balanceOf', async ({helper}) => {42 const caller = await helper.eth.createAccountWithBalance(donor);43 const collection = await helper.ft.mintCollection(alice);44 await collection.mint(alice, 200n, {Ethereum: caller});4546 const contract = await helper.ethNativeContract.collectionById(collection.collectionId, 'ft', caller);47 const balance = await contract.methods.balanceOf(caller).call();48 expect(balance).to.equal('200');49 });50});511952describe('Fungible: Plain calls', () => {20describe('Fungible: Plain calls', () => {53 let donor: IKeyringPair;21 let donor: IKeyringPair;61 });29 });62 });30 });6364 itEth('Can perform mint()', async ({helper}) => {65 const owner = await helper.eth.createAccountWithBalance(donor);66 const receiver = helper.eth.createAccount();67 const collection = await helper.ft.mintCollection(alice);68 await collection.addAdmin(alice, {Ethereum: owner});6970 const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);71 const contract = await helper.ethNativeContract.collection(collectionAddress, 'ft', owner);7273 const result = await contract.methods.mint(receiver, 100).send();7475 const event = result.events.Transfer;76 expect(event.address).to.equal(collectionAddress);77 expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');78 expect(event.returnValues.to).to.equal(receiver);79 expect(event.returnValues.value).to.equal('100');80 });813182 [32 [83 'substrate' as const,33 'substrate' as const,tests/src/eth/getCode.test.tsdiffbeforeafterbothno changes
tests/src/eth/nonFungible.test.tsdiffbeforeafterboth20import {ITokenPropertyPermission} from '../util/playgrounds/types';20import {ITokenPropertyPermission} from '../util/playgrounds/types';212223describe('NFT: Information getting', () => {24 let donor: IKeyringPair;25 let alice: IKeyringPair;2627 before(async function() {28 await usingEthPlaygrounds(async (helper, privateKey) => {29 donor = await privateKey({filename: __filename});30 [alice] = await helper.arrange.createAccounts([10n], donor);31 });32 });3334 itEth('totalSupply', async ({helper}) => {35 const collection = await helper.nft.mintCollection(alice, {});36 await collection.mintToken(alice);3738 const caller = await helper.eth.createAccountWithBalance(donor);3940 const contract = await helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);41 const totalSupply = await contract.methods.totalSupply().call();4243 expect(totalSupply).to.equal('1');44 });4546 itEth('balanceOf', async ({helper}) => {47 const collection = await helper.nft.mintCollection(alice, {});48 const caller = await helper.eth.createAccountWithBalance(donor);4950 await collection.mintToken(alice, {Ethereum: caller});51 await collection.mintToken(alice, {Ethereum: caller});52 await collection.mintToken(alice, {Ethereum: caller});5354 const contract = await helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);55 const balance = await contract.methods.balanceOf(caller).call();5657 expect(balance).to.equal('3');58 });5960 itEth('ownerOf', async ({helper}) => {61 const collection = await helper.nft.mintCollection(alice, {});62 const caller = await helper.eth.createAccountWithBalance(donor);6364 const token = await collection.mintToken(alice, {Ethereum: caller});6566 const contract = await helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);6768 const owner = await contract.methods.ownerOf(token.tokenId).call();6970 expect(owner).to.equal(caller);71 });7273 itEth('name/symbol is available regardless of ERC721Metadata support', async ({helper}) => {74 const collection = await helper.nft.mintCollection(alice, {name: 'test', tokenPrefix: 'TEST'});75 const caller = helper.eth.createAccount();7677 const contract = await helper.ethNativeContract.collectionById(collection.collectionId, 'nft', caller);7879 expect(await contract.methods.name().call()).to.equal('test');80 expect(await contract.methods.symbol().call()).to.equal('TEST');81 });82});832184describe('Check ERC721 token URI for NFT', () => {22describe('Check ERC721 token URI for NFT', () => {85 let donor: IKeyringPair;23 let donor: IKeyringPair;150 });88 });151 });89 });152153 itEth('Can perform mint() & get crossOwner()', async ({helper}) => {154 const owner = await helper.eth.createAccountWithBalance(donor);155 const receiver = helper.eth.createAccount();156157 const {collectionAddress} = await helper.eth.createERC721MetadataCompatibleNFTCollection(owner, 'Mint collection', '6', '6', '');158 const contract = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner);159160 const result = await contract.methods.mintWithTokenURI(receiver, 'Test URI').send();161 const tokenId = result.events.Transfer.returnValues.tokenId;162 expect(tokenId).to.be.equal('1');163164 const event = result.events.Transfer;165 expect(event.address).to.be.equal(collectionAddress);166 expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');167 expect(event.returnValues.to).to.be.equal(receiver);168169 expect(await contract.methods.tokenURI(tokenId).call()).to.be.equal('Test URI');170 expect(await contract.methods.crossOwnerOf(tokenId).call()).to.be.like([receiver, '0']);171 // TODO: this wont work right now, need release 919000 first172 // await helper.methods.setOffchainSchema(collectionIdAddress, 'https://offchain-service.local/token-info/{id}').send();173 // const tokenUri = await contract.methods.tokenURI(nextTokenId).call();174 // expect(tokenUri).to.be.equal(`https://offchain-service.local/token-info/${nextTokenId}`);175 });17690177 // TODO combine all minting tests in one place91 // TODO combine all minting tests in one place178 [92 [tests/src/eth/reFungible.test.tsdiffbeforeafterboth19import {IKeyringPair} from '@polkadot/types/types';19import {IKeyringPair} from '@polkadot/types/types';20import {ITokenPropertyPermission} from '../util/playgrounds/types';20import {ITokenPropertyPermission} from '../util/playgrounds/types';2122describe('Refungible: Information getting', () => {23 let donor: IKeyringPair;2425 before(async function() {26 await usingEthPlaygrounds(async (helper, privateKey) => {27 requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);2829 donor = await privateKey({filename: __filename});30 });31 });3233 itEth('totalSupply', async ({helper}) => {34 const caller = await helper.eth.createAccountWithBalance(donor);35 const {collectionAddress} = await helper.eth.createRFTCollection(caller, 'TotalSupply', '6', '6');36 const contract = await helper.ethNativeContract.collection(collectionAddress, 'rft', caller);3738 await contract.methods.mint(caller).send();3940 const totalSupply = await contract.methods.totalSupply().call();41 expect(totalSupply).to.equal('1');42 });4344 itEth('balanceOf', async ({helper}) => {45 const caller = await helper.eth.createAccountWithBalance(donor);46 const {collectionAddress} = await helper.eth.createRFTCollection(caller, 'BalanceOf', '6', '6');47 const contract = await helper.ethNativeContract.collection(collectionAddress, 'rft', caller);4849 await contract.methods.mint(caller).send();50 await contract.methods.mint(caller).send();51 await contract.methods.mint(caller).send();5253 const balance = await contract.methods.balanceOf(caller).call();54 expect(balance).to.equal('3');55 });5657 itEth('ownerOf', async ({helper}) => {58 const caller = await helper.eth.createAccountWithBalance(donor);59 const {collectionAddress} = await helper.eth.createRFTCollection(caller, 'OwnerOf', '6', '6');60 const contract = await helper.ethNativeContract.collection(collectionAddress, 'rft', caller);6162 const result = await contract.methods.mint(caller).send();63 const tokenId = result.events.Transfer.returnValues.tokenId;6465 const owner = await contract.methods.ownerOf(tokenId).call();66 expect(owner).to.equal(caller);67 });6869 itEth('ownerOf after burn', async ({helper}) => {70 const caller = await helper.eth.createAccountWithBalance(donor);71 const receiver = helper.eth.createAccount();72 const {collectionId, collectionAddress} = await helper.eth.createRFTCollection(caller, 'OwnerOf-AfterBurn', '6', '6');73 const contract = await helper.ethNativeContract.collection(collectionAddress, 'rft', caller);7475 const result = await contract.methods.mint(caller).send();76 const tokenId = result.events.Transfer.returnValues.tokenId;77 const tokenContract = await helper.ethNativeContract.rftTokenById(collectionId, tokenId, caller, true);7879 await tokenContract.methods.repartition(2).send();80 await tokenContract.methods.transfer(receiver, 1).send();8182 await tokenContract.methods.burnFrom(caller, 1).send();8384 const owner = await contract.methods.ownerOf(tokenId).call();85 expect(owner).to.equal(receiver);86 });8788 itEth('ownerOf for partial ownership', async ({helper}) => {89 const caller = await helper.eth.createAccountWithBalance(donor);90 const receiver = helper.eth.createAccount();91 const {collectionId, collectionAddress} = await helper.eth.createRFTCollection(caller, 'Partial-OwnerOf', '6', '6');92 const contract = await helper.ethNativeContract.collection(collectionAddress, 'rft', caller);9394 const result = await contract.methods.mint(caller).send();95 const tokenId = result.events.Transfer.returnValues.tokenId;96 const tokenContract = await helper.ethNativeContract.rftTokenById(collectionId, tokenId, caller);9798 await tokenContract.methods.repartition(2).send();99 await tokenContract.methods.transfer(receiver, 1).send();100101 const owner = await contract.methods.ownerOf(tokenId).call();102 expect(owner).to.equal('0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF');103 });104});10521106describe('Refungible: Plain calls', () => {22describe('Refungible: Plain calls', () => {107 let donor: IKeyringPair;23 let donor: IKeyringPair;118 });34 });119 });35 });120121 itEth('Can perform mint() & crossOwnerOf()', async ({helper}) => {122 const owner = await helper.eth.createAccountWithBalance(donor);123 const receiver = helper.eth.createAccount();124 const {collectionAddress} = await helper.eth.createERC721MetadataCompatibleRFTCollection(owner, 'Minty', '6', '6', '');125 const contract = await helper.ethNativeContract.collection(collectionAddress, 'rft', owner);126127 const result = await contract.methods.mintWithTokenURI(receiver, 'Test URI').send();128129 const event = result.events.Transfer;130 expect(event.address).to.equal(collectionAddress);131 expect(event.returnValues.from).to.equal('0x0000000000000000000000000000000000000000');132 expect(event.returnValues.to).to.equal(receiver);133 const tokenId = event.returnValues.tokenId;134 expect(tokenId).to.be.equal('1');135136 expect(await contract.methods.crossOwnerOf(tokenId).call()).to.be.like([receiver, '0']);137 expect(await contract.methods.tokenURI(tokenId).call()).to.be.equal('Test URI');138 });13936140 [37 [141 'substrate' as const,38 'substrate' as const,tests/src/eth/reFungibleToken.test.tsdiffbeforeafterboth20import {Contract} from 'web3-eth-contract';20import {Contract} from 'web3-eth-contract';212223describe('Refungible token: Information getting', () => {24 let donor: IKeyringPair;25 let alice: IKeyringPair;2627 before(async function() {28 await usingEthPlaygrounds(async (helper, privateKey) => {29 requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);3031 donor = await privateKey({filename: __filename});32 [alice] = await helper.arrange.createAccounts([20n], donor);33 });34 });3536 itEth('totalSupply', async ({helper}) => {37 const caller = await helper.eth.createAccountWithBalance(donor);38 const collection = await helper.rft.mintCollection(alice, {tokenPrefix: 'MUON'});39 const {tokenId} = await collection.mintToken(alice, 200n, {Ethereum: caller});4041 const contract = await helper.ethNativeContract.rftTokenById(collection.collectionId, tokenId, caller);42 const totalSupply = await contract.methods.totalSupply().call();43 expect(totalSupply).to.equal('200');44 });4546 itEth('balanceOf', async ({helper}) => {47 const caller = await helper.eth.createAccountWithBalance(donor);48 const collection = await helper.rft.mintCollection(alice, {tokenPrefix: 'MUON'});49 const {tokenId} = await collection.mintToken(alice, 200n, {Ethereum: caller});5051 const contract = await helper.ethNativeContract.rftTokenById(collection.collectionId, tokenId, caller);52 const balance = await contract.methods.balanceOf(caller).call();53 expect(balance).to.equal('200');54 });5556 itEth('decimals', async ({helper}) => {57 const caller = await helper.eth.createAccountWithBalance(donor);58 const collection = await helper.rft.mintCollection(alice, {tokenPrefix: 'MUON'});59 const {tokenId} = await collection.mintToken(alice, 200n, {Ethereum: caller});6061 const contract = await helper.ethNativeContract.rftTokenById(collection.collectionId, tokenId, caller);62 const decimals = await contract.methods.decimals().call();63 expect(decimals).to.equal('0');64 });65});662167// FIXME: Need erc721 for ReFubgible.22// FIXME: Need erc721 for ReFubgible.68describe('Check ERC721 token URI for ReFungible', () => {23describe('Check ERC721 token URI for ReFungible', () => {tests/src/eth/tokens/callMethodsERC20.test.tsdiffbeforeafterbothno changes
tests/src/eth/tokens/callMethodsERC721.test.tsdiffbeforeafterbothno changes
tests/src/eth/tokens/minting.test.tsdiffbeforeafterbothno changes
tests/src/eth/util/playgrounds/unique.dev.tsdiffbeforeafterboth257 }257 }258 }258 }259259260 async createCollection(mode: TCollectionMode, signer: string, name: string, description: string, tokenPrefix: string, decimals = 18): Promise<{ collectionId: number, collectionAddress: string, events: NormalizedEvent[] }> {260 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 }> {261 const collectionCreationPrice = this.helper.balance.getCollectionCreationPrice();261 const collectionCreationPrice = this.helper.balance.getCollectionCreationPrice();262 const collectionHelper = await this.helper.ethNativeContract.collectionHelpers(signer);262 const collectionHelper = await this.helper.ethNativeContract.collectionHelpers(signer);263 const functionName: string = this.createCollectionMethodName(mode);263 const functionName: string = this.createCollectionMethodName(mode);268 const collectionAddress = this.helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);268 const collectionAddress = this.helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);269 const collectionId = this.helper.ethAddress.extractCollectionId(collectionAddress);269 const collectionId = this.helper.ethAddress.extractCollectionId(collectionAddress);270 const events = this.helper.eth.normalizeEvents(result.events);270 const events = this.helper.eth.normalizeEvents(result.events);271 const collection = await this.helper.ethNativeContract.collectionById(collectionId, mode, signer, mergeDeprecated);271272272 return {collectionId, collectionAddress, events};273 return {collectionId, collectionAddress, events, collection};273 }274 }274275275 createNFTCollection(signer: string, name: string, description: string, tokenPrefix: string): Promise<{ collectionId: number, collectionAddress: string, events: NormalizedEvent[] }> {276 createNFTCollection(signer: string, name: string, description: string, tokenPrefix: string): Promise<{ collectionId: number, collectionAddress: string, events: NormalizedEvent[] }> {tests/src/nesting/nest.test.tsdiffbeforeafterboth15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.161617import {IKeyringPair} from '@polkadot/types/types';17import {IKeyringPair} from '@polkadot/types/types';18import {expect, itSub, Pallets, usingPlaygrounds} from '../util';18import {expect, itSub, usingPlaygrounds} from '../util';191920describe('Integration Test: Composite nesting tests', () => {20describe('Integration Test: Composite nesting tests', () => {21 let alice: IKeyringPair;21 let alice: IKeyringPair;289 expect(await collectionFT.getBalance(targetToken.nestingAccount())).to.be.equal(7n);289 expect(await collectionFT.getBalance(targetToken.nestingAccount())).to.be.equal(7n);290 });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});291});339292340describe('Negative Test: Nesting', () => {293describe('Negative Test: Nesting', () => {581 expect(await collectionFT.getBalance({Substrate: alice.address})).to.be.equal(5n);534 expect(await collectionFT.getBalance({Substrate: alice.address})).to.be.equal(5n);582 });535 });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});536});668537tests/src/refungible.test.tsdiffbeforeafterboth88 expect((await token.getTop10Owners()).length).to.be.equal(10);88 expect((await token.getTop10Owners()).length).to.be.equal(10);89 });89 });9091 itSub('Transfer token pieces', async ({helper}) => {92 const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});93 const token = await collection.mintToken(alice, 100n);9495 expect(await token.getBalance({Substrate: alice.address})).to.be.equal(100n);96 expect(await token.transfer(alice, {Substrate: bob.address}, 60n)).to.be.true;9798 expect(await token.getBalance({Substrate: alice.address})).to.be.equal(40n);99 expect(await token.getBalance({Substrate: bob.address})).to.be.equal(60n);100101 await expect(token.transfer(alice, {Substrate: bob.address}, 41n))102 .to.eventually.be.rejectedWith(/common\.TokenValueTooLow/);103 });10490105 itSub('Create multiple tokens', async ({helper}) => {91 itSub('Create multiple tokens', async ({helper}) => {106 const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});92 const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});120 expect(await collection.getTokenBalance(lastTokenId, {Substrate: alice.address})).to.be.equal(100n);106 expect(await collection.getTokenBalance(lastTokenId, {Substrate: alice.address})).to.be.equal(100n);121 });107 });122123 itSub('Burn some pieces', async ({helper}) => {124 const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});125 const token = await collection.mintToken(alice, 100n);126 expect(await collection.doesTokenExist(token.tokenId)).to.be.true;127 expect(await token.getBalance({Substrate: alice.address})).to.be.equal(100n);128 expect(await token.burn(alice, 99n)).to.be.true;129 expect(await collection.doesTokenExist(token.tokenId)).to.be.true;130 expect(await token.getBalance({Substrate: alice.address})).to.be.equal(1n);131 });132133 itSub('Burn all pieces', async ({helper}) => {134 const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});135 const token = await collection.mintToken(alice, 100n);136137 expect(await collection.doesTokenExist(token.tokenId)).to.be.true;138 expect(await token.getBalance({Substrate: alice.address})).to.be.equal(100n);139140 expect(await token.burn(alice, 100n)).to.be.true;141 expect(await collection.doesTokenExist(token.tokenId)).to.be.false;142 });143144 itSub('Burn some pieces for multiple users', async ({helper}) => {145 const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});146 const token = await collection.mintToken(alice, 100n);147148 expect(await collection.doesTokenExist(token.tokenId)).to.be.true;149150 expect(await token.getBalance({Substrate: alice.address})).to.be.equal(100n);151 expect(await token.transfer(alice, {Substrate: bob.address}, 60n)).to.be.true;152153 expect(await token.getBalance({Substrate: alice.address})).to.be.equal(40n);154 expect(await token.getBalance({Substrate: bob.address})).to.be.equal(60n);155156 expect(await token.burn(alice, 40n)).to.be.true;157158 expect(await collection.doesTokenExist(token.tokenId)).to.be.true;159 expect(await token.getBalance({Substrate: alice.address})).to.be.equal(0n);160161 expect(await token.burn(bob, 59n)).to.be.true;162163 expect(await token.getBalance({Substrate: bob.address})).to.be.equal(1n);164 expect(await collection.doesTokenExist(token.tokenId)).to.be.true;165166 expect(await token.burn(bob, 1n)).to.be.true;167168 expect(await collection.doesTokenExist(token.tokenId)).to.be.false;169 });170108171 itSub('Set allowance for token', async ({helper}) => {109 itSub('Set allowance for token', async ({helper}) => {172 const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});110 const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});183 expect(await token.getApprovedPieces({Substrate: alice.address}, {Substrate: bob.address})).to.be.equal(40n);121 expect(await token.getApprovedPieces({Substrate: alice.address}, {Substrate: bob.address})).to.be.equal(40n);184 });122 });185186 itSub('Repartition', async ({helper}) => {187 const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});188 const token = await collection.mintToken(alice, 100n);189190 expect(await token.repartition(alice, 200n)).to.be.true;191 expect(await token.getBalance({Substrate: alice.address})).to.be.equal(200n);192 expect(await token.getTotalPieces()).to.be.equal(200n);193194 expect(await token.transfer(alice, {Substrate: bob.address}, 110n)).to.be.true;195 expect(await token.getBalance({Substrate: alice.address})).to.be.equal(90n);196 expect(await token.getBalance({Substrate: bob.address})).to.be.equal(110n);197198 await expect(token.repartition(alice, 80n))199 .to.eventually.be.rejectedWith(/refungible\.RepartitionWhileNotOwningAllPieces/);200201 expect(await token.transfer(alice, {Substrate: bob.address}, 90n)).to.be.true;202 expect(await token.getBalance({Substrate: alice.address})).to.be.equal(0n);203 expect(await token.getBalance({Substrate: bob.address})).to.be.equal(200n);204205 expect(await token.repartition(bob, 150n)).to.be.true;206 await expect(token.transfer(bob, {Substrate: alice.address}, 160n))207 .to.eventually.be.rejectedWith(/common\.TokenValueTooLow/);208 });209210 itSub('Repartition with increased amount', async ({helper}) => {211 const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});212 const token = await collection.mintToken(alice, 100n);213 await token.repartition(alice, 200n);214 const chainEvents = helper.chainLog.slice(-1)[0].events;215 const event = chainEvents.find((event: any) => event.section === 'common' && event.method === 'ItemCreated');216 expect(event).to.deep.include({217 section: 'common',218 method: 'ItemCreated',219 index: [66, 2],220 data: [221 collection.collectionId,222 token.tokenId,223 {substrate: alice.address},224 100n,225 ],226 });227 });228229 itSub('Repartition with decreased amount', async ({helper}) => {230 const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});231 const token = await collection.mintToken(alice, 100n);232 await token.repartition(alice, 50n);233 const chainEvents = helper.chainLog.slice(-1)[0].events;234 const event = chainEvents.find((event: any) => event.section === 'common' && event.method === 'ItemDestroyed');235 expect(event).to.deep.include({236 section: 'common',237 method: 'ItemDestroyed',238 index: [66, 3],239 data: [240 collection.collectionId,241 token.tokenId,242 {substrate: alice.address},243 50n,244 ],245 });246 });247123248 itSub('Create new collection with properties', async ({helper}) => {124 itSub('Create new collection with properties', async ({helper}) => {249 const properties = [{key: 'key1', value: 'val1'}];125 const properties = [{key: 'key1', value: 'val1'}];255 });131 });256});132});257258describe('Refungible negative tests', () => {259 let donor: IKeyringPair;260 let alice: IKeyringPair;261 let bob: IKeyringPair;262 let charlie: IKeyringPair;263264 before(async function() {265 await usingPlaygrounds(async (helper, privateKey) => {266 requirePalletsOrSkip(this, helper, [Pallets.ReFungible]);267268 donor = await privateKey({filename: __filename});269 [alice, bob, charlie] = await helper.arrange.createAccounts([100n, 100n, 100n], donor);270 });271 });272273 itSub('Cannot transfer incorrect amount of token pieces', async ({helper}) => {274 const collection = await helper.rft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});275 const tokenAlice = await collection.mintToken(alice, 10n, {Substrate: alice.address});276 const tokenBob = await collection.mintToken(alice, 10n, {Substrate: bob.address});277278 // 1. Alice cannot transfer Bob's token:279 await expect(tokenBob.transfer(alice, {Substrate: charlie.address}, 0n)).to.be.rejectedWith('common.TokenValueTooLow');280 await expect(tokenBob.transfer(alice, {Substrate: charlie.address}, 1n)).to.be.rejectedWith('common.TokenValueTooLow');281 await expect(tokenBob.transfer(alice, {Substrate: charlie.address}, 10n)).to.be.rejectedWith('common.TokenValueTooLow');282 await expect(tokenBob.transfer(alice, {Substrate: charlie.address}, 100n)).to.be.rejectedWith('common.TokenValueTooLow');283284 // 2. Alice cannot transfer non-existing token:285 await expect(collection.transferToken(alice, 100, {Substrate: charlie.address}, 0n)).to.be.rejectedWith('common.TokenValueTooLow');286 await expect(collection.transferToken(alice, 100, {Substrate: charlie.address}, 1n)).to.be.rejectedWith('common.TokenValueTooLow');287288 // 3. Zero transfer allowed (EIP-20):289 await tokenAlice.transfer(alice, {Substrate: charlie.address}, 0n);290291 expect(await tokenAlice.getTop10Owners()).to.deep.eq([{Substrate: alice.address}]);292 expect(await tokenBob.getTop10Owners()).to.deep.eq([{Substrate: bob.address}]);293 expect(await tokenAlice.getBalance({Substrate: alice.address})).to.eq(10n);294 expect(await tokenBob.getBalance({Substrate: bob.address})).to.eq(10n);295 expect(await tokenBob.getBalance({Substrate: charlie.address})).to.eq(0n);296 });297});298133tests/src/sub/refungible/burn.test.tsdiffbeforeafterbothno changes
tests/src/sub/refungible/nesting.test.tsdiffbeforeafterbothno changes
tests/src/sub/refungible/repartition.test.tsdiffbeforeafterbothno changes
tests/src/sub/refungible/transfer.test.tsdiffbeforeafterbothno changes
tests/src/util/index.tsdiffbeforeafterboth100export const LOCKING_PERIOD = 12n; // 12 blocks of relay100export const LOCKING_PERIOD = 12n; // 12 blocks of relay101export const UNLOCKING_PERIOD = 6n; // 6 blocks of parachain101export const UNLOCKING_PERIOD = 6n; // 6 blocks of parachain102102103// Native contracts104export const COLLECTION_HELPER = '0x6c4e9fe1ae37a41e93cee429e8e1881abdcbb54f';105export const CONTRACT_HELPER = '0x842899ECF380553E8a4de75bF534cdf6fBF64049';103106104export enum Pallets {107export enum Pallets {105 Inflation = 'inflation',108 Inflation = 'inflation',