package v2peer import ( "testing" "time" btcdwire "github.com/btcsuite/btcd/wire/v2" "git.smesh.lol/nostrino/pkg/btcwire" ) // TestTheTwoHashTypesAgree: btcd's hash and this project's hash of one header // are the same 32 bytes in every field that matters, with no conversion. The // zero header looked like they disagreed because it reverses onto itself: it // carries no information about layout. A header with distinct fields shows // what holds for every header, and it is the rule the rest of the code uses. func TestTheTwoHashTypesAgree(t *testing.T) { theirs := &btcdwire.BlockHeader{Version: 1, Timestamp: time.Unix(1234567890, 0), Bits: 0x1d00ffff, Nonce: 42} ours := &btcwire.BlockHeader{Version: 1, Timestamp: 1234567890, Bits: 0x1d00ffff, Nonce: 42} for i := 0; i < 32; i++ { theirs.PrevBlock[i] = byte(i) theirs.MerkleRoot[i] = byte(0xff - i) ours.PrevBlock[i] = byte(i) ours.MerkleRoot[i] = byte(0xff - i) } v := [32]byte(theirs.BlockHash()) o := [32]byte(ours.BlockHash()) if v != o { t.Fatalf("this project hashes the header %x, btcd hashes it %x", o, v) } if toVendor(o) != theirs.BlockHash() { t.Fatal("toVendor is not the identity on a hash the two types already agree on") } if fromVendor(v) != o { t.Fatal("fromVendor is not the identity on a hash the two types already agree on") } t.Logf("both hash it %x", o) }