mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-03-03 10:46:42 +01:00
Adding unused op codes for tests in bitcoin core's scrip_valid.json tests
This commit is contained in:
parent
8039a72dfc
commit
a16f732981
7 changed files with 31 additions and 6 deletions
|
@ -38,12 +38,12 @@ trait ControlOperationsInterpreter {
|
|||
//means that we have an else statement which needs to be executed
|
||||
if (indexes._1.isDefined) {
|
||||
//removes the OP_ELSE as well
|
||||
val newScript = script.slice(0,indexes._1.get+1)
|
||||
val newScript = script.tail.slice(indexes._1.get+1,script.size)
|
||||
(stack.tail,newScript)
|
||||
} else {
|
||||
//means that we do not have an OP_ELSE statement
|
||||
//removes the OP_ENDIF as well
|
||||
val newScript = script.slice(0,indexes._2.get+1)
|
||||
val newScript = script.tail.slice(indexes._2.get+1,script.size)
|
||||
(stack.tail,newScript)
|
||||
}
|
||||
case _ => (stack.tail,script.tail)
|
||||
|
|
|
@ -32,7 +32,7 @@ trait ScriptInterpreter extends CryptoInterpreter with StackInterpreter with Con
|
|||
@tailrec
|
||||
def loop(scripts : (List[ScriptToken], List[ScriptToken])) : Boolean = {
|
||||
val (stack,script) = (scripts._1, scripts._2)
|
||||
logger.debug("Stack: " +stack)
|
||||
logger.debug("Stack: " + stack)
|
||||
logger.debug("Script: " + script)
|
||||
script match {
|
||||
//stack operations
|
||||
|
|
|
@ -84,4 +84,6 @@ case object OP_NOP10 extends ReservedOperation {
|
|||
override def opCode = 185
|
||||
}
|
||||
|
||||
case class UndefinedOP_NOP(opCode : Int) extends ReservedOperation
|
||||
|
||||
|
||||
|
|
|
@ -48,4 +48,9 @@ class ScriptOperationFactoryTest extends FlatSpec with MustMatchers {
|
|||
result.get must be (ScriptNumberImpl(2))
|
||||
}
|
||||
|
||||
it must "find undefined op codes"in {
|
||||
val result = ScriptOperationFactory.fromHex("ba")
|
||||
result.isDefined must be (true)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package org.scalacoin.script.control
|
||||
|
||||
import org.scalacoin.script.constant._
|
||||
import org.scalacoin.script.reserved.OP_RESERVED
|
||||
import org.scalatest.{MustMatchers, FlatSpec}
|
||||
|
||||
/**
|
||||
|
@ -43,6 +44,7 @@ class ControlOperationsInterpreterTest extends FlatSpec with MustMatchers with C
|
|||
findOP_ENDIF(l) must be (Some(0))
|
||||
findOP_ENDIF(List(OP_IF,OP_ELSE,OP_ENDIF,OP_ENDIF)) must be (Some(2))
|
||||
findOP_ENDIF(List(OP_0,OP_1,OP_2)) must be (None)
|
||||
findOP_ENDIF(List(OP_IF, OP_RESERVED, OP_ENDIF, OP_1)) must be (Some(2))
|
||||
|
||||
}
|
||||
|
||||
|
@ -57,4 +59,13 @@ class ControlOperationsInterpreterTest extends FlatSpec with MustMatchers with C
|
|||
findIndexesOP_ELSE_OP_ENDIF(List(OP_IF, OP_ELSE,OP_ENDIF, OP_IF,OP_ELSE,OP_ENDIF)) must be (Some(1),Some(2))
|
||||
findIndexesOP_ELSE_OP_ENDIF(List(OP_IF,OP_IF)) must be (None,None)
|
||||
}
|
||||
|
||||
|
||||
it must "evaluate an OP_IF correctly" in {
|
||||
val stack = List(OP_0)
|
||||
val script = List(OP_IF, OP_RESERVED, OP_ENDIF, OP_1)
|
||||
val (newStack,newScript) = opIf(stack,script)
|
||||
newStack.isEmpty must be (true)
|
||||
newScript must be (List(OP_1))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,13 +36,13 @@ class ScriptInterpreterTest extends FlatSpec with MustMatchers with ScriptInterp
|
|||
val source = scala.io.Source.fromFile("src/test/scala/org/scalacoin/script/interpreter/script_valid.json")
|
||||
|
||||
//use this to represent a single test case from script_valid.json
|
||||
val lines =
|
||||
/* val lines =
|
||||
"""
|
||||
|
|
||||
|[["0", "IF 0x50 ENDIF 1", "P2SH,STRICTENC", "0x50 is reserved (ok if not executed)"]]
|
||||
""".stripMargin
|
||||
""".stripMargin*/
|
||||
|
||||
//val lines = try source.getLines.filterNot(_.isEmpty).map(_.trim) mkString "\n" finally source.close()
|
||||
val lines = try source.getLines.filterNot(_.isEmpty).map(_.trim) mkString "\n" finally source.close()
|
||||
val json = lines.parseJson
|
||||
val testCasesOpt : Seq[Option[CoreTestCase]] = json.convertTo[Seq[Option[CoreTestCase]]]
|
||||
val testCases : Seq[CoreTestCase] = testCasesOpt.flatten
|
||||
|
|
|
@ -11,4 +11,11 @@ class ReservedOperationsFactoryTest extends FlatSpec with MustMatchers {
|
|||
ReservedOperationFactory.fromHex("50") must be (Some(OP_RESERVED))
|
||||
ReservedOperationFactory.fromHex("62") must be (Some(OP_VER))
|
||||
}
|
||||
|
||||
it must "find OP_NOP1 from its hex value" in {
|
||||
ReservedOperationFactory.fromHex("b0") must be (Some(OP_NOP1))
|
||||
}
|
||||
it must "find an undefined operation from its hex value" in {
|
||||
ReservedOperationFactory.fromHex("ba").isDefined must be (true)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue