messageStatus.spec.ts 1.47 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
import { describe, expect, it } from 'vitest'

import { CrossChainMessenger, MessageStatus } from '../src'
import { l1Provider, l2Provider } from './testUtils/ethersProviders'

const crossChainMessenger = new CrossChainMessenger({
  l1SignerOrProvider: l1Provider,
  l2SignerOrProvider: l2Provider,
  l1ChainId: 5,
  l2ChainId: 420,
  bedrock: true,
})

Wilson Cusack's avatar
Wilson Cusack committed
14
describe('getMessageStatus', () => {
15 16
  it(`should be able to correctly find a finalized withdrawal`, async () => {
    /**
Wilson Cusack's avatar
Wilson Cusack committed
17
     * Tx hash of a withdrawal
18
     *
Wilson Cusack's avatar
Wilson Cusack committed
19
     * @see https://goerli-optimism.etherscan.io/tx/0x8fb235a61079f3fa87da66e78c9da075281bc4ba5f1af4b95197dd9480e03bb5
20 21
     */
    const txWithdrawalHash =
Wilson Cusack's avatar
Wilson Cusack committed
22
      '0x8fb235a61079f3fa87da66e78c9da075281bc4ba5f1af4b95197dd9480e03bb5'
23 24 25 26 27

    const txReceipt = await l2Provider.getTransactionReceipt(txWithdrawalHash)

    expect(txReceipt).toBeDefined()

Wilson Cusack's avatar
Wilson Cusack committed
28 29 30 31 32 33 34 35
    expect(
      await crossChainMessenger.getMessageStatus(
        txWithdrawalHash,
        0,
        9370789 - 1000,
        9370789
      )
    ).toBe(MessageStatus.RELAYED)
36
  }, 20_000)
37

Wilson Cusack's avatar
Wilson Cusack committed
38
  it(`should return READY_FOR_RELAY if not in block range`, async () => {
39
    const txWithdrawalHash =
Wilson Cusack's avatar
Wilson Cusack committed
40
      '0x8fb235a61079f3fa87da66e78c9da075281bc4ba5f1af4b95197dd9480e03bb5'
41 42 43 44 45

    const txReceipt = await l2Provider.getTransactionReceipt(txWithdrawalHash)

    expect(txReceipt).toBeDefined()

Wilson Cusack's avatar
Wilson Cusack committed
46 47
    expect(
      await crossChainMessenger.getMessageStatus(txWithdrawalHash, 0, 0, 0)
Wilson Cusack's avatar
Wilson Cusack committed
48
    ).toBe(MessageStatus.READY_FOR_RELAY)
49
  }, 20_000)
50
})