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

upd: wasmd 0.43 #117

Merged
merged 62 commits into from
Nov 3, 2023
Merged
Changes from 1 commit
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
8627f85
style: lint wasmd in the same manner as cosmos-sdk (#1537)
faddat Jul 31, 2023
ae964a8
Bump bufbuild/buf-setup-action from 1.25.0 to 1.25.1 (#1541)
dependabot[bot] Aug 3, 2023
dc970c4
marshaler to codec (#1545)
faddat Aug 4, 2023
a2373f0
remove "check" from make test-all (#1548)
faddat Aug 4, 2023
33df4ae
Bump bufbuild/buf-setup-action from 1.25.1 to 1.26.0 (#1549)
dependabot[bot] Aug 11, 2023
08c517b
Fix label validation error (#1555)
pinosu Aug 17, 2023
3de2c49
Bump bufbuild/buf-setup-action from 1.26.0 to 1.26.1 (#1556)
dependabot[bot] Aug 17, 2023
7078c13
Bump cosmossdk.io/math from 1.0.1 to 1.1.2 (#1566)
dependabot[bot] Aug 22, 2023
881d6a7
Improve ToWasmVMGas/FromWasmVMGas code level documentation (#1564)
webmaster128 Aug 24, 2023
bfaf589
Fix gas calculation (#1567)
chipshort Aug 24, 2023
9e50a42
Bump actions/checkout from 3.5.3 to 3.6.0 (#1572)
dependabot[bot] Aug 25, 2023
acfe1e4
fix: make sure wasmvm cache metrics collector after VM setup
dadamu Aug 28, 2023
7c6069d
Merge pull request #1575 from desmos-labs/paul/fix-wasmvm-cache-metri…
alpe Aug 28, 2023
4595e6d
Fail fast on wasmvm cache metric setup
alpe Aug 28, 2023
78b5af2
Merge pull request #1576 from CosmWasm/1575_test
alpe Aug 28, 2023
baf3357
Add unit test for gas calculation
pinosu Aug 29, 2023
0d3bfce
Rename key store key attribute to be more concrete
alpe Aug 30, 2023
1f49d75
Merge pull request #1585 from CosmWasm/rename_key
alpe Aug 31, 2023
daf48ea
Merge pull request #1582 from CosmWasm/gas_unit_test
alpe Aug 31, 2023
0371b65
Bump github.com/cosmos/ibc-go/v7 from 7.2.0 to 7.3.0 (#1594)
dependabot[bot] Sep 1, 2023
2ca9379
Bump cosmos-sdk to v0.47.5
pinosu Sep 4, 2023
ffcfa8d
Remove Wasmer references
pinosu Sep 4, 2023
55ad68b
Bump actions/checkout from 3.6.0 to 4.0.0
dependabot[bot] Sep 5, 2023
1082ad5
Merge pull request #1603 from CosmWasm/dependabot/github_actions/acti…
alpe Sep 5, 2023
0903d63
Merge pull request #1598 from CosmWasm/1595-bump_sdk_0.47.5
alpe Sep 5, 2023
1149653
Merge pull request #1599 from CosmWasm/1596-remove_wasmer_ref
alpe Sep 5, 2023
51aae54
Deactivate thelper for linter
alpe Sep 5, 2023
086c052
Merge pull request #1604 from CosmWasm/linter_no_thelper
alpe Sep 5, 2023
3fc9224
Bump github.com/cosmos/iavl from 0.20.0 to 0.20.1
dependabot[bot] Sep 6, 2023
f1835a1
Add logging for query err before redacting (#1605)
pinosu Sep 6, 2023
7bd6566
Merge pull request #1606 from CosmWasm/dependabot/go_modules/github.c…
alpe Sep 6, 2023
9e3904c
test: add test cases in ContractsByCode
170210 Sep 7, 2023
cb887ee
Merge pull request #1607 from 170210/modify_wasmd_test
alpe Sep 7, 2023
87dce54
Add StoreAndMigrateContract proposal (#1539)
pinosu Sep 7, 2023
3d9d92c
Wasmvm 1.4 upgrade (#1590)
alpe Sep 7, 2023
0f82c95
Linter only (#1609)
alpe Sep 7, 2023
09b5008
Remove legacy gov proposal dependencies (#1587)
pinosu Sep 7, 2023
965e28c
Restrict pagination on all state query
alpe Sep 12, 2023
e81d655
Start rework channel query
alpe Sep 12, 2023
177c0a9
Test channels query
alpe Sep 13, 2023
d5fa278
Handle query for non ibc contracts
alpe Sep 13, 2023
42f3192
Merge pull request #1619 from CosmWasm/queries
alpe Sep 14, 2023
dd22204
Add store code authz (#1591)
pinosu Sep 14, 2023
e0bfaa5
Merge pull request #1620 from CosmWasm/channel_query
alpe Sep 14, 2023
b72d182
Ensure some contraints and limits on pin/unpin code ids
alpe Sep 13, 2023
6a2bffd
Add grant system tests (#1626)
pinosu Sep 15, 2023
7dba5c7
Merge pull request #1624 from CosmWasm/upper_limit
alpe Sep 18, 2023
7dc2d0c
Fix genesis import with predictable addresses
alpe Sep 18, 2023
c12e85e
Merge pull request #1630 from CosmWasm/1629_genesis
alpe Sep 18, 2023
afa85da
Set default query limit and ensure constraints (#1632)
alpe Sep 18, 2023
03f3c72
Update changelog for 0.42.0 release (#1633)
pinosu Sep 20, 2023
06c6385
Merge branch 'cosmwasm/v0.42.0' into upd/neutron-upd-0.42
Sep 27, 2023
a52bfa8
merge fixes
Sep 27, 2023
1dd39da
fixed tests
swelf19 Sep 27, 2023
5c6517e
regenerated proto
swelf19 Sep 27, 2023
3f634a3
Add msg update contract label (backport #1640) (#1642)
mergify[bot] Sep 28, 2023
cb9f569
Remove gov v1beta1 dependencies and deprecated proposals (#1645)
pinosu Oct 4, 2023
0e60308
Retract v0.42.0 release
pinosu Oct 6, 2023
9a569eb
Merge pull request #1655 from CosmWasm/mergify/bp/releases/v0.4x/pr-1652
alpe Oct 9, 2023
7270ccd
Bump wasmvm to v1.4.1 - bugfix (#1658)
alpe Oct 9, 2023
c51dcca
Update changelog for v0.43.0 release (#1662)
pinosu Oct 10, 2023
4e32ed6
Merge branch 'cosmwasm-orig-0.43.0' into upd/neutron-upd-0.43
swelf19 Oct 24, 2023
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
Prev Previous commit
Next Next commit
Add grant system tests (CosmWasm#1626)
* Add grant system tests

* Add unpermissioned chain test case

* Fix tests

* Update cli and fix feedbacks

* Revisit CLI and system tests (CosmWasm#1627)

* Restructure CLI; fix system test

* Review feedback

---------

Co-authored-by: Alexander Peters <alpe@users.noreply.github.com>
pinosu and alpe authored Sep 15, 2023
commit 6a2bffd479acd212d76ac92681b1b6ec099e649d
17 changes: 16 additions & 1 deletion tests/system/cli.go
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@ package system

import (
"fmt"
"io"
"os/exec"
"path/filepath"
"strconv"
@@ -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, " "))
}
@@ -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))
@@ -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")
1 change: 1 addition & 0 deletions tests/system/fraud_test.go
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@ import (
)

func TestRecursiveMsgsExternalTrigger(t *testing.T) {
sut.ResetChain(t)
const maxBlockGas = 2_000_000
sut.ModifyGenesisJSON(t, SetConsensusMaxGas(t, maxBlockGas))
sut.StartChain(t)
12 changes: 12 additions & 0 deletions tests/system/genesis_io.go
Original file line number Diff line number Diff line change
@@ -31,3 +31,15 @@ func GetGenesisBalance(rawGenesis []byte, addr string) sdk.Coins {
}
return r
}

// SetCodeUploadPermission sets the code upload permissions
func SetCodeUploadPermission(t *testing.T, permission string, addresses ...string) GenesisMutator {
return func(genesis []byte) []byte {
t.Helper()
state, err := sjson.Set(string(genesis), "app_state.wasm.params.code_upload_access.permission", permission)
require.NoError(t, err)
state, err = sjson.Set(state, "app_state.wasm.params.code_upload_access.addresses", addresses)
require.NoError(t, err)
return []byte(state)
}
}
62 changes: 62 additions & 0 deletions tests/system/permissioned_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
//go:build system_test

package system

import (
"os"
"path/filepath"
"testing"

"github.com/stretchr/testify/require"
"github.com/tidwall/gjson"
)

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

recoveredAddress := cli.AddKeyFromSeed("chain_authority", "aisle ship absurd wedding arch admit fringe foam cluster tide trim aisle salad shiver tackle palm glance wrist valley hamster couch crystal frozen chronic")
require.Equal(t, chainAuthorityAddress, recoveredAddress)
devAccount := cli.AddKey("dev_account")

sut.ModifyGenesisCLI(t,
[]string{"genesis", "add-genesis-account", chainAuthorityAddress, "100000000stake"},
)
sut.ModifyGenesisCLI(t,
[]string{"genesis", "add-genesis-account", devAccount, "100000000stake"},
)

sut.StartChain(t)

// query params
rsp := cli.CustomQuery("q", "wasm", "params")
permission := gjson.Get(rsp, "code_upload_access.permission").String()
addrRes := gjson.Get(rsp, "code_upload_access.addresses").Array()
require.Equal(t, 1, len(addrRes))

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

// chain_authority grant upload permission to dev_account
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="+chainAuthorityAddress, "--generate-only")
tx, ok := cli.run(args)
require.True(t, ok)

pathToTx := filepath.Join(t.TempDir(), "tx.json")
err := os.WriteFile(pathToTx, []byte(tx), os.FileMode(0o744))
require.NoError(t, err)

// store code via authz execution uses the given grant and should succeed
rsp = cli.CustomCommand("tx", "authz", "exec", pathToTx, "--from="+devAccount, "--gas=1500000", "--fees=2stake")
RequireTxSuccess(t, rsp)
}
43 changes: 26 additions & 17 deletions x/wasm/client/cli/tx.go
Original file line number Diff line number Diff line change
@@ -67,8 +67,7 @@ func GetTxCmd() *cobra.Command {
MigrateContractCmd(),
UpdateContractAdminCmd(),
ClearContractAdminCmd(),
GrantAuthorizationCmd(),
GrantStoreCodeAuthorizationCmd(),
GrantCmd(),
UpdateInstantiateConfigCmd(),
SubmitProposalCmd(),
)
@@ -415,17 +414,31 @@ func parseExecuteArgs(contractAddr, execMsg string, sender sdk.AccAddress, flags
}, nil
}

func GrantCmd() *cobra.Command {
txCmd := &cobra.Command{
Use: "grant",
Short: "Grant a authz permission",
DisableFlagParsing: true,
SilenceUsage: true,
}
txCmd.AddCommand(
GrantAuthorizationCmd(),
GrantStoreCodeAuthorizationCmd(),
)
return txCmd
}

func GrantAuthorizationCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "grant [grantee] [message_type=\"execution\"|\"migration\"] [contract_addr_bech32] --allow-raw-msgs [msg1,msg2,...] --allow-msg-keys [key1,key2,...] --allow-all-messages",
Short: "Grant authorization to an address",
Use: "contract [message_type=\"execution\"|\"migration\"] [grantee] [contract_addr_bech32] --allow-raw-msgs [msg1,msg2,...] --allow-msg-keys [key1,key2,...] --allow-all-messages",
Short: "Grant authorization to interact with a contract on behalf of you",
Long: fmt.Sprintf(`Grant authorization to an address.
Examples:
$ %s tx grant <grantee_addr> execution <contract_addr> --allow-all-messages --max-calls 1 --no-token-transfer --expiration 1667979596
$ %s tx grant contract execution <grantee_addr> <contract_addr> --allow-all-messages --max-calls 1 --no-token-transfer --expiration 1667979596

$ %s tx grant <grantee_addr> execution <contract_addr> --allow-all-messages --max-funds 100000uwasm --expiration 1667979596
$ %s tx grant contract execution <grantee_addr> <contract_addr> --allow-all-messages --max-funds 100000uwasm --expiration 1667979596

$ %s tx grant <grantee_addr> execution <contract_addr> --allow-all-messages --max-calls 5 --max-funds 100000uwasm --expiration 1667979596
$ %s tx grant contract execution <grantee_addr> <contract_addr> --allow-all-messages --max-calls 5 --max-funds 100000uwasm --expiration 1667979596
`, version.AppName, version.AppName, version.AppName),
Args: cobra.ExactArgs(3),
RunE: func(cmd *cobra.Command, args []string) error {
@@ -560,15 +573,15 @@ $ %s tx grant <grantee_addr> execution <contract_addr> --allow-all-messages --ma

func GrantStoreCodeAuthorizationCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "grant [grantee] store-code [code_hash:permission]",
Short: "Grant authorization to an address",
Use: "store-code [grantee] [code_hash:permission]",
Short: "Grant authorization to upload contract code on behalf of you",
Long: fmt.Sprintf(`Grant authorization to an address.
Examples:
$ %s tx grant <grantee_addr> store-code 13a1fc994cc6d1c81b746ee0c0ff6f90043875e0bf1d9be6b7d779fc978dc2a5:everybody 1wqrtry681b746ee0c0ff6f90043875e0bf1d9be6b7d779fc978dc2a5:nobody --expiration 1667979596
$ %s tx grant store-code <grantee_addr> 13a1fc994cc6d1c81b746ee0c0ff6f90043875e0bf1d9be6b7d779fc978dc2a5:everybody 1wqrtry681b746ee0c0ff6f90043875e0bf1d9be6b7d779fc978dc2a5:nobody --expiration 1667979596

$ %s tx grant <grantee_addr> store-code *:%s1l2rsakp388kuv9k8qzq6lrm9taddae7fpx59wm,%s1vx8knpllrj7n963p9ttd80w47kpacrhuts497x
$ %s tx grant store-code <grantee_addr> *:%s1l2rsakp388kuv9k8qzq6lrm9taddae7fpx59wm,%s1vx8knpllrj7n963p9ttd80w47kpacrhuts497x
`, version.AppName, version.AppName, version.AppName, version.AppName),
Args: cobra.MinimumNArgs(3),
Args: cobra.MinimumNArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
@@ -580,11 +593,7 @@ $ %s tx grant <grantee_addr> store-code *:%s1l2rsakp388kuv9k8qzq6lrm9taddae7fpx5
return err
}

if args[1] != "store-code" {
return fmt.Errorf("%s authorization type not supported", args[1])
}

grants, err := parseStoreCodeGrants(args[2:])
grants, err := parseStoreCodeGrants(args[1:])
if err != nil {
return err
}
4 changes: 2 additions & 2 deletions x/wasm/types/authz.go
Original file line number Diff line number Diff line change
@@ -51,7 +51,7 @@ func (a *StoreCodeAuthorization) Accept(ctx sdk.Context, msg sdk.Msg) (authztype
}

code := storeMsg.WASMByteCode
permission := *storeMsg.InstantiatePermission
permission := storeMsg.InstantiatePermission

if ioutils.IsGzip(code) {
gasRegister, ok := GasRegisterFromContext(ctx)
@@ -127,7 +127,7 @@ func (g CodeGrant) ValidateBasic() error {
}

// Accept checks if checksum and permission match the grant
func (g CodeGrant) Accept(checksum []byte, permission AccessConfig) bool {
func (g CodeGrant) Accept(checksum []byte, permission *AccessConfig) bool {
if !strings.EqualFold(string(g.CodeHash), CodehashWildcard) && !bytes.EqualFold(g.CodeHash, checksum) {
return false
}