add test for erp1159 check , trasnsfer child
MODIFY
src/enums/error_type.ts
src/enums/error_type.ts
@@ -4,5 +4,6 @@ export enum ERROR_TYPE {
Unknown = "unknown",
ProofAPINotSet = "proof_api_not_set",
TransactionOptionNotObject = "transation_object_not_object",
- BurnTxNotCheckPointed = "burn_tx_not_checkpointed"
+ BurnTxNotCheckPointed = "burn_tx_not_checkpointed",
+ EIP1559NotSupported = "eip-1559_not_supported"
}
\ No newline at end of file

MODIFY
src/utils/base_token.ts
src/utils/base_token.ts
@@ -176,26 +176,28 @@ export class BaseToken<T_CLIENT_CONFIG> {
return method ? method.estimateGas(config) :
client.estimateGas(config);
};
+ txConfig.chainId = !txConfig.chainId ? await client.getChainId() : txConfig.chainId;
+ txConfig.chainId = Converter.toHex(txConfig.chainId) as any;
if (isWrite) {
const { maxFeePerGas, maxPriorityFeePerGas } = txConfig;
const isEIP1559Supported = this.client.isEIP1559Supported(isParent);
- if (!isParent && isEIP1559Supported && (maxFeePerGas || maxPriorityFeePerGas)) {
- throw new Error(`Child chain doesn't support eip-1559`);
+ const isMaxFeeProvided = (maxFeePerGas || maxPriorityFeePerGas);
+
+ if (!isEIP1559Supported && isMaxFeeProvided) {
+ this.client.logger.error(ERROR_TYPE.EIP1559NotSupported, isParent).throw();
}
- const [gasLimit, gasPrice, nonce, chainId] = await Promise.all([
+ const [gasLimit, gasPrice, nonce] = await Promise.all([
!(txConfig.gasLimit)
? estimateGas({ from: txConfig.from, value: txConfig.value })
: txConfig.gasLimit,
!txConfig.gasPrice ? client.getGasPrice() : txConfig.gasPrice,
!txConfig.nonce ? client.getTransactionCount(txConfig.from as string, 'pending') : txConfig.nonce,
- !txConfig.chainId ? client.getChainId() : txConfig.chainId,
]);
this.client.logger.log("options filled");
txConfig.gasLimit = Number(gasLimit);
txConfig.nonce = nonce;
- txConfig.chainId = chainId;
- if (isEIP1559Supported) {
+ if (isEIP1559Supported && isMaxFeeProvided) {
txConfig.maxFeePerGas = maxFeePerGas;
txConfig.maxPriorityFeePerGas = maxPriorityFeePerGas;
}

MODIFY
src/utils/error_helper.ts
src/utils/error_helper.ts
@@ -36,6 +36,9 @@ export class ErrorHelper implements IError {
case ERROR_TYPE.BurnTxNotCheckPointed:
errMsg = `Burn transaction has not been checkpointed as yet`;
break;
+ case ERROR_TYPE.EIP1559NotSupported:
+ errMsg = `${info ? 'Root' : 'Child'} chain doesn't support eip-1559`;
+ break;
default:
if (!this.type) {
this.type = ERROR_TYPE.Unknown;

MODIFY
test/debug.js
test/debug.js
@@ -36,20 +36,23 @@ const execute = async () => {
const mumbaiERC20Token = client.erc20(mumbaiERC20);
const goerliERC20Token = client.erc20(goerliERC20, true);
- return console.log(await client.isDeposited('0xc67599f5c967f2040786d5924ec55d37bf943c009bdd23f3b50e5ae66efde258'));
+ // return console.log(await client.isDeposited('0xc67599f5c967f2040786d5924ec55d37bf943c009bdd23f3b50e5ae66efde258'));
- // const balance = await mumbaiERC20Token.getBalance(
- // from
- // );
- // return console.log("balance", balance);
+ const balance = await mumbaiERC20Token.getBalance(
+ from
+ );
+ return console.log("balance", balance);
// const tokens = await goerliERC720Token.getAllTokens(
// from
// );
// return console.log("tokens", tokens);
- // const tx = await goerliERC20Token.deposit(10, from);
+ const tx = await goerliERC20Token.deposit(10, from, {
+ returnTransaction: true
+ });
+ console.log('tx', tx);
// // setProofApi("https://apis.matic.network")
// // const tx = await goerliERC20Token.withdrawExit('0xd6f7f4c6052611761946519076de28fbd091693af974e7d4abc1b17fd7926fd7');
// console.log("txHash", await tx.getTransactionHash());

MODIFY
test/specs/erc20.spec.ts
test/specs/erc20.spec.ts
import { erc20, from, posClient, to } from "./client";
import { expect } from 'chai'
+import BN from "bn.js";
describe('ERC20', () => {
@@ -43,28 +44,87 @@ describe('ERC20', () => {
expect(isExited).to.be.an('boolean').equal(true);
})
+ it('child transfer returnTransaction with erp1159', async () => {
+ const amount = 10;
+ try {
+ const result = await erc20Child.transfer(to, amount, {
+ 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('parent transfer returnTransaction with erp1159', async () => {
+ const amount = 10;
+ const result = await erc20Parent.transfer(to, amount, {
+ maxFeePerGas: 10,
+ maxPriorityFeePerGas: 10,
+ returnTransaction: true
+ });
+ console.log('result', result);
+
+ expect(result).to.have.property('maxFeePerGas', 10)
+ expect(result).to.have.property('maxPriorityFeePerGas', 10)
+ expect(result).to.have.not.property('gasPrice')
+
+ });
+
// 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 () => {
+ it('child transfer', async () => {
const oldBalance = await erc20Child.getBalance(to);
console.log('oldBalance', oldBalance);
-
- const result = await erc20Child.transfer(to, '10');
+ const amount = 10;
+ const result = await erc20Child.transfer(to, amount);
const txHash = await result.getTransactionHash();
expect(txHash).to.be.an('string');
console.log('txHash', txHash);
const 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(erc20.child.toLowerCase());
+ expect(txReceipt.type).equal('0x0');
+ 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()
+ )
+ });
- // const newBalance = await erc20Child.getBalance(to);
- // console.log('newBalance', newBalance);
- });
+
+ if (process.env.NODE_ENV === 'test_all') {
+
// it('approve', async () => {
// const result = await erc20Parent.approve('10');

add test for erp1159 check , trasnsfer child