1234567891011121314151617import {collectionIdToAddress, createEthAccount, createEthAccountWithBalance, deployFlipper, ethBalanceViaSub, GAS_ARGS, itWeb3, recordEthFee} from './util/helpers';18import {expect} from 'chai';19import {createCollectionExpectSuccess, createItemExpectSuccess, UNIQUE} from '../util/helpers';20import nonFungibleAbi from './nonFungibleAbi.json';21import privateKey from '../substrate/privateKey';2223describe('Contract calls', () => {24 itWeb3('Call of simple contract fee is less than 0.2 UNQ', async ({web3, api}) => {25 const deployer = await createEthAccountWithBalance(api, web3);26 const flipper = await deployFlipper(web3, deployer);2728 const cost = await recordEthFee(api, deployer, () => flipper.methods.flip().send({from: deployer}));29 expect(cost < BigInt(0.2 * Number(UNIQUE))).to.be.true;30 });3132 itWeb3('Balance transfer fee is less than 0.2 UNQ', async ({web3, api}) => {33 const userA = await createEthAccountWithBalance(api, web3);34 const userB = createEthAccount(web3);3536 const cost = await recordEthFee(api, userA, () => web3.eth.sendTransaction({from: userA, to: userB, value: '1000000', ...GAS_ARGS}));37 const balanceB = await ethBalanceViaSub(api, userB);38 expect(cost - balanceB < BigInt(0.2 * Number(UNIQUE))).to.be.true;39 });4041 itWeb3('NFT transfer is close to 0.15 UNQ', async ({web3, api}) => {42 const caller = await createEthAccountWithBalance(api, web3);43 const receiver = createEthAccount(web3);4445 const alice = privateKey('//Alice');46 const collection = await createCollectionExpectSuccess({47 mode: {type: 'NFT'},48 });49 const itemId = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: caller});5051 const address = collectionIdToAddress(collection);52 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});5354 const cost = await recordEthFee(api, caller, () => contract.methods.transfer(receiver, itemId).send(caller));5556 const fee = Number(cost) / Number(UNIQUE);57 const expectedFee = 0.15;58 const tolerance = 0.00002;5960 expect(Math.abs(fee - expectedFee)).to.be.lessThan(tolerance);61 });62});