difftreelog
tests(nesting): refactor naming conventions for token addresses
in: master
7 files changed
tests/src/eth/util/playgrounds/unique.dev.tsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// SPDX-License-Identifier: Apache-2.034/* eslint-disable function-call-argument-newline */5// eslint-disable-next-line @typescript-eslint/triple-slash-reference6/// <reference path="unique.dev.d.ts" />78import {readFile} from 'fs/promises';910import Web3 from 'web3';11import {WebsocketProvider} from 'web3-core';12import {Contract} from 'web3-eth-contract';1314import * as solc from 'solc';1516import {evmToAddress} from '@polkadot/util-crypto';17import {IKeyringPair} from '@polkadot/types/types';1819import {DevUniqueHelper} from '../../../util/playgrounds/unique.dev';2021import {ContractImports, CompiledContract} from './types';2223// Native contracts ABI24import collectionHelpersAbi from '../../collectionHelpersAbi.json';25import fungibleAbi from '../../fungibleAbi.json';26import nonFungibleAbi from '../../nonFungibleAbi.json';27import refungibleAbi from '../../reFungibleAbi.json';28import refungibleTokenAbi from '../../reFungibleTokenAbi.json';29import contractHelpersAbi from './../contractHelpersAbi.json';3031class EthGroupBase {32 helper: EthUniqueHelper;3334 constructor(helper: EthUniqueHelper) {35 this.helper = helper;36 }37}383940class ContractGroup extends EthGroupBase {41 async findImports(imports?: ContractImports[]){42 if(!imports) return function(path: string) {43 return {error: `File not found: ${path}`};44 };45 46 const knownImports = {} as any;47 for(const imp of imports) {48 knownImports[imp.solPath] = (await readFile(imp.fsPath)).toString();49 }50 51 return function(path: string) {52 if(knownImports.hasOwnPropertyDescriptor(path)) return {contents: knownImports[path]};53 return {error: `File not found: ${path}`};54 };55 }5657 async compile(name: string, src: string, imports?: ContractImports[]): Promise<CompiledContract> {58 const out = JSON.parse(solc.compile(JSON.stringify({59 language: 'Solidity',60 sources: {61 [`${name}.sol`]: {62 content: src,63 },64 },65 settings: {66 outputSelection: {67 '*': {68 '*': ['*'],69 },70 },71 },72 }), {import: await this.findImports(imports)})).contracts[`${name}.sol`][name];73 74 return {75 abi: out.abi,76 object: '0x' + out.evm.bytecode.object,77 };78 }7980 async deployByCode(signer: string, name: string, src: string, imports?: ContractImports[]): Promise<Contract> {81 const compiledContract = await this.compile(name, src, imports);82 return this.deployByAbi(signer, compiledContract.abi, compiledContract.object);83 }8485 async deployByAbi(signer: string, abi: any, object: string): Promise<Contract> {86 const web3 = this.helper.getWeb3();87 const contract = new web3.eth.Contract(abi, undefined, {88 data: object,89 from: signer,90 gas: this.helper.eth.DEFAULT_GAS,91 });92 return await contract.deploy({data: object}).send({from: signer});93 }9495}96 97class NativeContractGroup extends EthGroupBase {9899 contractHelpers(caller: string): Contract {100 const web3 = this.helper.getWeb3();101 return new web3.eth.Contract(contractHelpersAbi as any, '0x842899ECF380553E8a4de75bF534cdf6fBF64049', {from: caller, gas: this.helper.eth.DEFAULT_GAS});102 }103104 collectionHelpers(caller: string) {105 const web3 = this.helper.getWeb3();106 return new web3.eth.Contract(collectionHelpersAbi as any, '0x6c4e9fe1ae37a41e93cee429e8e1881abdcbb54f', {from: caller, gas: this.helper.eth.DEFAULT_GAS});107 }108109 collection(address: string, mode: 'nft' | 'rft' | 'ft', caller?: string): Contract {110 const abi = {111 'nft': nonFungibleAbi,112 'rft': refungibleAbi,113 'ft': fungibleAbi,114 }[mode];115 const web3 = this.helper.getWeb3();116 return new web3.eth.Contract(abi as any, address, {gas: this.helper.eth.DEFAULT_GAS, ...(caller ? {from: caller} : {})});117 }118119 rftTokenByAddress(address: string, caller?: string): Contract {120 const web3 = this.helper.getWeb3();121 return new web3.eth.Contract(refungibleTokenAbi as any, address, {gas: this.helper.eth.DEFAULT_GAS, ...(caller ? {from: caller} : {})});122 }123124 rftToken(collectionId: number, tokenId: number, caller?: string): Contract {125 return this.rftTokenByAddress(this.helper.ethAddress.fromTokenId(collectionId, tokenId), caller);126 }127}128129 130class EthGroup extends EthGroupBase {131 DEFAULT_GAS = 2_500_000;132133 createAccount() {134 const web3 = this.helper.getWeb3();135 const account = web3.eth.accounts.create();136 web3.eth.accounts.wallet.add(account.privateKey);137 return account.address;138 }139140 async createAccountWithBalance(donor: IKeyringPair, amount=1000n) {141 const account = this.createAccount();142 await this.transferBalanceFromSubstrate(donor, account, amount);143 144 return account;145 }146147 async transferBalanceFromSubstrate(donor: IKeyringPair, recepient: string, amount=1000n, inTokens=true) {148 return await this.helper.balance.transferToSubstrate(donor, evmToAddress(recepient), amount * (inTokens ? this.helper.balance.getOneTokenNominal() : 1n));149 }150151 async callEVM(signer: IKeyringPair, contractAddress: string, abi: any, value: string, gasLimit?: number) {152 if(!gasLimit) gasLimit = this.DEFAULT_GAS;153 const web3 = this.helper.getWeb3();154 const gasPrice = await web3.eth.getGasPrice();155 // TODO: check execution status156 await this.helper.executeExtrinsic(157 signer,158 'api.tx.evm.call', [this.helper.address.substrateToEth(signer.address), contractAddress, abi, value, gasLimit, gasPrice, null, null, []],159 true,160 );161 }162163 async createNonfungibleCollection(signer: string, name: string, description: string, tokenPrefix: string): Promise<{collectionId: number, collectionAddress: string}> {164 const collectionHelper = this.helper.ethNativeContract.collectionHelpers(signer);165 166 const result = await collectionHelper.methods.createNonfungibleCollection(name, description, tokenPrefix).send();167168 const collectionAddress = this.helper.ethAddress.normalizeAddress(result.events.CollectionCreated.returnValues.collectionId);169 const collectionId = this.helper.ethAddress.extractCollectionId(collectionAddress);170171 return {collectionId, collectionAddress};172 }173174 async deployCollectorContract(signer: string): Promise<Contract> {175 return await this.helper.ethContract.deployByCode(signer, 'Collector', `176 // SPDX-License-Identifier: UNLICENSED177 pragma solidity ^0.8.6;178179 contract Collector {180 uint256 collected;181 fallback() external payable {182 giveMoney();183 }184 function giveMoney() public payable {185 collected += msg.value;186 }187 function getCollected() public view returns (uint256) {188 return collected;189 }190 function getUnaccounted() public view returns (uint256) {191 return address(this).balance - collected;192 }193194 function withdraw(address payable target) public {195 target.transfer(collected);196 collected = 0;197 }198 }199 `);200 }201202 async deployFlipper(signer: string): Promise<Contract> {203 return await this.helper.ethContract.deployByCode(signer, 'Flipper', `204 // SPDX-License-Identifier: UNLICENSED205 pragma solidity ^0.8.6;206207 contract Flipper {208 bool value = false;209 function flip() public {210 value = !value;211 }212 function getValue() public view returns (bool) {213 return value;214 }215 }216 `);217 }218} 219 220class EthAddressGroup extends EthGroupBase {221 extractCollectionId(address: string): number {222 if (!(address.length === 42 || address.length === 40)) throw new Error('address wrong format');223 return parseInt(address.substr(address.length - 8), 16);224 }225226 fromCollectionId(collectionId: number): string {227 if (collectionId >= 0xffffffff || collectionId < 0) throw new Error('collectionId overflow');228 return Web3.utils.toChecksumAddress(`0x17c4e6453cc49aaaaeaca894e6d9683e${collectionId.toString(16).padStart(8,'0')}`);229 }230231 extractTokenId(address: string): {collectionId: number, tokenId: number} {232 if (!address.startsWith('0x'))233 throw 'address not starts with "0x"';234 if (address.length > 42)235 throw 'address length is more than 20 bytes';236 return {237 collectionId: Number('0x' + address.substring(address.length - 16, address.length - 8)),238 tokenId: Number('0x' + address.substring(address.length - 8)),239 };240 }241242 fromTokenId(collectionId: number, tokenId: number): string {243 return this.helper.util.getNestingTokenAddressRaw({collectionId, tokenId});244 }245246 normalizeAddress(address: string): string {247 return '0x' + address.substring(address.length - 40);248 }249} 250 251252export class EthUniqueHelper extends DevUniqueHelper {253 web3: Web3 | null = null;254 web3Provider: WebsocketProvider | null = null;255256 eth: EthGroup;257 ethAddress: EthAddressGroup;258 ethNativeContract: NativeContractGroup;259 ethContract: ContractGroup;260261 constructor(logger: { log: (msg: any, level: any) => void, level: any }) {262 super(logger);263 this.eth = new EthGroup(this);264 this.ethAddress = new EthAddressGroup(this);265 this.ethNativeContract = new NativeContractGroup(this);266 this.ethContract = new ContractGroup(this);267 }268269 getWeb3(): Web3 {270 if(this.web3 === null) throw Error('Web3 not connected');271 return this.web3;272 }273274 async connectWeb3(wsEndpoint: string) {275 if(this.web3 !== null) return;276 this.web3Provider = new Web3.providers.WebsocketProvider(wsEndpoint);277 this.web3 = new Web3(this.web3Provider);278 }279280 async disconnectWeb3() {281 if(this.web3 === null) return;282 this.web3Provider?.connection.close();283 this.web3 = null;284 }285}286 tests/src/nesting/graphs.test.tsdiffbeforeafterboth--- a/tests/src/nesting/graphs.test.ts
+++ b/tests/src/nesting/graphs.test.ts
@@ -64,7 +64,7 @@
'second transaction',
).to.be.rejectedWith(/structure\.OuroborosDetected/);
await expect(
- tokens[1].transferFrom(alice, tokens[0].nestingAddress(), tokens[7].nestingAddress()),
+ tokens[1].transferFrom(alice, tokens[0].nestingAccount(), tokens[7].nestingAccount()),
'third transaction',
).to.be.rejectedWith(/structure\.OuroborosDetected/);
});
tests/src/nesting/nest.test.tsdiffbeforeafterboth--- a/tests/src/nesting/nest.test.ts
+++ b/tests/src/nesting/nest.test.ts
@@ -33,9 +33,9 @@
const targetToken = await collection.mintToken(alice);
// Create an immediately nested token
- const nestedToken = await collection.mintToken(alice, targetToken.nestingAddress());
+ const nestedToken = await collection.mintToken(alice, targetToken.nestingAccount());
expect(await nestedToken.getTopmostOwner()).to.be.deep.equal({Substrate: alice.address});
- expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAddress());
+ expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount());
// Create a token to be nested
const newToken = await collection.mintToken(alice);
@@ -43,14 +43,14 @@
// Nest
await newToken.nest(alice, targetToken);
expect(await newToken.getTopmostOwner()).to.be.deep.equal({Substrate: alice.address});
- expect(await newToken.getOwner()).to.be.deep.equal(targetToken.nestingAddress());
+ expect(await newToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount());
// Move bundle to different user
await targetToken.transfer(alice, {Substrate: bob.address});
expect(await nestedToken.getTopmostOwner()).to.be.deep.equal({Substrate: bob.address});
- expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAddress());
+ expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount());
expect(await newToken.getTopmostOwner()).to.be.deep.equal({Substrate: bob.address});
- expect(await newToken.getOwner()).to.be.deep.equal(targetToken.nestingAddress());
+ expect(await newToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount());
// Unnest
await newToken.unnest(bob, targetToken, {Substrate: bob.address});
@@ -64,13 +64,13 @@
const tokenB = await collection.mintToken(alice);
// Create a nested token
- const tokenC = await collection.mintToken(alice, tokenA.nestingAddress());
- expect(await tokenC.getOwner()).to.be.deep.equal(tokenA.nestingAddress());
+ const tokenC = await collection.mintToken(alice, tokenA.nestingAccount());
+ expect(await tokenC.getOwner()).to.be.deep.equal(tokenA.nestingAccount());
// Transfer the nested token to another token
- await expect(tokenC.transferFrom(alice, tokenA.nestingAddress(), tokenB.nestingAddress())).to.be.fulfilled;
+ await expect(tokenC.transferFrom(alice, tokenA.nestingAccount(), tokenB.nestingAccount())).to.be.fulfilled;
expect(await tokenC.getTopmostOwner()).to.be.deep.equal({Substrate: alice.address});
- expect(await tokenC.getOwner()).to.be.deep.equal(tokenB.nestingAddress());
+ expect(await tokenC.getOwner()).to.be.deep.equal(tokenB.nestingAccount());
});
itSub('Checks token children', async ({helper}) => {
@@ -81,7 +81,7 @@
expect((await targetToken.getChildren()).length).to.be.equal(0, 'Children length check at creation');
// Create a nested NFT token
- const tokenA = await collectionA.mintToken(alice, targetToken.nestingAddress());
+ const tokenA = await collectionA.mintToken(alice, targetToken.nestingAccount());
expect(await targetToken.getChildren()).to.have.deep.members([
{tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},
], 'Children contents check at nesting #1').and.be.length(1, 'Children length check at nesting #1');
@@ -102,7 +102,7 @@
// Create a fungible token in another collection and then nest
await collectionB.mint(alice, 10n);
- await collectionB.transfer(alice, targetToken.nestingAddress(), 2n);
+ await collectionB.transfer(alice, targetToken.nestingAccount(), 2n);
expect(await targetToken.getChildren()).to.be.have.deep.members([
{tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},
{tokenId: 0, collectionId: collectionB.collectionId},
@@ -110,7 +110,7 @@
.and.be.length(2, 'Children length check at nesting #4 (from another collection)');
// Move part of the fungible token inside token A deeper in the nesting tree
- await collectionB.transferFrom(alice, targetToken.nestingAddress(), tokenA.nestingAddress(), 1n);
+ await collectionB.transferFrom(alice, targetToken.nestingAccount(), tokenA.nestingAccount(), 1n);
expect(await targetToken.getChildren()).to.be.have.deep.members([
{tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},
{tokenId: 0, collectionId: collectionB.collectionId},
@@ -120,7 +120,7 @@
], 'Children contents check at nesting #5.5 (deeper)').and.be.length(1, 'Children length check at nesting #5.5 (deeper)');
// Move the remaining part of the fungible token inside token A deeper in the nesting tree
- await collectionB.transferFrom(alice, targetToken.nestingAddress(), tokenA.nestingAddress(), 1n);
+ await collectionB.transferFrom(alice, targetToken.nestingAccount(), tokenA.nestingAccount(), 1n);
expect(await targetToken.getChildren()).to.be.have.deep.members([
{tokenId: tokenA.tokenId, collectionId: collectionA.collectionId},
], 'Children contents check at nesting #6 (deeper)').and.be.length(1, 'Children length check at nesting #6 (deeper)');
@@ -148,15 +148,15 @@
const targetToken = await collection.mintToken(alice, {Substrate: charlie.address});
// Create an immediately nested token
- const nestedToken = await collection.mintToken(bob, targetToken.nestingAddress());
+ const nestedToken = await collection.mintToken(bob, targetToken.nestingAccount());
expect(await nestedToken.getTopmostOwner()).to.be.deep.equal({Substrate: charlie.address});
- expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAddress());
+ expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount());
// Create a token to be nested and nest
const newToken = await collection.mintToken(bob);
await newToken.nest(bob, targetToken);
expect(await newToken.getTopmostOwner()).to.be.deep.equal({Substrate: charlie.address});
- expect(await newToken.getOwner()).to.be.deep.equal(targetToken.nestingAddress());
+ expect(await newToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount());
});
itSub('Admin (NFT): Admin and Token Owner can operate together', async ({helper}) => {
@@ -165,15 +165,15 @@
const targetToken = await collection.mintToken(alice, {Substrate: charlie.address});
// Create an immediately nested token by an administrator
- const nestedToken = await collection.mintToken(bob, targetToken.nestingAddress());
+ const nestedToken = await collection.mintToken(bob, targetToken.nestingAccount());
expect(await nestedToken.getTopmostOwner()).to.be.deep.equal({Substrate: charlie.address});
- expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAddress());
+ expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount());
// Create a token to be nested and nest
const newToken = await collection.mintToken(alice, {Substrate: charlie.address});
await newToken.nest(charlie, targetToken);
expect(await newToken.getTopmostOwner()).to.be.deep.equal({Substrate: charlie.address});
- expect(await newToken.getOwner()).to.be.deep.equal(targetToken.nestingAddress());
+ expect(await newToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount());
});
itSub('Admin (NFT): allows an Admin to nest a token (Restricted nesting)', async ({helper}) => {
@@ -185,15 +185,15 @@
const targetToken = await collectionA.mintToken(alice, {Substrate: charlie.address});
// Create an immediately nested token
- const nestedToken = await collectionB.mintToken(bob, targetToken.nestingAddress());
+ const nestedToken = await collectionB.mintToken(bob, targetToken.nestingAccount());
expect(await nestedToken.getTopmostOwner()).to.be.deep.equal({Substrate: charlie.address});
- expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAddress());
+ expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount());
// Create a token to be nested and nest
const newToken = await collectionB.mintToken(bob);
await newToken.nest(bob, targetToken);
expect(await newToken.getTopmostOwner()).to.be.deep.equal({Substrate: charlie.address});
- expect(await newToken.getOwner()).to.be.deep.equal(targetToken.nestingAddress());
+ expect(await newToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount());
});
// ---------- Non-Fungible ----------
@@ -202,18 +202,18 @@
const collection = await helper.nft.mintCollection(alice, {permissions: {access: 'AllowList', mintMode: true, nesting: {tokenOwner: true}}});
await collection.addToAllowList(alice, {Substrate: charlie.address});
const targetToken = await collection.mintToken(charlie);
- await collection.addToAllowList(alice, targetToken.nestingAddress());
+ await collection.addToAllowList(alice, targetToken.nestingAccount());
// Create an immediately nested token
- const nestedToken = await collection.mintToken(charlie, targetToken.nestingAddress());
+ const nestedToken = await collection.mintToken(charlie, targetToken.nestingAccount());
expect(await nestedToken.getTopmostOwner()).to.be.deep.equal({Substrate: charlie.address});
- expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAddress());
+ expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount());
// Create a token to be nested and nest
const newToken = await collection.mintToken(charlie);
await newToken.nest(charlie, targetToken);
expect(await newToken.getTopmostOwner()).to.be.deep.equal({Substrate: charlie.address});
- expect(await newToken.getOwner()).to.be.deep.equal(targetToken.nestingAddress());
+ expect(await newToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount());
});
itSub('NFT: allows an Owner to nest/unnest their token (Restricted nesting)', async ({helper}) => {
@@ -224,22 +224,22 @@
await collectionA.setPermissions(alice, {access: 'AllowList', mintMode: true, nesting: {tokenOwner: true, restricted:[collectionB.collectionId]}});
await collectionA.addToAllowList(alice, {Substrate: charlie.address});
- await collectionA.addToAllowList(alice, targetToken.nestingAddress());
+ await collectionA.addToAllowList(alice, targetToken.nestingAccount());
await collectionB.setPermissions(alice, {access: 'AllowList', mintMode: true});
await collectionB.addToAllowList(alice, {Substrate: charlie.address});
- await collectionB.addToAllowList(alice, targetToken.nestingAddress());
+ await collectionB.addToAllowList(alice, targetToken.nestingAccount());
// Create an immediately nested token
- const nestedToken = await collectionB.mintToken(charlie, targetToken.nestingAddress());
+ const nestedToken = await collectionB.mintToken(charlie, targetToken.nestingAccount());
expect(await nestedToken.getTopmostOwner()).to.be.deep.equal({Substrate: charlie.address});
- expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAddress());
+ expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount());
// Create a token to be nested and nest
const newToken = await collectionB.mintToken(charlie);
await newToken.nest(charlie, targetToken);
expect(await newToken.getTopmostOwner()).to.be.deep.equal({Substrate: charlie.address});
- expect(await newToken.getOwner()).to.be.deep.equal(targetToken.nestingAddress());
+ expect(await newToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount());
});
// ---------- Fungible ----------
@@ -250,20 +250,20 @@
const targetToken = await collectionNFT.mintToken(alice, {Substrate: charlie.address});
await collectionNFT.addToAllowList(alice, {Substrate: charlie.address});
- await collectionNFT.addToAllowList(alice, targetToken.nestingAddress());
+ await collectionNFT.addToAllowList(alice, targetToken.nestingAccount());
await collectionFT.setPermissions(alice, {access: 'AllowList', mintMode: true});
await collectionFT.addToAllowList(alice, {Substrate: charlie.address});
- await collectionFT.addToAllowList(alice, targetToken.nestingAddress());
+ await collectionFT.addToAllowList(alice, targetToken.nestingAccount());
// Create an immediately nested token
- await collectionFT.mint(charlie, 5n, targetToken.nestingAddress());
- expect(await collectionFT.getBalance(targetToken.nestingAddress())).to.be.equal(5n);
+ await collectionFT.mint(charlie, 5n, targetToken.nestingAccount());
+ expect(await collectionFT.getBalance(targetToken.nestingAccount())).to.be.equal(5n);
// Create a token to be nested and nest
await collectionFT.mint(charlie, 5n);
- await collectionFT.transfer(charlie, targetToken.nestingAddress(), 2n);
- expect(await collectionFT.getBalance(targetToken.nestingAddress())).to.be.equal(7n);
+ await collectionFT.transfer(charlie, targetToken.nestingAccount(), 2n);
+ expect(await collectionFT.getBalance(targetToken.nestingAccount())).to.be.equal(7n);
});
itSub('Fungible: allows an Owner to nest/unnest their token (Restricted nesting)', async ({helper}) => {
@@ -273,20 +273,20 @@
await collectionNFT.setPermissions(alice, {access: 'AllowList', mintMode: true, nesting: {tokenOwner: true, restricted:[collectionFT.collectionId]}});
await collectionNFT.addToAllowList(alice, {Substrate: charlie.address});
- await collectionNFT.addToAllowList(alice, targetToken.nestingAddress());
+ await collectionNFT.addToAllowList(alice, targetToken.nestingAccount());
await collectionFT.setPermissions(alice, {access: 'AllowList', mintMode: true});
await collectionFT.addToAllowList(alice, {Substrate: charlie.address});
- await collectionFT.addToAllowList(alice, targetToken.nestingAddress());
+ await collectionFT.addToAllowList(alice, targetToken.nestingAccount());
// Create an immediately nested token
- await collectionFT.mint(charlie, 5n, targetToken.nestingAddress());
- expect(await collectionFT.getBalance(targetToken.nestingAddress())).to.be.equal(5n);
+ await collectionFT.mint(charlie, 5n, targetToken.nestingAccount());
+ expect(await collectionFT.getBalance(targetToken.nestingAccount())).to.be.equal(5n);
// Create a token to be nested and nest
await collectionFT.mint(charlie, 5n);
- await collectionFT.transfer(charlie, targetToken.nestingAddress(), 2n);
- expect(await collectionFT.getBalance(targetToken.nestingAddress())).to.be.equal(7n);
+ await collectionFT.transfer(charlie, targetToken.nestingAccount(), 2n);
+ expect(await collectionFT.getBalance(targetToken.nestingAccount())).to.be.equal(7n);
});
// ---------- Re-Fungible ----------
@@ -297,20 +297,20 @@
const targetToken = await collectionNFT.mintToken(alice, {Substrate: charlie.address});
await collectionNFT.addToAllowList(alice, {Substrate: charlie.address});
- await collectionNFT.addToAllowList(alice, targetToken.nestingAddress());
+ 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.nestingAddress());
+ await collectionRFT.addToAllowList(alice, targetToken.nestingAccount());
// Create an immediately nested token
- const nestedToken = await collectionRFT.mintToken(charlie, 5n, targetToken.nestingAddress());
- expect(await nestedToken.getBalance(targetToken.nestingAddress())).to.be.equal(5n);
+ 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.nestingAddress(), 2n);
- expect(await newToken.getBalance(targetToken.nestingAddress())).to.be.equal(2n);
+ await newToken.transfer(charlie, targetToken.nestingAccount(), 2n);
+ expect(await newToken.getBalance(targetToken.nestingAccount())).to.be.equal(2n);
});
itSub.ifWithPallets('ReFungible: allows an Owner to nest/unnest their token (Restricted nesting)', [Pallets.ReFungible], async ({helper}) => {
@@ -320,20 +320,20 @@
await collectionNFT.setPermissions(alice, {access: 'AllowList', mintMode: true, nesting: {tokenOwner: true, restricted:[collectionRFT.collectionId]}});
await collectionNFT.addToAllowList(alice, {Substrate: charlie.address});
- await collectionNFT.addToAllowList(alice, targetToken.nestingAddress());
+ 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.nestingAddress());
+ await collectionRFT.addToAllowList(alice, targetToken.nestingAccount());
// Create an immediately nested token
- const nestedToken = await collectionRFT.mintToken(charlie, 5n, targetToken.nestingAddress());
- expect(await nestedToken.getBalance(targetToken.nestingAddress())).to.be.equal(5n);
+ 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.nestingAddress(), 2n);
- expect(await newToken.getBalance(targetToken.nestingAddress())).to.be.equal(2n);
+ await newToken.transfer(charlie, targetToken.nestingAccount(), 2n);
+ expect(await newToken.getBalance(targetToken.nestingAccount())).to.be.equal(2n);
});
});
@@ -356,11 +356,11 @@
// Create a nested-token matryoshka
for (let i = 0; i < maxNestingLevel; i++) {
- token = await collection.mintToken(alice, token.nestingAddress());
+ token = await collection.mintToken(alice, token.nestingAccount());
}
// The nesting depth is limited by `maxNestingLevel`
- await expect(collection.mintToken(alice, token.nestingAddress()))
+ await expect(collection.mintToken(alice, token.nestingAccount()))
.to.be.rejectedWith(/structure\.DepthLimit/);
expect(await token.getTopmostOwner()).to.be.deep.equal({Substrate: alice.address});
expect(await token.getChildren()).to.be.length(0);
@@ -374,7 +374,7 @@
const targetToken = await collection.mintToken(alice);
// Try to create an immediately nested token as collection admin when it's disallowed
- await expect(collection.mintToken(bob, targetToken.nestingAddress()))
+ await expect(collection.mintToken(bob, targetToken.nestingAccount()))
.to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);
// Try to create a token to be nested and nest
@@ -390,10 +390,10 @@
const collection = await helper.nft.mintCollection(alice, {permissions: {access: 'AllowList', mintMode: true, nesting: {collectionAdmin: true}}});
const targetToken = await collection.mintToken(alice, {Substrate: bob.address});
await collection.addToAllowList(alice, {Substrate: bob.address});
- await collection.addToAllowList(alice, targetToken.nestingAddress());
+ await collection.addToAllowList(alice, targetToken.nestingAccount());
// Try to create a nested token as token owner when it's disallowed
- await expect(collection.mintToken(bob, targetToken.nestingAddress()))
+ await expect(collection.mintToken(bob, targetToken.nestingAccount()))
.to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);
// Try to create a token to be nested and nest
@@ -410,7 +410,7 @@
//await collection.addAdmin(alice, {Substrate: bob.address});
const targetToken = await collection.mintToken(alice, {Substrate: bob.address});
await collection.addToAllowList(alice, {Substrate: bob.address});
- await collection.addToAllowList(alice, targetToken.nestingAddress());
+ await collection.addToAllowList(alice, targetToken.nestingAccount());
// Try to nest somebody else's token
const newToken = await collection.mintToken(bob);
@@ -418,13 +418,13 @@
.to.be.rejectedWith(/common\.NoPermission/);
// Try to unnest a token belonging to someone else as collection admin
- const nestedToken = await collection.mintToken(alice, targetToken.nestingAddress());
+ const nestedToken = await collection.mintToken(alice, targetToken.nestingAccount());
await expect(nestedToken.unnest(alice, targetToken, {Substrate: bob.address}))
.to.be.rejectedWith(/common\.AddressNotInAllowlist/);
expect(await targetToken.getChildren()).to.be.length(1);
expect(await nestedToken.getTopmostOwner()).to.be.deep.equal({Substrate: bob.address});
- expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAddress());
+ expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount());
});
itSub('Admin (NFT): disallows an Admin to nest a token from an unlisted collection (Restricted nesting)', async ({helper}) => {
@@ -434,7 +434,7 @@
const targetToken = await collectionA.mintToken(alice);
// Try to create a nested token from another collection
- await expect(collectionB.mintToken(alice, targetToken.nestingAddress()))
+ await expect(collectionB.mintToken(alice, targetToken.nestingAccount()))
.to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);
// Create a token in another collection yet to be nested and try to nest
@@ -454,7 +454,7 @@
const targetToken = await collection.mintToken(alice);
// Try to create a nested token as token owner when it's disallowed
- await expect(collection.mintToken(alice, targetToken.nestingAddress()))
+ await expect(collection.mintToken(alice, targetToken.nestingAccount()))
.to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);
// Try to create a token to be nested and nest
@@ -472,7 +472,7 @@
await collection.setPermissions(alice, {access: 'AllowList', mintMode: true, nesting: {tokenOwner: true}});
await collection.addToAllowList(alice, {Substrate: bob.address});
- await collection.addToAllowList(alice, targetToken.nestingAddress());
+ await collection.addToAllowList(alice, targetToken.nestingAccount());
// Try to create a token to be nested and nest
const newToken = await collection.mintToken(alice);
@@ -488,11 +488,11 @@
await collection.setPermissions(alice, {access: 'AllowList', mintMode: true, nesting: {tokenOwner: true}});
await collection.addToAllowList(alice, {Substrate: bob.address});
- await collection.addToAllowList(alice, targetToken.nestingAddress());
+ await collection.addToAllowList(alice, targetToken.nestingAccount());
const collectionB = await helper.nft.mintCollection(alice, {permissions: {access: 'AllowList', mintMode: true}});
await collectionB.addToAllowList(alice, {Substrate: bob.address});
- await collectionB.addToAllowList(alice, targetToken.nestingAddress());
+ await collectionB.addToAllowList(alice, targetToken.nestingAccount());
// Try to create a token to be nested and nest
const newToken = await collectionB.mintToken(alice);
@@ -508,10 +508,10 @@
const targetToken = await collection.mintToken(alice, {Substrate: bob.address});
await collection.addToAllowList(alice, {Substrate: bob.address});
- await collection.addToAllowList(alice, targetToken.nestingAddress());
+ await collection.addToAllowList(alice, targetToken.nestingAccount());
// Try to mint in own collection after allowlisting the accounts
- await expect(collection.mintToken(bob, targetToken.nestingAddress()))
+ await expect(collection.mintToken(bob, targetToken.nestingAccount()))
.to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);
});
@@ -523,12 +523,12 @@
const targetToken = await collectionNFT.mintToken(alice);
// Try to create an immediately nested token
- await expect(collectionFT.mint(alice, 5n, targetToken.nestingAddress()))
+ await expect(collectionFT.mint(alice, 5n, targetToken.nestingAccount()))
.to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);
// Try to create a token to be nested and nest
await collectionFT.mint(alice, 5n);
- await expect(collectionFT.transfer(alice, targetToken.nestingAddress(), 2n))
+ await expect(collectionFT.transfer(alice, targetToken.nestingAccount(), 2n))
.to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);
expect(await collectionFT.getBalance({Substrate: alice.address})).to.be.equal(5n);
});
@@ -539,12 +539,12 @@
const targetToken = await collectionNFT.mintToken(alice, {Substrate: bob.address});
// Nest some tokens as Alice into Bob's token
- await collectionFT.mint(alice, 5n, targetToken.nestingAddress());
+ await collectionFT.mint(alice, 5n, targetToken.nestingAccount());
// Try to pull it out
- await expect(collectionFT.transferFrom(alice, targetToken.nestingAddress(), {Substrate: bob.address}, 1n))
+ await expect(collectionFT.transferFrom(alice, targetToken.nestingAccount(), {Substrate: bob.address}, 1n))
.to.be.rejectedWith(/common\.ApprovedValueTooLow/);
- expect(await collectionFT.getBalance(targetToken.nestingAddress())).to.be.equal(5n);
+ expect(await collectionFT.getBalance(targetToken.nestingAccount())).to.be.equal(5n);
});
itSub('Fungible: disallows a non-Owner to unnest someone else\'s token (Restricted nesting)', async ({helper}) => {
@@ -555,12 +555,12 @@
await collectionNFT.setPermissions(alice, {nesting: {collectionAdmin: true, tokenOwner: true, restricted: [collectionFT.collectionId]}});
// Nest some tokens as Alice into Bob's token
- await collectionFT.mint(alice, 5n, targetToken.nestingAddress());
+ await collectionFT.mint(alice, 5n, targetToken.nestingAccount());
// Try to pull it out as Alice still
- await expect(collectionFT.transferFrom(alice, targetToken.nestingAddress(), {Substrate: bob.address}, 1n))
+ await expect(collectionFT.transferFrom(alice, targetToken.nestingAccount(), {Substrate: bob.address}, 1n))
.to.be.rejectedWith(/common\.ApprovedValueTooLow/);
- expect(await collectionFT.getBalance(targetToken.nestingAddress())).to.be.equal(5n);
+ expect(await collectionFT.getBalance(targetToken.nestingAccount())).to.be.equal(5n);
});
itSub('Fungible: disallows to nest token in an unlisted collection', async ({helper}) => {
@@ -569,15 +569,15 @@
const targetToken = await collectionNFT.mintToken(alice);
// Try to mint an immediately nested token
- await expect(collectionFT.mint(alice, 5n, targetToken.nestingAddress()))
+ await expect(collectionFT.mint(alice, 5n, targetToken.nestingAccount()))
.to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);
// Mint a token and try to nest it
await collectionFT.mint(alice, 5n);
- await expect(collectionFT.transfer(alice, targetToken.nestingAddress(), 1n))
+ await expect(collectionFT.transfer(alice, targetToken.nestingAccount(), 1n))
.to.be.rejectedWith(/common\.SourceCollectionIsNotAllowedToNest/);
- expect(await collectionFT.getBalance(targetToken.nestingAddress())).to.be.equal(0n);
+ expect(await collectionFT.getBalance(targetToken.nestingAccount())).to.be.equal(0n);
expect(await collectionFT.getBalance({Substrate: alice.address})).to.be.equal(5n);
});
@@ -589,12 +589,12 @@
const targetToken = await collectionNFT.mintToken(alice);
// Try to create an immediately nested token
- await expect(collectionRFT.mintToken(alice, 5n, targetToken.nestingAddress()))
+ 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.nestingAddress(), 2n))
+ await expect(token.transfer(alice, targetToken.nestingAccount(), 2n))
.to.be.rejectedWith(/common\.UserIsNotAllowedToNest/);
expect(await token.getBalance({Substrate: alice.address})).to.be.equal(5n);
});
@@ -606,22 +606,22 @@
await collectionNFT.setPermissions(alice, {access: 'AllowList', mintMode: true, nesting: {tokenOwner: true}});
await collectionNFT.addToAllowList(alice, {Substrate: bob.address});
- await collectionNFT.addToAllowList(alice, targetToken.nestingAddress());
+ 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.nestingAddress())).to.be.rejectedWith(/common\.TokenValueTooLow/);
+ 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.nestingAddress());
+ await newToken.transfer(alice, targetToken.nestingAccount());
// Try to pull it out
- await expect(newToken.transferFrom(bob, targetToken.nestingAddress(), {Substrate: alice.address}, 1n))
+ await expect(newToken.transferFrom(bob, targetToken.nestingAccount(), {Substrate: alice.address}, 1n))
.to.be.rejectedWith(/common\.ApprovedValueTooLow/);
- expect(await newToken.getBalance(targetToken.nestingAddress())).to.be.equal(1n);
+ expect(await newToken.getBalance(targetToken.nestingAccount())).to.be.equal(1n);
});
itSub.ifWithPallets('ReFungible: disallows a non-Owner to nest someone else\'s token (Restricted nesting)', [Pallets.ReFungible], async ({helper}) => {
@@ -631,22 +631,22 @@
await collectionNFT.setPermissions(alice, {access: 'AllowList', mintMode: true, nesting: {tokenOwner: true, restricted: [collectionRFT.collectionId]}});
await collectionNFT.addToAllowList(alice, {Substrate: bob.address});
- await collectionNFT.addToAllowList(alice, targetToken.nestingAddress());
+ 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.nestingAddress())).to.be.rejectedWith(/common\.TokenValueTooLow/);
+ 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.nestingAddress());
+ await newToken.transfer(alice, targetToken.nestingAccount());
// Try to pull it out
- await expect(newToken.transferFrom(bob, targetToken.nestingAddress(), {Substrate: alice.address}, 1n))
+ await expect(newToken.transferFrom(bob, targetToken.nestingAccount(), {Substrate: alice.address}, 1n))
.to.be.rejectedWith(/common\.ApprovedValueTooLow/);
- expect(await newToken.getBalance(targetToken.nestingAddress())).to.be.equal(1n);
+ expect(await newToken.getBalance(targetToken.nestingAccount())).to.be.equal(1n);
});
itSub.ifWithPallets('ReFungible: disallows to nest token to an unlisted collection', [Pallets.ReFungible], async ({helper}) => {
@@ -655,12 +655,12 @@
const targetToken = await collectionNFT.mintToken(alice);
// Try to create an immediately nested token
- await expect(collectionRFT.mintToken(alice, 5n, targetToken.nestingAddress()))
+ 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.nestingAddress(), 2n))
+ 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/nesting/properties.test.tsdiffbeforeafterboth--- a/tests/src/nesting/properties.test.ts
+++ b/tests/src/nesting/properties.test.ts
@@ -651,7 +651,7 @@
const collectionA = await helper.nft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true}}});
const collectionB = await helper.nft.mintCollection(alice);
const targetToken = await collectionA.mintToken(alice);
- const nestedToken = await collectionB.mintToken(alice, targetToken.nestingAddress());
+ const nestedToken = await collectionB.mintToken(alice, targetToken.nestingAccount());
await collectionB.addAdmin(alice, {Substrate: bob.address});
await targetToken.transfer(alice, {Substrate: charlie.address});
@@ -692,7 +692,7 @@
const collectionA = await helper.nft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true}}});
const collectionB = await helper.nft.mintCollection(alice);
const targetToken = await collectionA.mintToken(alice);
- const nestedToken = await collectionB.mintToken(alice, targetToken.nestingAddress());
+ const nestedToken = await collectionB.mintToken(alice, targetToken.nestingAccount());
await collectionB.addAdmin(alice, {Substrate: bob.address});
await targetToken.transfer(alice, {Substrate: charlie.address});
@@ -739,7 +739,7 @@
const collectionA = await helper.nft.mintCollection(alice, {permissions: {nesting: {tokenOwner: true}}});
const collectionB = await helper.nft.mintCollection(alice);
const targetToken = await collectionA.mintToken(alice);
- const nestedToken = await collectionB.mintToken(alice, targetToken.nestingAddress());
+ const nestedToken = await collectionB.mintToken(alice, targetToken.nestingAccount());
await collectionB.addAdmin(alice, {Substrate: bob.address});
await targetToken.transfer(alice, {Substrate: charlie.address});
tests/src/nesting/unnest.test.tsdiffbeforeafterboth--- a/tests/src/nesting/unnest.test.ts
+++ b/tests/src/nesting/unnest.test.ts
@@ -32,15 +32,15 @@
const targetToken = await collection.mintToken(alice);
// Create a nested token
- const nestedToken = await collection.mintToken(alice, targetToken.nestingAddress());
+ const nestedToken = await collection.mintToken(alice, targetToken.nestingAccount());
// Unnest
- await expect(nestedToken.transferFrom(alice, targetToken.nestingAddress(), {Substrate: alice.address}), 'while unnesting').to.be.fulfilled;
+ await expect(nestedToken.transferFrom(alice, targetToken.nestingAccount(), {Substrate: alice.address}), 'while unnesting').to.be.fulfilled;
expect(await nestedToken.getOwner()).to.be.deep.equal({Substrate: alice.address});
// Nest and burn
await nestedToken.nest(alice, targetToken);
- await expect(nestedToken.burnFrom(alice, targetToken.nestingAddress()), 'while burning').to.be.fulfilled;
+ await expect(nestedToken.burnFrom(alice, targetToken.nestingAccount()), 'while burning').to.be.fulfilled;
await expect(nestedToken.getOwner()).to.be.rejected;
});
@@ -51,16 +51,16 @@
const collectionFT = await helper.ft.mintCollection(alice);
// Nest and unnest
- await collectionFT.mint(alice, 10n, targetToken.nestingAddress());
- await expect(collectionFT.transferFrom(alice, targetToken.nestingAddress(), {Substrate: alice.address}, 9n), 'while unnesting').to.be.fulfilled;
+ await collectionFT.mint(alice, 10n, targetToken.nestingAccount());
+ await expect(collectionFT.transferFrom(alice, targetToken.nestingAccount(), {Substrate: alice.address}, 9n), 'while unnesting').to.be.fulfilled;
expect(await collectionFT.getBalance({Substrate: alice.address})).to.be.equal(9n);
- expect(await collectionFT.getBalance(targetToken.nestingAddress())).to.be.equal(1n);
+ expect(await collectionFT.getBalance(targetToken.nestingAccount())).to.be.equal(1n);
// Nest and burn
- await collectionFT.transfer(alice, targetToken.nestingAddress(), 5n);
- await expect(collectionFT.burnTokensFrom(alice, targetToken.nestingAddress(), 6n), 'while burning').to.be.fulfilled;
+ await collectionFT.transfer(alice, targetToken.nestingAccount(), 5n);
+ await expect(collectionFT.burnTokensFrom(alice, targetToken.nestingAccount(), 6n), 'while burning').to.be.fulfilled;
expect(await collectionFT.getBalance({Substrate: alice.address})).to.be.equal(4n);
- expect(await collectionFT.getBalance(targetToken.nestingAddress())).to.be.equal(0n);
+ expect(await collectionFT.getBalance(targetToken.nestingAccount())).to.be.equal(0n);
expect(await targetToken.getChildren()).to.be.length(0);
});
@@ -71,16 +71,16 @@
const collectionRFT = await helper.rft.mintCollection(alice);
// Nest and unnest
- const token = await collectionRFT.mintToken(alice, 10n, targetToken.nestingAddress());
- await expect(token.transferFrom(alice, targetToken.nestingAddress(), {Substrate: alice.address}, 9n), 'while unnesting').to.be.fulfilled;
+ const token = await collectionRFT.mintToken(alice, 10n, targetToken.nestingAccount());
+ await expect(token.transferFrom(alice, targetToken.nestingAccount(), {Substrate: alice.address}, 9n), 'while unnesting').to.be.fulfilled;
expect(await token.getBalance({Substrate: alice.address})).to.be.equal(9n);
- expect(await token.getBalance(targetToken.nestingAddress())).to.be.equal(1n);
+ expect(await token.getBalance(targetToken.nestingAccount())).to.be.equal(1n);
// Nest and burn
- await token.transfer(alice, targetToken.nestingAddress(), 5n);
- await expect(token.burnFrom(alice, targetToken.nestingAddress(), 6n), 'while burning').to.be.fulfilled;
+ await token.transfer(alice, targetToken.nestingAccount(), 5n);
+ await expect(token.burnFrom(alice, targetToken.nestingAccount(), 6n), 'while burning').to.be.fulfilled;
expect(await token.getBalance({Substrate: alice.address})).to.be.equal(4n);
- expect(await token.getBalance(targetToken.nestingAddress())).to.be.equal(0n);
+ expect(await token.getBalance(targetToken.nestingAccount())).to.be.equal(0n);
expect(await targetToken.getChildren()).to.be.length(0);
});
});
@@ -101,15 +101,15 @@
const targetToken = await collection.mintToken(alice);
// Create a nested token
- const nestedToken = await collection.mintToken(alice, targetToken.nestingAddress());
+ const nestedToken = await collection.mintToken(alice, targetToken.nestingAccount());
// Try to unnest
await expect(nestedToken.unnest(bob, targetToken, {Substrate: alice.address})).to.be.rejectedWith(/common\.ApprovedValueTooLow/);
- expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAddress());
+ expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount());
// Try to burn
- await expect(nestedToken.burnFrom(bob, targetToken.nestingAddress())).to.be.rejectedWith(/common\.ApprovedValueTooLow/);
- expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAddress());
+ await expect(nestedToken.burnFrom(bob, targetToken.nestingAccount())).to.be.rejectedWith(/common\.ApprovedValueTooLow/);
+ expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount());
});
// todo another test for creating excessive depth matryoshka with Ethereum?
@@ -120,7 +120,7 @@
const targetToken = await collection.mintToken(alice);
// Fail to create a nested token ouroboros
- const nestedToken = await collection.mintToken(alice, targetToken.nestingAddress());
+ const nestedToken = await collection.mintToken(alice, targetToken.nestingAccount());
await expect(targetToken.nest(alice, nestedToken)).to.be.rejectedWith(/^structure\.OuroborosDetected$/);
});
});
tests/src/util/playgrounds/types.tsdiffbeforeafterboth--- a/tests/src/util/playgrounds/types.ts
+++ b/tests/src/util/playgrounds/types.ts
@@ -109,7 +109,6 @@
export interface IToken {
collectionId: number;
tokenId: number;
- //nestingAddress: () => {Ethereum: string};
}
export interface IBlock {
tests/src/util/playgrounds/unique.tsdiffbeforeafterboth--- a/tests/src/util/playgrounds/unique.ts
+++ b/tests/src/util/playgrounds/unique.ts
@@ -55,11 +55,11 @@
RPC: 'rpc',
};
- static getNestingTokenAddress(token: IToken) {
- return {Ethereum: this.getNestingTokenAddressRaw(token).toLowerCase()};
+ static getTokenAccount(token: IToken) {
+ return {Ethereum: this.getTokenAddress(token).toLowerCase()};
}
- static getNestingTokenAddressRaw(token: IToken) {
+ static getTokenAddress(token: IToken) {
return nesting.tokenIdToAddress(token.collectionId, token.tokenId);
}
@@ -1370,7 +1370,7 @@
* @returns ```true``` if extrinsic success, otherwise ```false```
*/
async nestToken(signer: TSigner, tokenObj: IToken, rootTokenObj: IToken): Promise<boolean> {
- const rootTokenAddress = this.helper.util.getNestingTokenAddress(rootTokenObj);
+ const rootTokenAddress = this.helper.util.getTokenAccount(rootTokenObj);
const result = await this.transferToken(signer, tokenObj.collectionId, tokenObj.tokenId, rootTokenAddress);
if(!result) {
throw Error('Unable to nest token!');
@@ -1388,7 +1388,7 @@
* @returns ```true``` if extrinsic success, otherwise ```false```
*/
async unnestToken(signer: TSigner, tokenObj: IToken, rootTokenObj: IToken, toAddressObj: ICrossAccountId): Promise<boolean> {
- const rootTokenAddress = this.helper.util.getNestingTokenAddress(rootTokenObj);
+ const rootTokenAddress = this.helper.util.getTokenAccount(rootTokenObj);
const result = await this.transferTokenFrom(signer, tokenObj.collectionId, tokenObj.tokenId, rootTokenAddress, toAddressObj);
if(!result) {
throw Error('Unable to unnest token!');
@@ -2566,8 +2566,8 @@
return await this.collection.deleteTokenProperties(signer, this.tokenId, propertyKeys);
}
- nestingAddress() {
- return this.collection.helper.util.getNestingTokenAddress(this);
+ nestingAccount() {
+ return this.collection.helper.util.getTokenAccount(this);
}
}