Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test for HandleCompleteSend #672

Merged
Merged
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 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 @@ -2862,6 +2863,78 @@ func (suite *KeeperTestSuite) TestGetValidatorForToken() {
}
}

func (suite *KeeperTestSuite) TestHandleCompleteSend() {
suite.Run("TestHandleCompleteSend", func() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey plz move this setup after line 2917 so we can know the name of each test case when we can run the testing

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)

// trigger handler with testcases
testCases := []struct {
name string
msg sdk.Msg
memo string
expectedError error
}{
{
name: "unexpected completed send",
msg: &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: "is withdrawal address",
msg: &banktypes.MsgSend{
FromAddress: zone.WithdrawalAddress.Address,
ToAddress: "",
Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, sdk.NewInt(1_000_000))),
},
expectedError: nil,
},
{
name: "is to delegation address",
msg: &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: "is from delegation address", // There is a separate test for handles withdraw for user
msg: &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 {
err := quicksilver.InterchainstakingKeeper.HandleCompleteSend(ctx, tc.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
Loading