github.com/lbryio/lbcd@v0.22.119/blockchain/error_test.go (about)

     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  		{ErrBlockWeightTooHigh, "ErrBlockWeightTooHigh"},
    20  		{ErrBlockVersionTooOld, "ErrBlockVersionTooOld"},
    21  		{ErrInvalidTime, "ErrInvalidTime"},
    22  		{ErrTimeTooOld, "ErrTimeTooOld"},
    23  		{ErrTimeTooNew, "ErrTimeTooNew"},
    24  		{ErrDifficultyTooLow, "ErrDifficultyTooLow"},
    25  		{ErrUnexpectedDifficulty, "ErrUnexpectedDifficulty"},
    26  		{ErrHighHash, "ErrHighHash"},
    27  		{ErrBadMerkleRoot, "ErrBadMerkleRoot"},
    28  		{ErrBadCheckpoint, "ErrBadCheckpoint"},
    29  		{ErrForkTooOld, "ErrForkTooOld"},
    30  		{ErrCheckpointTimeTooOld, "ErrCheckpointTimeTooOld"},
    31  		{ErrNoTransactions, "ErrNoTransactions"},
    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  		{ErrUnexpectedWitness, "ErrUnexpectedWitness"},
    56  		{ErrInvalidWitnessCommitment, "ErrInvalidWitnessCommitment"},
    57  		{ErrWitnessCommitmentMismatch, "ErrWitnessCommitmentMismatch"},
    58  		{ErrPreviousBlockUnknown, "ErrPreviousBlockUnknown"},
    59  		{ErrInvalidAncestorBlock, "ErrInvalidAncestorBlock"},
    60  		{ErrPrevBlockNotBest, "ErrPrevBlockNotBest"},
    61  		{0xffff, "Unknown ErrorCode (65535)"},
    62  	}
    63  
    64  	t.Logf("Running %d tests", len(tests))
    65  	for i, test := range tests {
    66  		result := test.in.String()
    67  		if result != test.want {
    68  			t.Errorf("String #%d\n got: %s want: %s", i, result,
    69  				test.want)
    70  			continue
    71  		}
    72  	}
    73  }
    74  
    75  // TestRuleError tests the error output for the RuleError type.
    76  func TestRuleError(t *testing.T) {
    77  	tests := []struct {
    78  		in   RuleError
    79  		want string
    80  	}{
    81  		{
    82  			RuleError{Description: "duplicate block"},
    83  			"duplicate block",
    84  		},
    85  		{
    86  			RuleError{Description: "human-readable error"},
    87  			"human-readable error",
    88  		},
    89  	}
    90  
    91  	t.Logf("Running %d tests", len(tests))
    92  	for i, test := range tests {
    93  		result := test.in.Error()
    94  		if result != test.want {
    95  			t.Errorf("Error #%d\n got: %s want: %s", i, result,
    96  				test.want)
    97  			continue
    98  		}
    99  	}
   100  }
   101  
   102  // TestDeploymentError tests the stringized output for the DeploymentError type.
   103  func TestDeploymentError(t *testing.T) {
   104  	t.Parallel()
   105  
   106  	tests := []struct {
   107  		in   DeploymentError
   108  		want string
   109  	}{
   110  		{
   111  			DeploymentError(0),
   112  			"deployment ID 0 does not exist",
   113  		},
   114  		{
   115  			DeploymentError(10),
   116  			"deployment ID 10 does not exist",
   117  		},
   118  		{
   119  			DeploymentError(123),
   120  			"deployment ID 123 does not exist",
   121  		},
   122  	}
   123  
   124  	t.Logf("Running %d tests", len(tests))
   125  	for i, test := range tests {
   126  		result := test.in.Error()
   127  		if result != test.want {
   128  			t.Errorf("Error #%d\n got: %s want: %s", i, result,
   129  				test.want)
   130  			continue
   131  		}
   132  	}
   133  
   134  }