Skip to content

Commit 7c1ed40

Browse files
j-konthesimplekid
authored andcommitted
test(dart): make live mint integration test configurable
1 parent a5b2e3b commit 7c1ed40

3 files changed

Lines changed: 64 additions & 22 deletions

File tree

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,9 @@ jobs:
556556
- name: Build native library and generate bindings
557557
run: nix develop -L .#bindings --command just binding-dart
558558
- name: Run Dart tests
559+
env:
560+
CDK_DART_TEST_MINT_URL: https://testnut.cashudevkit.org
561+
CDK_DART_MINT_SETTLEMENT_DELAY_SECONDS: "5"
559562
run: nix develop -L .#bindings --command just test-dart
560563

561564
kotlin-binding-tests:

bindings/dart/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,27 @@ and variables must be configured in the **CDK monorepo** repository settings
7272

7373
Set this under **Settings → Secrets and variables → Actions → Variables**.
7474

75+
## Testing
76+
77+
By default, running tests will skip live mint integration tests to allow offline/local testing:
78+
79+
```bash
80+
dart test
81+
```
82+
83+
To run the live mint integration tests, provide the `CDK_DART_TEST_MINT_URL` environment variable:
84+
85+
```bash
86+
CDK_DART_TEST_MINT_URL=https://testnut.cashudevkit.org dart test
87+
```
88+
89+
If the mint has a slower auto-payment settlement, you can optionally configure the settlement delay (in seconds):
90+
91+
```bash
92+
CDK_DART_TEST_MINT_URL=https://testnut.cashudevkit.org CDK_DART_MINT_SETTLEMENT_DELAY_SECONDS=5 dart test
93+
```
94+
7595
## License
7696

7797
[MIT](https://github.com/cashubtc/cdk/blob/main/LICENSE)
98+

bindings/dart/test/wallet_test.dart

Lines changed: 40 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,23 @@ void main() {
66
late Wallet wallet;
77
late String dbPath;
88

9+
final String mintUrl =
10+
Platform.environment['CDK_DART_TEST_MINT_URL'] ??
11+
'https://dummy-mint-url-for-local-testing.invalid';
12+
final bool runLiveMintTests =
13+
Platform.environment.containsKey('CDK_DART_TEST_MINT_URL') &&
14+
Platform.environment['CDK_DART_TEST_MINT_URL']!.isNotEmpty;
15+
final int settlementDelaySeconds =
16+
int.tryParse(
17+
Platform.environment['CDK_DART_MINT_SETTLEMENT_DELAY_SECONDS'] ?? '',
18+
) ??
19+
3;
20+
921
setUp(() {
1022
final tempDir = Directory.systemTemp;
1123
dbPath = '${tempDir.path}/${DateTime.now().microsecondsSinceEpoch}.sqlite';
1224
wallet = Wallet(
13-
mintUrl: 'https://testnut.cashudevkit.org',
25+
mintUrl: mintUrl,
1426
unit: SatCurrencyUnit(),
1527
mnemonic: generateMnemonic(),
1628
store: SqliteWalletStore(dbPath),
@@ -32,7 +44,7 @@ void main() {
3244

3345
test('in-memory sqlite handles concurrent access', () async {
3446
final memoryWallet = Wallet(
35-
mintUrl: 'https://testnut.cashudevkit.org',
47+
mintUrl: mintUrl,
3648
unit: SatCurrencyUnit(),
3749
mnemonic: generateMnemonic(),
3850
store: SqliteWalletStore(':memory:'),
@@ -52,29 +64,35 @@ void main() {
5264
}
5365
});
5466

55-
test('mint flow', () async {
56-
final quote = await wallet.mintQuote(
57-
paymentMethod: Bolt11PaymentMethod(),
58-
amount: Amount(value: 100),
59-
description: null,
60-
extra: null,
61-
);
67+
test(
68+
'mint flow',
69+
() async {
70+
final quote = await wallet.mintQuote(
71+
paymentMethod: Bolt11PaymentMethod(),
72+
amount: Amount(value: 100),
73+
description: null,
74+
extra: null,
75+
);
6276

63-
expect(quote.id, isNotEmpty);
64-
expect(quote.request, isNotEmpty);
77+
expect(quote.id, isNotEmpty);
78+
expect(quote.request, isNotEmpty);
6579

66-
// testnut pays quotes automatically, wait briefly for payment to settle
67-
await Future.delayed(Duration(seconds: 3));
80+
// testnut pays quotes automatically, wait briefly for payment to settle
81+
await Future.delayed(Duration(seconds: settlementDelaySeconds));
6882

69-
final proofs = await wallet.mint(
70-
quoteId: quote.id,
71-
amountSplitTarget: NoneSplitTarget(),
72-
spendingConditions: null,
73-
);
83+
final proofs = await wallet.mint(
84+
quoteId: quote.id,
85+
amountSplitTarget: NoneSplitTarget(),
86+
spendingConditions: null,
87+
);
7488

75-
expect(proofs, isNotEmpty);
89+
expect(proofs, isNotEmpty);
7690

77-
final balance = await wallet.totalBalance();
78-
expect(balance.value, equals(100));
79-
});
91+
final balance = await wallet.totalBalance();
92+
expect(balance.value, equals(100));
93+
},
94+
skip: !runLiveMintTests
95+
? 'Set CDK_DART_TEST_MINT_URL to run live mint integration tests'
96+
: false,
97+
);
8098
}

0 commit comments

Comments
 (0)