Skip to content
Merged
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
63 changes: 63 additions & 0 deletions test/models/dfx_transaction_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:realunit_wallet/models/dfx_transaction.dart';
import 'package:realunit_wallet/models/transaction.dart';
import 'package:realunit_wallet/packages/utils/default_assets.dart';

void main() {
DfxTransaction build({
int dfxId = 7,
String? inputTxId,
String? outputTxId,
double? rate,
}) =>
DfxTransaction(
dfxId: dfxId,
rate: rate,
inputTxId: inputTxId,
outputTxId: outputTxId,
height: 1,
txId: '0xabc',
chainId: realUnitAsset.chainId,
senderAddress: '0x0',
receiverAddress: '0x0',
amount: BigInt.from(123),
asset: realUnitAsset,
type: TransactionTypes.tokenTransfer,
note: null,
data: null,
timestamp: DateTime.utc(2026, 1, 1),
);

group('$DfxTransaction', () {
test('is a Transaction subclass and inherits the base fields', () {
final tx = build();

expect(tx, isA<Transaction>());
expect(tx.txId, '0xabc');
expect(tx.amount, BigInt.from(123));
expect(tx.asset, realUnitAsset);
});

test('carries the four DFX-only fields', () {
final tx = build(
dfxId: 42,
rate: 1.05,
inputTxId: '0xin',
outputTxId: '0xout',
);

expect(tx.dfxId, 42);
expect(tx.rate, 1.05);
expect(tx.inputTxId, '0xin');
expect(tx.outputTxId, '0xout');
});

test('rate / inputTxId / outputTxId are optional', () {
final tx = build();

expect(tx.rate, isNull);
expect(tx.inputTxId, isNull);
expect(tx.outputTxId, isNull);
});
});
}
35 changes: 35 additions & 0 deletions test/styles/currency_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:realunit_wallet/styles/currency.dart';

void main() {
group('$Currency', () {
test('eur and chf have the wire codes "EUR" and "CHF"', () {
expect(Currency.eur.code, 'EUR');
expect(Currency.chf.code, 'CHF');
});

test('values has exactly the two entries', () {
expect(Currency.values, hasLength(2));
expect(Currency.values, contains(Currency.eur));
expect(Currency.values, contains(Currency.chf));
});

group('fromCode', () {
test('resolves "EUR" and "CHF"', () {
expect(Currency.fromCode('EUR'), Currency.eur);
expect(Currency.fromCode('CHF'), Currency.chf);
});

test('is case-insensitive on the input', () {
expect(Currency.fromCode('eur'), Currency.eur);
expect(Currency.fromCode('chf'), Currency.chf);
expect(Currency.fromCode('Eur'), Currency.eur);
});

test('throws StateError on an unknown code', () {
expect(() => Currency.fromCode('USD'), throwsA(isA<StateError>()));
expect(() => Currency.fromCode(''), throwsA(isA<StateError>()));
});
});
});
}
39 changes: 39 additions & 0 deletions test/styles/language_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:realunit_wallet/styles/language.dart';

void main() {
group('$Language', () {
test('en and de carry their wire codes and flag asset paths', () {
expect(Language.en.code, 'en');
expect(Language.en.imagePath, 'assets/images/flags/gbr.png');
expect(Language.de.code, 'de');
expect(Language.de.imagePath, 'assets/images/flags/deu.png');
});

test('values has exactly the two entries', () {
expect(Language.values, hasLength(2));
expect(Language.values, contains(Language.en));
expect(Language.values, contains(Language.de));
});

group('fromCode', () {
test('resolves "en" and "de"', () {
expect(Language.fromCode('en'), Language.en);
expect(Language.fromCode('de'), Language.de);
});

test('is case-SENSITIVE on the input (matches the production lookup)', () {
// Documents the current behaviour: codes are lowercase on the wire,
// and the lookup does NOT lowercase the input. Different from
// Currency.fromCode which normalises with toUpperCase.
expect(() => Language.fromCode('EN'), throwsA(isA<StateError>()));
expect(() => Language.fromCode('De'), throwsA(isA<StateError>()));
});

test('throws StateError on an unknown code', () {
expect(() => Language.fromCode('fr'), throwsA(isA<StateError>()));
expect(() => Language.fromCode(''), throwsA(isA<StateError>()));
});
});
});
}
Loading