OSDN Git Service

new repo
[bytom/vapor.git] / vendor / github.com / btcsuite / btcd / blockchain / error_test.go
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.
4
5 package blockchain
6
7 import (
8         "testing"
9 )
10
11 // TestErrorCodeStringer tests the stringized output for the ErrorCode type.
12 func TestErrorCodeStringer(t *testing.T) {
13         tests := []struct {
14                 in   ErrorCode
15                 want string
16         }{
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)"},
56         }
57
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,
63                                 test.want)
64                         continue
65                 }
66         }
67 }
68
69 // TestRuleError tests the error output for the RuleError type.
70 func TestRuleError(t *testing.T) {
71         tests := []struct {
72                 in   RuleError
73                 want string
74         }{
75                 {
76                         RuleError{Description: "duplicate block"},
77                         "duplicate block",
78                 },
79                 {
80                         RuleError{Description: "human-readable error"},
81                         "human-readable error",
82                 },
83         }
84
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,
90                                 test.want)
91                         continue
92                 }
93         }
94 }
95
96 // TestDeploymentError tests the stringized output for the DeploymentError type.
97 func TestDeploymentError(t *testing.T) {
98         t.Parallel()
99
100         tests := []struct {
101                 in   DeploymentError
102                 want string
103         }{
104                 {
105                         DeploymentError(0),
106                         "deployment ID 0 does not exist",
107                 },
108                 {
109                         DeploymentError(10),
110                         "deployment ID 10 does not exist",
111                 },
112                 {
113                         DeploymentError(123),
114                         "deployment ID 123 does not exist",
115                 },
116         }
117
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,
123                                 test.want)
124                         continue
125                 }
126         }
127
128 }