@Test
public void pledgePerfectSize() throws Exception {

    // Grab a Project, and a wallet with some outputs in it, then form a pledge that does not require any changes
    // to the wallets output set.
    WalletTestObjects objects = new WalletTestObjects(() -> new PledgingWallet(UnitTestParams.get()));
    PledgingWallet wallet = (PledgingWallet) objects.wallet;
    objects.sendAmounts(100_000, 200_000, 300_000);
    assertEquals(600_000, objects.wallet.getBalance().longValue());
    boolean[] flags = new boolean[2];
    wallet.addEventListener(new AbstractWalletEventListener() {
        @Override
        public void onChange() {
            flags[0] = true;
        }
        @Override
        public void onCoinsSent(Wallet wallet, Transaction tx, Coin prevBalance, Coin newBalance) {
            flags[1] = true;
        }
    }, Threading.SAME_THREAD);
    Project project = new Project(makeProject(wallet, 100_000));
    PledgingWallet.PendingPledge pledge = wallet.createPledge(project, 100_000, null);
    assertNull(pledge.dependency);
    assertNotNull(pledge.pledge);
    final LHProtos.Pledge commit = pledge.commit(true);
    assertEquals(500_000, objects.wallet.getBalance().longValue());
    assertTrue(flags[0]);
    assertTrue(flags[1]);
    Transaction contract = project.completeContract(ImmutableSet.of(commit));
    assertEquals(contract.getInput(0).duplicateDetached(), pledge.pledge.getInput(0).duplicateDetached());
    List<TransactionOutput> outputs = ImmutableList.of(checkNotNull(pledge.pledge.getInput(0).getConnectedOutput()).duplicateDetached());
    project.verifyPledge(outpoint -> CompletableFuture.completedFuture(outputs), commit).get();
}