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

feat(txtar): add loadpkg command #1598

Merged
merged 26 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
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
2 changes: 1 addition & 1 deletion gno.land/cmd/gnoland/testdata/addpkg.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ package bar

func Render(path string) string {
return "hello from foo"
}
}
2 changes: 2 additions & 0 deletions gno.land/cmd/gnoland/testdata/append.txtar
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use gno.land/p/demo/ufmt

# start a new node
gnoland start

Expand Down
5 changes: 2 additions & 3 deletions gno.land/cmd/gnoland/testdata/grc20-registry.txtar
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# example for contract-contract interaction with ownership
# add registry
use gno.land/r/registry $WORK/registry

## start a new node
gnoland start

# add registry
gnokey maketx addpkg -pkgdir $WORK/registry -pkgpath gno.land/r/registry -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1

# we call Transfer with foo20, before it's registered
gnokey maketx call -pkgpath gno.land/r/registry -func TransferByName -args 'foo20' -args 'g123456789' -args '42' -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1
stdout 'not found'
Expand Down
1 change: 1 addition & 0 deletions gno.land/cmd/gnoland/testdata/issue-1167.txtar
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Reproducible Test for https://github.com/gnolang/gno/issues/1167
use gno.land/p/demo/avl

gnoland start

Expand Down
5 changes: 2 additions & 3 deletions gno.land/cmd/gnoland/testdata/run.txtar
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use gno.land/r/foobar/bar $WORK/bar

## start a new node
gnoland start

## add bar.gno package located in $WORK directory as gno.land/r/foobar/bar
gnokey maketx addpkg -pkgdir $WORK/bar -pkgpath gno.land/r/foobar/bar -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1

## execute Render
gnokey maketx run -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1 $WORK/script/script.gno

Expand Down
2 changes: 2 additions & 0 deletions gno.land/cmd/gnoland/testdata/wugnot.txtar
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use gno.land/r/demo/wugnot

gnoland start

gnokey maketx call -pkgpath gno.land/r/demo/wugnot -func Render -gas-fee 1000000ugnot -gas-wanted 2000000 -args '' -broadcast -chainid=tendermint_test test1
Expand Down
45 changes: 28 additions & 17 deletions gno.land/pkg/gnoland/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,27 +103,38 @@
nonDraftPkgs := sortedPkgs.GetNonDraftPkgs()
txs := []std.Tx{}
for _, pkg := range nonDraftPkgs {
// Open files in directory as MemPackage.
memPkg := gno.ReadMemPackage(pkg.Dir, pkg.Name)
if err := memPkg.Validate(); err != nil {
return nil, fmt.Errorf("invalid package: %w", err)
}

// Create transaction
tx := std.Tx{
Fee: fee,
Msgs: []std.Msg{
vmm.MsgAddPackage{
Creator: creator,
Package: memPkg,
Deposit: deposit,
},
},
tx, err := LoadPackage(pkg, creator, fee, deposit)
if err != nil {
return nil, fmt.Errorf("unable to load package %q: %w", pkg.Dir, err)

Check warning on line 108 in gno.land/pkg/gnoland/genesis.go

View check run for this annotation

Codecov / codecov/patch

gno.land/pkg/gnoland/genesis.go#L106-L108

Added lines #L106 - L108 were not covered by tests
}

tx.Signatures = make([]std.Signature, len(tx.GetSigners()))
txs = append(txs, tx)
}

return txs, nil
}

