Custom error types doesn't match at custom tests #70
Answered
by
julienrbrt
RaulBernal
asked this question in
Chain Builders (Cosmos SDK)
-
When I try to run this test: func TestSupplychainMsgServerDelete(t *testing.T) {
creator := "A"
tests := []struct {
desc string
request *types.MsgDeleteSupplychain
err error
}{
{
desc: "Completed",
request: &types.MsgDeleteSupplychain{Creator: creator},
},
{
desc: "Unauthorized",
request: &types.MsgDeleteSupplychain{Creator: "B"},
err: types.ErrUnauthorized,
},
{
desc: "KeyNotFound",
request: &types.MsgDeleteSupplychain{Creator: creator, Id: 10},
err: types.ErrKeyNotFound,
},
}
for _, tc := range tests {
t.Run(tc.desc, func(t *testing.T) {
_, srv, ctx := setupMsgServer(t)
wctx := sdk.UnwrapSDKContext(ctx)
_, err := srv.CreateSupplychain(wctx, &types.MsgCreateSupplychain{Creator: creator})
require.NoError(t, err)
_, err = srv.DeleteSupplychain(wctx, tc.request)
if tc.err != nil {
require.ErrorIs(t, err, tc.err)
} else {
require.NoError(t, err)
}
})
}
} I get this output: === RUN TestSupplychainMsgServerDelete/Unauthorized
/Users/raul/SDK/v0.50/bcna/x/bcna/keeper/msg_server_supplychain_test.go:97:
Error Trace: /Users/raul/SDK/v0.50/bcna/x/bcna/keeper/msg_server_supplychain_test.go:97
Error: Target error should be in err chain:
expected: "incorrect owner: unauthorized"
in chain: "incorrect owner: unauthorized"
"unauthorized"
"unauthorized"
Test: TestSupplychainMsgServerDelete/Unauthorized
--- FAIL: TestSupplychainMsgServerDelete/Unauthorized (0.00s) Having errors.go at my module this content: package types
// DONTCOVER
import (
sdkerrors "cosmossdk.io/errors"
)
// x/bcna module sentinel errors
var (
ErrInvalidSigner = sdkerrors.Register(ModuleName, 1100, "expected gov account as only signer for proposal message")
ErrDuplicateBitcannaid = sdkerrors.Register(ModuleName, 1101, "BitCannaID already exists")
ErrKeyNotFound = sdkerrors.Register(ModuleName, 1102, "Key doesn't exists: key not found")
ErrUnauthorized = sdkerrors.Register(ModuleName, 1103, "incorrect owner: unauthorized")
ErrUnrecognized = sdkerrors.Register(ModuleName, 1104, "Unrecognized messager")
ErrInvalidAddress = sdkerrors.Register(ModuleName, 1105, "invalid address")
ErrMaxCharacters = sdkerrors.Register(ModuleName, 1106, "input exceeds the permitted length limit")
) This happens when I try to use my custom "errors.go" types in place of |
Beta Was this translation helpful? Give feedback.
Answered by
julienrbrt
Feb 12, 2024
Replies: 1 comment 2 replies
-
Can you post how are the error wrapped / returned in |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
RaulBernal
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can you post how are the error wrapped / returned in
DeleteSupplychain
?