miden-testing 0.15.2

Miden protocol testing tools
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
//! Tests for the `Pausable` storage component, `PausableManager` admin wrapper, and the
//! pause integration (mint / burn / transfer / metadata setters).
//!
//! A single `pause()` call by an authorized sender blocks mint, burn, transfer, and metadata
//! updates uniformly until a matching `unpause()` call.

extern crate alloc;

use alloc::string::String;

use miden_processor::crypto::random::RandomCoin;
use miden_protocol::Word;
use miden_protocol::account::{Account, AccountBuilder, AccountId, AccountIdVersion, AccountType};
use miden_protocol::asset::{Asset, AssetAmount, AssetCallbackFlag, FungibleAsset};
use miden_protocol::errors::MasmError;
use miden_protocol::note::{Note, NoteTag, NoteType};
use miden_protocol::transaction::RawOutputNote;
use miden_protocol::utils::sync::LazyLock;
use miden_standards::account::access::AccessControl;
use miden_standards::account::access::pausable::{PausableManager, PausableStorage};
use miden_standards::account::faucets::{FungibleFaucet, TokenName};
use miden_standards::account::policies::{
    BurnPolicyConfig,
    MintPolicyConfig,
    PolicyRegistration,
    TokenPolicyManager,
    TransferPolicy,
};
use miden_standards::testing::note::NoteBuilder;
use miden_testing::{
    AccountState,
    Auth,
    MockChain,
    MockChainBuilder,
    assert_transaction_executor_error,
};

const ERR_PAUSABLE_IS_PAUSED: MasmError = MasmError::from_static_str("the contract is paused");

const ERR_SENDER_NOT_OWNER: MasmError = MasmError::from_static_str("note sender is not the owner");

static OWNER_ID: LazyLock<AccountId> = LazyLock::new(|| test_account_id(11));
static NON_OWNER_ID: LazyLock<AccountId> = LazyLock::new(|| test_account_id(99));

fn test_account_id(seed: u8) -> AccountId {
    AccountId::dummy([seed; 15], AccountIdVersion::Version1, AccountType::Private)
}

// FAUCET BUILDER
// ================================================================================================

/// Builds a fungible faucet with `Pausable + PausableManager + Ownable2Step(owner)`. Pause /
/// unpause are gated by the owner via `Authority::OwnerControlled` (installed automatically by
/// `AccessControl::Ownable2Step`).
fn add_faucet_with_pause(
    builder: &mut MockChainBuilder,
    owner: AccountId,
) -> anyhow::Result<Account> {
    let faucet = FungibleFaucet::builder()
        .name(TokenName::new("SYM")?)
        .symbol("SYM".try_into()?)
        .decimals(8)
        .max_supply(AssetAmount::new(1_000_000)?)
        .build()?;

    let account_builder = AccountBuilder::new([43u8; 32])
        .account_type(AccountType::Public)
        .with_component(faucet)
        .with_components(AccessControl::Ownable2Step { owner })
        .with_component(PausableManager);

    builder.add_account_from_builder(Auth::IncrNonce, account_builder, AccountState::Exists)
}

// NOTE BUILDERS
// ================================================================================================

fn build_note(sender: AccountId, code: impl Into<String>) -> anyhow::Result<Note> {
    let seed: [u32; 4] = rand::random();
    let mut rng = RandomCoin::new(Word::from(seed));
    Ok(NoteBuilder::new(sender, &mut rng)
        .note_type(NoteType::Private)
        .code(code.into())
        .build()?)
}

/// Builds an owner-authored note that calls `pausable::manager::pause`.
fn build_pause_note(sender: AccountId) -> anyhow::Result<Note> {
    build_note(
        sender,
        r#"
        use miden::standards::access::pausable::manager

        @note_script
        pub proc main
            repeat.16 push.0 end
            call.manager::pause
            dropw dropw dropw dropw
        end
        "#,
    )
}

