Skip to content

Commit

Permalink
tests(coinjoin): update CoinJoinSelectorTest with simulated fully mix…
Browse files Browse the repository at this point in the history
…ed coins
  • Loading branch information
HashEngineering committed Aug 24, 2023
1 parent 04ee10c commit 98fe7cb
Showing 1 changed file with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,20 @@ public void selectable() {
txCoinJoin.getConfidence().setConfidenceType(TransactionConfidence.ConfidenceType.BUILDING);
walletEx.addWalletTransaction(new WalletTransaction(WalletTransaction.Pool.UNSPENT, txCoinJoin));

assertTrue(coinSelector.shouldSelect(txCoinJoin));

Transaction txNotCoinJoin = new Transaction(UNITTEST);
txNotCoinJoin.addOutput(COIN, key);
txCoinJoin.getConfidence().setConfidenceType(TransactionConfidence.ConfidenceType.BUILDING);

assertFalse(coinSelector.shouldSelect(txNotCoinJoin));
// mix for the max number of required rounds to make sure that the coinselecter chooses the transaction
int requiredRounds = CoinJoinClientOptions.getRounds() + CoinJoinClientOptions.getRandomRounds();
Transaction lastTxCoinJoin = txCoinJoin;
for (int i = 1; i < requiredRounds; ++i) {
Transaction txNextCoinJoin = new Transaction(UNITTEST);
txNextCoinJoin.addInput(lastTxCoinJoin.getOutput(0));
txNextCoinJoin.addOutput(CoinJoin.getSmallestDenomination(), (DeterministicKey) walletEx.getCoinJoin().freshReceiveKey());
txNextCoinJoin.getConfidence().setConfidenceType(TransactionConfidence.ConfidenceType.BUILDING);
walletEx.addWalletTransaction(new WalletTransaction(WalletTransaction.Pool.UNSPENT, txNextCoinJoin));
lastTxCoinJoin = txNextCoinJoin;
}

assertTrue(coinSelector.shouldSelect(lastTxCoinJoin));
// txDenomination is mixed zero rounds, so it should not be selected
assertFalse(coinSelector.shouldSelect(txDemonination));
}
}

0 comments on commit 98fe7cb

Please sign in to comment.