dial_test.go raw
1 package litedial
2
3 import (
4 "context"
5 "net"
6 "os"
7 "testing"
8 "time"
9
10 btcdwire "github.com/btcsuite/btcd/wire/v2"
11 )
12
13 // TestConnectToTheRig dials the node on this machine went it is up. It is the
14 // instance's dial, run from a test binary.
15 func TestConnectToTheRig(t *testing.T) {
16 addr := os.Getenv("BTCD_LITE_TEST_PEER")
17 if addr == "" {
18 addr = "127.0.0.1:18444"
19 }
20 nc, err := net.DialTimeout("tcp", addr, time.Second)
21 if err != nil {
22 t.Skipf("no node at %s", addr)
23 }
24 _ = nc.Close()
25 start := time.Now()
26 p, err := Connect(context.Background(), addr, "/btcd-lite:0.1.0/", btcdwire.BitcoinNet(0xDAB5BFFA), 20*time.Second, true, t.Logf)
27 if err != nil {
28 t.Fatalf("connect after %s: %v", time.Since(start).Round(time.Millisecond), err)
29 }
30 defer p.Close()
31 t.Logf("connected in %s", time.Since(start).Round(time.Millisecond))
32 }
33