Skip to content

Commit b0f973e

Browse files
Merge #4083
4083: Add a simplified script environment constructor for emulator r=pattyshack a=pattyshack Co-authored-by: Patrick Lee <[email protected]>
2 parents def6a7b + 63b3845 commit b0f973e

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

fvm/environment/facade_env.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"github.com/onflow/cadence/runtime/common"
77
"github.com/onflow/cadence/runtime/interpreter"
88

9+
"github.com/onflow/flow-go/engine/execution/state/delta"
910
"github.com/onflow/flow-go/fvm/derived"
1011
"github.com/onflow/flow-go/fvm/state"
1112
"github.com/onflow/flow-go/fvm/storage"
@@ -157,6 +158,34 @@ func NewScriptEnvironment(
157158
})
158159
}
159160

161+
// This is mainly used by command line tools, the emulator, and cadence tools
162+
// testing.
163+
func NewScriptEnvironmentFromStorageSnapshot(
164+
params EnvironmentParams,
165+
storageSnapshot state.StorageSnapshot,
166+
) *facadeEnvironment {
167+
derivedBlockData := derived.NewEmptyDerivedBlockData()
168+
derivedTxn, err := derivedBlockData.NewSnapshotReadDerivedTransactionData(
169+
derived.EndOfBlockExecutionTime,
170+
derived.EndOfBlockExecutionTime)
171+
if err != nil {
172+
panic(err)
173+
}
174+
175+
txn := storage.SerialTransaction{
176+
NestedTransaction: state.NewTransactionState(
177+
delta.NewDeltaView(storageSnapshot),
178+
state.DefaultParameters()),
179+
DerivedTransactionCommitter: derivedTxn,
180+
}
181+
182+
return NewScriptEnv(
183+
context.Background(),
184+
tracing.NewTracerSpan(),
185+
params,
186+
txn)
187+
}
188+
160189
func NewScriptEnv(
161190
ctx context.Context,
162191
tracer tracing.TracerSpan,

0 commit comments

Comments
 (0)