Skip to content

Commit

Permalink
test for HandleCompleteSend (quicksilver-zone#672)
Browse files Browse the repository at this point in the history
* test for HandleCompleteSend

* Update x/interchainstaking/keeper/ibc_packet_handlers_test.go

* fix memo

* lint

* lint

* refacter

* Update x/interchainstaking/keeper/ibc_packet_handlers_test.go

Co-authored-by: Nguyen Thanh Nhan <[email protected]>

* Update x/interchainstaking/keeper/ibc_packet_handlers_test.go

Co-authored-by: Nguyen Thanh Nhan <[email protected]>

* Update x/interchainstaking/keeper/ibc_packet_handlers_test.go

Co-authored-by: Nguyen Thanh Nhan <[email protected]>

* lint

---------

Co-authored-by: Joe Bowman <[email protected]>
Co-authored-by: Nguyen Thanh Nhan <[email protected]>
Co-authored-by: ducnt131 <[email protected]>
  • Loading branch information
4 people authored Oct 27, 2023
1 parent 0d7bd7a commit 8d361ad
Showing 1 changed file with 82 additions and 0 deletions.
82 changes: 82 additions & 0 deletions x/interchainstaking/keeper/ibc_packet_handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package keeper_test

import (
"context"
"errors"
"fmt"
"testing"
"time"
Expand Down Expand Up @@ -2863,6 +2864,87 @@ func (suite *KeeperTestSuite) TestGetValidatorForToken() {
}
}

func (suite *KeeperTestSuite) TestHandleCompleteSend() {
testCases := []struct {
name string
message func(zone *icstypes.Zone) sdk.Msg
memo string
expectedError error
}{
{
name: "unexpected completed send",
message: func(zone *icstypes.Zone) sdk.Msg {
return &banktypes.MsgSend{
FromAddress: "",
ToAddress: "",
Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, sdk.NewInt(1_000_000))),
}
},
expectedError: errors.New("unexpected completed send (2) from to (amount: 1000000uatom)"),
},
{
name: "From WithdrawalAddress",
message: func(zone *icstypes.Zone) sdk.Msg {
return &banktypes.MsgSend{
FromAddress: zone.WithdrawalAddress.Address,
ToAddress: "",
Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, sdk.NewInt(1_000_000))),
}
},
expectedError: nil,
},
{
name: "From DepositAddress to DelegateAddress",
message: func(zone *icstypes.Zone) sdk.Msg {
return &banktypes.MsgSend{
FromAddress: zone.DepositAddress.Address,
ToAddress: zone.DelegationAddress.Address,
Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, sdk.NewInt(1_000_000))),
}
},
memo: "unbondSend/7C8B95EEE82CB63771E02EBEB05E6A80076D70B2E0A1C457F1FD1A0EF2EA961D",
expectedError: nil,
},
{
name: "From DepositAddress",
message: func(zone *icstypes.Zone) sdk.Msg {
return &banktypes.MsgSend{
FromAddress: zone.DelegationAddress.Address,
ToAddress: "",
Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, sdk.NewInt(1_000_000))),
}
},
memo: "unbondSend/7C8B95EEE82CB63771E02EBEB05E6A80076D70B2E0A1C457F1FD1A0EF2EA961D",
expectedError: errors.New("no matching withdrawal record found"),
},
}

for _, tc := range testCases {
suite.Run(tc.name, func() {
suite.SetupTest()
suite.setupTestZones()

quicksilver := suite.GetQuicksilverApp(suite.chainA)
ctx := suite.chainA.GetContext()
ctx = ctx.WithContext(context.WithValue(ctx.Context(), utils.ContextKey("connectionID"), suite.path.EndpointA.ConnectionID))
zone, found := quicksilver.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID)
if !found {
suite.Fail("unable to retrieve zone for test")
}
quicksilver.InterchainstakingKeeper.IBCKeeper.ChannelKeeper.SetChannel(ctx, "transfer", "channel-0", TestChannel)

msg := tc.message(&zone)

err := quicksilver.InterchainstakingKeeper.HandleCompleteSend(ctx, msg, tc.memo)
if tc.expectedError != nil {
suite.Equal(tc.expectedError, err)
} else {
suite.NoError(err)
}
})
}
}

func (suite *KeeperTestSuite) TestHandleFailedBankSend() {
v1 := addressutils.GenerateValAddressForTest().String()
v2 := addressutils.GenerateValAddressForTest().String()
Expand Down

0 comments on commit 8d361ad

Please sign in to comment.