From 421b7857ae8472b280d64ae6ecbefa6b0e1678c8 Mon Sep 17 00:00:00 2001 From: nhpd Date: Tue, 29 Oct 2024 16:14:42 +0400 Subject: [PATCH] return failure as before after resubmit --- wasmbinding/message_plugin.go | 73 +++++++++++++++---------- wasmbinding/test/custom_message_test.go | 3 +- 2 files changed, 47 insertions(+), 29 deletions(-) diff --git a/wasmbinding/message_plugin.go b/wasmbinding/message_plugin.go index 289ddf0af..ed76a8ed3 100644 --- a/wasmbinding/message_plugin.go +++ b/wasmbinding/message_plugin.go @@ -67,37 +67,39 @@ func CustomMessageDecorator( ) func(messenger wasmkeeper.Messenger) wasmkeeper.Messenger { return func(old wasmkeeper.Messenger) wasmkeeper.Messenger { return &CustomMessenger{ - Keeper: *ictx, - Wrapped: old, - Ictxmsgserver: ictxkeeper.NewMsgServerImpl(*ictx), - Icqmsgserver: icqkeeper.NewMsgServerImpl(*icq), - transferKeeper: transferKeeper, - Adminserver: adminmodulekeeper.NewMsgServerImpl(*adminKeeper), - Bank: bankKeeper, - TokenFactory: tokenFactoryKeeper, - CronMsgServer: cronkeeper.NewMsgServerImpl(*cronKeeper), - CronQueryServer: cronKeeper, - AdminKeeper: adminKeeper, - ContractmanagerMsgServer: contractmanagerkeeper.NewMsgServerImpl(*contractmanagerKeeper), - DexMsgServer: dexkeeper.NewMsgServerImpl(*dexKeeper), + Keeper: *ictx, + Wrapped: old, + Ictxmsgserver: ictxkeeper.NewMsgServerImpl(*ictx), + Icqmsgserver: icqkeeper.NewMsgServerImpl(*icq), + transferKeeper: transferKeeper, + Adminserver: adminmodulekeeper.NewMsgServerImpl(*adminKeeper), + Bank: bankKeeper, + TokenFactory: tokenFactoryKeeper, + CronMsgServer: cronkeeper.NewMsgServerImpl(*cronKeeper), + CronQueryServer: cronKeeper, + AdminKeeper: adminKeeper, + ContractmanagerMsgServer: contractmanagerkeeper.NewMsgServerImpl(*contractmanagerKeeper), + ContractmanagerQueryServer: contractmanagerkeeper.NewQueryServerImpl(*contractmanagerKeeper), + DexMsgServer: dexkeeper.NewMsgServerImpl(*dexKeeper), } } } type CustomMessenger struct { - Keeper ictxkeeper.Keeper - Wrapped wasmkeeper.Messenger - Ictxmsgserver ictxtypes.MsgServer - Icqmsgserver icqtypes.MsgServer - transferKeeper transferwrapperkeeper.KeeperTransferWrapper - Adminserver admintypes.MsgServer - Bank *bankkeeper.BaseKeeper - TokenFactory *tokenfactorykeeper.Keeper - CronMsgServer crontypes.MsgServer - CronQueryServer crontypes.QueryServer - AdminKeeper *adminmodulekeeper.Keeper - ContractmanagerMsgServer contractmanagertypes.MsgServer - DexMsgServer dextypes.MsgServer + Keeper ictxkeeper.Keeper + Wrapped wasmkeeper.Messenger + Ictxmsgserver ictxtypes.MsgServer + Icqmsgserver icqtypes.MsgServer + transferKeeper transferwrapperkeeper.KeeperTransferWrapper + Adminserver admintypes.MsgServer + Bank *bankkeeper.BaseKeeper + TokenFactory *tokenfactorykeeper.Keeper + CronMsgServer crontypes.MsgServer + CronQueryServer crontypes.QueryServer + AdminKeeper *adminmodulekeeper.Keeper + ContractmanagerMsgServer contractmanagertypes.MsgServer + ContractmanagerQueryServer contractmanagertypes.QueryServer + DexMsgServer dextypes.MsgServer } var _ wasmkeeper.Messenger = (*CustomMessenger)(nil) @@ -1062,7 +1064,15 @@ func (m *CustomMessenger) removeSchedule(ctx sdk.Context, contractAddr sdk.AccAd } func (m *CustomMessenger) resubmitFailure(ctx sdk.Context, contractAddr sdk.AccAddress, resubmitFailure *bindings.ResubmitFailure) ([]sdk.Event, [][]byte, [][]*types.Any, error) { - _, err := m.ContractmanagerMsgServer.ResubmitFailure(ctx, &contractmanagertypes.MsgResubmitFailure{ + failure, err := m.ContractmanagerQueryServer.AddressFailure(ctx, &contractmanagertypes.QueryFailureRequest{ + Address: contractAddr.String(), + FailureId: resubmitFailure.FailureId, + }) + if err != nil { + return nil, nil, nil, errors.Wrapf(err, "no failure with given FailureId found to resubmit") + } + + _, err = m.ContractmanagerMsgServer.ResubmitFailure(ctx, &contractmanagertypes.MsgResubmitFailure{ Sender: contractAddr.String(), FailureId: resubmitFailure.FailureId, }) @@ -1084,7 +1094,14 @@ func (m *CustomMessenger) resubmitFailure(ctx sdk.Context, contractAddr sdk.AccA return nil, nil, nil, errors.Wrap(err, "marshal json failed") } - return nil, [][]byte{data}, nil, nil + // Return failure for reverse compatibility purposes. + // Maybe it'll be removed in the future because it was already deleted after resubmit before returning here. + anyResp, err := types.NewAnyWithValue(failure) + if err != nil { + return nil, nil, nil, errors.Wrapf(err, "failed to convert {%T} to Any", failure) + } + msgResponses := [][]*types.Any{{anyResp}} + return nil, [][]byte{data}, msgResponses, nil } func (m *CustomMessenger) isAdmin(ctx sdk.Context, contractAddr sdk.AccAddress) bool { diff --git a/wasmbinding/test/custom_message_test.go b/wasmbinding/test/custom_message_test.go index 8640095d9..457e63163 100644 --- a/wasmbinding/test/custom_message_test.go +++ b/wasmbinding/test/custom_message_test.go @@ -75,6 +75,7 @@ func (suite *CustomMessengerTestSuite) SetupTest() { suite.messenger.CronQueryServer = suite.neutron.CronKeeper suite.messenger.AdminKeeper = &suite.neutron.AdminmoduleKeeper suite.messenger.ContractmanagerMsgServer = contractmanagerkeeper.NewMsgServerImpl(suite.neutron.ContractManagerKeeper) + suite.messenger.ContractmanagerQueryServer = contractmanagerkeeper.NewQueryServerImpl(suite.neutron.ContractManagerKeeper) suite.contractOwner = keeper.RandomAccountAddress(suite.T()) suite.contractKeeper = keeper.NewDefaultPermissionKeeper(&suite.neutron.WasmKeeper) @@ -807,7 +808,7 @@ func (suite *CustomMessengerTestSuite) TestResubmitFailureFromDifferentContract( // Dispatch _, err = suite.executeNeutronMsg(suite.contractAddress, msg) - suite.ErrorContains(err, "no failure with given FailureId found to resubmit: not found") + suite.ErrorContains(err, "no failure with given FailureId found to resubmit") } func (suite *CustomMessengerTestSuite) executeCustomMsg(contractAddress sdk.AccAddress, fullMsg json.RawMessage) (data []byte, err error) {