use stoffel_vm_types::{
compiled_binary::utils::{
from_vm_functions, load_from_file, save_to_file, try_to_vm_functions,
},
core_types::Value,
functions::VMFunction,
instructions::Instruction,
};
pub fn build_avss_keygen_program() -> Vec<Instruction> {
vec![
Instruction::CALL("Share.random".to_string()),
Instruction::MOV(1, 0),
Instruction::LDI(2, Value::I64(0)),
Instruction::PUSHARG(1),
Instruction::PUSHARG(2),
Instruction::CALL("Share.get_commitment".to_string()),
Instruction::RET(0),
]
}
#[test]
fn avss_keygen_bytecode_round_trips_without_mutating_fixtures() {
let func = VMFunction::new(
"main".to_string(),
vec![],
vec![],
None,
4,
build_avss_keygen_program(),
Default::default(),
);
let binary = from_vm_functions(&[func]);
let dir = tempfile::tempdir().expect("temp dir");
let path = dir.path().join("avss_keygen.stflb");
save_to_file(&binary, &path).expect("failed to save avss_keygen bytecode");
let loaded = load_from_file(&path).expect("failed to reload");
let functions =
try_to_vm_functions(&loaded).expect("generated AVSS keygen bytecode should be executable");
assert_eq!(functions.len(), 1);
assert_eq!(functions[0].name(), "main");
assert_eq!(functions[0].instructions().len(), 7);
}