From 0af6442986ab818efbe2e5b61c07f31322395868 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=90=C3=B4ng=20Li=E1=BB=81u?= <93205232+DongLieu@users.noreply.github.com> Date: Wed, 25 Oct 2023 14:50:10 +0700 Subject: [PATCH] test for DeleteRedelegationRecordByKey (#674) * test for TestDeleteRedelegationRecordByKey * lint --------- Co-authored-by: Joe Bowman --- .../keeper/redelegation_record_test.go | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/x/interchainstaking/keeper/redelegation_record_test.go b/x/interchainstaking/keeper/redelegation_record_test.go index a4604df6b..1fb3662b4 100644 --- a/x/interchainstaking/keeper/redelegation_record_test.go +++ b/x/interchainstaking/keeper/redelegation_record_test.go @@ -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()