Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/building/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ the app's own `zcash-ffi` library, against a private regtest chain. It starts
a `zebrad` and a `lightwalletd` on free local ports, in a temporary directory,
and stops them when it ends. It covers a new wallet, receiving, a send with a
memo from broadcast to confirmation, spending received funds, a restore from
the recovery phrase and birthday, and a payment to a Sapling address. Run it
through the wrapper, on a Linux
or macOS host with an app configured with `ZCASH` enabled:
the recovery phrase and birthday, a payment to a Sapling address, and moving
Sapling and transparent funds to Ironwood. Run it through the wrapper, on a
Linux or macOS host with an app configured with `ZCASH` enabled:

```sh
bash scripts/zcash_e2e_test.sh # host desktop
Expand Down
88 changes: 88 additions & 0 deletions integration_test/zcash/zcash_regtest_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import 'package:stackwallet/wallets/crypto_currency/crypto_currency.dart';
import 'package:stackwallet/wallets/isar/models/wallet_info.dart';
import 'package:stackwallet/wallets/models/tx_data.dart';
import 'package:stackwallet/wallets/wallet/impl/zcash_wallet.dart';
import 'package:stackwallet/wallets/wallet/intermediate/zcash_send.dart';
import 'package:stackwallet/wallets/wallet/intermediate/zcash_wallet_state_controller.dart';
import 'package:stackwallet/wallets/wallet/wallet.dart';
import 'package:zcash_flutter/zcash_flutter.dart' as zcash;
Expand Down Expand Up @@ -354,6 +355,93 @@ void main() {
expect(bob.info.cachedBalance.total, bobBefore.total + zec(amount ~/ 4));
expect(bob.info.cachedBalance.spendable, bobBefore.spendable);
expect(received(await row(bob, saplingTxid)), zec(amount ~/ 4));

// Bob moves the Sapling funds to Ironwood, where a send can spend
// them, once they are below the anchor of a move.
expect((await bob.movableFunds())[ZcashMovablePool.sapling], zec(0));
await chain.mine(zcashAnchorDepth);
await sync(bob);
expect(
(await bob.movableFunds())[ZcashMovablePool.sapling],
zec(amount ~/ 4),
);
final fromSapling = await bob.prepareMoveToIronwood(
ZcashMovablePool.sapling,
);
final saplingMoved = fromSapling.recipients!.single.amount;
expect(fromSapling.recipients!.single.address, await address(bob));
// The move leaves one zatoshi of Sapling change.
expect(saplingMoved + fromSapling.fee!, zec(amount ~/ 4 - 1));
final saplingMoveTxid = (await bob.confirmSend(txData: fromSapling))
.txid!;
await chain.waitForMempool(saplingMoveTxid);
// The notes are held by the move until it is mined.
expect((await bob.movableFunds())[ZcashMovablePool.sapling], zec(0));
await chain.mine(1);
await sync(bob);
expect(
bob.info.cachedBalance.total,
bobBefore.total + zec(amount ~/ 4) - fromSapling.fee!,
);
// What was moved is pending until it is below the anchor of a send.
expect(bob.info.cachedBalance.spendable, bobBefore.spendable);
expect(bob.info.cachedBalance.pendingSpendable, saplingMoved);
await chain.mine(zcashAnchorDepth);
await sync(bob);
expect(
bob.info.cachedBalance.spendable,
bobBefore.spendable + saplingMoved,
);
final saplingMove = await row(bob, saplingMoveTxid);
expect(saplingMove.type, TransactionType.sentToSelf);
expect(received(saplingMove), saplingMoved);
expect(fee(saplingMove), fromSapling.fee);

// A payment to the transparent receiver of Bob's address, which he
// moves to Ironwood as well.
final bobTransparent = zcash
.inventoryUnifiedAddressReceivers(
address: await address(bob),
network: zcash.ZcashNetwork.regtest,
)
.receivers
.firstWhere(
(receiver) => receiver.kind == zcash.ZcashAddressReceiverType.p2pkh,
)
.address!;
await sync(alice);
final toTransparent = await alice.prepareSend(
txData: payment(bobTransparent, zec(amount ~/ 8)),
);
final transparentTxid = (await alice.confirmSend(txData: toTransparent))
.txid!;
await chain.waitForMempool(transparentTxid);
await chain.mine(1);
await sync(bob);
final bobShielded = bob.info.cachedBalance.spendable;
expect(
(await bob.movableFunds())[ZcashMovablePool.transparent],
zec(amount ~/ 8),
);
final fromTransparent = await bob.prepareMoveToIronwood(
ZcashMovablePool.transparent,
);
final transparentMoved = fromTransparent.recipients!.single.amount;
expect(transparentMoved + fromTransparent.fee!, zec(amount ~/ 8));
final transparentMoveTxid = (await bob.confirmSend(
txData: fromTransparent,
)).txid!;
await chain.waitForMempool(transparentMoveTxid);
// The coins are held by the move until it is mined.
expect((await bob.movableFunds())[ZcashMovablePool.transparent], zec(0));
await chain.mine(1 + zcashAnchorDepth);
await sync(bob);
expect(bob.info.cachedBalance.spendable, bobShielded + transparentMoved);
expect((await bob.movableFunds())[ZcashMovablePool.transparent], zec(0));
final transparentMove = await row(bob, transparentMoveTxid);
expect(transparentMove.type, TransactionType.sentToSelf);
expect(received(transparentMove), transparentMoved);
expect(fee(transparentMove), fromTransparent.fee);
});
}, timeout: const Timeout(Duration(minutes: 15)));
}
Loading