Commit 29c54510 authored by James Kim's avatar James Kim

run linter

parent 49e44329
import ethers from 'ethers' import ethers from 'ethers'
import { describe, expect, it } from 'vitest' import { describe, expect, it } from 'vitest'
import { Address, PublicClient, parseEther } from 'viem'
import { import {
l1TestClient, l1TestClient,
l2TestClient, l2TestClient,
l1PublicClient, l1PublicClient,
l2PublicClient, l2PublicClient,
} from './testUtils/viemClients' } from './testUtils/viemClients'
import { BRIDGE_ADAPTER_DATA, CrossChainMessenger, L2ChainID } from '../src'
import { BRIDGE_ADAPTER_DATA, CrossChainMessenger, DEPOSIT_CONFIRMATION_BLOCKS, L2ChainID } from '../src'
import { Address, PublicClient, parseEther } from 'viem'
import { l1Provider, l2Provider } from './testUtils/ethersProviders' import { l1Provider, l2Provider } from './testUtils/ethersProviders'
const ECO_WHALE: Address = '0xBd11c836279a1352ce737FbBFba36b20734B04e7' const ECO_WHALE: Address = '0xBd11c836279a1352ce737FbBFba36b20734B04e7'
// we should instead use tokenlist as source of truth // we should instead use tokenlist as source of truth
const ECO_L1_TOKEN_ADDRESS: Address = '0x3E87d4d9E69163E7590f9b39a70853cf25e5ABE3' const ECO_L1_TOKEN_ADDRESS: Address =
const ECO_L2_TOKEN_ADDRESS: Address = '0x54bBECeA38ff36D32323f8A754683C1F5433A89f' '0x3E87d4d9E69163E7590f9b39a70853cf25e5ABE3'
const ECO_L2_TOKEN_ADDRESS: Address =
const getERC20TokenBalance = async (publicClient: PublicClient, tokenAddress: Address, ownerAddress: Address) => { '0x54bBECeA38ff36D32323f8A754683C1F5433A89f'
const getERC20TokenBalance = async (
publicClient: PublicClient,
tokenAddress: Address,
ownerAddress: Address
) => {
const result = await publicClient.readContract({ const result = await publicClient.readContract({
address: tokenAddress, address: tokenAddress,
abi: [ abi: [
...@@ -27,28 +33,36 @@ const getERC20TokenBalance = async (publicClient: PublicClient, tokenAddress: Ad ...@@ -27,28 +33,36 @@ const getERC20TokenBalance = async (publicClient: PublicClient, tokenAddress: Ad
outputs: [{ name: '', type: 'uint256' }], outputs: [{ name: '', type: 'uint256' }],
stateMutability: 'view', stateMutability: 'view',
type: 'function', type: 'function',
} },
], ],
functionName: 'balanceOf', functionName: 'balanceOf',
args: [ownerAddress] args: [ownerAddress],
}) })
return result as bigint return result as bigint
} }
const getL1ERC20TokenBalance = async (ownerAddress: Address) => { const getL1ERC20TokenBalance = async (ownerAddress: Address) => {
return getERC20TokenBalance(l1PublicClient, ECO_L1_TOKEN_ADDRESS, ownerAddress) return getERC20TokenBalance(
l1PublicClient,
ECO_L1_TOKEN_ADDRESS,
ownerAddress
)
} }
const getL2ERC20TokenBalance = async (ownerAddress: Address) => { const getL2ERC20TokenBalance = async (ownerAddress: Address) => {
return getERC20TokenBalance(l2PublicClient, ECO_L2_TOKEN_ADDRESS, ownerAddress) return getERC20TokenBalance(
l2PublicClient,
ECO_L2_TOKEN_ADDRESS,
ownerAddress
)
} }
describe('ECO token', () => { describe('ECO token', () => {
it('sdk should be able to deposit to l1 bridge contract correctly', async () => { it('sdk should be able to deposit to l1 bridge contract correctly', async () => {
await l1TestClient.impersonateAccount({ address: ECO_WHALE }) await l1TestClient.impersonateAccount({ address: ECO_WHALE })
const l1EcoWhaleSigner = await l1Provider.getSigner(ECO_WHALE); const l1EcoWhaleSigner = await l1Provider.getSigner(ECO_WHALE)
const preBridgeL1EcoWhaleBalance = await getL1ERC20TokenBalance(ECO_WHALE) const preBridgeL1EcoWhaleBalance = await getL1ERC20TokenBalance(ECO_WHALE)
const crossChainMessenger = new CrossChainMessenger({ const crossChainMessenger = new CrossChainMessenger({
...@@ -57,30 +71,32 @@ describe('ECO token', () => { ...@@ -57,30 +71,32 @@ describe('ECO token', () => {
l1ChainId: 5, l1ChainId: 5,
l2ChainId: 420, l2ChainId: 420,
bedrock: true, bedrock: true,
bridges: BRIDGE_ADAPTER_DATA[L2ChainID.OPTIMISM_GOERLI] bridges: BRIDGE_ADAPTER_DATA[L2ChainID.OPTIMISM_GOERLI],
}) })
await crossChainMessenger.approveERC20( await crossChainMessenger.approveERC20(
ECO_L1_TOKEN_ADDRESS, ECO_L1_TOKEN_ADDRESS,
ECO_L2_TOKEN_ADDRESS, ECO_L2_TOKEN_ADDRESS,
ethers.utils.parseEther('0.1'), ethers.utils.parseEther('0.1')
) )
const txResponse = await crossChainMessenger.depositERC20( const txResponse = await crossChainMessenger.depositERC20(
ECO_L1_TOKEN_ADDRESS, ECO_L1_TOKEN_ADDRESS,
ECO_L2_TOKEN_ADDRESS, ECO_L2_TOKEN_ADDRESS,
ethers.utils.parseEther('0.1'), ethers.utils.parseEther('0.1')
) )
await txResponse.wait(); await txResponse.wait()
const l1EcoWhaleBalance = await getL1ERC20TokenBalance(ECO_WHALE) const l1EcoWhaleBalance = await getL1ERC20TokenBalance(ECO_WHALE)
expect(l1EcoWhaleBalance).toEqual(preBridgeL1EcoWhaleBalance - parseEther('0.1')) expect(l1EcoWhaleBalance).toEqual(
preBridgeL1EcoWhaleBalance - parseEther('0.1')
)
}, 20_000) }, 20_000)
it('sdk should be able to withdraw into the l2 bridge contract correctly', async () => { it('sdk should be able to withdraw into the l2 bridge contract correctly', async () => {
await l2TestClient.impersonateAccount({ address: ECO_WHALE }) await l2TestClient.impersonateAccount({ address: ECO_WHALE })
const l2EcoWhaleSigner = await l2Provider.getSigner(ECO_WHALE); const l2EcoWhaleSigner = await l2Provider.getSigner(ECO_WHALE)
const preBridgeL2EcoWhaleBalance = await getL2ERC20TokenBalance(ECO_WHALE) const preBridgeL2EcoWhaleBalance = await getL2ERC20TokenBalance(ECO_WHALE)
...@@ -90,19 +106,20 @@ describe('ECO token', () => { ...@@ -90,19 +106,20 @@ describe('ECO token', () => {
l1ChainId: 5, l1ChainId: 5,
l2ChainId: 420, l2ChainId: 420,
bedrock: true, bedrock: true,
bridges: BRIDGE_ADAPTER_DATA[L2ChainID.OPTIMISM_GOERLI] bridges: BRIDGE_ADAPTER_DATA[L2ChainID.OPTIMISM_GOERLI],
}) })
const txResponse = await crossChainMessenger.withdrawERC20( const txResponse = await crossChainMessenger.withdrawERC20(
ECO_L1_TOKEN_ADDRESS, ECO_L1_TOKEN_ADDRESS,
ECO_L2_TOKEN_ADDRESS, ECO_L2_TOKEN_ADDRESS,
ethers.utils.parseEther('0.1'), ethers.utils.parseEther('0.1')
) )
await txResponse.wait(); await txResponse.wait()
const l2EcoWhaleBalance = await getL2ERC20TokenBalance(ECO_WHALE) const l2EcoWhaleBalance = await getL2ERC20TokenBalance(ECO_WHALE)
expect(l2EcoWhaleBalance).toEqual(preBridgeL2EcoWhaleBalance - parseEther('0.1')) expect(l2EcoWhaleBalance).toEqual(
preBridgeL2EcoWhaleBalance - parseEther('0.1')
)
}, 20_000) }, 20_000)
}) })
...@@ -25,7 +25,4 @@ const l2Provider = new ethers.providers.JsonRpcProvider({ ...@@ -25,7 +25,4 @@ const l2Provider = new ethers.providers.JsonRpcProvider({
headers: jsonRpcHeaders, headers: jsonRpcHeaders,
}) })
export { export { l1Provider, l2Provider }
l1Provider,
l2Provider
}
...@@ -7,9 +7,9 @@ import { ...@@ -7,9 +7,9 @@ import {
import { goerli, optimismGoerli } from 'viem/chains' import { goerli, optimismGoerli } from 'viem/chains'
// we should instead use env vars to determine chain so we can support alternate l1/l2 pairs // we should instead use env vars to determine chain so we can support alternate l1/l2 pairs
const L1_CHAIN = goerli; const L1_CHAIN = goerli
const L2_CHAIN = optimismGoerli; const L2_CHAIN = optimismGoerli
const L1_RPC_URL = 'http://localhost:8545'; const L1_RPC_URL = 'http://localhost:8545'
const L2_RPC_URL = 'http://localhost:9545' const L2_RPC_URL = 'http://localhost:9545'
const l1TestClient = createTestClient({ const l1TestClient = createTestClient({
...@@ -18,20 +18,17 @@ const l1TestClient = createTestClient({ ...@@ -18,20 +18,17 @@ const l1TestClient = createTestClient({
transport: http(L1_RPC_URL), transport: http(L1_RPC_URL),
}) })
const l2TestClient = createTestClient({ const l2TestClient = createTestClient({
mode: 'anvil', mode: 'anvil',
chain: L2_CHAIN, chain: L2_CHAIN,
transport: http(L2_RPC_URL), transport: http(L2_RPC_URL),
}) })
const l1PublicClient = createPublicClient({ const l1PublicClient = createPublicClient({
chain: L1_CHAIN, chain: L1_CHAIN,
transport: http(L1_RPC_URL), transport: http(L1_RPC_URL),
}) })
const l2PublicClient = createPublicClient({ const l2PublicClient = createPublicClient({
chain: L2_CHAIN, chain: L2_CHAIN,
transport: http(L2_RPC_URL), transport: http(L2_RPC_URL),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment