mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2024-11-20 10:13:26 +01:00
Adding equality functionality inside of Bitwise Interpreter
This commit is contained in:
parent
d3e8f3ee0b
commit
9cbb809650
@ -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]) = ???
|
||||
}
|
@ -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)
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user