Skip to content

Commit

Permalink
feat: add rustfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
zk-steve authored and Draply committed Aug 29, 2024
1 parent aae498e commit d130e9b
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 56 deletions.
3 changes: 3 additions & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
group_imports = "StdExternalCrate"
imports_granularity = "Preserve"
reorder_imports = true
3 changes: 1 addition & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use std::str::FromStr;

use anyhow::Result;
use dotenv::dotenv;

use aptos_sdk::move_types::account_address::AccountAddress;
use aptos_sdk::rest_client::Client;
use aptos_sdk::types::chain_id::ChainId;
use aptos_sdk::types::LocalAccount;
use dotenv::dotenv;

pub struct EnvConfig {
pub node_url: String,
Expand Down
2 changes: 1 addition & 1 deletion src/contracts_caller/memory_page_fact_registry/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub mod register_continuous_memorypage;
pub mod register_continuous_memory_page;
pub mod register_continuous_page_batch;
pub mod sample_register_memory;
pub mod types;
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
use crate::config::AppConfig;
use crate::contracts_caller::memory_page_fact_registry::types::register_continuous_memorypage::ContinuousMemorypage;
use crate::contracts_caller::transaction_helper::build_transaction;
use std::str::FromStr;

use aptos_sdk::move_types::identifier::Identifier;
use aptos_sdk::move_types::language_storage::ModuleId;
use aptos_sdk::move_types::u256::U256;
use aptos_sdk::move_types::value::{serialize_values, MoveValue};
use aptos_sdk::types::transaction::{EntryFunction, TransactionPayload};
use log::info;
use std::str::FromStr;

pub async fn register_continuous_memorypage(
use crate::config::AppConfig;
use crate::contracts_caller::memory_page_fact_registry::types::register_continuous_memory_page::ContinuousMemoryPage;
use crate::contracts_caller::transaction_helper::build_transaction;

pub async fn register_continuous_memory_page(
config: &AppConfig,
data: ContinuousMemorypage,
data: ContinuousMemoryPage,
) -> anyhow::Result<bool> {
let mut values = vec![];
for e in &data.values {
Expand All @@ -37,7 +39,7 @@ pub async fn register_continuous_memorypage(
let transaction = config.client.submit_and_wait(&tx).await?.into_inner();
let transaction_info = transaction.transaction_info()?;
info!(
"register_continuous_memorypage: {}; gas used: {}",
"register_continuous_memory_page: {}; gas used: {}",
transaction_info.hash.to_string(),
transaction_info.gas_used
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
use crate::config::AppConfig;
use crate::contracts_caller::memory_page_fact_registry::types::register_continuous_page_batch::MemoryPageEntries;
use crate::contracts_caller::transaction_helper::build_transaction;
use std::str::FromStr;

use aptos_sdk::move_types::identifier::Identifier;
use aptos_sdk::move_types::language_storage::ModuleId;
use aptos_sdk::move_types::u256::U256;
use aptos_sdk::move_types::value::{serialize_values, MoveValue};
use aptos_sdk::types::transaction::{EntryFunction, TransactionPayload};
use itertools::Itertools;
use log::info;
use std::str::FromStr;

use crate::config::AppConfig;
use crate::contracts_caller::memory_page_fact_registry::types::register_continuous_page_batch::MemoryPageEntries;
use crate::contracts_caller::transaction_helper::build_transaction;

pub async fn register_continuous_page_batch(
config: &AppConfig,
Expand Down Expand Up @@ -77,24 +79,14 @@ pub async fn register_continuous_page_batch(
};
let transaction_info = transaction.transaction_info()?;
info!(
"register_continuous_memorypage_batch: {}; gas used: {}",
"register_continuous_memory_page_batch: {}; gas used: {}",
transaction_info.hash.to_string(),
transaction_info.gas_used
);

if !transaction.success() {
success = false;
new_remaining_data.extend(chunk);
break;
}
}

if success {
break;
} else {
remaining_data = new_remaining_data;
chunk_size /= 2;
}
remaining_data = new_remaining_data;
chunk_size /= 2;
}
Ok(success)
}
Original file line number Diff line number Diff line change
@@ -1,34 +1,23 @@
use std::fs::File;
use std::io::BufReader;

use crate::contracts_caller::memory_page_fact_registry::types::register_continuous_memorypage::ContinuousMemorypage;
use crate::contracts_caller::memory_page_fact_registry::types::register_continuous_memory_page::ContinuousMemoryPage;
use crate::contracts_caller::memory_page_fact_registry::types::register_continuous_page_batch::MemoryPageEntries;

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)?;
let byte = include_bytes!(
"../../data_samples/memory_page_fact_registry/register_continuous_page_batch.json"
);
let memory_page_entries: MemoryPageEntries = serde_json::from_slice(byte)?;
Ok(memory_page_entries)
}

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)?;
pub fn sample_register_continuous_page() -> anyhow::Result<ContinuousMemoryPage> {
let byte =
include_bytes!("../../data_samples/memory_page_fact_registry/register_memory_page.json");
let continuous_memmory_page: ContinuousMemoryPage = serde_json::from_slice(byte)?;
Ok(continuous_memmory_page)
}

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)?;
let byte = include_bytes!("../../data_samples/memory_page_fact_registry/large_data_register_continuous_page_batch.json");
let memory_page_entries: MemoryPageEntries = serde_json::from_slice(byte)?;
Ok(memory_page_entries)
}
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pub mod register_continuous_memorypage;
pub mod register_continuous_memory_page;
pub mod register_continuous_page_batch;
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use serde::Deserialize;

#[derive(Deserialize, Clone, Debug)]
#[serde(rename_all = "camelCase")]
pub struct ContinuousMemorypage {
pub struct ContinuousMemoryPage {
pub start_addr: String,
pub values: Vec<String>,
pub z: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use crate::contracts_caller::memory_page_fact_registry::types::register_continuous_memorypage::ContinuousMemorypage;
use serde::Deserialize;

use crate::contracts_caller::memory_page_fact_registry::types::register_continuous_memory_page::ContinuousMemoryPage;

#[derive(Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct MemoryPageEntries {
pub memory_page_entries: Vec<ContinuousMemorypage>,
pub memory_page_entries: Vec<ContinuousMemoryPage>,
}
1 change: 0 additions & 1 deletion tests/flow_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ mod tests {
use aptos_testcontainer::test_utils::aptos_container_test_utils::{lazy_aptos_container, run};
use log::info;
use test_log::test;

use verifier_onchain_services::config::{AppConfig, EnvConfig};
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;
Expand Down
4 changes: 2 additions & 2 deletions tests/memory_page_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ mod tests {
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_memory_page::register_continuous_memory_page;
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};

Expand Down Expand Up @@ -58,7 +58,7 @@ mod tests {
.await?;

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

let large_data_register_continuous_page_batch_input =
sample_large_data_register_continuous_page_batch()?;
Expand Down

0 comments on commit d130e9b

Please sign in to comment.