Adding equality functionality inside of Bitwise Interpreter

This commit is contained in:
Chris Stewart 2016-01-06 19:13:57 -06:00
parent d3e8f3ee0b
commit 9cbb809650
2 changed files with 41 additions and 0 deletions

View File

@ -0,0 +1,21 @@
package org.scalacoin.script.bitwise
import org.scalacoin.script.ScriptOperation
/**
* Created by chris on 1/6/16.
*/
trait BitwiseInterpreter {
def equal(stack : List[String], script : List[ScriptOperation]) : (List[String], List[ScriptOperation]) = {
require(stack.size > 1, "Stack size must be 2 or more to compare the top two values")
require(script.headOption.isDefined && script.head == OP_EQUAL, "Script operation must be OP_EQUAL")
val newStack = stack match {
case h :: h1 :: t => if (h == h1) "1" :: t else "0" :: t
}
(newStack,script.tail)
}
def equalVerify(stack : Seq[String], script : List[ScriptOperation]) : (Seq[String], Seq[ScriptOperation]) = ???
}

View File

@ -0,0 +1,20 @@
package org.scalacoin.script.bitwise
import org.scalatest.{MustMatchers, FlatSpec}
/**
* Created by chris on 1/6/16.
*/
class BitwiseInterpreterTest extends FlatSpec with MustMatchers with BitwiseInterpreter {
"BitwiseInterpreter" must "evaluate OP_EQUAL" in {
val pubKeyHash = "5238C71458E464D9FF90299ABCA4A1D7B9CB76AB".toLowerCase
val stack = List(pubKeyHash, pubKeyHash)
val script = List(OP_EQUAL)
val (newStack,newScript) = equal(stack,script)
newStack.head.toInt must be (1)
}
}