From 79641ca910fb986041e9216ffe821a5842f7c868 Mon Sep 17 00:00:00 2001 From: Daniel Wedul Date: Thu, 12 Oct 2023 12:24:52 -0600 Subject: [PATCH] [1658]: Allow an admin to revoke their permission to manage permissions. --- x/exchange/msg.go | 7 ------- x/exchange/msg_test.go | 6 ++++-- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/x/exchange/msg.go b/x/exchange/msg.go index 1d0bd7893c..5efbd00166 100644 --- a/x/exchange/msg.go +++ b/x/exchange/msg.go @@ -307,9 +307,6 @@ func (m MsgMarketManagePermissionsRequest) ValidateBasic() error { errs = append(errs, fmt.Errorf("invalid revoke-all address %q: %w", addrStr, err)) } } - if ContainsString(m.RevokeAll, m.Admin) { - errs = append(errs, fmt.Errorf("message administrator %s cannot revoke all of their permissions", m.Admin)) - } if err := ValidateAccessGrantsField("to-revoke", m.ToRevoke); err != nil { errs = append(errs, err) @@ -320,10 +317,6 @@ func (m MsgMarketManagePermissionsRequest) ValidateBasic() error { if ContainsString(m.RevokeAll, ag.Address) { errs = append(errs, fmt.Errorf("address %s appears in both the revoke-all and to-revoke fields", ag.Address)) } - if ag.Address == m.Admin && ag.Contains(Permission_permissions) { - errs = append(errs, fmt.Errorf("message administrator %s cannot revoke their own ability to manage permissions", - ag.Address)) - } toRevokeByAddr[ag.Address] = ag } diff --git a/x/exchange/msg_test.go b/x/exchange/msg_test.go index 311d8e98fa..bfa473d6ff 100644 --- a/x/exchange/msg_test.go +++ b/x/exchange/msg_test.go @@ -1318,13 +1318,14 @@ func TestMsgMarketManagePermissionsRequest_ValidateBasic(t *testing.T) { }, }, { + // We allow this because it can be fixed via gov prop if no one is left that can manage permissions. name: "admin in revoke-all", msg: MsgMarketManagePermissionsRequest{ Admin: goodAdminAddr, MarketId: 1, RevokeAll: []string{goodAddr1, goodAdminAddr, goodAddr2}, }, - expErr: []string{"message administrator " + goodAdminAddr + " cannot revoke all of their permissions"}, + expErr: nil, }, { name: "admin revoking all their permissions except permissions", @@ -1342,6 +1343,7 @@ func TestMsgMarketManagePermissionsRequest_ValidateBasic(t *testing.T) { expErr: nil, }, { + // We allow this because it can be fixed via gov prop if no one is left that can manage permissions. name: "admin revoking own ability to manage permissions", msg: MsgMarketManagePermissionsRequest{ Admin: goodAdminAddr, @@ -1352,7 +1354,7 @@ func TestMsgMarketManagePermissionsRequest_ValidateBasic(t *testing.T) { {Address: goodAddr2, Permissions: []Permission{Permission_permissions}}, }, }, - expErr: []string{"message administrator " + goodAdminAddr + " cannot revoke their own ability to manage permissions"}, + expErr: nil, }, { name: "multiple errs",