mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2024-11-20 10:13:26 +01:00
create helper function for generating CLTVTransactions, add documentation to CLTV/CSV transaction-related generator functions
This commit is contained in:
parent
f75c1f8cff
commit
7d0ab4ce54
@ -347,10 +347,11 @@ sealed trait CLTVScriptPubKey extends ScriptPubKey {
|
||||
* The absolute CLTV-LockTime value (i.e. the output will remain unspendable until this timestamp or block height)
|
||||
* @return
|
||||
*/
|
||||
def locktime : UInt32 = {
|
||||
def locktime : ScriptNumber = {
|
||||
val hex = BitcoinSUtil.flipEndianess(asm(1).hex)
|
||||
UInt32(hex)
|
||||
}}
|
||||
ScriptNumber(hex)
|
||||
}
|
||||
}
|
||||
|
||||
object CLTVScriptPubKey extends Factory[CLTVScriptPubKey] {
|
||||
private case class CLTVScriptPubKeyImpl(hex : String) extends CLTVScriptPubKey
|
||||
@ -398,9 +399,9 @@ sealed trait CSVScriptPubKey extends ScriptPubKey {
|
||||
* The relative CSV-LockTime value (i.e. the amount of time the output should remain unspendable)
|
||||
* @return
|
||||
*/
|
||||
def locktime : UInt32 = {
|
||||
def locktime : ScriptNumber = {
|
||||
val hex = BitcoinSUtil.flipEndianess(asm(1).hex)
|
||||
UInt32(hex)
|
||||
ScriptNumber(hex)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -51,19 +51,22 @@ class TransactionSignatureCreatorSpec extends Properties("TransactionSignatureCr
|
||||
}
|
||||
|
||||
property("generate a valid signature for a valid and spendable cltv transaction") =
|
||||
Prop.forAllNoShrink(TransactionGenerators.spendableCLTVTransaction :| "cltv") {
|
||||
case (txSignatureComponent: TransactionSignatureComponent, keys, scriptNumber) =>
|
||||
Prop.forAllNoShrink(TransactionGenerators.spendableCLTVTransaction :| "cltv_spendable") {
|
||||
case (txSignatureComponent: TransactionSignatureComponent, _, scriptNumber) =>
|
||||
//run it through the interpreter
|
||||
require(txSignatureComponent.transaction.lockTime.underlying >= scriptNumber.underlying, "TxLocktime must be satisifed so it should be greater than or equal to " +
|
||||
"the cltv value. Got TxLockTime : " + txSignatureComponent.transaction.lockTime.underlying + " , and cltv Value: " +
|
||||
scriptNumber.underlying)
|
||||
val program = ScriptProgram(txSignatureComponent)
|
||||
val result = ScriptInterpreter.run(program)
|
||||
Seq(ScriptOk).contains(result)
|
||||
}
|
||||
|
||||
property("generate a valid signature for a validly constructed, but NOT spendable cltv transaction") =
|
||||
Prop.forAllNoShrink(TransactionGenerators.unspendableCLTVTransaction :| "cltv") {
|
||||
case (txSignatureComponent: TransactionSignatureComponent, keys, scriptNumber) =>
|
||||
Prop.forAllNoShrink(TransactionGenerators.unspendableCLTVTransaction :| "cltv_unspendable") {
|
||||
case (txSignatureComponent: TransactionSignatureComponent, _, scriptNumber) =>
|
||||
//run it through the interpreter
|
||||
require(txSignatureComponent.transaction.lockTime.underlying < scriptNumber.underlying, "Locktime must not be satisifed so it should be less than " +
|
||||
require(txSignatureComponent.transaction.lockTime.underlying < scriptNumber.underlying, "TxLocktime must not be satisifed so it should be less than " +
|
||||
"the cltv value. Got TxLockTime : " + txSignatureComponent.transaction.lockTime.underlying + " , and cltv Value: " +
|
||||
scriptNumber.underlying)
|
||||
val program = ScriptProgram(txSignatureComponent)
|
||||
|
Loading…
Reference in New Issue
Block a user