Skip to content

Commit

Permalink
ibchooks testutil
Browse files Browse the repository at this point in the history
  • Loading branch information
expertdicer committed Jan 14, 2024
1 parent 05bf1df commit f056561
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions tests/ibc-hooks/testutils/testing_hooks.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package testutils

import (
// external libraries
sdk "github.com/cosmos/cosmos-sdk/types"

// ibc-go
channeltypes "github.com/cosmos/ibc-go/v6/modules/core/04-channel/types"
ibcexported "github.com/cosmos/ibc-go/v6/modules/core/exported"

ibchooks "github.com/terra-money/core/v2/x/ibc-hooks"
)

var (
_ ibchooks.Hooks = TestRecvOverrideHooks{}
_ ibchooks.Hooks = TestRecvBeforeAfterHooks{}
)

type Status struct {
OverrideRan bool
BeforeRan bool
AfterRan bool
}

// Recv
type TestRecvOverrideHooks struct{ Status *Status }

func (t TestRecvOverrideHooks) OnRecvPacketOverride(im ibchooks.IBCMiddleware, ctx sdk.Context, packet channeltypes.Packet, relayer sdk.AccAddress) ibcexported.Acknowledgement {
t.Status.OverrideRan = true
ack := im.App.OnRecvPacket(ctx, packet, relayer)
return ack
}

type TestRecvBeforeAfterHooks struct{ Status *Status }

func (t TestRecvBeforeAfterHooks) OnRecvPacketBeforeHook(ctx sdk.Context, packet channeltypes.Packet, relayer sdk.AccAddress) {
t.Status.BeforeRan = true
}

func (t TestRecvBeforeAfterHooks) OnRecvPacketAfterHook(ctx sdk.Context, packet channeltypes.Packet, relayer sdk.AccAddress, ack ibcexported.Acknowledgement) {
t.Status.AfterRan = true
}

0 comments on commit f056561

Please sign in to comment.