/// Builds an owner-authored note that calls `pausable::manager::unpause`.
fn build_unpause_note(sender: AccountId) -> anyhow::Result<Note> {
    build_note(
        sender,
        r#"
        use miden::standards::access::pausable::manager

        @note_script
        pub proc main
            repeat.16 push.0 end
            call.manager::unpause
            dropw dropw dropw dropw
        end
        "#,
    )
}

async fn execute_note_on_faucet(
    mock_chain: &mut MockChain,
    faucet_id: AccountId,
    note: &Note,
) -> anyhow::Result<()> {
    let executed = mock_chain
        .build_tx_context(faucet_id, &[note.id()], &[])?
        .build()?
        .execute()
        .await?;
    mock_chain.add_pending_executed_transaction(&executed)?;
    mock_chain.prove_next_block()?;
    Ok(())
}

// TESTS — PAUSABLE MANAGER (Authority dispatch)
// ================================================================================================

#[tokio::test]
async fn pausable_manager_pause_succeeds_when_sender_is_owner() -> anyhow::Result<()> {
    let mut builder = MockChain::builder();
    let faucet = add_faucet_with_pause(&mut builder, *OWNER_ID)?;

    let pause_note = build_pause_note(*OWNER_ID)?;
    builder.add_output_note(RawOutputNote::Full(pause_note.clone()));

    let mut mock_chain = builder.build()?;
    mock_chain.prove_next_block()?;

    execute_note_on_faucet(&mut mock_chain, faucet.id(), &pause_note).await?;

    Ok(())
}

#[tokio::test]
async fn pausable_manager_pause_fails_when_sender_not_owner() -> anyhow::Result<()> {
    let mut builder = MockChain::builder();
    let faucet = add_faucet_with_pause(&mut builder, *OWNER_ID)?;

    // Authority::OwnerControlled (installed by AccessControl::Ownable2Step) rejects non-owner
    // senders for any procedure that calls `exec.authority::assert_authorized`.
    let attacker_note = build_pause_note(*NON_OWNER_ID)?;
    builder.add_output_note(RawOutputNote::Full(attacker_note.clone()));

    let mut mock_chain = builder.build()?;
    mock_chain.prove_next_block()?;

    let result = mock_chain
        .build_tx_context(faucet.id(), &[attacker_note.id()], &[])?
        .build()?
        .execute()
        .await;

    assert_transaction_executor_error!(result, ERR_SENDER_NOT_OWNER);

    Ok(())
}

#[tokio::test]
async fn pausable_manager_unpause_fails_when_sender_not_owner() -> anyhow::Result<()> {
    let mut builder = MockChain::builder();
    let faucet = add_faucet_with_pause(&mut builder, *OWNER_ID)?;

    // Pre-stage both notes: legitimate owner pause + attacker unpause.
    let pause_note = build_pause_note(*OWNER_ID)?;
    let attacker_unpause_note = build_unpause_note(*NON_OWNER_ID)?;
    builder.add_output_note(RawOutputNote::Full(pause_note.clone()));
    builder.add_output_note(RawOutputNote::Full(attacker_unpause_note.clone()));

    let mut mock_chain = builder.build()?;
    mock_chain.prove_next_block()?;

    execute_note_on_faucet(&mut mock_chain, faucet.id(), &pause_note).await?;

    let result = mock_chain
        .build_tx_context(faucet.id(), &[attacker_unpause_note.id()], &[])?
        .build()?
        .execute()
        .await;

    assert_transaction_executor_error!(result, ERR_SENDER_NOT_OWNER);

    Ok(())
}

