2026-02-21 01:04:59 +00:00
|
|
|
//go:build !integration
|
|
|
|
|
|
|
|
|
|
package consensus
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"testing"
|
|
|
|
|
|
2026-03-22 01:49:26 +00:00
|
|
|
"dappco.re/go/core/blockchain/config"
|
|
|
|
|
"dappco.re/go/core/blockchain/types"
|
2026-02-21 01:04:59 +00:00
|
|
|
"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)
|
2026-02-22 00:06:10 +00:00
|
|
|
err := VerifyTransactionSignatures(tx, config.MainnetForks, 100, nil, nil)
|
2026-02-21 01:04:59 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestVerifyTransactionSignatures_Bad_MissingSigs(t *testing.T) {
|
|
|
|
|
tx := validV1Tx()
|
|
|
|
|
tx.Signatures = nil // no signatures
|
2026-02-22 00:06:10 +00:00
|
|
|
err := VerifyTransactionSignatures(tx, config.MainnetForks, 100, nil, nil)
|
2026-02-21 01:04:59 +00:00
|
|
|
assert.Error(t, err)
|
|
|
|
|
}
|
2026-03-16 20:38:28 +00:00
|
|
|
|
|
|
|
|
// --- 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)
|
|
|
|
|
}
|