2015-12-01 19:44:58 +01:00
|
|
|
// Copyright (c) 2014 The btcsuite developers
|
|
|
|
// Use of this source code is governed by an ISC
|
|
|
|
// license that can be found in the LICENSE file.
|
2014-11-04 18:22:13 +01:00
|
|
|
|
|
|
|
package votingpool_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2018-05-15 07:11:11 +02:00
|
|
|
vp "github.com/btcsuite/btcwallet/votingpool"
|
2014-11-04 18:22:13 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// TestErrorCodeStringer tests that all error codes has a text
|
|
|
|
// representation and that text representation is still correct,
|
|
|
|
// ie. that a refactoring and renaming of the error code has not
|
|
|
|
// drifted from the textual representation.
|
|
|
|
func TestErrorCodeStringer(t *testing.T) {
|
|
|
|
// All the errors in ths
|
|
|
|
tests := []struct {
|
|
|
|
in vp.ErrorCode
|
|
|
|
want string
|
|
|
|
}{
|
|
|
|
{vp.ErrInputSelection, "ErrInputSelection"},
|
|
|
|
{vp.ErrWithdrawalProcessing, "ErrWithdrawalProcessing"},
|
|
|
|
{vp.ErrUnknownPubKey, "ErrUnknownPubKey"},
|
|
|
|
{vp.ErrSeriesSerialization, "ErrSeriesSerialization"},
|
|
|
|
{vp.ErrSeriesVersion, "ErrSeriesVersion"},
|
|
|
|
{vp.ErrSeriesNotExists, "ErrSeriesNotExists"},
|
|
|
|
{vp.ErrSeriesAlreadyExists, "ErrSeriesAlreadyExists"},
|
|
|
|
{vp.ErrSeriesAlreadyEmpowered, "ErrSeriesAlreadyEmpowered"},
|
|
|
|
{vp.ErrSeriesIDNotSequential, "ErrSeriesIDNotSequential"},
|
|
|
|
{vp.ErrSeriesIDInvalid, "ErrSeriesIDInvalid"},
|
|
|
|
{vp.ErrSeriesNotActive, "ErrSeriesNotActive"},
|
|
|
|
{vp.ErrKeyIsPrivate, "ErrKeyIsPrivate"},
|
|
|
|
{vp.ErrKeyIsPublic, "ErrKeyIsPublic"},
|
|
|
|
{vp.ErrKeyNeuter, "ErrKeyNeuter"},
|
|
|
|
{vp.ErrKeyMismatch, "ErrKeyMismatch"},
|
|
|
|
{vp.ErrKeysPrivatePublicMismatch, "ErrKeysPrivatePublicMismatch"},
|
|
|
|
{vp.ErrKeyDuplicate, "ErrKeyDuplicate"},
|
|
|
|
{vp.ErrTooFewPublicKeys, "ErrTooFewPublicKeys"},
|
|
|
|
{vp.ErrPoolAlreadyExists, "ErrPoolAlreadyExists"},
|
|
|
|
{vp.ErrPoolNotExists, "ErrPoolNotExists"},
|
|
|
|
{vp.ErrScriptCreation, "ErrScriptCreation"},
|
|
|
|
{vp.ErrTooManyReqSignatures, "ErrTooManyReqSignatures"},
|
|
|
|
{vp.ErrInvalidBranch, "ErrInvalidBranch"},
|
|
|
|
{vp.ErrInvalidValue, "ErrInvalidValue"},
|
|
|
|
{vp.ErrDatabase, "ErrDatabase"},
|
|
|
|
{vp.ErrKeyChain, "ErrKeyChain"},
|
|
|
|
{vp.ErrCrypto, "ErrCrypto"},
|
|
|
|
{vp.ErrRawSigning, "ErrRawSigning"},
|
|
|
|
{vp.ErrPreconditionNotMet, "ErrPreconditionNotMet"},
|
|
|
|
{vp.ErrTxSigning, "ErrTxSigning"},
|
|
|
|
{vp.ErrInvalidScriptHash, "ErrInvalidScriptHash"},
|
|
|
|
{vp.ErrWithdrawFromUnusedAddr, "ErrWithdrawFromUnusedAddr"},
|
2015-02-18 13:22:03 +01:00
|
|
|
{vp.ErrWithdrawalTxStorage, "ErrWithdrawalTxStorage"},
|
2015-02-23 17:07:12 +01:00
|
|
|
{vp.ErrWithdrawalStorage, "ErrWithdrawalStorage"},
|
2014-11-04 18:22:13 +01:00
|
|
|
{0xffff, "Unknown ErrorCode (65535)"},
|
|
|
|
}
|
|
|
|
|
|
|
|
if int(vp.TstLastErr) != len(tests)-1 {
|
|
|
|
t.Errorf("Wrong number of errorCodeStrings. Got: %d, want: %d",
|
|
|
|
int(vp.TstLastErr), len(tests))
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, test := range tests {
|
|
|
|
result := test.in.String()
|
|
|
|
if result != test.want {
|
|
|
|
t.Errorf("String #%d\ngot: %s\nwant: %s", i, result,
|
|
|
|
test.want)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|