#[tokio::test]
async fn pausable_manager_pause_then_unpause_then_pause_again() -> anyhow::Result<()> {
    let mut builder = MockChain::builder();
    let faucet = add_faucet_with_pause(&mut builder, *OWNER_ID)?;

    let pause_note_1 = build_pause_note(*OWNER_ID)?;
    let unpause_note = build_unpause_note(*OWNER_ID)?;
    let pause_note_2 = build_pause_note(*OWNER_ID)?;
    builder.add_output_note(RawOutputNote::Full(pause_note_1.clone()));
    builder.add_output_note(RawOutputNote::Full(unpause_note.clone()));
    builder.add_output_note(RawOutputNote::Full(pause_note_2.clone()));

    let mut mock_chain = builder.build()?;
    mock_chain.prove_next_block()?;

    execute_note_on_faucet(&mut mock_chain, faucet.id(), &pause_note_1).await?;
    execute_note_on_faucet(&mut mock_chain, faucet.id(), &unpause_note).await?;
    execute_note_on_faucet(&mut mock_chain, faucet.id(), &pause_note_2).await?;

    Ok(())
}

#[tokio::test]
async fn pausable_manager_unpause_while_unpaused_is_noop() -> anyhow::Result<()> {
    let mut builder = MockChain::builder();
    let faucet = add_faucet_with_pause(&mut builder, *OWNER_ID)?;

    let unpause_note = build_unpause_note(*OWNER_ID)?;
    builder.add_output_note(RawOutputNote::Full(unpause_note.clone()));

    let mut mock_chain = builder.build()?;
    mock_chain.prove_next_block()?;

    execute_note_on_faucet(&mut mock_chain, faucet.id(), &unpause_note).await?;

    Ok(())
}

#[tokio::test]
async fn pausable_manager_pause_while_paused_is_noop() -> anyhow::Result<()> {
    let mut builder = MockChain::builder();
    let faucet = add_faucet_with_pause(&mut builder, *OWNER_ID)?;

    let pause_note_1 = build_pause_note(*OWNER_ID)?;
    let pause_note_2 = build_pause_note(*OWNER_ID)?;
    builder.add_output_note(RawOutputNote::Full(pause_note_1.clone()));
    builder.add_output_note(RawOutputNote::Full(pause_note_2.clone()));

    let mut mock_chain = builder.build()?;
    mock_chain.prove_next_block()?;

    execute_note_on_faucet(&mut mock_chain, faucet.id(), &pause_note_1).await?;
    execute_note_on_faucet(&mut mock_chain, faucet.id(), &pause_note_2).await?;

    Ok(())
}

// SANITY TESTS — PausableStorage helper
// ================================================================================================

#[test]
fn pausable_storage_default_is_unpaused() {
    let storage = PausableStorage::default();
    assert!(!storage.state());
    assert_eq!(storage.to_word(), Word::default());
}

#[test]
fn pausable_storage_paused_writes_canonical_word() {
    let storage = PausableStorage::paused();
    assert!(storage.state());
    assert_eq!(storage.to_word(), Word::from([1u32, 0, 0, 0]));
}

// TESTS — PAUSE (mint / burn / transfer policies)
// ================================================================================================
fn add_faucet_with_pause_and_policies(
    builder: &mut MockChainBuilder,
    owner: AccountId,
) -> anyhow::Result<Account> {
    let faucet = FungibleFaucet::builder()
        .name(TokenName::new("SYM")?)
        .symbol("SYM".try_into()?)
        .decimals(8)
        .max_supply(AssetAmount::new(1_000_000)?)
        .build()?;

    let account_builder = AccountBuilder::new([44u8; 32])
        .account_type(AccountType::Public)
        .with_component(faucet)
        .with_components(AccessControl::Ownable2Step { owner })
        .with_component(PausableManager)
        .with_components(
            TokenPolicyManager::new()
                .with_mint_policy(MintPolicyConfig::AllowAll, PolicyRegistration::Active)?
                .with_burn_policy(BurnPolicyConfig::AllowAll, PolicyRegistration::Active)?
                .with_send_policy(TransferPolicy::Blocklist, PolicyRegistration::Active)?
                .with_receive_policy(TransferPolicy::Blocklist, PolicyRegistration::Active)?,
        );

    builder.add_account_from_builder(Auth::IncrNonce, account_builder, AccountState::Exists)
}

