-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LFVM: Refactor interpreter Configuration, test registration of experimental and default features. #868
Closed
Closed
LFVM: Refactor interpreter Configuration, test registration of experimental and default features. #868
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Copyright (c) 2024 Fantom Foundation | ||
// | ||
// Use of this software is governed by the Business Source License included | ||
// in the LICENSE file and at fantom.foundation/bsl11. | ||
// | ||
// Change Date: 2028-4-16 | ||
// | ||
// On the date above, in accordance with the Business Source License, use of | ||
// this software will be governed by the GNU Lesser General Public License v3. | ||
|
||
package lfvm_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/Fantom-foundation/Tosca/go/interpreter/lfvm" | ||
"github.com/Fantom-foundation/Tosca/go/tosca" | ||
) | ||
|
||
// TestLfvm_RegisterExperimentalConfigurations tests the registration of | ||
// experimental configurations. | ||
// This test is slightly different from other tests because of dealing with the | ||
// global registry: | ||
// - It is declared in it's own package to avoid leaking the registration to other tests. | ||
// - It tests different properties, in one single function. The reason is that the | ||
// order of different functions may change, invalidating the test. | ||
func TestLfvm_RegisterExperimentalConfigurations(t *testing.T) { | ||
|
||
// Fist registration must succeed. | ||
err := lfvm.RegisterExperimentalInterpreterConfigurations() | ||
if err != nil { | ||
t.Fatalf("failed to register experimental configurations: %v", err) | ||
} | ||
|
||
// Registering a second time must fail. | ||
err = lfvm.RegisterExperimentalInterpreterConfigurations() | ||
if err == nil { | ||
t.Fatalf("expected error when registering experimental configurations twice") | ||
} | ||
|
||
// Check that lfvm is registered by default, in addition to experimental configurations | ||
if _, ok := tosca.GetAllRegisteredInterpreters()["lfvm"]; !ok { | ||
t.Fatalf("lfvm is not registered") | ||
} | ||
|
||
// Construct all registered interpreter configurations | ||
for name, factory := range tosca.GetAllRegisteredInterpreters() { | ||
t.Run(name, func(t *testing.T) { | ||
vm, err := factory(lfvm.Config{}) | ||
if err != nil { | ||
t.Fatalf("failed to create interpreter: %v", err) | ||
} | ||
|
||
// Vms are opaque, we can't check their configuration directly. | ||
// We can only check that they do execute some basic code. | ||
params := tosca.Parameters{} | ||
params.Code = []byte{byte(lfvm.PUSH1), 0xff, byte(lfvm.POP), byte(lfvm.STOP)} | ||
params.Gas = 5 | ||
res, err := vm.Run(params) | ||
if err != nil { | ||
t.Fatalf("failed to run interpreter: %v", err) | ||
} | ||
|
||
if want, got := true, res.Success; want != got { | ||
t.Fatalf("unexpected success result: want %v, got %v", want, got) | ||
} | ||
if want, got := tosca.Gas(0), res.GasLeft; want != got { | ||
t.Fatalf("unexpected gas used: want %v, got %v", want, got) | ||
} | ||
}) | ||
} | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.