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

Revisit CLI and system tests #1627

Merged
merged 2 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
17 changes: 16 additions & 1 deletion tests/system/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package system

import (
"fmt"
"io"
"os/exec"
"path/filepath"
"strconv"
Expand Down Expand Up @@ -196,6 +197,10 @@ func (c WasmdCli) CustomQuery(args ...string) string {

// execute shell command
func (c WasmdCli) run(args []string) (output string, ok bool) {
return c.runWithInput(args, nil)
}

func (c WasmdCli) runWithInput(args []string, input io.Reader) (output string, ok bool) {
if c.Debug {
c.t.Logf("+++ running `%s %s`", c.execBinary, strings.Join(args, " "))
}
Expand All @@ -207,6 +212,7 @@ func (c WasmdCli) run(args []string) (output string, ok bool) {
}()
cmd := exec.Command(locateExecutable("wasmd"), args...) //nolint:gosec
cmd.Dir = workDir
cmd.Stdin = input
return cmd.CombinedOutput()
}()
ok = c.assertErrorFn(c.t, gotErr, string(gotOut))
Expand Down Expand Up @@ -256,13 +262,22 @@ func (c WasmdCli) WasmExecute(contractAddr, msg, from string, args ...string) st

// AddKey add key to default keyring. Returns address
func (c WasmdCli) AddKey(name string) string {
cmd := c.withKeyringFlags("keys", "add", name, "--no-backup")
cmd := c.withKeyringFlags("keys", "add", name) //, "--no-backup")
out, _ := c.run(cmd)
addr := gjson.Get(out, "address").String()
require.NotEmpty(c.t, addr, "got %q", out)
return addr
}

// AddKeyFromSeed recovers the key from given seed and add it to default keyring. Returns address
func (c WasmdCli) AddKeyFromSeed(name, mnemoic string) string {
cmd := c.withKeyringFlags("keys", "add", name, "--recover")
out, _ := c.runWithInput(cmd, strings.NewReader(mnemoic))
addr := gjson.Get(out, "address").String()
require.NotEmpty(c.t, addr, "got %q", out)
return addr
}

// GetKeyAddr returns address
func (c WasmdCli) GetKeyAddr(name string) string {
cmd := c.withKeyringFlags("keys", "show", name, "-a")
Expand Down
18 changes: 9 additions & 9 deletions tests/system/permissioned_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ import (
)

func TestGrantStoreCodePermissionedChain(t *testing.T) {
sut.ResetChain(t)
cli := NewWasmdCLI(t, sut, verbose)
// set params to restrict chain
const chainAuthorityAddress = "wasm1pvuujjdk0xt043ga0j9nrfh5u8pzj4rpplyqkm"
sut.ModifyGenesisJSON(t, SetCodeUploadPermission(t, "AnyOfAddresses", chainAuthorityAddress))

chainAuthorizedAccount := cli.AddKey("chain_authorized_account")
recoveredAddress := cli.AddKeyFromSeed("chain_authorized_account", "aisle ship absurd wedding arch admit fringe foam cluster tide trim aisle salad shiver tackle palm glance wrist valley hamster couch crystal frozen chronic")
alpe marked this conversation as resolved.
Show resolved Hide resolved
require.Equal(t, chainAuthorityAddress, recoveredAddress)
devAccount := cli.AddKey("dev_account")

//set params
sut.ModifyGenesisJSON(t, SetCodeUploadPermission(t, "AnyOfAddresses", chainAuthorizedAccount))

sut.ModifyGenesisCLI(t,
[]string{"genesis", "add-genesis-account", chainAuthorizedAccount, "100000000stake"},
[]string{"genesis", "add-genesis-account", chainAuthorityAddress, "100000000stake"},
)
sut.ModifyGenesisCLI(t,
[]string{"genesis", "add-genesis-account", devAccount, "100000000stake"},
Expand All @@ -37,18 +37,18 @@ func TestGrantStoreCodePermissionedChain(t *testing.T) {
require.Equal(t, 1, len(addrRes))

require.Equal(t, permission, "AnyOfAddresses")
require.Equal(t, chainAuthorizedAccount, addrRes[0].Str)
require.Equal(t, chainAuthorityAddress, addrRes[0].Str)

// chain_authorized_account grant upload permission to dev_account
alpe marked this conversation as resolved.
Show resolved Hide resolved
rsp = cli.CustomCommand("tx", "wasm", "grant", devAccount, "store-code", "*:*", "--from="+chainAuthorizedAccount)
rsp = cli.CustomCommand("tx", "wasm", "grant", "store-code", devAccount, "*:*", "--from="+chainAuthorityAddress)
RequireTxSuccess(t, rsp)

// dev_account store code fails as the address is not in the code-upload accept-list
rsp = cli.CustomCommand("tx", "wasm", "store", "./testdata/hackatom.wasm.gzip", "--from="+devAccount, "--gas=1500000", "--fees=2stake")
RequireTxFailure(t, rsp)

// create tx should work for addresses in the accept-list
args := cli.withTXFlags("tx", "wasm", "store", "./testdata/hackatom.wasm.gzip", "--from="+chainAuthorizedAccount, "--generate-only")
args := cli.withTXFlags("tx", "wasm", "store", "./testdata/hackatom.wasm.gzip", "--from="+chainAuthorityAddress, "--generate-only")
tx, ok := cli.run(args)
require.True(t, ok)

Expand Down
1 change: 1 addition & 0 deletions tests/system/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ type GenesisMutator func([]byte) []byte
// return state
// }
func (s *SystemUnderTest) ModifyGenesisJSON(t *testing.T, mutators ...GenesisMutator) {
s.ResetChain(t)
s.modifyGenesisJSON(t, mutators...)
}

Expand Down
Loading