From 1a067802bbd753d09bfb0b9ee1ee6e51cb7366ce Mon Sep 17 00:00:00 2001 From: mbaxter Date: Fri, 15 Nov 2024 10:17:17 -0500 Subject: [PATCH] cannon: Expand state codec tests (#12908) * cannon: Add version 3 state and enable detect test * cannon: Get other DetectVersion tests running --- cannon/mipsevm/versions/detect_test.go | 55 ++++++++++-------- .../mipsevm/versions/testdata/states/3.bin.gz | Bin 0 -> 45 bytes 2 files changed, 32 insertions(+), 23 deletions(-) create mode 100644 cannon/mipsevm/versions/testdata/states/3.bin.gz diff --git a/cannon/mipsevm/versions/detect_test.go b/cannon/mipsevm/versions/detect_test.go index be849269fff9..bd1acd115eaf 100644 --- a/cannon/mipsevm/versions/detect_test.go +++ b/cannon/mipsevm/versions/detect_test.go @@ -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" diff --git a/cannon/mipsevm/versions/testdata/states/3.bin.gz b/cannon/mipsevm/versions/testdata/states/3.bin.gz new file mode 100644 index 0000000000000000000000000000000000000000..b6f6728313a7d5f908724a9674dd68549270c623 GIT binary patch literal 45 wcmb2|=3oGW|4C^JWPk9p8rUgI^}2HM9dJ?>=i_Do%KrcV;pa7$!;B0J006)Yxc~qF literal 0 HcmV?d00001