Skip to content

Commit

Permalink
chore: Linter issues (#134)
Browse files Browse the repository at this point in the history
fix linter issues
  • Loading branch information
enemycnt authored Jan 5, 2023
1 parent 71ebab0 commit 333b57f
Show file tree
Hide file tree
Showing 29 changed files with 526 additions and 697 deletions.
4 changes: 4 additions & 0 deletions packages/sdk/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
module.exports = {
extends: "../../.eslintrc.js",
parserOptions: {
project: './tsconfig.json',
tsconfigRootDir: __dirname,
},
}
204 changes: 97 additions & 107 deletions packages/sdk/integration/test/chainbridge.e2e.test.ts
Original file line number Diff line number Diff line change
@@ -1,127 +1,117 @@
import { ContractReceipt, utils, BigNumber, ethers } from "ethers"
import { ERC20Bridge } from '../../src/chains'
/* eslint-disable */

import { ContractReceipt, utils, BigNumber, ethers } from 'ethers';
import { ERC20Bridge } from '../../src/chains';
import { Erc20DetailedFactory } from '../../src/Contracts/Erc20DetailedFactory';
import { BridgeData, Chainbridge } from "../../src"
import { BridgeData, Chainbridge } from '../../src';

// NOTE: this setup is dependant on current chainbridge core local setup
const bridgeSetup: BridgeData = {
chain1: {
bridgeAddress: "0xd606A00c1A39dA53EA7Bb3Ab570BBE40b156EB66",
erc20Address: "0xb83065680e6AEc805774d8545516dF4e936F0dC0",
erc20HandlerAddress: "0x3cA3808176Ad060Ad80c4e08F30d85973Ef1d99e",
rpcURL: "http://localhost:8545",
domainId: "1",
erc20ResourceID:
"0x0000000000000000000000000000000000000000000000000000000000000000",
bridgeAddress: '0xd606A00c1A39dA53EA7Bb3Ab570BBE40b156EB66',
erc20Address: '0xb83065680e6AEc805774d8545516dF4e936F0dC0',
erc20HandlerAddress: '0x3cA3808176Ad060Ad80c4e08F30d85973Ef1d99e',
rpcURL: 'http://localhost:8545',
domainId: '1',
erc20ResourceID: '0x0000000000000000000000000000000000000000000000000000000000000000',
decimals: 18,
feeSettings: {
type: 'basic',
address: '0x08CFcF164dc2C4AB1E0966F236E87F913DE77b69'
}
address: '0x08CFcF164dc2C4AB1E0966F236E87F913DE77b69',
},
},
chain2: {
bridgeAddress: "0xd606A00c1A39dA53EA7Bb3Ab570BBE40b156EB66",
erc20Address: "0xb83065680e6AEc805774d8545516dF4e936F0dC0",
erc20HandlerAddress: "0x3cA3808176Ad060Ad80c4e08F30d85973Ef1d99e",
rpcURL: "http://localhost:8547",
domainId: "2",
erc20ResourceID:
"0x0000000000000000000000000000000000000000000000000000000000000000",
bridgeAddress: '0xd606A00c1A39dA53EA7Bb3Ab570BBE40b156EB66',
erc20Address: '0xb83065680e6AEc805774d8545516dF4e936F0dC0',
erc20HandlerAddress: '0x3cA3808176Ad060Ad80c4e08F30d85973Ef1d99e',
rpcURL: 'http://localhost:8547',
domainId: '2',
erc20ResourceID: '0x0000000000000000000000000000000000000000000000000000000000000000',
decimals: 18,
feeSettings: {
type: 'basic',
address: '0x08CFcF164dc2C4AB1E0966F236E87F913DE77b69'
}
address: '0x08CFcF164dc2C4AB1E0966F236E87F913DE77b69',
},
},
};

