Skip to content

Commit 2ed564b

Browse files
authored
feat(core): Supply EIP712 domain sep with prefilled version and name (#210)
Signed-off-by: Alexis Asseman <[email protected]>
1 parent 2f7c268 commit 2ed564b

File tree

10 files changed

+47
-75
lines changed

10 files changed

+47
-75
lines changed

tap_aggregator/src/aggregator.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,14 @@ mod tests {
117117
use std::str::FromStr;
118118

119119
use alloy_primitives::Address;
120-
use alloy_sol_types::{eip712_domain, Eip712Domain};
120+
use alloy_sol_types::Eip712Domain;
121121
use ethers_signers::{LocalWallet, Signer};
122122
use rstest::*;
123123

124124
use crate::aggregator;
125-
use tap_core::{eip_712_signed_message::EIP712SignedMessage, tap_receipt::Receipt};
125+
use tap_core::{
126+
eip_712_signed_message::EIP712SignedMessage, tap_eip712_domain, tap_receipt::Receipt,
127+
};
126128

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

147149
#[fixture]
148150
fn domain_separator() -> Eip712Domain {
149-
eip712_domain! {
150-
name: "TAP",
151-
version: "1",
152-
chain_id: 1,
153-
verifying_contract: Address::from([0x11u8; 20]),
154-
}
151+
tap_eip712_domain(1, Address::from([0x11u8; 20]))
155152
}
156153

157154
#[rstest]

tap_aggregator/src/server.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -241,15 +241,16 @@ mod tests {
241241
use std::str::FromStr;
242242

243243
use alloy_primitives::Address;
244-
use alloy_sol_types::{eip712_domain, Eip712Domain};
244+
use alloy_sol_types::Eip712Domain;
245245
use ethers_signers::{coins_bip39::English, LocalWallet, MnemonicBuilder, Signer};
246246
use jsonrpsee::{core::client::ClientT, http_client::HttpClientBuilder, rpc_params};
247247
use rstest::*;
248248

249249
use crate::server;
250250
use tap_core::{
251251
eip_712_signed_message::EIP712SignedMessage,
252-
receipt_aggregate_voucher::ReceiptAggregateVoucher, tap_receipt::Receipt,
252+
receipt_aggregate_voucher::ReceiptAggregateVoucher, tap_eip712_domain,
253+
tap_receipt::Receipt,
253254
};
254255

255256
#[fixture]
@@ -277,12 +278,7 @@ mod tests {
277278

278279
#[fixture]
279280
fn domain_separator() -> Eip712Domain {
280-
eip712_domain! {
281-
name: "TAP",
282-
version: "1",
283-
chain_id: 1,
284-
verifying_contract: Address::from([0x11u8; 20]),
285-
}
281+
tap_eip712_domain(1, Address::from([0x11u8; 20]))
286282
}
287283

288284
#[fixture]

tap_core/benches/timeline_aggretion_protocol_benchmark.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@
1111
use std::str::FromStr;
1212

1313
use alloy_primitives::Address;
14-
use alloy_sol_types::{eip712_domain, Eip712Domain};
14+
use alloy_sol_types::Eip712Domain;
1515
use criterion::async_executor::AsyncStdExecutor;
1616
use criterion::{black_box, criterion_group, criterion_main, Criterion};
1717
use ethers::signers::{LocalWallet, Signer, Wallet};
1818
use ethers_core::k256::ecdsa::SigningKey;
1919
use rand_core::OsRng;
20+
use tap_core::tap_eip712_domain;
2021
use tap_core::{
2122
eip_712_signed_message::EIP712SignedMessage,
2223
receipt_aggregate_voucher::ReceiptAggregateVoucher, tap_receipt::Receipt,
@@ -39,12 +40,7 @@ pub async fn create_and_sign_receipt(
3940
}
4041

4142
pub fn criterion_benchmark(c: &mut Criterion) {
42-
let domain_seperator = eip712_domain! {
43-
name: "TAP",
44-
version: "1",
45-
chain_id: 1,
46-
verifying_contract: Address::from([0x11u8; 20]),
47-
};
43+
let domain_seperator = tap_eip712_domain(1, Address::from([0x11u8; 20]));
4844

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

tap_core/src/adapters/test/rav_storage_adapter_test.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ mod rav_storage_adapter_unit_test {
66
use std::{str::FromStr, sync::Arc};
77

88
use alloy_primitives::Address;
9-
use alloy_sol_types::{eip712_domain, Eip712Domain};
9+
use alloy_sol_types::Eip712Domain;
1010
use ethers::signers::coins_bip39::English;
1111
use ethers::signers::{LocalWallet, MnemonicBuilder};
1212
use rstest::*;
@@ -16,19 +16,15 @@ mod rav_storage_adapter_unit_test {
1616
use crate::adapters::{
1717
rav_storage_adapter::RAVStore, rav_storage_adapter_mock::RAVStorageAdapterMock,
1818
};
19+
use crate::tap_eip712_domain;
1920
use crate::{
2021
eip_712_signed_message::EIP712SignedMessage,
2122
receipt_aggregate_voucher::ReceiptAggregateVoucher, tap_receipt::Receipt,
2223
};
2324

2425
#[fixture]
2526
fn domain_separator() -> Eip712Domain {
26-
eip712_domain! {
27-
name: "TAP",
28-
version: "1",
29-
chain_id: 1,
30-
verifying_contract: Address::from([0x11u8; 20]),
31-
}
27+
tap_eip712_domain(1, Address::from([0x11u8; 20]))
3228
}
3329

3430
#[rstest]

tap_core/src/adapters/test/receipt_checks_adapter_test.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ mod receipt_checks_adapter_unit_test {
1010
};
1111

1212
use alloy_primitives::Address;
13-
use alloy_sol_types::{eip712_domain, Eip712Domain};
13+
use alloy_sol_types::Eip712Domain;
1414
use ethers::signers::{coins_bip39::English, LocalWallet, MnemonicBuilder};
1515
use futures::{stream, StreamExt};
1616
use rstest::*;
@@ -22,17 +22,13 @@ mod receipt_checks_adapter_unit_test {
2222
receipt_checks_adapter_mock::ReceiptChecksAdapterMock,
2323
},
2424
eip_712_signed_message::EIP712SignedMessage,
25+
tap_eip712_domain,
2526
tap_receipt::{get_full_list_of_checks, Receipt, ReceivedReceipt},
2627
};
2728

2829
#[fixture]
2930
fn domain_separator() -> Eip712Domain {
30-
eip712_domain! {
31-
name: "TAP",
32-
version: "1",
33-
chain_id: 1,
34-
verifying_contract: Address::from([0x11u8; 20]),
35-
}
31+
tap_eip712_domain(1, Address::from([0x11u8; 20]))
3632
}
3733

3834
#[rstest]

tap_core/src/adapters/test/receipt_storage_adapter_test.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ mod receipt_storage_adapter_unit_test {
1010
use std::sync::Arc;
1111

1212
use alloy_primitives::Address;
13-
use alloy_sol_types::{eip712_domain, Eip712Domain};
13+
use alloy_sol_types::Eip712Domain;
1414
use ethers::signers::coins_bip39::English;
1515
use ethers::signers::{LocalWallet, MnemonicBuilder};
1616
use rstest::*;
@@ -20,6 +20,7 @@ mod receipt_storage_adapter_unit_test {
2020
receipt_storage_adapter::ReceiptStore,
2121
receipt_storage_adapter_mock::ReceiptStorageAdapterMock,
2222
};
23+
use crate::tap_eip712_domain;
2324
use crate::tap_receipt::ReceivedReceipt;
2425
use crate::{
2526
eip_712_signed_message::EIP712SignedMessage, tap_receipt::get_full_list_of_checks,
@@ -28,12 +29,7 @@ mod receipt_storage_adapter_unit_test {
2829

2930
#[fixture]
3031
fn domain_separator() -> Eip712Domain {
31-
eip712_domain! {
32-
name: "TAP",
33-
version: "1",
34-
chain_id: 1,
35-
verifying_contract: Address::from([0x11u8; 20]),
36-
}
32+
tap_eip712_domain(1, Address::from([0x11u8; 20]))
3733
}
3834

3935
#[rstest]

tap_core/src/lib.rs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
99
use std::time::{SystemTime, UNIX_EPOCH};
1010

11+
use alloy_sol_types::eip712_domain;
1112
use thiserror::Error;
1213

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

32+
pub fn tap_eip712_domain(
33+
chain_id: u64,
34+
verifying_contract_address: alloy_primitives::Address,
35+
) -> alloy_sol_types::Eip712Domain {
36+
eip712_domain! {
37+
name: "TAP",
38+
version: "1",
39+
chain_id: chain_id,
40+
verifying_contract: verifying_contract_address,
41+
}
42+
}
43+
3144
#[cfg(test)]
3245
mod tap_tests {
3346
use std::str::FromStr;
3447

3548
use alloy_primitives::Address;
36-
use alloy_sol_types::{eip712_domain, Eip712Domain};
49+
use alloy_sol_types::Eip712Domain;
3750
use ethers::signers::{coins_bip39::English, LocalWallet, MnemonicBuilder, Signer};
3851
use rstest::*;
3952

4053
use crate::{
4154
eip_712_signed_message::EIP712SignedMessage,
42-
receipt_aggregate_voucher::ReceiptAggregateVoucher, tap_receipt::Receipt,
55+
receipt_aggregate_voucher::ReceiptAggregateVoucher, tap_eip712_domain,
56+
tap_receipt::Receipt,
4357
};
4458

4559
#[fixture]
@@ -67,12 +81,7 @@ mod tap_tests {
6781

6882
#[fixture]
6983
fn domain_separator() -> Eip712Domain {
70-
eip712_domain! {
71-
name: "TAP",
72-
version: "1",
73-
chain_id: 1,
74-
verifying_contract: Address::from([0x11u8; 20]),
75-
}
84+
tap_eip712_domain(1, Address::from([0x11u8; 20]))
7685
}
7786

7887
#[rstest]

tap_core/src/tap_manager/test/manager_test.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ mod manager_unit_test {
1010
};
1111

1212
use alloy_primitives::Address;
13-
use alloy_sol_types::{eip712_domain, Eip712Domain};
13+
use alloy_sol_types::Eip712Domain;
1414
use ethers::signers::{coins_bip39::English, LocalWallet, MnemonicBuilder, Signer};
1515
use rstest::*;
1616
use tokio::sync::RwLock;
@@ -24,7 +24,7 @@ mod manager_unit_test {
2424
receipt_storage_adapter::ReceiptRead,
2525
},
2626
eip_712_signed_message::EIP712SignedMessage,
27-
get_current_timestamp_u64_ns,
27+
get_current_timestamp_u64_ns, tap_eip712_domain,
2828
tap_receipt::{get_full_list_of_checks, Receipt, ReceiptCheck},
2929
};
3030

@@ -63,12 +63,7 @@ mod manager_unit_test {
6363

6464
#[fixture]
6565
fn domain_separator() -> Eip712Domain {
66-
eip712_domain! {
67-
name: "TAP",
68-
version: "1",
69-
chain_id: 1,
70-
verifying_contract: Address::from([0x11u8; 20]),
71-
}
66+
tap_eip712_domain(1, Address::from([0x11u8; 20]))
7267
}
7368

7469
#[fixture]

tap_core/src/tap_receipt/tests/received_receipt_tests.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ mod received_receipt_unit_test {
1010
};
1111

1212
use alloy_primitives::Address;
13-
use alloy_sol_types::{eip712_domain, Eip712Domain};
13+
use alloy_sol_types::Eip712Domain;
1414
use ethers::signers::{coins_bip39::English, LocalWallet, MnemonicBuilder, Signer};
1515
use rstest::*;
1616
use tokio::sync::RwLock;
@@ -24,7 +24,7 @@ mod received_receipt_unit_test {
2424
receipt_storage_adapter_mock::ReceiptStorageAdapterMock,
2525
},
2626
eip_712_signed_message::EIP712SignedMessage,
27-
get_current_timestamp_u64_ns,
27+
get_current_timestamp_u64_ns, tap_eip712_domain,
2828
tap_receipt::{
2929
get_full_list_of_checks, Receipt, ReceiptAuditor, ReceiptCheck, ReceivedReceipt,
3030
},
@@ -121,12 +121,7 @@ mod received_receipt_unit_test {
121121

122122
#[fixture]
123123
fn domain_separator() -> Eip712Domain {
124-
eip712_domain! {
125-
name: "TAP",
126-
version: "1",
127-
chain_id: 1,
128-
verifying_contract: Address::from([0x11u8; 20]),
129-
}
124+
tap_eip712_domain(1, Address::from([0x11u8; 20]))
130125
}
131126

132127
#[rstest]

tap_integration_tests/tests/showcase.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use std::{
1414
};
1515

1616
use alloy_primitives::Address;
17-
use alloy_sol_types::{eip712_domain, Eip712Domain};
17+
use alloy_sol_types::Eip712Domain;
1818
use anyhow::{Error, Result};
1919
use ethers::signers::{coins_bip39::English, LocalWallet, MnemonicBuilder, Signer};
2020
use jsonrpsee::{
@@ -33,6 +33,7 @@ use tap_core::{
3333
receipt_storage_adapter_mock::ReceiptStorageAdapterMock,
3434
},
3535
eip_712_signed_message::EIP712SignedMessage,
36+
tap_eip712_domain,
3637
tap_manager::SignedRAV,
3738
tap_receipt::{Receipt, ReceiptCheck, ReceivedReceipt},
3839
};
@@ -125,12 +126,7 @@ fn allocation_ids() -> Vec<Address> {
125126
// Domain separator is used to sign receipts/RAVs according to EIP-712
126127
#[fixture]
127128
fn domain_separator() -> Eip712Domain {
128-
eip712_domain! {
129-
name: "TAP",
130-
version: "1",
131-
chain_id: 1,
132-
verifying_contract: Address::from([0x11u8; 20]),
133-
}
129+
tap_eip712_domain(1, Address::from([0x11u8; 20]))
134130
}
135131

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

0 commit comments

Comments
 (0)