Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -1010,14 +1010,15 @@ pub fn execute(deps: DepsMut, env: Env, info: MessageInfo, msg: ExecuteMsg) -> S
code_hash,
label,
msg,
admin,
} => Ok(Response::new()
.add_message(CosmosMsg::Wasm(WasmMsg::Instantiate {
code_id,
code_hash,
msg: Binary(msg.as_bytes().into()),
funds: vec![],
label,
admin: None,
admin,
}))
.add_attribute("a", "a")),
ExecuteMsg::CallToExec {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ pub enum ExecuteMsg {
code_hash: String,
label: String,
msg: String,
admin: Option<String>,
},
CallToExec {
addr: String,
Expand Down
4 changes: 2 additions & 2 deletions go-cosmwasm/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions x/compute/internal/keeper/handler_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,7 @@ func EncodeWasmMsg(sender sdk.AccAddress, msg *v1wasmTypes.WasmMsg) ([]sdk.Msg,
InitMsg: msg.Instantiate.Msg,
InitFunds: coins,
CallbackSig: msg.Instantiate.CallbackSignature,
Admin: msg.Instantiate.Admin,
}
return []sdk.Msg{&sdkMsg}, nil
case msg.Migrate != nil:
Expand Down
32 changes: 32 additions & 0 deletions x/compute/internal/keeper/secret_contracts_migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8232,3 +8232,35 @@ func TestMigrateEnvTxHash(t *testing.T) {
res.WasmEvents,
)
}

func TestContractInitsContractWithAdmin(t *testing.T) {
for _, testContract := range testContracts {
t.Run("v1 inits "+testContract.CosmWasmVersion, func(t *testing.T) {
ctx, keeper, codeID, _, walletA, privKeyA, _, _ := setupTest(t, TestContractPaths[v1Contract], sdk.NewCoins())

_, _, addr, _, initErr := initHelper(t, keeper, ctx, codeID, walletA, walletA, privKeyA, `{"nop":{}}`, true, true, defaultGasForTests)
require.Empty(t, initErr)

newCodeId, codeHash := uploadCode(ctx, t, keeper, testContract.WasmFilePath, walletA)

initMsg := fmt.Sprintf(`{"call_to_init":{"admin": "%s", "code_id":%d,"code_hash":"%s","msg":"%s","label":"1"}}`, addr.String(), newCodeId, codeHash, `{\"nop\":{}}`)
_, ctx, _, events, _, err := execHelper(t, keeper, ctx, addr, walletA, privKeyA, initMsg, false, true, math.MaxUint64, 0)
require.Empty(t, err)

var newContractBech32 string
for _, v := range events[1] {
if v.Key == "contract_address" {
newContractBech32 = v.Value
break
}
}
require.NotEmpty(t, newContractBech32)

address, error2 := sdk.AccAddressFromBech32(newContractBech32)
require.NoError(t, error2)
info := keeper.GetContractInfo(ctx, address)

require.Equal(t, addr.String(), info.Admin)
})
}
}
11 changes: 10 additions & 1 deletion x/compute/internal/keeper/test_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,16 @@ func TestHandler(k Keeper) sdk.Handler {
}

func handleInstantiate(ctx sdk.Context, k Keeper, msg *wasmtypes.MsgInstantiateContract) (*sdk.Result, error) {
contractAddr, data, err := k.Instantiate(ctx, msg.CodeID, msg.Sender, nil, msg.InitMsg, msg.Label, msg.InitFunds, msg.CallbackSig)
var admin sdk.AccAddress
var err error
if msg.Admin != "" {
admin, err = sdk.AccAddressFromBech32(msg.Admin)
if err != nil {
return nil, err
}
}

contractAddr, data, err := k.Instantiate(ctx, msg.CodeID, msg.Sender, admin, msg.InitMsg, msg.Label, msg.InitFunds, msg.CallbackSig)
if err != nil {
result := sdk.Result{}
result.Data = data
Expand Down