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 6683c95 commit 04ee10c
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@

package org.bitcoinj.coinjoin;

import org.bitcoinj.core.Sha256Hash;
import org.bitcoinj.core.Transaction;
import org.bitcoinj.core.TransactionConfidence;
import org.bitcoinj.crypto.DeterministicKey;
import org.bitcoinj.script.Script;
import org.bitcoinj.testing.TestWithWallet;
import org.bitcoinj.wallet.DerivationPathFactory;
import org.bitcoinj.wallet.KeyChain;
import org.bitcoinj.wallet.WalletEx;
import org.bitcoinj.wallet.WalletTransaction;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
Expand All @@ -39,11 +41,13 @@ public class CoinJoinCoinSelectorTest extends TestWithWallet {
public void setUp() throws Exception {
super.setUp();
walletEx = WalletEx.fromSeed(wallet.getParams(), wallet.getKeyChainSeed(), Script.ScriptType.P2PKH);
CoinJoinClientOptions.setRounds(1);
}

@After
@Override
public void tearDown() throws Exception {
CoinJoinClientOptions.setRounds(CoinJoinConstants.DEFAULT_COINJOIN_ROUNDS);
super.tearDown();
}

Expand All @@ -54,14 +58,22 @@ public void selectable() {

CoinJoinCoinSelector coinSelector = new CoinJoinCoinSelector(walletEx);

Transaction txDeposit = new Transaction(UNITTEST);
txDeposit.addInput(Sha256Hash.ZERO_HASH, 0, new Script(new byte[0]));
txDeposit.addOutput(COIN, wallet.freshAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS));
walletEx.addWalletTransaction(new WalletTransaction(WalletTransaction.Pool.SPENT, txDeposit));

Transaction txCoinJoin;
Transaction txDemonination = new Transaction(UNITTEST);
txDemonination.addInput(txDeposit.getOutput(0));
txDemonination.addOutput(CoinJoin.getSmallestDenomination(), (DeterministicKey) walletEx.getCoinJoin().freshReceiveKey());
walletEx.addWalletTransaction(new WalletTransaction(WalletTransaction.Pool.SPENT, txDemonination));

txCoinJoin = new Transaction(UNITTEST);
txCoinJoin.addInput(txDemonination.getOutput(0));
txCoinJoin.addOutput(CoinJoin.getSmallestDenomination(), (DeterministicKey) walletEx.getCoinJoin().freshReceiveKey());
txCoinJoin.getConfidence().setConfidenceType(TransactionConfidence.ConfidenceType.BUILDING);
walletEx.addWalletTransaction(new WalletTransaction(WalletTransaction.Pool.UNSPENT, txCoinJoin));

assertTrue(coinSelector.shouldSelect(txCoinJoin));

Expand Down

0 comments on commit 04ee10c

Please sign in to comment.