package neutrino import ( "math/big" "testing" "git.smesh.lol/nostrino/pkg/btcwire" ) // TestShiftedBitsAppliesTheForkShiftOnce: the fork relaxes the target by 2^shift at the boundary // and nowhere else, capped at the chain's proof-of-work limit. func TestShiftedBitsAppliesTheForkShiftOnce(t *testing.T) { const ( bits = 0x1703a30c limit = 0x1d00ffff ) if got := shiftedBits(bits, 0, limit); got != bits { t.Fatalf("a zero shift changed the bits to %08x", got) } target, err := btcwire.CompactToBig(bits) if err != nil { t.Fatal(err) } want := BigToCompact(new(big.Int).Lsh(target, 22)) if got := shiftedBits(bits, 22, limit); got != want { t.Fatalf("shifted bits %08x, want %08x", got, want) } // The limit itself, shifted, is above the limit, so it must clamp rather than overflow. if got := shiftedBits(limit, 22, limit); got != limit { t.Fatalf("a shift above the limit gave %08x, want the limit %08x", got, limit) } }