1 package chains_test
2 3 import (
4 "testing"
5 6 btcdwire "github.com/btcsuite/btcd/wire/v2"
7 8 "git.smesh.lol/btcd-lite/internal/chains"
9 )
10 11 // TestWireMagic: a profile carries the magic as the four bytes on the wire and
12 // btcd's BitcoinNet is those bytes read little-endian. Mainnet is f9beb4d9 on
13 // the wire and d9b4bef9 in btcd's type, and passing the first where the second
14 // belongs writes a magic no node recognises, which reads as a peer that accepts
15 // TCP and then says nothing.
16 func TestWireMagic(t *testing.T) {
17 btc, err := chains.ParentChain()
18 if err != nil {
19 t.Fatal(err)
20 }
21 if got := btc.WireMagic(); got != btcdwire.MainNet {
22 t.Fatalf("btc wire magic is %#08x, btcd's mainnet is %#08x", uint32(got), uint32(btcdwire.MainNet))
23 }
24 xbt, err := chains.ForkChain()
25 if err != nil {
26 t.Fatal(err)
27 }
28 if xbt.WireMagic() != btcdwire.MainNet {
29 t.Fatalf("the fork's wire magic is %#08x; the fork reuses the magic", uint32(xbt.WireMagic()))
30 }
31 rt := chains.Regtest()
32 if got := uint32(rt.Exported.Magic); got != 0xdab5bffa {
33 t.Fatalf("regtest's exported magic is %#08x", got)
34 }
35 if got := uint32(rt.WireMagic()); got != 0xdab5bffa {
36 t.Fatalf("regtest's wire magic is %#08x, the node accepts 0xdab5bffa", got)
37 }
38 if got := uint32(rt.Profile.Magic); got != 0xfabfb5da {
39 t.Fatalf("regtest's profile magic is %#08x, the wire order is 0xfabfb5da", got)
40 }
41 }
42