mirror of
https://github.com/FlipsideCrypto/dcrd.git
synced 2026-02-06 10:56:47 +00:00
Contains the following upstream commits: -00bddf7540-250228c32f-f1bd2f8d6e-cbbe3a8bbe-aa03d68e1eIn addition to the normal required changes for syncing, the following changes have been made in order to facilitate integration of the new package into Decred: - Removed check in PushRejectMsg against protocol version since all peers since the initial version support it - Fixed leaked timer in `syncMiningStateAfterSync` function - Add the Decred-specific OnGetMiningState and OnMiningState handlers to the new peer package - Add handler for the new mining state messages to the 'serverPeer' type and register them - Use the new constant for wire.InitialProtocolVersion in the reject message instead of hard coded number - Remove logic specific to the regression network since Decred does not have it
66 lines
1.4 KiB
Go
66 lines
1.4 KiB
Go
// Copyright (c) 2015 The btcsuite developers Use of this source code is
|
|
// governed by an ISC license that can be found in the LICENSE file.
|
|
|
|
package peer_test
|
|
|
|
import (
|
|
"bytes"
|
|
"errors"
|
|
"io"
|
|
"testing"
|
|
|
|
"github.com/decred/dcrd/peer"
|
|
)
|
|
|
|
func TestSetLogWriter(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
w io.Writer
|
|
level string
|
|
expected error
|
|
}{
|
|
{
|
|
name: "nil writer",
|
|
w: nil,
|
|
level: "trace",
|
|
expected: errors.New("nil writer"),
|
|
},
|
|
{
|
|
name: "invalid log level",
|
|
w: bytes.NewBuffer(nil),
|
|
level: "wrong",
|
|
expected: errors.New("invalid log level"),
|
|
},
|
|
{
|
|
name: "use off level",
|
|
w: bytes.NewBuffer(nil),
|
|
level: "off",
|
|
expected: errors.New("min level can't be greater than max. Got min: 6, max: 5"),
|
|
},
|
|
{
|
|
name: "pass",
|
|
w: bytes.NewBuffer(nil),
|
|
level: "debug",
|
|
expected: nil,
|
|
},
|
|
}
|
|
|
|
t.Logf("Running %d tests", len(tests))
|
|
for i, test := range tests {
|
|
err := peer.SetLogWriter(test.w, test.level)
|
|
if err != nil {
|
|
if err.Error() != test.expected.Error() {
|
|
t.Errorf("SetLogWriter #%d (%s) wrong result\n"+
|
|
"got: %v\nwant: %v", i, test.name, err,
|
|
test.expected)
|
|
}
|
|
} else {
|
|
if test.expected != nil {
|
|
t.Errorf("SetLogWriter #%d (%s) wrong result\n"+
|
|
"got: %v\nwant: %v", i, test.name, err,
|
|
test.expected)
|
|
}
|
|
}
|
|
}
|
|
}
|