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
22 changes: 14 additions & 8 deletions lib/models/isar/models/blockchain_data/v2/transaction_v2.dart
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,10 @@ class TransactionV2 {
if (isConfirmed(currentChainHeight, minConfirms, minCoinbaseConfirms)) {
return "Received";
} else {
if ((onChainNote == null && numberOfMessages == 1) |
(onChainNote != null && numberOfMessages == 2)) {
// The wallet stores one message entry per participant, with or
// without a note. A receive has both entries once it is signed,
// and the sender still has to finalize.
if (numberOfMessages == 2) {
return "Receiving (waiting for sender)";
} else if ((numberOfMessages ?? 0) > 1) {
return "Receiving (waiting for confirmations)"; // TODO test if the sender still has to open again after the receiver has 2 messages present, ie. sender->receiver->sender->node (yes) vs. sender->receiver->node (no)
Expand All @@ -290,8 +292,9 @@ class TransactionV2 {
if (isConfirmed(currentChainHeight, minConfirms, minCoinbaseConfirms)) {
return "Sent (confirmed)";
} else {
if ((onChainNote == null && numberOfMessages == 1) |
(onChainNote != null && numberOfMessages == 2)) {
// A send has only its own entry until it is finalized with the
// receiver's response.
if (numberOfMessages == 1) {
return "Sending (waiting for receiver)";
} else if ((numberOfMessages ?? 0) > 1) {
return "Sending (waiting for confirmations)";
Expand All @@ -313,8 +316,10 @@ class TransactionV2 {
if (isConfirmed(currentChainHeight, minConfirms, minCoinbaseConfirms)) {
return "Received";
} else {
if ((onChainNote == null && numberOfMessages == 1) |
(onChainNote != null && numberOfMessages == 2)) {
// The wallet stores one message entry per participant, with or
// without a note. A receive has both entries once it is signed,
// and the sender still has to finalize.
if (numberOfMessages == 2) {
return "Receiving (waiting for sender)";
} else if ((numberOfMessages ?? 0) > 1) {
return "Receiving (waiting for confirmations)"; // TODO test if the sender still has to open again after the receiver has 2 messages present, ie. sender->receiver->sender->node (yes) vs. sender->receiver->node (no)
Expand All @@ -326,8 +331,9 @@ class TransactionV2 {
if (isConfirmed(currentChainHeight, minConfirms, minCoinbaseConfirms)) {
return "Sent (confirmed)";
} else {
if ((onChainNote == null && numberOfMessages == 1) |
(onChainNote != null && numberOfMessages == 2)) {
// A send has only its own entry until it is finalized with the
// receiver's response.
if (numberOfMessages == 1) {
return "Sending (waiting for receiver)";
} else if ((numberOfMessages ?? 0) > 1) {
return "Sending (waiting for confirmations)";
Expand Down
124 changes: 124 additions & 0 deletions test/models/transaction_v2_mimblewimble_status_label_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
import 'dart:convert';

import 'package:flutter_test/flutter_test.dart';
import 'package:stackwallet/models/isar/models/blockchain_data/transaction.dart';
import 'package:stackwallet/models/isar/models/blockchain_data/v2/transaction_v2.dart';

String _label({
required String coinKey,
required TransactionType type,
required int? messages,
String? note,
int? height,
bool cancelled = false,
}) {
final tx = TransactionV2(
walletId: 'wallet',
blockHash: null,
hash: 'hash',
txid: 'txid',
timestamp: 1,
height: height,
inputs: const [],
outputs: const [],
version: 1,
type: type,
subType: TransactionSubType.none,
otherData: jsonEncode({
coinKey: true,
TxV2OdKeys.slateId: 'slate',
TxV2OdKeys.numberOfMessages: messages,
TxV2OdKeys.onChainNote: note,
TxV2OdKeys.isCancelled: cancelled,
}),
);
return tx.statusLabel(
currentChainHeight: 100,
minConfirms: 10,
minCoinbaseConfirms: 10,
);
}

void main() {
for (final coinKey in [
TxV2OdKeys.isEpiccashTransaction,
TxV2OdKeys.isMimblewimblecoinTransaction,
]) {
group(coinKey, () {
// A note changes the text of a message entry and never the number of
// entries, so every label has to be the same with and without one.
for (final note in [null, 'thanks for lunch']) {
final withNote = note == null ? 'without a note' : 'with a note';

test('a send $withNote waits for the receiver until finalized', () {
expect(
_label(
coinKey: coinKey,
type: TransactionType.outgoing,
messages: 1,
note: note,
),
'Sending (waiting for receiver)',
);
});

test('a finalized send $withNote waits for confirmations', () {
expect(
_label(
coinKey: coinKey,
type: TransactionType.outgoing,
messages: 2,
note: note,
),
'Sending (waiting for confirmations)',
);
});

test('a signed receive $withNote waits for the sender', () {
expect(
_label(
coinKey: coinKey,
type: TransactionType.incoming,
messages: 2,
note: note,
),
'Receiving (waiting for sender)',
);
});
}

test('confirmed transactions say so', () {
expect(
_label(
coinKey: coinKey,
type: TransactionType.outgoing,
messages: 2,
height: 50,
),
'Sent (confirmed)',
);
expect(
_label(
coinKey: coinKey,
type: TransactionType.incoming,
messages: 2,
height: 50,
),
'Received',
);
});

test('a cancelled send says so', () {
expect(
_label(
coinKey: coinKey,
type: TransactionType.outgoing,
messages: 1,
cancelled: true,
),
'Cancelled',
);
});
});
}
}
Loading