package chain_test import ( "testing" "git.smesh.lol/nostrino/pkg/chain" ) // TestXBTProfileCarriesTheFork pins the fork's three moving parts to the values the node's source // and a direct peer's chain agree on. A light client that starts with any of them wrong either // syncs the wrong chain or cannot get past the fork. func TestXBTProfileCarriesTheFork(t *testing.T) { profile, err := chain.ByName("blake") if err != nil { t.Fatal(err) } if err := profile.Validate(); err != nil { t.Fatalf("xbt profile does not validate: %v", err) } if profile.HeaderV2Height != 961640 { t.Fatalf("fork height %d, want 961640", profile.HeaderV2Height) } if profile.TargetShift != 22 { t.Fatalf("target shift %d, want 22", profile.TargetShift) } if profile.Checkpoint == nil { t.Fatal("no checkpoint: a first sync would start at genesis") } if profile.Checkpoint.Height != 961631 { t.Fatalf("checkpoint height %d, want 961631", profile.Checkpoint.Height) } if got, want := profile.Checkpoint.BlockHash.String(), "00000000000000000000807f9dc917442a67910426d79ebb2f8aa2149327ce8a"; got != want { t.Fatalf("checkpoint block hash %s, want %s", got, want) } if got, want := profile.Checkpoint.FilterHeader.String(), "323d85f60703ce8b32e56bcaab8ccbe1b121abe7669aed933f557767194bb3f6"; got != want { t.Fatalf("checkpoint filter header %s, want %s", got, want) } // The fork shares Bitcoin's network parameters: that is why the transport profile is the // same and only the consensus above the fork differs. btc, err := chain.ByName("btc") if err != nil { t.Fatal(err) } if profile.Magic != btc.Magic || profile.GenesisHash != btc.GenesisHash { t.Fatal("the fork must keep Bitcoin's magic and genesis") } if profile.Bech32HRP != btc.Bech32HRP || profile.CoinType != btc.CoinType { t.Fatal("the fork must keep Bitcoin's address space") } } // TestProfileJSONRoundTripsTheFork: a profile is how the fork reaches a browser wallet or another // operator, so the fork fields have to survive the file. func TestProfileJSONRoundTripsTheFork(t *testing.T) { profile, err := chain.ByName("blake") if err != nil { t.Fatal(err) } body, err := chain.MarshalProfile(profile) if err != nil { t.Fatal(err) } back, err := chain.ParseProfile(body) if err != nil { t.Fatal(err) } if back.HeaderV2Height != profile.HeaderV2Height || back.TargetShift != profile.TargetShift { t.Fatal("the fork fields did not survive the JSON round trip") } if back.Checkpoint == nil || back.Checkpoint.FilterHeader != profile.Checkpoint.FilterHeader { t.Fatal("the checkpoint did not survive the JSON round trip") } }