diff --git a/.github/README.md b/.github/README.md index f8db8b9..28840f6 100644 --- a/.github/README.md +++ b/.github/README.md @@ -6,4 +6,4 @@ This repository includes the `x/aura` Cosmos SDK module implementation. -For more information, refer to the modules [spec](../x/aura/spec) files. +For more information, refer to the module's [spec](../x/aura/spec) files. diff --git a/utils/mocks/aura.go b/utils/mocks/aura.go index 1c8b887..445bd1c 100644 --- a/utils/mocks/aura.go +++ b/utils/mocks/aura.go @@ -22,8 +22,12 @@ func AuraKeeperWithBank(_ testing.TB, bank BankKeeper) (*keeper.Keeper, sdk.Cont key := storetypes.NewKVStoreKey(types.ModuleName) tkey := storetypes.NewTransientStoreKey("transient_aura") + reg := codectypes.NewInterfaceRegistry() + types.RegisterInterfaces(reg) + cdc := codec.NewProtoCodec(reg) + k := keeper.NewKeeper( - codec.NewProtoCodec(codectypes.NewInterfaceRegistry()), + cdc, key, "ausdy", nil, diff --git a/x/aura/keeper/msg_server.go b/x/aura/keeper/msg_server.go index 55e856e..b2326a7 100644 --- a/x/aura/keeper/msg_server.go +++ b/x/aura/keeper/msg_server.go @@ -143,6 +143,10 @@ func (k msgServer) TransferOwnership(goCtx context.Context, msg *types.MsgTransf return nil, sdkerrors.Wrapf(types.ErrInvalidOwner, "expected %s, got %s", owner, msg.Signer) } + if msg.NewOwner == owner { + return nil, types.ErrSameOwner + } + k.SetPendingOwner(ctx, msg.NewOwner) return &types.MsgTransferOwnershipResponse{}, ctx.EventManager().EmitTypedEvent(&types.OwnershipTransferStarted{ diff --git a/x/aura/keeper/msg_server_blocklist.go b/x/aura/keeper/msg_server_blocklist.go index 9bca107..838c4d3 100644 --- a/x/aura/keeper/msg_server_blocklist.go +++ b/x/aura/keeper/msg_server_blocklist.go @@ -29,6 +29,10 @@ func (k blocklistMsgServer) TransferOwnership(goCtx context.Context, msg *blockl return nil, errors.Wrapf(blocklist.ErrInvalidOwner, "expected %s, got %s", owner, msg.Signer) } + if msg.NewOwner == owner { + return nil, blocklist.ErrSameOwner + } + k.SetBlocklistPendingOwner(ctx, msg.NewOwner) return &blocklist.MsgTransferOwnershipResponse{}, ctx.EventManager().EmitTypedEvent(&blocklist.OwnershipTransferStarted{ diff --git a/x/aura/keeper/msg_server_blocklist_test.go b/x/aura/keeper/msg_server_blocklist_test.go index c2fbcd0..f4be44a 100644 --- a/x/aura/keeper/msg_server_blocklist_test.go +++ b/x/aura/keeper/msg_server_blocklist_test.go @@ -32,6 +32,14 @@ func TestBlocklistTransferOwnership(t *testing.T) { // ASSERT: The action should've failed due to invalid signer. require.ErrorContains(t, err, blocklist.ErrInvalidOwner.Error()) + // ACT: Attempt to transfer ownership to same owner. + _, err = server.TransferOwnership(goCtx, &blocklist.MsgTransferOwnership{ + Signer: owner.Address, + NewOwner: owner.Address, + }) + // ASSERT: The action should've failed due to same owner. + require.ErrorContains(t, err, blocklist.ErrSameOwner.Error()) + // ARRANGE: Generate a pending owner account. pendingOwner := utils.TestAccount() diff --git a/x/aura/keeper/msg_server_test.go b/x/aura/keeper/msg_server_test.go index 6eadba2..91bc7cb 100644 --- a/x/aura/keeper/msg_server_test.go +++ b/x/aura/keeper/msg_server_test.go @@ -262,6 +262,14 @@ func TestTransferOwnership(t *testing.T) { // ASSERT: The action should've failed due to invalid signer. require.ErrorContains(t, err, types.ErrInvalidOwner.Error()) + // ACT: Attempt to transfer ownership to same owner. + _, err = server.TransferOwnership(goCtx, &types.MsgTransferOwnership{ + Signer: owner.Address, + NewOwner: owner.Address, + }) + // ASSERT: The action should've failed due to same owner. + require.ErrorContains(t, err, types.ErrSameOwner.Error()) + // ARRANGE: Generate a pending owner account. pendingOwner := utils.TestAccount() diff --git a/x/aura/keeper/query_server_blocklist_test.go b/x/aura/keeper/query_server_blocklist_test.go index a7da2c4..7dc0ce8 100644 --- a/x/aura/keeper/query_server_blocklist_test.go +++ b/x/aura/keeper/query_server_blocklist_test.go @@ -91,7 +91,7 @@ func TestBlocklistAddressQuery(t *testing.T) { _, err = server.Address(goCtx, &blocklist.QueryAddress{ Address: "cosmos10d07y265gmmuvt4z0w9aw880jnsr700j6zn9kn", }) - // ASSERT: The action should've failed due to invalid address. + // ASSERT: The query should've failed due to invalid address. require.ErrorContains(t, err, "unable to decode address") // ACT: Attempt to query blocked state of unblocked address. diff --git a/x/aura/spec/02_messages.md b/x/aura/spec/02_messages.md index f69e3c9..d839a16 100644 --- a/x/aura/spec/02_messages.md +++ b/x/aura/spec/02_messages.md @@ -247,6 +247,7 @@ A message that initiates an ownership transfer to a provided address. ### Requirements - Signer must be the current [`owner`](./01_state.md#owner). +- `new_owner` must not be the current [`owner`](./01_state.md#owner). ### State Changes diff --git a/x/aura/spec/02_messages_blocklist.md b/x/aura/spec/02_messages_blocklist.md index c5c8895..431ace9 100644 --- a/x/aura/spec/02_messages_blocklist.md +++ b/x/aura/spec/02_messages_blocklist.md @@ -41,6 +41,7 @@ A message that initiates an ownership transfer to a provided address. ### Requirements - Signer must be the current [`owner`](./01_state_blocklist.md#owner). +- `new_owner` must not be the current [`owner`](./01_state_blocklist.md#owner). ### State Changes diff --git a/x/aura/types/blocklist/errors.go b/x/aura/types/blocklist/errors.go index b297726..0812031 100644 --- a/x/aura/types/blocklist/errors.go +++ b/x/aura/types/blocklist/errors.go @@ -6,7 +6,8 @@ var ( Codespace = "aura/blocklist" ErrNoOwner = errors.Register(Codespace, 1, "there is no blocklist owner") - ErrInvalidOwner = errors.Register(Codespace, 2, "signer is not blocklist owner") - ErrNoPendingOwner = errors.Register(Codespace, 3, "there is no pending blocklist owner") - ErrInvalidPendingOwner = errors.Register(Codespace, 4, "signer is not blocklist pending owner") + ErrSameOwner = errors.Register(Codespace, 2, "provided owner is the current owner") + ErrInvalidOwner = errors.Register(Codespace, 3, "signer is not blocklist owner") + ErrNoPendingOwner = errors.Register(Codespace, 4, "there is no pending blocklist owner") + ErrInvalidPendingOwner = errors.Register(Codespace, 5, "signer is not blocklist pending owner") ) diff --git a/x/aura/types/errors.go b/x/aura/types/errors.go index ab46d01..745502e 100644 --- a/x/aura/types/errors.go +++ b/x/aura/types/errors.go @@ -4,11 +4,12 @@ import "cosmossdk.io/errors" var ( ErrNoOwner = errors.Register(ModuleName, 1, "there is no owner") - ErrInvalidOwner = errors.Register(ModuleName, 2, "signer is not owner") - ErrNoPendingOwner = errors.Register(ModuleName, 3, "there is no pending owner") - ErrInvalidPendingOwner = errors.Register(ModuleName, 4, "signer is not pending owner") - ErrInvalidBurner = errors.Register(ModuleName, 5, "signer is not a burner") - ErrInvalidMinter = errors.Register(ModuleName, 6, "signer is not a minter") - ErrInvalidPauser = errors.Register(ModuleName, 7, "signer is not a pauser") - ErrInsufficientAllowance = errors.Register(ModuleName, 8, "insufficient allowance") + ErrSameOwner = errors.Register(ModuleName, 2, "provided owner is the current owner") + ErrInvalidOwner = errors.Register(ModuleName, 3, "signer is not owner") + ErrNoPendingOwner = errors.Register(ModuleName, 4, "there is no pending owner") + ErrInvalidPendingOwner = errors.Register(ModuleName, 5, "signer is not pending owner") + ErrInvalidBurner = errors.Register(ModuleName, 6, "signer is not a burner") + ErrInvalidMinter = errors.Register(ModuleName, 7, "signer is not a minter") + ErrInvalidPauser = errors.Register(ModuleName, 8, "signer is not a pauser") + ErrInsufficientAllowance = errors.Register(ModuleName, 9, "insufficient allowance") )