#[tokio::test]
async fn pausable_transfer_succeeds_when_unpaused() -> anyhow::Result<()> {
    let mut builder = MockChain::builder();
    let target = builder.add_existing_wallet(Auth::IncrNonce)?;
    let faucet = add_faucet_with_pause_and_policies(&mut builder, *OWNER_ID)?;

    let asset = FungibleAsset::new(faucet.id(), 100)?.with_callbacks(AssetCallbackFlag::Enabled);
    let note = builder.add_p2id_note(
        faucet.id(),
        target.id(),
        &[Asset::Fungible(asset)],
        NoteType::Public,
    )?;

    let mut mock_chain = builder.build()?;
    mock_chain.prove_next_block()?;

    let faucet_inputs = mock_chain.get_foreign_account_inputs(faucet.id())?;

    mock_chain
        .build_tx_context(target.id(), &[note.id()], &[])?
        .foreign_accounts(vec![faucet_inputs])
        .build()?
        .execute()
        .await?;

    Ok(())
}

#[tokio::test]
async fn pausable_transfer_fails_when_paused() -> anyhow::Result<()> {
    let mut builder = MockChain::builder();
    let target = builder.add_existing_wallet(Auth::IncrNonce)?;
    let faucet = add_faucet_with_pause_and_policies(&mut builder, *OWNER_ID)?;

    let asset = FungibleAsset::new(faucet.id(), 100)?.with_callbacks(AssetCallbackFlag::Enabled);
    let note = builder.add_p2id_note(
        faucet.id(),
        target.id(),
        &[Asset::Fungible(asset)],
        NoteType::Public,
    )?;

    let pause_note = build_pause_note(*OWNER_ID)?;
    builder.add_output_note(RawOutputNote::Full(pause_note.clone()));

    let mut mock_chain = builder.build()?;
    mock_chain.prove_next_block()?;

    execute_note_on_faucet(&mut mock_chain, faucet.id(), &pause_note).await?;

    let faucet_inputs = mock_chain.get_foreign_account_inputs(faucet.id())?;

    let result = mock_chain
        .build_tx_context(target.id(), &[note.id()], &[])?
        .foreign_accounts(vec![faucet_inputs])
        .build()?
        .execute()
        .await;

    assert_transaction_executor_error!(result, ERR_PAUSABLE_IS_PAUSED);

    Ok(())
}

#[tokio::test]
async fn pausable_transfer_resumes_after_unpause() -> anyhow::Result<()> {
    let mut builder = MockChain::builder();
    let target = builder.add_existing_wallet(Auth::IncrNonce)?;
    let faucet = add_faucet_with_pause_and_policies(&mut builder, *OWNER_ID)?;

    let asset = FungibleAsset::new(faucet.id(), 100)?.with_callbacks(AssetCallbackFlag::Enabled);
    let note = builder.add_p2id_note(
        faucet.id(),
        target.id(),
        &[Asset::Fungible(asset)],
        NoteType::Public,
    )?;

    let pause_note = build_pause_note(*OWNER_ID)?;
    let unpause_note = build_unpause_note(*OWNER_ID)?;
    builder.add_output_note(RawOutputNote::Full(pause_note.clone()));
    builder.add_output_note(RawOutputNote::Full(unpause_note.clone()));

    let mut mock_chain = builder.build()?;
    mock_chain.prove_next_block()?;

    execute_note_on_faucet(&mut mock_chain, faucet.id(), &pause_note).await?;
    execute_note_on_faucet(&mut mock_chain, faucet.id(), &unpause_note).await?;

    let faucet_inputs = mock_chain.get_foreign_account_inputs(faucet.id())?;

    mock_chain
        .build_tx_context(target.id(), &[note.id()], &[])?
        .foreign_accounts(vec![faucet_inputs])
        .build()?
        .execute()
        .await?;

    Ok(())
}

// TESTS — MINT / BURN / METADATA SETTER PAUSE
// ================================================================================================

