1234567891011121314151617import {18 ethBalanceViaSub,19 GAS_ARGS,20 recordEthFee,21} from './util/helpers';22import {Contract} from 'web3-eth-contract';2324import {IKeyringPair} from '@polkadot/types/types';25import {EthUniqueHelper, itEth, usingEthPlaygrounds, expect} from './util/playgrounds';26import {UNIQUE} from '../util/helpers';2728describe('Contract calls', () => {29 let donor: IKeyringPair;3031 before(async function() {32 await usingEthPlaygrounds(async (_helper, privateKey) => {33 donor = privateKey('//Alice');34 });35 });3637 itEth('Call of simple contract fee is less than 0.2 UNQ', async ({helper}) => {38 const deployer = await helper.eth.createAccountWithBalance(donor);39 const flipper = await helper.eth.deployFlipper(deployer);4041 const cost = await recordEthFee(helper.api!, deployer, () => flipper.methods.flip().send({from: deployer}));42 expect(cost < BigInt(0.2 * Number(UNIQUE))).to.be.true;43 });4445 itEth('Balance transfer fee is less than 0.2 UNQ', async ({helper}) => {46 const userA = await helper.eth.createAccountWithBalance(donor);47 const userB = helper.eth.createAccount();48 const cost = await recordEthFee(helper.api!, userA, () => helper.web3!.eth.sendTransaction({from: userA, to: userB, value: '1000000', ...GAS_ARGS}));49 const balanceB = await ethBalanceViaSub(helper.api!, userB);50 expect(cost - balanceB < BigInt(0.2 * Number(UNIQUE))).to.be.true;51 });5253 itEth('NFT transfer is close to 0.15 UNQ', async ({helper}) => {54 const caller = await helper.eth.createAccountWithBalance(donor);55 const receiver = helper.eth.createAccount();5657 const [alice] = await helper.arrange.createAccounts([10n], donor);58 const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});59 const {tokenId} = await collection.mintToken(alice, {Ethereum: caller});6061 const address = helper.ethAddress.fromCollectionId(collection.collectionId);62 const contract = helper.ethNativeContract.collection(address, 'nft', caller);6364 const cost = await recordEthFee(helper.api!, caller, () => contract.methods.transfer(receiver, tokenId).send(caller));6566 const fee = Number(cost) / Number(UNIQUE);67 const expectedFee = 0.15;68 const tolerance = 0.001;6970 expect(Math.abs(fee - expectedFee)).to.be.lessThan(tolerance);71 });72});7374describe('ERC165 tests', async () => {75 7677 let collection: number;78 let minter: string;7980 function contract(helper: EthUniqueHelper): Contract {81 return helper.ethNativeContract.collection(helper.ethAddress.fromCollectionId(collection), 'nft', minter);82 }8384 before(async () => {85 await usingEthPlaygrounds(async (helper, privateKey) => {86 const donor = privateKey('//Alice');87 const [alice] = await helper.arrange.createAccounts([10n], donor);88 ({collectionId: collection} = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'}));89 minter = helper.eth.createAccount();90 });91 });9293 itEth('interfaceID == 0xffffffff always false', async ({helper}) => {94 expect(await contract(helper).methods.supportsInterface('0xffffffff').call()).to.be.false;95 });9697 itEth('ERC721 support', async ({helper}) => {98 expect(await contract(helper).methods.supportsInterface('0x780e9d63').call()).to.be.true;99 });100101 itEth('ERC721Metadata support', async ({helper}) => {102 expect(await contract(helper).methods.supportsInterface('0x5b5e139f').call()).to.be.true;103 });104105 itEth('ERC721Mintable support', async ({helper}) => {106 expect(await contract(helper).methods.supportsInterface('0x68ccfe89').call()).to.be.true;107 });108109 itEth('ERC721Enumerable support', async ({helper}) => {110 expect(await contract(helper).methods.supportsInterface('0x780e9d63').call()).to.be.true;111 });112113 itEth('ERC721UniqueExtensions support', async ({helper}) => {114 expect(await contract(helper).methods.supportsInterface('0xd74d154f').call()).to.be.true;115 });116117 itEth('ERC721Burnable support', async ({helper}) => {118 expect(await contract(helper).methods.supportsInterface('0x42966c68').call()).to.be.true;119 });120121 itEth('ERC165 support', async ({helper}) => {122 expect(await contract(helper).methods.supportsInterface('0x01ffc9a7').call()).to.be.true;123 });124});