Skip to content

Commit

Permalink
feat: cosmwasm migrate contract (#1122)
Browse files Browse the repository at this point in the history
* feat: cosmwasm migrate contract (#1121)

* migrate contract

* consume codeID

* fix

---------

Co-authored-by: Reece Williams <[email protected]>
(cherry picked from commit e7c0c39)

# Conflicts:
#	chain/cosmos/chain_node.go

* move to module_cosmwasm

---------

Co-authored-by: Bi Phan <[email protected]>
Co-authored-by: Reece Williams <[email protected]>
  • Loading branch information
3 people authored May 10, 2024
1 parent 0559b76 commit c0037a7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
5 changes: 5 additions & 0 deletions chain/cosmos/cosmos_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,11 @@ func (c *CosmosChain) ExecuteContract(ctx context.Context, keyName string, contr
return c.getFullNode().ExecuteContract(ctx, keyName, contractAddress, message, extraExecTxArgs...)
}

// MigrateContract performs contract migration
func (c *CosmosChain) MigrateContract(ctx context.Context, keyName string, contractAddress string, codeID string, message string, extraExecTxArgs ...string) (res *types.TxResponse, err error) {
return c.getFullNode().MigrateContract(ctx, keyName, contractAddress, codeID, message, extraExecTxArgs...)
}

// QueryContract performs a smart query, taking in a query struct and returning a error with the response struct populated.
func (c *CosmosChain) QueryContract(ctx context.Context, contractAddress string, query any, response any) error {
return c.getFullNode().QueryContract(ctx, contractAddress, query, response)
Expand Down
23 changes: 23 additions & 0 deletions chain/cosmos/module_cosmwasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"path"
"path/filepath"

"github.com/cosmos/cosmos-sdk/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/strangelove-ventures/interchaintest/v8/testutil"
)
Expand Down Expand Up @@ -160,6 +161,28 @@ func (tn *ChainNode) QueryContract(ctx context.Context, contractAddress string,
return err
}

// MigrateContract performs contract migration
func (tn *ChainNode) MigrateContract(ctx context.Context, keyName string, contractAddress string, codeID string, message string, extraExecTxArgs ...string) (res *types.TxResponse, err error) {
cmd := []string{"wasm", "migrate", contractAddress, codeID, message}
cmd = append(cmd, extraExecTxArgs...)

txHash, err := tn.ExecTx(ctx, keyName, cmd...)
if err != nil {
return &types.TxResponse{}, err
}

txResp, err := tn.GetTransaction(tn.CliContext(), txHash)
if err != nil {
return &types.TxResponse{}, fmt.Errorf("failed to get transaction %s: %w", txHash, err)
}

if txResp.Code != 0 {
return txResp, fmt.Errorf("error in transaction (code: %d): %s", txResp.Code, txResp.RawLog)
}

return txResp, nil
}

// StoreClientContract takes a file path to a client smart contract and stores it on-chain. Returns the contracts code id.
func (tn *ChainNode) StoreClientContract(ctx context.Context, keyName string, fileName string, extraExecTxArgs ...string) (string, error) {
content, err := os.ReadFile(fileName)
Expand Down

0 comments on commit c0037a7

Please sign in to comment.