go-blockchain/mining/integration_test.go
Snider 34128d8e98
Some checks failed
Security Scan / security (pull_request) Successful in 11s
Test / Test (pull_request) Failing after 19s
refactor: migrate module path to dappco.re/go/core/blockchain
Update go.mod module line, all require/replace directives, and every
.go import path from forge.lthn.ai/core/go-blockchain to
dappco.re/go/core/blockchain. Add replace directives to bridge
dappco.re paths to existing forge.lthn.ai registry during migration.
Update CLAUDE.md, README, and docs to reflect the new module path.

Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-22 01:49:26 +00:00

58 lines
1.7 KiB
Go

//go:build integration
// Copyright (c) 2017-2026 Lethean (https://lt.hn)
//
// Licensed under the European Union Public Licence (EUPL) version 1.2.
// SPDX-License-Identifier: EUPL-1.2
package mining
import (
"bytes"
"encoding/hex"
"testing"
"dappco.re/go/core/blockchain/rpc"
"dappco.re/go/core/blockchain/wire"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestIntegration_GetBlockTemplate(t *testing.T) {
client := rpc.NewClient("http://localhost:46941")
// Get daemon info to check it's running.
info, err := client.GetInfo()
require.NoError(t, err, "daemon must be running on localhost:46941")
t.Logf("daemon height: %d, pow_difficulty: %d", info.Height, info.PowDifficulty)
// Get a block template.
// Use the testnet genesis coinbase address (all zeros — won't receive real
// coins but the daemon accepts it for template generation).
tmpl, err := client.GetBlockTemplate("iTHNtestaddr")
if err != nil {
t.Skipf("getblocktemplate failed (may need valid address): %v", err)
}
assert.Greater(t, tmpl.Height, uint64(0))
assert.NotEmpty(t, tmpl.Difficulty)
assert.NotEmpty(t, tmpl.BlockTemplateBlob)
// Decode the template blob.
blobBytes, err := hex.DecodeString(tmpl.BlockTemplateBlob)
require.NoError(t, err)
dec := wire.NewDecoder(bytes.NewReader(blobBytes))
block := wire.DecodeBlock(dec)
require.NoError(t, dec.Err())
t.Logf("template: height=%d, major=%d, timestamp=%d, txs=%d",
tmpl.Height, block.MajorVersion, block.Timestamp, len(block.TxHashes))
// Compute header mining hash.
headerHash := HeaderMiningHash(&block)
t.Logf("header mining hash: %s", hex.EncodeToString(headerHash[:]))
// Verify the header hash is non-zero.
assert.False(t, headerHash == [32]byte{})
}