Fixing issues inside of OP_PUSHDATA, now the script items for OP_PUSHDATA are pushed onto the stack by the ScriptInterpreter

This commit is contained in:
Chris Stewart 2016-02-12 09:02:22 -06:00
parent ee932cd55a
commit 0c486b303b
3 changed files with 20 additions and 44 deletions

View File

@ -26,19 +26,12 @@ trait ConstantInterpreter {
if (bytesToPush == BytesToPushOntoStackImpl(0)) {
ScriptProgramFactory.factory(program, OP_0 :: program.stack, program.script.tail.tail)
} else {
val newStack = program.script(2) :: program.stack
ScriptProgramFactory.factory(program, newStack, program.script.slice(3,program.script.size))
//leave the constant on the script to be pushed onto the stack by the next iteration of script interpreter
//TODO: probably push the script token on the stack here, but it needs to be converted to the
//appropriate type i.e. OP_1 is converted to ScriptNumberImpl(1)
ScriptProgramFactory.factory(program, program.stack, program.script.slice(2,program.script.size))
}
/* val numberOfBytes : Int = Integer.parseInt(program.script(1).hex,16)
if (numberOfBytes == 0) {
//if the number of bytes pushed onto the stack is zero, we push an empty byte vector onto the stack
ScriptProgramFactory.factory(program, OP_0 :: program.stack, program.script.slice(2,program.script.size))
} else {
val slicedScript = program.script.slice(2,program.script.size)
val (newStack,newScript) = opPushData(program.stack,slicedScript,numberOfBytes)
ScriptProgramFactory.factory(program, newStack,newScript)
}*/
}
/**
@ -53,19 +46,11 @@ trait ConstantInterpreter {
if (bytesToPush == BytesToPushOntoStackImpl(0)) {
ScriptProgramFactory.factory(program, OP_0 :: program.stack, program.script.tail.tail)
} else {
val newStack = program.script(2) :: program.stack
ScriptProgramFactory.factory(program, newStack, program.script.slice(3,program.script.size))
//leave the constant on the script to be pushed onto the stack by the next iteration of script interpreter
//TODO: probably push the script token on the stack here, but it needs to be converted to the
//appropriate type i.e. OP_1 is converted to ScriptNumberImpl(1)
ScriptProgramFactory.factory(program, program.stack, program.script.slice(2,program.script.size))
}
/* val reversedHex = ScalacoinUtil.littleEndianToBigEndian(program.script(1).hex)
val numberOfBytes : Int = Integer.parseInt(reversedHex,16)
if (numberOfBytes == 0) {
//if the number of bytes pushed onto the stack is zero, we push an empty byte vector onto the stack
ScriptProgramFactory.factory(program, OP_0 :: program.stack, program.script.slice(2,program.script.size))
} else {
val slicedScript = program.script.slice(2,program.script.size)
val (newStack,newScript) = opPushData(program.stack,slicedScript,numberOfBytes)
ScriptProgramFactory.factory(program, newStack, newScript)
}*/
}
/**
@ -81,19 +66,11 @@ trait ConstantInterpreter {
if (bytesToPush == BytesToPushOntoStackImpl(0)) {
ScriptProgramFactory.factory(program, OP_0 :: program.stack, program.script.tail.tail)
} else {
val newStack = program.script(2) :: program.stack
ScriptProgramFactory.factory(program, newStack, program.script.slice(3,program.script.size))
//leave the constant on the script to be pushed onto the stack by the next iteration of script interpreter
//TODO: probably push the script token on the stack here, but it needs to be converted to the
//appropriate type i.e. OP_1 is converted to ScriptNumberImpl(1)
ScriptProgramFactory.factory(program, program.stack, program.script.slice(2,program.script.size))
}
/* val reversedHex = ScalacoinUtil.littleEndianToBigEndian(program.script(1).hex)
val numberOfBytes : Int = Integer.parseInt(reversedHex,16)
if (numberOfBytes == 0) {
//if the number of bytes pushed onto the stack is zero, we push an empty byte vector onto the stack
ScriptProgramFactory.factory(program, OP_0 :: program.stack, program.script.slice(2,program.script.size))
} else {
val slicedScript = program.script.slice(2,program.script.size)
val (newStack,newScript) = opPushData(program.stack,slicedScript,numberOfBytes)
ScriptProgramFactory.factory(program, newStack,newScript)
}*/
}

View File

@ -16,8 +16,7 @@ class ConstantInterpreterTest extends FlatSpec with MustMatchers with ConstantIn
val program = ScriptProgramFactory.factory(TestUtil.testProgram, stack,script)
val newProgram = opPushData1(program)
newProgram.stack must be (List(ScriptNumberImpl(7)))
newProgram.script must be (List(OP_7,OP_EQUAL))
newProgram.script must be (List(ScriptNumberImpl(7), OP_7,OP_EQUAL))
}
it must "interpret OP_PUSHDATA2 correctly" in {
@ -25,8 +24,8 @@ class ConstantInterpreterTest extends FlatSpec with MustMatchers with ConstantIn
val script = List(OP_PUSHDATA2, ScriptConstantImpl("0100"), ScriptNumberImpl(8), OP_8, OP_EQUAL)
val program = ScriptProgramFactory.factory(TestUtil.testProgram, stack,script)
val newProgram = opPushData2(program)
newProgram.stack must be (List(ScriptNumberImpl(8)))
newProgram.script must be (List(OP_8,OP_EQUAL))
newProgram.stack must be (List())
newProgram.script must be (List(ScriptNumberImpl(8), OP_8,OP_EQUAL))
}
it must "interpret OP_PUSHDATA4 correctly" in {

View File

@ -62,14 +62,14 @@ 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 =
//use this to represent a single test case from script_valid.json
/* val lines =
"""
|
|[["0x4c 0x00","0 EQUAL", "P2SH,STRICTENC"]]
""".stripMargin
|[["0x4c 0 0x01 1", "HASH160 0x14 0xda1745e9b549bd0bfa1a569971c77eba30cd5a4b EQUAL", "P2SH,STRICTENC"]]
""".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