queue-ingestion.spec.ts 2.2 KB
Newer Older
1
/* Imports: Internal */
2
import { providers } from 'ethers'
3 4
import { applyL1ToL2Alias } from '@eth-optimism/core-utils'
import { asL2Provider } from '@eth-optimism/sdk'
5 6

/* Imports: External */
7
import { expect } from './shared/setup'
8
import { OptimismEnv } from './shared/env'
9
import { DEFAULT_TEST_GAS_L1, envConfig } from './shared/utils'
10

11
describe('Queue Ingestion', () => {
12
  let env: OptimismEnv
13
  let l2Provider: providers.JsonRpcProvider
14 15
  before(async () => {
    env = await OptimismEnv.new()
16
    l2Provider = asL2Provider(env.l2Wallet.provider as any)
17 18 19 20 21 22
  })

  // The batch submitter will notice that there are transactions
  // that are in the queue and submit them. L2 will pick up the
  // sequencer batch appended event and play the transactions.
  it('should order transactions correctly', async () => {
23
    const numTxs = envConfig.OVMCONTEXT_SPEC_NUM_TXS
24

25 26 27 28
    // Enqueue some transactions by building the calldata and then sending
    // the transaction to Layer 1
    const txs = []
    for (let i = 0; i < numTxs; i++) {
29 30 31 32 33 34 35 36 37
      const tx =
        await env.messenger.contracts.l1.L1CrossDomainMessenger.sendMessage(
          `0x${`${i}`.repeat(40)}`,
          `0x0${i}`,
          1_000_000,
          {
            gasLimit: DEFAULT_TEST_GAS_L1,
          }
        )
38 39
      await tx.wait()
      txs.push(tx)
40 41
    }

42 43 44
    for (let i = 0; i < numTxs; i++) {
      const l1Tx = txs[i]
      const l1TxReceipt = await txs[i].wait()
45
      const receipt = await env.waitForXDomainTransaction(l1Tx)
46 47 48 49
      const l2Tx = (await l2Provider.getTransaction(
        receipt.remoteTx.hash
      )) as any

50 51 52 53 54
      const params =
        env.messenger.contracts.l2.L2CrossDomainMessenger.interface.decodeFunctionData(
          'relayMessage',
          l2Tx.data
        )
55

56 57 58 59 60 61
      expect(params._sender.toLowerCase()).to.equal(
        env.l1Wallet.address.toLowerCase()
      )
      expect(params._target).to.equal('0x' + `${i}`.repeat(40))
      expect(l2Tx.queueOrigin).to.equal('l1')
      expect(l2Tx.l1TxOrigin.toLowerCase()).to.equal(
62 63 64
        applyL1ToL2Alias(
          env.messenger.contracts.l1.L1CrossDomainMessenger.address
        ).toLowerCase()
65 66
      )
      expect(l2Tx.l1BlockNumber).to.equal(l1TxReceipt.blockNumber)
67
    }
68
  })
69
})