Skip to content

Commit

Permalink
chore: format code
Browse files Browse the repository at this point in the history
  • Loading branch information
Draply committed Aug 29, 2024
1 parent 10be7e9 commit 88eaafb
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 79 deletions.
36 changes: 29 additions & 7 deletions src/bin/main.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
use log::{error, info};
use log::info;

use verifier_onchain_services::config::{AppConfig, EnvConfig};
use verifier_onchain_services::contracts_caller::memory_page_fact_registry::register_continuous_page_batch::register_continuous_page_batch;
use verifier_onchain_services::contracts_caller::memory_page_fact_registry::sample_register_memory::sample_register_continuous_page_batch;
use verifier_onchain_services::contracts_caller::verify_fri::sample_verify_fri_input::sample_verify_fri_input;
use verifier_onchain_services::contracts_caller::verify_fri::verify_fri::verify_fri;
use verifier_onchain_services::contracts_caller::verify_merkle::sample_verify_merkle_input::sample_verify_merkle_input;
use verifier_onchain_services::contracts_caller::verify_merkle::verify_merkle::verify_merkle;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
Expand All @@ -17,18 +20,37 @@ async fn main() -> anyhow::Result<()> {
config.account.set_sequence_number(sequence_number);

for i in 1..4 {
sample_verify_merkle_input(&config, i).await?;
let (merkle_view, initial_merkle_queue, height, expected_root) =
sample_verify_merkle_input(i)?;
verify_merkle(
&config,
merkle_view,
initial_merkle_queue,
height,
expected_root,
)
.await?;
info!("Verify Merkle {} success", i);
}

for i in 1..8 {
sample_verify_fri_input(&config, i).await?;
let (fri_verify_input, proof, fri_queue, evaluation_point, fri_step_size, expected_root) =
sample_verify_fri_input(i)?;
verify_fri(
&config,
fri_verify_input,
proof,
fri_queue,
evaluation_point,
fri_step_size,
expected_root,
)
.await?;
info!("Verify FRI {} success", i);
}

if !sample_register_continuous_page_batch(&config).await? {
error!("something went wrong!")
}

let register_continuous_page_batch_input = sample_register_continuous_page_batch()?;
register_continuous_page_batch(&config, register_continuous_page_batch_input).await?;
info!("Register continuous page batch success");
Ok(())
}
Original file line number Diff line number Diff line change
@@ -1,42 +1,34 @@
use std::fs::File;
use std::io::BufReader;

use crate::config::AppConfig;
use crate::contracts_caller::memory_page_fact_registry::register_continuous_memorypage::register_continuous_memorypage;
use crate::contracts_caller::memory_page_fact_registry::register_continuous_page_batch::register_continuous_page_batch;
use crate::contracts_caller::memory_page_fact_registry::types::register_continuous_memorypage::ContinuousMemorypage;
use crate::contracts_caller::memory_page_fact_registry::types::register_continuous_page_batch::MemoryPageEntries;

