-
Notifications
You must be signed in to change notification settings - Fork 7
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 0aca5a2
Showing
6 changed files
with
90 additions
and
57 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,81 @@ | ||
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 { AVG_BLOCK_TIME_2SECONDS, HOURS_12 } from '../services/monitor_withdrawals' | ||
import { App } from '../app' | ||
import * as Winston from 'winston' | ||
import { ethers } from 'forta-agent' | ||
import { ERC20Short__factory, L2Bridge__factory } from '../generated' | ||
import { BaseClient } from './base_client' | ||
|
||
const timeout = 120_000 | ||
|
||
describe('base provider tests', () => { | ||
test('should fetch block logs', async () => { | ||
const app = await App.getInstance() | ||
const app = App.getInstance() | ||
|
||
test( | ||
'should fetch block logs', | ||
async () => { | ||
const latestBlock = await app.baseClient.getLatestL2Block() | ||
if (E.isLeft(latestBlock)) { | ||
throw latestBlock | ||
} | ||
|
||
const blocksDto = await app.baseClient.getL2Logs(latestBlock.right.number, latestBlock.right.number) | ||
if (E.isLeft(blocksDto)) { | ||
throw blocksDto | ||
} | ||
|
||
expect(blocksDto.right.length).toBeGreaterThan(1) | ||
}, | ||
timeout, | ||
) | ||
|
||
test( | ||
'getWithdrawalEvents fetches 21_601 blocks for getting withdrawal events', | ||
async () => { | ||
const currentBlock = 15_091_860 | ||
|
||
const pastBlock = currentBlock - Math.ceil(HOURS_12 / AVG_BLOCK_TIME_2SECONDS) | ||
|
||
expect(21_601).toEqual(currentBlock - pastBlock + 1) | ||
|
||
const withdrawalEvents = await app.baseClient.getWithdrawalEvents(pastBlock, currentBlock - 1) | ||
if (E.isLeft(withdrawalEvents)) { | ||
throw withdrawalEvents | ||
} | ||
|
||
expect(withdrawalEvents.right.length).toEqual(0) | ||
}, | ||
timeout, | ||
) | ||
|
||
const latestBlock = await app.baseClient.getLatestL2Block() | ||
if (E.isLeft(latestBlock)) { | ||
throw latestBlock | ||
} | ||
test( | ||
'getWstEthTotalSupply is 16388.426826708573275643 wsETH', | ||
async () => { | ||
const logger: Winston.Logger = Winston.createLogger({ | ||
format: Winston.format.simple(), | ||
transports: [new Winston.transports.Console()], | ||
}) | ||
|
||
const blocksDto = await app.baseClient.getL2Logs(latestBlock.right.number, latestBlock.right.number) | ||
if (E.isLeft(blocksDto)) { | ||
throw blocksDto | ||
} | ||
const baseNetworkID = 8453 | ||
let defaultL2RPCURL = 'https://base.drpc.org' | ||
|
||
expect(blocksDto.right.length).toBeGreaterThan(1) | ||
}, 120_000) | ||
const baseProvider = new ethers.providers.JsonRpcProvider(defaultL2RPCURL, baseNetworkID) | ||
const adr: Address = Address | ||
|
||
test('getWstEthTotalSupply is 1696.070092078019991932 wsETH', async () => { | ||
const app = await App.getInstance() | ||
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) | ||
|
||
const baseBlockNumber = 13_022_744 | ||
const balance = await app.baseClient.getWstEthTotalSupply(baseBlockNumber) | ||
if (E.isLeft(balance)) { | ||
throw balance.left | ||
} | ||
const baseBlockNumber = 15_091_860 | ||
const balance = await baseClient.getWstEthTotalSupply(baseBlockNumber) | ||
if (E.isLeft(balance)) { | ||
throw balance.left | ||
} | ||
|
||
expect(balance.right.dividedBy(ETH_DECIMALS)).toEqual(new BigNumber('11430.956916416032084584')) | ||
}, 120_000) | ||
expect(balance.right.dividedBy(ETH_DECIMALS)).toEqual(new BigNumber('16388.426826708573275643')) | ||
}, | ||
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
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