difftreelog
test make eth tests pass
in: master
5 files changed
tests/src/eth/allowlist.test.tsdiffbeforeafterboth--- a/tests/src/eth/allowlist.test.ts
+++ b/tests/src/eth/allowlist.test.ts
@@ -1,6 +1,5 @@
import { expect } from 'chai';
import waitNewBlocks from '../substrate/wait-new-blocks';
-import { setContractSponsoringRateLimitExpectFailure } from '../util/helpers';
import { contractHelpers, createEthAccount, createEthAccountWithBalance, deployFlipper, itWeb3, usingWeb3Http } from './util/helpers';
describe('EVM allowlist', () => {
tests/src/eth/fungible.test.tsdiffbeforeafterboth--- a/tests/src/eth/fungible.test.ts
+++ b/tests/src/eth/fungible.test.ts
@@ -9,7 +9,7 @@
import fungibleAbi from './fungibleAbi.json';
import { expect } from 'chai';
-describe('Information getting', () => {
+describe('Fungible: Information getting', () => {
itWeb3('totalSupply', async ({ api, web3 }) => {
const collection = await createCollectionExpectSuccess({
name: 'token name',
@@ -22,8 +22,8 @@
await createFungibleItemExpectSuccess(alice, collection, { Value: 200n }, { substrate: alice.address });
const address = collectionIdToAddress(collection);
- const contract = new web3.eth.Contract(fungibleAbi as any, address);
- const totalSupply = await contract.methods.totalSupply().call({ from: caller, ...GAS_ARGS });
+ const contract = new web3.eth.Contract(fungibleAbi as any, address, {from: caller, ...GAS_ARGS});
+ const totalSupply = await contract.methods.totalSupply().call();
// FIXME: always equals to 0, because this method is not implemented
expect(totalSupply).to.equal('0');
@@ -41,14 +41,14 @@
await createFungibleItemExpectSuccess(alice, collection, { Value: 200n }, { ethereum: caller });
const address = collectionIdToAddress(collection);
- const contract = new web3.eth.Contract(fungibleAbi as any, address);
- const balance = await contract.methods.balanceOf(caller).call({ from: caller, ...GAS_ARGS });
+ const contract = new web3.eth.Contract(fungibleAbi as any, address, {from: caller, ...GAS_ARGS});
+ const balance = await contract.methods.balanceOf(caller).call();
expect(balance).to.equal('200');
});
});
-describe('Plain calls', () => {
+describe('Fungible: Plain calls', () => {
itWeb3('Can perform approve()', async ({ web3, api }) => {
const collection = await createCollectionExpectSuccess({
name: 'token name',
@@ -192,7 +192,7 @@
});
});
-describe('Substrate calls', () => {
+describe('Fungible: Substrate calls', () => {
itWeb3('Events emitted for approve()', async ({ web3 }) => {
const collection = await createCollectionExpectSuccess({
mode: { type: 'Fungible', decimalPoints: 0 },
tests/src/eth/metadata.test.tsdiffbeforeafterboth--- a/tests/src/eth/metadata.test.ts
+++ b/tests/src/eth/metadata.test.ts
@@ -4,9 +4,8 @@
//
import { expect } from 'chai';
-import privateKey from '../substrate/privateKey';
import { createCollectionExpectSuccess } from '../util/helpers';
-import { collectionIdToAddress, createEthAccount, itWeb3, transferBalanceToEth } from './util/helpers';
+import { collectionIdToAddress, createEthAccountWithBalance, GAS_ARGS, itWeb3 } from './util/helpers';
import fungibleMetadataAbi from './fungibleMetadataAbi.json';
describe('Common metadata', () => {
@@ -15,12 +14,11 @@
name: 'token name',
mode: { type: 'NFT' },
});
- const caller = createEthAccount(web3);
- await transferBalanceToEth(api, privateKey('//Alice'), caller, 999999);
+ const caller = await createEthAccountWithBalance(api, web3);
const address = collectionIdToAddress(collection);
- const contract = new web3.eth.Contract(fungibleMetadataAbi as any, address);
- const name = await contract.methods.name().call({ from: caller });
+ const contract = new web3.eth.Contract(fungibleMetadataAbi as any, address, { from: caller, ...GAS_ARGS });
+ const name = await contract.methods.name().call();
expect(name).to.equal('token name');
});
@@ -30,12 +28,11 @@
tokenPrefix: 'TOK',
mode: { type: 'NFT' },
});
- const caller = createEthAccount(web3);
- await transferBalanceToEth(api, privateKey('//Alice'), caller, 999999);
+ const caller = await createEthAccountWithBalance(api, web3);
const address = collectionIdToAddress(collection);
- const contract = new web3.eth.Contract(fungibleMetadataAbi as any, address);
- const symbol = await contract.methods.symbol().call({ from: caller });
+ const contract = new web3.eth.Contract(fungibleMetadataAbi as any, address, { from: caller, ...GAS_ARGS });
+ const symbol = await contract.methods.symbol().call();
expect(symbol).to.equal('TOK');
});
@@ -46,12 +43,11 @@
const collection = await createCollectionExpectSuccess({
mode: { type: 'Fungible', decimalPoints: 6 },
});
- const caller = createEthAccount(web3);
- await transferBalanceToEth(api, privateKey('//Alice'), caller, 999999);
+ const caller = await createEthAccountWithBalance(api, web3);
const address = collectionIdToAddress(collection);
- const contract = new web3.eth.Contract(fungibleMetadataAbi as any, address);
- const decimals = await contract.methods.decimals().call({ from: caller });
+ const contract = new web3.eth.Contract(fungibleMetadataAbi as any, address, { from: caller, ...GAS_ARGS });
+ const decimals = await contract.methods.decimals().call();
expect(+decimals).to.equal(6);
});
tests/src/eth/nonFungible.test.tsdiffbeforeafterboth1//2// This file is subject to the terms and conditions defined in3// file 'LICENSE', which is part of this source code package.4//56import privateKey from '../substrate/privateKey';7import { approveExpectSuccess, createCollectionExpectSuccess, createItemExpectSuccess, transferExpectSuccess, transferFromExpectSuccess } from '../util/helpers';8import { collectionIdToAddress, createEthAccount, itWeb3, normalizeEvents, recordEvents, subToEth, transferBalanceToEth } from './util/helpers';9import nonFungibleAbi from './nonFungibleAbi.json';10import { expect } from 'chai';1112describe('Information getting', () => {13 itWeb3('totalSupply', async ({ web3 }) => {14 const collection = await createCollectionExpectSuccess({15 mode: { type: 'NFT' },16 });17 const alice = privateKey('//Alice');1819 await createItemExpectSuccess(alice, collection, 'NFT', { substrate: alice.address });2021 const address = collectionIdToAddress(collection);22 const contract = new web3.eth.Contract(nonFungibleAbi as any, address);23 const totalSupply = await contract.methods.totalSupply().call();2425 // FIXME: always equals to 0, because this method is not implemented26 expect(totalSupply).to.equal('0');27 });2829 itWeb3('balanceOf', async ({ web3 }) => {30 const collection = await createCollectionExpectSuccess({31 mode: { type: 'NFT' },32 });33 const alice = privateKey('//Alice');3435 const caller = createEthAccount(web3);36 await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: caller });37 await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: caller });38 await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: caller });3940 const address = collectionIdToAddress(collection);41 const contract = new web3.eth.Contract(nonFungibleAbi as any, address);42 const balance = await contract.methods.balanceOf(caller).call();4344 expect(balance).to.equal('3');45 });4647 itWeb3('ownerOf', async ({ web3 }) => {48 const collection = await createCollectionExpectSuccess({49 mode: { type: 'NFT' },50 });51 const alice = privateKey('//Alice');5253 const caller = createEthAccount(web3);54 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: caller });5556 const address = collectionIdToAddress(collection);57 const contract = new web3.eth.Contract(nonFungibleAbi as any, address);58 const owner = await contract.methods.ownerOf(tokenId).call();5960 expect(owner).to.equal(caller);61 });62});6364describe('Plain calls', () => {65 itWeb3('Can perform approve()', async ({ web3, api }) => {66 const collection = await createCollectionExpectSuccess({67 mode: { type: 'NFT' },68 });69 const alice = privateKey('//Alice');7071 const owner = createEthAccount(web3);72 await transferBalanceToEth(api, alice, owner, 999999999999999);7374 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: owner });7576 const spender = createEthAccount(web3);7778 const address = collectionIdToAddress(collection);79 const contract = new web3.eth.Contract(nonFungibleAbi as any, address);8081 {82 const result = await contract.methods.approve(spender, tokenId).send({ from: owner, gas: '0x1000000', gasPrice: '0x01' });83 const events = normalizeEvents(result.events);8485 expect(events).to.be.deep.equal([86 {87 address,88 event: 'Approval',89 args: {90 owner,91 approved: spender,92 tokenId: tokenId.toString(),93 },94 },95 ]);96 }97 });9899 itWeb3('Can perform transferFrom()', async ({ web3, api }) => {100 const collection = await createCollectionExpectSuccess({101 mode: { type: 'NFT' },102 });103 const alice = privateKey('//Alice');104105 const owner = createEthAccount(web3);106 await transferBalanceToEth(api, alice, owner, 999999999999999);107108 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: owner });109110 const spender = createEthAccount(web3);111 await transferBalanceToEth(api, alice, spender, 999999999999999);112113 const receiver = createEthAccount(web3);114115 const address = collectionIdToAddress(collection);116 const contract = new web3.eth.Contract(nonFungibleAbi as any, address);117118 await contract.methods.approve(spender, tokenId).send({ from: owner, gas: '0x1000000', gasPrice: '0x01' });119120 {121 const result = await contract.methods.transferFrom(owner, receiver, tokenId).send({ from: spender, gas: '0x1000000', gasPrice: '0x01' });122 const events = normalizeEvents(result.events);123 expect(events).to.be.deep.equal([124 {125 address,126 event: 'Transfer',127 args: {128 from: owner,129 to: receiver,130 tokenId: tokenId.toString(),131 },132 },133 ]);134 }135136 {137 const balance = await contract.methods.balanceOf(receiver).call();138 expect(+balance).to.equal(1);139 }140141 {142 const balance = await contract.methods.balanceOf(owner).call();143 expect(+balance).to.equal(0);144 }145 });146147 itWeb3('Can perform transfer()', async ({ web3, api }) => {148 const collection = await createCollectionExpectSuccess({149 mode: { type: 'NFT' },150 });151 const alice = privateKey('//Alice');152153 const owner = createEthAccount(web3);154 await transferBalanceToEth(api, alice, owner, 999999999999999);155156 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: owner });157158 const receiver = createEthAccount(web3);159 await transferBalanceToEth(api, alice, receiver, 999999999999999);160161 const address = collectionIdToAddress(collection);162 const contract = new web3.eth.Contract(nonFungibleAbi as any, address);163164 {165 const result = await contract.methods.transfer(receiver, tokenId).send({ from: owner, gas: '0x1000000', gasPrice: '0x01' });166 console.log(result);167 const events = normalizeEvents(result.events);168 expect(events).to.be.deep.equal([169 {170 address,171 event: 'Transfer',172 args: {173 from: owner,174 to: receiver,175 tokenId: tokenId.toString(),176 },177 },178 ]);179 }180181 {182 const balance = await contract.methods.balanceOf(owner).call();183 expect(+balance).to.equal(0);184 }185186 {187 const balance = await contract.methods.balanceOf(receiver).call();188 expect(+balance).to.equal(1);189 }190 });191});192193describe('Substrate calls', () => {194 itWeb3('Events emitted for approve()', async ({ web3 }) => {195 const collection = await createCollectionExpectSuccess({196 mode: { type: 'NFT' },197 });198 const alice = privateKey('//Alice');199200 const receiver = createEthAccount(web3);201202 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT');203204 const address = collectionIdToAddress(collection);205 const contract = new web3.eth.Contract(nonFungibleAbi as any, address);206207 const events = await recordEvents(contract, async () => {208 await approveExpectSuccess(collection, tokenId, alice, { ethereum: receiver }, 1);209 });210211 expect(events).to.be.deep.equal([212 {213 address,214 event: 'Approval',215 args: {216 owner: subToEth(alice.address),217 approved: receiver,218 tokenId: tokenId.toString(),219 },220 },221 ]);222 });223224 itWeb3('Events emitted for transferFrom()', async ({ web3 }) => {225 const collection = await createCollectionExpectSuccess({226 mode: { type: 'NFT' },227 });228 const alice = privateKey('//Alice');229 const bob = privateKey('//Bob');230231 const receiver = createEthAccount(web3);232233 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT');234 await approveExpectSuccess(collection, tokenId, alice, bob, 1);235236 const address = collectionIdToAddress(collection);237 const contract = new web3.eth.Contract(nonFungibleAbi as any, address);238239 const events = await recordEvents(contract, async () => {240 await transferFromExpectSuccess(collection, tokenId, bob, alice, { ethereum: receiver }, 1, 'NFT');241 });242243 expect(events).to.be.deep.equal([244 {245 address,246 event: 'Transfer',247 args: {248 from: subToEth(alice.address),249 to: receiver,250 tokenId: tokenId.toString(),251 },252 },253 ]);254 });255256 itWeb3('Events emitted for transfer()', async ({ web3 }) => {257 const collection = await createCollectionExpectSuccess({258 mode: { type: 'NFT' },259 });260 const alice = privateKey('//Alice');261262 const receiver = createEthAccount(web3);263264 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT');265266 const address = collectionIdToAddress(collection);267 const contract = new web3.eth.Contract(nonFungibleAbi as any, address);268269 const events = await recordEvents(contract, async () => {270 await transferExpectSuccess(collection, tokenId, alice, { ethereum: receiver }, 1, 'NFT');271 });272273 expect(events).to.be.deep.equal([274 {275 address,276 event: 'Transfer',277 args: {278 from: subToEth(alice.address),279 to: receiver,280 tokenId: tokenId.toString(),281 },282 },283 ]);284 });285});1//2// This file is subject to the terms and conditions defined in3// file 'LICENSE', which is part of this source code package.4//56import privateKey from '../substrate/privateKey';7import { approveExpectSuccess, createCollectionExpectSuccess, createItemExpectSuccess, transferExpectSuccess, transferFromExpectSuccess } from '../util/helpers';8import { collectionIdToAddress, createEthAccount, createEthAccountWithBalance, GAS_ARGS, itWeb3, normalizeEvents, recordEvents, subToEth, transferBalanceToEth } from './util/helpers';9import nonFungibleAbi from './nonFungibleAbi.json';10import { expect } from 'chai';11import waitNewBlocks from '../substrate/wait-new-blocks';1213describe('NFT: Information getting', () => {14 itWeb3('totalSupply', async ({ api, web3 }) => {15 const collection = await createCollectionExpectSuccess({16 mode: { type: 'NFT' },17 });18 const alice = privateKey('//Alice');19 const caller = await createEthAccountWithBalance(api, web3);2021 await createItemExpectSuccess(alice, collection, 'NFT', { substrate: alice.address });2223 const address = collectionIdToAddress(collection);24 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});25 const totalSupply = await contract.methods.totalSupply().call();2627 // FIXME: always equals to 0, because this method is not implemented28 expect(totalSupply).to.equal('0');29 });3031 itWeb3('balanceOf', async ({ api, web3 }) => {32 const collection = await createCollectionExpectSuccess({33 mode: { type: 'NFT' },34 });35 const alice = privateKey('//Alice');3637 const caller = await createEthAccountWithBalance(api, web3);38 await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: caller });39 await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: caller });40 await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: caller });4142 const address = collectionIdToAddress(collection);43 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});44 const balance = await contract.methods.balanceOf(caller).call();4546 expect(balance).to.equal('3');47 });4849 itWeb3('ownerOf', async ({ api, web3 }) => {50 const collection = await createCollectionExpectSuccess({51 mode: { type: 'NFT' },52 });53 const alice = privateKey('//Alice');5455 const caller = await createEthAccountWithBalance(api, web3);56 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: caller });5758 const address = collectionIdToAddress(collection);59 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});60 const owner = await contract.methods.ownerOf(tokenId).call();6162 expect(owner).to.equal(caller);63 });64});6566describe('NFT: Plain calls', () => {67 itWeb3('Can perform approve()', async ({ web3, api }) => {68 const collection = await createCollectionExpectSuccess({69 mode: { type: 'NFT' },70 });71 const alice = privateKey('//Alice');7273 const owner = createEthAccount(web3);74 await transferBalanceToEth(api, alice, owner, 999999999999999);7576 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: owner });7778 const spender = createEthAccount(web3);7980 const address = collectionIdToAddress(collection);81 const contract = new web3.eth.Contract(nonFungibleAbi as any, address);8283 {84 const result = await contract.methods.approve(spender, tokenId).send({ from: owner, gas: '0x1000000', gasPrice: '0x01' });85 const events = normalizeEvents(result.events);8687 expect(events).to.be.deep.equal([88 {89 address,90 event: 'Approval',91 args: {92 owner,93 approved: spender,94 tokenId: tokenId.toString(),95 },96 },97 ]);98 }99 });100101 itWeb3('Can perform transferFrom()', async ({ web3, api }) => {102 const collection = await createCollectionExpectSuccess({103 mode: { type: 'NFT' },104 });105 const alice = privateKey('//Alice');106107 const owner = createEthAccount(web3);108 await transferBalanceToEth(api, alice, owner, 999999999999999);109110 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: owner });111112 const spender = createEthAccount(web3);113 await transferBalanceToEth(api, alice, spender, 999999999999999);114115 const receiver = createEthAccount(web3);116117 const address = collectionIdToAddress(collection);118 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: owner, ...GAS_ARGS});119120 await contract.methods.approve(spender, tokenId).send({ from: owner });121122 {123 const result = await contract.methods.transferFrom(owner, receiver, tokenId).send({ from: spender });124 const events = normalizeEvents(result.events);125 expect(events).to.be.deep.equal([126 {127 address,128 event: 'Transfer',129 args: {130 from: owner,131 to: receiver,132 tokenId: tokenId.toString(),133 },134 },135 ]);136 }137138 {139 const balance = await contract.methods.balanceOf(receiver).call();140 expect(+balance).to.equal(1);141 }142143 {144 const balance = await contract.methods.balanceOf(owner).call();145 expect(+balance).to.equal(0);146 }147 });148149 itWeb3('Can perform transfer()', async ({ web3, api }) => {150 const collection = await createCollectionExpectSuccess({151 mode: { type: 'NFT' },152 });153 const alice = privateKey('//Alice');154155 const owner = createEthAccount(web3);156 await transferBalanceToEth(api, alice, owner, 999999999999999);157158 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: owner });159160 const receiver = createEthAccount(web3);161 await transferBalanceToEth(api, alice, receiver, 999999999999999);162163 const address = collectionIdToAddress(collection);164 const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: owner, ...GAS_ARGS});165166 {167 const result = await contract.methods.transfer(receiver, tokenId).send({ from: owner });168 await waitNewBlocks(api, 1);169 const events = normalizeEvents(result.events);170 expect(events).to.be.deep.equal([171 {172 address,173 event: 'Transfer',174 args: {175 from: owner,176 to: receiver,177 tokenId: tokenId.toString(),178 },179 },180 ]);181 }182183 {184 const balance = await contract.methods.balanceOf(owner).call();185 expect(+balance).to.equal(0);186 }187188 {189 const balance = await contract.methods.balanceOf(receiver).call();190 expect(+balance).to.equal(1);191 }192 });193});194195describe('NFT: Substrate calls', () => {196 itWeb3('Events emitted for approve()', async ({ web3 }) => {197 const collection = await createCollectionExpectSuccess({198 mode: { type: 'NFT' },199 });200 const alice = privateKey('//Alice');201202 const receiver = createEthAccount(web3);203204 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT');205206 const address = collectionIdToAddress(collection);207 const contract = new web3.eth.Contract(nonFungibleAbi as any, address);208209 const events = await recordEvents(contract, async () => {210 await approveExpectSuccess(collection, tokenId, alice, { ethereum: receiver }, 1);211 });212213 expect(events).to.be.deep.equal([214 {215 address,216 event: 'Approval',217 args: {218 owner: subToEth(alice.address),219 approved: receiver,220 tokenId: tokenId.toString(),221 },222 },223 ]);224 });225226 itWeb3('Events emitted for transferFrom()', async ({ web3 }) => {227 const collection = await createCollectionExpectSuccess({228 mode: { type: 'NFT' },229 });230 const alice = privateKey('//Alice');231 const bob = privateKey('//Bob');232233 const receiver = createEthAccount(web3);234235 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT');236 await approveExpectSuccess(collection, tokenId, alice, bob, 1);237238 const address = collectionIdToAddress(collection);239 const contract = new web3.eth.Contract(nonFungibleAbi as any, address);240241 const events = await recordEvents(contract, async () => {242 await transferFromExpectSuccess(collection, tokenId, bob, alice, { ethereum: receiver }, 1, 'NFT');243 });244245 expect(events).to.be.deep.equal([246 {247 address,248 event: 'Transfer',249 args: {250 from: subToEth(alice.address),251 to: receiver,252 tokenId: tokenId.toString(),253 },254 },255 ]);256 });257258 itWeb3('Events emitted for transfer()', async ({ web3 }) => {259 const collection = await createCollectionExpectSuccess({260 mode: { type: 'NFT' },261 });262 const alice = privateKey('//Alice');263264 const receiver = createEthAccount(web3);265266 const tokenId = await createItemExpectSuccess(alice, collection, 'NFT');267268 const address = collectionIdToAddress(collection);269 const contract = new web3.eth.Contract(nonFungibleAbi as any, address);270271 const events = await recordEvents(contract, async () => {272 await transferExpectSuccess(collection, tokenId, alice, { ethereum: receiver }, 1, 'NFT');273 });274275 expect(events).to.be.deep.equal([276 {277 address,278 event: 'Transfer',279 args: {280 from: subToEth(alice.address),281 to: receiver,282 tokenId: tokenId.toString(),283 },284 },285 ]);286 });287});tests/src/substrate/substrate-api.tsdiffbeforeafterboth--- a/tests/src/substrate/substrate-api.ts
+++ b/tests/src/substrate/substrate-api.ts
@@ -37,6 +37,10 @@
const consoleWarn = console.warn;
const outFn = (message: string) => {
+ if (typeof message !== 'string') {
+ consoleErr(message);
+ return;
+ }
if (!message.includes('StorageChangeSet:: WebSocket is not connected') &&
!message.includes('2021-') &&
!message.includes('StorageChangeSet:: Normal connection closure'))