difftreelog
feat configure min gas price
in: master
9 files changed
runtime/src/lib.rsdiffbeforeafterboth--- a/runtime/src/lib.rs
+++ b/runtime/src/lib.rs
@@ -243,7 +243,8 @@
pub struct FixedFee;
impl FeeCalculator for FixedFee {
fn min_gas_price() -> U256 {
- 1.into()
+ // Targeting 0.15 UNQ per transfer
+ (1 * MICROUNIQUE).into()
}
}
tests/src/creditFeesToTreasury.test.tsdiffbeforeafterboth1//2// This file is subject to the terms and conditions defined in3// file 'LICENSE', which is part of this source code package.4//56import chai from 'chai';7import chaiAsPromised from 'chai-as-promised';8import {default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';9import {alicesPublicKey, bobsPublicKey} from './accounts';10import privateKey from './substrate/privateKey';11import {IKeyringPair} from '@polkadot/types/types';12import {13 createCollectionExpectSuccess,14 createItemExpectSuccess,15 getGenericResult,16 transferExpectSuccess,17} from './util/helpers';1819import {default as waitNewBlocks} from './substrate/wait-new-blocks';20import {ApiPromise} from '@polkadot/api';2122chai.use(chaiAsPromised);23const expect = chai.expect;2425const TREASURY = '5EYCAe5ijiYfyeZ2JJCGq56LmPyNRAKzpG4QkoQkkQNB5e6Z';26const saneMinimumFee = 0.05;27const saneMaximumFee = 0.5;28const createCollectionDeposit = 100;2930let alice: IKeyringPair;31let bob: IKeyringPair;3233// Skip the inflation block pauses if the block is close to inflation block34// until the inflation happens35/*eslint no-async-promise-executor: "off"*/36function skipInflationBlock(api: ApiPromise): Promise<void> {37 const promise = new Promise<void>(async (resolve) => {38 const blockInterval = (await api.consts.inflation.inflationBlockInterval).toNumber();39 const unsubscribe = await api.rpc.chain.subscribeNewHeads(head => {40 const currentBlock = head.number.toNumber();41 if (currentBlock % blockInterval < blockInterval - 10) {42 unsubscribe();43 resolve();44 } else {45 console.log(`Skipping inflation block, current block: ${currentBlock}`);46 }47 });48 });4950 return promise;51}5253describe('integration test: Fees must be credited to Treasury:', () => {54 before(async () => {55 await usingApi(async () => {56 alice = privateKey('//Alice');57 bob = privateKey('//Bob');58 });59 });6061 it('Total issuance does not change', async () => {62 await usingApi(async (api) => {63 await skipInflationBlock(api);64 await waitNewBlocks(api, 1);6566 const totalBefore = (await api.query.balances.totalIssuance()).toBigInt();6768 const alicePrivateKey = privateKey('//Alice');69 const amount = 1n;70 const transfer = api.tx.balances.transfer(bobsPublicKey, amount);7172 const result = getGenericResult(await submitTransactionAsync(alicePrivateKey, transfer));7374 const totalAfter = (await api.query.balances.totalIssuance()).toBigInt();7576 expect(result.success).to.be.true;77 expect(totalAfter).to.be.equal(totalBefore);78 });79 });8081 it('Sender balance decreased by fee+sent amount, Treasury balance increased by fee', async () => {82 await usingApi(async (api) => {83 await skipInflationBlock(api);84 await waitNewBlocks(api, 1);8586 const alicePrivateKey = privateKey('//Alice');87 const treasuryBalanceBefore: bigint = (await api.query.system.account(TREASURY)).data.free.toBigInt();88 const aliceBalanceBefore: bigint = (await api.query.system.account(alicesPublicKey)).data.free.toBigInt();8990 const amount = 1n;91 const transfer = api.tx.balances.transfer(bobsPublicKey, amount);92 const result = getGenericResult(await submitTransactionAsync(alicePrivateKey, transfer));9394 const treasuryBalanceAfter: bigint = (await api.query.system.account(TREASURY)).data.free.toBigInt();95 const aliceBalanceAfter: bigint = (await api.query.system.account(alicesPublicKey)).data.free.toBigInt();96 const fee = aliceBalanceBefore - aliceBalanceAfter - amount;97 const treasuryIncrease = treasuryBalanceAfter - treasuryBalanceBefore;9899 expect(result.success).to.be.true;100 expect(treasuryIncrease).to.be.equal(fee);101 });102 });103104 it('Treasury balance increased by failed tx fee', async () => {105 await usingApi(async (api) => {106 await skipInflationBlock(api);107 await waitNewBlocks(api, 1);108109 const bobPrivateKey = privateKey('//Bob');110 const treasuryBalanceBefore = (await api.query.system.account(TREASURY)).data.free.toBigInt();111 const bobBalanceBefore = (await api.query.system.account(bobsPublicKey)).data.free.toBigInt();112113 const badTx = api.tx.balances.setBalance(alicesPublicKey, 0, 0);114 await expect(submitTransactionExpectFailAsync(bobPrivateKey, badTx)).to.be.rejected;115116 const treasuryBalanceAfter = (await api.query.system.account(TREASURY)).data.free.toBigInt();117 const bobBalanceAfter = (await api.query.system.account(bobsPublicKey)).data.free.toBigInt();118 const fee = bobBalanceBefore - bobBalanceAfter;119 const treasuryIncrease = treasuryBalanceAfter - treasuryBalanceBefore;120121 expect(treasuryIncrease).to.be.equal(fee);122 });123 });124125 it('NFT Transactions also send fees to Treasury', async () => {126 await usingApi(async (api) => {127 await skipInflationBlock(api);128 await waitNewBlocks(api, 1);129130 const treasuryBalanceBefore = (await api.query.system.account(TREASURY)).data.free.toBigInt();131 const aliceBalanceBefore = (await api.query.system.account(alicesPublicKey)).data.free.toBigInt();132133 await createCollectionExpectSuccess();134135 const treasuryBalanceAfter = (await api.query.system.account(TREASURY)).data.free.toBigInt();136 const aliceBalanceAfter = (await api.query.system.account(alicesPublicKey)).data.free.toBigInt();137 const fee = aliceBalanceBefore - aliceBalanceAfter;138 const treasuryIncrease = treasuryBalanceAfter - treasuryBalanceBefore;139140 expect(treasuryIncrease).to.be.equal(fee);141 });142 });143144 it('Fees are sane', async () => {145 await usingApi(async (api) => {146 await skipInflationBlock(api);147 await waitNewBlocks(api, 1);148149 const aliceBalanceBefore: bigint = (await api.query.system.account(alicesPublicKey)).data.free.toBigInt();150151 await createCollectionExpectSuccess();152153 const aliceBalanceAfter: bigint = (await api.query.system.account(alicesPublicKey)).data.free.toBigInt();154 const fee = aliceBalanceBefore - aliceBalanceAfter;155156 expect(fee / 10n ** 15n < BigInt(Math.ceil(saneMaximumFee + createCollectionDeposit))).to.be.true;157 expect(fee / 10n ** 15n < BigInt(Math.ceil(saneMinimumFee + createCollectionDeposit))).to.be.true;158 });159 });160161 it('NFT Transfer fee is close to 0.1 Unique', async () => {162 await usingApi(async (api) => {163 await skipInflationBlock(api);164 await waitNewBlocks(api, 1);165166 const collectionId = await createCollectionExpectSuccess();167 const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT');168169 const aliceBalanceBefore: bigint = (await api.query.system.account(alicesPublicKey)).data.free.toBigInt();170 await transferExpectSuccess(collectionId, tokenId, alice, bob, 1, 'NFT');171 const aliceBalanceAfter: bigint = (await api.query.system.account(alicesPublicKey)).data.free.toBigInt();172 const fee = aliceBalanceBefore - aliceBalanceAfter;173174 // console.log(fee.toString());175 const expectedTransferFee = 0.1;176 const tolerance = 0.001;177 expect(Number(fee) / 1e15 - expectedTransferFee).to.be.lessThan(tolerance);178 });179 });180181});1//2// This file is subject to the terms and conditions defined in3// file 'LICENSE', which is part of this source code package.4//56import chai from 'chai';7import chaiAsPromised from 'chai-as-promised';8import {default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync} from './substrate/substrate-api';9import {alicesPublicKey, bobsPublicKey} from './accounts';10import privateKey from './substrate/privateKey';11import {IKeyringPair} from '@polkadot/types/types';12import {13 createCollectionExpectSuccess,14 createItemExpectSuccess,15 getGenericResult,16 transferExpectSuccess,17 UNIQUE,18} from './util/helpers';1920import {default as waitNewBlocks} from './substrate/wait-new-blocks';21import {ApiPromise} from '@polkadot/api';2223chai.use(chaiAsPromised);24const expect = chai.expect;2526const TREASURY = '5EYCAe5ijiYfyeZ2JJCGq56LmPyNRAKzpG4QkoQkkQNB5e6Z';27const saneMinimumFee = 0.05;28const saneMaximumFee = 0.5;29const createCollectionDeposit = 100;3031let alice: IKeyringPair;32let bob: IKeyringPair;3334// Skip the inflation block pauses if the block is close to inflation block35// until the inflation happens36/*eslint no-async-promise-executor: "off"*/37function skipInflationBlock(api: ApiPromise): Promise<void> {38 const promise = new Promise<void>(async (resolve) => {39 const blockInterval = (await api.consts.inflation.inflationBlockInterval).toNumber();40 const unsubscribe = await api.rpc.chain.subscribeNewHeads(head => {41 const currentBlock = head.number.toNumber();42 if (currentBlock % blockInterval < blockInterval - 10) {43 unsubscribe();44 resolve();45 } else {46 console.log(`Skipping inflation block, current block: ${currentBlock}`);47 }48 });49 });5051 return promise;52}5354describe('integration test: Fees must be credited to Treasury:', () => {55 before(async () => {56 await usingApi(async () => {57 alice = privateKey('//Alice');58 bob = privateKey('//Bob');59 });60 });6162 it('Total issuance does not change', async () => {63 await usingApi(async (api) => {64 await skipInflationBlock(api);65 await waitNewBlocks(api, 1);6667 const totalBefore = (await api.query.balances.totalIssuance()).toBigInt();6869 const alicePrivateKey = privateKey('//Alice');70 const amount = 1n;71 const transfer = api.tx.balances.transfer(bobsPublicKey, amount);7273 const result = getGenericResult(await submitTransactionAsync(alicePrivateKey, transfer));7475 const totalAfter = (await api.query.balances.totalIssuance()).toBigInt();7677 expect(result.success).to.be.true;78 expect(totalAfter).to.be.equal(totalBefore);79 });80 });8182 it('Sender balance decreased by fee+sent amount, Treasury balance increased by fee', async () => {83 await usingApi(async (api) => {84 await skipInflationBlock(api);85 await waitNewBlocks(api, 1);8687 const alicePrivateKey = privateKey('//Alice');88 const treasuryBalanceBefore: bigint = (await api.query.system.account(TREASURY)).data.free.toBigInt();89 const aliceBalanceBefore: bigint = (await api.query.system.account(alicesPublicKey)).data.free.toBigInt();9091 const amount = 1n;92 const transfer = api.tx.balances.transfer(bobsPublicKey, amount);93 const result = getGenericResult(await submitTransactionAsync(alicePrivateKey, transfer));9495 const treasuryBalanceAfter: bigint = (await api.query.system.account(TREASURY)).data.free.toBigInt();96 const aliceBalanceAfter: bigint = (await api.query.system.account(alicesPublicKey)).data.free.toBigInt();97 const fee = aliceBalanceBefore - aliceBalanceAfter - amount;98 const treasuryIncrease = treasuryBalanceAfter - treasuryBalanceBefore;99100 expect(result.success).to.be.true;101 expect(treasuryIncrease).to.be.equal(fee);102 });103 });104105 it('Treasury balance increased by failed tx fee', async () => {106 await usingApi(async (api) => {107 await skipInflationBlock(api);108 await waitNewBlocks(api, 1);109110 const bobPrivateKey = privateKey('//Bob');111 const treasuryBalanceBefore = (await api.query.system.account(TREASURY)).data.free.toBigInt();112 const bobBalanceBefore = (await api.query.system.account(bobsPublicKey)).data.free.toBigInt();113114 const badTx = api.tx.balances.setBalance(alicesPublicKey, 0, 0);115 await expect(submitTransactionExpectFailAsync(bobPrivateKey, badTx)).to.be.rejected;116117 const treasuryBalanceAfter = (await api.query.system.account(TREASURY)).data.free.toBigInt();118 const bobBalanceAfter = (await api.query.system.account(bobsPublicKey)).data.free.toBigInt();119 const fee = bobBalanceBefore - bobBalanceAfter;120 const treasuryIncrease = treasuryBalanceAfter - treasuryBalanceBefore;121122 expect(treasuryIncrease).to.be.equal(fee);123 });124 });125126 it('NFT Transactions also send fees to Treasury', async () => {127 await usingApi(async (api) => {128 await skipInflationBlock(api);129 await waitNewBlocks(api, 1);130131 const treasuryBalanceBefore = (await api.query.system.account(TREASURY)).data.free.toBigInt();132 const aliceBalanceBefore = (await api.query.system.account(alicesPublicKey)).data.free.toBigInt();133134 await createCollectionExpectSuccess();135136 const treasuryBalanceAfter = (await api.query.system.account(TREASURY)).data.free.toBigInt();137 const aliceBalanceAfter = (await api.query.system.account(alicesPublicKey)).data.free.toBigInt();138 const fee = aliceBalanceBefore - aliceBalanceAfter;139 const treasuryIncrease = treasuryBalanceAfter - treasuryBalanceBefore;140141 expect(treasuryIncrease).to.be.equal(fee);142 });143 });144145 it('Fees are sane', async () => {146 await usingApi(async (api) => {147 await skipInflationBlock(api);148 await waitNewBlocks(api, 1);149150 const aliceBalanceBefore: bigint = (await api.query.system.account(alicesPublicKey)).data.free.toBigInt();151152 await createCollectionExpectSuccess();153154 const aliceBalanceAfter: bigint = (await api.query.system.account(alicesPublicKey)).data.free.toBigInt();155 const fee = aliceBalanceBefore - aliceBalanceAfter;156157 expect(fee / 10n ** 15n < BigInt(Math.ceil(saneMaximumFee + createCollectionDeposit))).to.be.true;158 expect(fee / 10n ** 15n < BigInt(Math.ceil(saneMinimumFee + createCollectionDeposit))).to.be.true;159 });160 });161162 it('NFT Transfer fee is close to 0.1 Unique', async () => {163 await usingApi(async (api) => {164 await skipInflationBlock(api);165 await waitNewBlocks(api, 1);166167 const collectionId = await createCollectionExpectSuccess();168 const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT');169170 const aliceBalanceBefore: bigint = (await api.query.system.account(alicesPublicKey)).data.free.toBigInt();171 await transferExpectSuccess(collectionId, tokenId, alice, bob, 1, 'NFT');172 const aliceBalanceAfter: bigint = (await api.query.system.account(alicesPublicKey)).data.free.toBigInt();173 const fee = Number(aliceBalanceBefore - aliceBalanceAfter) / Number(UNIQUE);174175 const expectedTransferFee = 0.1;176 const tolerance = 0.001;177 expect(Number(fee) / Number(UNIQUE) - expectedTransferFee).to.be.lessThan(tolerance);178 });179 });180181});tests/src/eth/base.test.tsdiffbeforeafterboth--- a/tests/src/eth/base.test.ts
+++ b/tests/src/eth/base.test.ts
@@ -1,7 +1,9 @@
-import {createEthAccount, createEthAccountWithBalance, deployFlipper, ethBalanceViaSub, GAS_ARGS, itWeb3, recordEthFee} from './util/helpers';
+import {collectionIdToAddress, createEthAccount, createEthAccountWithBalance, deployFlipper, ethBalanceViaSub, GAS_ARGS, itWeb3, recordEthFee} from './util/helpers';
import {expect} from 'chai';
-import {UNIQUE} from '../util/helpers';
+import {createCollectionExpectSuccess, createItemExpectSuccess, UNIQUE} from '../util/helpers';
+import nonFungibleAbi from './nonFungibleAbi.json';
+import privateKey from '../substrate/privateKey';
describe('Contract calls', () => {
itWeb3('Call of simple contract fee is less than 0.2 UNQ', async ({web3, api}) => {
@@ -19,4 +21,26 @@
const cost = await recordEthFee(api, userA, () => web3.eth.sendTransaction({from: userA, to: userB, value: '1000000', ...GAS_ARGS}));
expect(cost - await ethBalanceViaSub(api, userB) < BigInt(0.2 * Number(UNIQUE))).to.be.true;
});
+
+ itWeb3('NFT transfer is close to 0.15 UNQ', async ({web3, api}) => {
+ const caller = await createEthAccountWithBalance(api, web3);
+ const receiver = createEthAccount(web3);
+
+ const alice = privateKey('//Alice');
+ const collection = await createCollectionExpectSuccess({
+ mode: {type: 'NFT'},
+ });
+ const itemId = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: caller});
+
+ const address = collectionIdToAddress(collection);
+ const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});
+
+ const cost = await recordEthFee(api, caller, () => contract.methods.transfer(receiver, itemId).send(caller));
+
+ const fee = Number(cost) / Number(UNIQUE);
+ const expectedFee = 0.15;
+ const tolerance = 0.002;
+
+ expect(Math.abs(fee - expectedFee) < tolerance).to.be.true;
+ });
});
tests/src/eth/fungible.test.tsdiffbeforeafterboth--- a/tests/src/eth/fungible.test.ts
+++ b/tests/src/eth/fungible.test.ts
@@ -95,12 +95,12 @@
const alice = privateKey('//Alice');
const owner = createEthAccount(web3);
- await transferBalanceToEth(api, alice, owner, 999999999999999);
+ await transferBalanceToEth(api, alice, owner);
await createFungibleItemExpectSuccess(alice, collection, {Value: 200n}, {Ethereum: owner});
const spender = createEthAccount(web3);
- await transferBalanceToEth(api, alice, spender, 999999999999999);
+ await transferBalanceToEth(api, alice, spender);
const receiver = createEthAccount(web3);
@@ -153,12 +153,12 @@
const alice = privateKey('//Alice');
const owner = createEthAccount(web3);
- await transferBalanceToEth(api, alice, owner, 999999999999999);
+ await transferBalanceToEth(api, alice, owner);
await createFungibleItemExpectSuccess(alice, collection, {Value: 200n}, {Ethereum: owner});
const receiver = createEthAccount(web3);
- await transferBalanceToEth(api, alice, receiver, 999999999999999);
+ await transferBalanceToEth(api, alice, receiver);
const address = collectionIdToAddress(collection);
const contract = new web3.eth.Contract(fungibleAbi as any, address, {from: owner, ...GAS_ARGS});
tests/src/eth/marketplace/marketplace.test.tsdiffbeforeafterboth--- a/tests/src/eth/marketplace/marketplace.test.ts
+++ b/tests/src/eth/marketplace/marketplace.test.ts
@@ -38,8 +38,8 @@
// Ask
{
- await executeEthTxOnSub(api, seller, evmCollection, m => m.approve(matcher.options.address, tokenId));
- await executeEthTxOnSub(api, seller, matcher, m => m.setAsk(PRICE, '0x0000000000000000000000000000000000000000', evmCollection.options.address, tokenId, 1));
+ await executeEthTxOnSub(web3, api, seller, evmCollection, m => m.approve(matcher.options.address, tokenId));
+ await executeEthTxOnSub(web3, api, seller, matcher, m => m.setAsk(PRICE, '0x0000000000000000000000000000000000000000', evmCollection.options.address, tokenId, 1));
}
// Token is transferred to matcher
@@ -49,7 +49,7 @@
{
const sellerBalanceBeforePurchase = await getBalanceSingle(api, seller.address);
// There is two functions named 'buy', so we should provide full signature
- await executeEthTxOnSub(api, alice, matcher, m => m['buy(address,uint256)'](evmCollection.options.address, tokenId), {value: PRICE});
+ await executeEthTxOnSub(web3, api, alice, matcher, m => m['buy(address,uint256)'](evmCollection.options.address, tokenId), {value: PRICE});
expect(await getBalanceSingle(api, seller.address) - sellerBalanceBeforePurchase === PRICE);
}
@@ -95,8 +95,8 @@
// Ask
{
- await executeEthTxOnSub(api, seller, evmCollection, m => m.approve(matcher.options.address, tokenId));
- await executeEthTxOnSub(api, seller, matcher, m => m.setAsk(PRICE, evmFungible.options.address, evmCollection.options.address, tokenId, 1));
+ await executeEthTxOnSub(web3, api, seller, evmCollection, m => m.approve(matcher.options.address, tokenId));
+ await executeEthTxOnSub(web3, api, seller, matcher, m => m.setAsk(PRICE, evmFungible.options.address, evmCollection.options.address, tokenId, 1));
}
// Token is transferred to matcher
@@ -107,9 +107,9 @@
const sellerBalanceBeforePurchase = BigInt(await evmFungible.methods.balanceOf(subToEth(seller.address)).call());
const buyerBalanceBeforePurchase = BigInt(await evmFungible.methods.balanceOf(subToEth(alice.address)).call());
- await executeEthTxOnSub(api, alice, evmFungible, m => m.approve(matcher.options.address, PRICE));
+ await executeEthTxOnSub(web3, api, alice, evmFungible, m => m.approve(matcher.options.address, PRICE));
// There is two functions named 'buy', so we should provide full signature
- await executeEthTxOnSub(api, alice, matcher, m =>
+ await executeEthTxOnSub(web3, api, alice, matcher, m =>
m['buy(address,uint256,address,uint256)'](evmCollection.options.address, tokenId, evmFungible.options.address, PRICE));
// Approved price is removed from buyer balance, and added to seller
@@ -158,8 +158,8 @@
// Ask
{
- await executeEthTxOnSub(api, seller, evmCollection, m => m.approve(matcher.options.address, tokenId));
- await executeEthTxOnSub(api, seller, matcher, m => m.setAsk(PRICE, ksmToken, evmCollection.options.address, tokenId, 1));
+ await executeEthTxOnSub(web3, api, seller, evmCollection, m => m.approve(matcher.options.address, tokenId));
+ await executeEthTxOnSub(web3, api, seller, matcher, m => m.setAsk(PRICE, ksmToken, evmCollection.options.address, tokenId, 1));
}
// Token is transferred to matcher
@@ -173,7 +173,7 @@
expect(await matcher.methods.escrowBalance(ksmToken, subToEth(seller.address)).call()).to.be.equal('0');
expect(await matcher.methods.escrowBalance(ksmToken, subToEth(alice.address)).call()).to.be.equal(PRICE.toString());
- await executeEthTxOnSub(api, alice, matcher, m => m.buy(evmCollection.options.address, tokenId));
+ await executeEthTxOnSub(web3, api, alice, matcher, m => m.buy(evmCollection.options.address, tokenId));
// Price is removed from buyer balance, and added to seller
expect(await matcher.methods.escrowBalance(ksmToken, subToEth(alice.address)).call()).to.be.equal('0');
tests/src/eth/nonFungible.test.tsdiffbeforeafterboth--- a/tests/src/eth/nonFungible.test.ts
+++ b/tests/src/eth/nonFungible.test.ts
@@ -203,7 +203,7 @@
const alice = privateKey('//Alice');
const owner = createEthAccount(web3);
- await transferBalanceToEth(api, alice, owner, 999999999999999);
+ await transferBalanceToEth(api, alice, owner);
const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: owner});
@@ -213,7 +213,7 @@
const contract = new web3.eth.Contract(nonFungibleAbi as any, address);
{
- const result = await contract.methods.approve(spender, tokenId).send({from: owner, gas: '0x1000000', gasPrice: '0x01'});
+ const result = await contract.methods.approve(spender, tokenId).send({from: owner, ...GAS_ARGS});
const events = normalizeEvents(result.events);
expect(events).to.be.deep.equal([
@@ -237,12 +237,12 @@
const alice = privateKey('//Alice');
const owner = createEthAccount(web3);
- await transferBalanceToEth(api, alice, owner, 999999999999999);
+ await transferBalanceToEth(api, alice, owner);
const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: owner});
const spender = createEthAccount(web3);
- await transferBalanceToEth(api, alice, spender, 999999999999999);
+ await transferBalanceToEth(api, alice, spender);
const receiver = createEthAccount(web3);
@@ -285,12 +285,12 @@
const alice = privateKey('//Alice');
const owner = createEthAccount(web3);
- await transferBalanceToEth(api, alice, owner, 999999999999999);
+ await transferBalanceToEth(api, alice, owner);
const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: owner});
const receiver = createEthAccount(web3);
- await transferBalanceToEth(api, alice, receiver, 999999999999999);
+ await transferBalanceToEth(api, alice, receiver);
const address = collectionIdToAddress(collection);
const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: owner, ...GAS_ARGS});
tests/src/eth/payable.test.tsdiffbeforeafterboth--- a/tests/src/eth/payable.test.ts
+++ b/tests/src/eth/payable.test.ts
@@ -32,7 +32,7 @@
contract.methods.giveMoney().encodeABI(),
'10000',
GAS_ARGS.gas,
- GAS_ARGS.gasPrice,
+ await web3.eth.getGasPrice(),
null,
);
const events = await submitTransactionAsync(alice, tx);
tests/src/eth/proxy/nonFungibleProxy.test.tsdiffbeforeafterboth--- a/tests/src/eth/proxy/nonFungibleProxy.test.ts
+++ b/tests/src/eth/proxy/nonFungibleProxy.test.ts
@@ -224,7 +224,7 @@
const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: contract.options.address});
{
- const result = await contract.methods.approve(spender, tokenId).send({from: caller, gas: '0x1000000', gasPrice: '0x01'});
+ const result = await contract.methods.approve(spender, tokenId).send({from: caller, ...GAS_ARGS});
const events = normalizeEvents(result.events);
expect(events).to.be.deep.equal([
tests/src/eth/util/helpers.tsdiffbeforeafterboth--- a/tests/src/eth/util/helpers.ts
+++ b/tests/src/eth/util/helpers.ts
@@ -12,14 +12,14 @@
import usingApi, {submitTransactionAsync} from '../../substrate/substrate-api';
import {IKeyringPair} from '@polkadot/types/types';
import {expect} from 'chai';
-import {getGenericResult} from '../../util/helpers';
+import {getGenericResult, UNIQUE} from '../../util/helpers';
import * as solc from 'solc';
import config from '../../config';
import privateKey from '../../substrate/privateKey';
import contractHelpersAbi from './contractHelpersAbi.json';
import getBalance from '../../substrate/get-balance';
-export const GAS_ARGS = {gas: 0x1000000, gasPrice: '0x01'};
+export const GAS_ARGS = {gas: 1000000};
let web3Connected = false;
export async function usingWeb3<T>(cb: (web3: Web3) => Promise<T> | T): Promise<T> {
@@ -63,7 +63,7 @@
return account;
}
-export async function transferBalanceToEth(api: ApiPromise, source: IKeyringPair, target: string, amount = 999999999999999) {
+export async function transferBalanceToEth(api: ApiPromise, source: IKeyringPair, target: string, amount = 10000n * UNIQUE) {
const tx = api.tx.balances.transfer(evmToAddress(target), amount);
const events = await submitTransactionAsync(source, tx);
const result = getGenericResult(events);
@@ -228,14 +228,14 @@
return new web3.eth.Contract(contractHelpersAbi as any, '0x842899ECF380553E8a4de75bF534cdf6fBF64049', {from: caller, ...GAS_ARGS});
}
-export async function executeEthTxOnSub(api: ApiPromise, from: IKeyringPair, to: any, mkTx: (methods: any) => any, {value = 0}: {value?: bigint | number} = { }) {
+export async function executeEthTxOnSub(web3: Web3, api: ApiPromise, from: IKeyringPair, to: any, mkTx: (methods: any) => any, {value = 0}: {value?: bigint | number} = { }) {
const tx = api.tx.evm.call(
subToEth(from.address),
to.options.address,
mkTx(to.methods).encodeABI(),
value,
GAS_ARGS.gas,
- GAS_ARGS.gasPrice,
+ await web3.eth.getGasPrice(),
null,
);
const events = await submitTransactionAsync(from, tx);