Skip to content

Commit

Permalink
chore: test separately
Browse files Browse the repository at this point in the history
  • Loading branch information
ashWhiteHat committed Jan 24, 2024
1 parent a8a7393 commit 3621262
Showing 1 changed file with 6 additions and 38 deletions.
44 changes: 6 additions & 38 deletions sample/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::{self as sum_storage, Config};

use core::marker::PhantomData;
use frame_support::assert_ok;
use frame_support::parameter_types;
use frame_support::{assert_err, assert_ok};
use frame_system as system;
use pallet_nova::*;
use rand_core::SeedableRng;
Expand Down Expand Up @@ -116,7 +116,7 @@ fn default_sum_zero() {

/// The set `Thing1` storage with valid proof
#[test]
fn sums_thing_one_with_valid_proof() {
fn sums_thing_one() {
let mut rng = get_rng();

let pp = PublicParams::<
Expand All @@ -126,6 +126,7 @@ fn sums_thing_one_with_valid_proof() {
ExampleFunction<Fq>,
>::setup(&mut rng);

println!("pass");
let z0_primary = DenseVectors::new(vec![Fr::from(0)]);
let z0_secondary = DenseVectors::new(vec![Fq::from(0)]);
let mut ivc =
Expand All @@ -134,50 +135,17 @@ fn sums_thing_one_with_valid_proof() {
z0_primary,
z0_secondary,
);
println!("pass");
(0..2).for_each(|_| {
ivc.prove_step(&pp);
});
println!("pass");
let proof = ivc.prove_step(&pp);
println!("pass");

new_test_ext().execute_with(|| {
assert_ok!(SumStorage::set_thing_1(Origin::signed(1), 42, proof, pp));
});

assert_eq!(SumStorage::get_sum(), 42);
}

/// The set `Thing1` storage with invalid proof
#[test]
fn sums_thing_one_with_invalid_proof() {
let mut rng = get_rng();

let pp = PublicParams::<
Bn254Driver,
GrumpkinDriver,
ExampleFunction<Fr>,
ExampleFunction<Fq>,
>::setup(&mut rng);

let z0_primary = DenseVectors::new(vec![Fr::from(0)]);
let z0_secondary = DenseVectors::new(vec![Fq::from(0)]);
let mut ivc =
Ivc::<Bn254Driver, GrumpkinDriver, ExampleFunction<Fr>, ExampleFunction<Fq>>::init(
&pp,
z0_primary,
z0_secondary,
);
(0..2).for_each(|_| {
ivc.prove_step(&pp);
});
let mut proof = ivc.prove_step(&pp);
proof.i = 2;

new_test_ext().execute_with(|| {
assert_err!(
SumStorage::set_thing_1(Origin::signed(1), 42, proof, pp),
"invalid proof"
);
});

assert_eq!(SumStorage::get_sum(), 0);
}

0 comments on commit 3621262

Please sign in to comment.