Commit 1a067802 authored by mbaxter's avatar mbaxter Committed by GitHub

cannon: Expand state codec tests (#12908)

* cannon: Add version 3 state and enable detect test

* cannon: Get other DetectVersion tests running
parent 2a40d226
......@@ -7,10 +7,12 @@ import (
"strconv"
"testing"
"github.com/stretchr/testify/require"
"github.com/ethereum-optimism/optimism/cannon/mipsevm/arch"
"github.com/ethereum-optimism/optimism/cannon/mipsevm/multithreaded"
"github.com/ethereum-optimism/optimism/cannon/mipsevm/singlethreaded"
"github.com/ethereum-optimism/optimism/op-service/ioutil"
"github.com/stretchr/testify/require"
)
const statesPath = "testdata/states"
......@@ -18,7 +20,7 @@ const statesPath = "testdata/states"
//go:embed testdata/states
var historicStates embed.FS
func TestDetectVersion(t *testing.T) {
func TestDetectVersion_fromFile(t *testing.T) {
testDetection := func(t *testing.T, version StateVersion, ext string) {
filename := strconv.Itoa(int(version)) + ext
dir := t.TempDir()
......@@ -34,9 +36,6 @@ func TestDetectVersion(t *testing.T) {
// Iterate all known versions to ensure we have a test case to detect every state version
for _, version := range StateVersionTypes {
version := version
if version == VersionMultiThreaded64 {
t.Skip("TODO(#12205)")
}
t.Run(version.String(), func(t *testing.T) {
testDetection(t, version, ".bin.gz")
})
......@@ -47,28 +46,38 @@ func TestDetectVersion(t *testing.T) {
})
}
}
}
// Additionally, check that the latest supported versions write new states in a way that is detected correctly
t.Run("SingleThreadedBinary", func(t *testing.T) {
state, err := NewFromState(singlethreaded.CreateEmptyState())
require.NoError(t, err)
path := writeToFile(t, "state.bin.gz", state)
version, err := DetectVersion(path)
require.NoError(t, err)
require.Equal(t, VersionSingleThreaded2, version)
})
// Check that the latest supported versions write new states in a way that is detected correctly
func TestDetectVersion_singleThreadedBinary(t *testing.T) {
targetVersion := VersionSingleThreaded2
if !arch.IsMips32 {
t.Skip("Single-threaded states are not supported for 64-bit VMs")
}
t.Run("MultiThreadedBinary", func(t *testing.T) {
state, err := NewFromState(multithreaded.CreateEmptyState())
require.NoError(t, err)
path := writeToFile(t, "state.bin.gz", state)
version, err := DetectVersion(path)
require.NoError(t, err)
require.Equal(t, VersionMultiThreaded, version)
})
state, err := NewFromState(singlethreaded.CreateEmptyState())
require.NoError(t, err)
path := writeToFile(t, "state.bin.gz", state)
version, err := DetectVersion(path)
require.NoError(t, err)
require.Equal(t, targetVersion, version)
}
func TestDetectVersion_multiThreadedBinary(t *testing.T) {
targetVersion := VersionMultiThreaded
if !arch.IsMips32 {
targetVersion = VersionMultiThreaded64
}
state, err := NewFromState(multithreaded.CreateEmptyState())
require.NoError(t, err)
path := writeToFile(t, "state.bin.gz", state)
version, err := DetectVersion(path)
require.NoError(t, err)
require.Equal(t, targetVersion, version)
}
func TestDetectVersionInvalid(t *testing.T) {
func TestDetectVersion_invalid(t *testing.T) {
t.Run("bad gzip", func(t *testing.T) {
dir := t.TempDir()
filename := "state.bin.gz"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment