Skip to content

Commit

Permalink
Add state register assertions for EVM.dryRun test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
m-Peter committed Jan 7, 2025
1 parent d1e1e8e commit 20c84f4
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions fvm/evm/evm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1964,7 +1964,7 @@ func TestDryCall(t *testing.T) {
ctx fvm.Context,
vm fvm.VM,
snapshot snapshot.SnapshotTree,
) *types.ResultSummary {
) (*types.ResultSummary, *snapshot.ExecutionSnapshot) {
code := []byte(fmt.Sprintf(`
import EVM from %s
Expand Down Expand Up @@ -1996,17 +1996,18 @@ func TestDryCall(t *testing.T) {
json.MustEncode(cadence.NewUInt64(tx.Gas())),
json.MustEncode(cadence.NewUInt(uint(tx.Value().Uint64()))),
)
_, output, err := vm.Run(
execSnapshot, output, err := vm.Run(
ctx,
script,
snapshot)
snapshot,
)
require.NoError(t, err)
require.NoError(t, output.Err)
require.Len(t, output.Events, 0)

result, err := impl.ResultSummaryFromEVMResultValue(output.Value)
require.NoError(t, err)
return result
return result, execSnapshot
}

// this test checks that gas limit is correctly used and gas usage correctly reported
Expand All @@ -2030,7 +2031,7 @@ func TestDryCall(t *testing.T) {
big.NewInt(0),
data,
)
result := dryCall(t, tx, ctx, vm, snapshot)
result, _ := dryCall(t, tx, ctx, vm, snapshot)
require.Equal(t, types.ErrCodeNoError, result.ErrorCode)
require.Equal(t, types.StatusSuccessful, result.Status)
require.Greater(t, result.GasConsumed, uint64(0))
Expand All @@ -2046,7 +2047,7 @@ func TestDryCall(t *testing.T) {
big.NewInt(0),
data,
)
result = dryCall(t, tx, ctx, vm, snapshot)
result, _ = dryCall(t, tx, ctx, vm, snapshot)
require.Equal(t, types.ExecutionErrCodeOutOfGas, result.ErrorCode)
require.Equal(t, types.StatusFailed, result.Status)
require.Equal(t, result.GasConsumed, limit)
Expand Down Expand Up @@ -2113,6 +2114,7 @@ func TestDryCall(t *testing.T) {
require.NoError(t, err)
require.NoError(t, output.Err)
assert.Len(t, output.Events, 1)
assert.Len(t, state.UpdatedRegisterIDs(), 4)
assert.Equal(
t,
flow.EventType("A.f8d6e0586b0a20c7.EVM.TransactionExecuted"),
Expand Down Expand Up @@ -2168,14 +2170,15 @@ func TestDryCall(t *testing.T) {
0,
)

_, output, err = vm.Run(
state, output, err = vm.Run(
ctx,
tx,
snapshot,
)
require.NoError(t, err)
require.NoError(t, output.Err)
assert.Len(t, output.Events, 0)
assert.Len(t, state.UpdatedRegisterIDs(), 0)
})
})

Expand All @@ -2201,7 +2204,8 @@ func TestDryCall(t *testing.T) {
data,
)

result := dryCall(t, tx, ctx, vm, snapshot)
result, state := dryCall(t, tx, ctx, vm, snapshot)
require.Len(t, state.UpdatedRegisterIDs(), 0)
require.Equal(t, types.ErrCodeNoError, result.ErrorCode)
require.Equal(t, types.StatusSuccessful, result.Status)
require.Greater(t, result.GasConsumed, uint64(0))
Expand Down Expand Up @@ -2240,12 +2244,14 @@ func TestDryCall(t *testing.T) {
json.MustEncode(coinbase),
)

_, output, err := vm.Run(
state, output, err := vm.Run(
ctx,
script,
snapshot)
snapshot,
)
require.NoError(t, err)
require.NoError(t, output.Err)
require.Len(t, state.UpdatedRegisterIDs(), 0)

res, err := impl.ResultSummaryFromEVMResultValue(output.Value)
require.NoError(t, err)
Expand Down Expand Up @@ -2275,7 +2281,7 @@ func TestDryCall(t *testing.T) {
data,
)

result := dryCall(t, tx, ctx, vm, snapshot)
result, _ := dryCall(t, tx, ctx, vm, snapshot)
assert.Equal(t, types.ValidationErrCodeInsufficientFunds, result.ErrorCode)
assert.Equal(t, types.StatusInvalid, result.Status)
assert.Equal(t, types.InvalidTransactionGasCost, int(result.GasConsumed))
Expand All @@ -2291,7 +2297,7 @@ func TestDryCall(t *testing.T) {
data,
)

result = dryCall(t, tx, ctx, vm, snapshot)
result, _ = dryCall(t, tx, ctx, vm, snapshot)
assert.Equal(t, types.ExecutionErrCodeExecutionReverted, result.ErrorCode)
assert.Equal(t, types.StatusFailed, result.Status)
assert.Equal(t, uint64(21331), result.GasConsumed)
Expand Down

0 comments on commit 20c84f4

Please sign in to comment.