PeerTest: static import of FakeTxBuilder methods

This commit is contained in:
Sean Gilligan 2022-05-24 16:19:58 -07:00 committed by Andreas Schildbach
parent 8800840e7e
commit 6d70c60bca

View File

@ -56,6 +56,7 @@ import static org.bitcoinj.core.Coin.valueOf;
import static org.bitcoinj.testing.FakeTxBuilder.createFakeBlock;
import static org.bitcoinj.testing.FakeTxBuilder.createFakeTx;
import static org.bitcoinj.testing.FakeTxBuilder.makeSolvedTestBlock;
import static org.bitcoinj.testing.FakeTxBuilder.roundTripTransaction;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
@ -524,7 +525,7 @@ public class PeerTest extends TestWithNetworkConnections {
peer.setDownloadTxDependencies(false);
connect();
// Check that if we request dependency download to be disabled and receive a relevant tx, things work correctly.
Transaction tx = FakeTxBuilder.createFakeTx(UNITTEST, COIN, address);
Transaction tx = createFakeTx(UNITTEST, COIN, address);
final Transaction[] result = new Transaction[1];
wallet.addCoinsReceivedEventListener((wallet, tx1, prevBalance, newBalance) -> result[0] = tx1);
inbound(writeTarget, tx);
@ -547,9 +548,9 @@ public class PeerTest extends TestWithNetworkConnections {
// -> [t7]
// -> [t8]
// The ones in brackets are assumed to be in the chain and are represented only by hashes.
Transaction t2 = FakeTxBuilder.createFakeTx(UNITTEST, COIN, to);
Transaction t2 = createFakeTx(UNITTEST, COIN, to);
Sha256Hash t5hash = t2.getInput(0).getOutpoint().getHash();
Transaction t4 = FakeTxBuilder.createFakeTx(UNITTEST, COIN, new ECKey());
Transaction t4 = createFakeTx(UNITTEST, COIN, new ECKey());
Sha256Hash t6hash = t4.getInput(0).getOutpoint().getHash();
t4.addOutput(COIN, new ECKey());
Transaction t3 = new Transaction(UNITTEST);
@ -563,10 +564,10 @@ public class PeerTest extends TestWithNetworkConnections {
Sha256Hash t8hash = Sha256Hash.wrap("3b801dd82f01d17bbde881687bf72bc62e2faa8ab8133d36fcb8c3abe7459da6");
t1.addInput(new TransactionInput(UNITTEST, t1, new byte[]{}, new TransactionOutPoint(UNITTEST, 1, t8hash)));
t1.addOutput(COIN, to);
t1 = FakeTxBuilder.roundTripTransaction(UNITTEST, t1);
t2 = FakeTxBuilder.roundTripTransaction(UNITTEST, t2);
t3 = FakeTxBuilder.roundTripTransaction(UNITTEST, t3);
t4 = FakeTxBuilder.roundTripTransaction(UNITTEST, t4);
t1 = roundTripTransaction(UNITTEST, t1);
t2 = roundTripTransaction(UNITTEST, t2);
t3 = roundTripTransaction(UNITTEST, t3);
t4 = roundTripTransaction(UNITTEST, t4);
// Announce the first one. Wait for it to be downloaded.
InventoryMessage inv = new InventoryMessage(UNITTEST);
@ -636,15 +637,15 @@ public class PeerTest extends TestWithNetworkConnections {
Transaction t3 = new Transaction(UNITTEST);
t3.addInput(new TransactionInput(UNITTEST, t3, new byte[]{}, new TransactionOutPoint(UNITTEST, 0, t4hash)));
t3.addOutput(COIN, new ECKey());
t3 = FakeTxBuilder.roundTripTransaction(UNITTEST, t3);
t3 = roundTripTransaction(UNITTEST, t3);
Transaction t2 = new Transaction(UNITTEST);
t2.addInput(t3.getOutput(0));
t2.addOutput(COIN, new ECKey());
t2 = FakeTxBuilder.roundTripTransaction(UNITTEST, t2);
t2 = roundTripTransaction(UNITTEST, t2);
Transaction t1 = new Transaction(UNITTEST);
t1.addInput(t2.getOutput(0));
t1.addOutput(COIN, new ECKey());
t1 = FakeTxBuilder.roundTripTransaction(UNITTEST, t1);
t1 = roundTripTransaction(UNITTEST, t1);
// Announce the first one. Wait for it to be downloaded.
InventoryMessage inv = new InventoryMessage(UNITTEST);
@ -686,7 +687,7 @@ public class PeerTest extends TestWithNetworkConnections {
final Transaction[] vtx = new Transaction[1];
wallet.addCoinsReceivedEventListener((wallet1, tx, prevBalance, newBalance) -> vtx[0] = tx);
// Send a normal relevant transaction, it's received correctly.
Transaction t1 = FakeTxBuilder.createFakeTx(UNITTEST, COIN, key);
Transaction t1 = createFakeTx(UNITTEST, COIN, key);
inbound(writeTarget, t1);
GetDataMessage getdata = (GetDataMessage) outbound(writeTarget);
inbound(writeTarget, new NotFoundMessage(UNITTEST, getdata.getItems()));
@ -695,7 +696,7 @@ public class PeerTest extends TestWithNetworkConnections {
assertNotNull(vtx[0]);
vtx[0] = null;
// Send a timelocked transaction, nothing happens.
Transaction t2 = FakeTxBuilder.createFakeTx(UNITTEST, valueOf(2, 0), key);
Transaction t2 = createFakeTx(UNITTEST, valueOf(2, 0), key);
t2.setLockTime(999999);
inbound(writeTarget, t2);
Threading.waitForUserCode();