difftreelog
Merge pull request #627 from UniqueNetwork/test/eth-market
in: master
Test/eth market to playgrounds
3 files changed
tests/src/eth/marketplace/marketplace.test.tsdiffbeforeafterboth14// You should have received a copy of the GNU General Public License14// You should have received a copy of the GNU General Public License15// 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 {usingPlaygrounds} from './../../util/playgrounds/index';18import {IKeyringPair} from '@polkadot/types/types';17import {readFile} from 'fs/promises';19import {readFile} from 'fs/promises';18import {getBalanceSingle} from '../../substrate/get-balance';20import {itEth, expect, SponsoringMode} from '../util/playgrounds';19import {20 addToAllowListExpectSuccess, 21 confirmSponsorshipExpectSuccess, 22 createCollectionExpectSuccess, 23 createItemExpectSuccess, 24 getTokenOwner,25 setCollectionLimitsExpectSuccess, 26 setCollectionSponsorExpectSuccess, 27 transferExpectSuccess, 28 transferFromExpectSuccess,29 transferBalanceTo,30} from '../../util/helpers';31import {collectionIdToAddress, contractHelpers, createEthAccountWithBalance, executeEthTxOnSub, GAS_ARGS, itWeb3, SponsoringMode, subToEth, subToEthLowercase, transferBalanceToEth} from '../util/helpers';32import {evmToAddress} from '@polkadot/util-crypto';33import nonFungibleAbi from '../nonFungibleAbi.json';342135import {expect} from 'chai';22describe('Matcher contract usage', () => {23 const PRICE = 2000n;24 let donor: IKeyringPair;25 let alice: IKeyringPair;26 let aliceMirror: string;27 let aliceDoubleMirror: string;28 let seller: IKeyringPair;29 let sellerMirror: string;363037const PRICE = 2000n;31 before(async () => {32 await usingPlaygrounds(async (_helper, privateKey) => {33 donor = privateKey('//Alice');34 }); 35 });383639describe('Matcher contract usage', () => {37 beforeEach(async () => {40 itWeb3('With UNQ', async ({api, web3, privateKeyWrapper}) => {38 await usingPlaygrounds(async (helper, privateKey) => {41 const alice = privateKeyWrapper('//Alice');39 [alice] = await helper.arrange.createAccounts([10000n], donor);40 aliceMirror = helper.address.substrateToEth(alice.address).toLowerCase();41 aliceDoubleMirror = helper.address.ethToSubstrate(aliceMirror);42 seller = privateKey(`//Seller/${Date.now()}`);42 const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);43 sellerMirror = helper.address.substrateToEth(seller.address).toLowerCase();4445 await helper.balance.transferToSubstrate(donor, aliceDoubleMirror, 10_000_000_000_000_000_000n);43 const matcherOwner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);46 });47 });4849 itEth('With UNQ', async ({helper}) => {50 const web3 = helper.getWeb3();51 const matcherOwner = await helper.eth.createAccountWithBalance(donor);44 const matcherContract = new web3.eth.Contract(JSON.parse((await readFile(`${__dirname}/MarketPlace.abi`)).toString()), undefined, {52 const matcherContract = new web3.eth.Contract(JSON.parse((await readFile(`${__dirname}/MarketPlace.abi`)).toString()), undefined, {45 from: matcherOwner,53 from: matcherOwner,46 ...GAS_ARGS,54 gas: helper.eth.DEFAULT_GAS,47 });55 });48 const matcher = await matcherContract.deploy({data: (await readFile(`${__dirname}/MarketPlace.bin`)).toString(), arguments:[matcherOwner]}).send({from: matcherOwner});56 const matcher = await matcherContract.deploy({data: (await readFile(`${__dirname}/MarketPlace.bin`)).toString(), arguments:[matcherOwner]}).send({from: matcherOwner});5749 const helpers = contractHelpers(web3, matcherOwner);58 const sponsor = await helper.eth.createAccountWithBalance(donor);59 const helpers = helper.ethNativeContract.contractHelpers(matcherOwner);50 await helpers.methods.setSponsoringMode(matcher.options.address, SponsoringMode.Allowlisted).send({from: matcherOwner});60 await helpers.methods.setSponsoringMode(matcher.options.address, SponsoringMode.Allowlisted).send({from: matcherOwner});51 await helpers.methods.setSponsoringRateLimit(matcher.options.address, 1).send({from: matcherOwner});61 await helpers.methods.setSponsoringRateLimit(matcher.options.address, 1).send({from: matcherOwner});52 62 53 await helpers.methods.setSponsor(matcher.options.address, sponsor).send({from: matcherOwner});63 await helpers.methods.setSponsor(matcher.options.address, sponsor).send({from: matcherOwner});54 await helpers.methods.confirmSponsorship(matcher.options.address).send({from: sponsor});64 await helpers.methods.confirmSponsorship(matcher.options.address).send({from: sponsor});556556 const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});66 const collection = await helper.nft.mintCollection(alice, {limits: {sponsorApproveTimeout: 1}, pendingSponsor: alice.address});57 await setCollectionLimitsExpectSuccess(alice, collectionId, {sponsorApproveTimeout: 1});67 await collection.confirmSponsorship(alice);68 await collection.addToAllowList(alice, {Substrate: aliceDoubleMirror});58 const evmCollection = new web3.eth.Contract(nonFungibleAbi as any, collectionIdToAddress(collectionId), {from: matcherOwner});69 const evmCollection = helper.ethNativeContract.collection(helper.ethAddress.fromCollectionId(collection.collectionId), 'nft');59 await setCollectionSponsorExpectSuccess(collectionId, alice.address);70 await helper.eth.transferBalanceFromSubstrate(donor, aliceMirror);60 await transferBalanceToEth(api, alice, subToEth(alice.address));61 await confirmSponsorshipExpectSuccess(collectionId);627163 await helpers.methods.toggleAllowed(matcher.options.address, subToEth(alice.address), true).send({from: matcherOwner});72 await helpers.methods.toggleAllowed(matcher.options.address, aliceMirror, true).send({from: matcherOwner});64 await addToAllowListExpectSuccess(alice, collectionId, evmToAddress(subToEth(alice.address)));73 await helpers.methods.toggleAllowed(matcher.options.address, sellerMirror, true).send({from: matcherOwner});657466 const seller = privateKeyWrapper(`//Seller/${Date.now()}`);75 const token = await collection.mintToken(alice, {Ethereum: sellerMirror});67 await helpers.methods.toggleAllowed(matcher.options.address, subToEth(seller.address), true).send({from: matcherOwner});687669 const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT', seller.address);7071 // To transfer item to matcher it first needs to be transfered to EVM account of bob72 await transferExpectSuccess(collectionId, tokenId, seller, {Ethereum: subToEth(seller.address)});7374 // Token is owned by seller initially77 // Token is owned by seller initially75 expect(await getTokenOwner(api, collectionId, tokenId)).to.be.deep.equal({Ethereum: subToEthLowercase(seller.address)});78 expect(await token.getOwner()).to.be.deep.equal({Ethereum: sellerMirror});767977 // Ask80 // Ask78 {81 {79 await executeEthTxOnSub(web3, api, seller, evmCollection, m => m.approve(matcher.options.address, tokenId));82 await helper.eth.sendEVM(seller, evmCollection.options.address, evmCollection.methods.approve(matcher.options.address, token.tokenId).encodeABI(), '0');80 await executeEthTxOnSub(web3, api, seller, matcher, m => m.addAsk(PRICE, '0x0000000000000000000000000000000000000001', evmCollection.options.address, tokenId));83 await helper.eth.sendEVM(seller, matcher.options.address, matcher.methods.addAsk(PRICE, '0x0000000000000000000000000000000000000001', evmCollection.options.address, token.tokenId).encodeABI(), '0');81 }84 }828583 // Token is transferred to matcher86 // Token is transferred to matcher84 expect(await getTokenOwner(api, collectionId, tokenId)).to.be.deep.equal({Ethereum: matcher.options.address.toLowerCase()});87 expect(await token.getOwner()).to.be.deep.equal({Ethereum: matcher.options.address.toLowerCase()});858886 // Buy89 // Buy87 {90 {88 const sellerBalanceBeforePurchase = await getBalanceSingle(api, seller.address);91 const sellerBalanceBeforePurchase = await helper.balance.getSubstrate(seller.address);89 await executeEthTxOnSub(web3, api, alice, matcher, m => m.buy(evmCollection.options.address, tokenId), {value: PRICE});92 await helper.eth.sendEVM(alice, matcher.options.address, matcher.methods.buy(evmCollection.options.address, token.tokenId).encodeABI(), PRICE.toString());90 expect(await getBalanceSingle(api, seller.address) - sellerBalanceBeforePurchase === PRICE);93 expect(await helper.balance.getSubstrate(seller.address) - sellerBalanceBeforePurchase === PRICE);91 }94 }929593 // Token is transferred to evm account of alice96 // Token is transferred to evm account of alice94 expect(await getTokenOwner(api, collectionId, tokenId)).to.be.deep.equal({Ethereum: subToEthLowercase(alice.address)});97 expect(await token.getOwner()).to.be.deep.equal({Ethereum: aliceMirror});959896 // Transfer token to substrate side of alice99 // Transfer token to substrate side of alice97 await transferFromExpectSuccess(collectionId, tokenId, alice, {Ethereum: subToEth(alice.address)}, {Substrate: alice.address});100 await token.transferFrom(alice, {Ethereum: aliceMirror}, {Substrate: alice.address});9810199 // Token is transferred to substrate account of alice, seller received funds102 // Token is transferred to substrate account of alice, seller received funds100 expect(await getTokenOwner(api, collectionId, tokenId)).to.be.deep.equal({Substrate: alice.address});103 expect(await token.getOwner()).to.be.deep.equal({Substrate: alice.address});101 });104 });102105103104 itWeb3('With escrow', async ({api, web3, privateKeyWrapper}) => {106 itEth('With escrow', async ({helper}) => {105 const alice = privateKeyWrapper('//Alice');107 const web3 = helper.getWeb3();106 const sponsor = await createEthAccountWithBalance(api, web3, privateKeyWrapper);108 const matcherOwner = await helper.eth.createAccountWithBalance(donor);107 const matcherOwner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);108 const escrow = await createEthAccountWithBalance(api, web3, privateKeyWrapper);109 const matcherContract = new web3.eth.Contract(JSON.parse((await readFile(`${__dirname}/MarketPlace.abi`)).toString()), undefined, {109 const matcherContract = new web3.eth.Contract(JSON.parse((await readFile(`${__dirname}/MarketPlace.abi`)).toString()), undefined, {110 from: matcherOwner,110 from: matcherOwner,111 ...GAS_ARGS,111 gas: helper.eth.DEFAULT_GAS,112 });112 });113 const matcher = await matcherContract.deploy({data: (await readFile(`${__dirname}/MarketPlace.bin`)).toString(), arguments: [matcherOwner]}).send({from: matcherOwner, gas: 10000000});113 const matcher = await matcherContract.deploy({data: (await readFile(`${__dirname}/MarketPlace.bin`)).toString(), arguments: [matcherOwner]}).send({from: matcherOwner, gas: 10000000});114115 const sponsor = await helper.eth.createAccountWithBalance(donor);116 const escrow = await helper.eth.createAccountWithBalance(donor);114 await matcher.methods.setEscrow(escrow).send({from: matcherOwner});117 await matcher.methods.setEscrow(escrow).send({from: matcherOwner});115 const helpers = contractHelpers(web3, matcherOwner);118 const helpers = helper.ethNativeContract.contractHelpers(matcherOwner);116 await helpers.methods.setSponsoringMode(matcher.options.address, SponsoringMode.Allowlisted).send({from: matcherOwner});119 await helpers.methods.setSponsoringMode(matcher.options.address, SponsoringMode.Allowlisted).send({from: matcherOwner});117 await helpers.methods.setSponsoringRateLimit(matcher.options.address, 1).send({from: matcherOwner});120 await helpers.methods.setSponsoringRateLimit(matcher.options.address, 1).send({from: matcherOwner});118 121 119 await helpers.methods.setSponsor(matcher.options.address, sponsor).send({from: matcherOwner});122 await helpers.methods.setSponsor(matcher.options.address, sponsor).send({from: matcherOwner});120 await helpers.methods.confirmSponsorship(matcher.options.address).send({from: sponsor});123 await helpers.methods.confirmSponsorship(matcher.options.address).send({from: sponsor});121124122 const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});125 const collection = await helper.nft.mintCollection(alice, {limits: {sponsorApproveTimeout: 1}, pendingSponsor: alice.address});123 await setCollectionLimitsExpectSuccess(alice, collectionId, {sponsorApproveTimeout: 1});126 await collection.confirmSponsorship(alice);127 await collection.addToAllowList(alice, {Substrate: aliceDoubleMirror});124 const evmCollection = new web3.eth.Contract(nonFungibleAbi as any, collectionIdToAddress(collectionId), {from: matcherOwner});128 const evmCollection = helper.ethNativeContract.collection(helper.ethAddress.fromCollectionId(collection.collectionId), 'nft');125 await setCollectionSponsorExpectSuccess(collectionId, alice.address);129 await helper.eth.transferBalanceFromSubstrate(donor, aliceMirror);126 await transferBalanceToEth(api, alice, subToEth(alice.address));127 await confirmSponsorshipExpectSuccess(collectionId);128130129 await helpers.methods.toggleAllowed(matcher.options.address, subToEth(alice.address), true).send({from: matcherOwner});130 await addToAllowListExpectSuccess(alice, collectionId, evmToAddress(subToEth(alice.address)));131131132 const seller = privateKeyWrapper(`//Seller/${Date.now()}`);132 await helpers.methods.toggleAllowed(matcher.options.address, aliceMirror, true).send({from: matcherOwner});133 await helpers.methods.toggleAllowed(matcher.options.address, subToEth(seller.address), true).send({from: matcherOwner});134133135 const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT', seller.address);134 await helpers.methods.toggleAllowed(matcher.options.address, sellerMirror, true).send({from: matcherOwner});136135137 // To transfer item to matcher it first needs to be transfered to EVM account of bob136 const token = await collection.mintToken(alice, {Ethereum: sellerMirror});138 await transferExpectSuccess(collectionId, tokenId, seller, {Ethereum: subToEth(seller.address)});139137140 // Token is owned by seller initially138 // Token is owned by seller initially141 expect(await getTokenOwner(api, collectionId, tokenId)).to.be.deep.equal({Ethereum: subToEthLowercase(seller.address)});139 expect(await token.getOwner()).to.be.deep.equal({Ethereum: sellerMirror});142140143 // Ask141 // Ask144 {142 {145 await executeEthTxOnSub(web3, api, seller, evmCollection, m => m.approve(matcher.options.address, tokenId));143 await helper.eth.sendEVM(seller, evmCollection.options.address, evmCollection.methods.approve(matcher.options.address, token.tokenId).encodeABI(), '0');146 await executeEthTxOnSub(web3, api, seller, matcher, m => m.addAsk(PRICE, '0x0000000000000000000000000000000000000001', evmCollection.options.address, tokenId));144 await helper.eth.sendEVM(seller, matcher.options.address, matcher.methods.addAsk(PRICE, '0x0000000000000000000000000000000000000001', evmCollection.options.address, token.tokenId).encodeABI(), '0');147 }145 }148146149 // Token is transferred to matcher147 // Token is transferred to matcher150 expect(await getTokenOwner(api, collectionId, tokenId)).to.be.deep.equal({Ethereum: matcher.options.address.toLowerCase()});148 expect(await token.getOwner()).to.be.deep.equal({Ethereum: matcher.options.address.toLowerCase()});151149152 // Give buyer KSM150 // Give buyer KSM153 await matcher.methods.depositKSM(PRICE, subToEth(alice.address)).send({from: escrow});151 await matcher.methods.depositKSM(PRICE, aliceMirror).send({from: escrow});154152155 // Buy153 // Buy156 {154 {157 expect(await matcher.methods.balanceKSM(subToEth(seller.address)).call()).to.be.equal('0');155 expect(await matcher.methods.balanceKSM(sellerMirror).call()).to.be.equal('0');158 expect(await matcher.methods.balanceKSM(subToEth(alice.address)).call()).to.be.equal(PRICE.toString());156 expect(await matcher.methods.balanceKSM(aliceMirror).call()).to.be.equal(PRICE.toString());159157160 await executeEthTxOnSub(web3, api, alice, matcher, m => m.buyKSM(evmCollection.options.address, tokenId, subToEth(alice.address), subToEth(alice.address)));158 await helper.eth.sendEVM(alice, matcher.options.address, matcher.methods.buyKSM(evmCollection.options.address, token.tokenId, aliceMirror, aliceMirror).encodeABI(), '0');161159162 // Price is removed from buyer balance, and added to seller160 // Price is removed from buyer balance, and added to seller163 expect(await matcher.methods.balanceKSM(subToEth(alice.address)).call()).to.be.equal('0');161 expect(await matcher.methods.balanceKSM(aliceMirror).call()).to.be.equal('0');164 expect(await matcher.methods.balanceKSM(subToEth(seller.address)).call()).to.be.equal(PRICE.toString());162 expect(await matcher.methods.balanceKSM(sellerMirror).call()).to.be.equal(PRICE.toString());165 }163 }166164167 // Token is transferred to evm account of alice165 // Token is transferred to evm account of alice168 expect(await getTokenOwner(api, collectionId, tokenId)).to.be.deep.equal({Ethereum: subToEthLowercase(alice.address)});166 expect(await token.getOwner()).to.be.deep.equal({Ethereum: aliceMirror});169167170 // Transfer token to substrate side of alice168 // Transfer token to substrate side of alice171 await transferFromExpectSuccess(collectionId, tokenId, alice, {Ethereum: subToEth(alice.address)}, {Substrate: alice.address});169 await token.transferFrom(alice, {Ethereum: aliceMirror}, {Substrate: alice.address});172170173 // Token is transferred to substrate account of alice, seller received funds171 // Token is transferred to substrate account of alice, seller received funds174 expect(await getTokenOwner(api, collectionId, tokenId)).to.be.deep.equal({Substrate: alice.address});172 expect(await token.getOwner()).to.be.deep.equal({Substrate: alice.address});175 });173 });176174177178 itWeb3('Sell tokens from substrate user via EVM contract', async ({api, web3, privateKeyWrapper}) => {175 itEth('Sell tokens from substrate user via EVM contract', async ({helper}) => {179 const alice = privateKeyWrapper('//Alice');176 const web3 = helper.getWeb3();180 const matcherOwner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);177 const matcherOwner = await helper.eth.createAccountWithBalance(donor);181 const matcherContract = new web3.eth.Contract(JSON.parse((await readFile(`${__dirname}/MarketPlace.abi`)).toString()), undefined, {178 const matcherContract = new web3.eth.Contract(JSON.parse((await readFile(`${__dirname}/MarketPlace.abi`)).toString()), undefined, {182 from: matcherOwner,179 from: matcherOwner,183 ...GAS_ARGS,180 gas: helper.eth.DEFAULT_GAS,184 });181 });185 const matcher = await matcherContract.deploy({data: (await readFile(`${__dirname}/MarketPlace.bin`)).toString(), arguments:[matcherOwner]}).send({from: matcherOwner});182 const matcher = await matcherContract.deploy({data: (await readFile(`${__dirname}/MarketPlace.bin`)).toString(), arguments:[matcherOwner]}).send({from: matcherOwner});186 await transferBalanceToEth(api, alice, matcher.options.address);187183188 const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});184 await helper.eth.transferBalanceFromSubstrate(donor, matcher.options.address);189 await setCollectionLimitsExpectSuccess(alice, collectionId, {sponsorApproveTimeout: 1});190 const evmCollection = new web3.eth.Contract(nonFungibleAbi as any, collectionIdToAddress(collectionId), {from: matcherOwner});191185192 const seller = privateKeyWrapper(`//Seller/${Date.now()}`);186 const collection = await helper.nft.mintCollection(alice, {limits: {sponsorApproveTimeout: 1}});187 const evmCollection = helper.ethNativeContract.collection(helper.ethAddress.fromCollectionId(collection.collectionId), 'nft');188193 await transferBalanceTo(api, alice, seller.address);189 await helper.balance.transferToSubstrate(donor, seller.address, 100_000_000_000_000_000_000n);194 190 195 const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT', seller.address);191 const token = await collection.mintToken(alice, {Ethereum: sellerMirror});196197 // To transfer item to matcher it first needs to be transfered to EVM account of bob198 await transferExpectSuccess(collectionId, tokenId, seller, {Ethereum: subToEth(seller.address)});199192200 // Token is owned by seller initially193 // Token is owned by seller initially201 expect(await getTokenOwner(api, collectionId, tokenId)).to.be.deep.equal({Ethereum: subToEthLowercase(seller.address)});194 expect(await token.getOwner()).to.be.deep.equal({Ethereum: sellerMirror});202195203 // Ask196 // Ask204 {197 {205 await executeEthTxOnSub(web3, api, seller, evmCollection, m => m.approve(matcher.options.address, tokenId));198 await helper.eth.sendEVM(seller, evmCollection.options.address, evmCollection.methods.approve(matcher.options.address, token.tokenId).encodeABI(), '0');206 await executeEthTxOnSub(web3, api, seller, matcher, m => m.addAsk(PRICE, '0x0000000000000000000000000000000000000001', evmCollection.options.address, tokenId));199 await helper.eth.sendEVM(seller, matcher.options.address, matcher.methods.addAsk(PRICE, '0x0000000000000000000000000000000000000001', evmCollection.options.address, token.tokenId).encodeABI(), '0');207 }200 }208201209 // Token is transferred to matcher202 // Token is transferred to matcher210 expect(await getTokenOwner(api, collectionId, tokenId)).to.be.deep.equal({Ethereum: matcher.options.address.toLowerCase()});203 expect(await token.getOwner()).to.be.deep.equal({Ethereum: matcher.options.address.toLowerCase()});211204212 // Buy205 // Buy213 {206 {214 const sellerBalanceBeforePurchase = await getBalanceSingle(api, seller.address);207 const sellerBalanceBeforePurchase = await helper.balance.getSubstrate(seller.address);215 await executeEthTxOnSub(web3, api, alice, matcher, m => m.buy(evmCollection.options.address, tokenId), {value: PRICE});208 await helper.eth.sendEVM(alice, matcher.options.address, matcher.methods.buy(evmCollection.options.address, token.tokenId).encodeABI(), PRICE.toString());216 expect(await getBalanceSingle(api, seller.address) - sellerBalanceBeforePurchase === PRICE);209 expect(await helper.balance.getSubstrate(seller.address) - sellerBalanceBeforePurchase === PRICE);217 }210 }218211219 // Token is transferred to evm account of alice212 // Token is transferred to evm account of alice220 expect(await getTokenOwner(api, collectionId, tokenId)).to.be.deep.equal({Ethereum: subToEthLowercase(alice.address)});213 expect(await token.getOwner()).to.be.deep.equal({Ethereum: aliceMirror});221214222 // Transfer token to substrate side of alice215 // Transfer token to substrate side of alice223 await transferFromExpectSuccess(collectionId, tokenId, alice, {Ethereum: subToEth(alice.address)}, {Substrate: alice.address});216 await token.transferFrom(alice, {Ethereum: aliceMirror}, {Substrate: alice.address});224217225 // Token is transferred to substrate account of alice, seller received funds218 // Token is transferred to substrate account of alice, seller received funds226 expect(await getTokenOwner(api, collectionId, tokenId)).to.be.deep.equal({Substrate: alice.address});219 expect(await token.getOwner()).to.be.deep.equal({Substrate: alice.address});227 });220 });228});221});229222tests/src/eth/util/playgrounds/index.tsdiffbeforeafterboth18chai.use(chaiLike);18chai.use(chaiLike);19export const expect = chai.expect;19export const expect = chai.expect;2021export enum SponsoringMode {22 Disabled = 0,23 Allowlisted = 1,24 Generous = 2,25}202621export const usingEthPlaygrounds = async (code: (helper: EthUniqueHelper, privateKey: (seed: string) => IKeyringPair) => Promise<void>) => {27export const usingEthPlaygrounds = async (code: (helper: EthUniqueHelper, privateKey: (seed: string) => IKeyringPair) => Promise<void>) => {22 const silentConsole = new SilentConsole();28 const silentConsole = new SilentConsole();tests/src/util/playgrounds/unique.tsdiffbeforeafterboth275 }275 }276 276 277 private static extractData(data: any, type: any): any {277 private static extractData(data: any, type: any): any {278 if(!type) return data.toHuman();278 if (['u16', 'u32'].indexOf(type.type) > -1) return data.toNumber();279 if (['u16', 'u32'].indexOf(type.type) > -1) return data.toNumber();279 if (['u64', 'u128', 'u256'].indexOf(type.type) > -1) return data.toBigInt();280 if (['u64', 'u128', 'u256'].indexOf(type.type) > -1) return data.toBigInt();280 if(type.hasOwnProperty('sub')) return this.extractSub(data, type.sub);281 if(type.hasOwnProperty('sub')) return this.extractSub(data, type.sub);2160 */2161 */2161 async stake(signer: TSigner, amountToStake: bigint, label?: string): Promise<boolean> {2162 async stake(signer: TSigner, amountToStake: bigint, label?: string): Promise<boolean> {2162 if(typeof label === 'undefined') label = `${signer.address} amount: ${amountToStake}`;2163 if(typeof label === 'undefined') label = `${signer.address} amount: ${amountToStake}`;2163 const stakeResult = await this.helper.executeExtrinsic(2164 const _stakeResult = await this.helper.executeExtrinsic(2164 signer, 'api.tx.appPromotion.stake',2165 signer, 'api.tx.appPromotion.stake',2165 [amountToStake], true,2166 [amountToStake], true,2166 );2167 );2177 */2178 */2178 async unstake(signer: TSigner, label?: string): Promise<number> {2179 async unstake(signer: TSigner, label?: string): Promise<number> {2179 if(typeof label === 'undefined') label = `${signer.address}`;2180 if(typeof label === 'undefined') label = `${signer.address}`;2180 const unstakeResult = await this.helper.executeExtrinsic(2181 const _unstakeResult = await this.helper.executeExtrinsic(2181 signer, 'api.tx.appPromotion.unstake',2182 signer, 'api.tx.appPromotion.unstake',2182 [], true,2183 [], true,2183 );2184 );