Skip to content

Commit

Permalink
Merge 881d857 into 28ac77b
Browse files Browse the repository at this point in the history
  • Loading branch information
talelbaz authored Jul 12, 2021
2 parents 28ac77b + 881d857 commit 7ade8bb
Show file tree
Hide file tree
Showing 2 changed files with 533 additions and 8 deletions.
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

0 comments on commit 7ade8bb

Please sign in to comment.