github.com/lbryio/lbcd@v0.22.119/txscript/error_test.go (about) 1 // Copyright (c) 2017 The btcsuite developers 2 // Copyright (c) 2015-2019 The Decred developers 3 // Use of this source code is governed by an ISC 4 // license that can be found in the LICENSE file. 5 6 package txscript 7 8 import ( 9 "testing" 10 ) 11 12 // TestErrorCodeStringer tests the stringized output for the ErrorCode type. 13 func TestErrorCodeStringer(t *testing.T) { 14 t.Parallel() 15 16 tests := []struct { 17 in ErrorCode 18 want string 19 }{ 20 {ErrInternal, "ErrInternal"}, 21 {ErrInvalidFlags, "ErrInvalidFlags"}, 22 {ErrInvalidIndex, "ErrInvalidIndex"}, 23 {ErrUnsupportedAddress, "ErrUnsupportedAddress"}, 24 {ErrTooManyRequiredSigs, "ErrTooManyRequiredSigs"}, 25 {ErrTooMuchNullData, "ErrTooMuchNullData"}, 26 {ErrUnsupportedScriptVersion, "ErrUnsupportedScriptVersion"}, 27 {ErrNotMultisigScript, "ErrNotMultisigScript"}, 28 {ErrEarlyReturn, "ErrEarlyReturn"}, 29 {ErrEmptyStack, "ErrEmptyStack"}, 30 {ErrEvalFalse, "ErrEvalFalse"}, 31 {ErrScriptUnfinished, "ErrScriptUnfinished"}, 32 {ErrInvalidProgramCounter, "ErrInvalidProgramCounter"}, 33 {ErrScriptTooBig, "ErrScriptTooBig"}, 34 {ErrElementTooBig, "ErrElementTooBig"}, 35 {ErrTooManyOperations, "ErrTooManyOperations"}, 36 {ErrStackOverflow, "ErrStackOverflow"}, 37 {ErrInvalidPubKeyCount, "ErrInvalidPubKeyCount"}, 38 {ErrInvalidSignatureCount, "ErrInvalidSignatureCount"}, 39 {ErrNumberTooBig, "ErrNumberTooBig"}, 40 {ErrVerify, "ErrVerify"}, 41 {ErrEqualVerify, "ErrEqualVerify"}, 42 {ErrNumEqualVerify, "ErrNumEqualVerify"}, 43 {ErrCheckSigVerify, "ErrCheckSigVerify"}, 44 {ErrCheckMultiSigVerify, "ErrCheckMultiSigVerify"}, 45 {ErrDisabledOpcode, "ErrDisabledOpcode"}, 46 {ErrReservedOpcode, "ErrReservedOpcode"}, 47 {ErrMalformedPush, "ErrMalformedPush"}, 48 {ErrInvalidStackOperation, "ErrInvalidStackOperation"}, 49 {ErrUnbalancedConditional, "ErrUnbalancedConditional"}, 50 {ErrMinimalData, "ErrMinimalData"}, 51 {ErrInvalidSigHashType, "ErrInvalidSigHashType"}, 52 {ErrSigTooShort, "ErrSigTooShort"}, 53 {ErrSigTooLong, "ErrSigTooLong"}, 54 {ErrSigInvalidSeqID, "ErrSigInvalidSeqID"}, 55 {ErrSigInvalidDataLen, "ErrSigInvalidDataLen"}, 56 {ErrSigMissingSTypeID, "ErrSigMissingSTypeID"}, 57 {ErrSigMissingSLen, "ErrSigMissingSLen"}, 58 {ErrSigInvalidSLen, "ErrSigInvalidSLen"}, 59 {ErrSigInvalidRIntID, "ErrSigInvalidRIntID"}, 60 {ErrSigZeroRLen, "ErrSigZeroRLen"}, 61 {ErrSigNegativeR, "ErrSigNegativeR"}, 62 {ErrSigTooMuchRPadding, "ErrSigTooMuchRPadding"}, 63 {ErrSigInvalidSIntID, "ErrSigInvalidSIntID"}, 64 {ErrSigZeroSLen, "ErrSigZeroSLen"}, 65 {ErrSigNegativeS, "ErrSigNegativeS"}, 66 {ErrSigTooMuchSPadding, "ErrSigTooMuchSPadding"}, 67 {ErrSigHighS, "ErrSigHighS"}, 68 {ErrNotPushOnly, "ErrNotPushOnly"}, 69 {ErrSigNullDummy, "ErrSigNullDummy"}, 70 {ErrPubKeyType, "ErrPubKeyType"}, 71 {ErrCleanStack, "ErrCleanStack"}, 72 {ErrNullFail, "ErrNullFail"}, 73 {ErrDiscourageUpgradableNOPs, "ErrDiscourageUpgradableNOPs"}, 74 {ErrNegativeLockTime, "ErrNegativeLockTime"}, 75 {ErrUnsatisfiedLockTime, "ErrUnsatisfiedLockTime"}, 76 {ErrWitnessProgramEmpty, "ErrWitnessProgramEmpty"}, 77 {ErrWitnessProgramMismatch, "ErrWitnessProgramMismatch"}, 78 {ErrWitnessProgramWrongLength, "ErrWitnessProgramWrongLength"}, 79 {ErrWitnessMalleated, "ErrWitnessMalleated"}, 80 {ErrWitnessMalleatedP2SH, "ErrWitnessMalleatedP2SH"}, 81 {ErrWitnessUnexpected, "ErrWitnessUnexpected"}, 82 {ErrMinimalIf, "ErrMinimalIf"}, 83 {ErrWitnessPubKeyType, "ErrWitnessPubKeyType"}, 84 {ErrDiscourageUpgradableWitnessProgram, "ErrDiscourageUpgradableWitnessProgram"}, 85 {0xffff, "Unknown ErrorCode (65535)"}, 86 } 87 88 // Detect additional error codes that don't have the stringer added. 89 if len(tests)-1 != int(numErrorCodes) { 90 t.Errorf("It appears an error code was added without adding an " + 91 "associated stringer test") 92 } 93 94 t.Logf("Running %d tests", len(tests)) 95 for i, test := range tests { 96 result := test.in.String() 97 if result != test.want { 98 t.Errorf("String #%d\n got: %s want: %s", i, result, 99 test.want) 100 continue 101 } 102 } 103 } 104 105 // TestError tests the error output for the Error type. 106 func TestError(t *testing.T) { 107 t.Parallel() 108 109 tests := []struct { 110 in Error 111 want string 112 }{ 113 { 114 Error{Description: "some error"}, 115 "some error", 116 }, 117 { 118 Error{Description: "human-readable error"}, 119 "human-readable error", 120 }, 121 } 122 123 t.Logf("Running %d tests", len(tests)) 124 for i, test := range tests { 125 result := test.in.Error() 126 if result != test.want { 127 t.Errorf("Error #%d\n got: %s want: %s", i, result, 128 test.want) 129 continue 130 } 131 } 132 }