#[tokio::test]
async fn pausable_mint_fails_when_paused() -> anyhow::Result<()> {
    let mut builder = MockChain::builder();
    let _target = builder.add_existing_wallet(Auth::IncrNonce)?;
    let faucet = add_faucet_with_pause_and_policies(&mut builder, *OWNER_ID)?;

    let pause_note = build_pause_note(*OWNER_ID)?;
    builder.add_output_note(RawOutputNote::Full(pause_note.clone()));

    let mut mock_chain = builder.build()?;
    mock_chain.prove_next_block()?;

    // Pause the faucet first.
    execute_note_on_faucet(&mut mock_chain, faucet.id(), &pause_note).await?;

    // Build a mint tx-script targeting the now-paused faucet.
    let recipient_word = Word::from([0u32, 1, 2, 3]);
    let tx_script_code = format!(
        r#"
        begin
            padw padw push.0
            push.{recipient}
            push.{note_type}
            push.{tag}
            push.{amount}
            call.::miden::standards::faucets::fungible::mint_and_send
            dropw dropw dropw dropw
        end
        "#,
        recipient = recipient_word,
        note_type = NoteType::Private as u8,
        tag = u32::from(NoteTag::default()),
        amount = 100u64,
    );
    let tx_script =
        miden_standards::code_builder::CodeBuilder::default().compile_tx_script(&tx_script_code)?;

    let result = mock_chain
        .build_tx_context(faucet.id(), &[], &[])?
        .tx_script(tx_script)
        .build()?
        .execute()
        .await;

    // execute_mint_policy calls exec.pausable::assert_not_paused before dispatch → panic.
    assert_transaction_executor_error!(result, ERR_PAUSABLE_IS_PAUSED);

    Ok(())
}

#[tokio::test]
async fn pausable_burn_fails_when_paused() -> anyhow::Result<()> {
    let mut builder = MockChain::builder();
    let faucet = add_faucet_with_pause_and_policies(&mut builder, *OWNER_ID)?;

    // Pre-stage a burn note carrying an asset issued by this faucet.
    let burn_asset = FungibleAsset::new(faucet.id(), 50)?;
    let burn_note_script_code = r#"
        @note_script
        pub proc main
            dropw
            call.::miden::standards::faucets::fungible::receive_and_burn
        end
    "#;
    let burn_note_script = miden_standards::code_builder::CodeBuilder::default()
        .compile_note_script(burn_note_script_code)?;
    let mut rng = RandomCoin::new(Word::from([1u32, 2, 3, 4]));
    let burn_note = NoteBuilder::new(faucet.id(), &mut rng)
        .note_type(NoteType::Private)
        .add_assets([Asset::Fungible(burn_asset)])
        .script(burn_note_script)
        .build()?;
    builder.add_output_note(RawOutputNote::Full(burn_note.clone()));

    let pause_note = build_pause_note(*OWNER_ID)?;
    builder.add_output_note(RawOutputNote::Full(pause_note.clone()));

    let mut mock_chain = builder.build()?;
    mock_chain.prove_next_block()?;

    execute_note_on_faucet(&mut mock_chain, faucet.id(), &pause_note).await?;

    let result = mock_chain
        .build_tx_context(faucet.id(), &[burn_note.id()], &[])?
        .build()?
        .execute()
        .await;

    // execute_burn_policy → exec.pausable::assert_not_paused → panic.
    assert_transaction_executor_error!(result, ERR_PAUSABLE_IS_PAUSED);

    Ok(())
}

/// Builds a faucet with mutable `max_supply` so that `set_max_supply` can be called via the
/// metadata setter path (which we want to verify is pause-gated).
fn add_faucet_mutable_max_supply_with_pause(
    builder: &mut MockChainBuilder,
    owner: AccountId,
) -> anyhow::Result<Account> {
    let faucet = FungibleFaucet::builder()
        .name(TokenName::new("SYM")?)
        .symbol("SYM".try_into()?)
        .decimals(8)
        .max_supply(AssetAmount::new(1_000_000)?)
        .is_max_supply_mutable(true)
        .build()?;

    let account_builder = AccountBuilder::new([45u8; 32])
        .account_type(AccountType::Public)
        .with_component(faucet)
        .with_components(AccessControl::Ownable2Step { owner })
        .with_component(PausableManager);

    builder.add_account_from_builder(Auth::IncrNonce, account_builder, AccountState::Exists)
}

