Skip to content

Commit

Permalink
Add test to serialize & deserialize VMState
Browse files Browse the repository at this point in the history
  • Loading branch information
mininny committed Oct 1, 2024
1 parent 481d5af commit 08f76b3
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions rvgo/fast/state_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package fast

import (
"bytes"

Check failure on line 4 in rvgo/fast/state_test.go

View workflow job for this annotation

GitHub Actions / rvgo-lint

File is not `goimports`-ed (goimports)
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/stretchr/testify/require"
"testing"
)

func TestSerializeStateRoundTrip(t *testing.T) {
// Construct a test case with populated fields
mem := NewMemory()
mem.AllocPage(5)
p := mem.AllocPage(123)
p.Data[2] = 0x01
state := &VMState{
Memory: mem,
PreimageKey: common.Hash{0xFF},
PreimageOffset: 5,
PC: 6,
ExitCode: 1,
Exited: true,
Step: 0xdeadbeef,
Heap: 0xc0ffee,
LoadReservation: 40,
Registers: [32]uint64{
0xdeadbeef,
0xdeadbeef,
0xc0ffee,
0xbeefbabe,
0xdeadc0de,
0xbadc0de,
0xdeaddead,
},
LastHint: hexutil.Bytes{1, 2, 3, 4, 5},
Witness: hexutil.Bytes{6, 7, 8, 9, 10},
StateHash: common.Hash{0x12},
}

ser := new(bytes.Buffer)
err := state.Serialize(ser)
require.NoError(t, err, "must serialize state")
state2 := &VMState{}
err = state2.Deserialize(ser)
require.NoError(t, err, "must deserialize state")
require.Equal(t, state, state2, "must roundtrip state")
}

0 comments on commit 08f76b3

Please sign in to comment.