new: testcases
MODIFY
src/hermez/bridge.ts
src/hermez/bridge.ts
@@ -85,6 +85,16 @@ export class Bridge extends BaseToken<IHermezClientConfig> {
});
}
+ claimNullifier(
+ index: number,
+ ) {
+ return this.method(
+ "claimNullifier", index
+ ).then(method => {
+ return this.processRead<string>(method);
+ });
+ }
+
precalculatedWrapperAddress(
originNetwork: number,
originTokenAddress: string

MODIFY
src/hermez/erc20.ts
src/hermez/erc20.ts
@@ -23,6 +23,17 @@ export class ERC20 extends HermezToken {
}, client, getContracts);
}
+ /**
+ * get bridge for that token
+ *
+ * @returns
+ * @memberof ERC20
+ */
+ getBridgeAddress() {
+ const bridge = this.contractParam.isParent ? this.parentBridge : this.childBridge;
+ return bridge.contractAddress;
+ }
+
/**
* get token balance of user
*

MODIFY
src/hermez/index.ts
src/hermez/index.ts
@@ -46,6 +46,15 @@ export class HermezClient extends HermezBridgeClient<IHermezClientConfig> {
});
}
+ /**
+ * creates instance of ERC20 token
+ *
+ * @param {string} tokenAddress
+ * @param {boolean} isParent
+ *
+ * @returns
+ * @memberof ERC20
+ */
erc20(tokenAddress: string, isParent?: boolean) {
return new ERC20(
tokenAddress,

MODIFY
src/utils/hermez_bridge_client.ts
src/utils/hermez_bridge_client.ts
@@ -43,4 +43,34 @@ export class HermezBridgeClient<T> {
});
}
+ /**
+ * check whether deposit is completed
+ *
+ * @param {string} txHash
+ * @returns
+ * @memberof HermezBridgeClient
+ */
+ isDeposited(txHash: string) {
+ return this.bridgeUtil.getBridgeLogData(
+ txHash, true
+ ).then(result => {
+ return this.childChainBridge.claimNullifier(result.depositCount);
+ });
+ }
+
+ /**
+ * check whether deposit is completed
+ *
+ * @param {string} txHash
+ * @returns
+ * @memberof HermezBridgeClient
+ */
+ isExited(txHash: string) {
+ return this.bridgeUtil.getBridgeLogData(
+ txHash, false
+ ).then(result => {
+ return this.rootChainBridge.claimNullifier(result.depositCount);
+ });
+ }
+
}

MODIFY
test/.env.example
test/.env.example
@@ -2,5 +2,6 @@ USER1_PRIVATE_KEY =
USER1_FROM =
USER2_FROM =
USER2_PRIVATE_KEY =
-ROOT_RPC =
+GOERLI_ROOT_RPC=
MATIC_RPC=
+HERMEZ_RPC=

