ScriptTest: more helpful errors.

This commit is contained in:
Mike Hearn 2013-10-07 18:09:47 +02:00
parent 1f7dd9495e
commit 8beb26c421

View file

@ -295,10 +295,12 @@ public class ScriptTest {
NetworkParameters params = TestNet3Params.get();
// Poor man's (aka. really, really poor) JSON parser (because pulling in a lib for this is probably not overkill)
int lineNum = -1;
List<JSONObject> tx = new ArrayList<JSONObject>(3);
in.read(); // remove first [
StringBuffer buffer = new StringBuffer(1000);
while (in.ready()) {
lineNum++;
String line = in.readLine();
if (line == null || line.equals("")) continue;
buffer.append(line);
@ -308,6 +310,8 @@ public class ScriptTest {
while (tx.size() > 0 && tx.get(0).isList() && tx.get(0).list.size() == 1 && tx.get(0).list.get(0).isString())
tx.remove(0); // ignore last ]
if (isFinished && tx.size() == 1 && tx.get(0).list.size() == 3) {
Transaction transaction = null;
try {
HashMap<TransactionOutPoint, Script> scriptPubKeys = new HashMap<TransactionOutPoint, Script>();
for (JSONObject input : tx.get(0).list.get(0).list) {
String hash = input.list.get(0).string;
@ -318,7 +322,7 @@ public class ScriptTest {
}
byte[] bytes = tx.get(0).list.get(1).string.getBytes(Charset.forName("UTF-8"));
Transaction transaction = new Transaction(params, Hex.decode(bytes));
transaction = new Transaction(params, Hex.decode(bytes));
boolean enforceP2SH = tx.get(0).list.get(2).booleanValue;
assertTrue(tx.get(0).list.get(2).isBoolean());
@ -332,6 +336,12 @@ public class ScriptTest {
input.getScriptSig().correctlySpends(transaction, i, scriptPubKeys.get(input.getOutpoint()), enforceP2SH);
}
tx.clear();
} catch (Exception e) {
System.err.println("Exception processing line " + lineNum + ": " + line);
if (transaction != null)
System.err.println(transaction);
throw e;
}
}
}
in.close();