github.com/dashpay/godash@v0.0.0-20160726055534-e038a21e0e3d/blockchain/error_test.go (about)

     1  // Copyright (c) 2014 The btcsuite developers
     2  // Copyright (c) 2016 The Dash 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 blockchain_test
     7  
     8  import (
     9  	"testing"
    10  
    11  	"github.com/dashpay/godash/blockchain"
    12  )
    13  
    14  // TestErrorCodeStringer tests the stringized output for the ErrorCode type.
    15  func TestErrorCodeStringer(t *testing.T) {
    16  	tests := []struct {
    17  		in   blockchain.ErrorCode
    18  		want string
    19  	}{
    20  		{blockchain.ErrDuplicateBlock, "ErrDuplicateBlock"},
    21  		{blockchain.ErrBlockTooBig, "ErrBlockTooBig"},
    22  		{blockchain.ErrBlockVersionTooOld, "ErrBlockVersionTooOld"},
    23  		{blockchain.ErrInvalidTime, "ErrInvalidTime"},
    24  		{blockchain.ErrTimeTooOld, "ErrTimeTooOld"},
    25  		{blockchain.ErrTimeTooNew, "ErrTimeTooNew"},
    26  		{blockchain.ErrDifficultyTooLow, "ErrDifficultyTooLow"},
    27  		{blockchain.ErrUnexpectedDifficulty, "ErrUnexpectedDifficulty"},
    28  		{blockchain.ErrHighHash, "ErrHighHash"},
    29  		{blockchain.ErrBadMerkleRoot, "ErrBadMerkleRoot"},
    30  		{blockchain.ErrBadCheckpoint, "ErrBadCheckpoint"},
    31  		{blockchain.ErrForkTooOld, "ErrForkTooOld"},
    32  		{blockchain.ErrCheckpointTimeTooOld, "ErrCheckpointTimeTooOld"},
    33  		{blockchain.ErrNoTransactions, "ErrNoTransactions"},
    34  		{blockchain.ErrTooManyTransactions, "ErrTooManyTransactions"},
    35  		{blockchain.ErrNoTxInputs, "ErrNoTxInputs"},
    36  		{blockchain.ErrNoTxOutputs, "ErrNoTxOutputs"},
    37  		{blockchain.ErrTxTooBig, "ErrTxTooBig"},
    38  		{blockchain.ErrBadTxOutValue, "ErrBadTxOutValue"},
    39  		{blockchain.ErrDuplicateTxInputs, "ErrDuplicateTxInputs"},
    40  		{blockchain.ErrBadTxInput, "ErrBadTxInput"},
    41  		{blockchain.ErrBadCheckpoint, "ErrBadCheckpoint"},
    42  		{blockchain.ErrMissingTx, "ErrMissingTx"},
    43  		{blockchain.ErrUnfinalizedTx, "ErrUnfinalizedTx"},
    44  		{blockchain.ErrDuplicateTx, "ErrDuplicateTx"},
    45  		{blockchain.ErrOverwriteTx, "ErrOverwriteTx"},
    46  		{blockchain.ErrImmatureSpend, "ErrImmatureSpend"},
    47  		{blockchain.ErrDoubleSpend, "ErrDoubleSpend"},
    48  		{blockchain.ErrSpendTooHigh, "ErrSpendTooHigh"},
    49  		{blockchain.ErrBadFees, "ErrBadFees"},
    50  		{blockchain.ErrTooManySigOps, "ErrTooManySigOps"},
    51  		{blockchain.ErrFirstTxNotCoinbase, "ErrFirstTxNotCoinbase"},
    52  		{blockchain.ErrMultipleCoinbases, "ErrMultipleCoinbases"},
    53  		{blockchain.ErrBadCoinbaseScriptLen, "ErrBadCoinbaseScriptLen"},
    54  		{blockchain.ErrBadCoinbaseValue, "ErrBadCoinbaseValue"},
    55  		{blockchain.ErrMissingCoinbaseHeight, "ErrMissingCoinbaseHeight"},
    56  		{blockchain.ErrBadCoinbaseHeight, "ErrBadCoinbaseHeight"},
    57  		{blockchain.ErrScriptMalformed, "ErrScriptMalformed"},
    58  		{blockchain.ErrScriptValidation, "ErrScriptValidation"},
    59  		{0xffff, "Unknown ErrorCode (65535)"},
    60  	}
    61  
    62  	t.Logf("Running %d tests", len(tests))
    63  	for i, test := range tests {
    64  		result := test.in.String()
    65  		if result != test.want {
    66  			t.Errorf("String #%d\n got: %s want: %s", i, result,
    67  				test.want)
    68  			continue
    69  		}
    70  	}
    71  }
    72  
    73  // TestRuleError tests the error output for the RuleError type.
    74  func TestRuleError(t *testing.T) {
    75  	tests := []struct {
    76  		in   blockchain.RuleError
    77  		want string
    78  	}{
    79  		{
    80  			blockchain.RuleError{Description: "duplicate block"},
    81  			"duplicate block",
    82  		},
    83  		{
    84  			blockchain.RuleError{Description: "human-readable error"},
    85  			"human-readable error",
    86  		},
    87  	}
    88  
    89  	t.Logf("Running %d tests", len(tests))
    90  	for i, test := range tests {
    91  		result := test.in.Error()
    92  		if result != test.want {
    93  			t.Errorf("Error #%d\n got: %s want: %s", i, result,
    94  				test.want)
    95  			continue
    96  		}
    97  	}
    98  }