Skip to content
This repository was archived by the owner on May 11, 2024. It is now read-only.

Commit c5ea6d7

Browse files
committed
unify anvil evm call
1 parent e7af5e7 commit c5ea6d7

File tree

3 files changed

+23
-27
lines changed

3 files changed

+23
-27
lines changed

driver/chain_syncer/chain_syncer_test.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,12 @@ func TestChainSyncerTestSuite(t *testing.T) {
136136

137137
func (s *ChainSyncerTestSuite) TakeSnapshot() {
138138
// record snapshot state to revert to before changes
139-
s.Nil(s.RPCClient.L1.CallContext(context.Background(), &s.snapshotID, "evm_snapshot"))
139+
s.snapshotID = s.EvmSnapshot()
140140
}
141141

142142
func (s *ChainSyncerTestSuite) RevertSnapshot() {
143143
// revert to the snapshot state so protocol configs are unaffected
144-
var revertRes bool
145-
s.Nil(s.RPCClient.L1.CallContext(context.Background(), &revertRes, "evm_revert", s.snapshotID))
146-
s.True(revertRes)
144+
s.EvmRevert(s.snapshotID)
147145
s.Nil(rpc.SetHead(context.Background(), s.RPCClient.L2, common.Big0))
148146
}
149147

driver/driver_test.go

+6-18
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,7 @@ func (s *DriverTestSuite) TestProcessL1Blocks() {
129129
}
130130

131131
func (s *DriverTestSuite) TestCheckL1ReorgToHigherFork() {
132-
var testnetL1SnapshotID string
133-
s.Nil(s.RPCClient.L1.CallContext(context.Background(), &testnetL1SnapshotID, "evm_snapshot"))
134-
s.NotEmpty(testnetL1SnapshotID)
132+
var testnetL1SnapshotID = s.EvmSnapshot()
135133

136134
l1Head1, err := s.d.rpc.L1.HeaderByNumber(context.Background(), nil)
137135
s.Nil(err)
@@ -159,9 +157,7 @@ func (s *DriverTestSuite) TestCheckL1ReorgToHigherFork() {
159157
s.False(reorged)
160158

161159
// Reorg back to l2Head1
162-
var revertRes bool
163-
s.Nil(s.RPCClient.L1.CallContext(context.Background(), &revertRes, "evm_revert", testnetL1SnapshotID))
164-
s.True(revertRes)
160+
s.EvmRevert(testnetL1SnapshotID)
165161

166162
l1Head3, err := s.d.rpc.L1.HeaderByNumber(context.Background(), nil)
167163
s.Nil(err)
@@ -192,9 +188,7 @@ func (s *DriverTestSuite) TestCheckL1ReorgToHigherFork() {
192188
}
193189

194190
func (s *DriverTestSuite) TestCheckL1ReorgToLowerFork() {
195-
var testnetL1SnapshotID string
196-
s.Nil(s.RPCClient.L1.CallContext(context.Background(), &testnetL1SnapshotID, "evm_snapshot"))
197-
s.NotEmpty(testnetL1SnapshotID)
191+
var testnetL1SnapshotID = s.EvmSnapshot()
198192

199193
l1Head1, err := s.d.rpc.L1.HeaderByNumber(context.Background(), nil)
200194
s.Nil(err)
@@ -222,9 +216,7 @@ func (s *DriverTestSuite) TestCheckL1ReorgToLowerFork() {
222216
s.False(reorged)
223217

224218
// Reorg back to l2Head1
225-
var revertRes bool
226-
s.Nil(s.RPCClient.L1.CallContext(context.Background(), &revertRes, "evm_revert", testnetL1SnapshotID))
227-
s.True(revertRes)
219+
s.EvmRevert(testnetL1SnapshotID)
228220

229221
l1Head3, err := s.d.rpc.L1.HeaderByNumber(context.Background(), nil)
230222
s.Nil(err)
@@ -252,9 +244,7 @@ func (s *DriverTestSuite) TestCheckL1ReorgToLowerFork() {
252244
}
253245

254246
func (s *DriverTestSuite) TestCheckL1ReorgToSameHeightFork() {
255-
var testnetL1SnapshotID string
256-
s.Nil(s.RPCClient.L1.CallContext(context.Background(), &testnetL1SnapshotID, "evm_snapshot"))
257-
s.NotEmpty(testnetL1SnapshotID)
247+
var testnetL1SnapshotID = s.EvmSnapshot()
258248

259249
l1Head1, err := s.d.rpc.L1.HeaderByNumber(context.Background(), nil)
260250
s.Nil(err)
@@ -282,9 +272,7 @@ func (s *DriverTestSuite) TestCheckL1ReorgToSameHeightFork() {
282272
s.False(reorged)
283273

284274
// Reorg back to l2Head1
285-
var revertRes bool
286-
s.Nil(s.RPCClient.L1.CallContext(context.Background(), &revertRes, "evm_revert", testnetL1SnapshotID))
287-
s.True(revertRes)
275+
s.EvmRevert(testnetL1SnapshotID)
288276

289277
l1Head3, err := s.d.rpc.L1.HeaderByNumber(context.Background(), nil)
290278
s.Nil(err)

internal/testutils/suite.go

+15-5
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,7 @@ func (s *ClientTestSuite) SetupTest() {
9292
s.setAllowance(l1ProverPrivKey)
9393
s.setAllowance(ownerPrivKey)
9494
}
95-
s.Nil(rpcCli.L1.CallContext(context.Background(), &s.testnetL1SnapshotID, "evm_snapshot"))
96-
s.NotEmpty(s.testnetL1SnapshotID)
95+
s.testnetL1SnapshotID = s.EvmSnapshot()
9796
}
9897

9998
func (s *ClientTestSuite) setAllowance(key *ecdsa.PrivateKey) {
@@ -124,9 +123,7 @@ func (s *ClientTestSuite) setAllowance(key *ecdsa.PrivateKey) {
124123
}
125124

126125
func (s *ClientTestSuite) TearDownTest() {
127-
var revertRes bool
128-
s.Nil(s.RPCClient.L1.CallContext(context.Background(), &revertRes, "evm_revert", s.testnetL1SnapshotID))
129-
s.True(revertRes)
126+
s.EvmRevert(s.testnetL1SnapshotID)
130127

131128
s.Nil(rpc.SetHead(context.Background(), s.RPCClient.L2, common.Big0))
132129
s.Nil(s.proverServer.Shutdown(context.Background()))
@@ -141,3 +138,16 @@ func (s *ClientTestSuite) IncreaseTime(time uint64) {
141138
s.Nil(s.RPCClient.L1.CallContext(context.Background(), &result, "evm_increaseTime", time))
142139
s.NotNil(result)
143140
}
141+
142+
func (s *ClientTestSuite) EvmSnapshot() string {
143+
var snapshotID string
144+
s.Nil(s.RPCClient.L1.CallContext(context.Background(), &snapshotID, "evm_snapshot"))
145+
s.NotEmpty(snapshotID)
146+
return snapshotID
147+
}
148+
149+
func (s *ClientTestSuite) EvmRevert(snapshotID string) {
150+
var revertRes bool
151+
s.Nil(s.RPCClient.L1.CallContext(context.Background(), &revertRes, "evm_revert", snapshotID))
152+
s.True(revertRes)
153+
}

0 commit comments

Comments
 (0)