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

[CORE-538] Address nit and fix Cosmos 0.50 post merge conflict #922

Merged
merged 2 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions protocol/app/process/other_msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ func DecodeOtherMsgsTx(decoder sdk.TxDecoder, txBytes []byte) (*OtherMsgsTx, err

// Validate returns an error if one of the underlying msgs fails `ValidateBasic`.
func (omt *OtherMsgsTx) Validate() error {
// Note that with Cosmos SDK 0.50.0 ValidateBasic has been removed from SDK message types,
// and it is recommended that users simulate the transaction instead to ensure that it could be
// processed.
for _, msg := range omt.msgs {
if m, ok := msg.(sdk.HasValidateBasic); ok {
if err := m.ValidateBasic(); err != nil {
Comment on lines 58 to 66
Copy link
Contributor

Choose a reason for hiding this comment

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

The Validate method's comments indicate that ValidateBasic has been removed from SDK message types in Cosmos SDK 0.50.0, and transaction simulation is recommended instead. However, the code still checks for sdk.HasValidateBasic and calls ValidateBasic if available. This could lead to confusion and should be clarified or updated to reflect the new recommended practice.

- if m, ok := msg.(sdk.HasValidateBasic); ok {
-     if err := m.ValidateBasic(); err != nil {
+ // if m, ok := msg.(sdk.HasValidateBasic); ok {
+ //     if err := m.ValidateBasic(); err != nil {
+ //         return getValidateBasicError(msg, err)
+ //     }
+ // }
+ // TODO: Implement transaction simulation as per Cosmos SDK 0.50.0 recommendations

Committable suggestion

IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
// Validate returns an error if one of the underlying msgs fails `ValidateBasic`.
func (omt *OtherMsgsTx) Validate() error {
// Note that with Cosmos SDK 0.50.0 ValidateBasic has been removed from SDK message types,
// and it is recommended that users simulate the transaction instead to ensure that it could be
// processed.
for _, msg := range omt.msgs {
if m, ok := msg.(sdk.HasValidateBasic); ok {
if err := m.ValidateBasic(); err != nil {
// Validate returns an error if one of the underlying msgs fails `ValidateBasic`.
func (omt *OtherMsgsTx) Validate() error {
// Note that with Cosmos SDK 0.50.0 ValidateBasic has been removed from SDK message types,
// and it is recommended that users simulate the transaction instead to ensure that it could be
// processed.
for _, msg := range omt.msgs {
// if m, ok := msg.(sdk.HasValidateBasic); ok {
// if err := m.ValidateBasic(); err != nil {
// return getValidateBasicError(msg, err)
// }
// }
// TODO: Implement transaction simulation as per Cosmos SDK 0.50.0 recommendations

Expand Down
41 changes: 21 additions & 20 deletions protocol/x/ratelimit/keeper/keeper_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package keeper_test

import (
sdkmath "cosmossdk.io/math"
"math/big"
"testing"

Expand Down Expand Up @@ -104,7 +105,7 @@ func TestSetGetLimitParams_Success(t *testing.T) {
Coins: sdk.Coins{
{
Denom: testDenom,
Amount: sdk.NewInt(25_000_000_000_000), // 25M token
Amount: sdkmath.NewInt(25_000_000_000_000), // 25M token
},
},
},
Expand All @@ -113,7 +114,7 @@ func TestSetGetLimitParams_Success(t *testing.T) {
Coins: sdk.Coins{
{
Denom: testDenom,
Amount: sdk.NewInt(25_000_000_000_000), // 25M token
Amount: sdkmath.NewInt(25_000_000_000_000), // 25M token
},
},
},
Expand Down Expand Up @@ -143,7 +144,7 @@ func TestSetGetLimitParams_Success(t *testing.T) {
Coins: sdk.Coins{
{
Denom: testDenom,
Amount: sdk.NewInt(25_123_450_000_000), // 25M token
Amount: sdkmath.NewInt(25_123_450_000_000), // 25M token
},
},
},
Expand All @@ -152,7 +153,7 @@ func TestSetGetLimitParams_Success(t *testing.T) {
Coins: sdk.Coins{
{
Denom: testDenom,
Amount: sdk.NewInt(25_000_000_000_000), // 25M token
Amount: sdkmath.NewInt(25_000_000_000_000), // 25M token
},
},
},
Expand Down Expand Up @@ -182,7 +183,7 @@ func TestSetGetLimitParams_Success(t *testing.T) {
Coins: sdk.Coins{
{
Denom: testDenom,
Amount: sdk.NewInt(25_000_000_000_000), // 25M token
Amount: sdkmath.NewInt(25_000_000_000_000), // 25M token
},
},
},
Expand All @@ -191,7 +192,7 @@ func TestSetGetLimitParams_Success(t *testing.T) {
Coins: sdk.Coins{
{
Denom: testDenom,
Amount: sdk.NewInt(25_000_000_000_000), // 25M token
Amount: sdkmath.NewInt(25_000_000_000_000), // 25M token
},
},
},
Expand Down Expand Up @@ -282,7 +283,7 @@ func TestGetBaseline(t *testing.T) {
Coins: sdk.Coins{
{
Denom: testDenom,
Amount: sdk.NewInt(1_000_000_000_000), // 1M token
Amount: sdkmath.NewInt(1_000_000_000_000), // 1M token
},
},
},
Expand All @@ -291,7 +292,7 @@ func TestGetBaseline(t *testing.T) {
Coins: sdk.Coins{
{
Denom: testDenom,
Amount: sdk.NewInt(4_000_000_000_000), // 4M token
Amount: sdkmath.NewInt(4_000_000_000_000), // 4M token
},
},
},
Expand All @@ -311,7 +312,7 @@ func TestGetBaseline(t *testing.T) {
Coins: sdk.Coins{
{
Denom: testDenom,
Amount: sdk.NewInt(1_000_000_000_000), // 1M token
Amount: sdkmath.NewInt(1_000_000_000_000), // 1M token
},
},
},
Expand All @@ -320,7 +321,7 @@ func TestGetBaseline(t *testing.T) {
Coins: sdk.Coins{
{
Denom: testDenom,
Amount: sdk.NewInt(4_000_000_000_000), // 4M token
Amount: sdkmath.NewInt(4_000_000_000_000), // 4M token
},
},
},
Expand All @@ -329,7 +330,7 @@ func TestGetBaseline(t *testing.T) {
Coins: sdk.Coins{
{
Denom: testDenom,
Amount: sdk.NewInt(10_000_000_000_000), // 10M token
Amount: sdkmath.NewInt(10_000_000_000_000), // 10M token
},
},
},
Expand All @@ -349,7 +350,7 @@ func TestGetBaseline(t *testing.T) {
Coins: sdk.Coins{
{
Denom: testDenom,
Amount: sdk.NewInt(1_000_000_000_000), // 1M token
Amount: sdkmath.NewInt(1_000_000_000_000), // 1M token
},
},
},
Expand All @@ -358,7 +359,7 @@ func TestGetBaseline(t *testing.T) {
Coins: sdk.Coins{
{
Denom: testDenom,
Amount: sdk.NewInt(4_000_123_456_777), // ~4M token
Amount: sdkmath.NewInt(4_000_123_456_777), // ~4M token
},
},
},
Expand All @@ -367,7 +368,7 @@ func TestGetBaseline(t *testing.T) {
Coins: sdk.Coins{
{
Denom: testDenom,
Amount: sdk.NewInt(10_200_000_000_000), // ~10M token
Amount: sdkmath.NewInt(10_200_000_000_000), // ~10M token
},
},
},
Expand All @@ -387,7 +388,7 @@ func TestGetBaseline(t *testing.T) {
Coins: sdk.Coins{
{
Denom: testDenom,
Amount: sdk.NewInt(6_000_000_000_000), // 6M token
Amount: sdkmath.NewInt(6_000_000_000_000), // 6M token
},
},
},
Expand All @@ -396,7 +397,7 @@ func TestGetBaseline(t *testing.T) {
Coins: sdk.Coins{
{
Denom: testDenom,
Amount: sdk.NewInt(4_000_000_000_000), // 4M token
Amount: sdkmath.NewInt(4_000_000_000_000), // 4M token
},
},
},
Expand All @@ -405,7 +406,7 @@ func TestGetBaseline(t *testing.T) {
Coins: sdk.Coins{
{
Denom: testDenom,
Amount: sdk.NewInt(10_000_000_000_000), // 10M token
Amount: sdkmath.NewInt(10_000_000_000_000), // 10M token
},
},
},
Expand All @@ -425,7 +426,7 @@ func TestGetBaseline(t *testing.T) {
Coins: sdk.Coins{
{
Denom: testDenom,
Amount: sdk.NewInt(2_000_000_000_000), // 2M token
Amount: sdkmath.NewInt(2_000_000_000_000), // 2M token
},
},
},
Expand All @@ -434,7 +435,7 @@ func TestGetBaseline(t *testing.T) {
Coins: sdk.Coins{
{
Denom: testDenom,
Amount: sdk.NewInt(4_000_000_000_000), // 4M token
Amount: sdkmath.NewInt(4_000_000_000_000), // 4M token
},
},
},
Expand All @@ -443,7 +444,7 @@ func TestGetBaseline(t *testing.T) {
Coins: sdk.Coins{
{
Denom: testDenom,
Amount: sdk.NewInt(2_000_000_000_000), // 2M token
Amount: sdkmath.NewInt(2_000_000_000_000), // 2M token
},
},
},
Expand Down
3 changes: 2 additions & 1 deletion protocol/x/ratelimit/types/expected_keepers.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package types

import (
"context"
sdk "github.com/cosmos/cosmos-sdk/types"
)

// BankKeeper defines the expected bank keeper used for simulations.
type BankKeeper interface {
GetSupply(ctx sdk.Context, denom string) sdk.Coin
GetSupply(ctx context.Context, denom string) sdk.Coin
}
Loading