2014-06-25 00:47:57 +02:00
|
|
|
// Copyright (c) 2014 Conformal Systems LLC.
|
|
|
|
// Use of this source code is governed by an ISC
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package btcchain_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2014-07-02 18:04:59 +02:00
|
|
|
|
2015-01-17 01:40:47 +01:00
|
|
|
"github.com/btcsuite/btcchain"
|
2014-06-25 00:47:57 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// TestErrorCodeStringer tests the stringized output for the ErrorCode type.
|
|
|
|
func TestErrorCodeStringer(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
in btcchain.ErrorCode
|
|
|
|
want string
|
|
|
|
}{
|
|
|
|
{btcchain.ErrDuplicateBlock, "ErrDuplicateBlock"},
|
2014-06-29 22:11:13 +02:00
|
|
|
{btcchain.ErrBlockTooBig, "ErrBlockTooBig"},
|
2014-06-25 00:47:57 +02:00
|
|
|
{btcchain.ErrBlockVersionTooOld, "ErrBlockVersionTooOld"},
|
|
|
|
{btcchain.ErrInvalidTime, "ErrInvalidTime"},
|
|
|
|
{btcchain.ErrTimeTooOld, "ErrTimeTooOld"},
|
|
|
|
{btcchain.ErrTimeTooNew, "ErrTimeTooNew"},
|
|
|
|
{btcchain.ErrDifficultyTooLow, "ErrDifficultyTooLow"},
|
|
|
|
{btcchain.ErrUnexpectedDifficulty, "ErrUnexpectedDifficulty"},
|
|
|
|
{btcchain.ErrHighHash, "ErrHighHash"},
|
|
|
|
{btcchain.ErrBadMerkleRoot, "ErrBadMerkleRoot"},
|
|
|
|
{btcchain.ErrBadCheckpoint, "ErrBadCheckpoint"},
|
|
|
|
{btcchain.ErrForkTooOld, "ErrForkTooOld"},
|
2014-07-11 16:36:53 +02:00
|
|
|
{btcchain.ErrCheckpointTimeTooOld, "ErrCheckpointTimeTooOld"},
|
2014-06-25 00:47:57 +02:00
|
|
|
{btcchain.ErrNoTransactions, "ErrNoTransactions"},
|
2014-06-29 22:11:13 +02:00
|
|
|
{btcchain.ErrTooManyTransactions, "ErrTooManyTransactions"},
|
2014-06-25 00:47:57 +02:00
|
|
|
{btcchain.ErrNoTxInputs, "ErrNoTxInputs"},
|
|
|
|
{btcchain.ErrNoTxOutputs, "ErrNoTxOutputs"},
|
2014-06-29 22:11:13 +02:00
|
|
|
{btcchain.ErrTxTooBig, "ErrTxTooBig"},
|
2014-06-25 00:47:57 +02:00
|
|
|
{btcchain.ErrBadTxOutValue, "ErrBadTxOutValue"},
|
|
|
|
{btcchain.ErrDuplicateTxInputs, "ErrDuplicateTxInputs"},
|
|
|
|
{btcchain.ErrBadTxInput, "ErrBadTxInput"},
|
|
|
|
{btcchain.ErrBadCheckpoint, "ErrBadCheckpoint"},
|
|
|
|
{btcchain.ErrMissingTx, "ErrMissingTx"},
|
|
|
|
{btcchain.ErrUnfinalizedTx, "ErrUnfinalizedTx"},
|
|
|
|
{btcchain.ErrDuplicateTx, "ErrDuplicateTx"},
|
|
|
|
{btcchain.ErrOverwriteTx, "ErrOverwriteTx"},
|
|
|
|
{btcchain.ErrImmatureSpend, "ErrImmatureSpend"},
|
|
|
|
{btcchain.ErrDoubleSpend, "ErrDoubleSpend"},
|
|
|
|
{btcchain.ErrSpendTooHigh, "ErrSpendTooHigh"},
|
|
|
|
{btcchain.ErrBadFees, "ErrBadFees"},
|
|
|
|
{btcchain.ErrTooManySigOps, "ErrTooManySigOps"},
|
|
|
|
{btcchain.ErrFirstTxNotCoinbase, "ErrFirstTxNotCoinbase"},
|
|
|
|
{btcchain.ErrMultipleCoinbases, "ErrMultipleCoinbases"},
|
|
|
|
{btcchain.ErrBadCoinbaseScriptLen, "ErrBadCoinbaseScriptLen"},
|
|
|
|
{btcchain.ErrBadCoinbaseValue, "ErrBadCoinbaseValue"},
|
|
|
|
{btcchain.ErrMissingCoinbaseHeight, "ErrMissingCoinbaseHeight"},
|
|
|
|
{btcchain.ErrBadCoinbaseHeight, "ErrBadCoinbaseHeight"},
|
2014-06-27 06:29:57 +02:00
|
|
|
{btcchain.ErrScriptMalformed, "ErrScriptMalformed"},
|
|
|
|
{btcchain.ErrScriptValidation, "ErrScriptValidation"},
|
2014-06-25 00:47:57 +02:00
|
|
|
{0xffff, "Unknown ErrorCode (65535)"},
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Logf("Running %d tests", len(tests))
|
|
|
|
for i, test := range tests {
|
|
|
|
result := test.in.String()
|
|
|
|
if result != test.want {
|
|
|
|
t.Errorf("String #%d\n got: %s want: %s", i, result,
|
|
|
|
test.want)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TestRuleError tests the error output for the RuleError type.
|
|
|
|
func TestRuleError(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
in btcchain.RuleError
|
|
|
|
want string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
btcchain.RuleError{Description: "duplicate block"},
|
|
|
|
"duplicate block",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
btcchain.RuleError{Description: "human-readable error"},
|
|
|
|
"human-readable error",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Logf("Running %d tests", len(tests))
|
|
|
|
for i, test := range tests {
|
|
|
|
result := test.in.Error()
|
|
|
|
if result != test.want {
|
|
|
|
t.Errorf("Error #%d\n got: %s want: %s", i, result,
|
|
|
|
test.want)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|