go-blockchain/crypto/pow_test.go
Claude 4fe3fdfbd2
feat(crypto): RandomX PoW hash via CGo bridge
Vendor RandomX source, add bridge_randomx_hash() with static
VM lifecycle. Key: LetheanRandomXv1. Input: header_hash || nonce.

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

40 lines
1.1 KiB
Go

// Copyright (c) 2017-2026 Lethean (https://lt.hn)
//
// Licensed under the European Union Public Licence (EUPL) version 1.2.
// SPDX-Licence-Identifier: EUPL-1.2
package crypto
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestRandomXHash_Good(t *testing.T) {
key := []byte("LetheanRandomXv1")
input := make([]byte, 40) // 32-byte hash + 8-byte nonce
hash, err := RandomXHash(key, input)
require.NoError(t, err)
assert.NotEqual(t, [32]byte{}, hash, "hash should be non-zero")
// Determinism: same input must produce the same output.
hash2, err := RandomXHash(key, input)
require.NoError(t, err)
assert.Equal(t, hash, hash2, "hash must be deterministic")
}
func TestRandomXHash_Bad(t *testing.T) {
key := []byte("LetheanRandomXv1")
input1 := make([]byte, 40)
input2 := make([]byte, 40)
input2[0] = 1
hash1, err := RandomXHash(key, input1)
require.NoError(t, err)
hash2, err := RandomXHash(key, input2)
require.NoError(t, err)
assert.NotEqual(t, hash1, hash2, "different inputs must produce different hashes")
}