// LoadPackage loads a single package into a `std.Tx`
func LoadPackage(pkg gnomod.Pkg, creator bft.Address, fee std.Fee, deposit std.Coins) (std.Tx, error) {
var tx std.Tx

// Open files in directory as MemPackage.
memPkg := gno.ReadMemPackage(pkg.Dir, pkg.Name)
err := memPkg.Validate()
if err != nil {
return tx, fmt.Errorf("invalid package: %w", err)
}

Check warning on line 126 in gno.land/pkg/gnoland/genesis.go

View check run for this annotation

Codecov / codecov/patch

gno.land/pkg/gnoland/genesis.go#L118-L126

Added lines #L118 - L126 were not covered by tests

// Create transaction
tx.Fee = fee
tx.Msgs = []std.Msg{
vmm.MsgAddPackage{
Creator: creator,
Package: memPkg,
Deposit: deposit,
},
}
tx.Signatures = make([]std.Signature, len(tx.GetSigners()))

return tx, nil

Check warning on line 139 in gno.land/pkg/gnoland/genesis.go

View check run for this annotation

Codecov / codecov/patch

gno.land/pkg/gnoland/genesis.go#L129-L139

Added lines #L129 - L139 were not covered by tests
}
15 changes: 15 additions & 0 deletions gno.land/pkg/integration/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,21 @@
// - Creates a new user in the default keybase directory.
// - Must be run before `gnoland start`.
//
// 4. `use`:
// - Loads a specific package from the example folder or from the working ($WORK) directory.
// - Can be used to load a single package or all packages within a directory.
// - The command takes either one or two arguments. The first argument is the name of the package(s),
// and the second (optional) argument is the path to the package(s).
// Examples:
// -- # Load a package from the example packages directory:
// -- use gno.land/p/demo/ufmt
// -- # Load a package `./bar` from the current testscript's working directory with the name `gno.land/r/foobar/bar`:
// -- use gno.land/r/foobar/bar $WORK/bar
// - If the path is not prefixed with the working directory, it is assumed to be relative to the examples directory.
// - It's important to note that the load order is significant when using
// multiple use command; packages should be loaded in the order they are
// dependent upon.
gfanton marked this conversation as resolved.
Show resolved Hide resolved
//
// Logging:
//
// Gnoland logs aren't forwarded to stdout to avoid overwhelming the tests with too much
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# test that the example packages directory is loaded and usable.
use gno.land/p/demo/ufmt
use $WORK

## start a new node
gnoland start

gnokey maketx addpkg -pkgdir $WORK -pkgpath gno.land/r/importtest -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1
stdout OK!

## execute Render
gnokey maketx call -pkgpath gno.land/r/importtest -func Render -gas-fee 1000000ugnot -gas-wanted 2000000 -args '' -broadcast -chainid=tendermint_test test1
stdout '("92054" string)'
Expand Down
28 changes: 28 additions & 0 deletions gno.land/pkg/integration/testdata/use_example.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# load a package from the example packages directory.
use gno.land/p/demo/ufmt

## start a new node
gnoland start

gnokey maketx addpkg -pkgdir $WORK -pkgpath gno.land/r/importtest -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1
stdout OK!

## execute Render
gnokey maketx call -pkgpath gno.land/r/importtest -func Render -gas-fee 1000000ugnot -gas-wanted 2000000 -args '' -broadcast -chainid=tendermint_test test1
stdout '("92054" string)'
stdout OK!

-- gno.mod --
module gno.land/r/importtest

-- import.gno --
package importtest

import (
"gno.land/p/demo/ufmt"
)

func Render(_ string) string {
return ufmt.Sprintf("%d", 92054)
}

23 changes: 23 additions & 0 deletions gno.land/pkg/integration/testdata/use_example_and_work.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# load a package from the example packages directory.
use gno.land/p/demo/ufmt
use gno.land/r/importtest $WORK

## start a new node
gnoland start

## execute Render
gnokey maketx call -pkgpath gno.land/r/importtest -func Render -gas-fee 1000000ugnot -gas-wanted 2000000 -args '' -broadcast -chainid=tendermint_test test1
stdout '("92054" string)'
stdout OK!

-- import.gno --
package importtest

import (
"gno.land/p/demo/ufmt"
)

func Render(_ string) string {
return ufmt.Sprintf("%d", 92054)
}

29 changes: 29 additions & 0 deletions gno.land/pkg/integration/testdata/use_work.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use gno.land/r/foobar/bar $WORK/bar

## start a new node
gnoland start

## execute Render
gnokey maketx run -gas-fee 1000000ugnot -gas-wanted 2000000 -broadcast -chainid=tendermint_test test1 $WORK/script/script.gno

## compare render
stdout 'main: --- hello from foo ---'
stdout 'OK!'
stdout 'GAS WANTED: 200000'
stdout 'GAS USED: '

-- bar/bar.gno --
package bar

func Render(path string) string {
return "hello from foo"
}

-- script/script.gno --
package main

import "gno.land/r/foobar/bar"

func main() {
println("main: ---", bar.Render(""), "---")
}
Loading
Loading