errors_test.gno
2.12 Kb · 64 lines
1package bolo
2
3import (
4 "strings"
5 "testing"
6)
7
8// Each error and its copy key, as API §7 pairs them; every key resolves to a
9// message in UI spec §8.
10var errorKeys = map[Error]string{
11 ErrNotFound: "err.not_found",
12 ErrNotUserCall: "err.use_wallet",
13 ErrSessionKey: "err.master_key",
14 ErrWrongDenom: "err.amount",
15 ErrBadAmount: "err.amount",
16 ErrDepositMismatch: "err.amount",
17 ErrPaused: "err.paused",
18 ErrNotOrganizer: "err.not_allowed",
19 ErrNotBeneficiary: "err.not_allowed",
20 ErrNotAdmin: "err.not_allowed",
21 ErrCampaignClosed: "err.state",
22 ErrCampaignSettled: "err.state",
23 ErrBondSlashed: "err.state",
24 ErrNoBond: "err.state",
25 ErrHoldEnded: "err.state",
26 ErrWrongMode: "err.mode",
27 ErrNothingToRefund: "err.refund",
28 ErrRefundWindowClosed: "err.refund",
29 ErrExitOpen: "err.exit_open",
30 ErrNotClosable: "err.not_yet",
31 ErrNotFinalizable: "err.not_yet",
32 ErrNothingToWithdraw: "err.withdraw",
33 ErrTitle: "err.text",
34 ErrDescription: "err.text",
35 ErrMessage: "err.text",
36 ErrUpdate: "err.text",
37 ErrNotice: "err.text",
38 ErrImage: "err.text",
39 ErrMarkup: "err.markup",
40 ErrBeneficiary: "err.input",
41 ErrCategory: "err.input",
42 ErrMode: "err.input",
43 ErrDeadline: "err.input",
44 ErrGoal: "err.input",
45 ErrSetting: "err.input",
46 ErrSunset: "err.sunset",
47 ErrCapReached: "err.cap",
48 ErrBooksMismatch: "err.internal",
49}
50
51// TestErrorsLeadWithCopyKeys: every error of API §7 starts with its own copy key,
52// then ": " and a message (API C10). The static check refuses an Error without a
53// key; this pins which key each one has.
54func TestErrorsLeadWithCopyKeys(t *testing.T) {
55 if len(errorKeys) != 38 {
56 t.Errorf("%d errors, API §7 has 38", len(errorKeys))
57 }
58 for e, want := range errorKeys {
59 key, msg, ok := strings.Cut(string(e), ": ")
60 if !ok || key != want || msg == "" {
61 t.Errorf("%q doesn't start with %s", string(e), want)
62 }
63 }
64}