### Question:
DefaultRiskAnalysis implements RiskAnalysis { @Override public Result analyze() { checkState(!analyzed); analyzed = true; Result result = analyzeIsFinal(); if (result != null && result != Result.OK) return result; return analyzeIsStandard(); } private  DefaultRiskAnalysis(Wallet wallet, Transaction tx, List<Transaction> dependencies); @Override Result analyze(); static RuleViolation isStandard(Transaction tx); static RuleViolation isOutputStandard(TransactionOutput output); static RuleViolation isInputStandard(TransactionInput input); @Nullable Transaction getNonStandard(); @Nullable Transaction getNonFinal(); @Override String toString(); static Analyzer FACTORY; }### Answer:
@Test public void selfCreatedAreNotRisky() { Transaction tx = new Transaction(MAINNET); tx.addInput(MAINNET.getGenesisBlock().getTransactions().get(0).getOutput(0)).setSequenceNumber(1); tx.addOutput(COIN, key1); tx.setLockTime(TIMESTAMP + 86400); { DefaultRiskAnalysis analysis = DefaultRiskAnalysis.FACTORY.create(wallet, tx, NO_DEPS); assertEquals(RiskAnalysis.Result.NON_FINAL, analysis.analyze()); } tx.getConfidence().setSource(TransactionConfidence.Source.SELF); { DefaultRiskAnalysis analysis = DefaultRiskAnalysis.FACTORY.create(wallet, tx, NO_DEPS); assertEquals(RiskAnalysis.Result.OK, analysis.analyze()); } }
@Test public void nonStandardDust() { Transaction standardTx = new Transaction(MAINNET); standardTx.addInput(MAINNET.getGenesisBlock().getTransactions().get(0).getOutput(0)); standardTx.addOutput(COIN, key1); assertEquals(RiskAnalysis.Result.OK, DefaultRiskAnalysis.FACTORY.create(wallet, standardTx, NO_DEPS).analyze()); Transaction dustTx = new Transaction(MAINNET); dustTx.addInput(MAINNET.getGenesisBlock().getTransactions().get(0).getOutput(0)); dustTx.addOutput(Coin.SATOSHI, key1); assertEquals(RiskAnalysis.Result.NON_STANDARD, DefaultRiskAnalysis.FACTORY.create(wallet, dustTx, NO_DEPS).analyze()); Transaction edgeCaseTx = new Transaction(MAINNET); edgeCaseTx.addInput(MAINNET.getGenesisBlock().getTransactions().get(0).getOutput(0)); Coin dustThreshold = new TransactionOutput(MAINNET, null, Coin.COIN, key1).getMinNonDustValue(); edgeCaseTx.addOutput(dustThreshold, key1); assertEquals(RiskAnalysis.Result.OK, DefaultRiskAnalysis.FACTORY.create(wallet, edgeCaseTx, NO_DEPS).analyze()); }
@Test public void standardOutputs() throws Exception { Transaction tx = new Transaction(MAINNET); tx.addInput(MAINNET.getGenesisBlock().getTransactions().get(0).getOutput(0)); tx.addOutput(Coin.CENT, ScriptBuilder.createP2PKHOutputScript(key1)); tx.addOutput(Coin.CENT, ScriptBuilder.createP2PKOutputScript(key1)); tx.addOutput(Coin.CENT, ScriptBuilder.createP2PKOutputScript(key1)); ImmutableList<ECKey> keys = ImmutableList.of(key1, new ECKey()); tx.addOutput(Coin.CENT, ScriptBuilder.createMultiSigOutputScript(1, keys)); tx.addOutput(Coin.CENT, ScriptBuilder.createMultiSigOutputScript(2, keys)); tx.addOutput(Coin.CENT, ScriptBuilder.createP2SHOutputScript(1, keys)); tx.addOutput(Coin.CENT, ScriptBuilder.createOpReturnScript("hi there".getBytes())); assertEquals(RiskAnalysis.Result.OK, DefaultRiskAnalysis.FACTORY.create(wallet, tx, NO_DEPS).analyze()); }