pub async fn sample_register_continuous_page_batch(config: &AppConfig) -> anyhow::Result<bool> {
pub fn sample_register_continuous_page_batch() -> anyhow::Result<MemoryPageEntries> {
let file_path =
"src/data_samples/memory_page_fact_registry/register_continuous_page_batch.json"
.to_string();
let input_file = File::open(file_path)?;
let reader = BufReader::new(input_file);
let memory_page_entries: MemoryPageEntries = serde_json::from_reader(reader)?;

register_continuous_page_batch(config, memory_page_entries).await
Ok(memory_page_entries)
}

pub async fn sample_register_continuous_page(config: &AppConfig) -> anyhow::Result<bool> {
pub fn sample_register_continuous_page() -> anyhow::Result<ContinuousMemorypage> {
let file_path =
"src/data_samples/memory_page_fact_registry/register_memory_page.json".to_string();
let input_file = File::open(file_path)?;
let reader = BufReader::new(input_file);
let continuous_memmory_page: ContinuousMemorypage = serde_json::from_reader(reader)?;

register_continuous_memorypage(config, continuous_memmory_page).await
Ok(continuous_memmory_page)
}

pub async fn sample_large_data_register_continuous_page_batch(
config: &AppConfig,
) -> anyhow::Result<bool> {
pub fn sample_large_data_register_continuous_page_batch() -> anyhow::Result<MemoryPageEntries> {
let file_path =
"src/data_samples/memory_page_fact_registry/large_data_register_continuous_page_batch.json"
.to_string();
let input_file = File::open(file_path)?;
let reader = BufReader::new(input_file);
let memory_page_entries: MemoryPageEntries = serde_json::from_reader(reader)?;

register_continuous_page_batch(config, memory_page_entries).await
Ok(memory_page_entries)
}
22 changes: 0 additions & 22 deletions src/contracts_caller/transaction_helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,25 +90,3 @@ pub fn get_event_from_transaction(
};
event.ok_or(Error::new(CoreError::NotFound))
}

pub fn get_events_from_transaction(
transaction: &Transaction,
event_type: MoveType,
) -> anyhow::Result<Vec<&Event>> {
let events: Vec<&Event> = match transaction {
Transaction::UserTransaction(txn) => {
txn.events.iter().filter(|s| s.typ == event_type).collect()
}
Transaction::BlockMetadataTransaction(_) => vec![],
Transaction::PendingTransaction(_) => vec![],
Transaction::GenesisTransaction(_) => vec![],
Transaction::StateCheckpointTransaction(_) => vec![],
Transaction::BlockEpilogueTransaction(_) => vec![],
Transaction::ValidatorTransaction(_) => vec![],
};
if events.is_empty() {
Err(Error::new(CoreError::NotFound))
} else {
Ok(events)
}
}
23 changes: 14 additions & 9 deletions src/contracts_caller/verify_fri/sample_verify_fri_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@ use std::fs::File;
use std::io::BufReader;
use std::str::FromStr;

use crate::config::AppConfig;
use crate::contracts_caller::verify_fri::types::fri_verify_input::FriVerifyInput;
use crate::contracts_caller::verify_fri::verify_fri::verify_fri;
use aptos_sdk::move_types::u256::U256;
use aptos_sdk::move_types::value::MoveValue;

pub async fn sample_verify_fri_input(config: &AppConfig, index: isize) -> anyhow::Result<()> {
use crate::contracts_caller::verify_fri::types::fri_verify_input::FriVerifyInput;

pub fn sample_verify_fri_input(
index: isize,
) -> anyhow::Result<(
FriVerifyInput,
MoveValue,
MoveValue,
MoveValue,
MoveValue,
MoveValue,
)> {
let file_path = format!("./src/data_samples/fri_verify/fri_verify_{}.json", index);
let input_file = File::open(file_path)?;
let reader = BufReader::new(input_file);
Expand Down Expand Up @@ -36,15 +44,12 @@ pub async fn sample_verify_fri_input(config: &AppConfig, index: isize) -> anyhow
MoveValue::U256(U256::from_str(&fri_verify_input.evaluation_point.clone())?);
let fri_step_size = MoveValue::U256(U256::from_str(&fri_verify_input.fri_step_size.clone())?);
let expected_root = MoveValue::U256(U256::from_str(&fri_verify_input.expected_root.clone())?);
verify_fri(
config,
Ok((
fri_verify_input,
proof,
fri_queue,
evaluation_point,
fri_step_size,
expected_root,
)
.await?;
Ok(())
))
}
19 changes: 6 additions & 13 deletions src/contracts_caller/verify_merkle/sample_verify_merkle_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ use std::fs::File;
use std::io::BufReader;
use std::str::FromStr;

use crate::config::AppConfig;
use crate::contracts_caller::verify_merkle::types::verify_merkle_input::MerkleVerifyInput;
use crate::contracts_caller::verify_merkle::verify_merkle::verify_merkle;
use aptos_sdk::move_types::u256::U256;
use aptos_sdk::move_types::value::MoveValue;

pub async fn sample_verify_merkle_input(config: &AppConfig, index: isize) -> anyhow::Result<()> {
use crate::contracts_caller::verify_merkle::types::verify_merkle_input::MerkleVerifyInput;

pub fn sample_verify_merkle_input(
index: isize,
) -> anyhow::Result<(MoveValue, MoveValue, MoveValue, MoveValue)> {
let file_path = format!(
"./src/data_samples/merkle_verify/merkle_verify_{}.json",
index
Expand Down Expand Up @@ -36,13 +37,5 @@ pub async fn sample_verify_merkle_input(config: &AppConfig, index: isize) -> any
let height = MoveValue::U64(u64::from_str(&merkle_verify_input.height.clone())?);
let expected_root =
MoveValue::U256(U256::from_str(&merkle_verify_input.expected_root.clone())?);
verify_merkle(
config,
merkle_view,
initial_merkle_queue,
height,
expected_root,
)
.await?;
Ok(())
Ok((merkle_view, initial_merkle_queue, height, expected_root))
}
34 changes: 31 additions & 3 deletions tests/flow_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,40 @@ mod tests {
.unwrap();

for i in 1..4 {
sample_verify_merkle_input(&config, i).await?;
let (merkle_view, initial_merkle_queue, height, expected_root) =
sample_verify_merkle_input(i).unwrap();
verify_merkle(
&config,
merkle_view,
initial_merkle_queue,
height,
expected_root,
)
.await
.unwrap();
info!("Verify Merkle {} success", i);
}

for i in 1..8 {
sample_verify_fri_input(&config, i).await?;
let (
fri_verify_input,
proof,
fri_queue,
evaluation_point,
fri_step_size,
expected_root,
) = sample_verify_fri_input(i).unwrap();
verify_fri(
&config,
fri_verify_input,
proof,
fri_queue,
evaluation_point,
fri_step_size,
expected_root,
)
.await
.unwrap();
info!("Verify FRI {} success", i);
}
Ok(())
Expand All @@ -70,4 +98,4 @@ mod tests {
.await
.unwrap()
}
}
}
28 changes: 17 additions & 11 deletions tests/memory_page_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ mod tests {

use aptos_sdk::types::LocalAccount;
use aptos_testcontainer::test_utils::aptos_container_test_utils::{lazy_aptos_container, run};
use log::error;
use test_log::test;

use verifier_onchain_services::config::{AppConfig, EnvConfig};
use verifier_onchain_services::contracts_caller::memory_page_fact_registry::register_continuous_memorypage::register_continuous_memorypage;
use verifier_onchain_services::contracts_caller::memory_page_fact_registry::register_continuous_page_batch::register_continuous_page_batch;
use verifier_onchain_services::contracts_caller::memory_page_fact_registry::sample_register_memory::{sample_large_data_register_continuous_page_batch, sample_register_continuous_page, sample_register_continuous_page_batch};

#[test(tokio::test)]
Expand Down Expand Up @@ -52,19 +53,24 @@ mod tests {
.await
.unwrap();

if !sample_register_continuous_page_batch(&config).await? {
error!("something went wrong!")
}
if !sample_register_continuous_page(&config).await? {
error!("something went wrong!")
}
if !sample_large_data_register_continuous_page_batch(&config).await? {
error!("something went wrong!")
}
let register_continuous_page_batch_input = sample_register_continuous_page_batch()?;
register_continuous_page_batch(&config, register_continuous_page_batch_input)
.await?;

let register_continuous_page_input = sample_register_continuous_page()?;
register_continuous_memorypage(&config, register_continuous_page_input).await?;

let large_data_register_continuous_page_batch_input =
sample_large_data_register_continuous_page_batch()?;
register_continuous_page_batch(
&config,
large_data_register_continuous_page_batch_input,
)
.await?;
Ok(())
})
})
.await
.unwrap()
}
}
}

0 comments on commit 88eaafb

Please sign in to comment.