Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V18 Upgrade Migrations #1084

Merged
merged 41 commits into from
Jan 26, 2024
Merged
Changes from 1 commit
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
dbfc0c3
re-fetched updated records after refresh
sampocs Jan 16, 2024
df83c77
added unit test for native refresh
sampocs Jan 17, 2024
910490d
Merge branch 'main' into reload-after-refresh
sampocs Jan 17, 2024
8354eaa
add upgrade handler
shellvish Jan 18, 2024
ff6fbab
Merge remote-tracking branch 'origin/reload-after-refresh' into v18-u…
shellvish Jan 18, 2024
c67c9f9
remove hub tokenizations
shellvish Jan 18, 2024
a3bd21c
migrate URRs
shellvish Jan 19, 2024
6552b59
set host zone unbonding at end of migration
shellvish Jan 19, 2024
a1773ab
nit changes
sampocs Jan 25, 2024
a66d8c4
Update x/stakeibc/keeper/unbonding_records.go
shellvish Jan 25, 2024
c3beefa
added constants file
sampocs Jan 25, 2024
421b1e6
switched to using redemption rate instead of unbond amount
sampocs Jan 25, 2024
9ac0359
Merge branch 'v18-upgrade-migrations' of github.com:Stride-Labs/strid…
sampocs Jan 25, 2024
02784bf
nit
sampocs Jan 25, 2024
ecfbd8b
nit
sampocs Jan 25, 2024
2759211
bugs
sampocs Jan 25, 2024
ebe7c3d
unit test
sampocs Jan 26, 2024
6403334
added starting epoch catch
sampocs Jan 26, 2024
3ae173c
Merge branch 'main' into v18-upgrade-migrations
asalzmann Jan 26, 2024
59d980a
add store key (#1088)
asalzmann Jan 26, 2024
72113ff
added upgrade unit test
sampocs Jan 26, 2024
98db45a
Merge branch 'v18-upgrade-migrations' of github.com:Stride-Labs/strid…
sampocs Jan 26, 2024
51eb82b
decrement terra delegations in progress by 3 in upgrade (#1089)
riley-stride Jan 26, 2024
3d9e44d
fixed unbonding unit tests (#1090)
sampocs Jan 26, 2024
f5ec490
added test case for status
sampocs Jan 26, 2024
ad69282
Merge branch 'v18-upgrade-migrations' of github.com:Stride-Labs/strid…
sampocs Jan 26, 2024
78b0e5f
lint fix
sampocs Jan 26, 2024
a73128a
added additional upgrade unit tests
sampocs Jan 26, 2024
ea02062
nit
sampocs Jan 26, 2024
289e922
nit
sampocs Jan 26, 2024
2f2f290
update constants
shellvish Jan 26, 2024
64fa722
Revert "update constants"
shellvish Jan 26, 2024
86c642d
Merge branch 'v18-upgrade-migrations' of github.com:Stride-Labs/strid…
sampocs Jan 26, 2024
bc3ec3d
Update constants.go
shellvish Jan 26, 2024
7f36d24
update starting estimate
shellvish Jan 26, 2024
1f06083
Update constants.go
shellvish Jan 26, 2024
5912787
Signaling prop in upgrade (#1092)
sampocs Jan 26, 2024
f9dea85
update constants with most recent data
shellvish Jan 26, 2024
0dd8f75
Merge branch 'v18-upgrade-migrations' of github.com:Stride-Labs/strid…
sampocs Jan 26, 2024
011a78a
fixed unit test after refresh
sampocs Jan 26, 2024
56602ca
Merge branch 'main' into v18-upgrade-migrations
sampocs Jan 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
147 changes: 145 additions & 2 deletions app/upgrades/v18/upgrades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,155 @@ type UpgradeTestSuite struct {
apptesting.AppTestHelper
}

func TestKeeperTestSuite(t *testing.T) {
suite.Run(t, new(UpgradeTestSuite))
}

func (s *UpgradeTestSuite) SetupTest() {
s.Setup()
}

func TestKeeperTestSuite(t *testing.T) {
suite.Run(t, new(UpgradeTestSuite))
func (s *UpgradeTestSuite) TestUpgrade() {
dummyUpgradeHeight := int64(5)

checkStoreAfterUpgrade := s.SetupTestUnbondingRecords()
s.ConfirmUpgradeSucceededs("v18", dummyUpgradeHeight)
checkStoreAfterUpgrade()
}

func (s *UpgradeTestSuite) SetupTestUnbondingRecords() func() {
chainId := "sommelier-3"
epochNumberBefore := uint64(501)
epochNumberAfter := uint64(510)
stTokenAmount := sdkmath.NewInt(1_000_000)

// Unbonding #1 (before prop)
redemptionRateUnbonded := sdk.MustNewDecFromStr("1.0256449837573494") // Rate used when unbonding occurred
redemptionRateRecords := sdk.MustNewDecFromStr("1.0257449837673494") // Rate that was on record at the time (+0.0001)

s.Require().Equal(redemptionRateUnbonded.String(), v18.RedemptionRatesBeforeProp[chainId][epochNumberBefore].String(),
"example redemption rate from before prop does not match constants - update the test")

// Unbonding #2 (after prop)
redemptionRateAtPropTime := sdk.MustNewDecFromStr("1.025900883208774724") // Rate at prop time
redemptionRateAtUpgradeTime := sdk.MustNewDecFromStr("1.03") // Rate at upgrade time
estimatedRedemptionRate := sdk.MustNewDecFromStr("1.027950441604387362") // Estimated rate used to update record
unknownRedemptionRate := sdk.MustNewDecFromStr("1.029") // Rate that was used in unbonding

s.Require().Equal(redemptionRateAtPropTime.String(), v18.RedemptionRatesAtTimeOfProp[chainId].String(),
"example redemption rate from time of prop does not match constants - update the test")

// Calculate native token in the records before the upgrade
initialNativeAmount1 := sdk.NewDecFromInt(stTokenAmount).Mul(redemptionRateRecords).TruncateInt()
initialNativeAmount2 := sdk.NewDecFromInt(stTokenAmount).Mul(unknownRedemptionRate).TruncateInt()

// Calculate expected native amounts after upgrade
expectedNativeAmount1 := sdk.NewDecFromInt(stTokenAmount).Mul(redemptionRateUnbonded).TruncateInt()
expectedNativeAmount2 := sdk.NewDecFromInt(stTokenAmount).Mul(estimatedRedemptionRate).TruncateInt()

// Create the host zone with redemption rate at time of upgrade
s.App.StakeibcKeeper.SetHostZone(s.Ctx, stakeibctypes.HostZone{
ChainId: chainId,
RedemptionRate: redemptionRateAtUpgradeTime,
})

// Create redemption records - one before and one after the prop
s.App.RecordsKeeper.SetUserRedemptionRecord(s.Ctx, recordtypes.UserRedemptionRecord{
Id: "A",
EpochNumber: epochNumberBefore,
HostZoneId: chainId,
StTokenAmount: stTokenAmount,
NativeTokenAmount: initialNativeAmount1,
})
s.App.RecordsKeeper.SetUserRedemptionRecord(s.Ctx, recordtypes.UserRedemptionRecord{
Id: "B",
EpochNumber: epochNumberAfter,
HostZoneId: chainId,
StTokenAmount: stTokenAmount,
NativeTokenAmount: initialNativeAmount2,
})

// Create epoch unbonding records
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we test records in other statuses?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was considering that too, but didn't want the test to get too bloated.

Happy to add it in the morn if you think it makes sense!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just one other status to make sure the record filtering works

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

s.App.RecordsKeeper.SetEpochUnbondingRecord(s.Ctx, recordtypes.EpochUnbondingRecord{
EpochNumber: epochNumberBefore,
HostZoneUnbondings: []*recordtypes.HostZoneUnbonding{
{
HostZoneId: chainId,
Status: recordtypes.HostZoneUnbonding_EXIT_TRANSFER_QUEUE,
StTokenAmount: stTokenAmount,
NativeTokenAmount: initialNativeAmount1,
UserRedemptionRecords: []string{"A"},
},
},
})
s.App.RecordsKeeper.SetEpochUnbondingRecord(s.Ctx, recordtypes.EpochUnbondingRecord{
EpochNumber: epochNumberAfter,
HostZoneUnbondings: []*recordtypes.HostZoneUnbonding{
{
HostZoneId: chainId,
Status: recordtypes.HostZoneUnbonding_EXIT_TRANSFER_QUEUE,
StTokenAmount: stTokenAmount,
NativeTokenAmount: initialNativeAmount2,
UserRedemptionRecords: []string{"B"},
},
},
})

// Add a record that should be ignored because the epoch number is too low
epochNumberIgnore := uint64(3)
nativeAmountIgnored := stTokenAmount
s.App.RecordsKeeper.SetUserRedemptionRecord(s.Ctx, recordtypes.UserRedemptionRecord{
Id: "C",
EpochNumber: epochNumberIgnore,
HostZoneId: chainId,
StTokenAmount: stTokenAmount,
NativeTokenAmount: nativeAmountIgnored,
})
s.App.RecordsKeeper.SetEpochUnbondingRecord(s.Ctx, recordtypes.EpochUnbondingRecord{
EpochNumber: epochNumberIgnore,
HostZoneUnbondings: []*recordtypes.HostZoneUnbonding{
{
HostZoneId: chainId,
Status: recordtypes.HostZoneUnbonding_EXIT_TRANSFER_QUEUE,
StTokenAmount: stTokenAmount,
NativeTokenAmount: nativeAmountIgnored,
UserRedemptionRecords: []string{"C"},
},
},
})

// Return callback to check store after upgrade
return func() {
// Check the user redemption record amount for unbonding 1
actualRedemptionRecord1, found := s.App.RecordsKeeper.GetUserRedemptionRecord(s.Ctx, "A")
s.Require().True(found, "record from first unbonding should have been found")
s.Require().Equal(expectedNativeAmount1.Int64(), actualRedemptionRecord1.NativeTokenAmount.Int64(),
"native amount on record from first unbonding")

// Check the user redemption record amount for unbonding 2
actualRedemptionRecord2, found := s.App.RecordsKeeper.GetUserRedemptionRecord(s.Ctx, "B")
s.Require().True(found, "record from second unbonding should have been found")
s.Require().Equal(expectedNativeAmount2.Int64(), actualRedemptionRecord2.NativeTokenAmount.Int64(),
"native amount on record from second unbonding")

// Check the host zone unbonding amount for unbonding 1
actualHostZoneUnbonding1, found := s.App.RecordsKeeper.GetHostZoneUnbondingByChainId(s.Ctx, epochNumberBefore, chainId)
s.Require().True(found, "host zone unbonding should have been found for second unbonding")
s.Require().Equal(expectedNativeAmount1.Int64(), actualHostZoneUnbonding1.NativeTokenAmount.Int64(),
"host zone native amount from first unbonding")

// Check the host zone unbonding amount for unbonding 2
actualHostZoneUnbonding2, found := s.App.RecordsKeeper.GetHostZoneUnbondingByChainId(s.Ctx, epochNumberAfter, chainId)
s.Require().True(found, "host zone unbonding should have been found for second unbonding")
s.Require().Equal(expectedNativeAmount2.Int64(), actualHostZoneUnbonding2.NativeTokenAmount.Int64(),
"host zone native amount from first unbonding")

// Check that the ignored record did not change
ignoredRecord, found := s.App.RecordsKeeper.GetUserRedemptionRecord(s.Ctx, "C")
s.Require().True(found, "ignored record should have been found")
s.Require().Equal(nativeAmountIgnored.Int64(), ignoredRecord.NativeTokenAmount.Int64(),
"native amount on ignored record should not have changed")
}
}

func (s *UpgradeTestSuite) TestUpdateUnbondingRecords() {
Expand Down