Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests check sequence verify #1793

Open
wants to merge 12 commits into
base: v0.11.1-dev
Choose a base branch
from
Open
17 changes: 9 additions & 8 deletions domain/consensus/timelock_CLTV_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package consensus_test

import (
"errors"
"testing"

"github.com/kaspanet/kaspad/domain/consensus"
"github.com/kaspanet/kaspad/domain/consensus/model"
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
Expand All @@ -11,7 +13,6 @@ import (
"github.com/kaspanet/kaspad/domain/consensus/utils/testutils"
"github.com/kaspanet/kaspad/domain/consensus/utils/transactionhelper"
"github.com/kaspanet/kaspad/domain/consensus/utils/txscript"
"testing"
)

// TestCheckLockTimeVerifyConditionedByDAAScore verifies that an output locked by the CLTV script is spendable only after
Expand Down Expand Up @@ -74,7 +75,7 @@ func TestCheckLockTimeVerifyConditionedByDAAScore(t *testing.T) {
t.Fatalf("Error creating blockE: %v", err)
}
// Create a transaction that tries to spend the locked output.
transactionThatSpentTheLockedOutput, err := createTransactionThatSpentTheLockedOutput(transactionWithLockedOutput,
transactionThatSpentTheLockedOutput, err := createTransactionThatSpentTheLockedOutputAbsoluteLock(transactionWithLockedOutput,
fees, redeemScriptCLTV, targetDAAScore)
if err != nil {
t.Fatalf("Error creating transactionThatSpentTheLockedOutput: %v", err)
Expand Down Expand Up @@ -182,7 +183,7 @@ func TestCheckLockTimeVerifyConditionedByDAAScoreWithWrongLockTime(t *testing.T)
}
// Create a transaction that tries to spend the locked output.
// Decreased the lock time to get wrong lock time.
transactionWithWrongLockTime, err := createTransactionThatSpentTheLockedOutput(transactionWithLockedOutput,
transactionWithWrongLockTime, err := createTransactionThatSpentTheLockedOutputAbsoluteLock(transactionWithLockedOutput,
fees, redeemScriptCLTV, targetDAAScore-1)
if err != nil {
t.Fatalf("Error creating transactionWithWrongLockTime: %v", err)
Expand Down Expand Up @@ -287,7 +288,7 @@ func TestCheckLockTimeVerifyConditionedByAbsoluteTime(t *testing.T) {
t.Fatalf("Failed getting blockE: %v", err)
}
// Create a transaction that tries to spend the locked output.
transactionThatSpentTheLockedOutput, err := createTransactionThatSpentTheLockedOutput(transactionWithLockedOutput,
transactionThatSpentTheLockedOutput, err := createTransactionThatSpentTheLockedOutputAbsoluteLock(transactionWithLockedOutput,
fees, redeemScriptCLTV, lockTimeTarget)
if err != nil {
t.Fatalf("Error creating transactionThatSpentTheLockedOutput: %v", err)
Expand Down Expand Up @@ -415,7 +416,7 @@ func TestCheckLockTimeVerifyConditionedByAbsoluteTimeWithWrongLockTime(t *testin
t.Fatalf("Failed getting blockE: %v", err)
}
// Create a transaction that tries to spend the locked output.
transactionWithWrongLockTime, err := createTransactionThatSpentTheLockedOutput(transactionWithLockedOutput,
transactionWithWrongLockTime, err := createTransactionThatSpentTheLockedOutputAbsoluteLock(transactionWithLockedOutput,
fees, redeemScriptCLTV, lockTimeTarget-1)
if err != nil {
t.Fatalf("Error creating transactionWithWrongLockTime: %v", err)
Expand Down Expand Up @@ -479,7 +480,7 @@ func createScriptCLTV(absoluteTimeOrDAAScoreTarget uint64) ([]byte, error) {
}

func createTransactionWithLockedOutput(txToSpend *externalapi.DomainTransaction, fee uint64,
scriptPublicKeyCLTV *externalapi.ScriptPublicKey) (*externalapi.DomainTransaction, error) {
scriptPublicKeyCLTVOrCSV *externalapi.ScriptPublicKey) (*externalapi.DomainTransaction, error) {

_, redeemScript := testutils.OpTrueScript()
signatureScript, err := txscript.PayToScriptHashSignatureScript(redeemScript, nil)
Expand All @@ -495,7 +496,7 @@ func createTransactionWithLockedOutput(txToSpend *externalapi.DomainTransaction,
Sequence: constants.MaxTxInSequenceNum,
}
output := &externalapi.DomainTransactionOutput{
ScriptPublicKey: scriptPublicKeyCLTV,
ScriptPublicKey: scriptPublicKeyCLTVOrCSV,
Value: txToSpend.Outputs[0].Value - fee,
}
return &externalapi.DomainTransaction{
Expand All @@ -506,7 +507,7 @@ func createTransactionWithLockedOutput(txToSpend *externalapi.DomainTransaction,
}, nil
}

func createTransactionThatSpentTheLockedOutput(txToSpend *externalapi.DomainTransaction, fee uint64,
func createTransactionThatSpentTheLockedOutputAbsoluteLock(txToSpend *externalapi.DomainTransaction, fee uint64,
redeemScript []byte, lockTime uint64) (*externalapi.DomainTransaction, error) {

signatureScript, err := txscript.PayToScriptHashSignatureScript(redeemScript, []byte{})
Expand Down
Loading