11/* Imports: External */
22import { Contract , ContractFactory } from 'ethers'
33import { ethers } from 'hardhat'
4- import { applyL1ToL2Alias , awaitCondition } from '@eth-optimism/core-utils'
4+ import { MessageDirection , MessageStatus } from '@eth-optimism/sdk'
5+ import {
6+ applyL1ToL2Alias ,
7+ awaitCondition ,
8+ sleep ,
9+ } from '@eth-optimism/core-utils'
510
611/* Imports: Internal */
712import { expect } from './shared/setup'
8- import { Direction } from './shared/watcher-utils'
913import { OptimismEnv } from './shared/env'
1014import {
1115 DEFAULT_TEST_GAS_L1 ,
1216 DEFAULT_TEST_GAS_L2 ,
1317 envConfig ,
14- sleep ,
1518 withdrawalTest ,
1619} from './shared/utils'
1720
@@ -56,23 +59,35 @@ describe('Basic L1<>L2 Communication', async () => {
5659 const value = `0x${ '77' . repeat ( 32 ) } `
5760
5861 // Send L2 -> L1 message.
59- const transaction = await env . l2Messenger . sendMessage (
60- L1SimpleStorage . address ,
61- L1SimpleStorage . interface . encodeFunctionData ( 'setValue' , [ value ] ) ,
62- 5000000 ,
62+ const transaction = await env . messenger . sendMessage (
63+ {
64+ direction : MessageDirection . L2_TO_L1 ,
65+ target : L1SimpleStorage . address ,
66+ message : L1SimpleStorage . interface . encodeFunctionData ( 'setValue' , [
67+ value ,
68+ ] ) ,
69+ } ,
6370 {
64- gasLimit : DEFAULT_TEST_GAS_L2 ,
71+ overrides : {
72+ gasLimit : DEFAULT_TEST_GAS_L2 ,
73+ } ,
6574 }
6675 )
67- await transaction . wait ( )
68- await env . relayXDomainMessages ( transaction )
69- await env . waitForXDomainTransaction ( transaction , Direction . L2ToL1 )
76+
77+ let status : MessageStatus
78+ while ( status !== MessageStatus . READY_FOR_RELAY ) {
79+ status = await env . messenger . getMessageStatus ( transaction )
80+ await sleep ( 1000 )
81+ }
82+
83+ await env . messenger . finalizeMessage ( transaction )
84+ await env . messenger . waitForMessageReceipt ( transaction )
7085
7186 expect ( await L1SimpleStorage . msgSender ( ) ) . to . equal (
72- env . l1Messenger . address
87+ env . messenger . contracts . l1 . L1CrossDomainMessenger . address
7388 )
7489 expect ( await L1SimpleStorage . xDomainSender ( ) ) . to . equal (
75- env . l2Wallet . address
90+ await env . messenger . l2Signer . getAddress ( )
7691 )
7792 expect ( await L1SimpleStorage . value ( ) ) . to . equal ( value )
7893 expect ( ( await L1SimpleStorage . totalCount ( ) ) . toNumber ( ) ) . to . equal ( 1 )
@@ -85,25 +100,36 @@ describe('Basic L1<>L2 Communication', async () => {
85100 const value = `0x${ '42' . repeat ( 32 ) } `
86101
87102 // Send L1 -> L2 message.
88- const transaction = await env . l1Messenger . sendMessage (
89- L2SimpleStorage . address ,
90- L2SimpleStorage . interface . encodeFunctionData ( 'setValue' , [ value ] ) ,
91- 5000000 ,
103+ const transaction = await env . messenger . sendMessage (
104+ {
105+ direction : MessageDirection . L1_TO_L2 ,
106+ target : L2SimpleStorage . address ,
107+ message : L2SimpleStorage . interface . encodeFunctionData ( 'setValue' , [
108+ value ,
109+ ] ) ,
110+ } ,
92111 {
93- gasLimit : DEFAULT_TEST_GAS_L1 ,
112+ l2GasLimit : 5000000 ,
113+ overrides : {
114+ gasLimit : DEFAULT_TEST_GAS_L1 ,
115+ } ,
94116 }
95117 )
96118
97- await env . waitForXDomainTransaction ( transaction , Direction . L1ToL2 )
119+ const receipt = await env . messenger . waitForMessageReceipt ( transaction )
98120
121+ console . log ( await env . messenger . l2Signer . getAddress ( ) )
122+ expect ( receipt . transactionReceipt . status ) . to . equal ( 1 )
99123 expect ( await L2SimpleStorage . msgSender ( ) ) . to . equal (
100- env . l2Messenger . address
124+ env . messenger . contracts . l2 . L2CrossDomainMessenger . address
101125 )
102126 expect ( await L2SimpleStorage . txOrigin ( ) ) . to . equal (
103- applyL1ToL2Alias ( env . l1Messenger . address )
127+ applyL1ToL2Alias (
128+ env . messenger . contracts . l1 . L1CrossDomainMessenger . address
129+ )
104130 )
105131 expect ( await L2SimpleStorage . xDomainSender ( ) ) . to . equal (
106- env . l1Wallet . address
132+ await env . messenger . l1Signer . getAddress ( )
107133 )
108134 expect ( await L2SimpleStorage . value ( ) ) . to . equal ( value )
109135 expect ( ( await L2SimpleStorage . totalCount ( ) ) . toNumber ( ) ) . to . equal ( 1 )
@@ -117,9 +143,10 @@ describe('Basic L1<>L2 Communication', async () => {
117143 const value = `0x${ '42' . repeat ( 32 ) } `
118144
119145 // Send L1 -> L2 message.
120- const tx = await env . ctc
121- . connect ( env . l1Wallet )
122- . enqueue (
146+ const tx =
147+ await env . messenger . contracts . l1 . CanonicalTransactionChain . connect (
148+ env . messenger . l1Signer
149+ ) . enqueue (
123150 L2SimpleStorage . address ,
124151 5000000 ,
125152 L2SimpleStorage . interface . encodeFunctionData ( 'setValueNotXDomain' , [
@@ -129,78 +156,41 @@ describe('Basic L1<>L2 Communication', async () => {
129156 gasLimit : DEFAULT_TEST_GAS_L1 ,
130157 }
131158 )
159+
132160 const receipt = await tx . wait ( )
133161
134162 const waitUntilBlock =
135163 receipt . blockNumber + envConfig . DTL_ENQUEUE_CONFIRMATIONS
136- let currBlock = await env . l1Provider . getBlockNumber ( )
164+ let currBlock = await env . messenger . l1Provider . getBlockNumber ( )
137165 while ( currBlock <= waitUntilBlock ) {
138166 const progress =
139167 envConfig . DTL_ENQUEUE_CONFIRMATIONS - ( waitUntilBlock - currBlock )
140168 console . log (
141169 `Waiting for ${ progress } /${ envConfig . DTL_ENQUEUE_CONFIRMATIONS } confirmations.`
142170 )
143171 await sleep ( 5000 )
144- currBlock = await env . l1Provider . getBlockNumber ( )
172+ currBlock = await env . messenger . l1Provider . getBlockNumber ( )
145173 }
146174 console . log ( 'Enqueue should be confirmed.' )
147175
148176 await awaitCondition (
149177 async ( ) => {
150178 const sender = await L2SimpleStorage . msgSender ( )
151- return sender === env . l1Wallet . address
179+ return sender === ( await env . messenger . l1Signer . getAddress ( ) )
152180 } ,
153181 2000 ,
154182 60
155183 )
156184
157185 // No aliasing when an EOA goes directly to L2.
158- expect ( await L2SimpleStorage . msgSender ( ) ) . to . equal ( env . l1Wallet . address )
159- expect ( await L2SimpleStorage . txOrigin ( ) ) . to . equal ( env . l1Wallet . address )
160- expect ( await L2SimpleStorage . value ( ) ) . to . equal ( value )
161- expect ( ( await L2SimpleStorage . totalCount ( ) ) . toNumber ( ) ) . to . equal ( 1 )
162- } )
163-
164- it ( 'should have a receipt with a status of 1 for a successful message' , async ( ) => {
165- const value = `0x${ '42' . repeat ( 32 ) } `
166-
167- // Send L1 -> L2 message.
168- const transaction = await env . l1Messenger . sendMessage (
169- L2SimpleStorage . address ,
170- L2SimpleStorage . interface . encodeFunctionData ( 'setValue' , [ value ] ) ,
171- 5000000 ,
172- {
173- gasLimit : DEFAULT_TEST_GAS_L1 ,
174- }
175- )
176- await transaction . wait ( )
177-
178- const { remoteReceipt } = await env . waitForXDomainTransaction (
179- transaction ,
180- Direction . L1ToL2
181- )
182-
183- expect ( remoteReceipt . status ) . to . equal ( 1 )
184- } )
185-
186- // SKIP: until we decide what should be done in this case
187- it . skip ( 'should have a receipt with a status of 0 for a failed message' , async ( ) => {
188- // Send L1 -> L2 message.
189- const transaction = await env . l1Messenger . sendMessage (
190- L2Reverter . address ,
191- L2Reverter . interface . encodeFunctionData ( 'doRevert' , [ ] ) ,
192- 5000000 ,
193- {
194- gasLimit : DEFAULT_TEST_GAS_L1 ,
195- }
186+ expect ( await L2SimpleStorage . msgSender ( ) ) . to . equal (
187+ await env . messenger . l1Signer . getAddress ( )
196188 )
197-
198- const { remoteReceipt } = await env . waitForXDomainTransaction (
199- transaction ,
200- Direction . L1ToL2
189+ expect ( await L2SimpleStorage . txOrigin ( ) ) . to . equal (
190+ await env . messenger . l1Signer . getAddress ( )
201191 )
202-
203- expect ( remoteReceipt . status ) . to . equal ( 0 )
192+ expect ( await L2SimpleStorage . value ( ) ) . to . equal ( value )
193+ expect ( ( await L2SimpleStorage . totalCount ( ) ) . toNumber ( ) ) . to . equal ( 1 )
204194 } )
205195 } )
206196} )
0 commit comments