* Provide source, builder and codehash information in store code proposal message * Make linter happy * Update x/wasm/simulation/proposals.go Co-authored-by: Alexander Peters <alpe@users.noreply.github.com> * Update x/wasm/client/cli/gov_tx.go * Update x/wasm/client/cli/gov_tx.go * Bump github.com/cosmos/gogoproto from 1.4.2 to 1.4.3 Bumps [github.com/cosmos/gogoproto](https://github.com/cosmos/gogoproto) from 1.4.2 to 1.4.3. - [Release notes](https://github.com/cosmos/gogoproto/releases) - [Changelog](https://github.com/cosmos/gogoproto/blob/main/CHANGELOG.md) - [Commits](https://github.com/cosmos/gogoproto/compare/v1.4.2...v1.4.3) --- updated-dependencies: - dependency-name: github.com/cosmos/gogoproto dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> * Update authz grant examples * Enable larger wasm bytecode upload for gov proposals (#1095) * Enable larger wasm bytecode upload for gov proposals * Set max proposal wasm code size to 3MB * Bump SDK to v0.45.11 * Fix license head * Fix README header * Bump version go to 1.19 (#1044) * bump go 1.19 * add change log * correct change log * Provide source, builder and codehash information in store code proposal message * Implement source, builder, code_info for StoreAndInstantiateProposal * Apply review recommendations * Make linter happy * Fix tests * Formatting only Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Alexander Peters <alpe@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Giancarlos Salas <giansalex@gmail.com> Co-authored-by: pinosu <95283998+pinosu@users.noreply.github.com> Co-authored-by: GNaD13 <89174180+GNaD13@users.noreply.github.com>
382 lines
14 KiB
Go
382 lines
14 KiB
Go
package client
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/cosmos/cosmos-sdk/client"
|
|
"github.com/cosmos/cosmos-sdk/client/flags"
|
|
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
|
"github.com/gorilla/mux"
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/CosmWasm/wasmd/x/wasm/keeper"
|
|
)
|
|
|
|
func TestGovRestHandlers(t *testing.T) {
|
|
type dict map[string]interface{}
|
|
var (
|
|
anyAddress = "cosmos100dejzacpanrldpjjwksjm62shqhyss44jf5xz"
|
|
aBaseReq = dict{
|
|
"from": anyAddress,
|
|
"memo": "rest test",
|
|
"chain_id": "testing",
|
|
"account_number": "1",
|
|
"sequence": "1",
|
|
"fees": []dict{{"denom": "ustake", "amount": "1000000"}},
|
|
}
|
|
)
|
|
encodingConfig := keeper.MakeEncodingConfig(t)
|
|
clientCtx := client.Context{}.
|
|
WithCodec(encodingConfig.Marshaler).
|
|
WithTxConfig(encodingConfig.TxConfig).
|
|
WithLegacyAmino(encodingConfig.Amino).
|
|
WithInput(os.Stdin).
|
|
WithAccountRetriever(authtypes.AccountRetriever{}).
|
|
WithBroadcastMode(flags.BroadcastBlock).
|
|
WithChainID("testing")
|
|
|
|
// router setup as in gov/client/rest/tx.go
|
|
propSubRtr := mux.NewRouter().PathPrefix("/gov/proposals").Subrouter()
|
|
for _, ph := range ProposalHandlers {
|
|
r := ph.RESTHandler(clientCtx)
|
|
propSubRtr.HandleFunc(fmt.Sprintf("/%s", r.SubRoute), r.Handler).Methods("POST")
|
|
}
|
|
|
|
specs := map[string]struct {
|
|
srcBody dict
|
|
srcPath string
|
|
expCode int
|
|
}{
|
|
"store-code": {
|
|
srcPath: "/gov/proposals/wasm_store_code",
|
|
srcBody: dict{
|
|
"title": "Test Proposal",
|
|
"description": "My proposal",
|
|
"type": "store-code",
|
|
"run_as": "cosmos100dejzacpanrldpjjwksjm62shqhyss44jf5xz",
|
|
"wasm_byte_code": []byte("valid wasm byte code"),
|
|
"source": "https://example.com/",
|
|
"builder": "cosmwasm/workspace-optimizer:v0.12.9",
|
|
"code_hash": "79F174F09BFE3F83398BF7C147929D5F735161BD46D645E85216BB13BF91D42D",
|
|
"instantiate_permission": dict{
|
|
"permission": "OnlyAddress",
|
|
"address": "cosmos1ve557a5g9yw2g2z57js3pdmcvd5my6g8ze20np",
|
|
},
|
|
"deposit": []dict{{"denom": "ustake", "amount": "10"}},
|
|
"proposer": "cosmos1ve557a5g9yw2g2z57js3pdmcvd5my6g8ze20np",
|
|
"base_req": aBaseReq,
|
|
},
|
|
expCode: http.StatusOK,
|
|
},
|
|
"store-code without verification info": {
|
|
srcPath: "/gov/proposals/wasm_store_code",
|
|
srcBody: dict{
|
|
"title": "Test Proposal",
|
|
"description": "My proposal",
|
|
"type": "store-code",
|
|
"run_as": "cosmos100dejzacpanrldpjjwksjm62shqhyss44jf5xz",
|
|
"wasm_byte_code": []byte("valid wasm byte code"),
|
|
"instantiate_permission": dict{
|
|
"permission": "OnlyAddress",
|
|
"address": "cosmos1ve557a5g9yw2g2z57js3pdmcvd5my6g8ze20np",
|
|
},
|
|
"deposit": []dict{{"denom": "ustake", "amount": "10"}},
|
|
"proposer": "cosmos1ve557a5g9yw2g2z57js3pdmcvd5my6g8ze20np",
|
|
"base_req": aBaseReq,
|
|
},
|
|
expCode: http.StatusOK,
|
|
},
|
|
"store-code without permission": {
|
|
srcPath: "/gov/proposals/wasm_store_code",
|
|
srcBody: dict{
|
|
"title": "Test Proposal",
|
|
"description": "My proposal",
|
|
"type": "store-code",
|
|
"run_as": "cosmos100dejzacpanrldpjjwksjm62shqhyss44jf5xz",
|
|
"wasm_byte_code": []byte("valid wasm byte code"),
|
|
"source": "https://example.com/",
|
|
"builder": "cosmwasm/workspace-optimizer:v0.12.9",
|
|
"code_hash": "79F174F09BFE3F83398BF7C147929D5F735161BD46D645E85216BB13BF91D42D",
|
|
"deposit": []dict{{"denom": "ustake", "amount": "10"}},
|
|
"proposer": "cosmos1ve557a5g9yw2g2z57js3pdmcvd5my6g8ze20np",
|
|
"base_req": aBaseReq,
|
|
},
|
|
expCode: http.StatusOK,
|
|
},
|
|
"store-code invalid permission": {
|
|
srcPath: "/gov/proposals/wasm_store_code",
|
|
srcBody: dict{
|
|
"title": "Test Proposal",
|
|
"description": "My proposal",
|
|
"type": "store-code",
|
|
"run_as": "cosmos100dejzacpanrldpjjwksjm62shqhyss44jf5xz",
|
|
"wasm_byte_code": []byte("valid wasm byte code"),
|
|
"source": "https://example.com/",
|
|
"builder": "cosmwasm/workspace-optimizer:v0.12.9",
|
|
"code_hash": "79F174F09BFE3F83398BF7C147929D5F735161BD46D645E85216BB13BF91D42D",
|
|
"instantiate_permission": dict{
|
|
"permission": "Nobody",
|
|
"address": "cosmos1ve557a5g9yw2g2z57js3pdmcvd5my6g8ze20np",
|
|
},
|
|
"deposit": []dict{{"denom": "ustake", "amount": "10"}},
|
|
"proposer": "cosmos1ve557a5g9yw2g2z57js3pdmcvd5my6g8ze20np",
|
|
"base_req": aBaseReq,
|
|
},
|
|
expCode: http.StatusBadRequest,
|
|
},
|
|
"store-code with incomplete proposal data: blank title": {
|
|
srcPath: "/gov/proposals/wasm_store_code",
|
|
srcBody: dict{
|
|
"title": "",
|
|
"description": "My proposal",
|
|
"type": "store-code",
|
|
"run_as": "cosmos100dejzacpanrldpjjwksjm62shqhyss44jf5xz",
|
|
"wasm_byte_code": []byte("valid wasm byte code"),
|
|
"source": "https://example.com/",
|
|
"code_hash": "79F174F09BFE3F83398BF7C147929D5F735161BD46D645E85216BB13BF91D42D",
|
|
"builder": "cosmwasm/workspace-optimizer:v0.12.9",
|
|
"instantiate_permission": dict{
|
|
"permission": "OnlyAddress",
|
|
"address": "cosmos1ve557a5g9yw2g2z57js3pdmcvd5my6g8ze20np",
|
|
},
|
|
"deposit": []dict{{"denom": "ustake", "amount": "10"}},
|
|
"proposer": "cosmos1ve557a5g9yw2g2z57js3pdmcvd5my6g8ze20np",
|
|
"base_req": aBaseReq,
|
|
},
|
|
expCode: http.StatusBadRequest,
|
|
},
|
|
"store-code with incomplete content data: no wasm_byte_code": {
|
|
srcPath: "/gov/proposals/wasm_store_code",
|
|
srcBody: dict{
|
|
"title": "Test Proposal",
|
|
"description": "My proposal",
|
|
"type": "store-code",
|
|
"run_as": "cosmos100dejzacpanrldpjjwksjm62shqhyss44jf5xz",
|
|
"wasm_byte_code": "",
|
|
"builder": "cosmwasm/workspace-optimizer:v0.12.9",
|
|
"source": "https://example.com/",
|
|
"code_hash": "79F174F09BFE3F83398BF7C147929D5F735161BD46D645E85216BB13BF91D42D",
|
|
"instantiate_permission": dict{
|
|
"permission": "OnlyAddress",
|
|
"address": "cosmos1ve557a5g9yw2g2z57js3pdmcvd5my6g8ze20np",
|
|
},
|
|
"deposit": []dict{{"denom": "ustake", "amount": "10"}},
|
|
"proposer": "cosmos1ve557a5g9yw2g2z57js3pdmcvd5my6g8ze20np",
|
|
"base_req": aBaseReq,
|
|
},
|
|
expCode: http.StatusBadRequest,
|
|
},
|
|
"store-code with incomplete content data: no builder": {
|
|
srcPath: "/gov/proposals/wasm_store_code",
|
|
srcBody: dict{
|
|
"title": "Test Proposal",
|
|
"description": "My proposal",
|
|
"type": "store-code",
|
|
"run_as": "cosmos100dejzacpanrldpjjwksjm62shqhyss44jf5xz",
|
|
"wasm_byte_code": "",
|
|
"source": "https://example.com/",
|
|
"code_hash": "79F174F09BFE3F83398BF7C147929D5F735161BD46D645E85216BB13BF91D42D",
|
|
"instantiate_permission": dict{
|
|
"permission": "OnlyAddress",
|
|
"address": "cosmos1ve557a5g9yw2g2z57js3pdmcvd5my6g8ze20np",
|
|
},
|
|
"deposit": []dict{{"denom": "ustake", "amount": "10"}},
|
|
"proposer": "cosmos1ve557a5g9yw2g2z57js3pdmcvd5my6g8ze20np",
|
|
"base_req": aBaseReq,
|
|
},
|
|
expCode: http.StatusBadRequest,
|
|
},
|
|
"store-code with incomplete content data: no code hash": {
|
|
srcPath: "/gov/proposals/wasm_store_code",
|
|
srcBody: dict{
|
|
"title": "Test Proposal",
|
|
"description": "My proposal",
|
|
"type": "store-code",
|
|
"run_as": "cosmos100dejzacpanrldpjjwksjm62shqhyss44jf5xz",
|
|
"wasm_byte_code": "",
|
|
"builder": "cosmwasm/workspace-optimizer:v0.12.9",
|
|
"source": "https://example.com/",
|
|
"instantiate_permission": dict{
|
|
"permission": "OnlyAddress",
|
|
"address": "cosmos1ve557a5g9yw2g2z57js3pdmcvd5my6g8ze20np",
|
|
},
|
|
"deposit": []dict{{"denom": "ustake", "amount": "10"}},
|
|
"proposer": "cosmos1ve557a5g9yw2g2z57js3pdmcvd5my6g8ze20np",
|
|
"base_req": aBaseReq,
|
|
},
|
|
expCode: http.StatusBadRequest,
|
|
},
|
|
"store-code with incomplete content data: no source": {
|
|
srcPath: "/gov/proposals/wasm_store_code",
|
|
srcBody: dict{
|
|
"title": "Test Proposal",
|
|
"description": "My proposal",
|
|
"type": "store-code",
|
|
"run_as": "cosmos100dejzacpanrldpjjwksjm62shqhyss44jf5xz",
|
|
"wasm_byte_code": "",
|
|
"builder": "cosmwasm/workspace-optimizer:v0.12.9",
|
|
"code_hash": "79F174F09BFE3F83398BF7C147929D5F735161BD46D645E85216BB13BF91D42D",
|
|
"instantiate_permission": dict{
|
|
"permission": "OnlyAddress",
|
|
"address": "cosmos1ve557a5g9yw2g2z57js3pdmcvd5my6g8ze20np",
|
|
},
|
|
"deposit": []dict{{"denom": "ustake", "amount": "10"}},
|
|
"proposer": "cosmos1ve557a5g9yw2g2z57js3pdmcvd5my6g8ze20np",
|
|
"base_req": aBaseReq,
|
|
},
|
|
expCode: http.StatusBadRequest,
|
|
},
|
|
"instantiate contract": {
|
|
srcPath: "/gov/proposals/wasm_instantiate",
|
|
srcBody: dict{
|
|
"title": "Test Proposal",
|
|
"description": "My proposal",
|
|
"type": "instantiate",
|
|
"run_as": "cosmos100dejzacpanrldpjjwksjm62shqhyss44jf5xz",
|
|
"admin": "cosmos100dejzacpanrldpjjwksjm62shqhyss44jf5xz",
|
|
"code_id": "1",
|
|
"label": "https://example.com/",
|
|
"msg": dict{"recipient": "cosmos100dejzacpanrldpjjwksjm62shqhyss44jf5xz"},
|
|
"funds": []dict{{"denom": "ustake", "amount": "100"}},
|
|
"deposit": []dict{{"denom": "ustake", "amount": "10"}},
|
|
"proposer": "cosmos1ve557a5g9yw2g2z57js3pdmcvd5my6g8ze20np",
|
|
"base_req": aBaseReq,
|
|
},
|
|
expCode: http.StatusOK,
|
|
},
|
|
"migrate contract": {
|
|
srcPath: "/gov/proposals/wasm_migrate",
|
|
srcBody: dict{
|
|
"title": "Test Proposal",
|
|
"description": "My proposal",
|
|
"type": "migrate",
|
|
"contract": "cosmos14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s4hmalr",
|
|
"code_id": "1",
|
|
"msg": dict{"foo": "bar"},
|
|
"run_as": "cosmos100dejzacpanrldpjjwksjm62shqhyss44jf5xz",
|
|
"deposit": []dict{{"denom": "ustake", "amount": "10"}},
|
|
"proposer": "cosmos1ve557a5g9yw2g2z57js3pdmcvd5my6g8ze20np",
|
|
"base_req": aBaseReq,
|
|
},
|
|
expCode: http.StatusOK,
|
|
},
|
|
"execute contract": {
|
|
srcPath: "/gov/proposals/wasm_execute",
|
|
srcBody: dict{
|
|
"title": "Test Proposal",
|
|
"description": "My proposal",
|
|
"type": "migrate",
|
|
"contract": "cosmos14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s4hmalr",
|
|
"msg": dict{"foo": "bar"},
|
|
"run_as": "cosmos100dejzacpanrldpjjwksjm62shqhyss44jf5xz",
|
|
"deposit": []dict{{"denom": "ustake", "amount": "10"}},
|
|
"proposer": "cosmos1ve557a5g9yw2g2z57js3pdmcvd5my6g8ze20np",
|
|
"base_req": aBaseReq,
|
|
},
|
|
expCode: http.StatusOK,
|
|
},
|
|
"execute contract fails with no run_as": {
|
|
srcPath: "/gov/proposals/wasm_execute",
|
|
srcBody: dict{
|
|
"title": "Test Proposal",
|
|
"description": "My proposal",
|
|
"type": "migrate",
|
|
"contract": "cosmos14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s4hmalr",
|
|
"msg": dict{"foo": "bar"},
|
|
"deposit": []dict{{"denom": "ustake", "amount": "10"}},
|
|
"proposer": "cosmos1ve557a5g9yw2g2z57js3pdmcvd5my6g8ze20np",
|
|
"base_req": aBaseReq,
|
|
},
|
|
expCode: http.StatusBadRequest,
|
|
},
|
|
"execute contract fails with no message": {
|
|
srcPath: "/gov/proposals/wasm_execute",
|
|
srcBody: dict{
|
|
"title": "Test Proposal",
|
|
"description": "My proposal",
|
|
"type": "migrate",
|
|
"contract": "cosmos14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s4hmalr",
|
|
"run_as": "cosmos100dejzacpanrldpjjwksjm62shqhyss44jf5xz",
|
|
"deposit": []dict{{"denom": "ustake", "amount": "10"}},
|
|
"proposer": "cosmos1ve557a5g9yw2g2z57js3pdmcvd5my6g8ze20np",
|
|
"base_req": aBaseReq,
|
|
},
|
|
expCode: http.StatusBadRequest,
|
|
},
|
|
"sudo contract": {
|
|
srcPath: "/gov/proposals/wasm_sudo",
|
|
srcBody: dict{
|
|
"title": "Test Proposal",
|
|
"description": "My proposal",
|
|
"type": "migrate",
|
|
"contract": "cosmos14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s4hmalr",
|
|
"msg": dict{"foo": "bar"},
|
|
"deposit": []dict{{"denom": "ustake", "amount": "10"}},
|
|
"proposer": "cosmos1ve557a5g9yw2g2z57js3pdmcvd5my6g8ze20np",
|
|
"base_req": aBaseReq,
|
|
},
|
|
expCode: http.StatusOK,
|
|
},
|
|
"sudo contract fails with no message": {
|
|
srcPath: "/gov/proposals/wasm_sudo",
|
|
srcBody: dict{
|
|
"title": "Test Proposal",
|
|
"description": "My proposal",
|
|
"type": "migrate",
|
|
"contract": "cosmos14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s4hmalr",
|
|
"deposit": []dict{{"denom": "ustake", "amount": "10"}},
|
|
"proposer": "cosmos1ve557a5g9yw2g2z57js3pdmcvd5my6g8ze20np",
|
|
"base_req": aBaseReq,
|
|
},
|
|
expCode: http.StatusBadRequest,
|
|
},
|
|
"update contract admin": {
|
|
srcPath: "/gov/proposals/wasm_update_admin",
|
|
srcBody: dict{
|
|
"title": "Test Proposal",
|
|
"description": "My proposal",
|
|
"type": "migrate",
|
|
"contract": "cosmos14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s4hmalr",
|
|
"new_admin": "cosmos100dejzacpanrldpjjwksjm62shqhyss44jf5xz",
|
|
"deposit": []dict{{"denom": "ustake", "amount": "10"}},
|
|
"proposer": "cosmos1ve557a5g9yw2g2z57js3pdmcvd5my6g8ze20np",
|
|
"base_req": aBaseReq,
|
|
},
|
|
expCode: http.StatusOK,
|
|
},
|
|
"clear contract admin": {
|
|
srcPath: "/gov/proposals/wasm_clear_admin",
|
|
srcBody: dict{
|
|
"title": "Test Proposal",
|
|
"description": "My proposal",
|
|
"type": "migrate",
|
|
"contract": "cosmos14hj2tavq8fpesdwxxcu44rty3hh90vhujrvcmstl4zr3txmfvw9s4hmalr",
|
|
"deposit": []dict{{"denom": "ustake", "amount": "10"}},
|
|
"proposer": "cosmos1ve557a5g9yw2g2z57js3pdmcvd5my6g8ze20np",
|
|
"base_req": aBaseReq,
|
|
},
|
|
expCode: http.StatusOK,
|
|
},
|
|
}
|
|
for msg, spec := range specs {
|
|
t.Run(msg, func(t *testing.T) {
|
|
src, err := json.Marshal(spec.srcBody)
|
|
require.NoError(t, err)
|
|
|
|
// when
|
|
r := httptest.NewRequest("POST", spec.srcPath, bytes.NewReader(src))
|
|
w := httptest.NewRecorder()
|
|
propSubRtr.ServeHTTP(w, r)
|
|
|
|
// then
|
|
require.Equal(t, spec.expCode, w.Code, w.Body.String())
|
|
})
|
|
}
|
|
}
|