@Test
public void dataDrivenValidTransactions() throws Exception {

    JsonNode json = new ObjectMapper().readTree(new InputStreamReader(getClass().getResourceAsStream(
            "tx_valid.json"), Charsets.UTF_8));
    for (JsonNode test : json) {
        if (test.isArray() && test.size() == 1 && test.get(0).isTextual())
            continue; // This is a comment.
        Transaction transaction = null;
        try {
            Map<TransactionOutPoint, Script> scriptPubKeys = parseScriptPubKeys(test.get(0));
            transaction = PARAMS.getDefaultSerializer().makeTransaction(HEX.decode(test.get(1).asText().toLowerCase()));
            transaction.verify();
            Set<VerifyFlag> verifyFlags = parseVerifyFlags(test.get(2).asText());
            for (int i = 0; i < transaction.getInputs().size(); i++) {
                TransactionInput input = transaction.getInputs().get(i);
                if (input.getOutpoint().getIndex() == 0xffffffffL)
                    input.getOutpoint().setIndex(-1);
                assertTrue(scriptPubKeys.containsKey(input.getOutpoint()));
                input.getScriptSig().correctlySpends(transaction, i, scriptPubKeys.get(input.getOutpoint()),
                        verifyFlags);
            }
        } catch (Exception e) {
            System.err.println(test);
            if (transaction != null)
                System.err.println(transaction);
            throw e;
        }
    }
}