Adding more unit tests for parsing p2sh inputs and outputs from byte arrays

This commit is contained in:
Chris Stewart 2016-01-11 09:56:27 -06:00
parent fdc502acba
commit 17770f6495
3 changed files with 27 additions and 10 deletions

View File

@ -10,8 +10,9 @@ import scala.annotation.tailrec
* Created by chris on 1/7/16.
*/
trait ScriptParser extends ScalacoinUtil {
/**
* Parses an output script of a transaction
* Parses an asm output script of a transaction
* @param str
* @return
*/
@ -50,7 +51,6 @@ trait ScriptParser extends ScalacoinUtil {
} else loop(t, op :: accum)
case Nil => accum
}
}
loop(bytes, List()).reverse
}

View File

@ -32,10 +32,24 @@ class ScriptParserTest extends FlatSpec with MustMatchers with ScriptParser with
parsedInput must be (TestUtil.p2shInputScriptAsm)
}
it must "parse a p2pkh input script from a byte array to script tokens" in {
/*val byteArray = TestUtil.p2pkhInputScript.getBytes.toList*/
it must "parse a p2pkh output script from a byte array to script tokens" in {
val bytes : List[Byte] = decodeHex(TestUtil.p2pkhOutputScript)
parse(bytes) must be (TestUtil.p2pkhOutputScriptAsm)
}
it must "parse a p2pkh input script from a byte array to script tokens" in {
val bytes = decodeHex(TestUtil.p2pkhInputScript)
parse(bytes) must be (TestUtil.p2pkhInputScriptAsm)
}
it must "parse a p2sh input script from a byte array into script tokens" in {
val bytes = decodeHex(TestUtil.p2shInputScript)
parse(bytes) must be (TestUtil.p2shInputScriptAsm)
}
it must "parse a p2sh outputscript from a byte array into script tokens" in {
val bytes = decodeHex(TestUtil.p2shOutputScript)
parse(bytes) must be (TestUtil.p2shOutputScriptAsm)
}
}

View File

@ -30,16 +30,19 @@ object TestUtil {
val p2pkhOutputScriptAsm = List(OP_DUP,OP_HASH160,ScriptConstantImpl("e2e7c1ab3f807151e832dd1accb3d4f5d7d19b4b"),OP_EQUALVERIFY, OP_CHECKSIG)
//tx id for p2sh inputs/outputs cad1082e674a7bd3bc9ab1bc7804ba8a57523607c876b8eb2cbe645f2b1803d6
val p2shInputScriptNotParsedAsm =
"""0 3045022100884c8a4776f4aa2a70f25f6bc0071929ade0ff4987844347e051e018c267aae402201fcec5dd052e7b01198bb57e1b58696c38ccd9d0b408c55047cac89b47287b4101 3045022100b064d492712a080b726ecf37de2957b783fa411edae33bd13005e62d6a45d02302201b82b632df54cf1204758c2b5a3599f1f9a80da3d508951695bfcf8d2c2cce0f01 522102632178d046673c9729d828cfee388e121f497707f810c131e0d3fc0fe0bd66d62103a0951ec7d3a9da9de171617026442fcd30f34d66100fab539853b43f508787d452ae"""
"0 304402207df6dd8dad22d49c3c83d8031733c32a53719278eb7985d3b35b375d776f84f102207054f9209a1e87d55feafc90aa04c33008e5bae9191da22aeaa16efde96f41f001 512102b022902a0fdd71e831c37e4136c2754a59887be0618fb75336d7ab67e2982ff551ae"
val p2shInputScript = "0047304402207df6dd8dad22d49c3c83d8031733c32a53719278eb7985d3b35b375d776f84f102207054f9209a1e87d55feafc90aa04c33008e5bae9191da22aeaa16efde96f41f00125512102b022902a0fdd71e831c37e4136c2754a59887be0618fb75336d7ab67e2982ff551ae"
val p2shInputScriptAsm = List(
OP_0,
ScriptConstantImpl("3045022100884c8a4776f4aa2a70f25f6bc0071929ade0ff4987844347e051e018c267aae402201fcec5dd052e7b01198bb57e1b58696c38ccd9d0b408c55047cac89b47287b4101"),
ScriptConstantImpl("3045022100b064d492712a080b726ecf37de2957b783fa411edae33bd13005e62d6a45d02302201b82b632df54cf1204758c2b5a3599f1f9a80da3d508951695bfcf8d2c2cce0f01"),
ScriptConstantImpl("522102632178d046673c9729d828cfee388e121f497707f810c131e0d3fc0fe0bd66d62103a0951ec7d3a9da9de171617026442fcd30f34d66100fab539853b43f508787d452ae")
ScriptConstantImpl("304402207df6dd8dad22d49c3c83d8031733c32a53719278eb7985d3b35b375d776f84f102207054f9209a1e87d55feafc90aa04c33008e5bae9191da22aeaa16efde96f41f001"),
ScriptConstantImpl("512102b022902a0fdd71e831c37e4136c2754a59887be0618fb75336d7ab67e2982ff551ae")
)
val p2shOutputScriptNotParsedAsm = "OP_HASH160 8ce5408cfeaddb7ccb2545ded41ef47810945484 OP_EQUAL"
val p2shOutputScriptAsm = List(OP_HASH160, ScriptConstantImpl("8ce5408cfeaddb7ccb2545ded41ef47810945484"), OP_EQUAL)
val p2shOutputScript = "a914eda8ae08b5c9f973f49543e90a7c292367b3337c87"
val p2shOutputScriptNotParsedAsm = "OP_HASH160 eda8ae08b5c9f973f49543e90a7c292367b3337c OP_EQUAL"
val p2shOutputScriptAsm = List(OP_HASH160, ScriptConstantImpl("eda8ae08b5c9f973f49543e90a7c292367b3337c"), OP_EQUAL)
}