private static void checkFile(File f) { try { TransactionPack tp = TransactionPack.unpack(Do.read(f), true); if (tp.isReconstructed()) { report("file " + f + " is a single contract"); } else { report("file " + f + " is a transaction pack"); } System.out.println(); checkContract(tp.getContract()); } catch (Quantiser.QuantiserException e) { addError("QUANTIZER_COST_LIMIT", f.getPath(), e.toString()); } catch (IOException e) { addError("READ_ERROR", f.getPath(), e.toString()); } catch (Exception e) { addError("UNKNOWN_ERROR", f.getPath(), e.toString()); } }
addError("QUANTIZER_COST_LIMIT", fileName, e.toString());
/** * Check bytes is contract. And if bytes is, check contract for errors. Print errors if found. * * @param data - data to check. * * @return true if bytes is Contract and Contract is valid. */ private static Boolean checkBytesIsValidContract(byte[] data) { try { Contract contract = new Contract(data); if (!contract.isOk()) { reporter.message("The capsule is not sealed"); contract.getErrors().forEach(e -> reporter.error(e.getError().toString(), e.getObjectName(), e.getMessage())); } checkContract(contract); } catch (RuntimeException e) { addError(Errors.BAD_VALUE.name(), "byte[] data", e.getMessage()); return false; } catch (Quantiser.QuantiserException e) { addError("QUANTIZER_COST_LIMIT", "", e.toString()); } catch (IOException e) { addError(Errors.BAD_VALUE.name(), "byte[] data", e.getMessage()); return false; } return true; }
@Test public void calculateProcessingCostSimpleBreak() throws Exception { // Should create contract, sign and seal it. Then while calculating cost should break. // should repeat contract processing procedure on the Node // (Contract.fromPackedTransaction() -> Contract(byte[], TransactionPack) -> Contract.check()) Contract contract = createCoin100apiv3(); contract.addSignerKeyFromFile(PRIVATE_KEY_PATH); sealCheckTrace(contract, true); // Check 4096 bits signature (8) + // Register a version (20) int costShouldBe = 28; boolean exceptionThrown = false; try { processContractAsItWillBeOnTheNode(contract, 10); } catch (Quantiser.QuantiserException e) { System.out.println("Thrown correct exception: " + e.toString()); exceptionThrown = true; } assertEquals(true, exceptionThrown); }