1234567891011121314151617import {collectionIdToAddress, createEthAccount, createEthAccountWithBalance, deployFlipper, ethBalanceViaSub, GAS_ARGS, itWeb3, recordEthFee, usingWeb3} from './util/helpers';18import {expect} from 'chai';19import {createCollectionExpectSuccess, createItemExpectSuccess, UNIQUE} from '../util/helpers';20import nonFungibleAbi from './nonFungibleAbi.json';21import privateKey from '../substrate/privateKey';22import {Contract} from 'web3-eth-contract';23import Web3 from 'web3';2425describe('Contract calls', () => {26 itWeb3('Call of simple contract fee is less than 0.2 UNQ', async ({web3, api}) => {27 const deployer = await createEthAccountWithBalance(api, web3);28 const flipper = await deployFlipper(web3, deployer);2930 const cost = await recordEthFee(api, deployer, () => flipper.methods.flip().send({from: deployer}));31 expect(cost < BigInt(0.2 * Number(UNIQUE))).to.be.true;32 });3334 itWeb3('Balance transfer fee is less than 0.2 UNQ', async ({web3, api}) => {35 const userA = await createEthAccountWithBalance(api, web3);36 const userB = createEthAccount(web3);3738 const cost = await recordEthFee(api, userA, () => web3.eth.sendTransaction({from: userA, to: userB, value: '1000000', ...GAS_ARGS}));39 const balanceB = await ethBalanceViaSub(api, userB);40 expect(cost - balanceB < BigInt(0.2 * Number(UNIQUE))).to.be.true;41 });4243 itWeb3('NFT transfer is close to 0.15 UNQ', async ({web3, api}) => {44 const caller = await createEthAccountWithBalance(api, web3);45 const receiver = createEthAccount(web3);4647 const alice = privateKey('//Alice');48 const collection = await createCollectionExpectSuccess({49 mode: {type: 'NFT'},50 });51 const itemId = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: caller});5253 const address = collectionIdToAddress(collection);54 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});5556 const cost = await recordEthFee(api, caller, () => contract.methods.transfer(receiver, itemId).send(caller));5758 const fee = Number(cost) / Number(UNIQUE);59 const expectedFee = 0.15;60 const tolerance = 0.00002;6162 expect(Math.abs(fee - expectedFee)).to.be.lessThan(tolerance);63 });64});6566describe('ERC165 tests', async () => {67 6869 let collection: number;70 let minter: string;7172 function contract(web3: Web3): Contract {73 return new web3.eth.Contract(nonFungibleAbi as any, collectionIdToAddress(collection), {from: minter, ...GAS_ARGS});74 }7576 before(async () => {77 await usingWeb3 (async (web3) => {78 collection = await createCollectionExpectSuccess();79 minter = createEthAccount(web3);80 });81 });8283 itWeb3('interfaceID == 0xffffffff always false', async ({web3}) => {84 expect(await contract(web3).methods.supportsInterface('0xffffffff').call()).to.be.false;85 });8687 itWeb3('ERC721 support', async ({web3}) => {88 expect(await contract(web3).methods.supportsInterface('0x58800161').call()).to.be.true;89 });9091 itWeb3('ERC721Metadata support', async ({web3}) => {92 expect(await contract(web3).methods.supportsInterface('0x5b5e139f').call()).to.be.true;93 });9495 itWeb3('ERC721Mintable support', async ({web3}) => {96 expect(await contract(web3).methods.supportsInterface('0x68ccfe89').call()).to.be.true;97 });9899 itWeb3('ERC721Enumerable support', async ({web3}) => {100 expect(await contract(web3).methods.supportsInterface('0x780e9d63').call()).to.be.true;101 });102103 itWeb3('ERC721UniqueExtensions support', async ({web3}) => {104 expect(await contract(web3).methods.supportsInterface('0xd74d154f').call()).to.be.true;105 });106107 itWeb3('ERC721Burnable support', async ({web3}) => {108 expect(await contract(web3).methods.supportsInterface('0x42966c68').call()).to.be.true;109 });110111 itWeb3('ERC165 support', async ({web3}) => {112 expect(await contract(web3).methods.supportsInterface('0x01ffc9a7').call()).to.be.true;113 });114});