mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-08-01 12:31:23 +00:00
Use ArrayList instead of HashSet in DefaultCoinSelector#select. Test
This commit is contained in:
committed by
Mike Hearn
parent
df00b1e27e
commit
552bf3fa4d
@@ -20,7 +20,7 @@ public class DefaultCoinSelector implements CoinSelector {
|
|||||||
@Override
|
@Override
|
||||||
public CoinSelection select(Coin biTarget, List<TransactionOutput> candidates) {
|
public CoinSelection select(Coin biTarget, List<TransactionOutput> candidates) {
|
||||||
long target = biTarget.value;
|
long target = biTarget.value;
|
||||||
HashSet<TransactionOutput> selected = new HashSet<TransactionOutput>();
|
ArrayList<TransactionOutput> selected = new ArrayList<TransactionOutput>();
|
||||||
// Sort the inputs by age*value so we get the highest "coindays" spent.
|
// Sort the inputs by age*value so we get the highest "coindays" spent.
|
||||||
// TODO: Consider changing the wallets internal format to track just outputs and keep them ordered.
|
// TODO: Consider changing the wallets internal format to track just outputs and keep them ordered.
|
||||||
ArrayList<TransactionOutput> sortedOutputs = new ArrayList<TransactionOutput>(candidates);
|
ArrayList<TransactionOutput> sortedOutputs = new ArrayList<TransactionOutput>(candidates);
|
||||||
|
@@ -29,6 +29,7 @@ import org.junit.Test;
|
|||||||
|
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
import static org.bitcoinj.core.Coin.*;
|
import static org.bitcoinj.core.Coin.*;
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
@@ -113,4 +114,22 @@ public class DefaultCoinSelectorTest extends TestWithWallet {
|
|||||||
assertEquals(t1.getOutput(0), candidates.get(1));
|
assertEquals(t1.getOutput(0), candidates.get(1));
|
||||||
assertEquals(t3.getOutput(0), candidates.get(2));
|
assertEquals(t3.getOutput(0), candidates.get(2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void identicalInputs() throws Exception {
|
||||||
|
// Add four outputs to a transaction with same value and destination. Select them all.
|
||||||
|
Transaction t = new Transaction(params);
|
||||||
|
java.util.List<TransactionOutput> outputs = Arrays.asList(
|
||||||
|
new TransactionOutput(params, t, Coin.valueOf(30302787), myAddress),
|
||||||
|
new TransactionOutput(params, t, Coin.valueOf(30302787), myAddress),
|
||||||
|
new TransactionOutput(params, t, Coin.valueOf(30302787), myAddress),
|
||||||
|
new TransactionOutput(params, t, Coin.valueOf(30302787), myAddress)
|
||||||
|
);
|
||||||
|
t.getConfidence().setConfidenceType(TransactionConfidence.ConfidenceType.BUILDING);
|
||||||
|
|
||||||
|
DefaultCoinSelector selector = new DefaultCoinSelector();
|
||||||
|
CoinSelection selection = selector.select(COIN.multiply(2), outputs);
|
||||||
|
|
||||||
|
assertTrue(selection.gathered.size() == 4);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user