add test for missing outputs

This commit is contained in:
Sergio Chouhy 2025-08-10 10:09:23 -03:00
parent ecdb4ba130
commit a3b64e4021
5 changed files with 50 additions and 6 deletions

View File

@ -87,12 +87,22 @@ impl Program {
}
/// A program that produces more output accounts than the inputs it received
pub fn extra_outputs_program() -> Self {
use test_program_methods::{EXTRA_OUTPUTS_ELF, EXTRA_OUTPUTS_ID};
pub fn extra_output_program() -> Self {
use test_program_methods::{EXTRA_OUTPUT_ELF, EXTRA_OUTPUT_ID};
Program {
id: EXTRA_OUTPUTS_ID,
elf: EXTRA_OUTPUTS_ELF,
id: EXTRA_OUTPUT_ID,
elf: EXTRA_OUTPUT_ELF,
}
}
/// A program that produces less output accounts than the inputs it received
pub fn missing_output_program() -> Self {
use test_program_methods::{MISSING_OUTPUT_ELF, MISSING_OUTPUT_ID};
Program {
id: MISSING_OUTPUT_ID,
elf: MISSING_OUTPUT_ELF,
}
}
}

View File

@ -147,7 +147,8 @@ impl V01State {
/// Include test programs in the builtin programs map
pub fn with_test_programs(mut self) -> Self {
self.insert_program(Program::nonce_changer_program());
self.insert_program(Program::extra_outputs_program());
self.insert_program(Program::extra_output_program());
self.insert_program(Program::missing_output_program());
self
}
}

View File

@ -24,7 +24,24 @@ fn test_program_should_fail_if_output_accounts_exceed_inputs() {
let mut state = V01State::new_with_genesis_accounts(&initial_data).with_test_programs();
let addresses = vec![Address::new([1; 32])];
let nonces = vec![];
let program_id = Program::extra_outputs_program().id();
let program_id = Program::extra_output_program().id();
let message = public_transaction::Message::new(program_id, addresses, nonces, 0);
let witness_set = public_transaction::WitnessSet::for_message(&message, &[]);
let tx = PublicTransaction::new(message, witness_set);
let result = state.transition_from_public_transaction(&tx);
assert!(matches!(result, Err(NssaError::InvalidProgramBehavior)));
}
#[test]
fn test_program_should_fail_with_missing_output_accounts() {
let initial_data = [([1; 32], 100)];
let mut state = V01State::new_with_genesis_accounts(&initial_data).with_test_programs();
let addresses = vec![Address::new([1; 32]), Address::new([2; 32])];
let nonces = vec![];
let program_id = Program::missing_output_program().id();
let message = public_transaction::Message::new(program_id, addresses, nonces, 0);
let witness_set = public_transaction::WitnessSet::for_message(&message, &[]);
let tx = PublicTransaction::new(message, witness_set);

View File

@ -0,0 +1,16 @@
use nssa_core::account::AccountWithMetadata;
use risc0_zkvm::guest::env;
fn main() {
let input_accounts: Vec<AccountWithMetadata> = env::read();
let _instruction_data: u128 = env::read();
let [pre1, _] = match input_accounts.try_into() {
Ok(array) => array,
Err(_) => return,
};
let account_pre1 = pre1.account;
env::commit(&vec![account_pre1]);
}