Skip to content
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

fix(cmd/gno): pass an ExecContext to MachineOptions in gno run #2856

Merged
merged 7 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions gnovm/cmd/gno/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
gno "github.com/gnolang/gno/gnovm/pkg/gnolang"
"github.com/gnolang/gno/gnovm/tests"
"github.com/gnolang/gno/tm2/pkg/commands"
"github.com/gnolang/gno/tm2/pkg/std"
)

type runCfg struct {
Expand Down Expand Up @@ -112,11 +113,15 @@ func execRun(cfg *runCfg, args []string, io commands.IO) error {
return errors.New("no files to run")
}

var send std.Coins
pkgPath := string(files[0].PkgName)
ctx := tests.TestContext(pkgPath, send)
m := gno.NewMachineWithOptions(gno.MachineOptions{
PkgPath: string(files[0].PkgName),
Input: stdin,
PkgPath: pkgPath,
Output: stdout,
Input: stdin,
Store: testStore,
Context: ctx,
Debug: cfg.debug || cfg.debugAddr != "",
})

Expand Down
4 changes: 4 additions & 0 deletions gnovm/cmd/gno/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ func TestRunApp(t *testing.T) {
args: []string{"run", "../../tests/integ/invalid_assign/main.gno"},
recoverShouldContain: "cannot use bool as main.C without explicit conversion",
},
{
args: []string{"run", "-expr", "Context()", "../../tests/integ/context/context.gno"},
stdoutShouldContain: "Context worked",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be nice to have the height so we can detect if it changes.

},
// TODO: a test file
// TODO: args
// TODO: nativeLibs VS stdlibs
Expand Down
11 changes: 11 additions & 0 deletions gnovm/tests/integ/context/context.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package runtests

import (
"fmt"
"std"
)

func Context() {
// This requires a Context to work; it will fail ugly if the Context isn't available.
fmt.Printf("Context worked: %d\n", std.GetHeight())
}
Loading