Rebasing ontop of new master, adding property for spendableEscrowTimeoutTxs

This commit is contained in:
Chris Stewart 2017-04-17 15:44:02 -05:00
parent 1bf292852c
commit a338b0f09a
3 changed files with 10 additions and 10 deletions

View file

@ -709,7 +709,7 @@ object EscrowTimeoutScriptPubKey extends ScriptFactory[EscrowTimeoutScriptPubKey
val escrowAsm = asm.slice(1,opElseIndex)
val escrow = Try(MultiSignatureScriptPubKey(escrowAsm))
val timeoutAsm = asm.slice(opElseIndex+1, asm.length-1)
val timeout = Try(CSVScriptPubKey(timeoutAsm))
val timeout = Try(LockTimeScriptPubKey.fromAsm(timeoutAsm))
escrow.isSuccess && timeout.isSuccess
} else false
}

View file

@ -1,10 +1,8 @@
package org.bitcoins.core.crypto
import org.bitcoins.core.gen.TransactionGenerators
import org.bitcoins.core.number.Int64
import org.bitcoins.core.protocol.script.{CLTVScriptPubKey, P2SHScriptPubKey}
import org.bitcoins.core.script.interpreter.ScriptInterpreter
import org.bitcoins.core.script.result.{ScriptErrorUnsatisfiedLocktime, ScriptErrorPushSize, ScriptOk}
import org.bitcoins.core.script.result._
import org.bitcoins.core.script.{PreExecutionScriptProgram, ScriptProgram}
import org.bitcoins.core.util.BitcoinSLogger
import org.scalacheck.{Prop, Properties}
@ -131,18 +129,18 @@ class TransactionSignatureCreatorSpec extends Properties("TransactionSignatureCr
}
property("generate a valid signature for a escrow timeout transaction") =
Prop.forAll(TransactionGenerators.spendableTimeoutEscrowTimeoutTransaction) { txSigComponent: TxSigComponent =>
Prop.forAll(TransactionGenerators.spendableEscrowTimeoutTransaction) { txSigComponent: TxSigComponent =>
val program = ScriptProgram(txSigComponent)
val result = ScriptInterpreter.run(program)
result == ScriptOk
}
property("fail to evaluate a csv escrow timeout transaction due to invalid csv timeout values") = {
Prop.forAll(TransactionGenerators.unspendableEscrowTimeoutTransaction) { txSigComponent: TxSigComponent =>
property("fail to evaluate a csv escrow timeout transaction") = {
Prop.forAll(TransactionGenerators.unspendableMultiSigEscrowTimeoutTransaction) { txSigComponent: TxSigComponent =>
val program = ScriptProgram(txSigComponent)
val result = ScriptInterpreter.run(program)
result == ScriptErrorUnsatisfiedLocktime
result != ScriptOk
}
}

View file

@ -20,6 +20,7 @@ import scala.io.Source
*/
class TransactionTest extends FlatSpec with MustMatchers with BitcoinSLogger {
"Transaction" must "derive the correct txid from the transaction contents" in {
//https://btc.blockr.io/api/v1/tx/raw/cddda897b0e9322937ee1f4fd5d6147d60f04a0f4d3b461e4f87066ac3918f2a
@ -65,17 +66,19 @@ class TransactionTest extends FlatSpec with MustMatchers with BitcoinSLogger {
it must "read all of the tx_valid.json's contents and return ScriptOk" in {
val source = Source.fromURL(getClass.getResource("/tx_valid.json"))
//use this to represent a single test case from script_valid.json
/* val lines =
/*val lines =
"""
|[ [[["0000000000000000000000000000000000000000000000000000000000000100", 0, "0x60 0x14 0x4c9c3dfac4207d5d8cb89df5722cb3d712385e3f", 1000]],
| "010000000100010000000000000000000000000000000000000000000000000000000000000000000000ffffffff01e803000000000000015100000000", "P2SH,WITNESS"]
|]
""".stripMargin*/
val lines = try source.getLines.filterNot(_.isEmpty).map(_.trim) mkString "\n" finally source.close()
val json = lines.parseJson
val testCasesOpt : Seq[Option[CoreTransactionTestCase]] = json.convertTo[Seq[Option[CoreTransactionTestCase]]]
@ -121,7 +124,6 @@ class TransactionTest extends FlatSpec with MustMatchers with BitcoinSLogger {
}
case None => ScriptProgram(tx,scriptPubKey,UInt32(inputIndex),testCase.flags)
}
withClue(testCase.raw + " input index: " + inputIndex) {
ScriptInterpreter.run(program) must equal (ScriptOk)
}