diff --git a/Cargo.toml b/Cargo.toml index c5d5831..7837173 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,3 +16,5 @@ anyhow = { version = "1.0.89" } tokio = { version = "1.40.0", features = ["macros", "signal"] } rand = "0.8.5" jsonrpsee = { version = "0.24.7", features = ["macros", "server"] } +insta = { version = "1.41.1", features = ["json"] } +serde_json = { version = "1.0.124", features = ["raw_value"] } diff --git a/tap_aggregator/Cargo.toml b/tap_aggregator/Cargo.toml index 9a92d9a..3e3ae63 100644 --- a/tap_aggregator/Cargo.toml +++ b/tap_aggregator/Cargo.toml @@ -17,9 +17,9 @@ serde.workspace = true alloy.workspace = true anyhow.workspace = true tokio.workspace = true +serde_json.workspace = true jsonrpsee = { workspace = true, features = ["server", "macros"] } clap = { version = "4.5.15", features = ["derive", "env"] } -serde_json = { version = "1.0.124", features = ["raw_value"] } strum = { version = "0.26.3", features = ["derive"] } tracing-subscriber = "0.3.17" log = "0.4.19" diff --git a/tap_core/Cargo.toml b/tap_core/Cargo.toml index 53a9a68..0621a3d 100644 --- a/tap_core/Cargo.toml +++ b/tap_core/Cargo.toml @@ -20,6 +20,8 @@ anymap3 = "1.0.0" [dev-dependencies] criterion = { version = "0.5", features = ["async_std"] } rstest.workspace = true +insta.workspace = true +serde_json.workspace = true [features] diff --git a/tap_core/tests/rav_test.rs b/tap_core/tests/rav_test.rs index 4be8d05..dd12102 100644 --- a/tap_core/tests/rav_test.rs +++ b/tap_core/tests/rav_test.rs @@ -6,8 +6,9 @@ use std::sync::RwLock; use std::{str::FromStr, sync::Arc}; use alloy::dyn_abi::Eip712Domain; -use alloy::primitives::Address; -use alloy::signers::local::PrivateKeySigner; +#[allow(deprecated)] +use alloy::primitives::{Address, PrimitiveSignature, Signature}; +use alloy::signers::local::{coins_bip39::English, MnemonicBuilder, PrivateKeySigner}; use rstest::*; use tap_core::manager::context::memory::InMemoryContext; @@ -39,6 +40,51 @@ fn context() -> InMemoryContext { ) } +#[rstest] +fn check_for_rav_serialization(domain_separator: Eip712Domain) { + let allocation_id = Address::from_str("0xabababababababababababababababababababab").unwrap(); + let wallet = MnemonicBuilder::::default() + .phrase("abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about") + .build() + .unwrap(); + let mut receipts = Vec::new(); + for value in 50..60 { + receipts.push( + EIP712SignedMessage::new( + &domain_separator, + Receipt { + allocation_id, + value, + nonce: value as u64, + timestamp_ns: value as u64, + }, + &wallet, + ) + .unwrap(), + ); + } + + let signed_rav = EIP712SignedMessage::new( + &domain_separator, + ReceiptAggregateVoucher::aggregate_receipts(allocation_id, &receipts, None).unwrap(), + &wallet, + ) + .unwrap(); + + insta::assert_json_snapshot!(receipts); + insta::assert_json_snapshot!(signed_rav); + + let raw_sig = r#"{ + "r": "0x1596dd0d380ede7aa5dec5ed09ea7d1fa8e4bc8dfdb43a4e965bb4f16906e321", + "s": "0x788b69625a031fbd2e769928b63505387df16e7c51f19ff67c782bfec101a387", + "yParity": "0x1C" + }"#; + + // serde_json::from_str::(raw_sig).unwrap(); + #[allow(deprecated)] + serde_json::from_str::(raw_sig).unwrap(); +} + #[rstest] #[tokio::test] async fn rav_storage_adapter_test(domain_separator: Eip712Domain, context: InMemoryContext) { diff --git a/tap_core/tests/snapshots/rav_test__check_for_rav_serialization-2.snap b/tap_core/tests/snapshots/rav_test__check_for_rav_serialization-2.snap new file mode 100644 index 0000000..836c4c7 --- /dev/null +++ b/tap_core/tests/snapshots/rav_test__check_for_rav_serialization-2.snap @@ -0,0 +1,18 @@ +--- +source: tap_core/tests/rav_test.rs +expression: signed_rav +snapshot_kind: text +--- +{ + "message": { + "allocationId": "0xabababababababababababababababababababab", + "timestampNs": 59, + "valueAggregate": 545 + }, + "signature": { + "r": "0x11d760201bac73d4e772d0999a1f9b5f6b8d8979d94ee29b7cb2659d23f2a551", + "s": "0x1036a994ff414de83f24601ab7cc22e0ece134d2199e0b675d94bd8cf7015226", + "yParity": "0x0", + "v": "0x0" + } +} diff --git a/tap_core/tests/snapshots/rav_test__check_for_rav_serialization.snap b/tap_core/tests/snapshots/rav_test__check_for_rav_serialization.snap new file mode 100644 index 0000000..2020b5b --- /dev/null +++ b/tap_core/tests/snapshots/rav_test__check_for_rav_serialization.snap @@ -0,0 +1,147 @@ +--- +source: tap_core/tests/rav_test.rs +expression: receipts +snapshot_kind: text +--- +[ + { + "message": { + "allocation_id": "0xabababababababababababababababababababab", + "timestamp_ns": 50, + "nonce": 50, + "value": 50 + }, + "signature": { + "r": "0x5257bab234e33525cd999db4defc805c2d3b4e51cde3697f43e37ce39473720f", + "s": "0x6c3af14c3d400dfd047fd2da90eb9e8cee863e77cc52742ebcbf080b8d6ec2", + "yParity": "0x1", + "v": "0x1" + } + }, + { + "message": { + "allocation_id": "0xabababababababababababababababababababab", + "timestamp_ns": 51, + "nonce": 51, + "value": 51 + }, + "signature": { + "r": "0x1596dd0d380ede7aa5dec5ed09ea7d1fa8e4bc8dfdb43a4e965bb4f16906e321", + "s": "0x788b69625a031fbd2e769928b63505387df16e7c51f19ff67c782bfec101a387", + "yParity": "0x0", + "v": "0x0" + } + }, + { + "message": { + "allocation_id": "0xabababababababababababababababababababab", + "timestamp_ns": 52, + "nonce": 52, + "value": 52 + }, + "signature": { + "r": "0xb3b8e2c1249fc14183024e28b14f7749ef852c898906c2442f380a26bf07a625", + "s": "0x6925e7dce01d539a658d552e43cfd92d9d204d6997604f8f613977251b964db3", + "yParity": "0x1", + "v": "0x1" + } + }, + { + "message": { + "allocation_id": "0xabababababababababababababababababababab", + "timestamp_ns": 53, + "nonce": 53, + "value": 53 + }, + "signature": { + "r": "0x3b4d08db319497c2cc0d515d25057e28ce44b194a23e84b9d35682f97027c7e3", + "s": "0x232e02eb4b52d302d620867a4c10829e5a307404ea1bcbbd2ee33e8422a18a16", + "yParity": "0x1", + "v": "0x1" + } + }, + { + "message": { + "allocation_id": "0xabababababababababababababababababababab", + "timestamp_ns": 54, + "nonce": 54, + "value": 54 + }, + "signature": { + "r": "0x619d84f659ea3941cdb0656100b2ea8a3d2f5658dbd67f796ebfb8840156530b", + "s": "0x163b236f88207b89452255da8ce196997d8f2f0880081659c780f2093797f75e", + "yParity": "0x1", + "v": "0x1" + } + }, + { + "message": { + "allocation_id": "0xabababababababababababababababababababab", + "timestamp_ns": 55, + "nonce": 55, + "value": 55 + }, + "signature": { + "r": "0x48e1e0e31eaf40eabbcbc3c6d125b7656c0796d51188f89d27194e22f2c5d6bb", + "s": "0xd26efc0ae8cc3646993a20b5aabac1125ecb149ad91d733c702ac9f03222b66", + "yParity": "0x1", + "v": "0x1" + } + }, + { + "message": { + "allocation_id": "0xabababababababababababababababababababab", + "timestamp_ns": 56, + "nonce": 56, + "value": 56 + }, + "signature": { + "r": "0xc3adb8be5db130f563d3a18fc9e742fca84f69a903413e04dc567b9c3aca8626", + "s": "0x564dd73bdd33897c7a085e4eb1bc0ce002b1d65c6006781ab54cd670846fe358", + "yParity": "0x0", + "v": "0x0" + } + }, + { + "message": { + "allocation_id": "0xabababababababababababababababababababab", + "timestamp_ns": 57, + "nonce": 57, + "value": 57 + }, + "signature": { + "r": "0xa0fe51e1b7253daed14f99c9320d0a539ef18b6ead6552947e5c93dde6f40dea", + "s": "0x4277d66d3a8c9f67cddc8d96a71ef8437e47e34a5b5789d7843eb691c3b9864", + "yParity": "0x0", + "v": "0x0" + } + }, + { + "message": { + "allocation_id": "0xabababababababababababababababababababab", + "timestamp_ns": 58, + "nonce": 58, + "value": 58 + }, + "signature": { + "r": "0x26f1657e4b8759867820be12c25e982e15ff9d70aa99fe1fd2587cbb644829de", + "s": "0x5cabbd965f93e544b07e5956c2831148dbf7960b4e2edadfa6ecbf1209dacda4", + "yParity": "0x0", + "v": "0x0" + } + }, + { + "message": { + "allocation_id": "0xabababababababababababababababababababab", + "timestamp_ns": 59, + "nonce": 59, + "value": 59 + }, + "signature": { + "r": "0x90ce08049b9ce9fa38077ebeed0e24558442d8ae001aeff6b9f4b06f4f553c69", + "s": "0x7a873491448ae696555f9d1314b4e78a7cc98a19a6b0c26aad562053dc26a202", + "yParity": "0x1", + "v": "0x1" + } + } +]