go-blockchain/consensus/verify_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

95 lines
2.8 KiB
Go

//go:build !integration
package consensus
import (
"testing"
"dappco.re/go/core/blockchain/config"
"dappco.re/go/core/blockchain/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestVerifyTransactionSignatures_Good_Coinbase(t *testing.T) {
// Coinbase transactions have no signatures to verify.
tx := validMinerTx(100)
err := VerifyTransactionSignatures(tx, config.MainnetForks, 100, nil, nil)
require.NoError(t, err)
}
func TestVerifyTransactionSignatures_Bad_MissingSigs(t *testing.T) {
tx := validV1Tx()
tx.Signatures = nil // no signatures
err := VerifyTransactionSignatures(tx, config.MainnetForks, 100, nil, nil)
assert.Error(t, err)
}
// --- HTLC signature verification tests (Task 9) ---
func TestVerifyV1Signatures_MixedHTLC_Good(t *testing.T) {
// Structural check only (getRingOutputs = nil).
tx := &types.Transaction{
Version: types.VersionPreHF4,
Vin: []types.TxInput{
types.TxInputToKey{Amount: 100, KeyImage: types.KeyImage{1}},
types.TxInputHTLC{Amount: 50, KeyImage: types.KeyImage{2}},
},
Signatures: [][]types.Signature{
{{1}}, // sig for TxInputToKey
{{2}}, // sig for TxInputHTLC
},
}
err := VerifyTransactionSignatures(tx, config.MainnetForks, 20000, nil, nil)
require.NoError(t, err)
}
func TestVerifyV1Signatures_MixedHTLC_Bad(t *testing.T) {
// Wrong signature count.
tx := &types.Transaction{
Version: types.VersionPreHF4,
Vin: []types.TxInput{
types.TxInputToKey{Amount: 100, KeyImage: types.KeyImage{1}},
types.TxInputHTLC{Amount: 50, KeyImage: types.KeyImage{2}},
},
Signatures: [][]types.Signature{
{{1}}, // only 1 sig for 2 ring inputs
},
}
err := VerifyTransactionSignatures(tx, config.MainnetForks, 20000, nil, nil)
assert.Error(t, err)
assert.Contains(t, err.Error(), "signature count")
}
func TestVerifyV1Signatures_HTLCOnly_Good(t *testing.T) {
// Transaction with only HTLC inputs.
tx := &types.Transaction{
Version: types.VersionPreHF4,
Vin: []types.TxInput{
types.TxInputHTLC{Amount: 50, KeyImage: types.KeyImage{1}},
types.TxInputHTLC{Amount: 30, KeyImage: types.KeyImage{2}},
},
Signatures: [][]types.Signature{
{{1}},
{{2}},
},
}
err := VerifyTransactionSignatures(tx, config.MainnetForks, 20000, nil, nil)
require.NoError(t, err)
}
func TestVerifyV1Signatures_MultisigSkipped_Good(t *testing.T) {
// Multisig inputs do not participate in NLSAG signatures.
tx := &types.Transaction{
Version: types.VersionPreHF4,
Vin: []types.TxInput{
types.TxInputToKey{Amount: 100, KeyImage: types.KeyImage{1}},
types.TxInputMultisig{Amount: 50},
},
Signatures: [][]types.Signature{
{{1}}, // only 1 sig, multisig is not counted
},
}
err := VerifyTransactionSignatures(tx, config.MainnetForks, 20000, nil, nil)
require.NoError(t, err)
}