-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: l2-bridge-base added test for getWithdrawalEvents
- Loading branch information
1 parent
b15400c
commit f57733e
Showing
3 changed files
with
68 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,76 @@ | ||
import { App } from '../app' | ||
import * as E from 'fp-ts/Either' | ||
import { ETH_DECIMALS } from '../utils/constants' | ||
import { Address, ETH_DECIMALS } from '../utils/constants' | ||
import BigNumber from 'bignumber.js' | ||
import { ethers } from 'ethers' | ||
import { ERC20Short__factory, L2Bridge__factory } from '../generated' | ||
import { BaseClient } from './base_client' | ||
import { AVG_BLOCK_TIME_2SECONDS, HOURS_12 } from '../services/monitor_withdrawals' | ||
import * as Winston from 'winston' | ||
|
||
const timeout = 120_000 | ||
|
||
describe('base provider tests', () => { | ||
test('should fetch block logs', async () => { | ||
const app = await App.getInstance() | ||
const logger: Winston.Logger = Winston.createLogger({ | ||
format: Winston.format.simple(), | ||
transports: [new Winston.transports.Console()], | ||
}) | ||
|
||
const baseNetworkID = 8453 | ||
const baseProvider = new ethers.providers.JsonRpcProvider('https://base.llamarpc.com', baseNetworkID) | ||
const adr: Address = Address | ||
|
||
const l2Bridge = L2Bridge__factory.connect(adr.BASE_L2ERC20_TOKEN_BRIDGE_ADDRESS, baseProvider) | ||
const bridgedWSthEthRunner = ERC20Short__factory.connect(adr.BASE_WSTETH_ADDRESS, baseProvider) | ||
const baseClient = new BaseClient(baseProvider, l2Bridge, logger, bridgedWSthEthRunner) | ||
|
||
test( | ||
'should fetch block logs', | ||
async () => { | ||
const latestBlock = await baseClient.getLatestL2Block() | ||
if (E.isLeft(latestBlock)) { | ||
throw latestBlock | ||
} | ||
|
||
const blocksDto = await baseClient.getL2Logs(latestBlock.right.number, latestBlock.right.number) | ||
if (E.isLeft(blocksDto)) { | ||
throw blocksDto | ||
} | ||
|
||
expect(blocksDto.right.length).toBeGreaterThan(1) | ||
}, | ||
timeout, | ||
) | ||
|
||
test( | ||
'getWstEthTotalSupply is 16388.426826708573275643 wsETH', | ||
async () => { | ||
const baseBlockNumber = 15_091_860 | ||
const balance = await baseClient.getWstEthTotalSupply(baseBlockNumber) | ||
if (E.isLeft(balance)) { | ||
throw balance.left | ||
} | ||
|
||
const latestBlock = await app.baseClient.getLatestL2Block() | ||
if (E.isLeft(latestBlock)) { | ||
throw latestBlock | ||
} | ||
expect(balance.right.dividedBy(ETH_DECIMALS)).toEqual(new BigNumber('16388.426826708573275643')) | ||
}, | ||
timeout, | ||
) | ||
|
||
const blocksDto = await app.baseClient.getL2Logs(latestBlock.right.number, latestBlock.right.number) | ||
if (E.isLeft(blocksDto)) { | ||
throw blocksDto | ||
} | ||
test( | ||
'getWithdrawalEvents fetches 21_601 blocks for getting withdrawal events', | ||
async () => { | ||
const currentBlock = 15_091_860 | ||
|
||
expect(blocksDto.right.length).toBeGreaterThan(1) | ||
}, 120_000) | ||
const pastBlock = currentBlock - Math.ceil(HOURS_12 / AVG_BLOCK_TIME_2SECONDS) | ||
|
||
test('getWstEthTotalSupply is 1696.070092078019991932 wsETH', async () => { | ||
const app = await App.getInstance() | ||
expect(21_601).toEqual(currentBlock - pastBlock + 1) | ||
|
||
const baseBlockNumber = 13_022_744 | ||
const balance = await app.baseClient.getWstEthTotalSupply(baseBlockNumber) | ||
if (E.isLeft(balance)) { | ||
throw balance.left | ||
} | ||
const withdrawalEvents = await baseClient.getWithdrawalEvents(pastBlock, currentBlock - 1) | ||
if (E.isLeft(withdrawalEvents)) { | ||
throw withdrawalEvents | ||
} | ||
|
||
expect(balance.right.dividedBy(ETH_DECIMALS)).toEqual(new BigNumber('11430.956916416032084584')) | ||
}, 120_000) | ||
expect(withdrawalEvents.right.length).toEqual(0) | ||
}, | ||
timeout, | ||
) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters