git.delta.rocks / unique-network / refs/commits / 723337089349

difftreelog

test fix tests for updated frontier

Yaroslav Bolyukin2021-07-27parent: #7168c55.patch.diff
in: master

3 files changed

modifiedtests/src/eth/fungible.test.tsdiffbeforeafterboth
55
6import 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';
1111
12describe('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');
1919
20 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 });
2123
22 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 });
2527
26 // FIXME: always equals to 0, because this method is not implemented28 // FIXME: always equals to 0, because this method is not implemented
27 expect(totalSupply).to.equal('0');29 expect(totalSupply).to.equal('0');
28 });30 });
2931
30 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');
3638
37 const caller = createEthAccount(web3);39 const caller = await createEthAccountWithBalance(api, web3);
40
38 await createFungibleItemExpectSuccess(alice, collection, { Value: 200n }, { ethereum: caller });41 await createFungibleItemExpectSuccess(alice, collection, { Value: 200n }, { ethereum: caller });
3942
40 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 });
4346
44 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');
5558
56 const owner = createEthAccount(web3);59 const owner = await createEthAccountWithBalance(api, web3);
57 await transferBalanceToEth(api, alice, owner, 999999999999999);
5860
59 await createFungibleItemExpectSuccess(alice, collection, { Value: 200n }, { ethereum: owner });61 await createFungibleItemExpectSuccess(alice, collection, { Value: 200n }, { ethereum: owner });
6062
61 const spender = createEthAccount(web3);63 const spender = createEthAccount(web3);
6264
63 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});
6567
66 {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);
6971
70 expect(events).to.be.deep.equal([72 expect(events).to.be.deep.equal([
104 const receiver = createEthAccount(web3);106 const receiver = createEthAccount(web3);
105107
106 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});
108110
109 await contract.methods.approve(spender, 100).send({ from: owner, gas: '0x1000000', gasPrice: '0x01' });111 await contract.methods.approve(spender, 100).send();
110112
111 {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);
161163
162 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});
164166
165 {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 {
modifiedtests/src/eth/nonFungible.test.tsdiffbeforeafterboth
61 });61 });
62});62});
6363
64describe.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' },
modifiedtests/src/eth/util/helpers.tsdiffbeforeafterboth
16 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;
1818
19 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);
2121
22 try {22 try {
45 return account.address;45 return account.address;
46}46}
47
48export async function createEthAccountWithBalance(api: ApiPromise, web3: Web3) {
49 const alice = privateKey('//Alice');
50 const account = createEthAccount(web3);
51 await transferBalanceToEth(api, alice, account);
52
53 return account;
54}
4755
48export 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);