1234567891011121314151617import {Contract} from 'web3-eth-contract';1819import {IKeyringPair} from '@polkadot/types/types';20import {EthUniqueHelper, itEth, usingEthPlaygrounds, expect} from './util/playgrounds';212223describe('Contract calls', () => {24 let donor: IKeyringPair;2526 before(async function() {27 await usingEthPlaygrounds(async (_helper, privateKey) => {28 donor = privateKey('//Alice');29 });30 });3132 itEth('Call of simple contract fee is less than 0.2 UNQ', async ({helper}) => {33 const deployer = await helper.eth.createAccountWithBalance(donor);34 const flipper = await helper.eth.deployFlipper(deployer);3536 const cost = await helper.eth.calculateFee({Ethereum: deployer}, () => flipper.methods.flip().send({from: deployer}));37 expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal()))).to.be.true;38 });3940 itEth('Balance transfer fee is less than 0.2 UNQ', async ({helper}) => {41 const userA = await helper.eth.createAccountWithBalance(donor);42 const userB = helper.eth.createAccount();43 const cost = await helper.eth.calculateFee({Ethereum: userA}, () => helper.getWeb3().eth.sendTransaction({from: userA, to: userB, value: '1000000', gas: helper.eth.DEFAULT_GAS}));44 const balanceB = await helper.balance.getEthereum(userB);45 expect(cost - balanceB < BigInt(0.2 * Number(helper.balance.getOneTokenNominal()))).to.be.true;46 });4748 itEth('NFT transfer is close to 0.15 UNQ', async ({helper}) => {49 const caller = await helper.eth.createAccountWithBalance(donor);50 const receiver = helper.eth.createAccount();5152 const [alice] = await helper.arrange.createAccounts([10n], donor);53 const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});54 const {tokenId} = await collection.mintToken(alice, {Ethereum: caller});5556 const address = helper.ethAddress.fromCollectionId(collection.collectionId);57 const contract = helper.ethNativeContract.collection(address, 'nft', caller);5859 const cost = await helper.eth.calculateFee({Ethereum: caller}, () => contract.methods.transfer(receiver, tokenId).send(caller));6061 const fee = Number(cost) / Number(helper.balance.getOneTokenNominal());62 const expectedFee = 0.15;63 const tolerance = 0.001;6465 expect(Math.abs(fee - expectedFee)).to.be.lessThan(tolerance);66 });67});6869describe('ERC165 tests', async () => {70 7172 let collection: number;73 let minter: string;7475 function contract(helper: EthUniqueHelper): Contract {76 return helper.ethNativeContract.collection(helper.ethAddress.fromCollectionId(collection), 'nft', minter);77 }7879 before(async () => {80 await usingEthPlaygrounds(async (helper, privateKey) => {81 const donor = privateKey('//Alice');82 const [alice] = await helper.arrange.createAccounts([10n], donor);83 ({collectionId: collection} = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'}));84 minter = helper.eth.createAccount();85 });86 });8788 itEth('interfaceID == 0xffffffff always false', async ({helper}) => {89 expect(await contract(helper).methods.supportsInterface('0xffffffff').call()).to.be.false;90 });9192 itEth('ERC721 support', async ({helper}) => {93 expect(await contract(helper).methods.supportsInterface('0x780e9d63').call()).to.be.true;94 });9596 itEth('ERC721Metadata support', async ({helper}) => {97 expect(await contract(helper).methods.supportsInterface('0x5b5e139f').call()).to.be.true;98 });99100 itEth('ERC721Mintable support', async ({helper}) => {101 expect(await contract(helper).methods.supportsInterface('0x68ccfe89').call()).to.be.true;102 });103104 itEth('ERC721Enumerable support', async ({helper}) => {105 expect(await contract(helper).methods.supportsInterface('0x780e9d63').call()).to.be.true;106 });107108 itEth('ERC721UniqueExtensions support', async ({helper}) => {109 expect(await contract(helper).methods.supportsInterface('0xd74d154f').call()).to.be.true;110 });111112 itEth('ERC721Burnable support', async ({helper}) => {113 expect(await contract(helper).methods.supportsInterface('0x42966c68').call()).to.be.true;114 });115116 itEth('ERC165 support', async ({helper}) => {117 expect(await contract(helper).methods.supportsInterface('0x01ffc9a7').call()).to.be.true;118 });119});