mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-02-15 11:45:51 +00:00
WalletTest: Split coinSelection_coinTimesDepth() from feeSolverAndCoinSelectionTests2().
This commit is contained in:
parent
2748b35181
commit
34f2fad07d
@ -2402,59 +2402,62 @@ public class WalletTest extends TestWithWallet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void feeSolverAndCoinSelectionTests2() throws Exception {
|
public void coinSelection_coinTimesDepth() throws Exception {
|
||||||
Transaction tx5 = sendMoneyToWallet(AbstractBlockChain.NewBlockType.BEST_CHAIN, CENT);
|
Transaction txCent = sendMoneyToWallet(AbstractBlockChain.NewBlockType.BEST_CHAIN, CENT);
|
||||||
assertEquals(CENT, wallet.getBalance());
|
|
||||||
|
|
||||||
// Now test coin selection properly selects coin*depth
|
|
||||||
for (int i = 0; i < 197; i++)
|
for (int i = 0; i < 197; i++)
|
||||||
sendMoneyToWallet(AbstractBlockChain.NewBlockType.BEST_CHAIN);
|
sendMoneyToWallet(AbstractBlockChain.NewBlockType.BEST_CHAIN);
|
||||||
|
Transaction txCoin = sendMoneyToWallet(AbstractBlockChain.NewBlockType.BEST_CHAIN, COIN);
|
||||||
|
assertEquals(COIN.add(CENT), wallet.getBalance());
|
||||||
|
|
||||||
Transaction tx6 = sendMoneyToWallet(AbstractBlockChain.NewBlockType.BEST_CHAIN, COIN);
|
assertTrue(txCent.getOutput(0).isMine(wallet));
|
||||||
assertTrue(tx5.getOutput(0).isMine(wallet));
|
assertTrue(txCent.getOutput(0).isAvailableForSpending());
|
||||||
assertTrue(tx5.getOutput(0).isAvailableForSpending());
|
assertEquals(199, txCent.getConfidence().getDepthInBlocks());
|
||||||
assertEquals(199, tx5.getConfidence().getDepthInBlocks());
|
assertTrue(txCoin.getOutput(0).isMine(wallet));
|
||||||
assertTrue(tx6.getOutput(0).isMine(wallet));
|
assertTrue(txCoin.getOutput(0).isAvailableForSpending());
|
||||||
assertTrue(tx6.getOutput(0).isAvailableForSpending());
|
assertEquals(1, txCoin.getConfidence().getDepthInBlocks());
|
||||||
assertEquals(1, tx6.getConfidence().getDepthInBlocks());
|
// txCent has higher coin*depth than txCoin...
|
||||||
|
assertTrue(txCent.getOutput(0).getValue().multiply(txCent.getConfidence().getDepthInBlocks())
|
||||||
// tx5 has higher coin*depth than tx6...
|
.isGreaterThan(txCoin.getOutput(0).getValue().multiply(txCoin.getConfidence().getDepthInBlocks())));
|
||||||
assertTrue(tx5.getOutput(0).getValue().multiply(tx5.getConfidence().getDepthInBlocks())
|
// ...so txCent should be selected
|
||||||
.isGreaterThan(tx6.getOutput(0).getValue().multiply(tx6.getConfidence().getDepthInBlocks())));
|
Transaction spend1 = wallet.createSend(OTHER_ADDRESS, CENT);
|
||||||
// ...so tx5 should be selected
|
assertEquals(1, spend1.getInputs().size());
|
||||||
Transaction spend12 = wallet.createSend(OTHER_ADDRESS, CENT);
|
assertEquals(CENT, spend1.getInput(0).getValue());
|
||||||
assertEquals(1, spend12.getInputs().size());
|
|
||||||
assertEquals(CENT, spend12.getInput(0).getValue());
|
|
||||||
|
|
||||||
sendMoneyToWallet(AbstractBlockChain.NewBlockType.BEST_CHAIN);
|
sendMoneyToWallet(AbstractBlockChain.NewBlockType.BEST_CHAIN);
|
||||||
assertTrue(tx5.getOutput(0).isMine(wallet));
|
assertTrue(txCent.getOutput(0).isMine(wallet));
|
||||||
assertTrue(tx5.getOutput(0).isAvailableForSpending());
|
assertTrue(txCent.getOutput(0).isAvailableForSpending());
|
||||||
assertEquals(200, tx5.getConfidence().getDepthInBlocks());
|
assertEquals(200, txCent.getConfidence().getDepthInBlocks());
|
||||||
assertTrue(tx6.getOutput(0).isMine(wallet));
|
assertTrue(txCoin.getOutput(0).isMine(wallet));
|
||||||
assertTrue(tx6.getOutput(0).isAvailableForSpending());
|
assertTrue(txCoin.getOutput(0).isAvailableForSpending());
|
||||||
assertEquals(2, tx6.getConfidence().getDepthInBlocks());
|
assertEquals(2, txCoin.getConfidence().getDepthInBlocks());
|
||||||
// Now tx5 and tx6 have exactly the same coin*depth...
|
// Now txCent and txCoin have exactly the same coin*depth...
|
||||||
assertEquals(tx5.getOutput(0).getValue().multiply(tx5.getConfidence().getDepthInBlocks()),
|
assertEquals(txCent.getOutput(0).getValue().multiply(txCent.getConfidence().getDepthInBlocks()),
|
||||||
tx6.getOutput(0).getValue().multiply(tx6.getConfidence().getDepthInBlocks()));
|
txCoin.getOutput(0).getValue().multiply(txCoin.getConfidence().getDepthInBlocks()));
|
||||||
// ...so the larger tx6 should be selected
|
// ...so the larger txCoin should be selected
|
||||||
Transaction spend13 = wallet.createSend(OTHER_ADDRESS, COIN);
|
Transaction spend2 = wallet.createSend(OTHER_ADDRESS, COIN);
|
||||||
assertEquals(1, spend13.getInputs().size());
|
assertEquals(1, spend2.getInputs().size());
|
||||||
assertEquals(COIN, spend13.getInput(0).getValue());
|
assertEquals(COIN, spend2.getInput(0).getValue());
|
||||||
|
|
||||||
sendMoneyToWallet(AbstractBlockChain.NewBlockType.BEST_CHAIN);
|
sendMoneyToWallet(AbstractBlockChain.NewBlockType.BEST_CHAIN);
|
||||||
assertTrue(tx5.getOutput(0).isMine(wallet));
|
assertTrue(txCent.getOutput(0).isMine(wallet));
|
||||||
assertTrue(tx5.getOutput(0).isAvailableForSpending());
|
assertTrue(txCent.getOutput(0).isAvailableForSpending());
|
||||||
assertEquals(201, tx5.getConfidence().getDepthInBlocks());
|
assertEquals(201, txCent.getConfidence().getDepthInBlocks());
|
||||||
assertTrue(tx6.getOutput(0).isMine(wallet));
|
assertTrue(txCoin.getOutput(0).isMine(wallet));
|
||||||
assertTrue(tx6.getOutput(0).isAvailableForSpending());
|
assertTrue(txCoin.getOutput(0).isAvailableForSpending());
|
||||||
assertEquals(3, tx6.getConfidence().getDepthInBlocks());
|
assertEquals(3, txCoin.getConfidence().getDepthInBlocks());
|
||||||
// Now tx5 has lower coin*depth than tx6...
|
// Now txCent has lower coin*depth than txCoin...
|
||||||
assertTrue(tx5.getOutput(0).getValue().multiply(tx5.getConfidence().getDepthInBlocks())
|
assertTrue(txCent.getOutput(0).getValue().multiply(txCent.getConfidence().getDepthInBlocks())
|
||||||
.isLessThan(tx6.getOutput(0).getValue().multiply(tx6.getConfidence().getDepthInBlocks())));
|
.isLessThan(txCoin.getOutput(0).getValue().multiply(txCoin.getConfidence().getDepthInBlocks())));
|
||||||
// ...so tx6 should be selected
|
// ...so txCoin should be selected
|
||||||
Transaction spend14 = wallet.createSend(OTHER_ADDRESS, COIN);
|
Transaction spend3 = wallet.createSend(OTHER_ADDRESS, COIN);
|
||||||
assertEquals(1, spend14.getInputs().size());
|
assertEquals(1, spend3.getInputs().size());
|
||||||
assertEquals(COIN, spend14.getInput(0).getValue());
|
assertEquals(COIN, spend3.getInput(0).getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void feeSolverAndCoinSelectionTests2() throws Exception {
|
||||||
|
Transaction tx5 = sendMoneyToWallet(AbstractBlockChain.NewBlockType.BEST_CHAIN, CENT);
|
||||||
|
sendMoneyToWallet(AbstractBlockChain.NewBlockType.BEST_CHAIN, COIN);
|
||||||
|
|
||||||
// Now test feePerKb
|
// Now test feePerKb
|
||||||
SendRequest request15 = SendRequest.to(OTHER_ADDRESS, CENT);
|
SendRequest request15 = SendRequest.to(OTHER_ADDRESS, CENT);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user