OSDN Git Service

Merge pull request #41 from Bytom/dev
[bytom/vapor.git] / vendor / github.com / btcsuite / btcd / txscript / error_test.go
1 // Copyright (c) 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 txscript
6
7 import (
8         "testing"
9 )
10
11 // TestErrorCodeStringer tests the stringized output for the ErrorCode type.
12 func TestErrorCodeStringer(t *testing.T) {
13         t.Parallel()
14
15         tests := []struct {
16                 in   ErrorCode
17                 want string
18         }{
19                 {ErrInternal, "ErrInternal"},
20                 {ErrInvalidFlags, "ErrInvalidFlags"},
21                 {ErrInvalidIndex, "ErrInvalidIndex"},
22                 {ErrUnsupportedAddress, "ErrUnsupportedAddress"},
23                 {ErrTooManyRequiredSigs, "ErrTooManyRequiredSigs"},
24                 {ErrTooMuchNullData, "ErrTooMuchNullData"},
25                 {ErrNotMultisigScript, "ErrNotMultisigScript"},
26                 {ErrEarlyReturn, "ErrEarlyReturn"},
27                 {ErrEmptyStack, "ErrEmptyStack"},
28                 {ErrEvalFalse, "ErrEvalFalse"},
29                 {ErrScriptUnfinished, "ErrScriptUnfinished"},
30                 {ErrInvalidProgramCounter, "ErrInvalidProgramCounter"},
31                 {ErrScriptTooBig, "ErrScriptTooBig"},
32                 {ErrElementTooBig, "ErrElementTooBig"},
33                 {ErrTooManyOperations, "ErrTooManyOperations"},
34                 {ErrStackOverflow, "ErrStackOverflow"},
35                 {ErrInvalidPubKeyCount, "ErrInvalidPubKeyCount"},
36                 {ErrInvalidSignatureCount, "ErrInvalidSignatureCount"},
37                 {ErrNumberTooBig, "ErrNumberTooBig"},
38                 {ErrVerify, "ErrVerify"},
39                 {ErrEqualVerify, "ErrEqualVerify"},
40                 {ErrNumEqualVerify, "ErrNumEqualVerify"},
41                 {ErrCheckSigVerify, "ErrCheckSigVerify"},
42                 {ErrCheckMultiSigVerify, "ErrCheckMultiSigVerify"},
43                 {ErrDisabledOpcode, "ErrDisabledOpcode"},
44                 {ErrReservedOpcode, "ErrReservedOpcode"},
45                 {ErrMalformedPush, "ErrMalformedPush"},
46                 {ErrInvalidStackOperation, "ErrInvalidStackOperation"},
47                 {ErrUnbalancedConditional, "ErrUnbalancedConditional"},
48                 {ErrMinimalData, "ErrMinimalData"},
49                 {ErrInvalidSigHashType, "ErrInvalidSigHashType"},
50                 {ErrSigDER, "ErrSigDER"},
51                 {ErrSigHighS, "ErrSigHighS"},
52                 {ErrNotPushOnly, "ErrNotPushOnly"},
53                 {ErrSigNullDummy, "ErrSigNullDummy"},
54                 {ErrPubKeyType, "ErrPubKeyType"},
55                 {ErrCleanStack, "ErrCleanStack"},
56                 {ErrNullFail, "ErrNullFail"},
57                 {ErrDiscourageUpgradableNOPs, "ErrDiscourageUpgradableNOPs"},
58                 {ErrNegativeLockTime, "ErrNegativeLockTime"},
59                 {ErrUnsatisfiedLockTime, "ErrUnsatisfiedLockTime"},
60                 {ErrWitnessProgramEmpty, "ErrWitnessProgramEmpty"},
61                 {ErrWitnessProgramMismatch, "ErrWitnessProgramMismatch"},
62                 {ErrWitnessProgramWrongLength, "ErrWitnessProgramWrongLength"},
63                 {ErrWitnessMalleated, "ErrWitnessMalleated"},
64                 {ErrWitnessMalleatedP2SH, "ErrWitnessMalleatedP2SH"},
65                 {ErrWitnessUnexpected, "ErrWitnessUnexpected"},
66                 {ErrMinimalIf, "ErrMinimalIf"},
67                 {ErrWitnessPubKeyType, "ErrWitnessPubKeyType"},
68                 {ErrDiscourageUpgradableWitnessProgram, "ErrDiscourageUpgradableWitnessProgram"},
69                 {0xffff, "Unknown ErrorCode (65535)"},
70         }
71
72         // Detect additional error codes that don't have the stringer added.
73         if len(tests)-1 != int(numErrorCodes) {
74                 t.Errorf("It appears an error code was added without adding an " +
75                         "associated stringer test")
76         }
77
78         t.Logf("Running %d tests", len(tests))
79         for i, test := range tests {
80                 result := test.in.String()
81                 if result != test.want {
82                         t.Errorf("String #%d\n got: %s want: %s", i, result,
83                                 test.want)
84                         continue
85                 }
86         }
87 }
88
89 // TestError tests the error output for the Error type.
90 func TestError(t *testing.T) {
91         t.Parallel()
92
93         tests := []struct {
94                 in   Error
95                 want string
96         }{
97                 {
98                         Error{Description: "some error"},
99                         "some error",
100                 },
101                 {
102                         Error{Description: "human-readable error"},
103                         "human-readable error",
104                 },
105         }
106
107         t.Logf("Running %d tests", len(tests))
108         for i, test := range tests {
109                 result := test.in.Error()
110                 if result != test.want {
111                         t.Errorf("Error #%d\n got: %s want: %s", i, result,
112                                 test.want)
113                         continue
114                 }
115         }
116 }