Skip to content

Commit

Permalink
test for DeleteRedelegationRecordByKey (#674)
Browse files Browse the repository at this point in the history
* test for TestDeleteRedelegationRecordByKey

* lint

---------

Co-authored-by: Joe Bowman <[email protected]>
  • Loading branch information
DongLieu and Joe Bowman authored Oct 25, 2023
1 parent 444e813 commit 0af6442
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions x/interchainstaking/keeper/redelegation_record_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,64 @@ func (suite *KeeperTestSuite) TestGCCompletedRedelegations() {
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))
}

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

0 comments on commit 0af6442

Please sign in to comment.