Skip to content

Commit

Permalink
fix: ibc-hooks unit tests to work with ibc-go >= 7.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Max authored and xlab committed Jul 24, 2023
1 parent ff99bd9 commit 3ea561a
Showing 1 changed file with 35 additions and 4 deletions.
39 changes: 35 additions & 4 deletions modules/ibc-hooks/tests/unit/module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,15 @@ func (suite *HooksTestSuite) TestOnRecvPacketEcho() {

// send funds to the escrow address to simulate a transfer from the ibc module
escrowAddress := transfertypes.GetEscrowAddress(recvPacket.GetDestPort(), recvPacket.GetDestChannel())
err := suite.App.BankKeeper.SendCoins(suite.Ctx, suite.TestAddress.GetAddress(), escrowAddress, sdk.NewCoins(sdk.NewInt64Coin("stake", 2)))
testEscrowAmount := sdk.NewInt64Coin("stake", 2)
err := suite.App.BankKeeper.SendCoins(suite.Ctx, suite.TestAddress.GetAddress(), escrowAddress, sdk.NewCoins(testEscrowAmount))
suite.NoError(err)

// since ibc-go >= 7.1.0 escrow needs to be explicitly tracked
if transferKeeper, ok := any(&suite.App.TransferKeeper).(TransferKeeperWithTotalEscrowTracking); ok {
transferKeeper.SetTotalEscrowForDenom(suite.Ctx, testEscrowAmount)
}

// create the wasm hooks
wasmHooks := ibc_hooks.NewWasmHooks(
&suite.App.IBCHooksKeeper,
Expand Down Expand Up @@ -158,9 +164,15 @@ func (suite *HooksTestSuite) TestOnRecvPacketCounterContract() {

// send funds to the escrow address to simulate a transfer from the ibc module
escrowAddress := transfertypes.GetEscrowAddress(recvPacket.GetDestPort(), recvPacket.GetDestChannel())
err := suite.App.BankKeeper.SendCoins(suite.Ctx, suite.TestAddress.GetAddress(), escrowAddress, sdk.NewCoins(sdk.NewInt64Coin("stake", 2)))
testEscrowAmount := sdk.NewInt64Coin("stake", 2)
err := suite.App.BankKeeper.SendCoins(suite.Ctx, suite.TestAddress.GetAddress(), escrowAddress, sdk.NewCoins(testEscrowAmount))
suite.NoError(err)

// since ibc-go >= 7.1.0 escrow needs to be explicitly tracked
if transferKeeper, ok := any(&suite.App.TransferKeeper).(TransferKeeperWithTotalEscrowTracking); ok {
transferKeeper.SetTotalEscrowForDenom(suite.Ctx, testEscrowAmount)
}

// create the wasm hooks
wasmHooks := ibc_hooks.NewWasmHooks(
&suite.App.IBCHooksKeeper,
Expand Down Expand Up @@ -230,9 +242,15 @@ func (suite *HooksTestSuite) TestOnAcknowledgementPacketCounterContract() {

// send funds to the escrow address to simulate a transfer from the ibc module
escrowAddress := transfertypes.GetEscrowAddress(callbackPacket.GetDestPort(), callbackPacket.GetDestChannel())
err := suite.App.BankKeeper.SendCoins(suite.Ctx, suite.TestAddress.GetAddress(), escrowAddress, sdk.NewCoins(sdk.NewInt64Coin("stake", 2)))
testEscrowAmount := sdk.NewInt64Coin("stake", 2)
err := suite.App.BankKeeper.SendCoins(suite.Ctx, suite.TestAddress.GetAddress(), escrowAddress, sdk.NewCoins(testEscrowAmount))
suite.NoError(err)

// since ibc-go >= 7.1.0 escrow needs to be explicitly tracked
if transferKeeper, ok := any(&suite.App.TransferKeeper).(TransferKeeperWithTotalEscrowTracking); ok {
transferKeeper.SetTotalEscrowForDenom(suite.Ctx, testEscrowAmount)
}

// create the wasm hooks
wasmHooks := ibc_hooks.NewWasmHooks(
&suite.App.IBCHooksKeeper,
Expand Down Expand Up @@ -323,9 +341,15 @@ func (suite *HooksTestSuite) TestOnTimeoutPacketOverrideCounterContract() {

// send funds to the escrow address to simulate a transfer from the ibc module
escrowAddress := transfertypes.GetEscrowAddress(callbackPacket.GetDestPort(), callbackPacket.GetDestChannel())
err := suite.App.BankKeeper.SendCoins(suite.Ctx, suite.TestAddress.GetAddress(), escrowAddress, sdk.NewCoins(sdk.NewInt64Coin("stake", 2)))
testEscrowAmount := sdk.NewInt64Coin("stake", 2)
err := suite.App.BankKeeper.SendCoins(suite.Ctx, suite.TestAddress.GetAddress(), escrowAddress, sdk.NewCoins(testEscrowAmount))
suite.NoError(err)

// since ibc-go >= 7.1.0 escrow needs to be explicitly tracked
if transferKeeper, ok := any(&suite.App.TransferKeeper).(TransferKeeperWithTotalEscrowTracking); ok {
transferKeeper.SetTotalEscrowForDenom(suite.Ctx, testEscrowAmount)
}

// create the wasm hooks
wasmHooks := ibc_hooks.NewWasmHooks(
&suite.App.IBCHooksKeeper,
Expand Down Expand Up @@ -397,3 +421,10 @@ func (suite *HooksTestSuite) TestOnTimeoutPacketOverrideCounterContract() {
suite.NoError(err)
suite.Equal(`{"count":10}`, string(count))
}

// TransferKeeperWithTotalEscrowTracking defines an interface to check for existing methods
// in TransferKeeper.
type TransferKeeperWithTotalEscrowTracking interface {
SetTotalEscrowForDenom(ctx sdk.Context, coin sdk.Coin)
GetTotalEscrowForDenom(ctx sdk.Context, denom string) sdk.Coin
}

0 comments on commit 3ea561a

Please sign in to comment.