Skip to content

Commit

Permalink
Test for GCCompletedRedelegations (#652)
Browse files Browse the repository at this point in the history
* add gcc completed redelegations test

* lint

* try to get deleted delegation record
  • Loading branch information
phamminh0811 authored Sep 28, 2023
1 parent 1457e3d commit a02415f
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions x/interchainstaking/keeper/redelegation_record_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,60 @@ func (suite *KeeperTestSuite) TestRedelegationRecordSetGetIterate() {
allCosmosRecords = quicksilver.InterchainstakingKeeper.AllRedelegationRecords(ctx)
suite.Equal(0, len(allCosmosRecords))
}

func (suite *KeeperTestSuite) TestGCCompletedRedelegations() {
quicksilver := suite.GetQuicksilverApp(suite.chainA)
ctx := suite.chainA.GetContext()

testValidatorOne := addressutils.GenerateAddressForTestWithPrefix("cosmosvaloper")
testValidatorTwo := addressutils.GenerateAddressForTestWithPrefix("cosmosvaloper")
testValidatorThree := addressutils.GenerateAddressForTestWithPrefix("cosmosvaloper")

suite.SetupTest()

records := quicksilver.InterchainstakingKeeper.AllRedelegationRecords(ctx)
suite.Equal(0, len(records))

currentTime := ctx.BlockTime()

record := types.RedelegationRecord{
ChainId: "cosmoshub-4",
EpochNumber: 1,
Source: testValidatorOne,
Destination: testValidatorTwo,
Amount: 3000,
CompletionTime: currentTime.Add(time.Hour).UTC(),
}
quicksilver.InterchainstakingKeeper.SetRedelegationRecord(ctx, record)

record = types.RedelegationRecord{
ChainId: "cosmoshub-4",
EpochNumber: 1,
Source: testValidatorOne,
Destination: testValidatorThree,
Amount: 3000,
CompletionTime: currentTime.Add(-time.Hour).UTC(),
}
quicksilver.InterchainstakingKeeper.SetRedelegationRecord(ctx, record)
record = types.RedelegationRecord{
ChainId: "cosmoshub-4",
EpochNumber: 1,
Source: testValidatorThree,
Destination: testValidatorTwo,
Amount: 3000,
CompletionTime: time.Time{},
}
quicksilver.InterchainstakingKeeper.SetRedelegationRecord(ctx, record)

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

err := quicksilver.InterchainstakingKeeper.GCCompletedRedelegations(ctx)
suite.NoError(err)

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

_, found := quicksilver.InterchainstakingKeeper.GetRedelegationRecord(ctx, "cosmoshub-4", testValidatorOne, testValidatorThree, 1)
suite.False(found)
}

0 comments on commit a02415f

Please sign in to comment.