From 5cba5d4b5490b021cd8aedb7eb310199291106b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ph=E1=BA=A1m=20Anh=20Minh?= <1phamminh0811@gmail.com> Date: Wed, 27 Sep 2023 14:47:10 +0700 Subject: [PATCH 1/3] add gcc completed redelegations test --- .../keeper/redelegation_record_test.go | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/x/interchainstaking/keeper/redelegation_record_test.go b/x/interchainstaking/keeper/redelegation_record_test.go index e95431a47..1c05d01b1 100644 --- a/x/interchainstaking/keeper/redelegation_record_test.go +++ b/x/interchainstaking/keeper/redelegation_record_test.go @@ -51,3 +51,57 @@ 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)) +} \ No newline at end of file From 45b3da31e2da194243380ec48d74a5442d308087 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ph=E1=BA=A1m=20Anh=20Minh?= <1phamminh0811@gmail.com> Date: Wed, 27 Sep 2023 15:16:12 +0700 Subject: [PATCH 2/3] lint --- x/interchainstaking/keeper/redelegation_record_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/x/interchainstaking/keeper/redelegation_record_test.go b/x/interchainstaking/keeper/redelegation_record_test.go index 1c05d01b1..881c1219e 100644 --- a/x/interchainstaking/keeper/redelegation_record_test.go +++ b/x/interchainstaking/keeper/redelegation_record_test.go @@ -59,14 +59,14 @@ func (suite *KeeperTestSuite) TestGCCompletedRedelegations() { 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, @@ -76,7 +76,7 @@ func (suite *KeeperTestSuite) TestGCCompletedRedelegations() { CompletionTime: currentTime.Add(time.Hour).UTC(), } quicksilver.InterchainstakingKeeper.SetRedelegationRecord(ctx, record) - + record = types.RedelegationRecord{ ChainId: "cosmoshub-4", EpochNumber: 1, @@ -104,4 +104,4 @@ func (suite *KeeperTestSuite) TestGCCompletedRedelegations() { records = quicksilver.InterchainstakingKeeper.AllRedelegationRecords(ctx) suite.Equal(2, len(records)) -} \ No newline at end of file +} From 44fa39e8ea644ec12d3e6ea9ab62bd81dcf863cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ph=E1=BA=A1m=20Anh=20Minh?= <1phamminh0811@gmail.com> Date: Wed, 27 Sep 2023 15:48:04 +0700 Subject: [PATCH 3/3] try to get deleted delegation record --- x/interchainstaking/keeper/redelegation_record_test.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/x/interchainstaking/keeper/redelegation_record_test.go b/x/interchainstaking/keeper/redelegation_record_test.go index 881c1219e..7a5bfee4a 100644 --- a/x/interchainstaking/keeper/redelegation_record_test.go +++ b/x/interchainstaking/keeper/redelegation_record_test.go @@ -104,4 +104,7 @@ func (suite *KeeperTestSuite) TestGCCompletedRedelegations() { records = quicksilver.InterchainstakingKeeper.AllRedelegationRecords(ctx) suite.Equal(2, len(records)) + + _, found := quicksilver.InterchainstakingKeeper.GetRedelegationRecord(ctx, "cosmoshub-4", testValidatorOne, testValidatorThree, 1) + suite.False(found) }