Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: zkSync ZkSync bridge balance mismatch func test #542

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 89 additions & 0 deletions l2-bridge-zksync/src/services/bridge_balance.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import { BridgeBalanceSrv } from './bridge_balance'
import * as Winston from 'winston'
import { ERC20Short__factory, L2ERC20Bridge__factory } from '../generated'
import { EthClient } from '../clients/eth_provider_client'
import { Address } from '../utils/constants'
import { ethers } from 'forta-agent'
import { ZkSyncClient } from '../clients/zksync_client'
import { expect } from '@jest/globals'

const TEST_TIMEOUT = 120_000 // ms

describe('Bridge balance srv functional tests', () => {
const logger: Winston.Logger = Winston.createLogger({
format: Winston.format.simple(),
transports: [new Winston.transports.Console()],
})

const adr = Address

const mainnet = 1
const drpcUrl = 'https://eth.drpc.org/'
const ethProvider = new ethers.providers.FallbackProvider([new ethers.providers.JsonRpcProvider(drpcUrl, mainnet)])

const wSthEthRunner = ERC20Short__factory.connect(adr.L1_WSTETH_ADDRESS, ethProvider)
const ethClient = new EthClient(logger, wSthEthRunner)

const l1ethBlock = 19_811_531
const l2EthBlocks = [33309095]

test(
'🚨🚨🚨 ZkSync bridge balance mismatch https://mainnet.era.zksync.io',
async () => {
const zkSyncNetworkID = 324
const zkSyncRpcURL = 'https://mainnet.era.zksync.io'
const zkSyncProvider = new ethers.providers.JsonRpcProvider(zkSyncRpcURL, zkSyncNetworkID)

const zkSyncL2BridgeRunner = L2ERC20Bridge__factory.connect(
adr.ZKSYNC_L2ERC20_TOKEN_BRIDGE_ADDRESS,
zkSyncProvider,
)

const bridgedWSthEthRunner = ERC20Short__factory.connect(adr.ZKSYNC_WSTETH_BRIDGED_ADDRESS, zkSyncProvider)
const zkSyncClient = new ZkSyncClient(zkSyncProvider, logger, zkSyncL2BridgeRunner, bridgedWSthEthRunner)

const bridgeBalanceSrv = new BridgeBalanceSrv(
logger,
ethClient,
zkSyncClient,
adr.ZKSYNC_L1ERC20_TOKEN_BRIDGE_ADDRESS,
)

const findings = await bridgeBalanceSrv.handleBlock(l1ethBlock, l2EthBlocks)

expect(findings.length).toEqual(1)
expect(findings[0].name).toEqual('🚨🚨🚨 ZkSync bridge balance mismatch 🚨🚨🚨')
},
TEST_TIMEOUT,
)

test(
'🚨🚨🚨 ZkSync bridge balance mismatch https://zksync.drpc.org',
async () => {
const zkSyncNetworkID = 324
const zkSyncRpcURL = 'https://zksync.drpc.org'
const zkSyncProvider = new ethers.providers.JsonRpcProvider(zkSyncRpcURL, zkSyncNetworkID)

const zkSyncL2BridgeRunner = L2ERC20Bridge__factory.connect(
adr.ZKSYNC_L2ERC20_TOKEN_BRIDGE_ADDRESS,
zkSyncProvider,
)

const bridgedWSthEthRunner = ERC20Short__factory.connect(adr.ZKSYNC_WSTETH_BRIDGED_ADDRESS, zkSyncProvider)
const zkSyncClient = new ZkSyncClient(zkSyncProvider, logger, zkSyncL2BridgeRunner, bridgedWSthEthRunner)

const bridgeBalanceSrv = new BridgeBalanceSrv(
logger,
ethClient,
zkSyncClient,
adr.ZKSYNC_L1ERC20_TOKEN_BRIDGE_ADDRESS,
)

const findings = await bridgeBalanceSrv.handleBlock(l1ethBlock, l2EthBlocks)

expect(findings.length).toEqual(1)
expect(findings[0].name).toEqual('🚨🚨🚨 ZkSync bridge balance mismatch 🚨🚨🚨')
},
TEST_TIMEOUT,
)
})
Loading