#[tokio::test]
async fn pausable_set_max_supply_fails_when_paused() -> anyhow::Result<()> {
    let mut builder = MockChain::builder();
    let faucet = add_faucet_mutable_max_supply_with_pause(&mut builder, *OWNER_ID)?;

    // Owner-authored note that calls set_max_supply.
    let set_max_supply_note_code = format!(
        r#"
        @note_script
        pub proc main
            push.{new_max_supply}
            swap drop
            call.::miden::standards::faucets::fungible::set_max_supply
        end
        "#,
        new_max_supply = 500_000u64,
    );
    let set_max_supply_note_script = miden_standards::code_builder::CodeBuilder::default()
        .compile_note_script(&set_max_supply_note_code)?;
    let mut rng = RandomCoin::new(Word::from([9u32, 8, 7, 6]));
    let set_max_supply_note = NoteBuilder::new(*OWNER_ID, &mut rng)
        .note_type(NoteType::Private)
        .script(set_max_supply_note_script)
        .build()?;
    builder.add_output_note(RawOutputNote::Full(set_max_supply_note.clone()));

    let pause_note = build_pause_note(*OWNER_ID)?;
    builder.add_output_note(RawOutputNote::Full(pause_note.clone()));

    let mut mock_chain = builder.build()?;
    mock_chain.prove_next_block()?;

    // Pause first.
    execute_note_on_faucet(&mut mock_chain, faucet.id(), &pause_note).await?;

    // Now try to update max_supply — should fail because set_max_supply has
    // `exec.pausable::assert_not_paused` after the authority check.
    let result = mock_chain
        .build_tx_context(faucet.id(), &[set_max_supply_note.id()], &[])?
        .build()?
        .execute()
        .await;

    assert_transaction_executor_error!(result, ERR_PAUSABLE_IS_PAUSED);

    Ok(())
}

// TESTS — PAUSABLE MANAGER WITH AUTH-CONTROLLED ACCESS CONTROL
// ================================================================================================

/// Same as `add_faucet_with_pause` but uses `AccessControl::AuthControlled`.
fn add_faucet_with_pause_auth_controlled(
    builder: &mut MockChainBuilder,
) -> anyhow::Result<Account> {
    let faucet = FungibleFaucet::builder()
        .name(TokenName::new("SYM")?)
        .symbol("SYM".try_into()?)
        .decimals(8)
        .max_supply(AssetAmount::new(1_000_000)?)
        .build()?;

    let account_builder = AccountBuilder::new([46u8; 32])
        .account_type(AccountType::Public)
        .with_component(faucet)
        .with_components(AccessControl::AuthControlled)
        .with_component(PausableManager);

    builder.add_account_from_builder(Auth::IncrNonce, account_builder, AccountState::Exists)
}

#[tokio::test]
async fn pausable_manager_works_with_auth_controlled() -> anyhow::Result<()> {
    let mut builder = MockChain::builder();
    let faucet = add_faucet_with_pause_auth_controlled(&mut builder)?;

    // Any sender works because Authority::AuthControlled defers auth entirely to the account's
    // own auth scheme (here Auth::IncrNonce, which accepts unconditionally).
    let pause_note = build_pause_note(*NON_OWNER_ID)?;
    builder.add_output_note(RawOutputNote::Full(pause_note.clone()));

    let mut mock_chain = builder.build()?;
    mock_chain.prove_next_block()?;

    execute_note_on_faucet(&mut mock_chain, faucet.id(), &pause_note).await?;

    Ok(())
}