Skip to content

Commit

Permalink
test: oapp config provider
Browse files Browse the repository at this point in the history
  • Loading branch information
sdlyy committed Mar 6, 2024
1 parent 6ba2a30 commit b56e210
Showing 1 changed file with 72 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { Logger } from '@l2beat/backend-tools'
import { MulticallClient } from '@l2beat/discovery'
// eslint-disable-next-line import/no-internal-modules
import { MulticallResponse } from '@l2beat/discovery/dist/discovery/provider/multicall/types'
// eslint-disable-next-line import/no-internal-modules
import { Bytes } from '@l2beat/discovery/dist/utils/Bytes'
import { ChainId, EthereumAddress } from '@lz/libs'
import { expect, mockFn, mockObject } from 'earl'
import { providers } from 'ethers'

import { BlockchainOAppConfigurationProvider } from './OAppConfigurationProvider'

// getAppConfig()
const mockBytesResponse = Bytes.fromHex(
'0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000902f09715b6303d4173037652fa7377e5b98089e0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000f000000000000000000000000d56e4eab23cb81f43168f9f45211eb027b9ac7cc',
)

describe(BlockchainOAppConfigurationProvider.name, () => {
it('decodes latest configuration for given OApp', async () => {
const blockNumber = 123
const oAppAddress = EthereumAddress.random()
const rpcProvider = mockObject<providers.StaticJsonRpcProvider>({
getBlockNumber: mockFn().resolvesTo(blockNumber),
})

const mcResponse: MulticallResponse[] = ChainId.getAll().map(() => ({
success: true,
data: mockBytesResponse,
}))

const multicall = mockObject<MulticallClient>({
multicall: mockFn().resolvesTo(mcResponse),
})

const provider = new BlockchainOAppConfigurationProvider(
rpcProvider,
multicall,
EthereumAddress.random(),
ChainId.ETHEREUM,
Logger.SILENT,
)

const result = await provider.getConfiguration(oAppAddress)

const keys = Object.keys(result)

// Remapped chain ids
expect(keys).toEqual([
'1',
'10',
'56',
'137',
'1101',
'8453',
'42161',
'42220',
'43114',
'59144',
])

const configurationsPerChain = Object.values(result)

for (const config of configurationsPerChain) {
expect(config.oracle).toBeTruthy()
expect(config.relayer).toBeTruthy()
expect(config.inboundProofLibraryVersion).toBeTruthy()
expect(config.outboundProofType).toBeTruthy()
expect(config.outboundBlockConfirmations).toBeTruthy()
expect(config.inboundBlockConfirmations).toBeTruthy()
}
})
})

0 comments on commit b56e210

Please sign in to comment.