package neutrino import ( "context" "errors" "net" "strings" "testing" "git.smesh.lol/nostrino/pkg/btcwire" "git.smesh.lol/nostrino/pkg/chain" "git.smesh.lol/nostrino/pkg/crypto/chainhash" ) // TestAWrongCheckpointIsNamed: a checkpoint that is not on the chain is refused at the block // above it, and the error names the checkpoint so an operator knows which deployment value to // fix. The same check protects an import: a backup anchored at the wrong fork fails here. func TestAWrongCheckpointIsNamed(t *testing.T) { profile := chain.Regtest store := NewMemory() checkpoint := Anchor{ Height: 30, BlockHash: chainhash.DoubleHashH([]byte("not this chain's block")), FilterHeight: 30, FilterHeader: chainhash.DoubleHashH([]byte("nor this filter header")), } if err := store.SetAnchor(checkpoint); err != nil { t.Fatal(err) } client, err := New(Config{Profile: &profile, Store: store, Dial: func(ctx context.Context) (net.Conn, error) { return nil, errors.New("no peer") }}) if err != nil { t.Fatal(err) } var header btcwire.BlockHeader header.PrevBlock = chainhash.DoubleHashH([]byte("some other parent")) if _, err := client.ApplyHeaders(checkpoint.Height+1, []btcwire.BlockHeader{header}); err == nil { t.Fatal("a header that does not link to the checkpoint was accepted") } else if !strings.Contains(err.Error(), "checkpoint at 30") { t.Fatalf("the error does not name the checkpoint: %v", err) } }