difftreelog
test fix tests for updated frontier
in: master
3 files changed
tests/src/eth/fungible.test.tsdiffbeforeafterboth556import privateKey from '../substrate/privateKey';6import privateKey from '../substrate/privateKey';7import { approveExpectSuccess, createCollectionExpectSuccess, createFungibleItemExpectSuccess, transferExpectSuccess, transferFromExpectSuccess } from '../util/helpers';7import { approveExpectSuccess, createCollectionExpectSuccess, createFungibleItemExpectSuccess, transferExpectSuccess, transferFromExpectSuccess } from '../util/helpers';8import { collectionIdToAddress, createEthAccount, itWeb3, normalizeEvents, recordEvents, subToEth, transferBalanceToEth } from './util/helpers';8import { collectionIdToAddress, createEthAccount, createEthAccountWithBalance, GAS_ARGS, itWeb3, normalizeEvents, recordEvents, subToEth, transferBalanceToEth } from './util/helpers';9import fungibleAbi from './fungibleAbi.json';9import fungibleAbi from './fungibleAbi.json';10import { expect } from 'chai';10import { expect } from 'chai';111112describe('Information getting', () => {12describe('Information getting', () => {13 itWeb3('totalSupply', async ({ web3 }) => {13 itWeb3('totalSupply', async ({ api, web3 }) => {14 const collection = await createCollectionExpectSuccess({14 const collection = await createCollectionExpectSuccess({15 name: 'token name',15 name: 'token name',16 mode: { type: 'Fungible', decimalPoints: 0 },16 mode: { type: 'Fungible', decimalPoints: 0 },17 });17 });18 const alice = privateKey('//Alice');18 const alice = privateKey('//Alice');191920 const caller = await createEthAccountWithBalance(api, web3);21 20 await createFungibleItemExpectSuccess(alice, collection, { Value: 200n }, { substrate: alice.address });22 await createFungibleItemExpectSuccess(alice, collection, { Value: 200n }, { substrate: alice.address });212322 const address = collectionIdToAddress(collection);24 const address = collectionIdToAddress(collection);23 const contract = new web3.eth.Contract(fungibleAbi as any, address);25 const contract = new web3.eth.Contract(fungibleAbi as any, address);24 const totalSupply = await contract.methods.totalSupply().call();26 const totalSupply = await contract.methods.totalSupply().call({ from: caller, ...GAS_ARGS });252726 // FIXME: always equals to 0, because this method is not implemented28 // FIXME: always equals to 0, because this method is not implemented27 expect(totalSupply).to.equal('0');29 expect(totalSupply).to.equal('0');28 });30 });293130 itWeb3('balanceOf', async ({ web3 }) => {32 itWeb3('balanceOf', async ({ api, web3 }) => {31 const collection = await createCollectionExpectSuccess({33 const collection = await createCollectionExpectSuccess({32 name: 'token name',34 name: 'token name',33 mode: { type: 'Fungible', decimalPoints: 0 },35 mode: { type: 'Fungible', decimalPoints: 0 },34 });36 });35 const alice = privateKey('//Alice');37 const alice = privateKey('//Alice');363837 const caller = createEthAccount(web3);39 const caller = await createEthAccountWithBalance(api, web3);4038 await createFungibleItemExpectSuccess(alice, collection, { Value: 200n }, { ethereum: caller });41 await createFungibleItemExpectSuccess(alice, collection, { Value: 200n }, { ethereum: caller });394240 const address = collectionIdToAddress(collection);43 const address = collectionIdToAddress(collection);41 const contract = new web3.eth.Contract(fungibleAbi as any, address);44 const contract = new web3.eth.Contract(fungibleAbi as any, address);42 const balance = await contract.methods.balanceOf(caller).call();45 const balance = await contract.methods.balanceOf(caller).call({ from: caller, ...GAS_ARGS });434644 expect(balance).to.equal('200');47 expect(balance).to.equal('200');45 });48 });53 });56 });54 const alice = privateKey('//Alice');57 const alice = privateKey('//Alice');555856 const owner = createEthAccount(web3);59 const owner = await createEthAccountWithBalance(api, web3);57 await transferBalanceToEth(api, alice, owner, 999999999999999);586059 await createFungibleItemExpectSuccess(alice, collection, { Value: 200n }, { ethereum: owner });61 await createFungibleItemExpectSuccess(alice, collection, { Value: 200n }, { ethereum: owner });606261 const spender = createEthAccount(web3);63 const spender = createEthAccount(web3);626463 const address = collectionIdToAddress(collection);65 const address = collectionIdToAddress(collection);64 const contract = new web3.eth.Contract(fungibleAbi as any, address);66 const contract = new web3.eth.Contract(fungibleAbi as any, address, {from: owner, ...GAS_ARGS});656766 {68 {67 const result = await contract.methods.approve(spender, 100).send({ from: owner, gas: '0x1000000', gasPrice: '0x01' });69 const result = await contract.methods.approve(spender, 100).send({from: owner});68 const events = normalizeEvents(result.events);70 const events = normalizeEvents(result.events);697170 expect(events).to.be.deep.equal([72 expect(events).to.be.deep.equal([104 const receiver = createEthAccount(web3);106 const receiver = createEthAccount(web3);105107106 const address = collectionIdToAddress(collection);108 const address = collectionIdToAddress(collection);107 const contract = new web3.eth.Contract(fungibleAbi as any, address);109 const contract = new web3.eth.Contract(fungibleAbi as any, address, {from: owner, ...GAS_ARGS});108110109 await contract.methods.approve(spender, 100).send({ from: owner, gas: '0x1000000', gasPrice: '0x01' });111 await contract.methods.approve(spender, 100).send();110112111 {113 {112 const result = await contract.methods.transferFrom(owner, receiver, 49).send({ from: spender, gas: '0x1000000', gasPrice: '0x01' });114 const result = await contract.methods.transferFrom(owner, receiver, 49).send({from: spender});113 const events = normalizeEvents(result.events);115 const events = normalizeEvents(result.events);114 expect(events).to.be.deep.equal([116 expect(events).to.be.deep.equal([115 {117 {160 await transferBalanceToEth(api, alice, receiver, 999999999999999);162 await transferBalanceToEth(api, alice, receiver, 999999999999999);161163162 const address = collectionIdToAddress(collection);164 const address = collectionIdToAddress(collection);163 const contract = new web3.eth.Contract(fungibleAbi as any, address);165 const contract = new web3.eth.Contract(fungibleAbi as any, address, {from: owner, ...GAS_ARGS});164166165 {167 {166 const result = await contract.methods.transfer(receiver, 50).send({ from: owner, gas: '0x1000000', gasPrice: '0x01' });168 const result = await contract.methods.transfer(receiver, 50).send({ from: owner});167 const events = normalizeEvents(result.events);169 const events = normalizeEvents(result.events);168 expect(events).to.be.deep.equal([170 expect(events).to.be.deep.equal([169 {171 {tests/src/eth/nonFungible.test.tsdiffbeforeafterboth61 });61 });62});62});636364describe.only('Plain calls', () => {64describe('Plain calls', () => {65 itWeb3('Can perform approve()', async ({ web3, api }) => {65 itWeb3('Can perform approve()', async ({ web3, api }) => {66 const collection = await createCollectionExpectSuccess({66 const collection = await createCollectionExpectSuccess({67 mode: { type: 'NFT' },67 mode: { type: 'NFT' },tests/src/eth/util/helpers.tsdiffbeforeafterboth16 if (web3Connected) throw new Error('do not nest usingWeb3 calls');16 if (web3Connected) throw new Error('do not nest usingWeb3 calls');17 web3Connected = true;17 web3Connected = true;181819 const provider = new Web3.providers.WebsocketProvider('http://localhost:9944');19 const provider = new Web3.providers.WebsocketProvider(config.substrateUrl);20 const web3 = new Web3(provider);20 const web3 = new Web3(provider);212122 try {22 try {45 return account.address;45 return account.address;46}46}4748export async function createEthAccountWithBalance(api: ApiPromise, web3: Web3) {49 const alice = privateKey('//Alice');50 const account = createEthAccount(web3);51 await transferBalanceToEth(api, alice, account);5253 return account;54}475548export async function transferBalanceToEth(api: ApiPromise, source: IKeyringPair, target: string, amount: number) {56export async function transferBalanceToEth(api: ApiPromise, source: IKeyringPair, target: string, amount = 999999999999999) {49 const tx = api.tx.balances.transfer(evmToAddress(target), amount);57 const tx = api.tx.balances.transfer(evmToAddress(target), amount);50 const events = await submitTransactionAsync(source, tx);58 const events = await submitTransactionAsync(source, tx);51 const result = getGenericResult(events);59 const result = getGenericResult(events);