Skip to content

Commit 58d7c99

Browse files
committed
test_missing_signers by default
1 parent 274de12 commit 58d7c99

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

program/tests/helpers/instruction_builders.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub struct InstructionExecution<'a, 'b> {
2222
accounts: Vec<(Pubkey, AccountSharedData)>,
2323
ctx: &'a StakeTestContext,
2424
checks: Option<&'b [Check<'b>]>,
25-
test_missing_signers: bool,
25+
test_missing_signers: Option<bool>, // `None` runs if `Check::success`
2626
}
2727

2828
impl<'b> InstructionExecution<'_, 'b> {
@@ -31,19 +31,28 @@ impl<'b> InstructionExecution<'_, 'b> {
3131
self
3232
}
3333

34-
pub fn test_missing_signers(mut self) -> Self {
35-
self.test_missing_signers = true;
34+
pub fn test_missing_signers(mut self, test: bool) -> Self {
35+
self.test_missing_signers = Some(test);
3636
self
3737
}
3838

39+
/// Executes the instruction. If `checks` is `None` or empty, uses `Check::success()`.
40+
/// Fail-safe default: when `test_missing_signers` is `None`, runs the missing-signers
41+
/// test (`true`). Callers must explicitly opt out with `.test_missing_signers(false)`.
3942
pub fn execute(self) -> mollusk_svm::result::InstructionResult {
4043
let default_checks = [Check::success()];
41-
let checks = self.checks.unwrap_or(&default_checks);
44+
let checks = match self.checks {
45+
Some(c) if !c.is_empty() => c,
46+
_ => &default_checks,
47+
};
48+
49+
let test_missing_signers = self.test_missing_signers.unwrap_or(true);
50+
4251
self.ctx.process_instruction_maybe_test_signers(
4352
&self.instruction,
4453
self.accounts,
4554
checks,
46-
self.test_missing_signers,
55+
test_missing_signers,
4756
)
4857
}
4958
}
@@ -59,7 +68,7 @@ impl<'a> InstructionExecution<'a, '_> {
5968
accounts,
6069
ctx,
6170
checks: None,
62-
test_missing_signers: false,
71+
test_missing_signers: None,
6372
}
6473
}
6574
}

program/tests/initialize.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ fn test_initialize(variant: InitializeVariant) {
6565
.space(StakeStateV2::size_of())
6666
.build(),
6767
])
68-
.test_missing_signers()
68+
.test_missing_signers(true)
6969
.execute(),
7070
InitializeVariant::InitializeChecked => ctx
7171
.process_with(InitializeCheckedConfig {
@@ -81,7 +81,7 @@ fn test_initialize(variant: InitializeVariant) {
8181
.space(StakeStateV2::size_of())
8282
.build(),
8383
])
84-
.test_missing_signers()
84+
.test_missing_signers(true)
8585
.execute(),
8686
};
8787

@@ -106,13 +106,15 @@ fn test_initialize(variant: InitializeVariant) {
106106
lockup: &lockup,
107107
})
108108
.checks(&[Check::err(ProgramError::InvalidAccountData)])
109+
.test_missing_signers(false)
109110
.execute(),
110111
InitializeVariant::InitializeChecked => ctx
111112
.process_with(InitializeCheckedConfig {
112113
stake: (&stake, &resulting_account),
113114
authorized: &authorized,
114115
})
115116
.checks(&[Check::err(ProgramError::InvalidAccountData)])
117+
.test_missing_signers(false)
116118
.execute(),
117119
};
118120
}
@@ -154,13 +156,15 @@ fn test_initialize_insufficient_funds(variant: InitializeVariant) {
154156
lockup: &lockup,
155157
})
156158
.checks(&[Check::err(ProgramError::InsufficientFunds)])
159+
.test_missing_signers(false)
157160
.execute(),
158161
InitializeVariant::InitializeChecked => ctx
159162
.process_with(InitializeCheckedConfig {
160163
stake: (&stake, &stake_account),
161164
authorized: &authorized,
162165
})
163166
.checks(&[Check::err(ProgramError::InsufficientFunds)])
167+
.test_missing_signers(false)
164168
.execute(),
165169
};
166170
}
@@ -206,13 +210,15 @@ fn test_initialize_incorrect_size_larger(variant: InitializeVariant) {
206210
lockup: &lockup,
207211
})
208212
.checks(&[Check::err(ProgramError::InvalidAccountData)])
213+
.test_missing_signers(false)
209214
.execute(),
210215
InitializeVariant::InitializeChecked => ctx
211216
.process_with(InitializeCheckedConfig {
212217
stake: (&stake, &stake_account),
213218
authorized: &authorized,
214219
})
215220
.checks(&[Check::err(ProgramError::InvalidAccountData)])
221+
.test_missing_signers(false)
216222
.execute(),
217223
};
218224
}
@@ -258,13 +264,15 @@ fn test_initialize_incorrect_size_smaller(variant: InitializeVariant) {
258264
lockup: &lockup,
259265
})
260266
.checks(&[Check::err(ProgramError::InvalidAccountData)])
267+
.test_missing_signers(false)
261268
.execute(),
262269
InitializeVariant::InitializeChecked => ctx
263270
.process_with(InitializeCheckedConfig {
264271
stake: (&stake, &stake_account),
265272
authorized: &authorized,
266273
})
267274
.checks(&[Check::err(ProgramError::InvalidAccountData)])
275+
.test_missing_signers(false)
268276
.execute(),
269277
};
270278
}

0 commit comments

Comments
 (0)