diff --git a/examples/.env.example b/examples/.env.example index e4df5704e..1b629a687 100644 --- a/examples/.env.example +++ b/examples/.env.example @@ -1,7 +1,7 @@ USER1_FROM=0x USER1_PRIVATE_KEY=0x USER2_FROM=0x -GOERLI_ROOT_RPC= +ROOT_RPC= MATIC_RPC= ZKEVM_RPC= PROOF_API= diff --git a/examples/config.js b/examples/config.js index 91fa3fc2a..e1e72f825 100644 --- a/examples/config.js +++ b/examples/config.js @@ -11,44 +11,35 @@ if (env.error) { module.exports = { rpc: { pos: { - parent: process.env.GOERLI_ROOT_RPC, - child: process.env.MATIC_RPC || 'https://rpc-mumbai.matic.today', + parent: process.env.ROOT_RPC || 'https://rpc.sepolia.org', + child: process.env.MATIC_RPC || 'https://rpc-amoy.polygon.technology', }, zkEvm: { - parent: process.env.GOERLI_ROOT_RPC, - child: process.env.ZKEVM_RPC || 'https://rpc.public.zkevm-test.net', + parent: process.env.ROOT_RPC || 'https://rpc.sepolia.org', + child: process.env.ZKEVM_RPC || 'https://rpc.cardona.zkevm-rpc.com', }, }, pos: { parent: { - erc20: '0x655f2166b0709cd575202630952d71e2bb0d61af', - erc721: '0x16F7EF3774c59264C46E5063b1111bCFd6e7A72f', - erc1155: '0x2e3Ef7931F2d0e4a7da3dea950FF3F19269d9063', - chainManagerAddress: '0xBbD7cBFA79faee899Eaf900F13C9065bF03B1A74', // Address of RootChainManager for POS Portal + erc20: '0xb480378044d92C96D16589Eb95986df6a97F2cFB', + erc721: '0x421DbB7B5dFCb112D7a13944DeFB80b28eC5D22C', + erc1155: '0x095DD31b6473c4a32548d2A5B09e0f2F3F30d8F1', + chainManagerAddress: '0xb991E39a401136348Dee93C75143B159FabF483f', }, child: { - erc721: '0xbD88C3A7c0e242156a46Fbdf87141Aa6D0c0c649', - erc20: '0xfe4F5145f6e09952a5ba9e956ED0C25e3Fa4c7F1', - weth: '0x714550C2C1Ea08688607D86ed8EeF4f5E4F22323', - erc1155: '0xA07e45A987F19E25176c877d98388878622623FA', + erc20: '0xf3202E7270a10E599394d8A7dA2F4Fbd475e96bA', + erc721: '0x02f83d4110D3595872481f677Ae323D50Aa09209', + erc1155: '0x488AfDFef019f511E343becb98B7c24ee02fA639', }, }, zkEvm: { parent: { - bridgeAdapter: "0x5eB6485573C2Ea289554A044e1D34b41958c0842", ether: '0x0000000000000000000000000000000000000000', - // erc20: '0xb4fbf271143f4fbf7b91a5ded31805e42b2208d6', // WETH - // erc20: '0x5C221E77624690fff6dd741493D735a17716c26B' // DAI - // erc20: '0x27b4861cf36453b9478cd5416426ca6fbd06f67a', // DAI TEMP - // erc20: '0xe7e7ad60b75614829be79a3014c5c6aeb006e079', // UNI TEMP - erc20: '0x4701Aa9471d7bfAc765D87dcb1Ea6BB23AD32733' // Polygon + erc20: '0x3fd0A53F4Bf853985a95F4Eb3F9C9FDE1F8e2b53', // MATIC }, child: { - bridgeAdapter: "0x6b0393fD45B1a95EfB1bcd93536DaB44417119C3", ether: '0x0000000000000000000000000000000000000000', - // erc20: '0x270969e59d170fB576cBB5E254493e9bfB13684f', // WETH - // erc20: '0x08bd5b6d0237FaAED3C5E04fB131de2f843aC756', // DAI - erc20: '0x73DeceDCa3d3aD2fFdB7FD5afd819a11dbc297f5' // Polygon + erc20: '0x244f21e2cDB60e9B6C9aEbB96FFe04489831F881' // MATIC }, }, SYNCER_URL: 'https://testnetv3-syncer.api.matic.network/api/v1', // Backend service which syncs the Matic sidechain state to a MySQL database which we use for faster querying. This comes in handy especially for constructing withdrawal proofs while exiting assets from Plasma. diff --git a/examples/utils_pos.js b/examples/utils_pos.js index aaabb7a98..f490176d0 100644 --- a/examples/utils_pos.js +++ b/examples/utils_pos.js @@ -14,7 +14,7 @@ if (config.proofApi) { const privateKey = config.user1.privateKey const userAddress = config.user1.address -const getPOSClient = (network = 'testnet', version = 'mumbai') => { +const getPOSClient = (network = 'testnet', version = 'amoy') => { const posClient = new POSClient() return posClient.init({ log: true, diff --git a/examples/utils_zkevm.js b/examples/utils_zkevm.js index 27f4ffbc2..f29fb8ef3 100644 --- a/examples/utils_zkevm.js +++ b/examples/utils_zkevm.js @@ -10,7 +10,7 @@ use(Web3ClientPlugin) const privateKey = config.user1.privateKey const userAddress = config.user1.address -const getZkEvmClient = (optional = {}, network = 'testnet', version = 'blueberry') => { +const getZkEvmClient = (optional = {}, network = 'testnet', version = 'cardona') => { const zkEvmClient = new ZkEvmClient() return zkEvmClient.init({ ...optional, diff --git a/package-lock.json b/package-lock.json index 2ee5af16d..248219458 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@maticnetwork/maticjs", - "version": "3.8.3-beta.2", + "version": "3.9.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@maticnetwork/maticjs", - "version": "3.8.3-beta.2", + "version": "3.9.0", "license": "MIT", "dependencies": { "@ethereumjs/block": "^3.6.2", diff --git a/package.json b/package.json index c0bbadf3e..ffd397489 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@maticnetwork/maticjs", - "version": "3.8.3-beta.2", + "version": "3.9.0", "description": "Javascript developer library for interacting with Matic Network", "main": "dist/npm.export.js", "types": "dist/ts/index.d.ts", @@ -14,7 +14,6 @@ ], "scripts": { "clean": "rimraf dist", - "build": "tsc", "build:link": "webpack && npm link", "build:dev": "webpack", "build:prod": "webpack --env build", @@ -22,10 +21,7 @@ "prepublishOnly": "npm run deploy", "lint": "tslint src/**/*.ts", "lint:fix": "tslint src/**/*.ts --fix", - "build:test": "npm run build:link && npm run test", - "test": "cd test && npm run install:lib:test", - "debug": "webpack && cd test && npm run link:lib:debug", - "testrpc": "ganache-cli --mnemonic 'clock radar mass judge dismiss just intact mind resemble fringe diary casino' --gasLimit 13000000" + "debug": "webpack && cd test && npm run link:lib:debug" }, "repository": { "type": "git", diff --git a/src/utils/index.ts b/src/utils/index.ts index 0499a455b..0de45132f 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -1,6 +1,6 @@ +import { BaseWeb3Client } from "../abstracts"; import { EmptyBigNumber } from "../implementation"; import { Converter } from "./converter"; -import { BaseWeb3Client } from "../abstracts/base_web3_client"; export * from "./use"; export * from "./event_bus"; diff --git a/test/config.js b/test/config.js index 63a42694a..7cdb85359 100644 --- a/test/config.js +++ b/test/config.js @@ -6,45 +6,34 @@ dotenv.config({ module.exports = { rpc: { pos: { - parent: process.env.GOERLI_ROOT_RPC || "https://rpc.ankr.com/eth_goerli", - child: process.env.MATIC_RPC || 'https://rpc-mumbai.matic.today', + parent: process.env.GOERLI_ROOT_RPC || "https://rpc.sepolia.org", + child: process.env.MATIC_RPC || 'https://rpc-amoy.polygon.technology', }, zkEvm: { - parent: process.env.GOERLI_ROOT_RPC || "https://rpc.ankr.com/eth_goerli", - child: process.env.ZKEVM_RPC || 'https://rpc.public.zkevm-test.net', + parent: process.env.GOERLI_ROOT_RPC || "https://rpc.sepolia.org", + child: process.env.ZKEVM_RPC || 'https://rpc.cardona.zkevm-rpc.com', }, }, pos: { parent: { - // erc20: '0x3f152b63ec5ca5831061b2dccfb29a874c317502', - erc20: '0x655f2166b0709cd575202630952d71e2bb0d61af', - erc721: '0x16f7ef3774c59264c46e5063b1111bcfd6e7a72f', - // erc721: '0x5a08d01e07714146747950CE07BB0f741445D1b8', - erc1155: '0x2e3Ef7931F2d0e4a7da3dea950FF3F19269d9063', - chainManagerAddress: '0xBbD7cBFA79faee899Eaf900F13C9065bF03B1A74', // Address of RootChainManager proxy for POS Portal + erc20: '0xb480378044d92C96D16589Eb95986df6a97F2cFB', + erc721: '0x421DbB7B5dFCb112D7a13944DeFB80b28eC5D22C', + erc1155: '0x095DD31b6473c4a32548d2A5B09e0f2F3F30d8F1', + chainManagerAddress: '0xb991E39a401136348Dee93C75143B159FabF483f', }, child: { - erc721: '0xbD88C3A7c0e242156a46Fbdf87141Aa6D0c0c649', - erc20: '0xfe4F5145f6e09952a5ba9e956ED0C25e3Fa4c7F1', - // erc20: '0xA0D9f8282cD48d22Fd875E43Be32793124f8eD47', - weth: '0x714550C2C1Ea08688607D86ed8EeF4f5E4F22323', - erc1155: '0xA07e45A987F19E25176c877d98388878622623FA', + erc20: '0xf3202E7270a10E599394d8A7dA2F4Fbd475e96bA', + erc721: '0x02f83d4110D3595872481f677Ae323D50Aa09209', + erc1155: '0x488AfDFef019f511E343becb98B7c24ee02fA639', }, }, zkEvm: { parent: { ether: '0x0000000000000000000000000000000000000000', - // erc20: '0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6', // WETH - // erc20: '0xD7E55eB808693D5Ff81a3391c59886C7E0449f35' // DAI - // erc20: '0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984', // UNI - erc20: '0x4701Aa9471d7bfAc765D87dcb1Ea6BB23AD32733', // MATIC - erc20: '0xdac17f958d2ee523a2206206994597c13d831ec7' // USDT + erc20: '0x3fd0A53F4Bf853985a95F4Eb3F9C9FDE1F8e2b53', // MATIC }, child: { ether: '0x0000000000000000000000000000000000000000', - // erc20: '0x3ce1bab7b7bAE26775F81Ee3576a99f0EAd5B33C', // WETH - // erc20: '0x0cdA85ADE5C84C386B69b562d1722642748DD194', // DAI - // erc20: '0x378588D64A464d61c646e5e86F4DA5277e65802C', // UNI erc20: '0x244f21e2cDB60e9B6C9aEbB96FFe04489831F881' // MATIC }, }, diff --git a/test/debug.js b/test/debug.js index 81020f335..8787e15df 100644 --- a/test/debug.js +++ b/test/debug.js @@ -10,20 +10,12 @@ const from = user1.address; const to = user2.address; const execute = async () => { - // return console.log( - // Converter.toHex('matic-bor-receipt-'), - // Buffer.from('matic-bor-receipt-', 'utf-8'), - // toBuffer(Converter.toHex('matic-bor-receipt-')) - // ) - - const privateKey = user1.privateKey; const mumbaiERC20 = pos.child.erc20; const goerliERC20 = pos.parent.erc20; const client = new POSClient(); - await client.init({ log: true, network: 'testnet', @@ -49,7 +41,7 @@ const execute = async () => { const mumbaiERC721Token = client.erc721(pos.child.erc721); const goerliERC1155Token = client.erc1155(pos.parent.erc1155, true); const mumbaiERC1155Token = client.erc1155(pos.child.erc1155); - + console.log(client.client.parent) let tx = await client.depositEther(1, "0xD7Fbe63Db5201f71482Fa47ecC4Be5e5B125eF07", { returnTransaction: true }) @@ -326,7 +318,7 @@ const executeZkEvm = async () => { // console.log("receipt", await tx.getReceipt()); } -executeZkEvm().then(_ => { +execute().then(_ => { process.exit(0) }).catch(err => { console.error(err); diff --git a/test/package.json b/test/package.json index ca73fb643..b4cd8aece 100644 --- a/test/package.json +++ b/test/package.json @@ -4,7 +4,6 @@ "description": "", "main": "index.spec.js", "scripts": { - "test:jest": "cross-env NODE_ENV=test jest --runInBand", "link:lib": "npm link @maticnetwork/maticjs", "debug": "dotenv node debug.js", "link:lib:debug": "npm run link:lib && npm run debug" diff --git a/test/specs/index.ts b/test/specs/index.ts deleted file mode 100644 index f932dcaf9..000000000 --- a/test/specs/index.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { use } from "@maticnetwork/maticjs"; -import { Web3ClientPlugin } from "@maticnetwork/maticjs-ethers"; - -use(Web3ClientPlugin); - -console.log('process.env.NODE_ENV', process.env.NODE_ENV); - -import './pos'; -import './zkevm'; diff --git a/test/specs/map_promise.spec.ts b/test/specs/map_promise.spec.ts deleted file mode 100644 index fbd72325e..000000000 --- a/test/specs/map_promise.spec.ts +++ /dev/null @@ -1,84 +0,0 @@ -import { expect } from 'chai' -import { mapPromise } from '@maticnetwork/maticjs' - -describe('Map promise', () => { - it('map promise without concurrent', async () => { - const result = await mapPromise([1, 2, 3, 4, 5], val => { - return Promise.resolve(val * 2) - }) - expect(result) - .to.be.an('array') - .eql([2, 4, 6, 8, 10]) - }) - - it('map promise using conncurrency less than value supplied', async () => { - let result = await mapPromise( - [1, 2, 3, 4, 5], - val => { - return Promise.resolve(val * 2) - }, - { - concurrency: 1, - } - ) - expect(result) - .to.be.an('array') - .eql([2, 4, 6, 8, 10]) - - result = await mapPromise( - result, - val => { - return Promise.resolve(val * 2) - }, - { - concurrency: 2, - } - ) - expect(result) - .to.be.an('array') - .eql([4, 8, 12, 16, 20]) - }) - - it('map promise using conncurrency greater than value supplied', async () => { - let result = await mapPromise( - [1, 2, 3, 4, 5], - val => { - return Promise.resolve(val * 2) - }, - { - concurrency: 10, - } - ) - expect(result) - .to.be.an('array') - .eql([2, 4, 6, 8, 10]) - - result = await mapPromise( - result, - val => { - return Promise.resolve(val * 2) - }, - { - concurrency: Infinity, - } - ) - expect(result) - .to.be.an('array') - .eql([4, 8, 12, 16, 20]) - }) - - it('map promise using conncurrency 0', async () => { - let result = await mapPromise( - [1, 2, 3, 4, 5], - val => { - return Promise.resolve(val * 2) - }, - { - concurrency: 0, - } - ) - expect(result) - .to.be.an('array') - .eql([2, 4, 6, 8, 10]) - }) -}) diff --git a/test/specs/pos/client.ts b/test/specs/pos/client.ts deleted file mode 100644 index d08544c19..000000000 --- a/test/specs/pos/client.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { POSClient } from "@maticnetwork/maticjs"; -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.pos; - -export const erc20 = { - parent: pos.parent.erc20, - child: pos.child.erc20 -} -export const erc721 = { - parent: pos.parent.erc721, - child: pos.child.erc721 -} -export const erc1155 = { - parent: pos.parent.erc1155, - child: pos.child.erc1155 -} - -export const posClient = new POSClient(); - -export const posClientForTo = new POSClient(); \ No newline at end of file diff --git a/test/specs/pos/erc1155.spec.ts b/test/specs/pos/erc1155.spec.ts deleted file mode 100644 index 268ef42d3..000000000 --- a/test/specs/pos/erc1155.spec.ts +++ /dev/null @@ -1,167 +0,0 @@ -import { erc1155, from, posClient, posClientForTo, to, } from "./client"; -import { expect } from 'chai' -import { ABIManager, setProofApi } from '@maticnetwork/maticjs' - - -describe('ERC1155', () => { - - console.log('erc1155', posClient.erc1155); - - let erc1155Child = posClient.erc1155(erc1155.child); - let erc1155Parent = posClient.erc1155(erc1155.parent, true); - - console.log('erc1155 token created'); - - const abiManager = new ABIManager("testnet", "mumbai"); - before(() => { - return Promise.all([ - abiManager.init() - ]); - }); - - it('getBalance child', async () => { - const balance = await erc1155Child.getBalance(from, 123); - expect(balance).to.be.an('string'); - expect(Number(balance)).gte(0); - }) - - it('getBalance parent', async () => { - const balance = await erc1155Parent.getBalance(from, '123'); - expect(balance).to.be.an('string'); - expect(Number(balance)).gte(0); - }) - - it('isWithdrawExited', async () => { - // const exitHash = '0xa3ed203336807249dea53dc99434e2d06b71c85f55c89ee49ca10244ab3dbcf5'; - const isExited = await erc1155Parent.isWithdrawExited('0xbc48c0ccd9821141779a200586ef52033a3487c4e1419625fe7a0ea984521052'); - expect(isExited).equal(true); - }) - - it('isDeposited', async () => { - const txHash = '0x507ea7267693d477917265f52c23c08f1830215a0c7d86643b9c1fb4997a021e'; - const isDeposited = await posClient.isDeposited(txHash); - expect(isDeposited).to.be.an('boolean').equal(true); - }) - - it('transfer return tx', async () => { - const targetToken = 123; - - const result = await erc1155Child.transfer({ - amount: 1, - from: from, - to: to, - tokenId: targetToken - }, { - returnTransaction: true - }); - // console.log(result); - expect(result['to'].toLowerCase()).equal(erc1155.child.toLowerCase()); - }) - - it('approveAll return tx', async () => { - const result = await erc1155Parent.approveAll({ - returnTransaction: true - }); - expect(result['to'].toLowerCase()).equal(erc1155.parent.toLowerCase()); - }) - - it('deposit return tx', async () => { - const tx = await erc1155Parent.deposit({ - amount: 1, - tokenId: 123, - userAddress: from - }, { - returnTransaction: true - }); - const rootChainManager = await abiManager.getConfig("Main.POSContracts.RootChainManagerProxy"); - console.log('tx', tx['to'], 'root', rootChainManager); - expect(tx['to'].toLowerCase()).equal(rootChainManager.toLowerCase()); - }) - - // it('depositMany return tx', async () => { - // const tx = await erc1155Parent.depositMany(allTokens, from, { - // returnTransaction: true - // }); - // const rootChainManager = await abiManager.getConfig("Main.POSContracts.RootChainManagerProxy") - // expect(tx['to'].toLowerCase()).equal(rootChainManager.toLowerCase()); - // }) - - it('withdrawStart return tx', async () => { - const result = await erc1155Child.withdrawStart(123, 10, { - returnTransaction: true - }); - expect(result['to'].toLowerCase()).equal(erc1155.child.toLowerCase()); - }) - - it('withdrawStartMany return tx', async () => { - const result = await erc1155Child.withdrawStartMany([123], [10], { - returnTransaction: true - }); - expect(result['to'].toLowerCase()).equal(erc1155.child.toLowerCase()); - }) - - if (process.env.NODE_ENV !== 'test_all') return; - - it('transfer write', async () => { - const targetToken = 123; - const allTokensFrom = await erc1155Child.getBalance(from, targetToken); - console.log('allTokensFrom', allTokensFrom); - const allTokensTo = await erc1155Child.getBalance(to, targetToken); - console.log('allTokensTo', allTokensTo); - const amountToTransfer = 1; - let result = await erc1155Child.transfer({ - tokenId: targetToken, from, to, - amount: amountToTransfer - }); - - 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).equal(from); - expect(txReceipt.to.toLowerCase()).equal(erc1155.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); - - - const newAllTokensFrom = await erc1155Child.getBalance(from, targetToken); - const newAllTokensFromInNumber = Number(newAllTokensFrom); - console.log('newAllTokensFrom', newAllTokensFrom); - expect(newAllTokensFromInNumber).equal(Number(allTokensFrom) - 1); - const newAllTokensTo = await erc1155Child.getBalance(to, targetToken); - const newAllTokensToInNumber = Number(newAllTokensTo); - console.log('newAllTokensTo', newAllTokensTo); - expect(newAllTokensToInNumber).equal(Number(allTokensTo) + 1); - - const erc1155ChildToken = posClientForTo.erc1155(erc1155.child); - - // transfer token back to sender - result = await erc1155ChildToken.transfer({ - tokenId: targetToken, - to: from, - from: to, - amount: amountToTransfer - }); - txHash = await result.getTransactionHash(); - txReceipt = await result.getReceipt(); - - const newFromCount = await erc1155Child.getBalance(from, targetToken); - const newToCount = await erc1155Child.getBalance(to, targetToken); - - expect(newFromCount).equal(allTokensFrom); - expect(newToCount).equal(allTokensTo); - - }) - - it('approve', async () => { - const result = await erc1155Parent.approveAll({ - returnTransaction: true - }); - expect(result['to'].toLowerCase()).equal(erc1155.parent.toLowerCase()); - }) -}); diff --git a/test/specs/pos/erc20.spec.ts b/test/specs/pos/erc20.spec.ts deleted file mode 100644 index 54170bab1..000000000 --- a/test/specs/pos/erc20.spec.ts +++ /dev/null @@ -1,292 +0,0 @@ -import { erc20, from, posClient, posClientForTo, to } from "./client"; -import { expect } from 'chai' -import { ABIManager, setProofApi, service, utils, ITransactionRequestConfig } from '@maticnetwork/maticjs' -import BN from "bn.js"; - - -describe('ERC20', () => { - - let erc20Child = posClient.erc20(erc20.child); - let erc20Parent = posClient.erc20(erc20.parent, true); - - const abiManager = new ABIManager("testnet", "mumbai"); - before(() => { - return Promise.all([ - abiManager.init() - ]); - }); - - it('get balance child', async () => { - console.log('process.env.NODE_ENV', process.env.NODE_ENV, posClient.client); - - const balance = await erc20Child.getBalance(from); - console.log('balance', balance); - expect(balance).to.be.an('string'); - expect(Number(balance)).gte(0); - }) - - it('get 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 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); - }) - - it('is check pointed', async () => { - const isCheckPointed = await posClient.isCheckPointed('0xd6f7f4c6052611761946519076de28fbd091693af974e7d4abc1b17fd7926fd7'); - expect(isCheckPointed).to.be.an('boolean').equal(true); - }) - - it('isWithdrawExited', async () => { - const exitTxHash = '0x95844235073da694e311dc90476c861e187c36f86a863a950534c9ac2b7c1a48'; - const isExited = await erc20Parent.isWithdrawExited('0xd6f7f4c6052611761946519076de28fbd091693af974e7d4abc1b17fd7926fd7'); - expect(isExited).to.be.an('boolean').equal(true); - }) - - it('child transfer returnTransaction with eip1159', async () => { - const amount = 1; - 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 = 1; - 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', 80001); - expect(result['chainId']).to.be.an('number'); - }); - - it('parent transfer returnTransaction with eip1159', async () => { - const amount = 1; - 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); - - }); - - it('isDeposited', async () => { - const txHash = '0xc67599f5c967f2040786d5924ec55d37bf943c009bdd23f3b50e5ae66efde258'; - const isDeposited = await posClient.isDeposited(txHash); - expect(isDeposited).to.be.an('boolean').equal(true); - }) - - it('withdraw start return tx', async () => { - - const result = await erc20Child.withdrawStart('1', { - returnTransaction: true - }); - - expect(result['to'].toLowerCase()).equal(erc20.child.toLowerCase()); - expect(result).to.have.property('data') - - }); - - it('approve parent return tx', async () => { - const result = await erc20Parent.approve('1', { - 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.getPredicateAddress(); - const result = await erc20Parent.approve('1', { - 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('1'); - 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.' - }); - } - }); - - it('deposit return tx', async () => { - const result = await erc20Parent.deposit(1, from, { - returnTransaction: true - }); - - const rootChainManager = await abiManager.getConfig("Main.POSContracts.RootChainManagerProxy") - expect(result['to'].toLowerCase()).equal(rootChainManager.toLowerCase()); - }); - - const exitData = "0x3805550f00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000827f9082484235e69b0b9010031f7f7ef8848837caca0654cdd16c2c1af23e138d5ea431107325c6d99dfa567b8e395866f4fd177d79de4a8fec9d06ecea4223f55d1724e6c8455dc62148394266f9e732545254f25407139bd8cb3ecfbd9053933f23e1fca181659680cf4c1a5a6c6f723df2d7d35f3fc14929c8ccef3a9fff644db162a845ecf3a89f41b98436f15fada0f112ebea28f29e9e97f3635bd68ff97de3c0f5cdbd867bd8cb13af5930f55ca3b9ee8f345c3923965d2935a72bb4ddff77b6d5a8f427fbe79945d58189e2f58bec6c09e38c058bb80978eee60bcc260c883be329eb37a9c029e7d5733a173b53aeb0e92f925db4dc681d4bfa2f05c8c5fdd296230d1411b05264a84013c786a84617a6c24a0a317bf456e88f02bccaab4c7aa1a919485ee451901772eeff615a2ab305f3ca0a0984131328f0f9b4ffba09638e99ce4ec98b1aec6eb46eb3023078a03be9d51f8b902ebf902e801830743f9b9010000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000008000000800000000000000000000100000000000000000000020000000000000000000800000000000000000080000010000000000000000000010000000008000000000000000000000000000000000000000000200000000000000020000000000000010001000000000000000000000000004000000003000000000001000000000000000000000000000000100000400020000000000000000000000000000000000000000000000000000000000000100000f901ddf89b94fe4f5145f6e09952a5ba9e956ed0c25e3fa4c7f1f863a0ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3efa0000000000000000000000000fd71dc9721d9ddcf0480a582927c3dcd42f3064ca00000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000000af9013d940000000000000000000000000000000000001010f884a04dfe1bbbcf077ddc3e01291eea2d5c70c2b422b415d95645b9adcfd678cb1d63a00000000000000000000000000000000000000000000000000000000000001010a0000000000000000000000000fd71dc9721d9ddcf0480a582927c3dcd42f3064ca0000000000000000000000000c26880a0af2ea0c7e8130e6ec47af756465452e8b8a000000000000000000000000000000000000000000000000000005d17d8a0120000000000000000000000000000000000000000000000006f680513d061bb0d020000000000000000000000000000000000000000000001c57a98b6c5d67d41f500000000000000000000000000000000000000000000006f6804b6b8891afb020000000000000000000000000000000000000000000001c57a9913ddaf1d53f5b903dbf903d8f851a051de183267eca4127869bd2deab74a212d98ec445ea022f108006a65d32011b780808080808080a0f3099598ea2f187f803b8d66b328edf300720bfb016f4d89b4a1eceebf969f508080808080808080f89180a0ee5f307c063eefc1f9ad442f3b9f8f2981f9385b41da5465de5ac5dec863d5c7a0d5a8f8f4ab278e0aea28f1044da97c7bd3a5e807b48cd01bf705b704aa5ddd14a032a40b81b5316142b455addcb7bdd194be8e38196408efefcc4291803a402eeea0188088651f1f064c8fa57051108a83c9d695f1a124dc3783ed2a2e6e7c8fd21a808080808080808080808080f902ef20b902ebf902e801830743f9b9010000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000008000000800000000000000000000100000000000000000000020000000000000000000800000000000000000080000010000000000000000000010000000008000000000000000000000000000000000000000000200000000000000020000000000000010001000000000000000000000000004000000003000000000001000000000000000000000000000000100000400020000000000000000000000000000000000000000000000000000000000000100000f901ddf89b94fe4f5145f6e09952a5ba9e956ed0c25e3fa4c7f1f863a0ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3efa0000000000000000000000000fd71dc9721d9ddcf0480a582927c3dcd42f3064ca00000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000000af9013d940000000000000000000000000000000000001010f884a04dfe1bbbcf077ddc3e01291eea2d5c70c2b422b415d95645b9adcfd678cb1d63a00000000000000000000000000000000000000000000000000000000000001010a0000000000000000000000000fd71dc9721d9ddcf0480a582927c3dcd42f3064ca0000000000000000000000000c26880a0af2ea0c7e8130e6ec47af756465452e8b8a000000000000000000000000000000000000000000000000000005d17d8a0120000000000000000000000000000000000000000000000006f680513d061bb0d020000000000000000000000000000000000000000000001c57a98b6c5d67d41f500000000000000000000000000000000000000000000006f6804b6b8891afb020000000000000000000000000000000000000000000001c57a9913ddaf1d53f58200038000000000000000000000000000000000000000000000000000" - - it('withdrawExit return tx', async () => { - const result: ITransactionRequestConfig = await erc20Parent.withdrawExit('0x1c20c41b9d97d1026aa456a21f13725df63edec1b1f43aacb180ebcc6340a2d3', { - returnTransaction: true - }) as any; - expect(result.data).equal( - exitData - ); - const rootChainManager = await abiManager.getConfig("Main.POSContracts.RootChainManagerProxy") - expect(result['to'].toLowerCase()).equal(rootChainManager.toLowerCase()); - console.log("withdraw exit ended"); - }); - - it('withdrawExitFaster return tx without setProofAPI', async () => { - try { - const result = await erc20Parent.withdrawExitFaster('0x1c20c41b9d97d1026aa456a21f13725df63edec1b1f43aacb180ebcc6340a2d3', { - returnTransaction: true - }); - throw new Error("there should be exception"); - } catch (error) { - expect(error).deep.equal({ - message: `Proof api is not set, please set it using "setProofApi"`, - type: 'proof_api_not_set' - }) - } - }); - - // it('call getBlockIncluded', async () => { - - // setProofApi("https://proof-generator.polygon.technology"); - // try { - // // const result = await service.network.getBlockIncluded("testnet", 1000); - // // console.log("result", result); - // // expect(result.end).to.be.an('string'); - // // expect(result.start).to.be.an('string'); - // // expect(utils.BN.isBN(result.headerBlockNumber)).equal(true); - - // } catch (error) { - // console.error('error', error, error.stack); - // } - - // }); - - it('withdrawExitFaster return tx', async () => { - setProofApi("https://proof-generator.polygon.technology"); - - const result: ITransactionRequestConfig = await erc20Parent.withdrawExitFaster('0x1c20c41b9d97d1026aa456a21f13725df63edec1b1f43aacb180ebcc6340a2d3', { - returnTransaction: true - }) as any; - expect(result.data).equal( - exitData - ) - const rootChainManager = await abiManager.getConfig("Main.POSContracts.RootChainManagerProxy") - expect(result['to'].toLowerCase()).equal(rootChainManager.toLowerCase()); - - }); - - if (process.env.NODE_ENV !== 'test_all') return; - - it('child transfer', async () => { - const oldBalance = await erc20Child.getBalance(to); - console.log('oldBalance', oldBalance); - const amount = 1; - 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 = posClientForTo.erc20(erc20.child); - - result = await erc20ChildToken.transfer(amount, to); - txHash = await result.getTransactionHash(); - txReceipt = await result.getReceipt(); - }); - - 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); - }); - - it('deposit', async () => { - const result = await erc20Parent.deposit('1', from); - - const txHash = await result.getTransactionHash(); - expect(txHash).to.be.an('string'); - - const txReceipt = await result.getReceipt(); - expect(txReceipt).to.be.an('object'); - }); - -}); diff --git a/test/specs/pos/erc721.spec.ts b/test/specs/pos/erc721.spec.ts deleted file mode 100644 index 055a1dc10..000000000 --- a/test/specs/pos/erc721.spec.ts +++ /dev/null @@ -1,188 +0,0 @@ -import { erc721, from, posClient, posClientForTo, to, } from "./client"; -import { expect } from 'chai' -import { ABIManager, setProofApi } from '@maticnetwork/maticjs' - - -describe('ERC721', () => { - - let erc721Child = posClient.erc721(erc721.child); - let erc721Parent = posClient.erc721(erc721.parent, true); - - const abiManager = new ABIManager("testnet", "mumbai"); - before(() => { - return Promise.all([ - abiManager.init() - ]); - }); - - it('getTokensCounts child', async () => { - const tokensCount = await erc721Child.getTokensCount(from); - console.log('tokensCount', tokensCount); - expect(tokensCount).to.be.an('number'); - expect(tokensCount).gte(0); - }) - - it('getTokensCount parent', async () => { - const tokensCount = await erc721Parent.getTokensCount(from); - console.log('tokensCount', tokensCount); - expect(tokensCount).to.be.an('number'); - expect(tokensCount).gte(0); - }) - - it('getAllTokens child', async () => { - const tokensCount = await erc721Child.getTokensCount(from); - const allTokens = await erc721Child.getAllTokens(from); - expect(allTokens).to.be.an('array').length(tokensCount); - }) - - it('getAllTokens parent', async () => { - const tokensCount = await erc721Parent.getTokensCount(from); - const allTokens = await erc721Parent.getAllTokens(from); - expect(allTokens).to.be.an('array').length(tokensCount); - }) - - it('isWithdrawExited', async () => { - // const exitHash = '0xa3ed203336807249dea53dc99434e2d06b71c85f55c89ee49ca10244ab3dbcf5'; - const isExited = await erc721Parent.isWithdrawExited('0x2697a930ae883dd28c40a263a6a3b4d41a027cab56836de987ed2c2896abcdeb'); - expect(isExited).equal(true); - }) - - it('isDeposited for deposit many', async () => { - const depositTxhash = '0x2ae0f5073e0c0f96f622268ef8bc61ecec7349ffc97c61412e4f5cc157cb418e'; - const isExited = await posClient.isDeposited(depositTxhash); - expect(isExited).equal(true); - }) - - it('transfer return tx', async () => { - const allTokensFrom = await erc721Child.getAllTokens(from); - const targetToken = allTokensFrom[0]; - if (targetToken) { - const result = await erc721Child.transfer(targetToken, from, to, { - returnTransaction: true - }); - // console.log(result); - expect(result['to'].toLowerCase()).equal(erc721.child.toLowerCase()); - } - - }) - - it('approve return tx', async () => { - const allTokens = await erc721Parent.getAllTokens(from); - const result = await erc721Parent.approve(allTokens[0], { - returnTransaction: true - }); - expect(result['to'].toLowerCase()).equal(erc721.parent.toLowerCase()); - }) - - it('approveAll return tx', async () => { - const result = await erc721Parent.approveAll({ - returnTransaction: true - }); - expect(result['to'].toLowerCase()).equal(erc721.parent.toLowerCase()); - }) - - it('deposit return tx', async () => { - const allTokens = await erc721Parent.getAllTokens(from); - if (allTokens && allTokens[0]) { - const tx = await erc721Parent.deposit(allTokens[0], from, { - returnTransaction: true - }); - const rootChainManager = await abiManager.getConfig("Main.POSContracts.RootChainManagerProxy") - expect(tx['to'].toLowerCase()).equal(rootChainManager.toLowerCase()); - } - }) - - it('depositMany return tx', async () => { - const allTokens = await erc721Parent.getAllTokens(from); - if (allTokens && allTokens.length) { - const tx = await erc721Parent.depositMany(allTokens, from, { - returnTransaction: true - }); - const rootChainManager = await abiManager.getConfig("Main.POSContracts.RootChainManagerProxy") - expect(tx['to'].toLowerCase()).equal(rootChainManager.toLowerCase()); - } - - }) - - it('withdrawStart return tx', async () => { - const allTokens = await erc721Child.getAllTokens(from); - if (allTokens && allTokens.length) { - const result = await erc721Child.withdrawStart(allTokens[0], { - returnTransaction: true - }); - expect(result['to'].toLowerCase()).equal(erc721.child.toLowerCase()); - } - }) - - it('withdrawStartWithMetaData return tx', async () => { - const allTokens = await erc721Child.getAllTokens(from); - if (allTokens && allTokens.length) { - const result = await erc721Child.withdrawStartWithMetaData(allTokens[0], { - returnTransaction: true - }); - expect(result['to'].toLowerCase()).equal(erc721.child.toLowerCase()); - } - }) - - if (process.env.NODE_ENV !== 'test_all') return; - - it('transfer write', async () => { - const allTokensFrom = await erc721Child.getAllTokens(from); - // console.log('allTokensFrom', allTokensFrom); - const allTokensTo = await erc721Child.getAllTokens(to); - // console.log('allTokensTo', allTokensTo); - - const targetToken = allTokensFrom[0]; - if (targetToken) { - let result = await erc721Child.transfer(targetToken, from, 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).equal(from); - expect(txReceipt.to.toLowerCase()).equal(erc721.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); - - - const newAllTokensFrom = await erc721Child.getAllTokens(from); - // console.log('newAllTokensFrom', newAllTokensFrom); - expect(newAllTokensFrom.length).equal(allTokensFrom.length - 1); - const newAllTokensTo = await erc721Child.getAllTokens(to); - // console.log('newAllTokensTo', newAllTokensTo); - expect(newAllTokensTo.length).equal(allTokensTo.length + 1); - - const erc721ChildToken = posClientForTo.erc721(erc721.child); - - - // transfer token back to sender - result = await erc721ChildToken.transfer(targetToken, to, from); - txHash = await result.getTransactionHash(); - txReceipt = await result.getReceipt(); - - const newFromCount = await erc721Child.getTokensCount(from); - const newToCount = await erc721Child.getTokensCount(to); - - expect(newFromCount).equal(allTokensFrom.length); - expect(newToCount).equal(allTokensTo.length); - } - - }) - - it('approve', async () => { - const allTokens = await erc721Parent.getAllTokens(from); - if (allTokens && allTokens[0]) { - const result = await erc721Parent.approve(allTokens[0], { - returnTransaction: true - }); - expect(result['to'].toLowerCase()).equal(erc721.parent.toLowerCase()); - } - - }) -}); diff --git a/test/specs/pos/index.ts b/test/specs/pos/index.ts deleted file mode 100644 index 6d3388310..000000000 --- a/test/specs/pos/index.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { use } from "@maticnetwork/maticjs"; -import { Web3ClientPlugin } from "@maticnetwork/maticjs-ethers"; - -use(Web3ClientPlugin); - -console.log('process.env.NODE_ENV', process.env.NODE_ENV); - -import './pos_client.spec' -import './erc20.spec' -import './erc721.spec' -import './erc1155.spec' \ No newline at end of file diff --git a/test/specs/pos/pos_client.spec.ts b/test/specs/pos/pos_client.spec.ts deleted file mode 100644 index f6f26c5e4..000000000 --- a/test/specs/pos/pos_client.spec.ts +++ /dev/null @@ -1,62 +0,0 @@ -import { from, posClient, posClientForTo, privateKey, RPC, to, toPrivateKey } from "./client"; -import { expect } from 'chai' -import { ABIManager } from '@maticnetwork/maticjs' -import { providers, Wallet } from "ethers"; - - -describe('POS Client', () => { - - const abiManager = new ABIManager("testnet", "mumbai"); - const parentPrivder = new providers.JsonRpcProvider(RPC.parent); - const childProvider = new providers.JsonRpcProvider(RPC.child); - - before(() => { - return Promise.all([ - posClient.init({ - // log: true, - network: 'testnet', - version: 'mumbai', - parent: { - provider: new Wallet(privateKey, parentPrivder), - defaultConfig: { - from - } - }, - child: { - provider: new Wallet(privateKey, childProvider), - defaultConfig: { - from - } - } - }), - posClientForTo.init({ - // log: true, - network: 'testnet', - version: 'mumbai', - parent: { - provider: new Wallet(toPrivateKey, parentPrivder), - defaultConfig: { - from: to - } - }, - child: { - provider: new Wallet(toPrivateKey, childProvider), - defaultConfig: { - from: to - } - } - }), - abiManager.init() - ]); - }); - - it('depositEther return transaction', async () => { - const amount = 100; - const result = await posClient.depositEther(amount, from, { - returnTransaction: true - }); - const rootChainManager = await abiManager.getConfig("Main.POSContracts.RootChainManagerProxy") - expect(result['to'].toLowerCase()).equal(rootChainManager.toLowerCase()); - expect(result['value']).equal('0x64') - }) -}); \ No newline at end of file diff --git a/test/specs/zkevm/client.ts b/test/specs/zkevm/client.ts deleted file mode 100644 index 63b8415f2..000000000 --- a/test/specs/zkevm/client.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { ZkEvmClient } from "@maticnetwork/maticjs"; -import { user1, rpc, zkEvm, 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.zkEvm; - -export const erc20 = { - parent: zkEvm.parent.erc20, - child: zkEvm.child.erc20 -} - -export const ether = { - parent: zkEvm.parent.ether, - child: zkEvm.child.ether -} - -export const zkEvmClient = new ZkEvmClient(); - -export const zkEvmClientForTo = new ZkEvmClient(); diff --git a/test/specs/zkevm/erc20.spec.ts b/test/specs/zkevm/erc20.spec.ts deleted file mode 100644 index 22177a4aa..000000000 --- a/test/specs/zkevm/erc20.spec.ts +++ /dev/null @@ -1,396 +0,0 @@ -import { erc20, ether, from, zkEvmClient, zkEvmClientForTo, to, RPC, privateKey, toPrivateKey } from "./client"; -import { expect } from 'chai' -import { ABIManager } from '@maticnetwork/maticjs' -import BN from "bn.js"; -import { providers, Wallet } from "ethers"; - - -describe('ERC20', () => { - - const parentPrivder = new providers.JsonRpcProvider(RPC.parent); - const childProvider = new providers.JsonRpcProvider(RPC.child); - - let erc20Child = zkEvmClient.erc20(erc20.child); - let erc20Parent = zkEvmClient.erc20(erc20.parent, true); - - let etherChild = zkEvmClient.erc20(ether.child); - let etherParent = zkEvmClient.erc20(ether.parent, true); - - const abiManager = new ABIManager("testnet", "blueberry"); - before(() => { - return Promise.all([ - zkEvmClient.init({ - // log: true, - network: 'testnet', - version: 'blueberry', - parent: { - provider: new Wallet(privateKey, parentPrivder), - defaultConfig: { - from - } - }, - child: { - provider: new Wallet(privateKey, childProvider), - defaultConfig: { - from - } - } - }), - zkEvmClientForTo.init({ - // log: true, - network: 'testnet', - version: 'blueberry', - parent: { - provider: new Wallet(toPrivateKey, parentPrivder), - defaultConfig: { - from: to - } - }, - child: { - provider: new Wallet(toPrivateKey, childProvider), - defaultConfig: { - from: to - } - } - }), - abiManager.init() - ]); - }); - - // BALANCE - it('get erc20 balance child', async () => { - console.log('process.env.NODE_ENV', process.env.NODE_ENV); - const balance = await erc20Child.getBalance(from); - console.log('ERC20 balance child', 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('ERC20 balance parent', balance); - expect(balance).to.be.an('string'); - expect(Number(balance)).gte(0); - }) - - it('get ether balance child', async () => { - 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); - console.log('allowance', allowance); - expect(allowance).to.be.an('string'); - expect(Number(allowance)).gte(0); - }) - - it('get allowance child', async () => { - const allowance = await erc20Child.getAllowance(from); - console.log('allowance', allowance); - expect(allowance).to.be.an('string'); - expect(Number(allowance)).gte(0); - }) - - // IS DEPOSIT CLAIMABLE - it('is Deposit Claimable', async () => { - const isDepositClaimable = await zkEvmClient.isDepositClaimable('0xeaa6af0ac116f3c7b20a583bd6187e1a0714a6be69e1738887ce1b380409eefe'); - console.log('isDepositClaimable', isDepositClaimable); - expect(isDepositClaimable).to.be.an('boolean').equal(true); - }) - - // IS WITHDRAW EXITABLE - it('is Withdraw Exitable', async () => { - const isWithdrawExitable = await zkEvmClient.isWithdrawExitable('0x45f96efb6e58d61aafa4727caa2dca4fcaf441cedf82b83d2db7b14aa6f9ca2c'); - console.log('isWithdrawExitable', isWithdrawExitable); - expect(isWithdrawExitable).to.be.an('boolean').equal(true); - }) - - // IS DEPOSITED - it('is Deposited', async () => { - const isDeposited = await zkEvmClient.isDeposited('0xab0cdd96a5524a061ace48e4a91974fca3edcd1ad14ee8d6e7c9b468666b0bfd'); - console.log('isDeposited', isDeposited); - expect(isDeposited).to.be.an('boolean').equal(true); - }) - - // IS EXITED - it('is Exited', async () => { - const isExited = await zkEvmClient.isExited('0x27d52864c39601a722771acd89ec2f287905be84dd0678aca3cba00e59fa1982'); - console.log('isExited', isExited); - expect(isExited).to.be.an('boolean').equal(false); - }) - - // 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('chainId', 1442); - 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('approval needed', async () => { - const isApprovalNeeded = await erc20Parent.isApprovalNeeded(); - console.log('isApprovalNeeded', isApprovalNeeded); - expect(isApprovalNeeded).to.be.an('boolean').equal(true); - }); - - it('approve parent return tx', async () => { - const result = await erc20Parent.approve('10000', { - 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', {returnTransaction: true}); - 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 erc20Parent.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.Contracts.PolygonZkEVMBridgeProxy") - 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(1, from, { - returnTransaction: true - }); - - const bridge = await abiManager.getConfig("Main.Contracts.PolygonZkEVMBridgeProxy") - 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.Contracts.PolygonZkEVMBridgeProxy") - expect(result['to'].toLowerCase()).equal(bridge.toLowerCase()); - expect(result).to.have.property('data'); - }); - - it('claim erc20 deposit return tx', async () => { - const result = await erc20Child.depositClaim('0x27bbd4d96fc73c344bc1560ade28de1c4805802738beb772b995e14f41625623', { - returnTransaction: true - }); - const bridge = await abiManager.getConfig("zkEVM.Contracts.PolygonZkEVMBridge") - 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.PolygonZkEVMBridge") - 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.PolygonZkEVMBridge") - expect(result['to'].toLowerCase()).equal(bridge.toLowerCase()); - expect(Number(result['value'])).eq(1); - expect(result).to.have.property('data'); - }); - - it('exit return tx', async () => { - const result = await erc20Parent.withdrawExit('0x27d52864c39601a722771acd89ec2f287905be84dd0678aca3cba00e59fa1982', { - returnTransaction: true - }); - const bridge = await abiManager.getConfig("Main.Contracts.PolygonZkEVMBridgeProxy") - expect(result['to'].toLowerCase()).equal(bridge.toLowerCase()); - expect(result).to.have.property('data'); - }); - - if (process.env.NODE_ENV !== 'test_all') return; - - // 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(0); - 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 = zkEvmClientForTo.erc20(erc20.child); - - result = await erc20ChildToken.transfer(amount, to); - txHash = await result.getTransactionHash(); - txReceipt = await result.getReceipt(); - }); - - // 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 amount = '1'; - const spenderAddress = await erc20Parent.getBridgeAddress(); - const oldBalanceforUser = await erc20Parent.getBalance(from); - console.log('oldBalanceforUser', oldBalanceforUser); - - const oldBalanceforBridge = await erc20Parent.getBalance(spenderAddress); - console.log('oldBalanceforBridge', oldBalanceforBridge); - - const result = await erc20Parent.deposit(amount, 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 erc20Parent.getBalance(from); - console.log('newBalanceforUser', newBalanceforUser); - - const newBalanceforBridge = await erc20Parent.getBalance(spenderAddress); - console.log('newBalanceforBridge', newBalanceforBridge); - - expect(oldBalanceforUser.toString()).equal( - new BN(newBalanceforUser).add(new BN(amount)).toString() - ) - - expect(newBalanceforBridge.toString()).equal( - new BN(oldBalanceforBridge).add(new BN(amount)).toString() - ) - }); - -}); diff --git a/test/specs/zkevm/index.ts b/test/specs/zkevm/index.ts deleted file mode 100644 index 37c49c59b..000000000 --- a/test/specs/zkevm/index.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { use } from "@maticnetwork/maticjs"; -import { Web3ClientPlugin } from "@maticnetwork/maticjs-ethers"; - -use(Web3ClientPlugin); - -import './erc20.spec' \ No newline at end of file diff --git a/webpack.config.js b/webpack.config.js index 01620adf6..129141e8e 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -61,6 +61,11 @@ const serverConfig = { // globalObject: 'this', libraryTarget: 'commonjs2', }, + plugins: [ + new webpack.DefinePlugin({ + 'process.env.BUILD_ENV': JSON.stringify("node") + }), +], } const standaloneConfig = {