MODIFY
test/config.js
test/config.js
@@ -5,9 +5,15 @@ dotenv.config({
});
module.exports = {
rpc: {
- parent: process.env.ROOT_RPC,
+ hermez: {
+ parent: process.env.GOERLI_ROOT_RPC,
child: process.env.MATIC_RPC || 'https://rpc-mumbai.matic.today',
},
+ pos: {
+ parent: process.env.GOERLI_ROOT_RPC,
+ child: process.env.HERMEZ_RPC || 'https://rpc.public.zkevm-test.net',
+ },
+ },
pos: {
parent: {
erc20: '0x3f152b63ec5ca5831061b2dccfb29a874c317502',
@@ -31,13 +37,14 @@ module.exports = {
// erc20: '0xb4fbf271143f4fbf7b91a5ded31805e42b2208d6', // WETH
// erc20: '0x5C221E77624690fff6dd741493D735a17716c26B' // DAI
// erc20: '0x27b4861cf36453b9478cd5416426ca6fbd06f67a', // DAI TEMP
- erc20: '0xe7e7ad60b75614829be79a3014c5c6aeb006e079', // UNI TEMP
- // erc20: '0x4701Aa9471d7bfAc765D87dcb1Ea6BB23AD32733' // Polygon
+ // erc20: '0xe7e7ad60b75614829be79a3014c5c6aeb006e079', // UNI TEMP
+ erc20: '0x4701Aa9471d7bfAc765D87dcb1Ea6BB23AD32733' // Polygon
},
child: {
ether: '0x0000000000000000000000000000000000000000',
// erc20: '0x270969e59d170fB576cBB5E254493e9bfB13684f', // WETH
- erc20: '0x08bd5b6d0237FaAED3C5E04fB131de2f843aC756' // DAI
+ // erc20: '0x08bd5b6d0237FaAED3C5E04fB131de2f843aC756', // DAI
+ erc20: '0x73DeceDCa3d3aD2fFdB7FD5afd819a11dbc297f5' // Polygon
},
},
user1: {

MODIFY
test/debug.js
test/debug.js
@@ -28,13 +28,13 @@ const execute = async () => {
network: 'testnet',
version: 'mumbai',
parent: {
- provider: new HDWalletProvider(privateKey, rpc.parent),
+ provider: new HDWalletProvider(privateKey, rpc.pos.parent),
defaultConfig: {
from
}
},
child: {
- provider: new HDWalletProvider(privateKey, rpc.child),
+ provider: new HDWalletProvider(privateKey, rpc.pos.child),
defaultConfig: {
from
}
@@ -159,13 +159,13 @@ const executeHermez = async () => {
network: 'testnet',
version: 'mumbai',
parent: {
- provider: new HDWalletProvider(privateKey, rpc.parent),
+ provider: new HDWalletProvider(privateKey, rpc.hermez.parent),
defaultConfig: {
from
}
},
child: {
- provider: new HDWalletProvider(privateKey, rpc.child),
+ provider: new HDWalletProvider(privateKey, rpc.hermez.child),
defaultConfig: {
from
}
@@ -185,12 +185,20 @@ const executeHermez = async () => {
// var result = await client.isDepositClaimable('0x6c8d9bb18c6d01f75a4900f0e46ed4179c04f96bfce1e8286313ab659c59cade');
// return console.log('result', result);
+ // // isDeposited
+ // var result = await client.isDeposited('0x6c8d9bb18c6d01f75a4900f0e46ed4179c04f96bfce1e8286313ab659c59cade');
+ // return console.log('result', result);
+
// // isWithdrawExitable
// var result = await client.isWithdrawExitable('0xc3567e692b7f2ad1f3da019c97c6b01483330f5b2cb022ae0d8fdccd4d1c0d60');
// return console.log('result', result);
+ // // isExited
+ // var result = await client.isExited('0xc3567e692b7f2ad1f3da019c97c6b01483330f5b2cb022ae0d8fdccd4d1c0d60');
+ // return console.log('result', result);
+
// // getTokenWrappedAddress
- // var result = await client.childChainBridge.getTokenWrappedAddress("0", "0x5C221E77624690fff6dd741493D735a17716c26B");
+ // var result = await client.childChainBridge.getTokenWrappedAddress("0", '0x4701Aa9471d7bfAc765D87dcb1Ea6BB23AD32733');
// return console.log('result', result);
// // wrappedTokenToTokenInfo
@@ -214,44 +222,44 @@ const executeHermez = async () => {
// return console.log('result', result);
// // approve
- // var tx = await goerliERC20Token.approve("22000000000000000000", {returnTransaction: false});
+ // var tx = await goerliERC20Token.approve("10", {returnTransaction: false});
// return console.log("hash", await tx.getTransactionHash());
// // deposit Ether
- // var tx = await goerliEtherToken.deposit("220000000000", from, {returnTransaction: false});
- // return console.log("hash", await tx.getTransactionHash());
+ // var tx = await goerliEtherToken.deposit("220000000000", from, {returnTransaction: true});
+ // return console.log("hash", tx);
// // claim Ether
// var tx = await litchiEtherToken.depositClaim("0xd2019abfdb978346cfc886525752b3d8a5798b8c474a46a8d18ed9b293bd5862", {returnTransaction: false});
// return console.log("hash", await tx.getTransactionHash());
// // deposit ERC20
- // var tx = await goerliERC20Token.deposit("220000000000", from, {returnTransaction: false});
- // return console.log("hash", await tx.getTransactionHash());
+ // var tx = await goerliERC20Token.deposit("10", from, {returnTransaction: true});
+ // return console.log("hash", tx);
// // deposit claim ERC20
- // var tx = await litchiERC20Token.depositClaim("0x81594c5e9a73e195c6fb13db1b25e9388407611ad4649b01f61d85c27eb86049", {returnTransaction: false});
+ // var tx = await litchiERC20Token.depositClaim("0x080b05623d70c2858cb1fc64fd76cd04bde52a0a344d3cb896d33833ef221b12", {returnTransaction: false});
// return console.log("hash", await tx.getTransactionHash());
// // withdraw Ether
- // var tx = await litchiEtherToken.withdraw("22000000000", from, {returnTransaction: false});
- // return console.log("hash", await tx.getTransactionHash());
+ // var tx = await litchiEtherToken.withdraw("1", from, {returnTransaction: true});
+ // return console.log("hash", tx);
// // withdraw ERC20
- // var tx = await litchiERC20Token.withdraw("22000000000", from, {returnTransaction: false});
- // return console.log("hash", await tx.getTransactionHash());
+ // var tx = await litchiERC20Token.withdraw("1", from, {returnTransaction: true});
+ // return console.log("hash", tx);
// // Get Permit Data
// var tx = await goerliERC20Token.getPermitData('2000000000000000000', {returnTransaction: false});
// return console.log("hash", tx);
- // deposit with Permit
- var tx = await goerliERC20Token.depositWithPermit("2000000000000000000", from, {returnTransaction: false});
- return console.log("hash", await tx.getTransactionHash());
+ // // deposit with Permit
+ // var tx = await goerliERC20Token.depositWithPermit("10", from, {returnTransaction: true});
+ // return console.log("hash", tx);
// // withdraw exit ERC20
- // var tx = await goerliERC20Token.withdrawExit("0xc3567e692b7f2ad1f3da019c97c6b01483330f5b2cb022ae0d8fdccd4d1c0d60", {returnTransaction: false});
- // return console.log("hash", await tx.getTransactionHash());
+ // var tx = await goerliERC20Token.withdrawExit("0x2df7caedb9a28b3110a43d5380c19d8f7d3a177aad4c8c11a07cbc46ce377654", {returnTransaction: true});
+ // return console.log("hash", tx);
// console.log("hash", await tx.getTransactionHash());

ADD
test/specs/hermez/client.ts
+import { HermezClient } from "@maticnetwork/maticjs";
+import { user1, rpc, hermez, user2 } from "../../config";
+
+export const privateKey = user1.privateKey;
+export const from = user1.address;
+export const to = user2.address;
+export const toPrivateKey = user2.privateKey;
+
+export const RPC = rpc.hermez;
+
+export const erc20 = {
+ parent: hermez.parent.erc20,
+ child: hermez.child.erc20
+}
+
+export const ether = {
+ parent: hermez.parent.ether,
+ child: hermez.child.ether
+}
+
+export const hermezClient = new HermezClient();
+
+export const hermezClientForTo = new HermezClient();
\ No newline at end of file

ADD
test/specs/hermez/erc20.spec.ts
+import { erc20, ether, from, hermezClient, hermezClientForTo, to } from "./client";
+import { expect } from 'chai'
+import { ABIManager } from '@maticnetwork/maticjs'
+import BN from "bn.js";
+
+
+describe('ERC20', () => {
+
+ let erc20Child = hermezClient.erc20(erc20.child);
+ let erc20Parent = hermezClient.erc20(erc20.parent, true);
+
+ let etherChild = hermezClient.erc20(ether.child);
+ let etherParent = hermezClient.erc20(ether.parent, true);
+
+ const abiManager = new ABIManager("testnet", "mumbai");
+ before(() => {
+ return Promise.all([
+ abiManager.init()
+ ]);
+ });
+
+ // BALANCE
+ it('get erc20 balance child', async () => {
+ console.log('process.env.NODE_ENV', process.env.NODE_ENV, hermezClient.client);
+
+ const balance = await erc20Child.getBalance(from);
+ console.log('balance', balance);
+ expect(balance).to.be.an('string');
+ expect(Number(balance)).gte(0);
+ })
+
+ it('get erc20 balance parent', async () => {
+ const balance = await erc20Parent.getBalance(from);
+ console.log('balance', balance);
+ expect(balance).to.be.an('string');
+ expect(Number(balance)).gte(0);
+ })
+
+ it('get ether balance child', async () => {
+ console.log('process.env.NODE_ENV', process.env.NODE_ENV, hermezClient.client);
+
+ const balance = await etherChild.getBalance(from);
+ console.log('balance', balance);
+ expect(balance).to.be.an('string');
+ expect(Number(balance)).gte(0);
+ })
+
+ it('get ether balance parent', async () => {
+ const balance = await etherParent.getBalance(from);
+ console.log('balance', balance);
+ expect(balance).to.be.an('string');
+ expect(Number(balance)).gte(0);
+ })
+
+ // ALLOWANCE
+ it('get allowance parent', async () => {
+ const allowance = await erc20Parent.getAllowance(from);
+ expect(allowance).to.be.an('string');
+ expect(Number(allowance)).gte(0);
+ })
+
+ it('get allowance child', async () => {
+ const allowance = await erc20Child.getAllowance(from);
+ expect(allowance).to.be.an('string');
+ expect(Number(allowance)).gte(0);
+ })
+
+ // IS DEPOSIT CLAIMABLE
+ it('is Deposit Claimable', async () => {
+ const isDepositClaimable = await hermezClient.isDepositClaimable('0x81594c5e9a73e195c6fb13db1b25e9388407611ad4649b01f61d85c27eb86049');
+ expect(isDepositClaimable).to.be.an('boolean').equal(true);
+ })
+
+ // IS WITHDRAW EXITABLE
+ it('is Withdraw Exitable', async () => {
+ const isWithdrawExitable = await hermezClient.isWithdrawExitable('0xd2019abfdb978346cfc886525752b3d8a5798b8c474a46a8d18ed9b293bd5862');
+ expect(isWithdrawExitable).to.be.an('boolean').equal(true);
+ })
+
+ // IS DEPOSITED
+ it('is Deposited', async () => {
+ const isDeposited = await hermezClient.isDeposited('0x81594c5e9a73e195c6fb13db1b25e9388407611ad4649b01f61d85c27eb86049');
+ expect(isDeposited).to.be.an('boolean').equal(true);
+ })
+
+ // IS EXITED
+ it('is Exited', async () => {
+ const isExited = await hermezClient.isExited('0x81594c5e9a73e195c6fb13db1b25e9388407611ad4649b01f61d85c27eb86049');
+ expect(isExited).to.be.an('boolean').equal(true);
+ })
+
+ // TRANSFER
+ it('child transfer returnTransaction with eip1159', async () => {
+ const amount = 10;
+ try {
+ const result = await erc20Child.transfer(amount, to, {
+ maxFeePerGas: 10,
+ maxPriorityFeePerGas: 10,
+ returnTransaction: true
+ });
+ console.log('result', result);
+ } catch (error) {
+ console.log('error', error);
+ expect(error).deep.equal({
+ message: `Child chain doesn't support eip-1559`,
+ type: 'eip-1559_not_supported'
+ })
+ }
+ });
+
+ it('child transfer returnTransaction', async () => {
+ const amount = 10;
+ const result = await erc20Child.transfer(amount, to, {
+ returnTransaction: true
+ });
+ expect(result).to.have.not.property('maxFeePerGas')
+ expect(result).to.have.not.property('maxPriorityFeePerGas')
+ // expect(result).to.have.property('gasPrice')
+ // expect(result['gasPrice']).to.be.an('number').gt(0);
+ expect(result).to.have.property('chainId', 1402);
+ expect(result['chainId']).to.be.an('number');
+ });
+
+ it('parent transfer returnTransaction with eip1159', async () => {
+ const amount = 10;
+ const result = await erc20Parent.transfer(amount, to, {
+ maxFeePerGas: 20,
+ maxPriorityFeePerGas: 20,
+ returnTransaction: true
+ });
+
+ expect(result).to.have.property('maxFeePerGas', 20)
+ expect(result).to.have.property('maxPriorityFeePerGas', 20)
+ expect(result).to.have.not.property('gasPrice')
+ expect(result).to.have.property('chainId', 5);
+
+ });
+
+ // APPROVE
+ it('approve parent return tx', async () => {
+ const result = await erc20Parent.approve('10', {
+ returnTransaction: true
+ });
+
+ expect(result['to'].toLowerCase()).equal(erc20.parent.toLowerCase());
+ expect(result).to.have.property('data')
+ });
+
+ it('approve parent return tx with spender address', async () => {
+ const spenderAddress = await erc20Parent.getBridgeAddress();
+ const result = await erc20Parent.approve('10', {
+ spenderAddress: spenderAddress,
+ returnTransaction: true
+ });
+
+ expect(result['to'].toLowerCase()).equal(erc20.parent.toLowerCase());
+ expect(result).to.have.property('data')
+ });
+
+ it('approve child return tx without spender address', async () => {
+ try {
+ const result = await erc20Child.approve('10');
+ expect(result['to'].toLowerCase()).equal(erc20.child.toLowerCase());
+ expect(result).to.have.property('data');
+ } catch (error) {
+ // console.log('error', error);
+ expect(error).eql({
+ type: 'null_spender_address',
+ message: 'Please provide spender address.'
+ });
+ }
+ });
+
+ // PERMIT
+ it('permit data', async () => {
+ const result = await etherParent.getPermitData(10, {
+ returnTransaction: true
+ });
+ expect(result).to.be.an('string');
+ });
+
+ // DEPOSIT
+ it('deposit ether return tx', async () => {
+ const result = await etherParent.deposit(10, from, {
+ returnTransaction: true
+ });
+
+ const bridge = await abiManager.getConfig("Main.zkEVMContracts.BridgeProxy")
+ expect(result['to'].toLowerCase()).equal(bridge.toLowerCase());
+ expect(Number(result['value'])).eq(10);
+ expect(result).to.have.property('data');
+ });
+
+ it('deposit erc20 return tx', async () => {
+ const result = await erc20Parent.deposit(10, from, {
+ returnTransaction: true
+ });
+
+ const bridge = await abiManager.getConfig("Main.zkEVMContracts.BridgeProxy")
+ expect(result['to'].toLowerCase()).equal(bridge.toLowerCase());
+ expect(result).to.have.property('data');
+ });
+
+ it('deposit erc20 with permit return tx', async () => {
+ const result = await erc20Parent.depositWithPermit(10, from, {
+ returnTransaction: true
+ });
+
+ const bridge = await abiManager.getConfig("Main.zkEVMContracts.BridgeProxy")
+ expect(result['to'].toLowerCase()).equal(bridge.toLowerCase());
+ expect(result).to.have.property('data');
+ });
+
+ it('claim erc20 deposit return tx', async () => {
+ const result = await erc20Parent.depositClaim('0x067ed611aa63d607186dcc0d70a7b60dd909c6d91b40842f424a6dadeae21f22', {
+ returnTransaction: true
+ });
+
+ const bridge = await abiManager.getConfig("zkEVM.Contracts.BridgeProxy")
+ expect(result['to'].toLowerCase()).equal(bridge.toLowerCase());
+ expect(result).to.have.property('data');
+ });
+
+ // WITHDRAW
+ it('erc20 withdraw return tx', async () => {
+ const result = await erc20Child.withdraw('1', from, {
+ returnTransaction: true
+ });
+
+ const bridge = await abiManager.getConfig("zkEVM.Contracts.BridgeProxy")
+ expect(result['to'].toLowerCase()).equal(bridge.toLowerCase());
+ expect(result).to.have.property('data');
+ });
+
+ it('ether withdraw return tx', async () => {
+ const result = await etherChild.withdraw('1', from, {
+ returnTransaction: true
+ });
+
+ const bridge = await abiManager.getConfig("zkEVM.Contracts.BridgeProxy")
+ expect(result['to'].toLowerCase()).equal(bridge.toLowerCase());
+ expect(Number(result['value'])).eq(1);
+ expect(result).to.have.property('data');
+ });
+
+ const exitData = '0x5d5d326f00000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000000000000000000000e743776c4840a5af4773755062ff5b9e62b10dd39321f79d155e23dd79f32d614ea5b17e7fada5feb5c19abf5c4640da7aa6b1405d659a006de6c80933d1c56340d000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000fd71dc9721d9ddcf0480a582927c3dcd42f3064c0000000000000000000000000000000000000000000000000003328b944c400000000000000000000000000000000000000000000000000000000000000005600000000000000000000000000000000000000000000000000000000000000020a9f6b096519e017de4c8a3a12a04caff69de9caea872f5b13573ec4e62708fae650a16dd2d88d2a69bad071376c3a772bb5c2eeb28ee418cd0c2dc089f22829b194d824c3e9f530ff9cca5bd960fa8c38d47355d9981edf0207a42481f5c81c45376b4374fffaf8381debd36d3c90fa219da8acf08afd5c38e2a533e5e916aa371bc83920b28517b7ca955286812be1f825bb8ff9090ab59155fa57bee6e46f5014f13d30c5e670b9a058620b408fb76edebc23617a6af6564c6faa64c01326942db0146f1789b447120e68d5164d2303ffe048c5e41e40382d9d636e58b4eb89027c513740da9a58058e64a2e25e7d74d0ad9a74a37a05c2328eb7c8c4fbd1a9867cc5f7f196b93bae1e27e6320742445d290f2263827498b54fec539f756af75ac602f9900a53be23ebc6d94231c54c8486cab2f81fe37c5c3d2154b1a039ca2eea7b16f992ac60284cc78197e7b1f345359b35f29a051e321fad14f41e9be3b7355ca5a10f560b36f8089d64dc69b7ecbba4103ae4e0b5894a622b8873a253490c6ceeb450aecdc82e28293031d10c7d73bf85e57bf041a97360aa2c5d99cc1df82d9c4b87413eae2ef048f94b4d3554cea73d92b0f7af96e0271c691e2bb5c67add7c6caf302256adedf7ab114da0acfe870d449a3a489f781d659e8beccda7bce9f4e8618b6bd2f4132ce798cdc7a60e7e1460a7299e3c6342a579626d22733e50f526ec2fa19a22b31e8ed50f23cd1fdf94c9154ed3a7609a2f1ff981fe1d3b5c807b281e4683cc6d6315cf95b9ade8641defcb32372f1c126e398ef7a5a2dce0a8a7f68bb74560f8f71837c2c2ebbcbf7fffb42ae1896f13f7c7479a0b46a28b6f55540f89444f63de0378e3d121be09e06cc9ded1c20e65876d36aa0c65e9645644786b620e2dd2ad648ddfcbf4a7e5b1a3a4ecfe7f64667a3f0b7e2f4418588ed35a2458cffeb39b93d26f18d2ab13bdce6aee58e7b99359ec2dfd95a9c16dc00d6ef18b7933a6f8dc65ccb55667138776f7dea101070dc8796e3774df84f40ae0c8229d0d6069e5c8f39a7c299677a09d367fc7b05e3bc380ee652cdc72595f74c7b1043d0e1ffbab734648c838dfb0527d971b602bc216c9619ef0abf5ac974a1ed57f4050aa510dd9c74f508277b39d7973bb2dfccc5eeb0618db8cd74046ff337f0a7bf2c8e03e10f642c1886798d71806ab1e888d9e5ee87d0838c5655cb21c6cb83313b5a631175dff4963772cce9108188b34ac87c81c41e662ee4dd2dd7b2bc707961b1e646c4047669dcb6584f0d8d770daf5d7e7deb2e388ab20e2573d171a88108e79d820e98f26c0b84aa8b2f4aa4968dbb818ea32293237c50ba75ee485f4c22adf2f741400bdf8d6a9cc7df7ecae576221665d7358448818bb4ae4562849e949e17ac16e0be16688e156b5cf15e098c627c0056a90000000000000000000000000000000000000000000000000000000000000000'
+ it('exit return tx', async () => {
+ const result = await erc20Child.withdrawExit('0x2df7caedb9a28b3110a43d5380c19d8f7d3a177aad4c8c11a07cbc46ce377654', {
+ returnTransaction: true
+ });
+ expect(result['data']).equal(
+ exitData
+ );
+ const bridge = await abiManager.getConfig("Main.zkEVMContracts.BridgeProxy")
+ expect(result['to'].toLowerCase()).equal(bridge.toLowerCase());
+ expect(result).to.have.property('data');
+ });
+
+ // CHILD TRANSFER FLOW
+ it('child transfer', async () => {
+ const oldBalance = await erc20Child.getBalance(to);
+ console.log('oldBalance', oldBalance);
+ const amount = 9;
+ let result = await erc20Child.transfer(amount, to);
+ let txHash = await result.getTransactionHash();
+ expect(txHash).to.be.an('string');
+ // console.log('txHash', txHash);
+ let txReceipt = await result.getReceipt();
+ // console.log("txReceipt", txReceipt);
+
+ expect(txReceipt.transactionHash).equal(txHash);
+ expect(txReceipt).to.be.an('object');
+ expect(txReceipt.from.toLowerCase()).equal(from.toLowerCase());
+ expect(txReceipt.to.toLowerCase()).equal(erc20.child.toLowerCase());
+ expect(txReceipt.type).equal(2);
+ expect(txReceipt.gasUsed).to.be.an('number').gt(0);
+ expect(txReceipt.cumulativeGasUsed).to.be.an('number').gt(0);
+
+ expect(txReceipt).to.have.property('blockHash')
+ expect(txReceipt).to.have.property('blockNumber');
+ expect(txReceipt).to.have.property('events');
+ // expect(txReceipt).to.have.property('logs');
+ expect(txReceipt).to.have.property('logsBloom');
+ expect(txReceipt).to.have.property('status');
+ expect(txReceipt).to.have.property('transactionIndex');
+
+ const newBalance = await erc20Child.getBalance(to);
+ console.log('newBalance', newBalance);
+
+ const oldBalanceBig = new BN(oldBalance);
+ const newBalanceBig = new BN(newBalance);
+
+ expect(newBalanceBig.toString()).equal(
+ oldBalanceBig.add(new BN(amount)).toString()
+ )
+
+ //transfer money back to user
+ const erc20ChildToken = hermezClientForTo.erc20(erc20.child);
+
+ result = await erc20ChildToken.transfer(amount, to);
+ txHash = await result.getTransactionHash();
+ txReceipt = await result.getReceipt();
+ });
+
+ if (process.env.NODE_ENV !== 'test_all') return;
+
+ // APPROVE FLOW
+ 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(2);
+
+ const allowance = await erc20Parent.getAllowance(from);
+ expect(allowance).to.be.an('string');
+ expect(Number(allowance)).eq(10);
+ });
+
+ // DEPOSIT FLOW
+ it('deposit', async () => {
+ const spenderAddress = await erc20Parent.getBridgeAddress();
+
+ const oldBalanceforUser = await erc20Child.getBalance(from);
+ console.log('oldBalanceforUser', oldBalanceforUser);
+
+ const oldBalanceforBridge = await erc20Child.getBalance(spenderAddress);
+ console.log('oldBalanceforBridge', oldBalanceforBridge);
+
+ 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');
+
+ const newBalanceforUser = await erc20Child.getBalance(from);
+ console.log('newBalanceforUser', newBalanceforUser);
+
+ const newBalanceforBridge = await erc20Child.getBalance(spenderAddress);
+ console.log('newBalanceforBridge', newBalanceforBridge);
+
+ expect(oldBalanceforUser.toString()).equal(
+ new BN(newBalanceforUser).add(new BN(10)).toString()
+ )
+
+ expect(newBalanceforBridge.toString()).equal(
+ new BN(oldBalanceforBridge).add(new BN(10)).toString()
+ )
+ });
+
+});

MODIFY
test/specs/index.ts
test/specs/index.ts
@@ -5,9 +5,13 @@ use(Web3ClientPlugin);
console.log('process.env.NODE_ENV', process.env.NODE_ENV);
-
import './map_promise.spec'
-import './pos_client.spec'
-import './erc20.spec'
-import './erc721.spec'
-import './erc1155.spec'
+
+// HERMEZ
+import './hermez/erc20.spec'
+
+// PoS
+// import './pos/pos_client.spec'
+// import './pos/erc20.spec'
+// import './pos/erc721.spec'
+// import './pos/erc1155.spec'

RENAME
test/specs/client.ts
test/specs/pos/client.ts
import { POSClient } from "@maticnetwork/maticjs";
-import { user1, rpc, pos, user2 } from "../config";
+import { user1, rpc, pos, user2 } from "../../config";
export const privateKey = user1.privateKey;
export const from = user1.address;
export const to = user2.address;
export const toPrivateKey = user2.privateKey;
-export const RPC = rpc;
+export const RPC = rpc.pos;
export const erc20 = {
parent: pos.parent.erc20,

RENAME
test/specs/erc1155.spec.ts
test/specs/pos/erc1155.spec.ts
RENAME
test/specs/erc20.spec.ts
test/specs/pos/erc20.spec.ts
RENAME
test/specs/erc721.spec.ts
test/specs/pos/erc721.spec.ts
RENAME
test/specs/pos_client.spec.ts
test/specs/pos/pos_client.spec.ts
new: testcases