diff --git a/CHANGELOG.md b/CHANGELOG.md index 646da12cc3..3533580a2d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,10 +20,11 @@ * [\#69](https://github.com/Finschia/wasmd/pull/69) refactor: refactor test cases for Params * [\#71](https://github.com/Finschia/wasmd/pull/71) add test cases in ContractsByCode * [\#82](https://github.com/Finschia/wasmd/pull/82) add test case to QueryInactiveContracts -* [\#87](https://github.com/Finschia/wasmd/pull/87) add an integration test for TestExecuteContract +* [\#87](https://github.com/Finschia/wasmd/pull/87) add an integration test for TestExecuteContract * [\#79](https://github.com/Finschia/wasmd/pull/79) add an integration test for TestStoreAndInstantiateContract * [\#88](https://github.com/Finschia/wasmd/pull/88) add the test case for invalid address * [\#76](https://github.com/Finschia/wasmd/pull/76) add an integration test for ClearAdmin +* [\#68](https://github.com/Finschia/wasmd/pull/68) add an integration test for UpdateAdmin ### Bug Fixes * [\#62](https://github.com/Finschia/wasmd/pull/62) fill ContractHistory querier result's Updated field diff --git a/x/wasm/keeper/msg_server_integration_test.go b/x/wasm/keeper/msg_server_integration_test.go index 2a0a1aedfb..969dee35fb 100644 --- a/x/wasm/keeper/msg_server_integration_test.go +++ b/x/wasm/keeper/msg_server_integration_test.go @@ -440,6 +440,107 @@ func TestExecuteContract(t *testing.T) { } } +func TestUpdateAdmin(t *testing.T) { + wasmApp := app.Setup(false) + ctx := wasmApp.BaseApp.NewContext(false, tmproto.Header{Time: time.Now()}) + + var ( + myAddress sdk.AccAddress = make([]byte, types.ContractAddrLen) + _, _, otherAddr = testdata.KeyTestPubAddr() + _, _, newAdmin = testdata.KeyTestPubAddr() + ) + + // setup + storeMsg := types.MsgStoreCodeFixture(func(m *types.MsgStoreCode) { + m.WASMByteCode = wasmContract + m.Sender = myAddress.String() + }) + rsp, err := wasmApp.MsgServiceRouter().Handler(storeMsg)(ctx, storeMsg) + require.NoError(t, err) + var storeCodeResult types.MsgStoreCodeResponse + require.NoError(t, wasmApp.AppCodec().Unmarshal(rsp.Data, &storeCodeResult)) + codeID := storeCodeResult.CodeID + + initMsg := types.MsgInstantiateContractFixture(func(m *types.MsgInstantiateContract) { + m.Sender = myAddress.String() + m.Admin = myAddress.String() + m.CodeID = codeID + m.Msg = []byte(`{}`) + m.Funds = sdk.Coins{} + }) + rsp, err = wasmApp.MsgServiceRouter().Handler(initMsg)(ctx, initMsg) + require.NoError(t, err) + + var instantiateContractResult types.MsgInstantiateContractResponse + require.NoError(t, wasmApp.AppCodec().Unmarshal(rsp.Data, &instantiateContractResult)) + contractAddress := instantiateContractResult.Address + + specs := map[string]struct { + addr string + expErr bool + expEvents []abci.Event + }{ + "admin can update admin": { + addr: myAddress.String(), + expErr: false, + expEvents: []abci.Event{ + { + Type: "message", + Attributes: []abci.EventAttribute{ + { + Key: []byte("module"), + Value: []byte("wasm"), + }, + { + Key: []byte("sender"), + Value: []byte(myAddress.String()), + }, + }, + }, + { + Type: "update_contract_admin", + Attributes: []abci.EventAttribute{ + { + Key: []byte("_contract_address"), + Value: []byte(contractAddress), + }, + { + Key: []byte("new_admin_address"), + Value: []byte(newAdmin.String()), + }, + }, + }, + }, + }, + "other address cannot update admin": { + addr: otherAddr.String(), + expErr: true, + }, + } + for name, spec := range specs { + t.Run(name, func(t *testing.T) { + xCtx, _ := ctx.CacheContext() + + // when + msgUpdateAdmin := &types.MsgUpdateAdmin{ + Sender: spec.addr, + NewAdmin: newAdmin.String(), + Contract: contractAddress, + } + rsp, err = wasmApp.MsgServiceRouter().Handler(msgUpdateAdmin)(xCtx, msgUpdateAdmin) + + // then + if spec.expErr { + require.Error(t, err) + return + } + + require.NoError(t, err) + assert.Equal(t, spec.expEvents, rsp.Events) + }) + } +} + func TestClearAdmin(t *testing.T) { wasmApp := app.Setup(false) ctx := wasmApp.BaseApp.NewContext(false, tmproto.Header{Time: time.Now()})