Skip to content

Commit

Permalink
return failure as before after resubmit
Browse files Browse the repository at this point in the history
  • Loading branch information
NeverHappened committed Oct 29, 2024
1 parent 59ce5bc commit 421b785
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 29 deletions.
73 changes: 45 additions & 28 deletions wasmbinding/message_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
})
Expand All @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion wasmbinding/test/custom_message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 421b785

Please sign in to comment.