Skip to content

Commit b6394e3

Browse files
committed
Remove unnecessary delta view usage in tests
1 parent 7accaea commit b6394e3

File tree

4 files changed

+35
-55
lines changed

4 files changed

+35
-55
lines changed

engine/execution/computation/committer/committer_test.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"github.com/stretchr/testify/require"
88

99
"github.com/onflow/flow-go/engine/execution/computation/committer"
10-
"github.com/onflow/flow-go/engine/execution/state/delta"
10+
"github.com/onflow/flow-go/fvm/state"
1111
led "github.com/onflow/flow-go/ledger"
1212
ledgermock "github.com/onflow/flow-go/ledger/mock"
1313
"github.com/onflow/flow-go/model/flow"
@@ -33,16 +33,12 @@ func TestLedgerViewCommitter(t *testing.T) {
3333
Return(expectedProof, nil).
3434
Once()
3535

36-
view := delta.NewDeltaView(nil)
37-
38-
err := view.Set(
39-
flow.NewRegisterID("owner", "key"),
40-
[]byte{1},
41-
)
42-
require.NoError(t, err)
43-
4436
newState, proof, _, err := com.CommitView(
45-
view.Finalize(),
37+
&state.ExecutionSnapshot{
38+
WriteSet: map[flow.RegisterID]flow.RegisterValue{
39+
flow.NewRegisterID("owner", "key"): []byte{1},
40+
},
41+
},
4642
utils.StateCommitmentFixture())
4743
require.NoError(t, err)
4844
require.Equal(t, flow.StateCommitment(expectedStateCommitment), newState)

engine/execution/computation/computer/computer_test.go

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535
fvmmock "github.com/onflow/flow-go/fvm/mock"
3636
reusableRuntime "github.com/onflow/flow-go/fvm/runtime"
3737
"github.com/onflow/flow-go/fvm/state"
38+
"github.com/onflow/flow-go/fvm/storage"
3839
"github.com/onflow/flow-go/fvm/storage/testutils"
3940
"github.com/onflow/flow-go/fvm/systemcontracts"
4041
"github.com/onflow/flow-go/ledger"
@@ -362,15 +363,20 @@ func TestBlockExecutor_ExecuteBlock(t *testing.T) {
362363

363364
opts := append(baseOpts, contextOptions...)
364365
ctx := fvm.NewContext(opts...)
365-
view := delta.NewDeltaView(nil)
366+
snapshotTree := storage.NewSnapshotTree(nil)
366367

367368
baseBootstrapOpts := []fvm.BootstrapProcedureOption{
368369
fvm.WithInitialTokenSupply(unittest.GenesisTokenSupply),
369370
}
370371
bootstrapOpts := append(baseBootstrapOpts, bootstrapOptions...)
371-
err := vm.Run(ctx, fvm.Bootstrap(unittest.ServiceAccountPublicKey, bootstrapOpts...), view)
372+
executionSnapshot, _, err := vm.RunV2(
373+
ctx,
374+
fvm.Bootstrap(unittest.ServiceAccountPublicKey, bootstrapOpts...),
375+
snapshotTree)
372376
require.NoError(t, err)
373377

378+
snapshotTree = snapshotTree.Append(executionSnapshot)
379+
374380
comm := new(computermock.ViewCommitter)
375381

376382
bservice := requesterunit.MockBlobService(blockstore.NewBlockstore(dssync.MutexWrap(datastore.NewMapDatastore())))
@@ -407,7 +413,7 @@ func TestBlockExecutor_ExecuteBlock(t *testing.T) {
407413
context.Background(),
408414
unittest.IdentifierFixture(),
409415
block,
410-
view,
416+
snapshotTree,
411417
derivedBlockData)
412418
assert.NoError(t, err)
413419
assert.Len(t, result.StateSnapshots, 1)
@@ -718,18 +724,15 @@ func TestBlockExecutor_ExecuteBlock(t *testing.T) {
718724
const transactionCount = 2
719725
block := generateBlock(collectionCount, transactionCount, rag)
720726

721-
view := delta.NewDeltaView(nil)
722-
723-
err = view.Set(
724-
flow.AccountStatusRegisterID(flow.BytesToAddress(address.Bytes())),
725-
environment.NewAccountStatus().ToBytes())
726-
require.NoError(t, err)
727+
key := flow.AccountStatusRegisterID(
728+
flow.BytesToAddress(address.Bytes()))
729+
value := environment.NewAccountStatus().ToBytes()
727730

728731
result, err := exe.ExecuteBlock(
729732
context.Background(),
730733
unittest.IdentifierFixture(),
731734
block,
732-
view,
735+
state.MapStorageSnapshot{key: value},
733736
derived.NewEmptyDerivedBlockData())
734737
assert.NoError(t, err)
735738
assert.Len(t, result.StateSnapshots, collectionCount+1) // +1 system chunk
@@ -818,18 +821,15 @@ func TestBlockExecutor_ExecuteBlock(t *testing.T) {
818821

819822
block := generateBlock(collectionCount, transactionCount, rag)
820823

821-
view := delta.NewDeltaView(nil)
822-
823-
err = view.Set(
824-
flow.AccountStatusRegisterID(flow.BytesToAddress(address.Bytes())),
825-
environment.NewAccountStatus().ToBytes())
826-
require.NoError(t, err)
824+
key := flow.AccountStatusRegisterID(
825+
flow.BytesToAddress(address.Bytes()))
826+
value := environment.NewAccountStatus().ToBytes()
827827

828828
result, err := exe.ExecuteBlock(
829829
context.Background(),
830830
unittest.IdentifierFixture(),
831831
block,
832-
view,
832+
state.MapStorageSnapshot{key: value},
833833
derived.NewEmptyDerivedBlockData())
834834
require.NoError(t, err)
835835
assert.Len(t, result.StateSnapshots, collectionCount+1) // +1 system chunk
@@ -1154,13 +1154,11 @@ func Test_ExecutingSystemCollection(t *testing.T) {
11541154
// create empty block, it will have system collection attached while executing
11551155
block := generateBlock(0, 0, rag)
11561156

1157-
view := delta.NewDeltaView(ledger)
1158-
11591157
result, err := exe.ExecuteBlock(
11601158
context.Background(),
11611159
unittest.IdentifierFixture(),
11621160
block,
1163-
view,
1161+
ledger,
11641162
derived.NewEmptyDerivedBlockData())
11651163
assert.NoError(t, err)
11661164
assert.Len(t, result.StateSnapshots, 1) // +1 system chunk

fvm/accounts_test.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"github.com/stretchr/testify/assert"
1212
"github.com/stretchr/testify/require"
1313

14-
"github.com/onflow/flow-go/engine/execution/state/delta"
1514
"github.com/onflow/flow-go/engine/execution/testutil"
1615
"github.com/onflow/flow-go/fvm"
1716
"github.com/onflow/flow-go/fvm/state"
@@ -1375,13 +1374,12 @@ func TestAccountBalanceFields(t *testing.T) {
13751374
}
13761375
`, address)))
13771376

1378-
view = delta.NewDeltaView(
1379-
errorOnAddressSnapshotWrapper{
1380-
view: view,
1381-
owner: address,
1382-
})
1377+
snapshot := errorOnAddressSnapshotWrapper{
1378+
view: view,
1379+
owner: address,
1380+
}
13831381

1384-
_, _, err := vm.RunV2(ctx, script, view)
1382+
_, _, err := vm.RunV2(ctx, script, snapshot)
13851383
require.ErrorContains(
13861384
t,
13871385
err,

ledger/partial/ledger_test.go

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"github.com/stretchr/testify/require"
99

1010
executionState "github.com/onflow/flow-go/engine/execution/state"
11-
"github.com/onflow/flow-go/engine/execution/state/delta"
1211
"github.com/onflow/flow-go/ledger"
1312
"github.com/onflow/flow-go/ledger/common/testutils"
1413
"github.com/onflow/flow-go/ledger/complete"
@@ -119,27 +118,16 @@ func TestProofsForEmptyRegisters(t *testing.T) {
119118
// create empty update
120119
emptyState := l.InitialState()
121120

122-
view := delta.NewDeltaView(
123-
executionState.NewLedgerStorageSnapshot(
124-
l,
125-
flow.StateCommitment(emptyState)))
126-
127-
registerID := flow.NewRegisterID("b", "nk")
128-
129-
v, err := view.Get(registerID)
130-
require.NoError(t, err)
131-
require.Empty(t, v)
132-
133-
keys, values := executionState.RegisterEntriesToKeysValues(
134-
view.Delta().UpdatedRegisters())
121+
// No updates.
122+
keys, values := executionState.RegisterEntriesToKeysValues(nil)
135123

136124
updated, err := ledger.NewUpdate(emptyState, keys, values)
137125
require.NoError(t, err)
138126

139-
allRegisters := view.Interactions().AllRegisterIDs()
140-
allKeys := make([]ledger.Key, len(allRegisters))
141-
for i, id := range allRegisters {
142-
allKeys[i] = executionState.RegisterIDToKey(id)
127+
// Read one register during execution.
128+
registerID := flow.NewRegisterID("b", "nk")
129+
allKeys := []ledger.Key{
130+
executionState.RegisterIDToKey(registerID),
143131
}
144132

145133
newState := updated.State()

0 commit comments

Comments
 (0)