Skip to content
This repository has been archived by the owner on Oct 31, 2023. It is now read-only.

Commit

Permalink
chore: Switch to tokio test macro for async function (#191)
Browse files Browse the repository at this point in the history
  • Loading branch information
phated authored May 17, 2023
1 parent 04c9d0f commit ac930d4
Show file tree
Hide file tree
Showing 5 changed files with 152 additions and 143 deletions.
81 changes: 52 additions & 29 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pkg-config = "0.3"
blake2 = "0.10.6"
sled = "0.34.6"
tempfile = "3.3"
tokio = "1.0"
tokio = { version = "1.0", features = [ "macros" ] }

[features]
default = ["native"]
Expand Down
89 changes: 46 additions & 43 deletions src/acvm_interop/smart_contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,47 +75,50 @@ impl SmartContract for Barretenberg {
}
}

#[test]
fn test_smart_contract() -> Result<(), BackendError> {
use crate::barretenberg_structures::{Constraint, ConstraintSystem};
use crate::composer::Composer;
use crate::Barretenberg;
use acvm::FieldElement;
use tokio::runtime::Builder;

let constraint = Constraint {
a: 1,
b: 2,
c: 3,
qm: FieldElement::zero(),
ql: FieldElement::one(),
qr: FieldElement::one(),
qo: -FieldElement::one(),
qc: FieldElement::zero(),
};

let constraint_system = ConstraintSystem::new()
.var_num(4)
.public_inputs(vec![1, 2])
.constraints(vec![constraint]);

let bb = Barretenberg::new();
let crs = Builder::new_current_thread()
.enable_all()
.build()
.unwrap()
.block_on(bb.get_crs(&constraint_system))?;

let proving_key = bb.compute_proving_key(&constraint_system)?;
let verification_key = bb.compute_verification_key(&crs, &proving_key)?;

let common_reference_string: Vec<u8> = crs.try_into()?;

let contract = bb.eth_contract_from_vk(&common_reference_string, &verification_key)?;

assert!(contract.contains("contract BaseUltraVerifier"));
assert!(contract.contains("contract UltraVerifier"));
assert!(contract.contains("library UltraVerificationKey"));

Ok(())
#[cfg(test)]
mod tests {
use acvm::SmartContract;
use tokio::test;

use crate::BackendError;

#[test]
async fn test_smart_contract() -> Result<(), BackendError> {
use crate::barretenberg_structures::{Constraint, ConstraintSystem};
use crate::composer::Composer;
use crate::Barretenberg;
use acvm::FieldElement;

let constraint = Constraint {
a: 1,
b: 2,
c: 3,
qm: FieldElement::zero(),
ql: FieldElement::one(),
qr: FieldElement::one(),
qo: -FieldElement::one(),
qc: FieldElement::zero(),
};

let constraint_system = ConstraintSystem::new()
.var_num(4)
.public_inputs(vec![1, 2])
.constraints(vec![constraint]);

let bb = Barretenberg::new();
let crs = bb.get_crs(&constraint_system).await?;

let proving_key = bb.compute_proving_key(&constraint_system)?;
let verification_key = bb.compute_verification_key(&crs, &proving_key)?;

let common_reference_string: Vec<u8> = crs.try_into()?;

let contract = bb.eth_contract_from_vk(&common_reference_string, &verification_key)?;

assert!(contract.contains("contract BaseUltraVerifier"));
assert!(contract.contains("contract UltraVerifier"));
assert!(contract.contains("library UltraVerificationKey"));

Ok(())
}
}
Loading

0 comments on commit ac930d4

Please sign in to comment.