describe("Chainbridge e2e deposit event", () => {
const provider = new ethers.providers.JsonRpcProvider("http://localhost:8545")
const testintAcc = '0xF4314cb9046bECe6AA54bb9533155434d0c76909'
let chainbridge: Chainbridge
describe('Chainbridge e2e deposit event', () => {
const provider = new ethers.providers.JsonRpcProvider('http://localhost:8545');
const testintAcc = '0xF4314cb9046bECe6AA54bb9533155434d0c76909';
let chainbridge: Chainbridge;

it('Should instantiate Chainbridge class and initialize connection providing an address', async () => {
chainbridge = new Chainbridge({ bridgeSetup })
const connectionData = await chainbridge.initializeConnection(testintAcc)

chainbridge = new Chainbridge({ bridgeSetup });
const connectionData = await chainbridge.initializeConnection(testintAcc);

expect(Object.keys(connectionData)).toHaveLength(2)
Object.keys(connectionData).forEach((key) => {
const expectedKeys = ["bridgeEvents", "proposalEvents", "voteEvents", "feeHandler"]
expect(Object.keys(connectionData)).toHaveLength(2);
Object.keys(connectionData).forEach(key => {
const expectedKeys = ['bridgeEvents', 'proposalEvents', 'voteEvents', 'feeHandler'];
// @ts-ignore-line
expect(Object.keys(connectionData[key as keyof BridgeData])).toEqual(expectedKeys)
})
})


it("Should be mintable before doing the deposit", async () => {
const isMintable = await chainbridge.hasTokenSupplies(2, "chain2")

expect(isMintable).toBe(true)
})

it("Should return false when token is not mintable", async () => {
jest.spyOn(ERC20Bridge.prototype, "hasTokenSupplies").mockImplementation(async (...params: any) => {
return false
})

const ch = new Chainbridge({ bridgeSetup })
ch.initializeConnection(testintAcc)
const isMintable = await ch.hasTokenSupplies(2, "chain2")

expect(isMintable).toBe(false)
})

it("Should checkCurrentAllowance and it should be zero", async () => {
const allowance = await chainbridge.checkCurrentAllowance(
"chain1",
testintAcc
)

expect(allowance).toBe(0)
})

it("Should check is the node is EIP1559 compatible and get gasPrice", async () => {
const gasPrice = await chainbridge.isEIP1559MaxFeePerGas(
"chain1"
)

expect(gasPrice).toBeInstanceOf(BigNumber)
})

it("Should get token info, balance and token name", async () => {
const tokenInfo = await chainbridge.getTokenInfo("chain1")

const expectedKeys = [
"balanceOfTokens",
"tokenName"
]

expect(Object.keys(tokenInfo)).toEqual(expectedKeys)
})

it("Should get balance of erc20 tokens", async () => {
const erc20ContractInstance = Erc20DetailedFactory.connect(bridgeSetup.chain1.erc20Address, provider)
const tokenBalance = await chainbridge.getTokenBalance(erc20ContractInstance, testintAcc)

expect(Number(utils.formatUnits(tokenBalance)) > 0).toBe(true)
})

it("Should transfer some tokens from chain1 to chain2", async () => {
const amount = 7
const recipientAddress = testintAcc
const from = "chain1"
const to = "chain2"

const depositAction = await chainbridge.deposit(
amount,
recipientAddress,
from,
to
)

console.log("depositAction", depositAction)
const { status } = depositAction as ContractReceipt
expect(status).toBe(1)
})
})
expect(Object.keys(connectionData[key as keyof BridgeData])).toEqual(expectedKeys);
});
});

it('Should be mintable before doing the deposit', async () => {
const isMintable = await chainbridge.hasTokenSupplies(2, 'chain2');

expect(isMintable).toBe(true);
});

it('Should return false when token is not mintable', async () => {
jest
.spyOn(ERC20Bridge.prototype, 'hasTokenSupplies')
.mockImplementation(async (...params: any) => {
return false;
});

const ch = new Chainbridge({ bridgeSetup });
ch.initializeConnection(testintAcc);
const isMintable = await ch.hasTokenSupplies(2, 'chain2');

expect(isMintable).toBe(false);
});

it('Should checkCurrentAllowance and it should be zero', async () => {
const allowance = await chainbridge.checkCurrentAllowance('chain1', testintAcc);

expect(allowance).toBe(0);
});

it('Should check is the node is EIP1559 compatible and get gasPrice', async () => {
const gasPrice = await chainbridge.isEIP1559MaxFeePerGas('chain1');

expect(gasPrice).toBeInstanceOf(BigNumber);
});

it('Should get token info, balance and token name', async () => {
const tokenInfo = await chainbridge.getTokenInfo('chain1');

const expectedKeys = ['balanceOfTokens', 'tokenName'];

expect(Object.keys(tokenInfo)).toEqual(expectedKeys);
});

it('Should get balance of erc20 tokens', async () => {
const erc20ContractInstance = Erc20DetailedFactory.connect(
bridgeSetup.chain1.erc20Address,
provider,
);
const tokenBalance = await chainbridge.getTokenBalance(erc20ContractInstance, testintAcc);

expect(Number(utils.formatUnits(tokenBalance)) > 0).toBe(true);
});

it('Should transfer some tokens from chain1 to chain2', async () => {
const amount = 7;
const recipientAddress = testintAcc;
const from = 'chain1';
const to = 'chain2';

const depositAction = await chainbridge.deposit(amount, recipientAddress, from, to);

console.log('depositAction', depositAction);
const { status } = depositAction as ContractReceipt;
expect(status).toBe(1);
});
});
2 changes: 2 additions & 0 deletions packages/sdk/integration/test/chainbridge.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable */

import { Chainbridge } from '../../src';
import { BridgeData } from '../../src/types';
import { calculateFeeData, calculateBasicfee } from '../../src/fee';
Expand Down
2 changes: 2 additions & 0 deletions packages/sdk/integration/test/connector.browser.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable */

/**
* @jest-environment jsdom
*/
Expand Down
2 changes: 2 additions & 0 deletions packages/sdk/integration/test/connectors.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable */

import { BigNumber, ethers } from "ethers"
import { Connector } from "../../src/connectors"

Expand Down
2 changes: 2 additions & 0 deletions packages/sdk/integration/test/utils.browser.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable */

/**
* @jest-environment jsdom
*/
Expand Down
2 changes: 2 additions & 0 deletions packages/sdk/integration/test/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/* eslint-disable */

import { Bridge__factory } from '@chainsafe/chainbridge-contracts'
import { Erc20DetailedFactory } from '../../src/Contracts/Erc20DetailedFactory'
import { BridgeData, ChainbridgeContracts, Signer } from '../../src/types'
Expand Down
1 change: 1 addition & 0 deletions packages/sdk/src/Contracts/Erc20Detailed.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* Generated by ts-generator ver. 0.0.8 */
/* tslint:disable */
/* eslint-disable */

import {
ethers,
Expand Down
Loading

0 comments on commit 333b57f

Please sign in to comment.