FakeTxBuilder: don't create unnecessary transaction in makeSolvedTestBlock()

This commit is contained in:
Andreas Schildbach 2023-04-02 17:29:41 +02:00
parent 16da4f8ccf
commit c309994e99
2 changed files with 4 additions and 4 deletions

View File

@ -41,6 +41,7 @@ import org.bitcoinj.script.ScriptBuilder;
import org.bitcoinj.store.BlockStore;
import org.bitcoinj.store.BlockStoreException;
import javax.annotation.Nullable;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
@ -329,11 +330,10 @@ public class FakeTxBuilder {
}
public static Block makeSolvedTestBlock(Block prev, Transaction... transactions) throws BlockStoreException {
Address to = randomAddress(prev.getParams());
return makeSolvedTestBlock(prev, to, transactions);
return makeSolvedTestBlock(prev, null, transactions);
}
public static Block makeSolvedTestBlock(Block prev, Address to, Transaction... transactions) throws BlockStoreException {
public static Block makeSolvedTestBlock(Block prev, @Nullable Address to, Transaction... transactions) throws BlockStoreException {
Block b = prev.createNextBlock(to);
// Coinbase tx already exists.
for (Transaction tx : transactions) {

View File

@ -820,7 +820,7 @@ public class PeerGroupTest extends TestWithPeerGroup {
for (ECKey key1 : keys) {
Address addr = key1.toAddress(ScriptType.P2PKH, UNITTEST.network());
Block next = FakeTxBuilder.makeSolvedTestBlock(prev, FakeTxBuilder.createFakeTx(UNITTEST, Coin.FIFTY_COINS, addr));
expectedBalance = expectedBalance.add(next.getTransactions().get(2).getOutput(0).getValue());
expectedBalance = expectedBalance.add(next.getTransactions().get(1).getOutput(0).getValue());
blocks.add(next);
prev = next;
}