Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): Supply EIP712 domain sep with prefilled version and name #210

Merged
merged 1 commit into from
Feb 2, 2024
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
13 changes: 5 additions & 8 deletions tap_aggregator/src/aggregator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,14 @@ mod tests {
use std::str::FromStr;

use alloy_primitives::Address;
use alloy_sol_types::{eip712_domain, Eip712Domain};
use alloy_sol_types::Eip712Domain;
use ethers_signers::{LocalWallet, Signer};
use rstest::*;

use crate::aggregator;
use tap_core::{eip_712_signed_message::EIP712SignedMessage, tap_receipt::Receipt};
use tap_core::{
eip_712_signed_message::EIP712SignedMessage, tap_eip712_domain, tap_receipt::Receipt,
};

#[fixture]
fn keys() -> (LocalWallet, Address) {
Expand All @@ -146,12 +148,7 @@ mod tests {

#[fixture]
fn domain_separator() -> Eip712Domain {
eip712_domain! {
name: "TAP",
version: "1",
chain_id: 1,
verifying_contract: Address::from([0x11u8; 20]),
}
tap_eip712_domain(1, Address::from([0x11u8; 20]))
}

#[rstest]
Expand Down
12 changes: 4 additions & 8 deletions tap_aggregator/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,15 +241,16 @@ mod tests {
use std::str::FromStr;

use alloy_primitives::Address;
use alloy_sol_types::{eip712_domain, Eip712Domain};
use alloy_sol_types::Eip712Domain;
use ethers_signers::{coins_bip39::English, LocalWallet, MnemonicBuilder, Signer};
use jsonrpsee::{core::client::ClientT, http_client::HttpClientBuilder, rpc_params};
use rstest::*;

use crate::server;
use tap_core::{
eip_712_signed_message::EIP712SignedMessage,
receipt_aggregate_voucher::ReceiptAggregateVoucher, tap_receipt::Receipt,
receipt_aggregate_voucher::ReceiptAggregateVoucher, tap_eip712_domain,
tap_receipt::Receipt,
};

#[fixture]
Expand Down Expand Up @@ -277,12 +278,7 @@ mod tests {

#[fixture]
fn domain_separator() -> Eip712Domain {
eip712_domain! {
name: "TAP",
version: "1",
chain_id: 1,
verifying_contract: Address::from([0x11u8; 20]),
}
tap_eip712_domain(1, Address::from([0x11u8; 20]))
}

#[fixture]
Expand Down
10 changes: 3 additions & 7 deletions tap_core/benches/timeline_aggretion_protocol_benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
use std::str::FromStr;

use alloy_primitives::Address;
use alloy_sol_types::{eip712_domain, Eip712Domain};
use alloy_sol_types::Eip712Domain;
use criterion::async_executor::AsyncStdExecutor;
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use ethers::signers::{LocalWallet, Signer, Wallet};
use ethers_core::k256::ecdsa::SigningKey;
use rand_core::OsRng;
use tap_core::tap_eip712_domain;
use tap_core::{
eip_712_signed_message::EIP712SignedMessage,
receipt_aggregate_voucher::ReceiptAggregateVoucher, tap_receipt::Receipt,
Expand All @@ -39,12 +40,7 @@ pub async fn create_and_sign_receipt(
}

pub fn criterion_benchmark(c: &mut Criterion) {
let domain_seperator = eip712_domain! {
name: "TAP",
version: "1",
chain_id: 1,
verifying_contract: Address::from([0x11u8; 20]),
};
let domain_seperator = tap_eip712_domain(1, Address::from([0x11u8; 20]));

let async_runtime = Runtime::new().unwrap();

Expand Down
10 changes: 3 additions & 7 deletions tap_core/src/adapters/test/rav_storage_adapter_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ mod rav_storage_adapter_unit_test {
use std::{str::FromStr, sync::Arc};

use alloy_primitives::Address;
use alloy_sol_types::{eip712_domain, Eip712Domain};
use alloy_sol_types::Eip712Domain;
use ethers::signers::coins_bip39::English;
use ethers::signers::{LocalWallet, MnemonicBuilder};
use rstest::*;
Expand All @@ -16,19 +16,15 @@ mod rav_storage_adapter_unit_test {
use crate::adapters::{
rav_storage_adapter::RAVStore, rav_storage_adapter_mock::RAVStorageAdapterMock,
};
use crate::tap_eip712_domain;
use crate::{
eip_712_signed_message::EIP712SignedMessage,
receipt_aggregate_voucher::ReceiptAggregateVoucher, tap_receipt::Receipt,
};

#[fixture]
fn domain_separator() -> Eip712Domain {
eip712_domain! {
name: "TAP",
version: "1",
chain_id: 1,
verifying_contract: Address::from([0x11u8; 20]),
}
tap_eip712_domain(1, Address::from([0x11u8; 20]))
}

#[rstest]
Expand Down
10 changes: 3 additions & 7 deletions tap_core/src/adapters/test/receipt_checks_adapter_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ mod receipt_checks_adapter_unit_test {
};

use alloy_primitives::Address;
use alloy_sol_types::{eip712_domain, Eip712Domain};
use alloy_sol_types::Eip712Domain;
use ethers::signers::{coins_bip39::English, LocalWallet, MnemonicBuilder};
use futures::{stream, StreamExt};
use rstest::*;
Expand All @@ -22,17 +22,13 @@ mod receipt_checks_adapter_unit_test {
receipt_checks_adapter_mock::ReceiptChecksAdapterMock,
},
eip_712_signed_message::EIP712SignedMessage,
tap_eip712_domain,
tap_receipt::{get_full_list_of_checks, Receipt, ReceivedReceipt},
};

#[fixture]
fn domain_separator() -> Eip712Domain {
eip712_domain! {
name: "TAP",
version: "1",
chain_id: 1,
verifying_contract: Address::from([0x11u8; 20]),
}
tap_eip712_domain(1, Address::from([0x11u8; 20]))
}

#[rstest]
Expand Down
10 changes: 3 additions & 7 deletions tap_core/src/adapters/test/receipt_storage_adapter_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ mod receipt_storage_adapter_unit_test {
use std::sync::Arc;

use alloy_primitives::Address;
use alloy_sol_types::{eip712_domain, Eip712Domain};
use alloy_sol_types::Eip712Domain;
use ethers::signers::coins_bip39::English;
use ethers::signers::{LocalWallet, MnemonicBuilder};
use rstest::*;
Expand All @@ -20,6 +20,7 @@ mod receipt_storage_adapter_unit_test {
receipt_storage_adapter::ReceiptStore,
receipt_storage_adapter_mock::ReceiptStorageAdapterMock,
};
use crate::tap_eip712_domain;
use crate::tap_receipt::ReceivedReceipt;
use crate::{
eip_712_signed_message::EIP712SignedMessage, tap_receipt::get_full_list_of_checks,
Expand All @@ -28,12 +29,7 @@ mod receipt_storage_adapter_unit_test {

#[fixture]
fn domain_separator() -> Eip712Domain {
eip712_domain! {
name: "TAP",
version: "1",
chain_id: 1,
verifying_contract: Address::from([0x11u8; 20]),
}
tap_eip712_domain(1, Address::from([0x11u8; 20]))
}

#[rstest]
Expand Down
25 changes: 17 additions & 8 deletions tap_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

use std::time::{SystemTime, UNIX_EPOCH};

use alloy_sol_types::eip712_domain;
use thiserror::Error;

pub mod adapters;
Expand All @@ -28,18 +29,31 @@ pub(crate) fn get_current_timestamp_u64_ns() -> Result<u64> {
.as_nanos() as u64)
}

pub fn tap_eip712_domain(
chain_id: u64,
verifying_contract_address: alloy_primitives::Address,
) -> alloy_sol_types::Eip712Domain {
eip712_domain! {
name: "TAP",
version: "1",
chain_id: chain_id,
verifying_contract: verifying_contract_address,
}
}

#[cfg(test)]
mod tap_tests {
use std::str::FromStr;

use alloy_primitives::Address;
use alloy_sol_types::{eip712_domain, Eip712Domain};
use alloy_sol_types::Eip712Domain;
use ethers::signers::{coins_bip39::English, LocalWallet, MnemonicBuilder, Signer};
use rstest::*;

use crate::{
eip_712_signed_message::EIP712SignedMessage,
receipt_aggregate_voucher::ReceiptAggregateVoucher, tap_receipt::Receipt,
receipt_aggregate_voucher::ReceiptAggregateVoucher, tap_eip712_domain,
tap_receipt::Receipt,
};

#[fixture]
Expand Down Expand Up @@ -67,12 +81,7 @@ mod tap_tests {

#[fixture]
fn domain_separator() -> Eip712Domain {
eip712_domain! {
name: "TAP",
version: "1",
chain_id: 1,
verifying_contract: Address::from([0x11u8; 20]),
}
tap_eip712_domain(1, Address::from([0x11u8; 20]))
}

#[rstest]
Expand Down
11 changes: 3 additions & 8 deletions tap_core/src/tap_manager/test/manager_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ mod manager_unit_test {
};

use alloy_primitives::Address;
use alloy_sol_types::{eip712_domain, Eip712Domain};
use alloy_sol_types::Eip712Domain;
use ethers::signers::{coins_bip39::English, LocalWallet, MnemonicBuilder, Signer};
use rstest::*;
use tokio::sync::RwLock;
Expand All @@ -24,7 +24,7 @@ mod manager_unit_test {
receipt_storage_adapter::ReceiptRead,
},
eip_712_signed_message::EIP712SignedMessage,
get_current_timestamp_u64_ns,
get_current_timestamp_u64_ns, tap_eip712_domain,
tap_receipt::{get_full_list_of_checks, Receipt, ReceiptCheck},
};

Expand Down Expand Up @@ -63,12 +63,7 @@ mod manager_unit_test {

#[fixture]
fn domain_separator() -> Eip712Domain {
eip712_domain! {
name: "TAP",
version: "1",
chain_id: 1,
verifying_contract: Address::from([0x11u8; 20]),
}
tap_eip712_domain(1, Address::from([0x11u8; 20]))
}

#[fixture]
Expand Down
11 changes: 3 additions & 8 deletions tap_core/src/tap_receipt/tests/received_receipt_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ mod received_receipt_unit_test {
};

use alloy_primitives::Address;
use alloy_sol_types::{eip712_domain, Eip712Domain};
use alloy_sol_types::Eip712Domain;
use ethers::signers::{coins_bip39::English, LocalWallet, MnemonicBuilder, Signer};
use rstest::*;
use tokio::sync::RwLock;
Expand All @@ -24,7 +24,7 @@ mod received_receipt_unit_test {
receipt_storage_adapter_mock::ReceiptStorageAdapterMock,
},
eip_712_signed_message::EIP712SignedMessage,
get_current_timestamp_u64_ns,
get_current_timestamp_u64_ns, tap_eip712_domain,
tap_receipt::{
get_full_list_of_checks, Receipt, ReceiptAuditor, ReceiptCheck, ReceivedReceipt,
},
Expand Down Expand Up @@ -121,12 +121,7 @@ mod received_receipt_unit_test {

#[fixture]
fn domain_separator() -> Eip712Domain {
eip712_domain! {
name: "TAP",
version: "1",
chain_id: 1,
verifying_contract: Address::from([0x11u8; 20]),
}
tap_eip712_domain(1, Address::from([0x11u8; 20]))
}

#[rstest]
Expand Down
10 changes: 3 additions & 7 deletions tap_integration_tests/tests/showcase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use std::{
};

use alloy_primitives::Address;
use alloy_sol_types::{eip712_domain, Eip712Domain};
use alloy_sol_types::Eip712Domain;
use anyhow::{Error, Result};
use ethers::signers::{coins_bip39::English, LocalWallet, MnemonicBuilder, Signer};
use jsonrpsee::{
Expand All @@ -33,6 +33,7 @@ use tap_core::{
receipt_storage_adapter_mock::ReceiptStorageAdapterMock,
},
eip_712_signed_message::EIP712SignedMessage,
tap_eip712_domain,
tap_manager::SignedRAV,
tap_receipt::{Receipt, ReceiptCheck, ReceivedReceipt},
};
Expand Down Expand Up @@ -125,12 +126,7 @@ fn allocation_ids() -> Vec<Address> {
// Domain separator is used to sign receipts/RAVs according to EIP-712
#[fixture]
fn domain_separator() -> Eip712Domain {
eip712_domain! {
name: "TAP",
version: "1",
chain_id: 1,
verifying_contract: Address::from([0x11u8; 20]),
}
tap_eip712_domain(1, Address::from([0x11u8; 20]))
}

// Query price will typically be set by the Indexer. It's assumed to be part of the Indexer service.
Expand Down
Loading