difftreelog
eth/base migrated
in: master
1 file changed
tests/src/eth/base.test.tsdiffbeforeafterboth15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.161617import {17import {18 collectionIdToAddress,19 createEthAccount,20 createEthAccountWithBalance,21 deployFlipper,22 ethBalanceViaSub,18 ethBalanceViaSub,23 GAS_ARGS,19 GAS_ARGS,24 itWeb3,25 recordEthFee,20 recordEthFee,26 usingWeb3,27} from './util/helpers';21} from './util/helpers';28import {expect} from 'chai';22import {Contract} from 'web3-eth-contract';2329import {createCollectionExpectSuccess, createItemExpectSuccess, UNIQUE} from '../util/helpers';24import {IKeyringPair} from '@polkadot/types/types';30import nonFungibleAbi from './nonFungibleAbi.json';25import {EthUniqueHelper, itEth, usingEthPlaygrounds, expect} from './util/playgrounds';31import {Contract} from 'web3-eth-contract';26import {UNIQUE} from '../util/helpers';32import Web3 from 'web3';332734describe('Contract calls', () => {28describe('Contract calls', () => {29 let donor: IKeyringPair;3031 before(async function() {32 await usingEthPlaygrounds(async (_helper, privateKey) => {33 donor = privateKey('//Alice');34 });35 });3635 itWeb3('Call of simple contract fee is less than 0.2 UNQ', async ({web3, api, privateKeyWrapper}) => {37 itEth('Call of simple contract fee is less than 0.2 UNQ', async ({helper}) => {36 const deployer = await createEthAccountWithBalance(api, web3, privateKeyWrapper);38 const deployer = await helper.eth.createAccountWithBalance(donor);37 const flipper = await deployFlipper(web3, deployer);39 const flipper = await helper.eth.deployFlipper(deployer);384039 const cost = await recordEthFee(api, deployer, () => flipper.methods.flip().send({from: deployer}));41 const cost = await recordEthFee(helper.api!, deployer, () => flipper.methods.flip().send({from: deployer}));40 expect(cost < BigInt(0.2 * Number(UNIQUE))).to.be.true;42 expect(cost < BigInt(0.2 * Number(UNIQUE))).to.be.true;41 });43 });424443 itWeb3('Balance transfer fee is less than 0.2 UNQ', async ({web3, api, privateKeyWrapper}) => {45 itEth('Balance transfer fee is less than 0.2 UNQ', async ({helper}) => {44 const userA = await createEthAccountWithBalance(api, web3, privateKeyWrapper);46 const userA = await helper.eth.createAccountWithBalance(donor);45 const userB = createEthAccount(web3);47 const userB = helper.eth.createAccount();4647 const cost = await recordEthFee(api, userA, () => web3.eth.sendTransaction({from: userA, to: userB, value: '1000000', ...GAS_ARGS}));48 const cost = await recordEthFee(helper.api!, userA, () => helper.web3!.eth.sendTransaction({from: userA, to: userB, value: '1000000', ...GAS_ARGS}));48 const balanceB = await ethBalanceViaSub(api, userB);49 const balanceB = await ethBalanceViaSub(helper.api!, userB);49 expect(cost - balanceB < BigInt(0.2 * Number(UNIQUE))).to.be.true;50 expect(cost - balanceB < BigInt(0.2 * Number(UNIQUE))).to.be.true;50 });51 });515252 itWeb3('NFT transfer is close to 0.15 UNQ', async ({web3, api, privateKeyWrapper}) => {53 itEth('NFT transfer is close to 0.15 UNQ', async ({helper}) => {53 const caller = await createEthAccountWithBalance(api, web3, privateKeyWrapper);54 const caller = await helper.eth.createAccountWithBalance(donor);54 const receiver = createEthAccount(web3);55 const receiver = helper.eth.createAccount();555656 const alice = privateKeyWrapper('//Alice');57 const [alice] = await helper.arrange.createAccounts([10n], donor);57 const collection = await createCollectionExpectSuccess({58 const collection = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'});58 mode: {type: 'NFT'},59 });60 const itemId = await createItemExpectSuccess(alice, collection, 'NFT', {Ethereum: caller});59 const {tokenId} = await collection.mintToken(alice, {Ethereum: caller});616062 const address = collectionIdToAddress(collection);61 const address = helper.ethAddress.fromCollectionId(collection.collectionId);63 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});62 const contract = helper.ethNativeContract.collection(address, 'nft', caller);646365 const cost = await recordEthFee(api, caller, () => contract.methods.transfer(receiver, itemId).send(caller));64 const cost = await recordEthFee(helper.api!, caller, () => contract.methods.transfer(receiver, tokenId).send(caller));666567 const fee = Number(cost) / Number(UNIQUE);66 const fee = Number(cost) / Number(UNIQUE);68 const expectedFee = 0.15;67 const expectedFee = 0.15;78 let collection: number;77 let collection: number;79 let minter: string;78 let minter: string;807981 function contract(web3: Web3): Contract {80 function contract(helper: EthUniqueHelper): Contract {82 return new web3.eth.Contract(nonFungibleAbi as any, collectionIdToAddress(collection), {from: minter, ...GAS_ARGS});81 return helper.ethNativeContract.collection(helper.ethAddress.fromCollectionId(collection), 'nft', minter);83 }82 }848385 before(async () => {84 before(async () => {86 await usingWeb3 (async (web3) => {85 await usingEthPlaygrounds(async (helper, privateKey) => {86 const donor = privateKey('//Alice');87 const [alice] = await helper.arrange.createAccounts([10n], donor);87 collection = await createCollectionExpectSuccess();88 ({collectionId: collection} = await helper.nft.mintCollection(alice, {name: 'test', description: 'test', tokenPrefix: 'test'}));88 minter = createEthAccount(web3);89 minter = helper.eth.createAccount();89 });90 });90 });91 });919292 itWeb3('interfaceID == 0xffffffff always false', async ({web3}) => {93 itEth('interfaceID == 0xffffffff always false', async ({helper}) => {93 expect(await contract(web3).methods.supportsInterface('0xffffffff').call()).to.be.false;94 expect(await contract(helper).methods.supportsInterface('0xffffffff').call()).to.be.false;94 });95 });959696 itWeb3('ERC721 support', async ({web3}) => {97 itEth('ERC721 support', async ({helper}) => {97 expect(await contract(web3).methods.supportsInterface('0x780e9d63').call()).to.be.true;98 expect(await contract(helper).methods.supportsInterface('0x780e9d63').call()).to.be.true;98 });99 });99100100 itWeb3('ERC721Metadata support', async ({web3}) => {101 itEth('ERC721Metadata support', async ({helper}) => {101 expect(await contract(web3).methods.supportsInterface('0x5b5e139f').call()).to.be.true;102 expect(await contract(helper).methods.supportsInterface('0x5b5e139f').call()).to.be.true;102 });103 });103104104 itWeb3('ERC721Mintable support', async ({web3}) => {105 itEth('ERC721Mintable support', async ({helper}) => {105 expect(await contract(web3).methods.supportsInterface('0x68ccfe89').call()).to.be.true;106 expect(await contract(helper).methods.supportsInterface('0x68ccfe89').call()).to.be.true;106 });107 });107108108 itWeb3('ERC721Enumerable support', async ({web3}) => {109 itEth('ERC721Enumerable support', async ({helper}) => {109 expect(await contract(web3).methods.supportsInterface('0x780e9d63').call()).to.be.true;110 expect(await contract(helper).methods.supportsInterface('0x780e9d63').call()).to.be.true;110 });111 });111112112 itWeb3('ERC721UniqueExtensions support', async ({web3}) => {113 itEth('ERC721UniqueExtensions support', async ({helper}) => {113 expect(await contract(web3).methods.supportsInterface('0xd74d154f').call()).to.be.true;114 expect(await contract(helper).methods.supportsInterface('0xd74d154f').call()).to.be.true;114 });115 });115116116 itWeb3('ERC721Burnable support', async ({web3}) => {117 itEth('ERC721Burnable support', async ({helper}) => {117 expect(await contract(web3).methods.supportsInterface('0x42966c68').call()).to.be.true;118 expect(await contract(helper).methods.supportsInterface('0x42966c68').call()).to.be.true;118 });119 });119120120 itWeb3('ERC165 support', async ({web3}) => {121 itEth('ERC165 support', async ({helper}) => {121 expect(await contract(web3).methods.supportsInterface('0x01ffc9a7').call()).to.be.true;122 expect(await contract(helper).methods.supportsInterface('0x01ffc9a7').call()).to.be.true;122 });123 });123});124});124125