services_test.go raw

   1  package neutrino
   2  
   3  import (
   4  	"testing"
   5  
   6  	"git.smesh.lol/nostrino/pkg/btcwire"
   7  	"git.smesh.lol/nostrino/pkg/chain"
   8  )
   9  
  10  // TestPeerServicesAdvertisesTheFork: a forked chain's node holds a peer that
  11  // does not advertise the fork's bit to the last block the two chains share and
  12  // answers a header request above it with an empty message. The client has to
  13  // say it follows the fork before it asks.
  14  func TestPeerServicesAdvertisesTheFork(t *testing.T) {
  15  	btc := &chain.Profile{Name: "btc"}
  16  	if s := peerServices(btc); s&btcwire.ServiceNodeBlake2b != 0 {
  17  		t.Fatalf("bitcoin mainnet advertises the forked chain bit: %#x", s)
  18  	}
  19  
  20  	xbt := &chain.Profile{Name: "xbt", HeaderV2Height: 961640}
  21  	s := peerServices(xbt)
  22  	if s&btcwire.ServiceNodeBlake2b == 0 {
  23  		t.Fatalf("the forked chain does not advertise its bit: %#x", s)
  24  	}
  25  	if s&btcwire.ServiceNodeCompactFilters == 0 || s&btcwire.ServiceNodeWitness == 0 {
  26  		t.Fatalf("the base service bits were dropped: %#x", s)
  27  	}
  28  }
  29