git.delta.rocks / unique-network / refs/commits / ab382166ac96

difftreelog

Merge pull request #627 from UniqueNetwork/test/eth-market

ut-akuznetsov2022-10-05parents: #8b875cb #4ad2532.patch.diff
in: master
Test/eth market to playgrounds

3 files changed

modifiedtests/src/eth/marketplace/marketplace.test.tsdiffbeforeafterboth
14// You should have received a copy of the GNU General Public License14// You should have received a copy of the GNU General Public License
15// 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/>.
1616
17import {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';
3421
35import {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;
3630
37const PRICE = 2000n;31 before(async () => {
32 await usingPlaygrounds(async (_helper, privateKey) => {
33 donor = privateKey('//Alice');
34 });
35 });
3836
39describe('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();
44
45 await helper.balance.transferToSubstrate(donor, aliceDoubleMirror, 10_000_000_000_000_000_000n);
43 const matcherOwner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);46 });
47 });
48
49 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});
57
49 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});
5565
56 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);
6271
63 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});
6574
66 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});
6876
69 const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT', seller.address);
70
71 // To transfer item to matcher it first needs to be transfered to EVM account of bob
72 await transferExpectSuccess(collectionId, tokenId, seller, {Ethereum: subToEth(seller.address)});
73
74 // Token is owned by seller initially77 // Token is owned by seller initially
75 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});
7679
77 // Ask80 // Ask
78 {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 }
8285
83 // Token is transferred to matcher86 // Token is transferred to matcher
84 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()});
8588
86 // Buy89 // Buy
87 {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 }
9295
93 // Token is transferred to evm account of alice96 // Token is transferred to evm account of alice
94 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});
9598
96 // Transfer token to substrate side of alice99 // Transfer token to substrate side of alice
97 await transferFromExpectSuccess(collectionId, tokenId, alice, {Ethereum: subToEth(alice.address)}, {Substrate: alice.address});100 await token.transferFrom(alice, {Ethereum: aliceMirror}, {Substrate: alice.address});
98101
99 // Token is transferred to substrate account of alice, seller received funds102 // Token is transferred to substrate account of alice, seller received funds
100 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 });
102105
103
104 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});
114
115 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});
121124
122 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);
128130
129 await helpers.methods.toggleAllowed(matcher.options.address, subToEth(alice.address), true).send({from: matcherOwner});
130 await addToAllowListExpectSuccess(alice, collectionId, evmToAddress(subToEth(alice.address)));
131131
132 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});
134133
135 const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT', seller.address);134 await helpers.methods.toggleAllowed(matcher.options.address, sellerMirror, true).send({from: matcherOwner});
136135
137 // 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)});
139137
140 // Token is owned by seller initially138 // Token is owned by seller initially
141 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});
142140
143 // Ask141 // Ask
144 {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 }
148146
149 // Token is transferred to matcher147 // Token is transferred to matcher
150 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()});
151149
152 // Give buyer KSM150 // Give buyer KSM
153 await matcher.methods.depositKSM(PRICE, subToEth(alice.address)).send({from: escrow});151 await matcher.methods.depositKSM(PRICE, aliceMirror).send({from: escrow});
154152
155 // Buy153 // Buy
156 {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());
159157
160 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');
161159
162 // Price is removed from buyer balance, and added to seller160 // Price is removed from buyer balance, and added to seller
163 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 }
166164
167 // Token is transferred to evm account of alice165 // Token is transferred to evm account of alice
168 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});
169167
170 // Transfer token to substrate side of alice168 // Transfer token to substrate side of alice
171 await transferFromExpectSuccess(collectionId, tokenId, alice, {Ethereum: subToEth(alice.address)}, {Substrate: alice.address});169 await token.transferFrom(alice, {Ethereum: aliceMirror}, {Substrate: alice.address});
172170
173 // Token is transferred to substrate account of alice, seller received funds171 // Token is transferred to substrate account of alice, seller received funds
174 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 });
176174
177
178 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);
187183
188 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});
191185
192 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');
188
193 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});
196
197 // To transfer item to matcher it first needs to be transfered to EVM account of bob
198 await transferExpectSuccess(collectionId, tokenId, seller, {Ethereum: subToEth(seller.address)});
199192
200 // Token is owned by seller initially193 // Token is owned by seller initially
201 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});
202195
203 // Ask196 // Ask
204 {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 }
208201
209 // Token is transferred to matcher202 // Token is transferred to matcher
210 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()});
211204
212 // Buy205 // Buy
213 {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 }
218211
219 // Token is transferred to evm account of alice212 // Token is transferred to evm account of alice
220 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});
221214
222 // Transfer token to substrate side of alice215 // Transfer token to substrate side of alice
223 await transferFromExpectSuccess(collectionId, tokenId, alice, {Ethereum: subToEth(alice.address)}, {Substrate: alice.address});216 await token.transferFrom(alice, {Ethereum: aliceMirror}, {Substrate: alice.address});
224217
225 // Token is transferred to substrate account of alice, seller received funds218 // Token is transferred to substrate account of alice, seller received funds
226 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});
229222
modifiedtests/src/eth/util/playgrounds/index.tsdiffbeforeafterboth
18chai.use(chaiLike);18chai.use(chaiLike);
19export const expect = chai.expect;19export const expect = chai.expect;
20
21export enum SponsoringMode {
22 Disabled = 0,
23 Allowlisted = 1,
24 Generous = 2,
25}
2026
21export 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();
modifiedtests/src/util/playgrounds/unique.tsdiffbeforeafterboth
275 }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 );