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

difftreelog

test update gas prices for new frontier

Yaroslav Bolyukin2021-11-26parent: #d53cfa2.patch.diff
in: master

4 files changed

modifiednode/cli/src/chain_spec.rsdiffbeforeafterboth
213 balances: endowed_accounts213 balances: endowed_accounts
214 .iter()214 .iter()
215 .cloned()215 .cloned()
216 // 1e13 UNQ
216 .map(|k| (k, 1 << 70))217 .map(|k| (k, 1 << 100))
217 .collect(),218 .collect(),
218 },219 },
219 treasury: Default::default(),220 treasury: Default::default(),
modifiedtests/src/eth/marketplace/marketplace.test.tsdiffbeforeafterboth
13describe('Matcher contract usage', () => {13describe('Matcher contract usage', () => {
14 itWeb3('With UNQ', async ({api, web3}) => {14 itWeb3('With UNQ', async ({api, web3}) => {
15 const alice = privateKey('//Alice');15 const alice = privateKey('//Alice');
16 const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
17 const evmCollection = new web3.eth.Contract(nonFungibleAbi as any, collectionIdToAddress(collectionId));
18 const matcherOwner = await createEthAccountWithBalance(api, web3);16 const matcherOwner = await createEthAccountWithBalance(api, web3);
19 const helpers = contractHelpers(web3, matcherOwner);
20
21 const matcherContract = new web3.eth.Contract(JSON.parse((await readFile(`${__dirname}/MarketPlace.abi`)).toString()), undefined, {17 const matcherContract = new web3.eth.Contract(JSON.parse((await readFile(`${__dirname}/MarketPlace.abi`)).toString()), undefined, {
22 from: matcherOwner,18 from: matcherOwner,
23 ...GAS_ARGS,19 ...GAS_ARGS,
24 });20 });
25 const matcher = await matcherContract.deploy({data: (await readFile(`${__dirname}/MarketPlace.bin`)).toString(), arguments:[matcherOwner]}).send({from: matcherOwner});21 const matcher = await matcherContract.deploy({data: (await readFile(`${__dirname}/MarketPlace.bin`)).toString(), arguments:[matcherOwner]}).send({from: matcherOwner});
2622 const helpers = contractHelpers(web3, matcherOwner);
27 await transferBalanceToEth(api, alice, matcher.options.address);23 await helpers.methods.toggleSponsoring(matcher.options.address, true).send({from: matcherOwner});
28 await helpers.methods.toggleSponsoring(matcher.options.address, true).send({from: matcherOwner});24 await helpers.methods.setSponsoringRateLimit(matcher.options.address, 1).send({from: matcherOwner});
29
30 await transferBalanceToEth(api, alice, subToEth(alice.address));25 await transferBalanceToEth(api, alice, matcher.options.address);
26
27 const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
28 const evmCollection = new web3.eth.Contract(nonFungibleAbi as any, collectionIdToAddress(collectionId), {from: matcherOwner});
31 await setCollectionSponsorExpectSuccess(collectionId, alice.address);29 await setCollectionSponsorExpectSuccess(collectionId, alice.address);
32 await confirmSponsorshipExpectSuccess(collectionId);30 await confirmSponsorshipExpectSuccess(collectionId);
3331
34 const seller = privateKey('//Seller/' + Date.now());32 await helpers.methods.toggleAllowed(matcher.options.address, subToEth(alice.address), true).send({from: matcherOwner});
35 await addToAllowListExpectSuccess(alice, collectionId, {Ethereum:subToEth(seller.address)});33 await addToAllowListExpectSuccess(alice, collectionId, evmToAddress(subToEth(alice.address)));
34
35 const seller = privateKey('//Bob');
36 await helpers.methods.toggleAllowed(matcher.options.address, subToEth(seller.address), true).send({from: matcherOwner});36 await helpers.methods.toggleAllowed(matcher.options.address, subToEth(seller.address), true).send({from: matcherOwner});
37 await addToAllowListExpectSuccess(alice, collectionId, evmToAddress(subToEth(seller.address)));
3738
38 const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT', seller.address);39 const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT', seller.address);
3940
40 // To transfer item to matcher it first needs to be transfered to EVM account of seller41 // To transfer item to matcher it first needs to be transfered to EVM account of bob
41 await transferExpectSuccess(collectionId, tokenId, seller, {Ethereum: subToEth(seller.address)});42 await transferExpectSuccess(collectionId, tokenId, seller, {Ethereum: subToEth(seller.address)});
43
44 // Token is owned by seller initially
42 expect(await getTokenOwner(api, collectionId, tokenId)).to.be.deep.equal({Ethereum: subToEthLowercase(seller.address)});45 expect(await getTokenOwner(api, collectionId, tokenId)).to.be.deep.equal({Ethereum: subToEthLowercase(seller.address)});
4346
44 // Ask47 // Ask
45 {48 {
46 await executeEthTxOnSub(web3, api, seller, evmCollection, m => m.approve(matcher.options.address, tokenId));49 await executeEthTxOnSub(web3, api, seller, evmCollection, m => m.approve(matcher.options.address, tokenId));
47 await executeEthTxOnSub(web3, api, seller, matcher, m => m.setAsk(PRICE, '0x0000000000000000000000000000000000000001', evmCollection.options.address, tokenId));50 await executeEthTxOnSub(web3, api, seller, matcher, m => m.addAsk(PRICE, '0x0000000000000000000000000000000000000001', evmCollection.options.address, tokenId));
48 }51 }
4952
50 // Token is transferred to matcher53 // Token is transferred to matcher
6972
70 // selling for custom tokens excluded from release73 // selling for custom tokens excluded from release
71 itWeb3.skip('With custom ERC20', async ({api, web3}) => {74 itWeb3.skip('With custom ERC20', async ({api, web3}) => {
75 const alice = privateKey('//Alice');
72 const matcherOwner = await createEthAccountWithBalance(api, web3);76 const matcherOwner = await createEthAccountWithBalance(api, web3);
73 const matcherContract = new web3.eth.Contract(JSON.parse((await readFile(`${__dirname}/MarketPlace.abi`)).toString()), undefined, {77 const matcherContract = new web3.eth.Contract(JSON.parse((await readFile(`${__dirname}/MarketPlace.abi`)).toString()), undefined, {
74 from: matcherOwner,78 from: matcherOwner,
75 ...GAS_ARGS,79 ...GAS_ARGS,
76 });80 });
77 const matcher = await matcherContract.deploy({data: (await readFile(`${__dirname}/MarketPlace.bin`)).toString(), arguments: [matcherOwner]}).send({from: matcherOwner});81 const matcher = await matcherContract.deploy({data: (await readFile(`${__dirname}/MarketPlace.bin`)).toString(), arguments: [matcherOwner]}).send({from: matcherOwner});
7882
79 const alice = privateKey('//Alice');
80 const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});83 const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
81 const evmCollection = new web3.eth.Contract(nonFungibleAbi as any, collectionIdToAddress(collectionId), {from: matcherOwner});84 const evmCollection = new web3.eth.Contract(nonFungibleAbi as any, collectionIdToAddress(collectionId), {from: matcherOwner});
8285
100 // Ask103 // Ask
101 {104 {
102 await executeEthTxOnSub(web3, api, seller, evmCollection, m => m.approve(matcher.options.address, tokenId));105 await executeEthTxOnSub(web3, api, seller, evmCollection, m => m.approve(matcher.options.address, tokenId));
103 await executeEthTxOnSub(web3, api, seller, matcher, m => m.setAsk(PRICE, evmFungible.options.address, evmCollection.options.address, tokenId, 1));106 await executeEthTxOnSub(web3, api, seller, matcher, m => m.addAsk(PRICE, evmFungible.options.address, evmCollection.options.address, tokenId, 1));
104 }107 }
105108
106 // Token is transferred to matcher109 // Token is transferred to matcher
134137
135 itWeb3('With escrow', async ({api, web3}) => {138 itWeb3('With escrow', async ({api, web3}) => {
136 const alice = privateKey('//Alice');139 const alice = privateKey('//Alice');
137 const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
138 const evmCollection = new web3.eth.Contract(nonFungibleAbi as any, collectionIdToAddress(collectionId));
139 const matcherOwner = await createEthAccountWithBalance(api, web3);140 const matcherOwner = await createEthAccountWithBalance(api, web3);
140 const helpers = contractHelpers(web3, matcherOwner);
141 const escrow = await createEthAccountWithBalance(api, web3);141 const escrow = await createEthAccountWithBalance(api, web3);
142
143 const matcherContract = new web3.eth.Contract(JSON.parse((await readFile(`${__dirname}/MarketPlace.abi`)).toString()), undefined, {142 const matcherContract = new web3.eth.Contract(JSON.parse((await readFile(`${__dirname}/MarketPlace.abi`)).toString()), undefined, {
144 from: matcherOwner,143 from: matcherOwner,
145 ...GAS_ARGS,144 ...GAS_ARGS,
146 });145 });
147 const matcher = await matcherContract.deploy({data: (await readFile(`${__dirname}/MarketPlace.bin`)).toString(), arguments: [matcherOwner]}).send({from: matcherOwner});146 const matcher = await matcherContract.deploy({data: (await readFile(`${__dirname}/MarketPlace.bin`)).toString(), arguments: [matcherOwner]}).send({from: matcherOwner, gas: 10000000});
148 await matcher.methods.setEscrow(escrow).send({from: matcherOwner});147 await matcher.methods.setEscrow(escrow).send({from: matcherOwner});
149148 const helpers = contractHelpers(web3, matcherOwner);
150 await transferBalanceToEth(api, alice, matcher.options.address);149 await helpers.methods.toggleSponsoring(matcher.options.address, true).send({from: matcherOwner});
151 await helpers.methods.toggleSponsoring(matcher.options.address, true).send({from: matcherOwner});150 await helpers.methods.setSponsoringRateLimit(matcher.options.address, 1).send({from: matcherOwner});
152
153 await transferBalanceToEth(api, alice, subToEth(alice.address));151 await transferBalanceToEth(api, alice, matcher.options.address);
152
153 const collectionId = await createCollectionExpectSuccess({mode: {type: 'NFT'}});
154 const evmCollection = new web3.eth.Contract(nonFungibleAbi as any, collectionIdToAddress(collectionId), {from: matcherOwner});
154 await setCollectionSponsorExpectSuccess(collectionId, alice.address);155 await setCollectionSponsorExpectSuccess(collectionId, alice.address);
155 await confirmSponsorshipExpectSuccess(collectionId);156 await confirmSponsorshipExpectSuccess(collectionId);
157
158 await helpers.methods.toggleAllowed(matcher.options.address, subToEth(alice.address), true).send({from: matcherOwner});
159 await addToAllowListExpectSuccess(alice, collectionId, evmToAddress(subToEth(alice.address)));
156160
157 const seller = privateKey('//Seller/' + Date.now());161 const seller = privateKey('//Bob');
158 await helpers.methods.toggleAllowed(matcher.options.address, subToEth(seller.address), true).send({from: matcherOwner});162 await helpers.methods.toggleAllowed(matcher.options.address, subToEth(seller.address), true).send({from: matcherOwner});
159 await addToAllowListExpectSuccess(alice, collectionId, evmToAddress(subToEth(seller.address)));163 await addToAllowListExpectSuccess(alice, collectionId, evmToAddress(subToEth(seller.address)));
160164
161 const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT', seller.address);165 const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT', seller.address);
162166
163 // To transfer item to matcher it first needs to be transfered to EVM account of seller167 // To transfer item to matcher it first needs to be transfered to EVM account of bob
164 await transferExpectSuccess(collectionId, tokenId, seller, {Ethereum: subToEth(seller.address)});168 await transferExpectSuccess(collectionId, tokenId, seller, {Ethereum: subToEth(seller.address)});
169
170 // Token is owned by seller initially
165 expect(await getTokenOwner(api, collectionId, tokenId)).to.be.deep.equal({Ethereum: subToEthLowercase(seller.address)});171 expect(await getTokenOwner(api, collectionId, tokenId)).to.be.deep.equal({Ethereum: subToEthLowercase(seller.address)});
166172
167 // Ask173 // Ask
168 {174 {
169 await executeEthTxOnSub(web3, api, seller, evmCollection, m => m.approve(matcher.options.address, tokenId));175 await executeEthTxOnSub(web3, api, seller, evmCollection, m => m.approve(matcher.options.address, tokenId));
170 await executeEthTxOnSub(web3, api, seller, matcher, m => m.setAsk(PRICE, '0x0000000000000000000000000000000000000001', evmCollection.options.address, tokenId));176 await executeEthTxOnSub(web3, api, seller, matcher, m => m.addAsk(PRICE, '0x0000000000000000000000000000000000000001', evmCollection.options.address, tokenId));
171 }177 }
172178
173 // Token is transferred to matcher179 // Token is transferred to matcher
modifiedtests/src/eth/payable.test.tsdiffbeforeafterboth
1import {expect} from 'chai';1import {expect} from 'chai';
2import privateKey from '../substrate/privateKey';2import privateKey from '../substrate/privateKey';
3import {submitTransactionAsync} from '../substrate/substrate-api';3import {submitTransactionAsync} from '../substrate/substrate-api';
4import {createEthAccountWithBalance, deployCollector, GAS_ARGS, itWeb3, subToEth} from './util/helpers';4import {createEthAccountWithBalance, deployCollector, GAS_ARGS, itWeb3, subToEth, transferBalanceToEth} from './util/helpers';
5import {evmToAddress} from '@polkadot/util-crypto';5import {evmToAddress} from '@polkadot/util-crypto';
6import {getGenericResult} from '../util/helpers';6import {getGenericResult} from '../util/helpers';
7import {getBalanceSingle, transferBalanceExpectSuccess} from '../substrate/get-balance';7import {getBalanceSingle, transferBalanceExpectSuccess} from '../substrate/get-balance';
2323
24 // Transaction fee/value will be payed from subToEth(sender) evm balance,24 // Transaction fee/value will be payed from subToEth(sender) evm balance,
25 // which is backed by evmToAddress(subToEth(sender)) substrate balance25 // which is backed by evmToAddress(subToEth(sender)) substrate balance
26 await transferBalanceExpectSuccess(api, alice, evmToAddress(subToEth(alice.address)), '1000000000000');26 await transferBalanceToEth(api, alice, subToEth(alice.address));
2727
28 {28 {
29 const tx = api.tx.evm.call(29 const tx = api.tx.evm.call(
modifiedtests/src/eth/util/helpers.tsdiffbeforeafterboth
19import contractHelpersAbi from './contractHelpersAbi.json';19import contractHelpersAbi from './contractHelpersAbi.json';
20import getBalance from '../../substrate/get-balance';20import getBalance from '../../substrate/get-balance';
2121
22export const GAS_ARGS = {gas: 1000000};22export const GAS_ARGS = {gas: 2500000};
2323
24let web3Connected = false;24let web3Connected = false;
25export async function usingWeb3<T>(cb: (web3: Web3) => Promise<T> | T): Promise<T> {25export async function usingWeb3<T>(cb: (web3: Web3) => Promise<T> | T): Promise<T> {
63 return account;63 return account;
64}64}
6565
66export async function transferBalanceToEth(api: ApiPromise, source: IKeyringPair, target: string, amount = 10000n * UNIQUE) {66export async function transferBalanceToEth(api: ApiPromise, source: IKeyringPair, target: string, amount = 1000n * UNIQUE) {
67 const tx = api.tx.balances.transfer(evmToAddress(target), amount);67 const tx = api.tx.balances.transfer(evmToAddress(target), amount);
68 const events = await submitTransactionAsync(source, tx);68 const events = await submitTransactionAsync(source, tx);
69 const result = getGenericResult(events);69 const result = getGenericResult(events);
228 return new web3.eth.Contract(contractHelpersAbi as any, '0x842899ECF380553E8a4de75bF534cdf6fBF64049', {from: caller, ...GAS_ARGS});228 return new web3.eth.Contract(contractHelpersAbi as any, '0x842899ECF380553E8a4de75bF534cdf6fBF64049', {from: caller, ...GAS_ARGS});
229}229}
230230
231/**231/**
232 * Execute ethereum method call using substrate account232 * Execute ethereum method call using substrate account
233 * @param to target contract233 * @param to target contract
234 * @param mkTx - closure, receiving `contract.methods`, and returning method call,234 * @param mkTx - closure, receiving `contract.methods`, and returning method call,
235 * to be used as following (assuming `to` = erc20 contract):235 * to be used as following (assuming `to` = erc20 contract):
236 * `m => m.transfer(to, amount)`236 * `m => m.transfer(to, amount)`
237 * 237 *
238 * # Example238 * # Example
239 * ```ts239 * ```ts
240 * executeEthTxOnSub(api, alice, erc20Contract, m => m.transfer(target, amount));240 * executeEthTxOnSub(api, alice, erc20Contract, m => m.transfer(target, amount));
241 * ```241 * ```
242 */242 */
243export async function executeEthTxOnSub(web3: Web3, api: ApiPromise, from: IKeyringPair, to: any, mkTx: (methods: any) => any, {value = 0}: {value?: bigint | number} = { }) {243export async function executeEthTxOnSub(web3: Web3, api: ApiPromise, from: IKeyringPair, to: any, mkTx: (methods: any) => any, {value = 0}: {value?: bigint | number} = { }) {
244 const tx = api.tx.evm.call(244 const tx = api.tx.evm.call(
245 subToEth(from.address),245 subToEth(from.address),
258 return (await getBalance(api, [evmToAddress(address)]))[0];258 return (await getBalance(api, [evmToAddress(address)]))[0];
259}259}
260260
261/**261/**
262 * Measure how much gas given closure consumes262 * Measure how much gas given closure consumes
263 * 263 *
264 * @param user which user balance will be checked264 * @param user which user balance will be checked
265 */265 */
266export async function recordEthFee(api: ApiPromise, user: string, call: () => Promise<any>): Promise<bigint> {266export async function recordEthFee(api: ApiPromise, user: string, call: () => Promise<any>): Promise<bigint> {
267 const before = await ethBalanceViaSub(api, user);267 const before = await ethBalanceViaSub(api, user);
268268