Skip to content

Commit

Permalink
added unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
sampocs committed Mar 5, 2024
1 parent 15be2a5 commit cd751c1
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/upgrades/v19/legacyratelimit/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The legacy ratelimit types aren't required for this migration (since the types are the same), but they're used as a sanity check in the unit tests.
94 changes: 94 additions & 0 deletions app/upgrades/v19/upgrades_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package v19_test

import (
"testing"

sdkmath "cosmossdk.io/math"

ratelimittypes "github.com/Stride-Labs/ibc-rate-limiting/ratelimit/types"
"github.com/cosmos/cosmos-sdk/store/prefix"
"github.com/stretchr/testify/suite"

"github.com/Stride-Labs/stride/v18/app"
"github.com/Stride-Labs/stride/v18/app/apptesting"
legacyratelimittypes "github.com/Stride-Labs/stride/v18/app/upgrades/v19/legacyratelimit/types"
)

type UpgradeTestSuite struct {
apptesting.AppTestHelper
}

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

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

func (s *UpgradeTestSuite) TestUpgrade() {
dummyUpgradeHeight := int64(5)

checkRateLimitsAfterUpgrade := s.SetupRateLimitsBeforeUpgrade()

// Run through upgrade
s.ConfirmUpgradeSucceededs("v19", dummyUpgradeHeight)

checkRateLimitsAfterUpgrade()
}

func (s *UpgradeTestSuite) SetupRateLimitsBeforeUpgrade() func() {
rateLimitStore := s.Ctx.KVStore(s.App.GetKey(ratelimittypes.StoreKey))
cdc := app.MakeEncodingConfig().Marshaler

denom := "denom"
channelId := "channel-0"
flow := sdkmath.NewInt(10)
channelValue := sdkmath.NewInt(100)

initialRateLimit := legacyratelimittypes.RateLimit{
Path: &legacyratelimittypes.Path{
Denom: denom,
ChannelId: channelId,
},
Flow: &legacyratelimittypes.Flow{
Inflow: flow,
Outflow: flow,
ChannelValue: channelValue,
},
Quota: &legacyratelimittypes.Quota{
MaxPercentSend: sdkmath.NewInt(10),
MaxPercentRecv: sdkmath.NewInt(10),
DurationHours: 24,
},
}

expectedRateLimit := ratelimittypes.RateLimit{
Path: &ratelimittypes.Path{
Denom: denom,
ChannelId: channelId,
},
Flow: &ratelimittypes.Flow{
Inflow: flow,
Outflow: flow,
ChannelValue: channelValue,
},
Quota: &ratelimittypes.Quota{
MaxPercentSend: sdkmath.NewInt(10),
MaxPercentRecv: sdkmath.NewInt(10),
DurationHours: 24,
},
}

initialRateLimitBz, err := cdc.Marshal(&initialRateLimit)
s.Require().NoError(err)

hostzoneStore := prefix.NewStore(rateLimitStore, ratelimittypes.RateLimitKeyPrefix)
hostzoneStore.Set(ratelimittypes.GetRateLimitItemKey(denom, channelId), initialRateLimitBz)

return func() {
actualRateLimit, found := s.App.RatelimitKeeper.GetRateLimit(s.Ctx, denom, channelId)
s.Require().True(found, "rate limit should have been found")
s.Require().Equal(expectedRateLimit, actualRateLimit, "rate limit after upgrade")
}
}

0 comments on commit cd751c1

Please sign in to comment.