add test for erc20 deposit, approve, transfer
MODIFY
src/helpers/contract_write_result.ts
src/helpers/contract_write_result.ts
@@ -2,7 +2,7 @@ import { ITransactionWriteResult, ITransactionReceipt } from "../interfaces";
export class ContractWriteResult {
private txHashPromise: Promise<string>;
- private receiptPromise: Promise<string>;
+ private receiptPromise: Promise<ITransactionReceipt>;
constructor(result: ITransactionWriteResult) {
this.txHashPromise = new Promise((res, rej) => {

MODIFY
test/config.js
test/config.js
@@ -23,10 +23,10 @@ module.exports = {
},
},
user1: {
- "privateKey": process.env.PRIVATE_KEY,
- "address": process.env.FROM
+ "privateKey": process.env.USER1_PRIVATE_KEY,
+ "address": process.env.USER1_FROM
},
user2: {
- address: '<paste address here>', // Your address
+ address: process.env.USER2_FROM, // Your address
},
}

MODIFY
test/package.json
test/package.json
"install:lib:test": "npm run install:lib && npm run test",
"install:lib:debug": "npm run install:lib && npm run debug",
"un:lib": "npm un @maticnetwork/maticjs",
- "test": "dotenv cross-env NODE_ENV=test karma start karma.conf.js",
- "test:all": "cross-env NODE_ENV=test_all npm run test",
+ "karma:start": "dotenv karma start karma.conf.js",
+ "test": "cross-env NODE_ENV=test npm run karma:start",
+ "test:all": "cross-env NODE_ENV=test_all npm run karma:start",
"test:mocha": "cross-env-file -p ./config.json cross-env NODE_ENV=test mochapack --webpack-config ./webpack.config.test.js --colors ./specs/index.ts"
},
"author": "",

MODIFY
test/specs/client.ts
test/specs/client.ts
import { POSClient } from "@maticnetwork/maticjs";
import HDWalletProvider from "@truffle/hdwallet-provider";
-import { user1, rpc, pos } from "../config";
+import { user1, rpc, pos, user2 } from "../config";
const privateKey = user1.privateKey;
export const from = user1.address;
+export const to = user2.address;
export const erc20 = {
parent: pos.parent.erc20,
child: pos.child.erc20
@@ -14,7 +15,7 @@ export const erc721 = {
}
export const posClient = new POSClient({
- log: true,
+ // log: true,
network: 'testnet',
version: 'mumbai',
parent: {

MODIFY
test/specs/erc20.spec.ts
test/specs/erc20.spec.ts
-import { erc20, from, posClient } from "./client";
+import { erc20, from, posClient, to } from "./client";
import { expect } from 'chai'
@@ -11,7 +11,7 @@ describe('ERC20', () => {
});
it('get balance child', async () => {
- console.log('process.env.test_all', process.env.test_all);
+ console.log('process.env.NODE_ENV', process.env.NODE_ENV);
const balance = await erc20Child.getBalance(from);
console.log('balance', balance);
@@ -42,4 +42,42 @@ describe('ERC20', () => {
const isExited = await erc20Parent.isWithdrawExited('0xd6f7f4c6052611761946519076de28fbd091693af974e7d4abc1b17fd7926fd7');
expect(isExited).to.be.an('boolean').equal(true);
})
+
+ // it('isDeposited', async () => {
+ // const txHash = '0xc67599f5c967f2040786d5924ec55d37bf943c009bdd23f3b50e5ae66efde258';
+ // const isExited = await posClient.isDeposited(txHash);
+ // expect(isExited).to.be.an('boolean').equal(true);
+ // })
+
+ if (process.env.NODE_ENV === 'test_all') {
+ // it('transfer', async () => {
+ // const result = await erc20Child.transfer(to, '10');
+ // const txHash = await result.getTransactionHash();
+ // expect(txHash).to.be.an('string');
+
+ // const txReceipt = await result.getReceipt();
+ // expect(txReceipt).to.be.an('object');
+ // });
+
+ // it('approve', async () => {
+ // const result = await erc20Parent.approve('10');
+
+ // const txHash = await result.getTransactionHash();
+ // expect(txHash).to.be.an('string');
+
+ // const txReceipt = await result.getReceipt();
+ // console.log("txReceipt", txReceipt);
+ // expect(txReceipt.type).equal('0x0');
+ // });
+
+ it('deposit', async () => {
+ const result = await erc20Parent.deposit('10', from);
+
+ const txHash = await result.getTransactionHash();
+ expect(txHash).to.be.an('string');
+
+ const txReceipt = await result.getReceipt();
+ expect(txReceipt).to.be.an('object');
+ });
+ }
});
\ No newline at end of file

MODIFY
test/specs/index.ts
test/specs/index.ts
@@ -3,6 +3,9 @@ import { Web3ClientPlugin } from "@maticnetwork/maticjs-web3";
use(Web3ClientPlugin);
+console.log('process.env.NODE_ENV', process.env.NODE_ENV);
+
+
import './map_promise.spec'
import './erc20.spec'
import './erc721.spec'

MODIFY
test/webpack.config.test.js
test/webpack.config.test.js
const webpack = require('webpack')
const path = require('path')
+// return console.log('process.env', process.env.from)
+
+
module.exports = {
mode: 'development',
module: {
@@ -21,8 +24,8 @@ module.exports = {
},
plugins: [
new webpack.DefinePlugin({
- // 'process.env.NODE_ENV': "'test'"
'process.env': JSON.stringify(process.env),
+ 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV)
}),
],
devtool: 'inline-source-map',

add test for erc20 deposit, approve, transfer