Skip to content

Commit

Permalink
test for TestDeleteRedelegationRecordByKey
Browse files Browse the repository at this point in the history
  • Loading branch information
DongLieu committed Oct 9, 2023
1 parent 543f819 commit 8ee78d6
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 @@ -108,3 +108,60 @@ func (suite *KeeperTestSuite) TestGCCompletedRedelegations() {
_, found := quicksilver.InterchainstakingKeeper.GetRedelegationRecord(ctx, "cosmoshub-4", testValidatorOne, testValidatorThree, 1)
suite.False(found)
}
func (suite *KeeperTestSuite) TestDeleteRedelegationRecordByKey() {
quicksilver := suite.GetQuicksilverApp(suite.chainA)
ctx := suite.chainA.GetContext()

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

suite.SetupTest()

// Currently there are 0 records
records := quicksilver.InterchainstakingKeeper.AllRedelegationRecords(ctx)
suite.Equal(0, len(records))

// Set 3 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)
// Check set 3 records
records = quicksilver.InterchainstakingKeeper.AllRedelegationRecords(ctx)
suite.Equal(3, len(records))
// Handle DeleteRedelegationRecordByKey for 3 records
quicksilver.InterchainstakingKeeper.IterateRedelegationRecords(ctx, func(idx int64, key []byte, redelegation types.RedelegationRecord) bool {
quicksilver.InterchainstakingKeeper.DeleteRedelegationRecordByKey(ctx, append(types.KeyPrefixRedelegationRecord, key...))
return false
})
// Check DeleteRedelegationRecordByKey 3 records to 0 records
records = quicksilver.InterchainstakingKeeper.AllRedelegationRecords(ctx)
suite.Equal(0, len(records))
}

0 comments on commit 8ee78d6

Please sign in to comment.