1234567891011121314151617import {18 collectionIdToAddress, 19 createEthAccount, 20 createEthAccountWithBalance, 21 deployFlipper, 22 ethBalanceViaSub, 23 GAS_ARGS, 24 itWeb3, 25 recordEthFee, 26 usingWeb3,27} from './util/helpers';28import {expect} from 'chai';29import {createCollectionExpectSuccess, createItemExpectSuccess, UNIQUE} from '../util/helpers';30import nonFungibleAbi from './nonFungibleAbi.json';31import privateKey from '../substrate/privateKey';32import {Contract} from 'web3-eth-contract';33import Web3 from 'web3';3435describe('Contract calls', () => {36 itWeb3('Call of simple contract fee is less than 0.2 UNQ', async ({web3, api}) => {37 const deployer = await createEthAccountWithBalance(api, web3);38 const flipper = await deployFlipper(web3, deployer);3940 const cost = await recordEthFee(api, deployer, () => flipper.methods.flip().send({from: deployer}));41 expect(cost < BigInt(0.2 * Number(UNIQUE))).to.be.true;42 });4344 itWeb3('Balance transfer fee is less than 0.2 UNQ', async ({web3, api}) => {45 const userA = await createEthAccountWithBalance(api, web3);46 const userB = createEthAccount(web3);4748 const cost = await recordEthFee(api, userA, () => web3.eth.sendTransaction({from: userA, to: userB, value: '1000000', ...GAS_ARGS}));49 const balanceB = await ethBalanceViaSub(api, userB);50 expect(cost - balanceB < BigInt(0.2 * Number(UNIQUE))).to.be.true;51 });5253 itWeb3('NFT transfer is close to 0.15 UNQ', async ({web3, api}) => {54 const caller = await createEthAccountWithBalance(api, web3);55 const receiver = createEthAccount(web3);5657 const alice = privateKey('//Alice');58 const collection = await createCollectionExpectSuccess({59 mode: {type: 'NFT'},60 });61 const itemId = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: caller});6263 const address = collectionIdToAddress(collection);64 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});6566 const cost = await recordEthFee(api, caller, () => contract.methods.transfer(receiver, itemId).send(caller));6768 const fee = Number(cost) / Number(UNIQUE);69 const expectedFee = 0.15;70 const tolerance = 0.00002;7172 expect(Math.abs(fee - expectedFee)).to.be.lessThan(tolerance);73 });74});7576describe('ERC165 tests', async () => {77 7879 let collection: number;80 let minter: string;8182 function contract(web3: Web3): Contract {83 return new web3.eth.Contract(nonFungibleAbi as any, collectionIdToAddress(collection), {from: minter, ...GAS_ARGS});84 }8586 before(async () => {87 await usingWeb3 (async (web3) => {88 collection = await createCollectionExpectSuccess();89 minter = createEthAccount(web3);90 });91 });9293 itWeb3('interfaceID == 0xffffffff always false', async ({web3}) => {94 expect(await contract(web3).methods.supportsInterface('0xffffffff').call()).to.be.false;95 });9697 itWeb3('ERC721 support', async ({web3}) => {98 expect(await contract(web3).methods.supportsInterface('0x58800161').call()).to.be.true;99 });100101 itWeb3('ERC721Metadata support', async ({web3}) => {102 expect(await contract(web3).methods.supportsInterface('0x5b5e139f').call()).to.be.true;103 });104105 itWeb3('ERC721Mintable support', async ({web3}) => {106 expect(await contract(web3).methods.supportsInterface('0x68ccfe89').call()).to.be.true;107 });108109 itWeb3('ERC721Enumerable support', async ({web3}) => {110 expect(await contract(web3).methods.supportsInterface('0x780e9d63').call()).to.be.true;111 });112113 itWeb3('ERC721UniqueExtensions support', async ({web3}) => {114 expect(await contract(web3).methods.supportsInterface('0xd74d154f').call()).to.be.true;115 });116117 itWeb3('ERC721Burnable support', async ({web3}) => {118 expect(await contract(web3).methods.supportsInterface('0x42966c68').call()).to.be.true;119 });120121 itWeb3('ERC165 support', async ({web3}) => {122 expect(await contract(web3).methods.supportsInterface('0x01ffc9a7').call()).to.be.true;123 });124});