Skip to content

Commit

Permalink
Merge branch 'main' into dong/TestGetChainIDFromContext
Browse files Browse the repository at this point in the history
  • Loading branch information
DongLieu committed Oct 11, 2023
2 parents 5285b25 + 3ac2700 commit 35c6884
Showing 1 changed file with 98 additions and 0 deletions.
98 changes: 98 additions & 0 deletions x/interchainstaking/keeper/redelegation_record_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package keeper_test
import (
"time"

sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/quicksilver-zone/quicksilver/utils/addressutils"
"github.com/quicksilver-zone/quicksilver/x/interchainstaking/types"
)
Expand Down Expand Up @@ -108,3 +110,99 @@ func (suite *KeeperTestSuite) TestGCCompletedRedelegations() {
_, found := quicksilver.InterchainstakingKeeper.GetRedelegationRecord(ctx, "cosmoshub-4", testValidatorOne, testValidatorThree, 1)
suite.False(found)
}

func (suite *KeeperTestSuite) TestGCCompletedUnbondings() {
suite.SetupTest()
suite.setupTestZones()

quicksilver := suite.GetQuicksilverApp(suite.chainA)
ctx := suite.chainA.GetContext()

zone, found := quicksilver.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID)
if !found {
suite.Fail("unable to retrieve zone for test")
}
records := quicksilver.InterchainstakingKeeper.AllWithdrawalRecords(ctx)
suite.Equal(0, len(records))

vals := quicksilver.InterchainstakingKeeper.GetValidators(ctx, zone.ChainId)
currentTime := ctx.BlockTime()

record1 := types.WithdrawalRecord{
ChainId: suite.chainB.ChainID,
Delegator: zone.DelegationAddress.Address,
Distribution: []*types.Distribution{
{
Valoper: vals[0].ValoperAddress,
Amount: 500,
},
{
Valoper: vals[1].ValoperAddress,
Amount: 500,
},
},
Recipient: user1.String(),
Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, sdk.NewInt(1000))),
BurnAmount: sdk.NewCoin(zone.LocalDenom, sdk.NewInt(1000)),
Txhash: "1613D2E8FBF7C7294A4D2247B55EE89FB22FC68C62D61050B944F1191DF092BD",
Status: types.WithdrawStatusCompleted,
CompletionTime: currentTime.Add(-25 * time.Hour).UTC(),
}
quicksilver.InterchainstakingKeeper.SetWithdrawalRecord(ctx, record1)

record2 := types.WithdrawalRecord{
ChainId: suite.chainB.ChainID,
Delegator: zone.DelegationAddress.Address,
Distribution: []*types.Distribution{
{
Valoper: vals[0].ValoperAddress,
Amount: 500,
},
{
Valoper: vals[1].ValoperAddress,
Amount: 500,
},
},
Recipient: user2.String(),
Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, sdk.NewInt(1000))),
BurnAmount: sdk.NewCoin(zone.LocalDenom, sdk.NewInt(1000)),
Txhash: "91DF093BD1613D2E8FBF7C7294A4D2247B55EE89FB22FC68C62D61050B944F11",
Status: types.WithdrawStatusUnbond,
CompletionTime: currentTime.Add(25 * time.Hour).UTC(),
}
quicksilver.InterchainstakingKeeper.SetWithdrawalRecord(ctx, record2)

record3 := types.WithdrawalRecord{
ChainId: suite.chainB.ChainID,
Delegator: zone.DelegationAddress.Address,
Distribution: []*types.Distribution{
{
Valoper: vals[0].ValoperAddress,
Amount: 500,
},
{
Valoper: vals[1].ValoperAddress,
Amount: 500,
},
},
Recipient: user2.String(),
Amount: sdk.NewCoins(sdk.NewCoin(zone.BaseDenom, sdk.NewInt(1000))),
BurnAmount: sdk.NewCoin(zone.LocalDenom, sdk.NewInt(1000)),
Txhash: "2247B55EE89FB22FC68C62D61050B944F1191DF093BD1613D2E8FBF7C7294A4D",
Status: types.WithdrawStatusUnbond,
CompletionTime: time.Time{},
}
quicksilver.InterchainstakingKeeper.SetWithdrawalRecord(ctx, record3)

records = quicksilver.InterchainstakingKeeper.AllWithdrawalRecords(ctx)
suite.Equal(3, len(records))

err := quicksilver.InterchainstakingKeeper.GCCompletedUnbondings(ctx, &zone)
suite.NoError(err)

records = quicksilver.InterchainstakingKeeper.AllWithdrawalRecords(ctx)
suite.Equal(2, len(records))

_, found = quicksilver.InterchainstakingKeeper.GetWithdrawalRecord(ctx, record1.ChainId, record1.Txhash, record1.Status)
suite.False(found)
}

0 comments on commit 35c6884

Please sign in to comment.