1 // Copyright (c) 2014-2017 The btcsuite developers
2 // Use of this source code is governed by an ISC
3 // license that can be found in the LICENSE file.
11 // TestErrorCodeStringer tests the stringized output for the ErrorCode type.
12 func TestErrorCodeStringer(t *testing.T) {
17 {ErrDuplicateBlock, "ErrDuplicateBlock"},
18 {ErrBlockTooBig, "ErrBlockTooBig"},
19 {ErrBlockVersionTooOld, "ErrBlockVersionTooOld"},
20 {ErrInvalidTime, "ErrInvalidTime"},
21 {ErrTimeTooOld, "ErrTimeTooOld"},
22 {ErrTimeTooNew, "ErrTimeTooNew"},
23 {ErrDifficultyTooLow, "ErrDifficultyTooLow"},
24 {ErrUnexpectedDifficulty, "ErrUnexpectedDifficulty"},
25 {ErrHighHash, "ErrHighHash"},
26 {ErrBadMerkleRoot, "ErrBadMerkleRoot"},
27 {ErrBadCheckpoint, "ErrBadCheckpoint"},
28 {ErrForkTooOld, "ErrForkTooOld"},
29 {ErrCheckpointTimeTooOld, "ErrCheckpointTimeTooOld"},
30 {ErrNoTransactions, "ErrNoTransactions"},
31 {ErrTooManyTransactions, "ErrTooManyTransactions"},
32 {ErrNoTxInputs, "ErrNoTxInputs"},
33 {ErrNoTxOutputs, "ErrNoTxOutputs"},
34 {ErrTxTooBig, "ErrTxTooBig"},
35 {ErrBadTxOutValue, "ErrBadTxOutValue"},
36 {ErrDuplicateTxInputs, "ErrDuplicateTxInputs"},
37 {ErrBadTxInput, "ErrBadTxInput"},
38 {ErrBadCheckpoint, "ErrBadCheckpoint"},
39 {ErrMissingTxOut, "ErrMissingTxOut"},
40 {ErrUnfinalizedTx, "ErrUnfinalizedTx"},
41 {ErrDuplicateTx, "ErrDuplicateTx"},
42 {ErrOverwriteTx, "ErrOverwriteTx"},
43 {ErrImmatureSpend, "ErrImmatureSpend"},
44 {ErrSpendTooHigh, "ErrSpendTooHigh"},
45 {ErrBadFees, "ErrBadFees"},
46 {ErrTooManySigOps, "ErrTooManySigOps"},
47 {ErrFirstTxNotCoinbase, "ErrFirstTxNotCoinbase"},
48 {ErrMultipleCoinbases, "ErrMultipleCoinbases"},
49 {ErrBadCoinbaseScriptLen, "ErrBadCoinbaseScriptLen"},
50 {ErrBadCoinbaseValue, "ErrBadCoinbaseValue"},
51 {ErrMissingCoinbaseHeight, "ErrMissingCoinbaseHeight"},
52 {ErrBadCoinbaseHeight, "ErrBadCoinbaseHeight"},
53 {ErrScriptMalformed, "ErrScriptMalformed"},
54 {ErrScriptValidation, "ErrScriptValidation"},
55 {0xffff, "Unknown ErrorCode (65535)"},
58 t.Logf("Running %d tests", len(tests))
59 for i, test := range tests {
60 result := test.in.String()
61 if result != test.want {
62 t.Errorf("String #%d\n got: %s want: %s", i, result,
69 // TestRuleError tests the error output for the RuleError type.
70 func TestRuleError(t *testing.T) {
76 RuleError{Description: "duplicate block"},
80 RuleError{Description: "human-readable error"},
81 "human-readable error",
85 t.Logf("Running %d tests", len(tests))
86 for i, test := range tests {
87 result := test.in.Error()
88 if result != test.want {
89 t.Errorf("Error #%d\n got: %s want: %s", i, result,
96 // TestDeploymentError tests the stringized output for the DeploymentError type.
97 func TestDeploymentError(t *testing.T) {
106 "deployment ID 0 does not exist",
110 "deployment ID 10 does not exist",
113 DeploymentError(123),
114 "deployment ID 123 does not exist",
118 t.Logf("Running %d tests", len(tests))
119 for i, test := range tests {
120 result := test.in.Error()
121 if result != test.want {
122 t.Errorf("Error #%d\n got: %s want: %s", i, result,