-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cannon: Move CreateVM to FPVMState for simplicity
Test read/write/create for VersionedState
- Loading branch information
Showing
7 changed files
with
133 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package versions | ||
|
||
import ( | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/ethereum-optimism/optimism/cannon/mipsevm/multithreaded" | ||
"github.com/ethereum-optimism/optimism/cannon/mipsevm/singlethreaded" | ||
"github.com/ethereum-optimism/optimism/cannon/serialize" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestNewFromState(t *testing.T) { | ||
t.Run("singlethreaded", func(t *testing.T) { | ||
rawState := singlethreaded.CreateEmptyState() | ||
expected, err := NewFromState(rawState) | ||
require.NoError(t, err) | ||
require.IsType(t, &singlethreaded.State{}, expected.FPVMState) | ||
require.Equal(t, VersionSingleThreaded, expected.Version) | ||
}) | ||
|
||
t.Run("multithreaded", func(t *testing.T) { | ||
rawState := multithreaded.CreateEmptyState() | ||
expected, err := NewFromState(rawState) | ||
require.NoError(t, err) | ||
require.IsType(t, &multithreaded.State{}, expected.FPVMState) | ||
require.Equal(t, VersionMultiThreaded, expected.Version) | ||
}) | ||
} | ||
|
||
func TestLoadStateFromFile(t *testing.T) { | ||
t.Run("SinglethreadedFromJSON", func(t *testing.T) { | ||
expected, err := NewFromState(singlethreaded.CreateEmptyState()) | ||
require.NoError(t, err) | ||
|
||
path := writeToFile(t, "state.json", expected) | ||
actual, err := LoadStateFromFile(path) | ||
require.NoError(t, err) | ||
require.Equal(t, expected, actual) | ||
}) | ||
|
||
t.Run("SinglethreadedFromBinary", func(t *testing.T) { | ||
expected, err := NewFromState(singlethreaded.CreateEmptyState()) | ||
require.NoError(t, err) | ||
|
||
path := writeToFile(t, "state.bin.gz", expected) | ||
actual, err := LoadStateFromFile(path) | ||
require.NoError(t, err) | ||
require.Equal(t, expected, actual) | ||
}) | ||
|
||
t.Run("MultithreadedFromBinary", func(t *testing.T) { | ||
expected, err := NewFromState(multithreaded.CreateEmptyState()) | ||
require.NoError(t, err) | ||
|
||
path := writeToFile(t, "state.bin.gz", expected) | ||
actual, err := LoadStateFromFile(path) | ||
require.NoError(t, err) | ||
require.Equal(t, expected, actual) | ||
}) | ||
} | ||
|
||
func TestMultithreadedDoesNotSupportJSON(t *testing.T) { | ||
state, err := NewFromState(multithreaded.CreateEmptyState()) | ||
require.NoError(t, err) | ||
|
||
dir := t.TempDir() | ||
path := filepath.Join(dir, "test.json") | ||
err = serialize.Write(path, state, 0o644) | ||
require.ErrorIs(t, err, ErrJsonNotSupported) | ||
} | ||
|
||
func writeToFile(t *testing.T, filename string, data serialize.Serializable) string { | ||
dir := t.TempDir() | ||
path := filepath.Join(dir, filename) | ||
require.NoError(t, serialize.Write(path, data, 0o644)) | ||
return path | ||
} |