Exemple #1
0
  @Test
  public void dataDrivenInvalidScripts() throws Exception {
    BufferedReader in =
        new BufferedReader(
            new InputStreamReader(
                getClass().getResourceAsStream("script_invalid.json"), Charset.forName("UTF-8")));

    NetworkParameters params = TestNet3Params.get();

    // Poor man's JSON parser (because pulling in a lib for this is overkill)
    String script = "";
    while (in.ready()) {
      String line = in.readLine();
      if (line == null || line.equals("")) continue;
      script += line;
      if (line.equals("]") && script.equals("]") && !in.ready()) break; // ignore last ]
      if (line.trim().endsWith("],") || line.trim().equals("]")) {
        String[] scripts = script.split(",");
        try {
          scripts[0] = scripts[0].replaceAll("[\"\\[\\]]", "").trim();
          scripts[1] = scripts[1].replaceAll("[\"\\[\\]]", "").trim();
          Script scriptSig = parseScriptString(scripts[0]);
          Script scriptPubKey = parseScriptString(scripts[1]);

          scriptSig.correctlySpends(new Transaction(params), 0, scriptPubKey, true);
          System.err.println("scriptSig: " + scripts[0]);
          System.err.println("scriptPubKey: " + scripts[1]);
          System.err.flush();
          fail();
        } catch (VerificationException e) {
          // Expected.
        }
        script = "";
      }
    }
    in.close();
  }