-
Notifications
You must be signed in to change notification settings - Fork 341
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rollapp): option to transfer rollapp owner (#1039)
- Loading branch information
Showing
23 changed files
with
853 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package cli | ||
|
||
import ( | ||
"github.com/cosmos/cosmos-sdk/client" | ||
"github.com/cosmos/cosmos-sdk/client/flags" | ||
"github.com/cosmos/cosmos-sdk/client/tx" | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/dymensionxyz/dymension/v3/x/rollapp/types" | ||
) | ||
|
||
func CmdTransferOwnership() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "transfer-ownership [rollapp-id] [new-owner]", | ||
Short: "Transfer ownership of a rollapp to a new owner", | ||
Example: "dymd tx rollapp transfer-ownership ROLLAPP_CHAIN_ID <new_owner_address>", | ||
Args: cobra.ExactArgs(2), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
// nolint:gofumpt | ||
argRollappId, newOwner := args[0], args[1] | ||
|
||
clientCtx, err := client.GetClientTxContext(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
msg := types.NewMsgTransferOwnership( | ||
clientCtx.GetFromAddress().String(), | ||
newOwner, | ||
argRollappId, | ||
) | ||
|
||
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) | ||
}, | ||
} | ||
|
||
flags.AddTxFlagsToCmd(cmd) | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package keeper | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
errorsmod "cosmossdk.io/errors" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
"github.com/dymensionxyz/dymension/v3/x/rollapp/types" | ||
) | ||
|
||
func (k msgServer) TransferOwnership(goCtx context.Context, msg *types.MsgTransferOwnership) (*types.MsgTransferOwnershipResponse, error) { | ||
if err := msg.ValidateBasic(); err != nil { | ||
return nil, errorsmod.Wrap(types.ErrInvalidRequest, err.Error()) | ||
} | ||
|
||
ctx := sdk.UnwrapSDKContext(goCtx) | ||
|
||
rollapp, ok := k.GetRollapp(ctx, msg.RollappId) | ||
if !ok { | ||
return nil, types.ErrUnknownRollappID | ||
} | ||
|
||
if rollapp.Owner != msg.CurrentOwner { | ||
return nil, types.ErrUnauthorizedSigner | ||
} | ||
|
||
if rollapp.Frozen { | ||
return nil, types.ErrRollappFrozen | ||
} | ||
|
||
if rollapp.Owner == msg.NewOwner { | ||
return nil, types.ErrSameOwner | ||
} | ||
|
||
rollapp.Owner = msg.NewOwner | ||
k.SetRollapp(ctx, rollapp) | ||
|
||
if err := ctx.EventManager().EmitTypedEvent(msg); err != nil { | ||
return nil, fmt.Errorf("emit event: %w", err) | ||
} | ||
|
||
return &types.MsgTransferOwnershipResponse{}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package keeper_test | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
"github.com/dymensionxyz/dymension/v3/x/rollapp/types" | ||
) | ||
|
||
func (suite *RollappTestSuite) TestTransferOwnership() { | ||
const rollappId = "rollapp_1234-1" | ||
|
||
tests := []struct { | ||
name string | ||
request *types.MsgTransferOwnership | ||
malleate func(rollapp types.Rollapp) types.Rollapp | ||
expError error | ||
expRollapp types.Rollapp | ||
}{ | ||
{ | ||
name: "Transfer rollapp ownership: success", | ||
request: types.NewMsgTransferOwnership( | ||
alice, bob, rollappId, | ||
), | ||
expError: nil, | ||
expRollapp: types.Rollapp{ | ||
Owner: bob, | ||
RollappId: rollappId, | ||
}, | ||
}, { | ||
name: "Transfer rollapp ownership: failed, rollapp not found", | ||
request: types.NewMsgTransferOwnership( | ||
alice, bob, "rollapp_1235-2", | ||
), | ||
expError: types.ErrUnknownRollappID, | ||
}, { | ||
name: "Transfer rollapp ownership: failed, same owner", | ||
request: types.NewMsgTransferOwnership( | ||
alice, alice, rollappId, | ||
), | ||
expError: types.ErrSameOwner, | ||
}, { | ||
name: "Transfer rollapp ownership: failed, unauthorized signer", | ||
request: types.NewMsgTransferOwnership( | ||
bob, alice, rollappId, | ||
), | ||
expError: types.ErrUnauthorizedSigner, | ||
}, { | ||
name: "Transfer rollapp ownership: failed, frozen rollapp", | ||
request: types.NewMsgTransferOwnership( | ||
alice, bob, rollappId, | ||
), | ||
malleate: func(rollapp types.Rollapp) types.Rollapp { | ||
rollapp.Frozen = true | ||
return rollapp | ||
}, | ||
expError: types.ErrRollappFrozen, | ||
}, { | ||
name: "Transfer rollapp ownership: failed, invalid current owner address", | ||
request: types.NewMsgTransferOwnership( | ||
"invalid_address", bob, rollappId, | ||
), | ||
expError: types.ErrInvalidRequest, | ||
}, { | ||
name: "Transfer rollapp ownership: failed, invalid new owner address", | ||
request: types.NewMsgTransferOwnership( | ||
alice, "invalid_address", rollappId, | ||
), | ||
expError: types.ErrInvalidRequest, | ||
}, | ||
} | ||
|
||
for _, tc := range tests { | ||
suite.Run(tc.name, func() { | ||
suite.SetupTest() | ||
|
||
rollapp := types.Rollapp{ | ||
RollappId: rollappId, | ||
Owner: alice, | ||
Frozen: false, | ||
Sealed: false, | ||
} | ||
|
||
if tc.malleate != nil { | ||
rollapp = tc.malleate(rollapp) | ||
} | ||
|
||
suite.App.RollappKeeper.SetRollapp(suite.Ctx, rollapp) | ||
|
||
goCtx := sdk.WrapSDKContext(suite.Ctx) | ||
_, err := suite.msgServer.TransferOwnership(goCtx, tc.request) | ||
if tc.expError == nil { | ||
suite.Require().NoError(err) | ||
resp, err := suite.queryClient.Rollapp(goCtx, &types.QueryGetRollappRequest{RollappId: tc.request.RollappId}) | ||
suite.Require().NoError(err) | ||
suite.Equal(tc.expRollapp, resp.Rollapp) | ||
} else { | ||
suite.ErrorIs(err, tc.expError) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.