Skip to content

Commit e08cad8

Browse files
committed
refactor util tests
1 parent 892922e commit e08cad8

File tree

1 file changed

+10
-32
lines changed

1 file changed

+10
-32
lines changed

fvm/evm/offchain/utils/collection_test.go

Lines changed: 10 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"strings"
1111
"testing"
1212

13-
"github.com/rs/zerolog"
1413
"github.com/rs/zerolog/log"
1514
"github.com/stretchr/testify/require"
1615

@@ -20,9 +19,6 @@ import (
2019
"github.com/onflow/flow-go/fvm/environment"
2120
"github.com/onflow/flow-go/fvm/evm"
2221
"github.com/onflow/flow-go/fvm/evm/events"
23-
"github.com/onflow/flow-go/fvm/evm/offchain/blocks"
24-
"github.com/onflow/flow-go/fvm/evm/offchain/storage"
25-
"github.com/onflow/flow-go/fvm/evm/offchain/sync"
2622
"github.com/onflow/flow-go/fvm/evm/offchain/utils"
2723
. "github.com/onflow/flow-go/fvm/evm/testutils"
2824
"github.com/onflow/flow-go/model/flow"
@@ -128,10 +124,6 @@ func replayEvents(
128124

129125
rootAddr := evm.StorageAccountAddress(chainID)
130126

131-
bpStorage := storage.NewEphemeralStorage(store)
132-
bp, err := blocks.NewBasicProvider(chainID, bpStorage, rootAddr)
133-
require.NoError(t, err)
134-
135127
nextHeight := initialNextHeight
136128

137129
scanEventFilesAndRun(t, eventsFilePath,
@@ -142,31 +134,17 @@ func replayEvents(
142134
nextHeight, blockEventPayload.Height)
143135
}
144136

145-
err = bp.OnBlockReceived(blockEventPayload)
146-
require.NoError(t, err)
147-
148-
sp := NewTestStorageProvider(store, blockEventPayload.Height)
149-
cr := sync.NewReplayer(chainID, rootAddr, sp, bp, zerolog.Logger{}, nil, true)
150-
res, results, err := cr.ReplayBlock(txEvents, blockEventPayload)
151-
require.NoError(t, err)
152-
153-
// commit all changes
154-
for k, v := range res.StorageRegisterUpdates() {
155-
err = store.SetValue([]byte(k.Owner), []byte(k.Key), v)
156-
require.NoError(t, err)
157-
}
158-
159-
proposal := blocks.ReconstructProposal(blockEventPayload, results)
160-
161-
err = bp.OnBlockExecuted(blockEventPayload.Height, res, proposal)
162-
require.NoError(t, err)
163-
164-
// commit all block hash list changes
165-
for k, v := range bpStorage.StorageRegisterUpdates() {
166-
err = store.SetValue([]byte(k.Owner), []byte(k.Key), v)
167-
require.NoError(t, err)
137+
_, _, err := utils.ReplayEVMEventsToStore(
138+
log.Logger,
139+
store,
140+
chainID,
141+
rootAddr,
142+
blockEventPayload,
143+
txEvents,
144+
)
145+
if err != nil {
146+
return fmt.Errorf("fail to replay events: %w", err)
168147
}
169-
170148
// verify the block height is sequential without gap
171149
nextHeight++
172150

0 commit comments

Comments
 (0)