Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ jobs:
fmt:
name: cargo fmt
runs-on: ubuntu-latest
container:
image: rust:1.83-bookworm
steps:
- uses: actions/checkout@v3
- run: |
rustup component add rustfmt
cargo fmt --all -- --check
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- uses: actions-rust-lang/setup-rust-toolchain@11df97af8e8102fd60b60a77dfbf58d40cd843b8 # v1
with:
# Imports formatting is an unstable feature, so we need to use nightly
toolchain: nightly
components: rustfmt
cache: false
- run: cargo +nightly fmt --all -- --check

clippy:
name: cargo clippy
Expand Down
6 changes: 6 additions & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
edition = "2021"

# Enable nightly features required for formatting imports
unstable_features = true
imports_granularity = "Crate"
group_imports = "StdExternalCrate"
reorder_modules = true
2 changes: 1 addition & 1 deletion tap_aggregator/src/aggregator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ mod tests {

use alloy::{dyn_abi::Eip712Domain, primitives::Address, signers::local::PrivateKeySigner};
use rstest::*;
use tap_core::{receipt::Receipt, signed_message::EIP712SignedMessage, tap_eip712_domain};

use crate::aggregator;
use tap_core::{receipt::Receipt, signed_message::EIP712SignedMessage, tap_eip712_domain};

#[fixture]
fn keys() -> (PrivateKeySigner, Address) {
Expand Down
3 changes: 1 addition & 2 deletions tap_aggregator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ use alloy::{dyn_abi::Eip712Domain, primitives::Address, signers::local::PrivateK
use anyhow::Result;
use clap::Parser;
use log::{debug, info};
use tap_core::tap_eip712_domain;

use tap_aggregator::{metrics, server};
use tap_core::tap_eip712_domain;

#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
Expand Down
10 changes: 4 additions & 6 deletions tap_aggregator/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,21 +388,19 @@ fn create_json_rpc_service(
#[cfg(test)]
#[allow(clippy::too_many_arguments)]
mod tests {
use std::collections::HashSet;
use std::str::FromStr;
use std::{collections::HashSet, str::FromStr};

use alloy::{dyn_abi::Eip712Domain, primitives::Address, signers::local::PrivateKeySigner};
use jsonrpsee::{core::client::ClientT, http_client::HttpClientBuilder, rpc_params};
use rand::prelude::*;
use rand::seq::SliceRandom;
use rand::{prelude::*, seq::SliceRandom};
use rstest::*;

use crate::server;
use tap_core::{
rav::ReceiptAggregateVoucher, receipt::Receipt, signed_message::EIP712SignedMessage,
tap_eip712_domain,
};

use crate::server;

#[derive(Clone)]
struct Keys {
wallet: PrivateKeySigner,
Expand Down
1 change: 0 additions & 1 deletion tap_aggregator/tests/aggregate_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
use std::{collections::HashSet, str::FromStr};

use alloy::{primitives::Address, signers::local::PrivateKeySigner};

use jsonrpsee::{core::client::ClientT, http_client::HttpClientBuilder, rpc_params};
use tap_aggregator::{
grpc::{tap_aggregator_client::TapAggregatorClient, RavRequest},
Expand Down
6 changes: 2 additions & 4 deletions tap_core/benches/timeline_aggretion_protocol_benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@

use std::str::FromStr;

use alloy::dyn_abi::Eip712Domain;
use alloy::primitives::Address;
use alloy::signers::local::PrivateKeySigner;
use alloy::{dyn_abi::Eip712Domain, primitives::Address, signers::local::PrivateKeySigner};
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use tap_core::tap_eip712_domain;
use tap_core::{
rav::ReceiptAggregateVoucher, receipt::Receipt, signed_message::EIP712SignedMessage,
tap_eip712_domain,
};

pub fn create_and_sign_receipt(
Expand Down
6 changes: 4 additions & 2 deletions tap_core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
//! Module containing Error type and Result typedef
//!

use crate::{rav::ReceiptAggregateVoucher, receipt::ReceiptError};
use alloy::primitives::{Address, SignatureError};
use std::result::Result as StdResult;

use alloy::primitives::{Address, SignatureError};
use thiserror::Error as ThisError;

use crate::{rav::ReceiptAggregateVoucher, receipt::ReceiptError};

/// Error type for the TAP protocol
#[derive(ThisError, Debug)]
pub enum Error {
Expand Down
26 changes: 16 additions & 10 deletions tap_core/src/manager/context/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,21 @@
//! This module provides an in-memory implementation of the TAP manager context.
//! It is useful for testing and development purposes.

use std::{
collections::HashMap,
ops::RangeBounds,
sync::{Arc, RwLock},
};

use alloy::primitives::Address;
use async_trait::async_trait;

use crate::{
manager::adapters::*,
rav::SignedRAV,
receipt::{checks::StatefulTimestampCheck, state::Checking, ReceiptWithState},
signed_message::MessageId,
};
use alloy::primitives::Address;
use async_trait::async_trait;
use std::ops::RangeBounds;
use std::sync::RwLock;
use std::{collections::HashMap, sync::Arc};

pub type EscrowStorage = Arc<RwLock<HashMap<Address, u128>>>;
pub type QueryAppraisals = Arc<RwLock<HashMap<MessageId, u128>>>;
Expand Down Expand Up @@ -259,6 +263,13 @@ impl EscrowHandler for InMemoryContext {
}

pub mod checks {
use std::{
collections::{HashMap, HashSet},
sync::{Arc, RwLock},
};

use alloy::{dyn_abi::Eip712Domain, primitives::Address};

use crate::{
receipt::{
checks::{Check, CheckError, CheckResult, ReceiptCheck},
Expand All @@ -267,11 +278,6 @@ pub mod checks {
},
signed_message::MessageId,
};
use alloy::{dyn_abi::Eip712Domain, primitives::Address};
use std::{
collections::{HashMap, HashSet},
sync::{Arc, RwLock},
};

pub fn get_full_list_of_checks(
domain_separator: Eip712Domain,
Expand Down
6 changes: 2 additions & 4 deletions tap_core/src/rav.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,10 @@ mod request;

use std::cmp;

use alloy::primitives::Address;
use alloy::sol;
use alloy::{primitives::Address, sol};
use serde::{Deserialize, Serialize};

use crate::Error;
use crate::{receipt::Receipt, signed_message::EIP712SignedMessage};
use crate::{receipt::Receipt, signed_message::EIP712SignedMessage, Error};

/// EIP712 signed message for ReceiptAggregateVoucher
pub type SignedRAV = EIP712SignedMessage<ReceiptAggregateVoucher>;
Expand Down
8 changes: 5 additions & 3 deletions tap_core/src/rav/request.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// Copyright 2023-, Semiotic AI, Inc.
// SPDX-License-Identifier: Apache-2.0

use crate::receipt::state::Reserved;
use crate::Error;
use crate::{
rav::{ReceiptAggregateVoucher, SignedRAV},
receipt::{state::Failed, ReceiptWithState},
receipt::{
state::{Failed, Reserved},
ReceiptWithState,
},
Error,
};

/// Request to `tap_aggregator` to aggregate receipts into a Signed RAV.
Expand Down
31 changes: 15 additions & 16 deletions tap_core/src/receipt/checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,18 @@
//! let my_check: ReceiptCheck = Arc::new(MyCheck);
//! ```

use crate::signed_message::{SignatureBytes, SignatureBytesExt};

use super::{
state::{Checking, Failed},
Context, ReceiptError, ReceiptWithState,
};
use std::{
collections::HashSet,
ops::Deref,
sync::{Arc, RwLock},
};

use super::{
state::{Checking, Failed},
Context, ReceiptError, ReceiptWithState,
};
use crate::signed_message::{SignatureBytes, SignatureBytesExt};

/// ReceiptCheck is a type alias for an Arc of a struct that implements the `Check` trait.
pub type ReceiptCheck = Arc<dyn Check + Sync + Send>;

Expand Down Expand Up @@ -200,19 +200,18 @@ impl CheckBatch for UniqueCheck {

#[cfg(test)]
mod tests {
use std::str::FromStr;
use std::time::Duration;
use std::time::SystemTime;

use alloy::dyn_abi::Eip712Domain;
use alloy::primitives::Address;
use alloy::signers::local::PrivateKeySigner;
use alloy::sol_types::eip712_domain;
use std::{
str::FromStr,
time::{Duration, SystemTime},
};

use crate::receipt::Receipt;
use crate::signed_message::EIP712SignedMessage;
use alloy::{
dyn_abi::Eip712Domain, primitives::Address, signers::local::PrivateKeySigner,
sol_types::eip712_domain,
};

use super::*;
use crate::{receipt::Receipt, signed_message::EIP712SignedMessage};

fn create_signed_receipt_with_custom_value(value: u128) -> ReceiptWithState<Checking> {
let wallet: PrivateKeySigner = PrivateKeySigner::random();
Expand Down
10 changes: 7 additions & 3 deletions tap_core/src/receipt/receipt_sol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,14 @@ impl Receipt {

#[cfg(test)]
mod receipt_unit_test {
use super::*;
use std::{
str::FromStr,
time::{SystemTime, UNIX_EPOCH},
};

use rstest::*;
use std::str::FromStr;
use std::time::{SystemTime, UNIX_EPOCH};

use super::*;

#[fixture]
fn allocation_ids() -> Vec<Address> {
Expand Down
10 changes: 6 additions & 4 deletions tap_core/src/receipt/received_receipt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@

use alloy::dyn_abi::Eip712Domain;

use super::checks::CheckError;
use super::{Context, Receipt, ReceiptError, ReceiptResult, SignedReceipt};
use crate::receipt::state::{AwaitingReserve, Checking, Failed, ReceiptState, Reserved};
use super::{checks::CheckError, Context, Receipt, ReceiptError, ReceiptResult, SignedReceipt};
use crate::{
manager::adapters::EscrowHandler, receipt::checks::ReceiptCheck,
manager::adapters::EscrowHandler,
receipt::{
checks::ReceiptCheck,
state::{AwaitingReserve, Checking, Failed, ReceiptState, Reserved},
},
signed_message::EIP712SignedMessage,
};

Expand Down
1 change: 0 additions & 1 deletion tap_core/tests/escrow_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use std::{

use alloy::signers::local::PrivateKeySigner;
use rstest::*;

use tap_core::{
manager::{adapters::EscrowHandler, context::memory::InMemoryContext},
receipt::checks::StatefulTimestampCheck,
Expand Down
21 changes: 13 additions & 8 deletions tap_core/tests/rav_test.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
// Copyright 2023-, Semiotic AI, Inc.
// SPDX-License-Identifier: Apache-2.0

use std::collections::HashMap;
use std::sync::RwLock;
use std::{str::FromStr, sync::Arc};
use std::{
collections::HashMap,
str::FromStr,
sync::{Arc, RwLock},
};

use alloy::dyn_abi::Eip712Domain;
#[allow(deprecated)]
use alloy::primitives::{Address, PrimitiveSignature, Signature};
use alloy::signers::local::{coins_bip39::English, MnemonicBuilder, PrivateKeySigner};
use alloy::{
dyn_abi::Eip712Domain,
signers::local::{coins_bip39::English, MnemonicBuilder, PrivateKeySigner},
};
use rstest::*;

use tap_core::manager::context::memory::InMemoryContext;
use tap_core::{
manager::adapters::{RAVRead, RAVStore},
manager::{
adapters::{RAVRead, RAVStore},
context::memory::InMemoryContext,
},
rav::ReceiptAggregateVoucher,
receipt::{checks::StatefulTimestampCheck, Receipt},
signed_message::EIP712SignedMessage,
Expand Down
21 changes: 10 additions & 11 deletions tap_core/tests/receipt_test.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
use alloy::dyn_abi::Eip712Domain;
use alloy::primitives::Address;
use alloy::signers::local::PrivateKeySigner;
use std::{
collections::HashMap,
str::FromStr,
sync::{Arc, RwLock},
};

use alloy::{dyn_abi::Eip712Domain, primitives::Address, signers::local::PrivateKeySigner};
// Copyright 2023-, Semiotic AI, Inc.
// SPDX-License-Identifier: Apache-2.0
use rand::seq::SliceRandom;
use rand::thread_rng;
use std::collections::HashMap;
use std::str::FromStr;
use std::sync::{Arc, RwLock};
use tap_core::manager::context::memory::InMemoryContext;
use tap_core::receipt::{state::Checking, ReceiptWithState};

use rstest::*;
use tap_core::receipt::checks::StatefulTimestampCheck;
use tap_core::{
manager::adapters::ReceiptStore, receipt::Receipt, signed_message::EIP712SignedMessage,
manager::{adapters::ReceiptStore, context::memory::InMemoryContext},
receipt::{checks::StatefulTimestampCheck, state::Checking, Receipt, ReceiptWithState},
signed_message::EIP712SignedMessage,
tap_eip712_domain,
};

Expand Down
1 change: 0 additions & 1 deletion tap_integration_tests/tests/indexer_mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use jsonrpsee::{
rpc_params,
server::{ServerBuilder, ServerHandle},
};

use tap_aggregator::jsonrpsee_helpers;
use tap_core::{
manager::{
Expand Down
1 change: 0 additions & 1 deletion tap_integration_tests/tests/showcase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ use jsonrpsee::{
};
use rand::{rngs::StdRng, Rng, SeedableRng};
use rstest::*;

use tap_aggregator::{jsonrpsee_helpers, server as agg_server};
use tap_core::{
manager::context::memory::{checks::get_full_list_of_checks, *},
Expand Down
Loading