Skip to content

Commit

Permalink
Fix and update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zale144 committed Jul 24, 2024
1 parent 17a5014 commit 6cbcd75
Show file tree
Hide file tree
Showing 16 changed files with 176 additions and 137 deletions.
2 changes: 1 addition & 1 deletion app/apptesting/test_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (s *KeeperTestHelper) CreateDefaultRollapp() string {
}

func (s *KeeperTestHelper) CreateRollappWithName(name string) string {
alias := name // reuse rollappID to avoid alias conflicts
alias := strings.NewReplacer("_", "", "-", "").Replace(name) // base it on rollappID to avoid alias conflicts
msgCreateRollapp := rollapptypes.MsgCreateRollapp{
Creator: alice,
RollappId: name,
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 @@ -45,7 +45,7 @@ const (
expectDelayedackEpochIdentifier = "hour"

expectDisputePeriodInBlocks = 3
expectRegistrationFee = "1000000000000000000adym"
expectRegistrationFee = "10000000000000000000adym"
)

var expectDelayedackBridgingFee = sdk.NewDecWithPrec(1, 3)
Expand Down
6 changes: 4 additions & 2 deletions testutil/keeper/sequencer.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ import (
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
typesparams "github.com/cosmos/cosmos-sdk/x/params/types"
"github.com/stretchr/testify/require"

rollappkeeper "github.com/dymensionxyz/dymension/v3/x/rollapp/keeper"
"github.com/dymensionxyz/dymension/v3/x/sequencer/keeper"
"github.com/dymensionxyz/dymension/v3/x/sequencer/types"
"github.com/stretchr/testify/require"
)

func SequencerKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) {
Expand Down Expand Up @@ -42,7 +44,7 @@ func SequencerKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) {
memStoreKey,
paramsSubspace,
nil,
nil,
&rollappkeeper.Keeper{},
)

ctx := sdk.NewContext(stateStore, cometbftproto.Header{}, false, log.NewNopLogger())
Expand Down
2 changes: 1 addition & 1 deletion x/delayedack/types/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,5 @@ var validRollappPacket = ctypes.RollappPacket{
Relayer: []byte("cosmos1"),
Type: ctypes.RollappPacket_ON_RECV,
Error: "error",
OriginalTransferTarget: "cosmos18wvvwfmq77a6d8tza4h5sfuy2yj3jj88yqg82a",
OriginalTransferTarget: "dym1hpnekcl344ckklw07j7qcfs2x3j03zn6rppt2r",
}
10 changes: 6 additions & 4 deletions x/incentives/client/cli/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cli_test

import (
"context"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -29,12 +30,13 @@ type QueryTestSuite struct {

// SetupLockAndGauge creates both a lock and a gauge.
func (suite *QueryTestSuite) CreateDefaultRollapp() string {
alice := sdk.AccAddress([]byte("addr1---------------"))
alice := sdk.AccAddress("addr1---------------")
suite.FundAcc(alice, sdk.NewCoins(rollapptypes.DefaultRegistrationFee))

msgCreateRollapp := rollapptypes.MsgCreateRollapp{
Creator: alice.String(),
RollappId: tmrand.Str(8),
MaxSequencers: 1,
Creator: alice.String(),
RollappId: tmrand.Str(8),
Bech32Prefix: strings.ToLower(tmrand.Str(3)),
}

msgServer := rollapp.NewMsgServerImpl(*suite.App.RollappKeeper)
Expand Down
13 changes: 8 additions & 5 deletions x/incentives/keeper/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ package keeper_test
import (
"crypto/rand"
"fmt"
"strings"
"time"

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

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"
lockuptypes "github.com/osmosis-labs/osmosis/v15/x/lockup/types"

sdk "github.com/cosmos/cosmos-sdk/types"
)
Expand Down Expand Up @@ -205,12 +207,13 @@ func (suite *KeeperTestSuite) SetupLockAndGauge(isPerpetual bool) (sdk.AccAddres

// SetupLockAndGauge creates both a lock and a gauge.
func (suite *KeeperTestSuite) CreateDefaultRollapp() string {
alice := sdk.AccAddress([]byte("addr1---------------"))
alice := sdk.AccAddress("addr1---------------")
suite.FundAcc(alice, sdk.NewCoins(rollapptypes.DefaultRegistrationFee))

msgCreateRollapp := rollapptypes.MsgCreateRollapp{
Creator: alice.String(),
RollappId: tmrand.Str(8),
MaxSequencers: 1,
Creator: alice.String(),
RollappId: tmrand.Str(8),
Bech32Prefix: strings.ToLower(tmrand.Str(3)),
}

msgServer := rollapp.NewMsgServerImpl(*suite.App.RollappKeeper)
Expand Down
40 changes: 6 additions & 34 deletions x/rollapp/keeper/msg_server_create_rollapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package keeper_test

import (
"fmt"
"strings"

"github.com/cometbft/cometbft/libs/rand"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -42,35 +43,6 @@ func (suite *RollappTestSuite) TestCreateRollappAlreadyExists() {
suite.ErrorIs(err, types.ErrRollappExists)
}

func (suite *RollappTestSuite) TestCreateRollappSequencerExists() {
suite.SetupTest()

goCtx := sdk.WrapSDKContext(suite.Ctx)
seqAddr := sample.AccAddress()

rollapp := types.MsgCreateRollapp{
Creator: alice,
RollappId: "rollapp1",
InitialSequencerAddress: seqAddr,
Bech32Prefix: "rol",
GenesisChecksum: "checksum",
Alias: "Rollapp1",
}
_, err := suite.msgServer.CreateRollapp(goCtx, &rollapp)
suite.Require().Nil(err)

rollapp = types.MsgCreateRollapp{
Creator: alice,
RollappId: "rollapp2",
InitialSequencerAddress: seqAddr,
Bech32Prefix: "rol",
GenesisChecksum: "checksum",
Alias: "Rollapp2",
}
_, err = suite.msgServer.CreateRollapp(goCtx, &rollapp)
suite.ErrorIs(err, types.ErrInitialSequencerAddressTaken)
}

func (suite *RollappTestSuite) TestCreateRollappAliasAlreadyExists() {
suite.SetupTest()

Expand Down Expand Up @@ -149,7 +121,7 @@ func (suite *RollappTestSuite) TestCreateRollappId() {
}
for _, test := range tests {
suite.Run(test.name, func() {
alias := test.rollappId // reuse rollapp ID to avoid alias conflicts
alias := strings.NewReplacer("_", "", "-", "").Replace(test.rollappId) // reuse rollapp ID to avoid alias conflicts
rollapp := types.MsgCreateRollapp{
Creator: alice,
RollappId: test.rollappId,
Expand Down Expand Up @@ -214,7 +186,7 @@ func (suite *RollappTestSuite) TestCreateRollappIdRevisionNumber() {
}
for _, test := range tests {
suite.Run(test.name, func() {
alias := test.rollappId // reuse rollapp ID to avoid alias conflicts
alias := strings.NewReplacer("_", "", "-", "").Replace(test.rollappId) // reuse rollapp ID to avoid alias conflicts
rollapp := types.MsgCreateRollapp{
Creator: alice,
RollappId: test.rollappId,
Expand Down Expand Up @@ -334,7 +306,7 @@ func (suite *RollappTestSuite) TestOverwriteEIP155Key() {
suite.Run(test.name, func() {
suite.SetupTest()
goCtx := sdk.WrapSDKContext(suite.Ctx)
alias := test.rollappId // reuse rollapp ID to avoid alias conflicts
alias := strings.NewReplacer("_", "", "-", "").Replace(test.rollappId) // reuse rollapp ID to avoid alias conflicts
rollapp := types.MsgCreateRollapp{
Creator: alice,
RollappId: test.rollappId,
Expand Down Expand Up @@ -407,8 +379,8 @@ func (suite *RollappTestSuite) createRollappWithCreatorAndVerify(expectedErr err
// generate sequencer address
address := sample.AccAddress()
// rollapp is the rollapp to create
rollappID := fmt.Sprintf("%s%d", "rollapp", rand.Int63()) //nolint:gosec // this is for a test
alias := rollappID // has to be unique, so same as rollapp ID
rollappID := fmt.Sprintf("%s%d", "rollapp", rand.Int63()) //nolint:gosec // this is for a test
alias := strings.NewReplacer("_", "", "-", "").Replace(rollappID) // reuse rollapp ID to avoid alias conflicts

rollapp := types.MsgCreateRollapp{
Creator: creator,
Expand Down
6 changes: 5 additions & 1 deletion x/rollapp/keeper/msg_server_update_rollapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@ import (
)

func (k msgServer) UpdateRollappInformation(goCtx context.Context, msg *types.MsgUpdateRollappInformation) (*types.MsgUpdateRollappInformationResponse, error) {
if msg == nil || msg.GetUpdate() == nil {
return nil, types.ErrInvalidRequest
}

ctx := sdk.UnwrapSDKContext(goCtx)

if err := k.UpdateRollapp(ctx, msg.GetUpdate()); err != nil {
if err := k.UpdateRollapp(ctx, *msg.Update); err != nil {
return nil, err
}

Expand Down
Loading

0 comments on commit 6cbcd75

Please sign in to comment.