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 expect(cost - await ethBalanceViaSub(api, userB) < BigInt(0.2 * Number(UNIQUE))).to.be.true;40 });4142 itWeb3('NFT transfer is close to 0.15 UNQ', async ({web3, api}) => {43 const caller = await createEthAccountWithBalance(api, web3);44 const receiver = createEthAccount(web3);4546 const alice = privateKey('//Alice');47 const collection = await createCollectionExpectSuccess({48 mode: {type: 'NFT'},49 });50 const itemId = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: caller});5152 const address = collectionIdToAddress(collection);53 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});5455 const cost = await recordEthFee(api, caller, () => contract.methods.transfer(receiver, itemId).send(caller));5657 const fee = Number(cost) / Number(UNIQUE);58 const expectedFee = 0.15;59 const tolerance = 0.00002;6061 expect(Math.abs(fee - expectedFee)).to.be.lessThan(tolerance);62 });63});6465describe('ERC165 tests', async () => {66 6768 let collection: number;69 let minter: string;7071 function contract(web3: Web3): Contract {72 return new web3.eth.Contract(nonFungibleAbi as any, collectionIdToAddress(collection), {from: minter, ...GAS_ARGS});73 }7475 before(async () => {76 await usingWeb3 (async (web3) => {77 collection = await createCollectionExpectSuccess();78 minter = createEthAccount(web3);79 });80 });81 82 itWeb3('interfaceID == 0xffffffff always false', async ({web3}) => {83 expect(await contract(web3).methods.supportsInterface('0xffffffff').call()).to.be.false;84 });8586 itWeb3('ERC721 support', async ({web3}) => {87 expect(await contract(web3).methods.supportsInterface('0x58800161').call()).to.be.true;88 });8990 itWeb3('ERC721Metadata support', async ({web3}) => {91 expect(await contract(web3).methods.supportsInterface('0x5b5e139f').call()).to.be.true;92 });9394 itWeb3('ERC721Mintable support', async ({web3}) => {95 expect(await contract(web3).methods.supportsInterface('0x68ccfe89').call()).to.be.true;96 });9798 itWeb3('ERC721Enumerable support', async ({web3}) => {99 expect(await contract(web3).methods.supportsInterface('0x780e9d63').call()).to.be.true;100 });101102 itWeb3('ERC721UniqueExtensions support', async ({web3}) => {103 expect(await contract(web3).methods.supportsInterface('0xe562194d').call()).to.be.true;104 });105106 itWeb3('ERC721Burnable support', async ({web3}) => {107 expect(await contract(web3).methods.supportsInterface('0x42966c68').call()).to.be.true;108 });109110 itWeb3('ERC165 support', async ({web3}) => {111 expect(await contract(web3).methods.supportsInterface('0x01ffc9a7').call()).to.be.true;112 });113});