Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ordishs committed Mar 14, 2023
1 parent 83db018 commit ae44d1a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
18 changes: 7 additions & 11 deletions Peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,26 +84,22 @@ func NewPeer(logger utils.Logger, address string, peerHandler PeerHandlerI, netw
go p.writeChannelHandler()
}

if p.incomingConn != nil {
p.logger.Infof("[%s] Incoming connection from peer on %s", p.address, p.network)
go func() {
err := p.connect()
if err != nil {
logger.Warnf("Failed to connect to peer %s: %v", address, err)
}
}()
} else {
// reconnect if disconnected, but only on outgoing connections
go func() {
err := p.connect()
if err != nil {
logger.Warnf("Failed to connect to peer %s: %v", address, err)
}
}()

if p.incomingConn != nil {
p.logger.Infof("[%s] Incoming connection from peer on %s", p.address, p.network)
} else {
// reconnect if disconnected, but only on outgoing connections
go func() {
for range time.NewTicker(10 * time.Second).C {
// logger.Debugf("checking connection to peer %s, connected = %t, connecting = %t", address, p.Connected(), p.Connecting())
if !p.Connected() && !p.Connecting() {
err = p.connect()
err := p.connect()
if err != nil {
logger.Warnf("Failed to connect to peer %s: %v", address, err)
}
Expand Down
2 changes: 1 addition & 1 deletion Peer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ func Test_readHandler(t *testing.T) {
assert.Equal(t, 2, len(block.TransactionHashes))

// read the transactions
expectedTxBytes := [][]byte{test.TX1Bytes, test.TX2Bytes}
expectedTxBytes := []*chainhash.Hash{test.TX1Hash, test.TX2Hash}
blockTransactions := peerHandler.GetBlockTransactions(0)
for i, txMsg := range blockTransactions {
assert.Equal(t, expectedTxBytes[i], txMsg)
Expand Down
5 changes: 3 additions & 2 deletions test/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@ import (
"encoding/hex"
"time"

"github.com/libsv/go-p2p/chaincfg/chainhash"
"github.com/ordishs/go-utils"
)

var (
TX1 = "b042f298deabcebbf15355aa3a13c7d7cfe96c44ac4f492735f936f8e50d06f6"
TX1Bytes, _ = utils.DecodeAndReverseHexString(TX1)
TX1Hash, _ = chainhash.NewHashFromStr(TX1)
TX1Raw = "01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff1a0386c40b2f7461616c2e636f6d2f00cf47ad9c7af83836000000ffffffff0117564425000000001976a914522cf9e7626d9bd8729e5a1398ece40dad1b6a2f88ac00000000"
TX1RawBytes, _ = hex.DecodeString(TX1Raw)
TX2 = "1a8fda8c35b8fc30885e88d6eb0214e2b3a74c96c82c386cb463905446011fdf"
TX2Bytes, _ = utils.DecodeAndReverseHexString(TX2)
TX2Hash, _ = chainhash.NewHashFromStr(TX2)
TX2Raw = "01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff1a0385c40b2f7461616c2e636f6d2f0fde4a8a8fbbf5c636010000ffffffff02c9d74425000000001976a914522cf9e7626d9bd8729e5a1398ece40dad1b6a2f88ac0000000000000000fda502006a04ac1eed884d53027b2276657273696f6e223a22302e31222c22686569676874223a3737313230352c22707265764d696e65724964223a22303365393264336535633366376264393435646662663438653761393933393362316266623366313166333830616533306432383665376666326165633561323730222c22707265764d696e65724964536967223a2233303435303232313030643736333630653464323133333163613836663031386330343665353763393338663139373735303734373333333533363062653337303438636165316166333032323030626536363034353430323162663934363465393966356139353831613938633963663439353430373539386335396234373334623266646234383262663937222c226d696e65724964223a22303365393264336535633366376264393435646662663438653761393933393362316266623366313166333830616533306432383665376666326165633561323730222c2276637478223a7b2274784964223a2235373962343335393235613930656533396133376265336230306239303631653734633330633832343133663664306132303938653162656137613235313566222c22766f7574223a307d2c226d696e6572436f6e74616374223a7b22656d61696c223a22696e666f407461616c2e636f6d222c226e616d65223a225441414c20446973747269627574656420496e666f726d6174696f6e20546563686e6f6c6f67696573222c226d65726368616e74415049456e64506f696e74223a2268747470733a2f2f6d65726368616e746170692e7461616c2e636f6d2f227d7d473045022100f7a4d02865a503d202b4e3d1b045a7efaef830b3d27efd6482c939c376e58c7802202d9332ca0a8b90001fa143512b4b6f3fe00f227d9d882861cc87975cb8778da800000000"
TX2RawBytes, _ = hex.DecodeString(TX2Raw)
TX3 = "3f63399b3d9d94ba9c5b7398b9328dcccfcfd50f07ad8b214e766168c391642b"
Expand Down

0 comments on commit ae44d1a

Please sign in to comment.