difftreelog
test call fees
in: master
6 files changed
tests/src/eth/base.test.tsdiffbeforeafterboth--- /dev/null
+++ b/tests/src/eth/base.test.ts
@@ -0,0 +1,22 @@
+
+import { createEthAccount, createEthAccountWithBalance, deployFlipper, ethBalanceViaSub, GAS_ARGS, itWeb3, recordEthFee } from './util/helpers';
+import { expect } from 'chai';
+import { UNIQUE } from '../util/helpers';
+
+describe('Contract calls', () => {
+ itWeb3('Call of simple contract fee is less than 0.2 UNQ', async ({ web3, api }) => {
+ const deployer = await createEthAccountWithBalance(api, web3);
+ const flipper = await deployFlipper(web3 as any, deployer);
+
+ const cost = await recordEthFee(api, deployer, () => flipper.methods.flip());
+ expect(cost < BigInt(0.2 * Number(UNIQUE))).to.be.true;
+ });
+
+ itWeb3('Balance transfer fee is less than 0.2 UNQ', async ({ web3, api }) => {
+ const userA = await createEthAccountWithBalance(api, web3);
+ const userB = createEthAccount(web3);
+
+ 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;
+ });
+});
\ No newline at end of file
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 } from '../util/helpers';8import { collectionIdToAddress, createEthAccount, createEthAccountWithBalance, GAS_ARGS, itWeb3, normalizeEvents, 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);21 22 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 // FIXME: always equals to 0, because this method is not implemented29 expect(totalSupply).to.equal('0');30 });3132 itWeb3('balanceOf', async ({ api, web3 }) => {33 const collection = await createCollectionExpectSuccess({34 name: 'token name',35 mode: { type: 'Fungible', decimalPoints: 0 },36 });37 const alice = privateKey('//Alice');3839 const caller = await createEthAccountWithBalance(api, web3);4041 await createFungibleItemExpectSuccess(alice, collection, { Value: 200n }, { ethereum: caller });4243 const address = collectionIdToAddress(collection);44 const contract = new web3.eth.Contract(fungibleAbi as any, address, {from: caller, ...GAS_ARGS});45 const balance = await contract.methods.balanceOf(caller).call();4647 expect(balance).to.equal('200');48 });49});5051describe('Fungible: Plain calls', () => {52 itWeb3('Can perform approve()', async ({ web3, api }) => {53 const collection = await createCollectionExpectSuccess({54 name: 'token name',55 mode: { type: 'Fungible', decimalPoints: 0 },56 });57 const alice = privateKey('//Alice');5859 const owner = await createEthAccountWithBalance(api, web3);6061 await createFungibleItemExpectSuccess(alice, collection, { Value: 200n }, { ethereum: owner });6263 const spender = createEthAccount(web3);6465 const address = collectionIdToAddress(collection);66 const contract = new web3.eth.Contract(fungibleAbi as any, address, {from: owner, ...GAS_ARGS});6768 {69 const result = await contract.methods.approve(spender, 100).send({from: owner});70 const events = normalizeEvents(result.events);7172 expect(events).to.be.deep.equal([73 {74 address,75 event: 'Approval',76 args: {77 owner,78 spender,79 value: '100',80 },81 },82 ]);83 }8485 {86 const allowance = await contract.methods.allowance(owner, spender).call();87 expect(+allowance).to.equal(100);88 }89 });9091 itWeb3('Can perform transferFrom()', async ({ web3, api }) => {92 const collection = await createCollectionExpectSuccess({93 name: 'token name',94 mode: { type: 'Fungible', decimalPoints: 0 },95 });96 const alice = privateKey('//Alice');9798 const owner = createEthAccount(web3);99 await transferBalanceToEth(api, alice, owner, 999999999999999);100101 await createFungibleItemExpectSuccess(alice, collection, { Value: 200n }, { ethereum: owner });102103 const spender = createEthAccount(web3);104 await transferBalanceToEth(api, alice, spender, 999999999999999);105106 const receiver = createEthAccount(web3);107108 const address = collectionIdToAddress(collection);109 const contract = new web3.eth.Contract(fungibleAbi as any, address, {from: owner, ...GAS_ARGS});110111 await contract.methods.approve(spender, 100).send();112113 {114 const result = await contract.methods.transferFrom(owner, receiver, 49).send({from: spender});115 const events = normalizeEvents(result.events);116 expect(events).to.be.deep.equal([117 {118 address,119 event: 'Transfer',120 args: {121 from: owner,122 to: receiver,123 value: '49',124 },125 },126 {127 address,128 event: 'Approval',129 args: {130 owner,131 spender,132 value: '51',133 },134 },135 ]);136 }137138 {139 const balance = await contract.methods.balanceOf(receiver).call();140 expect(+balance).to.equal(49);141 }142143 {144 const balance = await contract.methods.balanceOf(owner).call();145 expect(+balance).to.equal(151);146 }147 });148149 itWeb3('Can perform transfer()', async ({ web3, api }) => {150 const collection = await createCollectionExpectSuccess({151 name: 'token name',152 mode: { type: 'Fungible', decimalPoints: 0 },153 });154 const alice = privateKey('//Alice');155156 const owner = createEthAccount(web3);157 await transferBalanceToEth(api, alice, owner, 999999999999999);158159 await createFungibleItemExpectSuccess(alice, collection, { Value: 200n }, { ethereum: owner });160161 const receiver = createEthAccount(web3);162 await transferBalanceToEth(api, alice, receiver, 999999999999999);163164 const address = collectionIdToAddress(collection);165 const contract = new web3.eth.Contract(fungibleAbi as any, address, {from: owner, ...GAS_ARGS});166167 {168 const result = await contract.methods.transfer(receiver, 50).send({ from: owner});169 const events = normalizeEvents(result.events);170 expect(events).to.be.deep.equal([171 {172 address,173 event: 'Transfer',174 args: {175 from: owner,176 to: receiver,177 value: '50',178 },179 },180 ]);181 }182183 {184 const balance = await contract.methods.balanceOf(owner).call();185 expect(+balance).to.equal(150);186 }187188 {189 const balance = await contract.methods.balanceOf(receiver).call();190 expect(+balance).to.equal(50);191 }192 });193});194195describe('Fungible: Substrate calls', () => {196 itWeb3('Events emitted for approve()', async ({ web3 }) => {197 const collection = await createCollectionExpectSuccess({198 mode: { type: 'Fungible', decimalPoints: 0 },199 });200 const alice = privateKey('//Alice');201202 const receiver = createEthAccount(web3);203204 await createFungibleItemExpectSuccess(alice, collection, { Value: 200n });205206 const address = collectionIdToAddress(collection);207 const contract = new web3.eth.Contract(fungibleAbi as any, address);208209 const events = await recordEvents(contract, async () => {210 await approveExpectSuccess(collection, 1, alice, { ethereum: receiver }, 100);211 });212213 expect(events).to.be.deep.equal([214 {215 address,216 event: 'Approval',217 args: {218 owner: subToEth(alice.address),219 spender: receiver,220 value: '100',221 },222 },223 ]);224 });225226 itWeb3('Events emitted for transferFrom()', async ({ web3 }) => {227 const collection = await createCollectionExpectSuccess({228 mode: { type: 'Fungible', decimalPoints: 0 },229 });230 const alice = privateKey('//Alice');231 const bob = privateKey('//Bob');232233 const receiver = createEthAccount(web3);234235 await createFungibleItemExpectSuccess(alice, collection, { Value: 200n });236 await approveExpectSuccess(collection, 1, alice, bob, 100);237238 const address = collectionIdToAddress(collection);239 const contract = new web3.eth.Contract(fungibleAbi as any, address);240241 const events = await recordEvents(contract, async () => {242 await transferFromExpectSuccess(collection, 1, bob, alice, { ethereum: receiver }, 51, 'Fungible');243 });244245 expect(events).to.be.deep.equal([246 {247 address,248 event: 'Transfer',249 args: {250 from: subToEth(alice.address),251 to: receiver,252 value: '51',253 },254 },255 {256 address,257 event: 'Approval',258 args: {259 owner: subToEth(alice.address),260 spender: subToEth(bob.address),261 value: '49',262 },263 },264 ]);265 });266267 itWeb3('Events emitted for transfer()', async ({ web3 }) => {268 const collection = await createCollectionExpectSuccess({269 mode: { type: 'Fungible', decimalPoints: 0 },270 });271 const alice = privateKey('//Alice');272273 const receiver = createEthAccount(web3);274275 await createFungibleItemExpectSuccess(alice, collection, { Value: 200n });276277 const address = collectionIdToAddress(collection);278 const contract = new web3.eth.Contract(fungibleAbi as any, address);279280 const events = await recordEvents(contract, async () => {281 await transferExpectSuccess(collection, 1, alice, { ethereum: receiver }, 51, 'Fungible');282 });283284 expect(events).to.be.deep.equal([285 {286 address,287 event: 'Transfer',288 args: {289 from: subToEth(alice.address),290 to: receiver,291 value: '51',292 },293 },294 ]);295 });296});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);21 22 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 // FIXME: always equals to 0, because this method is not implemented29 expect(totalSupply).to.equal('0');30 });3132 itWeb3('balanceOf', async ({ api, web3 }) => {33 const collection = await createCollectionExpectSuccess({34 name: 'token name',35 mode: { type: 'Fungible', decimalPoints: 0 },36 });37 const alice = privateKey('//Alice');3839 const caller = await createEthAccountWithBalance(api, web3);4041 await createFungibleItemExpectSuccess(alice, collection, { Value: 200n }, { ethereum: caller });4243 const address = collectionIdToAddress(collection);44 const contract = new web3.eth.Contract(fungibleAbi as any, address, {from: caller, ...GAS_ARGS});45 const balance = await contract.methods.balanceOf(caller).call();4647 expect(balance).to.equal('200');48 });49});5051describe('Fungible: Plain calls', () => {52 itWeb3('Can perform approve()', async ({ web3, api }) => {53 const collection = await createCollectionExpectSuccess({54 name: 'token name',55 mode: { type: 'Fungible', decimalPoints: 0 },56 });57 const alice = privateKey('//Alice');5859 const owner = await createEthAccountWithBalance(api, web3);6061 await createFungibleItemExpectSuccess(alice, collection, { Value: 200n }, { ethereum: owner });6263 const spender = createEthAccount(web3);6465 const address = collectionIdToAddress(collection);66 const contract = new web3.eth.Contract(fungibleAbi as any, address, {from: owner, ...GAS_ARGS});6768 {69 const result = await contract.methods.approve(spender, 100).send({from: owner});70 const events = normalizeEvents(result.events);7172 expect(events).to.be.deep.equal([73 {74 address,75 event: 'Approval',76 args: {77 owner,78 spender,79 value: '100',80 },81 },82 ]);83 }8485 {86 const allowance = await contract.methods.allowance(owner, spender).call();87 expect(+allowance).to.equal(100);88 }89 });9091 itWeb3('Can perform transferFrom()', async ({ web3, api }) => {92 const collection = await createCollectionExpectSuccess({93 name: 'token name',94 mode: { type: 'Fungible', decimalPoints: 0 },95 });96 const alice = privateKey('//Alice');9798 const owner = createEthAccount(web3);99 await transferBalanceToEth(api, alice, owner, 999999999999999);100101 await createFungibleItemExpectSuccess(alice, collection, { Value: 200n }, { ethereum: owner });102103 const spender = createEthAccount(web3);104 await transferBalanceToEth(api, alice, spender, 999999999999999);105106 const receiver = createEthAccount(web3);107108 const address = collectionIdToAddress(collection);109 const contract = new web3.eth.Contract(fungibleAbi as any, address, {from: owner, ...GAS_ARGS});110111 await contract.methods.approve(spender, 100).send();112113 {114 const result = await contract.methods.transferFrom(owner, receiver, 49).send({from: spender});115 const events = normalizeEvents(result.events);116 expect(events).to.be.deep.equal([117 {118 address,119 event: 'Transfer',120 args: {121 from: owner,122 to: receiver,123 value: '49',124 },125 },126 {127 address,128 event: 'Approval',129 args: {130 owner,131 spender,132 value: '51',133 },134 },135 ]);136 }137138 {139 const balance = await contract.methods.balanceOf(receiver).call();140 expect(+balance).to.equal(49);141 }142143 {144 const balance = await contract.methods.balanceOf(owner).call();145 expect(+balance).to.equal(151);146 }147 });148149 itWeb3('Can perform transfer()', async ({ web3, api }) => {150 const collection = await createCollectionExpectSuccess({151 name: 'token name',152 mode: { type: 'Fungible', decimalPoints: 0 },153 });154 const alice = privateKey('//Alice');155156 const owner = createEthAccount(web3);157 await transferBalanceToEth(api, alice, owner, 999999999999999);158159 await createFungibleItemExpectSuccess(alice, collection, { Value: 200n }, { ethereum: owner });160161 const receiver = createEthAccount(web3);162 await transferBalanceToEth(api, alice, receiver, 999999999999999);163164 const address = collectionIdToAddress(collection);165 const contract = new web3.eth.Contract(fungibleAbi as any, address, {from: owner, ...GAS_ARGS});166167 {168 const result = await contract.methods.transfer(receiver, 50).send({ from: owner});169 const events = normalizeEvents(result.events);170 expect(events).to.be.deep.equal([171 {172 address,173 event: 'Transfer',174 args: {175 from: owner,176 to: receiver,177 value: '50',178 },179 },180 ]);181 }182183 {184 const balance = await contract.methods.balanceOf(owner).call();185 expect(+balance).to.equal(150);186 }187188 {189 const balance = await contract.methods.balanceOf(receiver).call();190 expect(+balance).to.equal(50);191 }192 });193});194195describe('Fungible: Fees', () => {196 itWeb3('approve() call fee is less than 0.2UNQ', async ({ web3, api }) => {197 const collection = await createCollectionExpectSuccess({198 mode: { type: 'Fungible', decimalPoints: 0 },199 });200 const alice = privateKey('//Alice');201202 const owner = await createEthAccountWithBalance(api, web3);203 const spender = createEthAccount(web3);204205 await createFungibleItemExpectSuccess(alice, collection, { Value: 200n }, { ethereum: owner });206207 const address = collectionIdToAddress(collection);208 const contract = new web3.eth.Contract(fungibleAbi as any, address, { from: owner, ...GAS_ARGS });209210 const cost = await recordEthFee(api, owner, () => contract.methods.approve(spender, 100).send({ from: owner }));211 expect(cost < BigInt(0.2 * Number(UNIQUE)));212 });213214 itWeb3('transferFrom() call fee is less than 0.2UNQ', async ({ web3, api }) => {215 const collection = await createCollectionExpectSuccess({216 mode: {type: 'Fungible', decimalPoints: 0},217 });218 const alice = privateKey('//Alice');219 220 const owner = await createEthAccountWithBalance(api, web3);221 const spender = await createEthAccountWithBalance(api, web3);222223 await createFungibleItemExpectSuccess(alice, collection, { Value: 200n }, { ethereum: owner });224225 const address = collectionIdToAddress(collection);226 const contract = new web3.eth.Contract(fungibleAbi as any, address, { from: owner, ...GAS_ARGS });227228 await contract.methods.approve(spender, 100).send({ from: owner });229230 const cost = await recordEthFee(api, spender, () => contract.methods.transferFrom(owner, spender, 100).send({ from: spender }));231 expect(cost < BigInt(0.2 * Number(UNIQUE)));232 });233234 itWeb3('transfer() call fee is less than 0.2UNQ', async ({ web3, api }) => {235 const collection = await createCollectionExpectSuccess({236 mode: { type: 'Fungible', decimalPoints: 0 },237 });238 const alice = privateKey('//Alice');239240 const owner = await createEthAccountWithBalance(api, web3);241 const receiver = createEthAccount(web3);242243 await createFungibleItemExpectSuccess(alice, collection, { Value: 200n }, { ethereum: owner });244245 const address = collectionIdToAddress(collection);246 const contract = new web3.eth.Contract(fungibleAbi as any, address, { from: owner, ...GAS_ARGS });247248 const cost = await recordEthFee(api, owner, () => contract.methods.transfer(receiver, 100).send({ from: owner }));249 expect(cost < BigInt(0.2 * Number(UNIQUE)));250 });251});252253describe('Fungible: Substrate calls', () => {254 itWeb3('Events emitted for approve()', async ({ web3 }) => {255 const collection = await createCollectionExpectSuccess({256 mode: { type: 'Fungible', decimalPoints: 0 },257 });258 const alice = privateKey('//Alice');259260 const receiver = createEthAccount(web3);261262 await createFungibleItemExpectSuccess(alice, collection, { Value: 200n });263264 const address = collectionIdToAddress(collection);265 const contract = new web3.eth.Contract(fungibleAbi as any, address);266267 const events = await recordEvents(contract, async () => {268 await approveExpectSuccess(collection, 1, alice, { ethereum: receiver }, 100);269 });270271 expect(events).to.be.deep.equal([272 {273 address,274 event: 'Approval',275 args: {276 owner: subToEth(alice.address),277 spender: receiver,278 value: '100',279 },280 },281 ]);282 });283284 itWeb3('Events emitted for transferFrom()', async ({ web3 }) => {285 const collection = await createCollectionExpectSuccess({286 mode: { type: 'Fungible', decimalPoints: 0 },287 });288 const alice = privateKey('//Alice');289 const bob = privateKey('//Bob');290291 const receiver = createEthAccount(web3);292293 await createFungibleItemExpectSuccess(alice, collection, { Value: 200n });294 await approveExpectSuccess(collection, 1, alice, bob, 100);295296 const address = collectionIdToAddress(collection);297 const contract = new web3.eth.Contract(fungibleAbi as any, address);298299 const events = await recordEvents(contract, async () => {300 await transferFromExpectSuccess(collection, 1, bob, alice, { ethereum: receiver }, 51, 'Fungible');301 });302303 expect(events).to.be.deep.equal([304 {305 address,306 event: 'Transfer',307 args: {308 from: subToEth(alice.address),309 to: receiver,310 value: '51',311 },312 },313 {314 address,315 event: 'Approval',316 args: {317 owner: subToEth(alice.address),318 spender: subToEth(bob.address),319 value: '49',320 },321 },322 ]);323 });324325 itWeb3('Events emitted for transfer()', async ({ web3 }) => {326 const collection = await createCollectionExpectSuccess({327 mode: { type: 'Fungible', decimalPoints: 0 },328 });329 const alice = privateKey('//Alice');330331 const receiver = createEthAccount(web3);332333 await createFungibleItemExpectSuccess(alice, collection, { Value: 200n });334335 const address = collectionIdToAddress(collection);336 const contract = new web3.eth.Contract(fungibleAbi as any, address);337338 const events = await recordEvents(contract, async () => {339 await transferExpectSuccess(collection, 1, alice, { ethereum: receiver }, 51, 'Fungible');340 });341342 expect(events).to.be.deep.equal([343 {344 address,345 event: 'Transfer',346 args: {347 from: subToEth(alice.address),348 to: receiver,349 value: '51',350 },351 },352 ]);353 });354});tests/src/eth/helpersSmoke.test.tsdiffbeforeafterboth--- a/tests/src/eth/helpersSmoke.test.ts
+++ b/tests/src/eth/helpersSmoke.test.ts
@@ -1,26 +1,24 @@
import { expect } from 'chai';
import waitNewBlocks from '../substrate/wait-new-blocks';
-import { createEthAccountWithBalance, deployFlipper, itWeb3, usingWeb3Http, contractHelpers } from './util/helpers';
+import { createEthAccountWithBalance, deployFlipper, itWeb3, contractHelpers } from './util/helpers';
-itWeb3('Contract owner is recorded', async ({ api, web3 }) => {
- await usingWeb3Http(async web3Http => {
- const owner = await createEthAccountWithBalance(api, web3Http);
+describe('Helpers sanity check', () => {
+ itWeb3('Contract owner is recorded', async ({ api, web3 }) => {
+ const owner = await createEthAccountWithBalance(api, web3);
- const flipper = await deployFlipper(web3Http, owner);
+ const flipper = await deployFlipper(web3, owner);
await waitNewBlocks(api, 1);
expect(await contractHelpers(web3, owner).methods.contractOwner(flipper.options.address).call()).to.be.equal(owner);
});
-});
-itWeb3('Flipper is working', async({api}) => {
- await usingWeb3Http(async web3Http => {
- const owner = await createEthAccountWithBalance(api, web3Http);
- const flipper = await deployFlipper(web3Http, owner);
+ itWeb3('Flipper is working', async ({ api, web3 }) => {
+ const owner = await createEthAccountWithBalance(api, web3);
+ const flipper = await deployFlipper(web3, owner);
await waitNewBlocks(api, 1);
expect(await flipper.methods.getValue().call()).to.be.false;
- await flipper.methods.flip().send({from: owner});
+ await flipper.methods.flip().send({ from: owner });
await waitNewBlocks(api, 1);
expect(await flipper.methods.getValue().call()).to.be.true;
});
tests/src/eth/nonFungible.test.tsdiffbeforeafterboth--- a/tests/src/eth/nonFungible.test.ts
+++ b/tests/src/eth/nonFungible.test.ts
@@ -4,8 +4,8 @@
//
import privateKey from '../substrate/privateKey';
-import { approveExpectSuccess, createCollectionExpectSuccess, createItemExpectSuccess, transferExpectSuccess, transferFromExpectSuccess } from '../util/helpers';
-import { collectionIdToAddress, createEthAccount, createEthAccountWithBalance, GAS_ARGS, itWeb3, normalizeEvents, recordEvents, subToEth, transferBalanceToEth } from './util/helpers';
+import { approveExpectSuccess, createCollectionExpectSuccess, createItemExpectSuccess, transferExpectSuccess, transferFromExpectSuccess, UNIQUE } from '../util/helpers';
+import { collectionIdToAddress, createEthAccount, createEthAccountWithBalance, GAS_ARGS, itWeb3, normalizeEvents, recordEthFee, recordEvents, subToEth, transferBalanceToEth } from './util/helpers';
import nonFungibleAbi from './nonFungibleAbi.json';
import { expect } from 'chai';
import waitNewBlocks from '../substrate/wait-new-blocks';
@@ -192,6 +192,64 @@
});
});
+describe('NFT: Fees', () => {
+ itWeb3('approve() call fee is less than 0.2UNQ', async ({ web3, api }) => {
+ const collection = await createCollectionExpectSuccess({
+ mode: { type: 'NFT' },
+ });
+ const alice = privateKey('//Alice');
+
+ const owner = await createEthAccountWithBalance(api, web3);
+ const spender = createEthAccount(web3);
+
+ const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: owner });
+
+ const address = collectionIdToAddress(collection);
+ const contract = new web3.eth.Contract(nonFungibleAbi as any, address, { from: owner, ...GAS_ARGS });
+
+ const cost = await recordEthFee(api, owner, () => contract.methods.approve(spender, tokenId).send({ from: owner }));
+ expect(cost < BigInt(0.2 * Number(UNIQUE)));
+ });
+
+ itWeb3('transferFrom() call fee is less than 0.2UNQ', async ({ web3, api }) => {
+ const collection = await createCollectionExpectSuccess({
+ mode: { type: 'NFT' },
+ });
+ const alice = privateKey('//Alice');
+
+ const owner = await createEthAccountWithBalance(api, web3);
+ const spender = await createEthAccountWithBalance(api, web3);
+
+ const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: owner });
+
+ const address = collectionIdToAddress(collection);
+ const contract = new web3.eth.Contract(nonFungibleAbi as any, address, { from: owner, ...GAS_ARGS });
+
+ await contract.methods.approve(spender, tokenId).send({ from: owner });
+
+ const cost = await recordEthFee(api, spender, () => contract.methods.transferFrom(owner, spender, tokenId).send({ from: spender }));
+ expect(cost < BigInt(0.2 * Number(UNIQUE)));
+ });
+
+ itWeb3('transfer() call fee is less than 0.2UNQ', async ({ web3, api }) => {
+ const collection = await createCollectionExpectSuccess({
+ mode: { type: 'NFT' },
+ });
+ const alice = privateKey('//Alice');
+
+ const owner = await createEthAccountWithBalance(api, web3);
+ const receiver = createEthAccount(web3);
+
+ const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: owner });
+
+ const address = collectionIdToAddress(collection);
+ const contract = new web3.eth.Contract(nonFungibleAbi as any, address, { from: owner, ...GAS_ARGS });
+
+ const cost = await recordEthFee(api, owner, () => contract.methods.transfer(receiver, tokenId).send({ from: owner }));
+ expect(cost < BigInt(0.2 * Number(UNIQUE)));
+ });
+});
+
describe('NFT: Substrate calls', () => {
itWeb3('Events emitted for approve()', async ({ web3 }) => {
const collection = await createCollectionExpectSuccess({
tests/src/eth/util/helpers.tsdiffbeforeafterboth--- a/tests/src/eth/util/helpers.ts
+++ b/tests/src/eth/util/helpers.ts
@@ -17,6 +17,7 @@
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' };
@@ -221,4 +222,21 @@
export function contractHelpers(web3: Web3, caller: string) {
return new web3.eth.Contract(contractHelpersAbi as any, '0x842899ECF380553E8a4de75bF534cdf6fBF64049', {from: caller, ...GAS_ARGS});
+}
+
+export async function ethBalanceViaSub(api: ApiPromise, address: string): Promise<bigint> {
+ return (await getBalance(api, [evmToAddress(address)]))[0];
+}
+
+export async function recordEthFee(api: ApiPromise, user: string, call: () => Promise<any>): Promise<bigint> {
+ const before = await ethBalanceViaSub(api, user);
+
+ await call();
+
+ const after = await ethBalanceViaSub(api, user);
+
+ // Can't use .to.be.less, because chai doesn't supports bigint
+ expect(after < before).to.be.true;
+
+ return before - after;
}
\ No newline at end of file
tests/src/util/helpers.tsdiffbeforeafterboth--- a/tests/src/util/helpers.ts
+++ b/tests/src/util/helpers.ts
@@ -53,6 +53,11 @@
export const U128_MAX = (1n << 128n) - 1n;
+const MICROUNIQUE = 1_000_000_000n;
+const MILLIUNIQUE = 1_000n * MICROUNIQUE;
+const CENTIUNIQUE = 10n * MILLIUNIQUE;
+export const UNIQUE = 100n * CENTIUNIQUE;
+
type GenericResult = {
success: boolean,
};