github.com/palcoin-project/palcd@v1.0.0/txscript/error_test.go (about) 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 {ErrSigTooShort, "ErrSigTooShort"}, 51 {ErrSigTooLong, "ErrSigTooLong"}, 52 {ErrSigInvalidSeqID, "ErrSigInvalidSeqID"}, 53 {ErrSigInvalidDataLen, "ErrSigInvalidDataLen"}, 54 {ErrSigMissingSTypeID, "ErrSigMissingSTypeID"}, 55 {ErrSigMissingSLen, "ErrSigMissingSLen"}, 56 {ErrSigInvalidSLen, "ErrSigInvalidSLen"}, 57 {ErrSigInvalidRIntID, "ErrSigInvalidRIntID"}, 58 {ErrSigZeroRLen, "ErrSigZeroRLen"}, 59 {ErrSigNegativeR, "ErrSigNegativeR"}, 60 {ErrSigTooMuchRPadding, "ErrSigTooMuchRPadding"}, 61 {ErrSigInvalidSIntID, "ErrSigInvalidSIntID"}, 62 {ErrSigZeroSLen, "ErrSigZeroSLen"}, 63 {ErrSigNegativeS, "ErrSigNegativeS"}, 64 {ErrSigTooMuchSPadding, "ErrSigTooMuchSPadding"}, 65 {ErrSigHighS, "ErrSigHighS"}, 66 {ErrNotPushOnly, "ErrNotPushOnly"}, 67 {ErrSigNullDummy, "ErrSigNullDummy"}, 68 {ErrPubKeyType, "ErrPubKeyType"}, 69 {ErrCleanStack, "ErrCleanStack"}, 70 {ErrNullFail, "ErrNullFail"}, 71 {ErrDiscourageUpgradableNOPs, "ErrDiscourageUpgradableNOPs"}, 72 {ErrNegativeLockTime, "ErrNegativeLockTime"}, 73 {ErrUnsatisfiedLockTime, "ErrUnsatisfiedLockTime"}, 74 {ErrWitnessProgramEmpty, "ErrWitnessProgramEmpty"}, 75 {ErrWitnessProgramMismatch, "ErrWitnessProgramMismatch"}, 76 {ErrWitnessProgramWrongLength, "ErrWitnessProgramWrongLength"}, 77 {ErrWitnessMalleated, "ErrWitnessMalleated"}, 78 {ErrWitnessMalleatedP2SH, "ErrWitnessMalleatedP2SH"}, 79 {ErrWitnessUnexpected, "ErrWitnessUnexpected"}, 80 {ErrMinimalIf, "ErrMinimalIf"}, 81 {ErrWitnessPubKeyType, "ErrWitnessPubKeyType"}, 82 {ErrDiscourageUpgradableWitnessProgram, "ErrDiscourageUpgradableWitnessProgram"}, 83 {0xffff, "Unknown ErrorCode (65535)"}, 84 } 85 86 // Detect additional error codes that don't have the stringer added. 87 if len(tests)-1 != int(numErrorCodes) { 88 t.Errorf("It appears an error code was added without adding an " + 89 "associated stringer test") 90 } 91 92 t.Logf("Running %d tests", len(tests)) 93 for i, test := range tests { 94 result := test.in.String() 95 if result != test.want { 96 t.Errorf("String #%d\n got: %s want: %s", i, result, 97 test.want) 98 continue 99 } 100 } 101 } 102 103 // TestError tests the error output for the Error type. 104 func TestError(t *testing.T) { 105 t.Parallel() 106 107 tests := []struct { 108 in Error 109 want string 110 }{ 111 { 112 Error{Description: "some error"}, 113 "some error", 114 }, 115 { 116 Error{Description: "human-readable error"}, 117 "human-readable error", 118 }, 119 } 120 121 t.Logf("Running %d tests", len(tests)) 122 for i, test := range tests { 123 result := test.in.Error() 124 if result != test.want { 125 t.Errorf("Error #%d\n got: %s want: %s", i, result, 126 test.want) 127 continue 128 } 129 } 130 }