[#174] subnet: Rename ErrSubNotExist -> ErrNotExist

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2021-11-23 18:36:45 +03:00 committed by LeL
parent 9e2842b4ad
commit c4ff617525
2 changed files with 25 additions and 25 deletions

View file

@ -19,8 +19,8 @@ const (
ErrInvalidAdmin = "invalid administrator"
// ErrAlreadyExists is thrown when id already exists.
ErrAlreadyExists = "subnet id already exists"
// ErrSubNotExist is thrown when id doesn't exist.
ErrSubNotExist = "subnet id doesn't exist"
// ErrNotExist is thrown when id doesn't exist.
ErrNotExist = "subnet id doesn't exist"
// ErrInvalidUser is thrown when user has invalid format.
ErrInvalidUser = "invalid user"
// ErrInvalidNode is thrown when node has invalid format.
@ -133,7 +133,7 @@ func Get(id []byte) []byte {
key := append([]byte{infoPrefix}, id...)
raw := storage.Get(ctx, key)
if raw == nil {
panic("get: " + ErrSubNotExist)
panic("get: " + ErrNotExist)
}
return raw.([]byte)
}
@ -144,7 +144,7 @@ func Delete(id []byte) {
key := append([]byte{ownerPrefix}, id...)
raw := storage.Get(ctx, key)
if raw == nil {
panic("delete:" + ErrSubNotExist)
panic("delete:" + ErrNotExist)
}
owner := raw.([]byte)
@ -172,7 +172,7 @@ func AddNodeAdmin(subnetID []byte, adminKey interop.PublicKey) {
rawOwner := storage.Get(ctx, stKey)
if rawOwner == nil {
panic("addNodeAdmin: " + ErrSubNotExist)
panic("addNodeAdmin: " + ErrNotExist)
}
owner := rawOwner.([]byte)
@ -202,7 +202,7 @@ func RemoveNodeAdmin(subnetID []byte, adminKey interop.PublicKey) {
rawOwner := storage.Get(ctx, stKey)
if rawOwner == nil {
panic("removeNodeAdmin: " + ErrSubNotExist)
panic("removeNodeAdmin: " + ErrNotExist)
}
owner := rawOwner.([]byte)
@ -233,7 +233,7 @@ func AddNode(subnetID []byte, node interop.PublicKey) {
rawOwner := storage.Get(ctx, stKey)
if rawOwner == nil {
panic("addNode: " + ErrSubNotExist)
panic("addNode: " + ErrNotExist)
}
stKey[0] = nodeAdminPrefix
@ -267,7 +267,7 @@ func RemoveNode(subnetID []byte, node interop.PublicKey) {
rawOwner := storage.Get(ctx, stKey)
if rawOwner == nil {
panic("removeNode: " + ErrSubNotExist)
panic("removeNode: " + ErrNotExist)
}
stKey[0] = nodeAdminPrefix
@ -302,7 +302,7 @@ func NodeAllowed(subnetID []byte, node interop.PublicKey) bool {
rawOwner := storage.Get(ctx, stKey)
if rawOwner == nil {
panic("nodeAllowed: " + ErrSubNotExist)
panic("nodeAllowed: " + ErrNotExist)
}
stKey[0] = nodePrefix
@ -323,7 +323,7 @@ func AddClientAdmin(subnetID []byte, groupID []byte, adminPublicKey interop.Publ
rawOwner := storage.Get(ctx, stKey)
if rawOwner == nil {
panic("addClientAdmin: " + ErrSubNotExist)
panic("addClientAdmin: " + ErrNotExist)
}
owner := rawOwner.([]byte)
@ -355,7 +355,7 @@ func RemoveClientAdmin(subnetID []byte, groupID []byte, adminPublicKey interop.P
rawOwner := storage.Get(ctx, stKey)
if rawOwner == nil {
panic("removeClientAdmin: " + ErrSubNotExist)
panic("removeClientAdmin: " + ErrNotExist)
}
owner := rawOwner.([]byte)
@ -386,7 +386,7 @@ func AddUser(subnetID []byte, groupID []byte, userID []byte) {
rawOwner := storage.Get(ctx, stKey)
if rawOwner == nil {
panic("addUser: " + ErrSubNotExist)
panic("addUser: " + ErrNotExist)
}
stKey[0] = clientAdminPrefix
@ -421,7 +421,7 @@ func RemoveUser(subnetID []byte, groupID []byte, userID []byte) {
rawOwner := storage.Get(ctx, stKey)
if rawOwner == nil {
panic("removeUser: " + ErrSubNotExist)
panic("removeUser: " + ErrNotExist)
}
stKey[0] = clientAdminPrefix
@ -451,7 +451,7 @@ func UserAllowed(subnetID []byte, user []byte) bool {
stKey := append([]byte{ownerPrefix}, subnetID...)
if storage.Get(ctx, stKey) == nil {
panic("userAllowed: " + ErrSubNotExist)
panic("userAllowed: " + ErrNotExist)
}
stKey[0] = userPrefix

View file

@ -70,10 +70,10 @@ func TestSubnet_Delete(t *testing.T) {
e.InvokeFail(t, "witness check failed", "delete", id)
cAcc := e.WithSigners(owner)
cAcc.InvokeFail(t, subnet.ErrSubNotExist, "delete", []byte{1, 1, 1, 1})
cAcc.InvokeFail(t, subnet.ErrNotExist, "delete", []byte{1, 1, 1, 1})
cAcc.Invoke(t, stackitem.Null{}, "delete", id)
cAcc.InvokeFail(t, subnet.ErrSubNotExist, "get", id)
cAcc.InvokeFail(t, subnet.ErrSubNotExist, "delete", id)
cAcc.InvokeFail(t, subnet.ErrNotExist, "get", id)
cAcc.InvokeFail(t, subnet.ErrNotExist, "delete", id)
}
func TestSubnet_AddNodeAdmin(t *testing.T) {
@ -88,7 +88,7 @@ func TestSubnet_AddNodeAdmin(t *testing.T) {
const method = "addNodeAdmin"
e.InvokeFail(t, method+errSeparator+subnet.ErrInvalidAdmin, method, id, admPub[1:])
e.InvokeFail(t, method+errSeparator+subnet.ErrSubNotExist, method, []byte{0, 0, 0, 0}, admPub)
e.InvokeFail(t, method+errSeparator+subnet.ErrNotExist, method, []byte{0, 0, 0, 0}, admPub)
cAdm := e.WithSigners(adm)
cAdm.InvokeFail(t, method+errSeparator+"owner witness check failed", method, id, admPub)
@ -111,7 +111,7 @@ func TestSubnet_RemoveNodeAdmin(t *testing.T) {
const method = "removeNodeAdmin"
e.InvokeFail(t, method+errSeparator+subnet.ErrInvalidAdmin, method, id, admPub[1:])
e.InvokeFail(t, method+errSeparator+subnet.ErrSubNotExist, method, []byte{0, 0, 0, 0}, admPub)
e.InvokeFail(t, method+errSeparator+subnet.ErrNotExist, method, []byte{0, 0, 0, 0}, admPub)
cAdm := e.WithSigners(adm)
cAdm.InvokeFail(t, method+errSeparator+"owner witness check failed", method, id, admPub)
@ -137,7 +137,7 @@ func TestSubnet_AddNode(t *testing.T) {
cOwn := e.WithSigners(owner)
cOwn.InvokeFail(t, method+errSeparator+subnet.ErrInvalidNode, method, id, nodePub[1:])
cOwn.InvokeFail(t, method+errSeparator+subnet.ErrSubNotExist, method, []byte{0, 0, 0, 0}, nodePub)
cOwn.InvokeFail(t, method+errSeparator+subnet.ErrNotExist, method, []byte{0, 0, 0, 0}, nodePub)
cOwn.Invoke(t, stackitem.Null{}, method, id, nodePub)
cOwn.InvokeFail(t, method+errSeparator+"node has already been added", method, id, nodePub)
@ -160,7 +160,7 @@ func TestSubnet_RemoveNode(t *testing.T) {
cOwn := e.WithSigners(owner)
cOwn.InvokeFail(t, method+errSeparator+subnet.ErrInvalidNode, method, id, nodePub[1:])
cOwn.InvokeFail(t, method+errSeparator+subnet.ErrSubNotExist, method, []byte{0, 0, 0, 0}, nodePub)
cOwn.InvokeFail(t, method+errSeparator+subnet.ErrNotExist, method, []byte{0, 0, 0, 0}, nodePub)
cOwn.InvokeFail(t, method+errSeparator+subnet.ErrNodeNotExist, method, id, nodePub)
cOwn.Invoke(t, stackitem.Null{}, "addNode", id, nodePub)
@ -185,7 +185,7 @@ func TestSubnet_NodeAllowed(t *testing.T) {
cOwn := e.WithSigners(owner)
cOwn.InvokeFail(t, method+errSeparator+subnet.ErrInvalidNode, method, id, nodePub[1:])
cOwn.InvokeFail(t, method+errSeparator+subnet.ErrSubNotExist, method, []byte{0, 0, 0, 0}, nodePub)
cOwn.InvokeFail(t, method+errSeparator+subnet.ErrNotExist, method, []byte{0, 0, 0, 0}, nodePub)
cOwn.Invoke(t, stackitem.NewBool(false), method, id, nodePub)
cOwn.Invoke(t, stackitem.Null{}, "addNode", id, nodePub)
@ -207,7 +207,7 @@ func TestSubnet_AddClientAdmin(t *testing.T) {
cOwn := e.WithSigners(owner)
cOwn.InvokeFail(t, method+errSeparator+subnet.ErrInvalidAdmin, method, id, groupId, admPub[1:])
cOwn.InvokeFail(t, method+errSeparator+subnet.ErrSubNotExist, method, []byte{0, 0, 0, 0}, groupId, admPub)
cOwn.InvokeFail(t, method+errSeparator+subnet.ErrNotExist, method, []byte{0, 0, 0, 0}, groupId, admPub)
cOwn.Invoke(t, stackitem.Null{}, method, id, groupId, admPub)
cOwn.InvokeFail(t, method+errSeparator+"client admin has already been added", method, id, groupId, admPub)
}
@ -227,7 +227,7 @@ func TestSubnet_RemoveClientAdmin(t *testing.T) {
cOwn := e.WithSigners(owner)
cOwn.InvokeFail(t, method+errSeparator+subnet.ErrInvalidAdmin, method, id, groupId, admPub[1:])
cOwn.InvokeFail(t, method+errSeparator+subnet.ErrSubNotExist, method, []byte{0, 0, 0, 0}, groupId, admPub)
cOwn.InvokeFail(t, method+errSeparator+subnet.ErrNotExist, method, []byte{0, 0, 0, 0}, groupId, admPub)
cOwn.InvokeFail(t, method+errSeparator+subnet.ErrClientAdmNotExist, method, id, groupId, admPub)
cOwn.Invoke(t, stackitem.Null{}, "addClientAdmin", id, groupId, admPub)
cOwn.Invoke(t, stackitem.Null{}, method, id, groupId, admPub)
@ -297,7 +297,7 @@ func TestSubnet_UserAllowed(t *testing.T) {
const method = "userAllowed"
cOwn := e.WithSigners(owner)
cOwn.InvokeFail(t, method+errSeparator+subnet.ErrSubNotExist, method, []byte{0, 0, 0, 0}, user)
cOwn.InvokeFail(t, method+errSeparator+subnet.ErrNotExist, method, []byte{0, 0, 0, 0}, user)
cOwn.Invoke(t, stackitem.NewBool(false), method, id, user)
cOwn.Invoke(t, stackitem.Null{}, "addUser", id, groupId, user)