From 0358c1c07caa43c9d8280ed2196379bf9b42c2a9 Mon Sep 17 00:00:00 2001 From: Alex Peters Date: Wed, 3 Mar 2021 11:12:28 +0100 Subject: [PATCH 1/2] Add data field to Instantiate response --- doc/proto.md | 1 + x/wasm/internal/keeper/ibc_test.go | 2 +- x/wasm/internal/keeper/keeper.go | 24 +-- x/wasm/internal/keeper/keeper_test.go | 56 ++++--- x/wasm/internal/keeper/legacy_querier_test.go | 4 +- x/wasm/internal/keeper/msg_server.go | 3 +- x/wasm/internal/keeper/proposal_handler.go | 2 +- x/wasm/internal/keeper/querier_test.go | 2 +- x/wasm/internal/keeper/reflect_test.go | 12 +- x/wasm/internal/keeper/staking_test.go | 8 +- x/wasm/internal/keeper/test_common.go | 27 ++-- .../keeper/wasmtesting/mock_engine.go | 5 + x/wasm/internal/types/tx.pb.go | 151 ++++++++++++------ x/wasm/internal/types/tx.proto | 2 + 14 files changed, 184 insertions(+), 115 deletions(-) diff --git a/doc/proto.md b/doc/proto.md index 3cdf5f0f87..262d98b8a1 100644 --- a/doc/proto.md +++ b/doc/proto.md @@ -756,6 +756,7 @@ MsgInstantiateContractResponse return instantiation result data | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | | address | [string](#string) | | Address is the bech32 address of the new contract instance. | +| data | [bytes](#bytes) | | Data contains base64-encoded bytes to returned from the contract | diff --git a/x/wasm/internal/keeper/ibc_test.go b/x/wasm/internal/keeper/ibc_test.go index dbf8145e7a..45519f6123 100644 --- a/x/wasm/internal/keeper/ibc_test.go +++ b/x/wasm/internal/keeper/ibc_test.go @@ -29,7 +29,7 @@ func TestBindingPortForIBCContractOnInstantiate(t *testing.T) { // create a second contract should give yet another portID (and different address) creator := RandomAccountAddress(t) - addr, err := keepers.WasmKeeper.Instantiate(ctx, example.CodeID, creator, nil, initMsgBz, "ibc-reflect-2", nil) + addr, _, err := keepers.WasmKeeper.Instantiate(ctx, example.CodeID, creator, nil, initMsgBz, "ibc-reflect-2", nil) require.NoError(t, err) require.NotEqual(t, example.Contract, addr) diff --git a/x/wasm/internal/keeper/keeper.go b/x/wasm/internal/keeper/keeper.go index 1b597e3de8..b9425a2b2f 100644 --- a/x/wasm/internal/keeper/keeper.go +++ b/x/wasm/internal/keeper/keeper.go @@ -215,28 +215,28 @@ func (k Keeper) importCode(ctx sdk.Context, codeID uint64, codeInfo types.CodeIn } // Instantiate creates an instance of a WASM contract -func (k Keeper) Instantiate(ctx sdk.Context, codeID uint64, creator, admin sdk.AccAddress, initMsg []byte, label string, deposit sdk.Coins) (sdk.AccAddress, error) { +func (k Keeper) Instantiate(ctx sdk.Context, codeID uint64, creator, admin sdk.AccAddress, initMsg []byte, label string, deposit sdk.Coins) (sdk.AccAddress, []byte, error) { return k.instantiate(ctx, codeID, creator, admin, initMsg, label, deposit, k.authZPolicy) } -func (k Keeper) instantiate(ctx sdk.Context, codeID uint64, creator, admin sdk.AccAddress, initMsg []byte, label string, deposit sdk.Coins, authZ AuthorizationPolicy) (sdk.AccAddress, error) { +func (k Keeper) instantiate(ctx sdk.Context, codeID uint64, creator, admin sdk.AccAddress, initMsg []byte, label string, deposit sdk.Coins, authZ AuthorizationPolicy) (sdk.AccAddress, []byte, error) { ctx.GasMeter().ConsumeGas(InstanceCost, "Loading CosmWasm module: init") // create contract address contractAddress := k.generateContractAddress(ctx, codeID) existingAcct := k.accountKeeper.GetAccount(ctx, contractAddress) if existingAcct != nil { - return nil, sdkerrors.Wrap(types.ErrAccountExists, existingAcct.GetAddress().String()) + return nil, nil, sdkerrors.Wrap(types.ErrAccountExists, existingAcct.GetAddress().String()) } // deposit initial contract funds if !deposit.IsZero() { if k.bankKeeper.BlockedAddr(creator) { - return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "blocked address can not be used") + return nil, nil, sdkerrors.Wrap(sdkerrors.ErrInvalidAddress, "blocked address can not be used") } sdkerr := k.bankKeeper.SendCoins(ctx, creator, contractAddress, deposit) if sdkerr != nil { - return nil, sdkerr + return nil, nil, sdkerr } } else { // create an empty account (so we don't have issues later) @@ -249,13 +249,13 @@ func (k Keeper) instantiate(ctx sdk.Context, codeID uint64, creator, admin sdk.A store := ctx.KVStore(k.storeKey) bz := store.Get(types.GetCodeKey(codeID)) if bz == nil { - return nil, sdkerrors.Wrap(types.ErrNotFound, "code") + return nil, nil, sdkerrors.Wrap(types.ErrNotFound, "code") } var codeInfo types.CodeInfo k.cdc.MustUnmarshalBinaryBare(bz, &codeInfo) if !authZ.CanInstantiateContract(codeInfo.InstantiateConfig, creator) { - return nil, sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "can not instantiate") + return nil, nil, sdkerrors.Wrap(sdkerrors.ErrUnauthorized, "can not instantiate") } // prepare params for contract instantiate call @@ -278,7 +278,7 @@ func (k Keeper) instantiate(ctx sdk.Context, codeID uint64, creator, admin sdk.A res, gasUsed, err := k.wasmer.Instantiate(codeInfo.CodeHash, env, info, initMsg, prefixStore, cosmwasmAPI, querier, gasMeter(ctx), gas) consumeGas(ctx, gasUsed) if err != nil { - return contractAddress, sdkerrors.Wrap(types.ErrInstantiateFailed, err.Error()) + return contractAddress, nil, sdkerrors.Wrap(types.ErrInstantiateFailed, err.Error()) } // emit all events from this contract itself @@ -292,13 +292,13 @@ func (k Keeper) instantiate(ctx sdk.Context, codeID uint64, creator, admin sdk.A // check for IBC flag report, err := k.wasmer.AnalyzeCode(codeInfo.CodeHash) if err != nil { - return contractAddress, sdkerrors.Wrap(types.ErrInstantiateFailed, err.Error()) + return contractAddress, nil, sdkerrors.Wrap(types.ErrInstantiateFailed, err.Error()) } if report.HasIBCEntryPoints { // register IBC port ibcPort, err := k.ensureIbcPort(ctx, contractAddress) if err != nil { - return nil, err + return nil, nil, err } contractInfo.IBCPortID = ibcPort } @@ -309,10 +309,10 @@ func (k Keeper) instantiate(ctx sdk.Context, codeID uint64, creator, admin sdk.A // then dispatch so that contract could be called back err = k.dispatchMessages(ctx, contractAddress, contractInfo.IBCPortID, res.Messages) if err != nil { - return nil, err + return nil, nil, err } - return contractAddress, nil + return contractAddress, res.Data, nil } // Execute executes the contract instance diff --git a/x/wasm/internal/keeper/keeper_test.go b/x/wasm/internal/keeper/keeper_test.go index 198251fd78..a7d3cee866 100644 --- a/x/wasm/internal/keeper/keeper_test.go +++ b/x/wasm/internal/keeper/keeper_test.go @@ -5,6 +5,8 @@ import ( "encoding/json" "errors" "github.com/CosmWasm/wasmd/x/wasm/internal/keeper/wasmtesting" + wasmvm "github.com/CosmWasm/wasmvm" + wasmvmtypes "github.com/CosmWasm/wasmvm/types" "io/ioutil" "testing" "time" @@ -274,9 +276,9 @@ func TestInstantiate(t *testing.T) { gasBefore := ctx.GasMeter().GasConsumed() // create with no balance is also legal - contractAddr, err := keeper.Instantiate(ctx, codeID, creator, nil, initMsgBz, "demo contract 1", nil) + gotContractAddr, _, err := keeper.Instantiate(ctx, codeID, creator, nil, initMsgBz, "demo contract 1", nil) require.NoError(t, err) - require.Equal(t, "cosmos18vd8fpwxzck93qlwghaj6arh4p7c5n89uzcee5", contractAddr.String()) + require.Equal(t, "cosmos18vd8fpwxzck93qlwghaj6arh4p7c5n89uzcee5", gotContractAddr.String()) gasAfter := ctx.GasMeter().GasConsumed() if types.EnableGasVerification { @@ -284,7 +286,7 @@ func TestInstantiate(t *testing.T) { } // ensure it is stored properly - info := keeper.GetContractInfo(ctx, contractAddr) + info := keeper.GetContractInfo(ctx, gotContractAddr) require.NotNil(t, info) assert.Equal(t, creator.String(), info.Creator) assert.Equal(t, codeID, info.CodeID) @@ -296,7 +298,7 @@ func TestInstantiate(t *testing.T) { Updated: types.NewAbsoluteTxPosition(ctx), Msg: json.RawMessage(initMsgBz), }} - assert.Equal(t, exp, keeper.GetContractHistory(ctx, contractAddr)) + assert.Equal(t, exp, keeper.GetContractHistory(ctx, gotContractAddr)) } func TestInstantiateWithDeposit(t *testing.T) { @@ -345,7 +347,7 @@ func TestInstantiateWithDeposit(t *testing.T) { require.NoError(t, err) // when - addr, err := keeper.Instantiate(ctx, contractID, spec.srcActor, nil, initMsgBz, "my label", deposit) + addr, _, err := keeper.Instantiate(ctx, contractID, spec.srcActor, nil, initMsgBz, "my label", deposit) // then if spec.expError { require.Error(t, err) @@ -412,7 +414,7 @@ func TestInstantiateWithPermissions(t *testing.T) { contractID, err := keeper.Create(ctx, myAddr, wasmCode, "https://github.com/CosmWasm/wasmd/blob/master/x/wasm/testdata/escrow.wasm", "", &spec.srcPermission) require.NoError(t, err) - _, err = keeper.Instantiate(ctx, contractID, spec.srcActor, nil, initMsgBz, "demo contract 1", nil) + _, _, err = keeper.Instantiate(ctx, contractID, spec.srcActor, nil, initMsgBz, "demo contract 1", nil) assert.True(t, spec.expError.Is(err), "got %+v", err) }) } @@ -430,24 +432,26 @@ func TestInstantiateWithNonExistingCodeID(t *testing.T) { require.NoError(t, err) const nonExistingCodeID = 9999 - addr, err := keeper.Instantiate(ctx, nonExistingCodeID, creator, nil, initMsgBz, "demo contract 2", nil) + addr, _, err := keeper.Instantiate(ctx, nonExistingCodeID, creator, nil, initMsgBz, "demo contract 2", nil) require.True(t, types.ErrNotFound.Is(err), err) require.Nil(t, addr) } -func TestInstantiateWithCallbackToContract(t *testing.T) { +func TestInstantiateWithContractDataResponse(t *testing.T) { ctx, keepers := CreateTestInput(t, false, SupportedFeatures, nil, nil) - var ( - executeCalled bool - err error - ) - wasmerMock := wasmtesting.SelfCallingInstMockWasmer(&executeCalled) - keepers.WasmKeeper.wasmer = wasmerMock - example := StoreHackatomExampleContract(t, ctx, keepers) - _, err = keepers.WasmKeeper.Instantiate(ctx, example.CodeID, example.CreatorAddr, nil, nil, "test", nil) + wasmerMock := &wasmtesting.MockWasmer{ + InstantiateFn: func(codeID wasmvm.Checksum, env wasmvmtypes.Env, info wasmvmtypes.MessageInfo, initMsg []byte, store wasmvm.KVStore, goapi wasmvm.GoAPI, querier wasmvm.Querier, gasMeter wasmvm.GasMeter, gasLimit uint64) (*wasmvmtypes.InitResponse, uint64, error) { + return &wasmvmtypes.InitResponse{Data: []byte("my-response-data")}, 0, nil + }, + AnalyzeCodeFn: wasmtesting.WithoutIBCAnalyzeFn, + CreateFn: wasmtesting.NoOpCreateFn, + } + + example := StoreRandomContract(t, ctx, keepers, wasmerMock) + _, data, err := keepers.WasmKeeper.Instantiate(ctx, example.CodeID, example.CreatorAddr, nil, nil, "test", nil) require.NoError(t, err) - assert.True(t, executeCalled) + assert.Equal(t, []byte("my-response-data"), data) } func TestExecute(t *testing.T) { @@ -473,7 +477,7 @@ func TestExecute(t *testing.T) { initMsgBz, err := json.Marshal(initMsg) require.NoError(t, err) - addr, err := keeper.Instantiate(ctx, contractID, creator, nil, initMsgBz, "demo contract 3", deposit) + addr, _, err := keeper.Instantiate(ctx, contractID, creator, nil, initMsgBz, "demo contract 3", deposit) require.NoError(t, err) require.Equal(t, "cosmos18vd8fpwxzck93qlwghaj6arh4p7c5n89uzcee5", addr.String()) @@ -582,7 +586,7 @@ func TestExecuteWithDeposit(t *testing.T) { initMsgBz, err := json.Marshal(initMsg) require.NoError(t, err) - contractAddr, err := keeper.Instantiate(ctx, codeID, spec.srcActor, nil, initMsgBz, "my label", nil) + contractAddr, _, err := keeper.Instantiate(ctx, codeID, spec.srcActor, nil, initMsgBz, "my label", nil) require.NoError(t, err) // when @@ -636,7 +640,7 @@ func TestExecuteWithPanic(t *testing.T) { initMsgBz, err := json.Marshal(initMsg) require.NoError(t, err) - addr, err := keeper.Instantiate(ctx, contractID, creator, nil, initMsgBz, "demo contract 4", deposit) + addr, _, err := keeper.Instantiate(ctx, contractID, creator, nil, initMsgBz, "demo contract 4", deposit) require.NoError(t, err) // let's make sure we get a reasonable error, no panic/crash @@ -670,7 +674,7 @@ func TestExecuteWithCpuLoop(t *testing.T) { initMsgBz, err := json.Marshal(initMsg) require.NoError(t, err) - addr, err := keeper.Instantiate(ctx, contractID, creator, nil, initMsgBz, "demo contract 5", deposit) + addr, _, err := keeper.Instantiate(ctx, contractID, creator, nil, initMsgBz, "demo contract 5", deposit) require.NoError(t, err) // make sure we set a limit before calling @@ -715,7 +719,7 @@ func TestExecuteWithStorageLoop(t *testing.T) { initMsgBz, err := json.Marshal(initMsg) require.NoError(t, err) - addr, err := keeper.Instantiate(ctx, contractID, creator, nil, initMsgBz, "demo contract 6", deposit) + addr, _, err := keeper.Instantiate(ctx, contractID, creator, nil, initMsgBz, "demo contract 6", deposit) require.NoError(t, err) // make sure we set a limit before calling @@ -876,7 +880,7 @@ func TestMigrate(t *testing.T) { t.Run(msg, func(t *testing.T) { // given a contract instance ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1) - contractAddr, err := keeper.Instantiate(ctx, spec.fromCodeID, creator, spec.admin, spec.initMsg, "demo contract", nil) + contractAddr, _, err := keeper.Instantiate(ctx, spec.fromCodeID, creator, spec.admin, spec.initMsg, "demo contract", nil) require.NoError(t, err) if spec.overrideContractAddr != nil { contractAddr = spec.overrideContractAddr @@ -969,7 +973,7 @@ func TestMigrateWithDispatchedMessage(t *testing.T) { initMsgBz := initMsg.GetBytes(t) ctx = ctx.WithBlockHeight(ctx.BlockHeight() + 1) - contractAddr, err := keeper.Instantiate(ctx, originalContractID, creator, fred, initMsgBz, "demo contract", deposit) + contractAddr, _, err := keeper.Instantiate(ctx, originalContractID, creator, fred, initMsgBz, "demo contract", deposit) require.NoError(t, err) migMsgBz := BurnerExampleInitMsg{Payout: myPayoutAddr}.GetBytes(t) @@ -1101,7 +1105,7 @@ func TestUpdateContractAdmin(t *testing.T) { } for msg, spec := range specs { t.Run(msg, func(t *testing.T) { - addr, err := keeper.Instantiate(ctx, originalContractID, creator, spec.instAdmin, initMsgBz, "demo contract", nil) + addr, _, err := keeper.Instantiate(ctx, originalContractID, creator, spec.instAdmin, initMsgBz, "demo contract", nil) require.NoError(t, err) if spec.overrideContractAddr != nil { addr = spec.overrideContractAddr @@ -1167,7 +1171,7 @@ func TestClearContractAdmin(t *testing.T) { } for msg, spec := range specs { t.Run(msg, func(t *testing.T) { - addr, err := keeper.Instantiate(ctx, originalContractID, creator, spec.instAdmin, initMsgBz, "demo contract", nil) + addr, _, err := keeper.Instantiate(ctx, originalContractID, creator, spec.instAdmin, initMsgBz, "demo contract", nil) require.NoError(t, err) if spec.overrideContractAddr != nil { addr = spec.overrideContractAddr diff --git a/x/wasm/internal/keeper/legacy_querier_test.go b/x/wasm/internal/keeper/legacy_querier_test.go index 06eb00ddc9..94276541eb 100644 --- a/x/wasm/internal/keeper/legacy_querier_test.go +++ b/x/wasm/internal/keeper/legacy_querier_test.go @@ -38,7 +38,7 @@ func TestLegacyQueryContractState(t *testing.T) { initMsgBz, err := json.Marshal(initMsg) require.NoError(t, err) - addr, err := keeper.Instantiate(ctx, contractID, creator, nil, initMsgBz, "demo contract to query", deposit) + addr, _, err := keeper.Instantiate(ctx, contractID, creator, nil, initMsgBz, "demo contract to query", deposit) require.NoError(t, err) contractModel := []types.Model{ @@ -190,7 +190,7 @@ func TestLegacyQueryContractListByCodeOrdering(t *testing.T) { ctx = setBlock(ctx, h) h++ } - _, err = keeper.Instantiate(ctx, codeID, creator, nil, initMsgBz, fmt.Sprintf("contract %d", i), topUp) + _, _, err = keeper.Instantiate(ctx, codeID, creator, nil, initMsgBz, fmt.Sprintf("contract %d", i), topUp) require.NoError(t, err) } diff --git a/x/wasm/internal/keeper/msg_server.go b/x/wasm/internal/keeper/msg_server.go index 8b9a359699..58e96aaeea 100644 --- a/x/wasm/internal/keeper/msg_server.go +++ b/x/wasm/internal/keeper/msg_server.go @@ -55,7 +55,7 @@ func (m msgServer) InstantiateContract(goCtx context.Context, msg *types.MsgInst } } - contractAddr, err := m.keeper.Instantiate(ctx, msg.CodeID, senderAddr, adminAddr, msg.InitMsg, msg.Label, msg.Funds) + contractAddr, data, err := m.keeper.Instantiate(ctx, msg.CodeID, senderAddr, adminAddr, msg.InitMsg, msg.Label, msg.Funds) if err != nil { return nil, err } @@ -70,6 +70,7 @@ func (m msgServer) InstantiateContract(goCtx context.Context, msg *types.MsgInst return &types.MsgInstantiateContractResponse{ Address: contractAddr.String(), + Data: data, }, nil } diff --git a/x/wasm/internal/keeper/proposal_handler.go b/x/wasm/internal/keeper/proposal_handler.go index 784e7cc266..937996e2e4 100644 --- a/x/wasm/internal/keeper/proposal_handler.go +++ b/x/wasm/internal/keeper/proposal_handler.go @@ -75,7 +75,7 @@ func handleInstantiateProposal(ctx sdk.Context, k Keeper, p types.InstantiateCon return sdkerrors.Wrap(err, "admin") } - contractAddr, err := k.instantiate(ctx, p.CodeID, runAsAddr, adminAddr, p.InitMsg, p.Label, p.Funds, GovAuthorizationPolicy{}) + contractAddr, _, err := k.instantiate(ctx, p.CodeID, runAsAddr, adminAddr, p.InitMsg, p.Label, p.Funds, GovAuthorizationPolicy{}) if err != nil { return err } diff --git a/x/wasm/internal/keeper/querier_test.go b/x/wasm/internal/keeper/querier_test.go index b061d6a3bc..5230c20803 100644 --- a/x/wasm/internal/keeper/querier_test.go +++ b/x/wasm/internal/keeper/querier_test.go @@ -288,7 +288,7 @@ func TestQueryContractListByCodeOrdering(t *testing.T) { ctx = setBlock(ctx, h) h++ } - _, err = keeper.Instantiate(ctx, codeID, creator, nil, initMsgBz, fmt.Sprintf("contract %d", i), topUp) + _, _, err = keeper.Instantiate(ctx, codeID, creator, nil, initMsgBz, fmt.Sprintf("contract %d", i), topUp) require.NoError(t, err) } diff --git a/x/wasm/internal/keeper/reflect_test.go b/x/wasm/internal/keeper/reflect_test.go index 99bdffb612..da86e0380c 100644 --- a/x/wasm/internal/keeper/reflect_test.go +++ b/x/wasm/internal/keeper/reflect_test.go @@ -96,7 +96,7 @@ func TestMaskReflectContractSend(t *testing.T) { // creator instantiates a contract and gives it tokens maskStart := sdk.NewCoins(sdk.NewInt64Coin("denom", 40000)) - maskAddr, err := keeper.Instantiate(ctx, maskID, creator, nil, []byte("{}"), "mask contract 2", maskStart) + maskAddr, _, err := keeper.Instantiate(ctx, maskID, creator, nil, []byte("{}"), "mask contract 2", maskStart) require.NoError(t, err) require.NotEmpty(t, maskAddr) @@ -108,7 +108,7 @@ func TestMaskReflectContractSend(t *testing.T) { initMsgBz, err := json.Marshal(initMsg) require.NoError(t, err) escrowStart := sdk.NewCoins(sdk.NewInt64Coin("denom", 25000)) - escrowAddr, err := keeper.Instantiate(ctx, escrowID, creator, nil, initMsgBz, "escrow contract 2", escrowStart) + escrowAddr, _, err := keeper.Instantiate(ctx, escrowID, creator, nil, initMsgBz, "escrow contract 2", escrowStart) require.NoError(t, err) require.NotEmpty(t, escrowAddr) @@ -172,7 +172,7 @@ func TestMaskReflectCustomMsg(t *testing.T) { // creator instantiates a contract and gives it tokens contractStart := sdk.NewCoins(sdk.NewInt64Coin("denom", 40000)) - contractAddr, err := keeper.Instantiate(ctx, codeID, creator, nil, []byte("{}"), "mask contract 1", contractStart) + contractAddr, _, err := keeper.Instantiate(ctx, codeID, creator, nil, []byte("{}"), "mask contract 1", contractStart) require.NoError(t, err) require.NotEmpty(t, contractAddr) @@ -263,7 +263,7 @@ func TestMaskReflectCustomQuery(t *testing.T) { // creator instantiates a contract and gives it tokens contractStart := sdk.NewCoins(sdk.NewInt64Coin("denom", 40000)) - contractAddr, err := keeper.Instantiate(ctx, codeID, creator, nil, []byte("{}"), "mask contract 1", contractStart) + contractAddr, _, err := keeper.Instantiate(ctx, codeID, creator, nil, []byte("{}"), "mask contract 1", contractStart) require.NoError(t, err) require.NotEmpty(t, contractAddr) @@ -316,7 +316,7 @@ func TestMaskReflectWasmQueries(t *testing.T) { // creator instantiates a contract and gives it tokens maskStart := sdk.NewCoins(sdk.NewInt64Coin("denom", 40000)) - maskAddr, err := keeper.Instantiate(ctx, maskID, creator, nil, []byte("{}"), "mask contract 2", maskStart) + maskAddr, _, err := keeper.Instantiate(ctx, maskID, creator, nil, []byte("{}"), "mask contract 2", maskStart) require.NoError(t, err) require.NotEmpty(t, maskAddr) @@ -387,7 +387,7 @@ func TestWasmRawQueryWithNil(t *testing.T) { // creator instantiates a contract and gives it tokens maskStart := sdk.NewCoins(sdk.NewInt64Coin("denom", 40000)) - maskAddr, err := keeper.Instantiate(ctx, maskID, creator, nil, []byte("{}"), "mask contract 2", maskStart) + maskAddr, _, err := keeper.Instantiate(ctx, maskID, creator, nil, []byte("{}"), "mask contract 2", maskStart) require.NoError(t, err) require.NotEmpty(t, maskAddr) diff --git a/x/wasm/internal/keeper/staking_test.go b/x/wasm/internal/keeper/staking_test.go index b8eacb1caf..6b31939458 100644 --- a/x/wasm/internal/keeper/staking_test.go +++ b/x/wasm/internal/keeper/staking_test.go @@ -121,7 +121,7 @@ func TestInitializeStaking(t *testing.T) { initBz, err := json.Marshal(&initMsg) require.NoError(t, err) - stakingAddr, err := keeper.Instantiate(ctx, stakingID, creator, nil, initBz, "staking derivates - DRV", nil) + stakingAddr, _, err := keeper.Instantiate(ctx, stakingID, creator, nil, initBz, "staking derivates - DRV", nil) require.NoError(t, err) require.NotEmpty(t, stakingAddr) @@ -141,7 +141,7 @@ func TestInitializeStaking(t *testing.T) { badBz, err := json.Marshal(&badInitMsg) require.NoError(t, err) - _, err = keeper.Instantiate(ctx, stakingID, creator, nil, badBz, "missing validator", nil) + _, _, err = keeper.Instantiate(ctx, stakingID, creator, nil, badBz, "missing validator", nil) require.Error(t, err) // no changes to bonding shares @@ -202,7 +202,7 @@ func initializeStaking(t *testing.T) initInfo { initBz, err := json.Marshal(&initMsg) require.NoError(t, err) - stakingAddr, err := keeper.Instantiate(ctx, stakingID, creator, nil, initBz, "staking derivates - DRV", nil) + stakingAddr, _, err := keeper.Instantiate(ctx, stakingID, creator, nil, initBz, "staking derivates - DRV", nil) require.NoError(t, err) require.NotEmpty(t, stakingAddr) @@ -447,7 +447,7 @@ func TestQueryStakingInfo(t *testing.T) { require.Equal(t, uint64(2), maskID) // creator instantiates a contract and gives it tokens - maskAddr, err := keeper.Instantiate(ctx, maskID, creator, nil, []byte("{}"), "mask contract 2", nil) + maskAddr, _, err := keeper.Instantiate(ctx, maskID, creator, nil, []byte("{}"), "mask contract 2", nil) require.NoError(t, err) require.NotEmpty(t, maskAddr) diff --git a/x/wasm/internal/keeper/test_common.go b/x/wasm/internal/keeper/test_common.go index 2f08d39aee..c93aa306d4 100644 --- a/x/wasm/internal/keeper/test_common.go +++ b/x/wasm/internal/keeper/test_common.go @@ -353,7 +353,7 @@ func handleInstantiate(ctx sdk.Context, k *Keeper, msg *types.MsgInstantiateCont } } - contractAddr, err := k.Instantiate(ctx, msg.CodeID, senderAddr, adminAddr, msg.InitMsg, msg.Label, msg.Funds) + contractAddr, _, err := k.Instantiate(ctx, msg.CodeID, senderAddr, adminAddr, msg.InitMsg, msg.Label, msg.Funds) if err != nil { return nil, err } @@ -442,6 +442,19 @@ type ExampleContractInstance struct { // SeedNewContractInstance sets the mock wasmerEngine in keeper and calls store + instantiate to init the contract's metadata func SeedNewContractInstance(t *testing.T, ctx sdk.Context, keepers TestKeepers, mock types.WasmerEngine) ExampleContractInstance { + t.Helper() + exampleContract := StoreRandomContract(t, ctx, keepers, mock) + contractAddr, _, err := keepers.WasmKeeper.Instantiate(ctx, exampleContract.CodeID, exampleContract.CreatorAddr, exampleContract.CreatorAddr, []byte(`{}`), "", nil) + require.NoError(t, err) + return ExampleContractInstance{ + ExampleContract: exampleContract, + Contract: contractAddr, + } +} + +// StoreRandomContract sets the mock wasmerEngine in keeper and calls store +func StoreRandomContract(t *testing.T, ctx sdk.Context, keepers TestKeepers, mock types.WasmerEngine) ExampleContract { + t.Helper() anyAmount := sdk.NewCoins(sdk.NewInt64Coin("denom", 1000)) creator, _, creatorAddr := keyPubAddr() fundAccounts(t, ctx, keepers.AccountKeeper, keepers.BankKeeper, creatorAddr, anyAmount) @@ -449,12 +462,8 @@ func SeedNewContractInstance(t *testing.T, ctx sdk.Context, keepers TestKeepers, wasmCode := append(wasmIdent, rand.Bytes(10)...) codeID, err := keepers.WasmKeeper.Create(ctx, creatorAddr, wasmCode, "", "", nil) require.NoError(t, err) - contractAddr, err := keepers.WasmKeeper.Instantiate(ctx, codeID, creatorAddr, creatorAddr, []byte(`{}`), "", nil) - require.NoError(t, err) - return ExampleContractInstance{ - ExampleContract: ExampleContract{InitialAmount: anyAmount, Creator: creator, CreatorAddr: creatorAddr, CodeID: codeID}, - Contract: contractAddr, - } + exampleContract := ExampleContract{InitialAmount: anyAmount, Creator: creator, CreatorAddr: creatorAddr, CodeID: codeID} + return exampleContract } type HackatomExampleInstance struct { @@ -481,7 +490,7 @@ func InstantiateHackatomExampleContract(t *testing.T, ctx sdk.Context, keepers T initialAmount := sdk.NewCoins(sdk.NewInt64Coin("denom", 100)) adminAddr := contract.CreatorAddr - contractAddr, err := keepers.WasmKeeper.Instantiate(ctx, contract.CodeID, contract.CreatorAddr, adminAddr, initMsgBz, "demo contract to query", initialAmount) + contractAddr, _, err := keepers.WasmKeeper.Instantiate(ctx, contract.CodeID, contract.CreatorAddr, adminAddr, initMsgBz, "demo contract to query", initialAmount) require.NoError(t, err) return HackatomExampleInstance{ ExampleContract: contract, @@ -521,7 +530,7 @@ func InstantiateIBCReflectContract(t *testing.T, ctx sdk.Context, keepers TestKe }.GetBytes(t) adminAddr := RandomAccountAddress(t) - contractAddr, err := keepers.WasmKeeper.Instantiate(ctx, ibcReflectID, adminAddr, adminAddr, initMsgBz, "ibc-reflect-factory", nil) + contractAddr, _, err := keepers.WasmKeeper.Instantiate(ctx, ibcReflectID, adminAddr, adminAddr, initMsgBz, "ibc-reflect-factory", nil) require.NoError(t, err) return IBCReflectExampleInstance{ Admin: adminAddr, diff --git a/x/wasm/internal/keeper/wasmtesting/mock_engine.go b/x/wasm/internal/keeper/wasmtesting/mock_engine.go index 70a7c9625a..25d9114c98 100644 --- a/x/wasm/internal/keeper/wasmtesting/mock_engine.go +++ b/x/wasm/internal/keeper/wasmtesting/mock_engine.go @@ -7,6 +7,7 @@ import ( wasmvm "github.com/CosmWasm/wasmvm" wasmvmtypes "github.com/CosmWasm/wasmvm/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/tendermint/tendermint/libs/rand" ) var _ types.WasmerEngine = &MockWasmer{} @@ -276,6 +277,10 @@ func NoOpInstantiateFn(wasmvm.Checksum, wasmvmtypes.Env, wasmvmtypes.MessageInfo return &wasmvmtypes.InitResponse{}, 0, nil } +func NoOpCreateFn(_ wasmvm.WasmCode) (wasmvm.Checksum, error) { + return rand.Bytes(32), nil +} + func HasIBCAnalyzeFn(wasmvm.Checksum) (*wasmvmtypes.AnalysisReport, error) { return &wasmvmtypes.AnalysisReport{ HasIBCEntryPoints: true, diff --git a/x/wasm/internal/types/tx.pb.go b/x/wasm/internal/types/tx.pb.go index 991e78d3cc..6a729abb4a 100644 --- a/x/wasm/internal/types/tx.pb.go +++ b/x/wasm/internal/types/tx.pb.go @@ -170,6 +170,8 @@ var xxx_messageInfo_MsgInstantiateContract proto.InternalMessageInfo type MsgInstantiateContractResponse struct { // Address is the bech32 address of the new contract instance. Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` + // Data contains base64-encoded bytes to returned from the contract + Data []byte `protobuf:"bytes,3,opt,name=data,proto3" json:"data,omitempty"` } func (m *MsgInstantiateContractResponse) Reset() { *m = MsgInstantiateContractResponse{} } @@ -550,58 +552,58 @@ func init() { func init() { proto.RegisterFile("x/wasm/internal/types/tx.proto", fileDescriptor_5129e02f2349864e) } var fileDescriptor_5129e02f2349864e = []byte{ - // 805 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x56, 0xcd, 0x6e, 0xeb, 0x44, - 0x14, 0x8e, 0x6f, 0xfe, 0x9a, 0x93, 0x70, 0x41, 0xa6, 0x2d, 0xc6, 0x20, 0x27, 0xf8, 0x82, 0x14, - 0x04, 0xb5, 0xdb, 0x22, 0x40, 0x02, 0xb1, 0x68, 0x02, 0x8b, 0x2e, 0x8c, 0x90, 0xaf, 0xd0, 0x95, - 0x2a, 0xa1, 0x30, 0xb1, 0xa7, 0x66, 0x20, 0x9e, 0x89, 0x3c, 0x13, 0x92, 0x8a, 0x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x88, 0xef, 0x0d, 0xef, 0xfc, 0x1d, 0x00, 0x00, 0xff, 0xff, 0x9f, 0x95, 0xe8, - 0x1b, 0xc9, 0x08, 0x00, 0x00, + // 809 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x56, 0xcd, 0x6e, 0xf3, 0x44, + 0x14, 0x8d, 0xbf, 0xfc, 0x35, 0x37, 0xe1, 0x03, 0x99, 0xb6, 0x18, 0x83, 0x9c, 0x90, 0x82, 0x14, + 0x04, 0xb5, 0xdb, 0x22, 0x60, 0x81, 0x58, 0x34, 0x81, 0x45, 0x17, 0xae, 0x90, 0x2b, 0x54, 0xa9, + 0x12, 0x0a, 0x13, 0x7b, 0x6a, 0x06, 0xe2, 0x99, 0xc8, 0x33, 0x21, 0xa9, 0x78, 0x03, 0x56, 0xbc, + 0x00, 0x2f, 0x80, 0x78, 0x90, 0x2e, 0xbb, 0x44, 0x42, 0x0a, 0x90, 0x6e, 0x79, 0x02, 0x56, 0x68, + 0x6c, 0xc7, 0x71, 0x43, 0x1c, 0x19, 0x21, 0x36, 0xf6, 0xdc, 0xf1, 0xb9, 0xe7, 0xf8, 0x1e, 0xdd, + 0x3b, 0x1a, 0x30, 0xe6, 0xd6, 0x0c, 0xf1, 0xc0, 0x22, 0x54, 0xe0, 0x90, 0xa2, 0xb1, 0x25, 0xee, + 0x26, 0x98, 0x5b, 0x62, 0x6e, 0x4e, 0x42, 0x26, 0x98, 0x7a, 0xe0, 0x32, 0x1e, 0x48, 0x84, 0x19, + 0x3d, 0xbe, 0x3d, 0x1d, 0x61, 0x81, 0x4e, 0x75, 0x43, 0x6e, 0x33, 0x6e, 0x8d, 0x10, 0xc7, 0x56, + 0xb2, 0x69, 0xb9, 0x8c, 0xd0, 0x38, 0x4d, 0xdf, 0xf7, 0x99, 0xcf, 0xa2, 0xa5, 0x25, 0x57, 0xc9, + 0xee, 0x1b, 0x39, 0x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 0xd6, 0x85, 0x66, 0xb6, 0x3b, 0xdf, 0xca, 0x67, 0xc8, + 0xc0, 0xf4, 0xe3, 0x42, 0xb0, 0x54, 0xe4, 0x4b, 0x80, 0x4c, 0x17, 0xbe, 0x99, 0x9f, 0xbc, 0x46, + 0xe9, 0xef, 0x16, 0x41, 0xad, 0x14, 0xfa, 0x97, 0xf7, 0x7f, 0x18, 0xa5, 0xfb, 0xa5, 0xa1, 0x3c, + 0x2c, 0x0d, 0xe5, 0xf7, 0xa5, 0xa1, 0xfc, 0xf0, 0x68, 0x94, 0x1e, 0x1e, 0x8d, 0xd2, 0x2f, 0x8f, + 0x46, 0xe9, 0xe6, 0x24, 0x73, 0x92, 0x0d, 0x18, 0x0f, 0xae, 0xe5, 0x15, 0x42, 0xb2, 0x7a, 0xd6, + 0x3c, 0x79, 0x3f, 0xbd, 0x50, 0x8c, 0x6a, 0xd1, 0x5d, 0xe2, 0xbd, 0xbf, 0x03, 0x00, 0x00, 0xff, + 0xff, 0x9c, 0x18, 0x4c, 0x2a, 0xdd, 0x08, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -1057,6 +1059,13 @@ func (m *MsgInstantiateContractResponse) MarshalToSizedBuffer(dAtA []byte) (int, _ = i var l int _ = l + if len(m.Data) > 0 { + i -= len(m.Data) + copy(dAtA[i:], m.Data) + i = encodeVarintTx(dAtA, i, uint64(len(m.Data))) + i-- + dAtA[i] = 0x1a + } if len(m.Address) > 0 { i -= len(m.Address) copy(dAtA[i:], m.Address) @@ -1457,6 +1466,10 @@ func (m *MsgInstantiateContractResponse) Size() (n int) { if l > 0 { n += 1 + l + sovTx(uint64(l)) } + l = len(m.Data) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } return n } @@ -2187,6 +2200,40 @@ func (m *MsgInstantiateContractResponse) Unmarshal(dAtA []byte) error { } m.Address = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Data", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + byteLen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + byteLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Data = append(m.Data[:0], dAtA[iNdEx:postIndex]...) + if m.Data == nil { + m.Data = []byte{} + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipTx(dAtA[iNdEx:]) diff --git a/x/wasm/internal/types/tx.proto b/x/wasm/internal/types/tx.proto index 1553a6b93c..3bde9c6a80 100644 --- a/x/wasm/internal/types/tx.proto +++ b/x/wasm/internal/types/tx.proto @@ -63,6 +63,8 @@ message MsgInstantiateContract { message MsgInstantiateContractResponse { // Address is the bech32 address of the new contract instance. string address = 1; + // Data contains base64-encoded bytes to returned from the contract + bytes data = 3; } // MsgExecuteContract submits the given message data to a smart contract From 4a3e12a1a065106d59b884bcf47d4a3517ec3762 Mon Sep 17 00:00:00 2001 From: Alex Peters Date: Wed, 3 Mar 2021 14:34:03 +0100 Subject: [PATCH 2/2] Fix proto field number --- x/wasm/internal/types/tx.pb.go | 50 +++++++++++++++++----------------- x/wasm/internal/types/tx.proto | 2 +- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/x/wasm/internal/types/tx.pb.go b/x/wasm/internal/types/tx.pb.go index 6a729abb4a..41766b2590 100644 --- a/x/wasm/internal/types/tx.pb.go +++ b/x/wasm/internal/types/tx.pb.go @@ -171,7 +171,7 @@ type MsgInstantiateContractResponse struct { // Address is the bech32 address of the new contract instance. Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` // Data contains base64-encoded bytes to returned from the contract - Data []byte `protobuf:"bytes,3,opt,name=data,proto3" json:"data,omitempty"` + Data []byte `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` } func (m *MsgInstantiateContractResponse) Reset() { *m = MsgInstantiateContractResponse{} } @@ -552,7 +552,7 @@ func init() { func init() { proto.RegisterFile("x/wasm/internal/types/tx.proto", fileDescriptor_5129e02f2349864e) } var fileDescriptor_5129e02f2349864e = []byte{ - // 809 bytes of a gzipped FileDescriptorProto + // 808 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x56, 0xcd, 0x6e, 0xf3, 0x44, 0x14, 0x8d, 0xbf, 0xfc, 0x35, 0x37, 0xe1, 0x03, 0x99, 0xb6, 0x18, 0x83, 0x9c, 0x90, 0x82, 0x14, 0x04, 0xb5, 0xdb, 0x22, 0x60, 0x81, 0x58, 0x34, 0x81, 0x45, 0x17, 0xae, 0x90, 0x2b, 0x54, 0xa9, @@ -583,27 +583,27 @@ var fileDescriptor_5129e02f2349864e = []byte{ 0xb2, 0xa3, 0x52, 0x0b, 0x07, 0x8c, 0xd0, 0xfe, 0xc9, 0xfd, 0xa2, 0x5d, 0xfa, 0xe9, 0xb7, 0x76, 0xcf, 0x27, 0xe2, 0xab, 0xe9, 0xc8, 0x74, 0x59, 0x60, 0x25, 0xed, 0x17, 0xbf, 0x8e, 0xb9, 0xf7, 0x4d, 0xd2, 0x44, 0x32, 0x81, 0x3b, 0x31, 0x73, 0xf7, 0x12, 0x8c, 0xed, 0xf6, 0xa4, 0x36, 0x6b, - 0x50, 0x47, 0x9e, 0x17, 0x62, 0xce, 0x13, 0x9f, 0x56, 0xa1, 0xaa, 0x42, 0xc5, 0x43, 0x02, 0x45, - 0x7e, 0xb4, 0x9c, 0x68, 0xdd, 0xfd, 0x55, 0x01, 0xd5, 0xe6, 0xfe, 0xa7, 0x73, 0xec, 0x4e, 0x0b, - 0x78, 0xad, 0xc3, 0x9e, 0x9b, 0x60, 0x12, 0xbb, 0xd3, 0x58, 0x35,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0x6a, 0xa5, 0xd0, 0xbf, 0xbc, 0xff, 0xc3, 0x28, 0xdd, 0x2f, 0x0d, 0xe5, 0x61, + 0x69, 0x28, 0xbf, 0x2f, 0x0d, 0xe5, 0x87, 0x47, 0xa3, 0xf4, 0xf0, 0x68, 0x94, 0x7e, 0x79, 0x34, + 0x4a, 0x37, 0x27, 0x99, 0x93, 0x6c, 0xc0, 0x78, 0x70, 0x2d, 0xaf, 0x10, 0x92, 0xd5, 0xb3, 0xe6, + 0xc9, 0xfb, 0xe9, 0x85, 0x62, 0x54, 0x8b, 0xee, 0x12, 0xef, 0xfd, 0x1d, 0x00, 0x00, 0xff, 0xff, + 0x96, 0x93, 0x22, 0x47, 0xdd, 0x08, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -1064,7 +1064,7 @@ func (m *MsgInstantiateContractResponse) MarshalToSizedBuffer(dAtA []byte) (int, copy(dAtA[i:], m.Data) i = encodeVarintTx(dAtA, i, uint64(len(m.Data))) i-- - dAtA[i] = 0x1a + dAtA[i] = 0x12 } if len(m.Address) > 0 { i -= len(m.Address) @@ -2200,7 +2200,7 @@ func (m *MsgInstantiateContractResponse) Unmarshal(dAtA []byte) error { } m.Address = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex - case 3: + case 2: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field Data", wireType) } diff --git a/x/wasm/internal/types/tx.proto b/x/wasm/internal/types/tx.proto index 3bde9c6a80..370c0d4982 100644 --- a/x/wasm/internal/types/tx.proto +++ b/x/wasm/internal/types/tx.proto @@ -64,7 +64,7 @@ message MsgInstantiateContractResponse { // Address is the bech32 address of the new contract instance. string address = 1; // Data contains base64-encoded bytes to returned from the contract - bytes data = 3; + bytes data = 2; } // MsgExecuteContract submits the given message data to a smart contract