Skip to content

Commit

Permalink
Merge pull request #1808 from AleoHQ/test/deploy-credits-program
Browse files Browse the repository at this point in the history
Test deployments of `credits.aleo`
  • Loading branch information
howardwu authored Jul 19, 2023
2 parents d027ddf + 65cd813 commit 90ab1af
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
47 changes: 47 additions & 0 deletions synthesizer/process/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2329,6 +2329,53 @@ function compute:
process.verify_execution(&execution).unwrap();
}

#[test]
fn test_process_deploy_credits_program() {
let rng = &mut TestRng::default();

// Initialize an empty process without the `credits` program.
let empty_process =
Process { universal_srs: Arc::new(UniversalSRS::<CurrentNetwork>::load().unwrap()), stacks: IndexMap::new() };

// Construct the process.
let process = Process::load().unwrap();

// Fetch the credits program
let program = Program::credits().unwrap();

// Create a deployment for the credits.aleo program.
let deployment = empty_process.deploy::<CurrentAleo, _>(&program, rng).unwrap();

// Ensure the deployment is valid on the empty process.
assert!(empty_process.verify_deployment::<CurrentAleo, _>(&deployment, rng).is_ok());
// Ensure the deployment is not valid on the standard process.
assert!(process.verify_deployment::<CurrentAleo, _>(&deployment, rng).is_err());

// Create a new `credits.aleo` program.
let program = Program::from_str(
r"
program credits.aleo;
record token:
owner as address.private;
amount as u64.private;
function compute:
input r0 as u32.private;
add r0 r0 into r1;
output r1 as u32.public;",
)
.unwrap();

// Create a deployment for the credits.aleo program.
let deployment = empty_process.deploy::<CurrentAleo, _>(&program, rng).unwrap();

// Ensure the deployment is valid on the empty process.
assert!(empty_process.verify_deployment::<CurrentAleo, _>(&deployment, rng).is_ok());
// Ensure the deployment is not valid on the standard process.
assert!(process.verify_deployment::<CurrentAleo, _>(&deployment, rng).is_err());
}

fn get_assignment(
stack: &Stack<CurrentNetwork>,
private_key: &PrivateKey<CurrentNetwork>,
Expand Down
31 changes: 31 additions & 0 deletions synthesizer/src/vm/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -481,4 +481,35 @@ mod tests {
assert!(vm.check_transaction(&transaction, None).is_ok());
assert!(vm.verify_transaction(&transaction, None));
}

#[test]
fn test_failed_credits_deployment() {
let rng = &mut TestRng::default();
let vm = crate::vm::test_helpers::sample_vm();

// Fetch the credits program
let program = Program::credits().unwrap();

// Ensure that the program can't be deployed.
assert!(vm.deploy_raw(&program, rng).is_err());

// Create a new `credits.aleo` program.
let program = Program::from_str(
r"
program credits.aleo;
record token:
owner as address.private;
amount as u64.private;
function compute:
input r0 as u32.private;
add r0 r0 into r1;
output r1 as u32.public;",
)
.unwrap();

// Ensure that the program can't be deployed.
assert!(vm.deploy_raw(&program, rng).is_err());
}
}

0 comments on commit 90ab1af

Please sign in to comment.