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.tsdiffbeforeafterboth--- a/tests/src/creditFeesToTreasury.test.ts
+++ b/tests/src/creditFeesToTreasury.test.ts
@@ -14,6 +14,7 @@
createItemExpectSuccess,
getGenericResult,
transferExpectSuccess,
+ UNIQUE,
} from './util/helpers';
import {default as waitNewBlocks} from './substrate/wait-new-blocks';
@@ -169,12 +170,11 @@
const aliceBalanceBefore: bigint = (await api.query.system.account(alicesPublicKey)).data.free.toBigInt();
await transferExpectSuccess(collectionId, tokenId, alice, bob, 1, 'NFT');
const aliceBalanceAfter: bigint = (await api.query.system.account(alicesPublicKey)).data.free.toBigInt();
- const fee = aliceBalanceBefore - aliceBalanceAfter;
+ const fee = Number(aliceBalanceBefore - aliceBalanceAfter) / Number(UNIQUE);
- // console.log(fee.toString());
const expectedTransferFee = 0.1;
const tolerance = 0.001;
- expect(Number(fee) / 1e15 - expectedTransferFee).to.be.lessThan(tolerance);
+ expect(Number(fee) / Number(UNIQUE) - expectedTransferFee).to.be.lessThan(tolerance);
});
});
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.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 privateKey from '../substrate/privateKey';7import {approveExpectSuccess, createCollectionExpectSuccess, createFungibleItemExpectSuccess, transferExpectSuccess, transferFromExpectSuccess, UNIQUE} from '../util/helpers';8import {collectionIdToAddress, createEthAccount, createEthAccountWithBalance, GAS_ARGS, itWeb3, normalizeEvents, recordEthFee, recordEvents, subToEth, transferBalanceToEth} from './util/helpers';9import fungibleAbi from './fungibleAbi.json';10import {expect} from 'chai';1112describe('Fungible: Information getting', () => {13 itWeb3('totalSupply', async ({api, web3}) => {14 const collection = await createCollectionExpectSuccess({15 name: 'token name',16 mode: {type: 'Fungible', decimalPoints: 0},17 });18 const alice = privateKey('//Alice');1920 const caller = await createEthAccountWithBalance(api, web3);2122 await createFungibleItemExpectSuccess(alice, collection, {Value: 200n}, {Substrate: alice.address});2324 const address = collectionIdToAddress(collection);25 const contract = new web3.eth.Contract(fungibleAbi as any, address, {from: caller, ...GAS_ARGS});26 const totalSupply = await contract.methods.totalSupply().call();2728 expect(totalSupply).to.equal('200');29 });3031 itWeb3('balanceOf', async ({api, web3}) => {32 const collection = await createCollectionExpectSuccess({33 name: 'token name',34 mode: {type: 'Fungible', decimalPoints: 0},35 });36 const alice = privateKey('//Alice');3738 const caller = await createEthAccountWithBalance(api, web3);3940 await createFungibleItemExpectSuccess(alice, collection, {Value: 200n}, {Ethereum: caller});4142 const address = collectionIdToAddress(collection);43 const contract = new web3.eth.Contract(fungibleAbi as any, address, {from: caller, ...GAS_ARGS});44 const balance = await contract.methods.balanceOf(caller).call();4546 expect(balance).to.equal('200');47 });48});4950describe('Fungible: Plain calls', () => {51 itWeb3('Can perform approve()', async ({web3, api}) => {52 const collection = await createCollectionExpectSuccess({53 name: 'token name',54 mode: {type: 'Fungible', decimalPoints: 0},55 });56 const alice = privateKey('//Alice');5758 const owner = await createEthAccountWithBalance(api, web3);5960 await createFungibleItemExpectSuccess(alice, collection, {Value: 200n}, {Ethereum: owner});6162 const spender = createEthAccount(web3);6364 const address = collectionIdToAddress(collection);65 const contract = new web3.eth.Contract(fungibleAbi as any, address, {from: owner, ...GAS_ARGS});6667 {68 const result = await contract.methods.approve(spender, 100).send({from: owner});69 const events = normalizeEvents(result.events);7071 expect(events).to.be.deep.equal([72 {73 address,74 event: 'Approval',75 args: {76 owner,77 spender,78 value: '100',79 },80 },81 ]);82 }8384 {85 const allowance = await contract.methods.allowance(owner, spender).call();86 expect(+allowance).to.equal(100);87 }88 });8990 itWeb3('Can perform transferFrom()', async ({web3, api}) => {91 const collection = await createCollectionExpectSuccess({92 name: 'token name',93 mode: {type: 'Fungible', decimalPoints: 0},94 });95 const alice = privateKey('//Alice');9697 const owner = createEthAccount(web3);98 await transferBalanceToEth(api, alice, owner, 999999999999999);99100 await createFungibleItemExpectSuccess(alice, collection, {Value: 200n}, {Ethereum: owner});101102 const spender = createEthAccount(web3);103 await transferBalanceToEth(api, alice, spender, 999999999999999);104105 const receiver = createEthAccount(web3);106107 const address = collectionIdToAddress(collection);108 const contract = new web3.eth.Contract(fungibleAbi as any, address, {from: owner, ...GAS_ARGS});109110 await contract.methods.approve(spender, 100).send();111112 {113 const result = await contract.methods.transferFrom(owner, receiver, 49).send({from: spender});114 const events = normalizeEvents(result.events);115 expect(events).to.be.deep.equal([116 {117 address,118 event: 'Transfer',119 args: {120 from: owner,121 to: receiver,122 value: '49',123 },124 },125 {126 address,127 event: 'Approval',128 args: {129 owner,130 spender,131 value: '51',132 },133 },134 ]);135 }136137 {138 const balance = await contract.methods.balanceOf(receiver).call();139 expect(+balance).to.equal(49);140 }141142 {143 const balance = await contract.methods.balanceOf(owner).call();144 expect(+balance).to.equal(151);145 }146 });147148 itWeb3('Can perform transfer()', async ({web3, api}) => {149 const collection = await createCollectionExpectSuccess({150 name: 'token name',151 mode: {type: 'Fungible', decimalPoints: 0},152 });153 const alice = privateKey('//Alice');154155 const owner = createEthAccount(web3);156 await transferBalanceToEth(api, alice, owner, 999999999999999);157158 await createFungibleItemExpectSuccess(alice, collection, {Value: 200n}, {Ethereum: owner});159160 const receiver = createEthAccount(web3);161 await transferBalanceToEth(api, alice, receiver, 999999999999999);162163 const address = collectionIdToAddress(collection);164 const contract = new web3.eth.Contract(fungibleAbi as any, address, {from: owner, ...GAS_ARGS});165166 {167 const result = await contract.methods.transfer(receiver, 50).send({from: owner});168 const events = normalizeEvents(result.events);169 expect(events).to.be.deep.equal([170 {171 address,172 event: 'Transfer',173 args: {174 from: owner,175 to: receiver,176 value: '50',177 },178 },179 ]);180 }181182 {183 const balance = await contract.methods.balanceOf(owner).call();184 expect(+balance).to.equal(150);185 }186187 {188 const balance = await contract.methods.balanceOf(receiver).call();189 expect(+balance).to.equal(50);190 }191 });192});193194describe('Fungible: Fees', () => {195 itWeb3('approve() call fee is less than 0.2UNQ', async ({web3, api}) => {196 const collection = await createCollectionExpectSuccess({197 mode: {type: 'Fungible', decimalPoints: 0},198 });199 const alice = privateKey('//Alice');200201 const owner = await createEthAccountWithBalance(api, web3);202 const spender = createEthAccount(web3);203204 await createFungibleItemExpectSuccess(alice, collection, {Value: 200n}, {Ethereum: owner});205206 const address = collectionIdToAddress(collection);207 const contract = new web3.eth.Contract(fungibleAbi as any, address, {from: owner, ...GAS_ARGS});208209 const cost = await recordEthFee(api, owner, () => contract.methods.approve(spender, 100).send({from: owner}));210 expect(cost < BigInt(0.2 * Number(UNIQUE)));211 });212213 itWeb3('transferFrom() call fee is less than 0.2UNQ', async ({web3, api}) => {214 const collection = await createCollectionExpectSuccess({215 mode: {type: 'Fungible', decimalPoints: 0},216 });217 const alice = privateKey('//Alice');218219 const owner = await createEthAccountWithBalance(api, web3);220 const spender = await createEthAccountWithBalance(api, web3);221222 await createFungibleItemExpectSuccess(alice, collection, {Value: 200n}, {Ethereum: owner});223224 const address = collectionIdToAddress(collection);225 const contract = new web3.eth.Contract(fungibleAbi as any, address, {from: owner, ...GAS_ARGS});226227 await contract.methods.approve(spender, 100).send({from: owner});228229 const cost = await recordEthFee(api, spender, () => contract.methods.transferFrom(owner, spender, 100).send({from: spender}));230 expect(cost < BigInt(0.2 * Number(UNIQUE)));231 });232233 itWeb3('transfer() call fee is less than 0.2UNQ', async ({web3, api}) => {234 const collection = await createCollectionExpectSuccess({235 mode: {type: 'Fungible', decimalPoints: 0},236 });237 const alice = privateKey('//Alice');238239 const owner = await createEthAccountWithBalance(api, web3);240 const receiver = createEthAccount(web3);241242 await createFungibleItemExpectSuccess(alice, collection, {Value: 200n}, {Ethereum: owner});243244 const address = collectionIdToAddress(collection);245 const contract = new web3.eth.Contract(fungibleAbi as any, address, {from: owner, ...GAS_ARGS});246247 const cost = await recordEthFee(api, owner, () => contract.methods.transfer(receiver, 100).send({from: owner}));248 expect(cost < BigInt(0.2 * Number(UNIQUE)));249 });250});251252describe('Fungible: Substrate calls', () => {253 itWeb3('Events emitted for approve()', async ({web3}) => {254 const collection = await createCollectionExpectSuccess({255 mode: {type: 'Fungible', decimalPoints: 0},256 });257 const alice = privateKey('//Alice');258259 const receiver = createEthAccount(web3);260261 await createFungibleItemExpectSuccess(alice, collection, {Value: 200n});262263 const address = collectionIdToAddress(collection);264 const contract = new web3.eth.Contract(fungibleAbi as any, address);265266 const events = await recordEvents(contract, async () => {267 await approveExpectSuccess(collection, 0, alice, {Ethereum: receiver}, 100);268 });269270 expect(events).to.be.deep.equal([271 {272 address,273 event: 'Approval',274 args: {275 owner: subToEth(alice.address),276 spender: receiver,277 value: '100',278 },279 },280 ]);281 });282283 itWeb3('Events emitted for transferFrom()', async ({web3}) => {284 const collection = await createCollectionExpectSuccess({285 mode: {type: 'Fungible', decimalPoints: 0},286 });287 const alice = privateKey('//Alice');288 const bob = privateKey('//Bob');289290 const receiver = createEthAccount(web3);291292 await createFungibleItemExpectSuccess(alice, collection, {Value: 200n});293 await approveExpectSuccess(collection, 0, alice, bob.address, 100);294295 const address = collectionIdToAddress(collection);296 const contract = new web3.eth.Contract(fungibleAbi as any, address);297298 const events = await recordEvents(contract, async () => {299 await transferFromExpectSuccess(collection, 0, bob, alice, {Ethereum: receiver}, 51, 'Fungible');300 });301302 expect(events).to.be.deep.equal([303 {304 address,305 event: 'Transfer',306 args: {307 from: subToEth(alice.address),308 to: receiver,309 value: '51',310 },311 },312 {313 address,314 event: 'Approval',315 args: {316 owner: subToEth(alice.address),317 spender: subToEth(bob.address),318 value: '49',319 },320 },321 ]);322 });323324 itWeb3('Events emitted for transfer()', async ({web3}) => {325 const collection = await createCollectionExpectSuccess({326 mode: {type: 'Fungible', decimalPoints: 0},327 });328 const alice = privateKey('//Alice');329330 const receiver = createEthAccount(web3);331332 await createFungibleItemExpectSuccess(alice, collection, {Value: 200n});333334 const address = collectionIdToAddress(collection);335 const contract = new web3.eth.Contract(fungibleAbi as any, address);336337 const events = await recordEvents(contract, async () => {338 await transferExpectSuccess(collection, 0, alice, {Ethereum:receiver}, 51, 'Fungible');339 });340341 expect(events).to.be.deep.equal([342 {343 address,344 event: 'Transfer',345 args: {346 from: subToEth(alice.address),347 to: receiver,348 value: '51',349 },350 },351 ]);352 });353});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 privateKey from '../substrate/privateKey';7import {approveExpectSuccess, createCollectionExpectSuccess, createFungibleItemExpectSuccess, transferExpectSuccess, transferFromExpectSuccess, UNIQUE} from '../util/helpers';8import {collectionIdToAddress, createEthAccount, createEthAccountWithBalance, GAS_ARGS, itWeb3, normalizeEvents, recordEthFee, recordEvents, subToEth, transferBalanceToEth} from './util/helpers';9import fungibleAbi from './fungibleAbi.json';10import {expect} from 'chai';1112describe('Fungible: Information getting', () => {13 itWeb3('totalSupply', async ({api, web3}) => {14 const collection = await createCollectionExpectSuccess({15 name: 'token name',16 mode: {type: 'Fungible', decimalPoints: 0},17 });18 const alice = privateKey('//Alice');1920 const caller = await createEthAccountWithBalance(api, web3);2122 await createFungibleItemExpectSuccess(alice, collection, {Value: 200n}, {Substrate: alice.address});2324 const address = collectionIdToAddress(collection);25 const contract = new web3.eth.Contract(fungibleAbi as any, address, {from: caller, ...GAS_ARGS});26 const totalSupply = await contract.methods.totalSupply().call();2728 expect(totalSupply).to.equal('200');29 });3031 itWeb3('balanceOf', async ({api, web3}) => {32 const collection = await createCollectionExpectSuccess({33 name: 'token name',34 mode: {type: 'Fungible', decimalPoints: 0},35 });36 const alice = privateKey('//Alice');3738 const caller = await createEthAccountWithBalance(api, web3);3940 await createFungibleItemExpectSuccess(alice, collection, {Value: 200n}, {Ethereum: caller});4142 const address = collectionIdToAddress(collection);43 const contract = new web3.eth.Contract(fungibleAbi as any, address, {from: caller, ...GAS_ARGS});44 const balance = await contract.methods.balanceOf(caller).call();4546 expect(balance).to.equal('200');47 });48});4950describe('Fungible: Plain calls', () => {51 itWeb3('Can perform approve()', async ({web3, api}) => {52 const collection = await createCollectionExpectSuccess({53 name: 'token name',54 mode: {type: 'Fungible', decimalPoints: 0},55 });56 const alice = privateKey('//Alice');5758 const owner = await createEthAccountWithBalance(api, web3);5960 await createFungibleItemExpectSuccess(alice, collection, {Value: 200n}, {Ethereum: owner});6162 const spender = createEthAccount(web3);6364 const address = collectionIdToAddress(collection);65 const contract = new web3.eth.Contract(fungibleAbi as any, address, {from: owner, ...GAS_ARGS});6667 {68 const result = await contract.methods.approve(spender, 100).send({from: owner});69 const events = normalizeEvents(result.events);7071 expect(events).to.be.deep.equal([72 {73 address,74 event: 'Approval',75 args: {76 owner,77 spender,78 value: '100',79 },80 },81 ]);82 }8384 {85 const allowance = await contract.methods.allowance(owner, spender).call();86 expect(+allowance).to.equal(100);87 }88 });8990 itWeb3('Can perform transferFrom()', async ({web3, api}) => {91 const collection = await createCollectionExpectSuccess({92 name: 'token name',93 mode: {type: 'Fungible', decimalPoints: 0},94 });95 const alice = privateKey('//Alice');9697 const owner = createEthAccount(web3);98 await transferBalanceToEth(api, alice, owner);99100 await createFungibleItemExpectSuccess(alice, collection, {Value: 200n}, {Ethereum: owner});101102 const spender = createEthAccount(web3);103 await transferBalanceToEth(api, alice, spender);104105 const receiver = createEthAccount(web3);106107 const address = collectionIdToAddress(collection);108 const contract = new web3.eth.Contract(fungibleAbi as any, address, {from: owner, ...GAS_ARGS});109110 await contract.methods.approve(spender, 100).send();111112 {113 const result = await contract.methods.transferFrom(owner, receiver, 49).send({from: spender});114 const events = normalizeEvents(result.events);115 expect(events).to.be.deep.equal([116 {117 address,118 event: 'Transfer',119 args: {120 from: owner,121 to: receiver,122 value: '49',123 },124 },125 {126 address,127 event: 'Approval',128 args: {129 owner,130 spender,131 value: '51',132 },133 },134 ]);135 }136137 {138 const balance = await contract.methods.balanceOf(receiver).call();139 expect(+balance).to.equal(49);140 }141142 {143 const balance = await contract.methods.balanceOf(owner).call();144 expect(+balance).to.equal(151);145 }146 });147148 itWeb3('Can perform transfer()', async ({web3, api}) => {149 const collection = await createCollectionExpectSuccess({150 name: 'token name',151 mode: {type: 'Fungible', decimalPoints: 0},152 });153 const alice = privateKey('//Alice');154155 const owner = createEthAccount(web3);156 await transferBalanceToEth(api, alice, owner);157158 await createFungibleItemExpectSuccess(alice, collection, {Value: 200n}, {Ethereum: owner});159160 const receiver = createEthAccount(web3);161 await transferBalanceToEth(api, alice, receiver);162163 const address = collectionIdToAddress(collection);164 const contract = new web3.eth.Contract(fungibleAbi as any, address, {from: owner, ...GAS_ARGS});165166 {167 const result = await contract.methods.transfer(receiver, 50).send({from: owner});168 const events = normalizeEvents(result.events);169 expect(events).to.be.deep.equal([170 {171 address,172 event: 'Transfer',173 args: {174 from: owner,175 to: receiver,176 value: '50',177 },178 },179 ]);180 }181182 {183 const balance = await contract.methods.balanceOf(owner).call();184 expect(+balance).to.equal(150);185 }186187 {188 const balance = await contract.methods.balanceOf(receiver).call();189 expect(+balance).to.equal(50);190 }191 });192});193194describe('Fungible: Fees', () => {195 itWeb3('approve() call fee is less than 0.2UNQ', async ({web3, api}) => {196 const collection = await createCollectionExpectSuccess({197 mode: {type: 'Fungible', decimalPoints: 0},198 });199 const alice = privateKey('//Alice');200201 const owner = await createEthAccountWithBalance(api, web3);202 const spender = createEthAccount(web3);203204 await createFungibleItemExpectSuccess(alice, collection, {Value: 200n}, {Ethereum: owner});205206 const address = collectionIdToAddress(collection);207 const contract = new web3.eth.Contract(fungibleAbi as any, address, {from: owner, ...GAS_ARGS});208209 const cost = await recordEthFee(api, owner, () => contract.methods.approve(spender, 100).send({from: owner}));210 expect(cost < BigInt(0.2 * Number(UNIQUE)));211 });212213 itWeb3('transferFrom() call fee is less than 0.2UNQ', async ({web3, api}) => {214 const collection = await createCollectionExpectSuccess({215 mode: {type: 'Fungible', decimalPoints: 0},216 });217 const alice = privateKey('//Alice');218219 const owner = await createEthAccountWithBalance(api, web3);220 const spender = await createEthAccountWithBalance(api, web3);221222 await createFungibleItemExpectSuccess(alice, collection, {Value: 200n}, {Ethereum: owner});223224 const address = collectionIdToAddress(collection);225 const contract = new web3.eth.Contract(fungibleAbi as any, address, {from: owner, ...GAS_ARGS});226227 await contract.methods.approve(spender, 100).send({from: owner});228229 const cost = await recordEthFee(api, spender, () => contract.methods.transferFrom(owner, spender, 100).send({from: spender}));230 expect(cost < BigInt(0.2 * Number(UNIQUE)));231 });232233 itWeb3('transfer() call fee is less than 0.2UNQ', async ({web3, api}) => {234 const collection = await createCollectionExpectSuccess({235 mode: {type: 'Fungible', decimalPoints: 0},236 });237 const alice = privateKey('//Alice');238239 const owner = await createEthAccountWithBalance(api, web3);240 const receiver = createEthAccount(web3);241242 await createFungibleItemExpectSuccess(alice, collection, {Value: 200n}, {Ethereum: owner});243244 const address = collectionIdToAddress(collection);245 const contract = new web3.eth.Contract(fungibleAbi as any, address, {from: owner, ...GAS_ARGS});246247 const cost = await recordEthFee(api, owner, () => contract.methods.transfer(receiver, 100).send({from: owner}));248 expect(cost < BigInt(0.2 * Number(UNIQUE)));249 });250});251252describe('Fungible: Substrate calls', () => {253 itWeb3('Events emitted for approve()', async ({web3}) => {254 const collection = await createCollectionExpectSuccess({255 mode: {type: 'Fungible', decimalPoints: 0},256 });257 const alice = privateKey('//Alice');258259 const receiver = createEthAccount(web3);260261 await createFungibleItemExpectSuccess(alice, collection, {Value: 200n});262263 const address = collectionIdToAddress(collection);264 const contract = new web3.eth.Contract(fungibleAbi as any, address);265266 const events = await recordEvents(contract, async () => {267 await approveExpectSuccess(collection, 0, alice, {Ethereum: receiver}, 100);268 });269270 expect(events).to.be.deep.equal([271 {272 address,273 event: 'Approval',274 args: {275 owner: subToEth(alice.address),276 spender: receiver,277 value: '100',278 },279 },280 ]);281 });282283 itWeb3('Events emitted for transferFrom()', async ({web3}) => {284 const collection = await createCollectionExpectSuccess({285 mode: {type: 'Fungible', decimalPoints: 0},286 });287 const alice = privateKey('//Alice');288 const bob = privateKey('//Bob');289290 const receiver = createEthAccount(web3);291292 await createFungibleItemExpectSuccess(alice, collection, {Value: 200n});293 await approveExpectSuccess(collection, 0, alice, bob.address, 100);294295 const address = collectionIdToAddress(collection);296 const contract = new web3.eth.Contract(fungibleAbi as any, address);297298 const events = await recordEvents(contract, async () => {299 await transferFromExpectSuccess(collection, 0, bob, alice, {Ethereum: receiver}, 51, 'Fungible');300 });301302 expect(events).to.be.deep.equal([303 {304 address,305 event: 'Transfer',306 args: {307 from: subToEth(alice.address),308 to: receiver,309 value: '51',310 },311 },312 {313 address,314 event: 'Approval',315 args: {316 owner: subToEth(alice.address),317 spender: subToEth(bob.address),318 value: '49',319 },320 },321 ]);322 });323324 itWeb3('Events emitted for transfer()', async ({web3}) => {325 const collection = await createCollectionExpectSuccess({326 mode: {type: 'Fungible', decimalPoints: 0},327 });328 const alice = privateKey('//Alice');329330 const receiver = createEthAccount(web3);331332 await createFungibleItemExpectSuccess(alice, collection, {Value: 200n});333334 const address = collectionIdToAddress(collection);335 const contract = new web3.eth.Contract(fungibleAbi as any, address);336337 const events = await recordEvents(contract, async () => {338 await transferExpectSuccess(collection, 0, alice, {Ethereum:receiver}, 51, 'Fungible');339 });340341 expect(events).to.be.deep.equal([342 {343 address,344 event: 'Transfer',345 args: {346 from: subToEth(alice.address),347 to: receiver,348 value: '51',349 },350 },351 ]);352 });353});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);