Skip to content

Commit

Permalink
feat(rollapp): enforce EIP155 chain ID for rollapp creation (#1020)
Browse files Browse the repository at this point in the history
  • Loading branch information
zale144 authored Aug 7, 2024
1 parent c2c92a9 commit 55a7517
Show file tree
Hide file tree
Showing 20 changed files with 364 additions and 375 deletions.
6 changes: 3 additions & 3 deletions app/apptesting/test_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import (
"strings"

"github.com/cometbft/cometbft/libs/rand"
"github.com/cosmos/cosmos-sdk/crypto/types"

codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
"github.com/cosmos/cosmos-sdk/crypto/types"
sdk "github.com/cosmos/cosmos-sdk/types"
bankutil "github.com/cosmos/cosmos-sdk/x/bank/testutil"
"github.com/dymensionxyz/sdk-utils/utils/urand"
"github.com/stretchr/testify/suite"

"github.com/dymensionxyz/dymension/v3/app"
Expand All @@ -31,7 +31,7 @@ type KeeperTestHelper struct {
}

func (s *KeeperTestHelper) CreateDefaultRollappWithProposer() (string, string) {
return s.CreateRollappWithNameWithProposer(rand.Str(8))
return s.CreateRollappWithNameWithProposer(urand.RollappID())
}

func (s *KeeperTestHelper) CreateRollappWithNameWithProposer(name string) (string, string) {
Expand Down
2 changes: 1 addition & 1 deletion app/upgrades/v4/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func (s *UpgradeTestSuite) validateRollappsMigration(numRoll int) error {
s.Require().Len(rollapps, len(expectRollapps))

for _, rollapp := range rollapps {
rollappID, _ := rollapptypes.NewChainID(rollapp.RollappId)
rollappID := rollapptypes.MustNewChainID(rollapp.RollappId)
// check that the rollapp can be retrieved by EIP155 key
if _, ok := s.App.RollappKeeper.GetRollappByEIP155(s.Ctx, rollappID.GetEIP155ID()); !ok {
return fmt.Errorf("rollapp by EIP155 not found")
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ require (
github.com/decred/dcrd/dcrec/edwards v1.0.0
github.com/dustin/go-humanize v1.0.1
github.com/dymensionxyz/gerr-cosmos v1.0.0
github.com/dymensionxyz/sdk-utils v0.2.2
github.com/dymensionxyz/sdk-utils v0.2.7-0.20240807091416-0717365f0f61
github.com/ethereum/go-ethereum v1.10.26
github.com/evmos/ethermint v0.22.0
github.com/gogo/protobuf v1.3.3
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -503,8 +503,8 @@ github.com/dymensionxyz/osmosis/osmomath v0.0.6-dym-v0.0.1 h1:59ZE3Ocrn04MUpb5VJ
github.com/dymensionxyz/osmosis/osmomath v0.0.6-dym-v0.0.1/go.mod h1:2idySYJxP5YfMAEeSeqD8e7fSchfsI4jn7XFHJgNUsM=
github.com/dymensionxyz/osmosis/v15 v15.2.1-0.20240627111157-f2243f47cdb3 h1:4VD23Jv5d8hqXEhLNNcLXlpSDJCWAGYJLF0kisJtkIk=
github.com/dymensionxyz/osmosis/v15 v15.2.1-0.20240627111157-f2243f47cdb3/go.mod h1:2rsnXAdjYfXtyEw0mNwAdOiAccALYjAPvINGUf9Qg7Y=
github.com/dymensionxyz/sdk-utils v0.2.2 h1:RoANEXbR4nkEMaRGWCLT1P9A7KBCmzJ2U9wAZnNbszo=
github.com/dymensionxyz/sdk-utils v0.2.2/go.mod h1:ywr7+EEhHyuXCPUyLsktF3R4Mr31uCiviIjqwWNbQ84=
github.com/dymensionxyz/sdk-utils v0.2.7-0.20240807091416-0717365f0f61 h1:L9gxOTR+ZGd3+7Ycm3QVRHEYnE+rkIXRchlZMMAbsAc=
github.com/dymensionxyz/sdk-utils v0.2.7-0.20240807091416-0717365f0f61/go.mod h1:it9owYOpnIe17+ftTATQNDN4z+mBQx20/2Jm8SK15Rk=
github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs=
github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU=
github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I=
Expand Down
13 changes: 5 additions & 8 deletions x/incentives/client/cli/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,18 @@ import (
"testing"
"time"

tmrand "github.com/cometbft/cometbft/libs/rand"
cometbftproto "github.com/cometbft/cometbft/proto/tendermint/types"
"github.com/cosmos/cosmos-sdk/baseapp"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/dymensionxyz/sdk-utils/utils/urand"
"github.com/stretchr/testify/suite"

tmrand "github.com/cometbft/cometbft/libs/rand"

"github.com/dymensionxyz/dymension/v3/app/apptesting"
"github.com/dymensionxyz/dymension/v3/x/incentives/keeper"
"github.com/dymensionxyz/dymension/v3/x/incentives/types"

"github.com/cosmos/cosmos-sdk/baseapp"

rollapp "github.com/dymensionxyz/dymension/v3/x/rollapp/keeper"
rollapptypes "github.com/dymensionxyz/dymension/v3/x/rollapp/types"

sdk "github.com/cosmos/cosmos-sdk/types"
)

type QueryTestSuite struct {
Expand All @@ -35,7 +32,7 @@ func (suite *QueryTestSuite) CreateDefaultRollapp() string {

msgCreateRollapp := rollapptypes.MsgCreateRollapp{
Creator: alice.String(),
RollappId: tmrand.Str(8),
RollappId: urand.RollappID(),
Bech32Prefix: strings.ToLower(tmrand.Str(3)),
Alias: strings.ToLower(tmrand.Str(3)),
VmType: rollapptypes.Rollapp_EVM,
Expand Down
7 changes: 3 additions & 4 deletions x/incentives/keeper/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ import (
"time"

tmrand "github.com/cometbft/cometbft/libs/rand"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/dymensionxyz/sdk-utils/utils/urand"
lockuptypes "github.com/osmosis-labs/osmosis/v15/x/lockup/types"

"github.com/dymensionxyz/dymension/v3/x/incentives/types"
rollapp "github.com/dymensionxyz/dymension/v3/x/rollapp/keeper"
rollapptypes "github.com/dymensionxyz/dymension/v3/x/rollapp/types"

sdk "github.com/cosmos/cosmos-sdk/types"
)

var (
Expand Down Expand Up @@ -211,7 +210,7 @@ func (suite *KeeperTestSuite) CreateDefaultRollapp(addr sdk.AccAddress) string {

msgCreateRollapp := rollapptypes.MsgCreateRollapp{
Creator: addr.String(),
RollappId: tmrand.Str(8),
RollappId: urand.RollappID(),
Bech32Prefix: strings.ToLower(tmrand.Str(3)),
GenesisChecksum: "checksum",
InitialSequencer: addr.String(),
Expand Down
22 changes: 13 additions & 9 deletions x/rollapp/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,51 @@ package rollapp_test
import (
"testing"

"github.com/stretchr/testify/require"

keepertest "github.com/dymensionxyz/dymension/v3/testutil/keeper"
"github.com/dymensionxyz/dymension/v3/testutil/nullify"
"github.com/dymensionxyz/dymension/v3/x/rollapp"
"github.com/dymensionxyz/dymension/v3/x/rollapp/types"
"github.com/stretchr/testify/require"
)

func TestInitExportGenesis(t *testing.T) {
const (
rollappID1 = "rollapp_1234-1"
rollappID2 = "rollupp_1235-2"
)

genesisState := types.GenesisState{
Params: types.DefaultParams(),

RollappList: []types.Rollapp{
{
RollappId: "0",
RollappId: rollappID1,
},
{
RollappId: "1",
RollappId: rollappID2,
},
},
StateInfoList: []types.StateInfo{
{
StateInfoIndex: types.StateInfoIndex{
RollappId: "0",
RollappId: rollappID1,
Index: 0,
},
},
{
StateInfoIndex: types.StateInfoIndex{
RollappId: "1",
RollappId: rollappID2,
Index: 1,
},
},
},
LatestStateInfoIndexList: []types.StateInfoIndex{
{
RollappId: "0",
RollappId: rollappID1,
},
{
RollappId: "1",
RollappId: rollappID2,
},
},
BlockHeightToFinalizationQueueList: []types.BlockHeightToFinalizationQueue{
Expand All @@ -52,7 +58,6 @@ func TestInitExportGenesis(t *testing.T) {
CreationHeight: 1,
},
},
// this line is used by starport scaffolding # genesis/test/state
}

k, ctx := keepertest.RollappKeeper(t)
Expand All @@ -67,5 +72,4 @@ func TestInitExportGenesis(t *testing.T) {
require.ElementsMatch(t, genesisState.StateInfoList, got.StateInfoList)
require.ElementsMatch(t, genesisState.LatestStateInfoIndexList, got.LatestStateInfoIndexList)
require.ElementsMatch(t, genesisState.BlockHeightToFinalizationQueueList, got.BlockHeightToFinalizationQueueList)
// this line is used by starport scaffolding # genesis/test/assert
}
Loading

0 comments on commit 55a7517

Please sign in to comment.