Skip to content

Commit

Permalink
merged orig v0.50
Browse files Browse the repository at this point in the history
  • Loading branch information
swelf19 committed Mar 4, 2024
1 parent 1e620a5 commit 564e5d1
Show file tree
Hide file tree
Showing 19 changed files with 1,187 additions and 882 deletions.
3 changes: 0 additions & 3 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -651,9 +651,6 @@ func NewWasmApp(
wasmOpts...,
)

// Set legacy router for backwards compatibility with gov v1beta1
app.GovKeeper.SetLegacyRouter(govRouter)

// Create Transfer Stack
var transferStack porttypes.IBCModule
transferStack = transfer.NewIBCModule(app.TransferKeeper)
Expand Down
3 changes: 2 additions & 1 deletion cmd/wasmd/genwasm.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package main

import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/spf13/cobra"

"github.com/cosmos/cosmos-sdk/client"

wasmcli "github.com/CosmWasm/wasmd/x/wasm/client/cli"
)

Expand Down
1,368 changes: 694 additions & 674 deletions docs/proto/proto-docs.md

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ require (
github.com/spf13/cast v1.5.1
github.com/spf13/cobra v1.8.0
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.16.0
github.com/spf13/viper v1.17.0
github.com/stretchr/testify v1.8.4
github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d
google.golang.org/genproto v0.0.0-20231016165738-49dd2c1f3d0b // indirect
Expand Down Expand Up @@ -51,7 +51,6 @@ require (
github.com/cosmos/ibc-go/v8 v8.0.0
github.com/distribution/reference v0.5.0
github.com/rs/zerolog v1.31.0
github.com/spf13/viper v1.17.0
google.golang.org/genproto/googleapis/api v0.0.0-20231012201019-e917dd12ba7a
)

Expand Down
15 changes: 8 additions & 7 deletions x/wasm/client/cli/genesis_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,18 @@ import (
"errors"
"fmt"

tmtypes "github.com/cometbft/cometbft/types"
"github.com/spf13/cobra"

errorsmod "cosmossdk.io/errors"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
"github.com/cosmos/cosmos-sdk/server"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/cosmos/cosmos-sdk/x/genutil"
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
"github.com/spf13/cobra"

"github.com/CosmWasm/wasmd/x/wasm/ioutils"
"github.com/CosmWasm/wasmd/x/wasm/keeper"
Expand Down Expand Up @@ -354,12 +355,12 @@ func hasAccountBalance(cmd *cobra.Command, appState map[string]json.RawMessage,
// GenesisData contains raw and unmarshalled data from the genesis file
type GenesisData struct {
GenesisFile string
GenDoc *tmtypes.GenesisDoc
GenDoc *genutiltypes.AppGenesis
AppState map[string]json.RawMessage
WasmModuleState *types.GenesisState
}

func NewGenesisData(genesisFile string, genDoc *tmtypes.GenesisDoc, appState map[string]json.RawMessage, wasmModuleState *types.GenesisState) *GenesisData {
func NewGenesisData(genesisFile string, genDoc *genutiltypes.AppGenesis, appState map[string]json.RawMessage, wasmModuleState *types.GenesisState) *GenesisData {
return &GenesisData{GenesisFile: genesisFile, GenDoc: genDoc, AppState: appState, WasmModuleState: wasmModuleState}
}

Expand Down Expand Up @@ -425,13 +426,13 @@ func (x DefaultGenesisIO) AlterWasmModuleState(cmd *cobra.Command, callback func
clientCtx := client.GetClientContextFromCmd(cmd)
wasmGenStateBz, err := clientCtx.Codec.MarshalJSON(g.WasmModuleState)
if err != nil {
return sdkerrors.Wrap(err, "marshal wasm genesis state")
return errorsmod.Wrap(err, "marshal wasm genesis state")
}

g.AppState[types.ModuleName] = wasmGenStateBz
appStateJSON, err := json.Marshal(g.AppState)
if err != nil {
return sdkerrors.Wrap(err, "marshal application genesis state")
return errorsmod.Wrap(err, "marshal application genesis state")
}

g.GenDoc.AppState = appStateJSON
Expand Down
26 changes: 12 additions & 14 deletions x/wasm/client/cli/genesis_msg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,14 @@ import (
"path"
"testing"

"github.com/cometbft/cometbft/libs/log"
tmtypes "github.com/cometbft/cometbft/types"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"cosmossdk.io/log"
"cosmossdk.io/math"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/crypto/hd"
Expand All @@ -22,10 +28,6 @@ import (
genutiltest "github.com/cosmos/cosmos-sdk/x/genutil/client/testutil"
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/CosmWasm/wasmd/x/wasm/keeper"
"github.com/CosmWasm/wasmd/x/wasm/types"
Expand Down Expand Up @@ -646,7 +648,6 @@ func TestGetAllContracts(t *testing.T) {
}

func setupGenesis(t *testing.T, wasmGenesis types.GenesisState, myWellFundedAccount string) string {

appCodec := keeper.MakeEncodingConfig(t).Codec
homeDir := t.TempDir()

Expand All @@ -659,26 +660,23 @@ func setupGenesis(t *testing.T, wasmGenesis types.GenesisState, myWellFundedAcco
bankGenesis.Balances = append(bankGenesis.Balances, banktypes.Balance{
// add a balance for the default sender account
Address: myWellFundedAccount,
Coins: sdk.NewCoins(sdk.NewCoin("stake", sdk.NewInt(10000000000))),
Coins: sdk.NewCoins(sdk.NewCoin("stake", math.NewInt(10000000000))),
})
appState[banktypes.ModuleName] = appCodec.MustMarshalJSON(bankGenesis)
appState[stakingtypes.ModuleName] = appCodec.MustMarshalJSON(stakingtypes.DefaultGenesisState())

appStateBz, err := json.Marshal(appState)
require.NoError(t, err)
genDoc := tmtypes.GenesisDoc{
ChainID: "testing",
AppState: appStateBz,
}
err = genutil.ExportGenesisFile(&genDoc, genFilename)
genDoc := genutiltypes.NewAppGenesisWithVersion("testing", appStateBz)
err = genutil.ExportGenesisFile(genDoc, genFilename)
require.NoError(t, err)

return homeDir
}

func executeCmdWithContext(t *testing.T, homeDir string, cmd *cobra.Command) error {
logger := log.NewNopLogger()
cfg, err := genutiltest.CreateDefaultTendermintConfig(homeDir)
cfg, err := genutiltest.CreateDefaultCometConfig(homeDir)
require.NoError(t, err)
appCodec := keeper.MakeEncodingConfig(t).Codec
serverCtx := server.NewContext(viper.New(), cfg, logger)
Expand Down
2 changes: 1 addition & 1 deletion x/wasm/ioutils/ioutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package ioutils
import (
"bytes"
"compress/gzip"
"errors"
"encoding/json"
"errors"
"io"

errorsmod "cosmossdk.io/errors"
Expand Down
1 change: 0 additions & 1 deletion x/wasm/keeper/addresses_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"testing"

tmbytes "github.com/cometbft/cometbft/libs/bytes"

"github.com/stretchr/testify/require"

sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down
4 changes: 2 additions & 2 deletions x/wasm/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ func InitGenesis(ctx sdk.Context, keeper *Keeper, data types.GenesisState, msgRo
for _, genTx := range data.GenMsgs {
msg := genTx.AsMsg()
if msg == nil {
return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "unknown message")
return nil, errorsmod.Wrapf(sdkerrors.ErrInvalidType, "unknown message")
}
handler := msgRouter.Handler(msg)
_, err := handler(ctx, msg)
if err != nil {
return nil, sdkerrors.Wrap(err, "genesis")
return nil, errorsmod.Wrap(err, "genesis")
}
}
return nil, nil
Expand Down
9 changes: 5 additions & 4 deletions x/wasm/keeper/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/stretchr/testify/require"

"cosmossdk.io/log"
"cosmossdk.io/math"
"cosmossdk.io/store"
storemetrics "cosmossdk.io/store/metrics"
storetypes "cosmossdk.io/store/types"
Expand Down Expand Up @@ -716,7 +717,7 @@ func TestSupportedGenMsgTypes(t *testing.T) {
Verifier: verifierAddress,
Beneficiary: beneficiaryAddress,
}.GetBytes(t),
Funds: sdk.NewCoins(sdk.NewCoin(denom, sdk.NewInt(10))),
Funds: sdk.NewCoins(sdk.NewCoin(denom, math.NewInt(10))),
},
},
},
Expand All @@ -734,8 +735,8 @@ func TestSupportedGenMsgTypes(t *testing.T) {
require.NoError(t, importState.ValidateBasic())
ctx, keepers := CreateDefaultTestInput(t)
keeper := keepers.WasmKeeper
ctx = ctx.WithBlockHeight(0).WithGasMeter(sdk.NewInfiniteGasMeter())
keepers.Faucet.Fund(ctx, myAddress, sdk.NewCoin(denom, sdk.NewInt(100)))
ctx = ctx.WithBlockHeight(0).WithGasMeter(storetypes.NewInfiniteGasMeter())
keepers.Faucet.Fund(ctx, myAddress, sdk.NewCoin(denom, math.NewInt(100)))

// when
_, err = InitGenesis(ctx, keeper, importState, TestHandler(keepers.ContractKeeper))
Expand All @@ -754,7 +755,7 @@ func TestSupportedGenMsgTypes(t *testing.T) {

// verify contract executed
gotBalance := keepers.BankKeeper.GetBalance(ctx, beneficiaryAddress, denom)
assert.Equal(t, sdk.NewCoin(denom, sdk.NewInt(10)), gotBalance)
assert.Equal(t, sdk.NewCoin(denom, math.NewInt(10)), gotBalance)
}

func setupKeeper(t *testing.T) (*Keeper, sdk.Context) {
Expand Down
2 changes: 1 addition & 1 deletion x/wasm/keeper/handler_plugin_encoders_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TestEncoding(t *testing.T) {

msg, err := codectypes.NewAnyWithValue(types.MsgStoreCodeFixture())
require.NoError(t, err)
proposalMsg := &v1.MsgSubmitProposal{
proposalMsg := &govv1.MsgSubmitProposal{
Proposer: addr1.String(),
Messages: []*codectypes.Any{msg},
InitialDeposit: sdk.NewCoins(sdk.NewInt64Coin("uatom", 12345)),
Expand Down
23 changes: 2 additions & 21 deletions x/wasm/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ func (k Keeper) instantiate(

initMsg, err := ioutils.CompactMsg(rawInitMsg)
if err != nil {
return nil, nil, sdkerrors.Wrapf(types.ErrInvalidMsg, "failed to compact init msg: %s", err.Error())
return nil, nil, errorsmod.Wrapf(types.ErrInvalidMsg, "failed to compact init msg: %s", err.Error())
}

if creator == nil {
Expand Down Expand Up @@ -434,7 +434,7 @@ func (k Keeper) migrate(

msg, err := ioutils.CompactMsg(rawMsg)
if err != nil {
return nil, sdkerrors.Wrapf(types.ErrInvalidMsg, "failed to compact migrate msg: %s", err.Error())
return nil, errorsmod.Wrapf(types.ErrInvalidMsg, "failed to compact migrate msg: %s", err.Error())
}

sdkCtx := sdk.UnwrapSDKContext(ctx)
Expand Down Expand Up @@ -663,25 +663,6 @@ func (k Keeper) setContractAdmin(ctx context.Context, contractAddress, caller, n
return nil
}

func (k Keeper) setContractLabel(ctx sdk.Context, contractAddress, caller sdk.AccAddress, newLabel string, authZ types.AuthorizationPolicy) error {
contractInfo := k.GetContractInfo(ctx, contractAddress)
if contractInfo == nil {
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "unknown contract")
}
if !authZ.CanModifyContract(contractInfo.AdminAddr(), caller) {
return errorsmod.Wrap(sdkerrors.ErrUnauthorized, "can not modify contract")
}
contractInfo.Label = newLabel
k.storeContractInfo(ctx, contractAddress, contractInfo)
ctx.EventManager().EmitEvent(sdk.NewEvent(
types.EventTypeUpdateContractLabel,
sdk.NewAttribute(types.AttributeKeyContractAddr, contractAddress.String()),
sdk.NewAttribute(types.AttributeKeyNewLabel, newLabel),
))

return nil
}

func (k Keeper) setContractLabel(ctx context.Context, contractAddress, caller sdk.AccAddress, newLabel string, authZ types.AuthorizationPolicy) error {
sdkCtx := sdk.UnwrapSDKContext(ctx)
contractInfo := k.GetContractInfo(sdkCtx, contractAddress)
Expand Down
Loading

0 comments on commit 564e5d1

Please sign in to comment.