go-blockchain/consensus/pow_test.go
Claude c2888c487b
feat(consensus): PoW difficulty check with RandomX
CheckDifficulty compares a 256-bit LE hash against a difficulty target.
CheckPoWHash computes RandomX hash and checks against difficulty.

Co-Authored-By: Charon <charon@lethean.io>
2026-02-21 01:04:16 +00:00

25 lines
516 B
Go

//go:build !integration
package consensus
import (
"testing"
"forge.lthn.ai/core/go-blockchain/types"
"github.com/stretchr/testify/assert"
)
func TestCheckDifficulty_Good(t *testing.T) {
// A zero hash meets any difficulty.
hash := types.Hash{}
assert.True(t, CheckDifficulty(hash, 1))
}
func TestCheckDifficulty_Bad(t *testing.T) {
// Max hash (all 0xFF) should fail high difficulty.
hash := types.Hash{}
for i := range hash {
hash[i] = 0xFF
}
assert.False(t, CheckDifficulty(hash, ^uint64(0)))
}