Skip to content

Commit a6c5193

Browse files
authored
test: add insta test for serialization of receipts and ravs (#252)
Signed-off-by: Gustavo Inacio <[email protected]>
1 parent 454ed40 commit a6c5193

File tree

6 files changed

+218
-3
lines changed

6 files changed

+218
-3
lines changed

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,5 @@ anyhow = { version = "1.0.89" }
1616
tokio = { version = "1.40.0", features = ["macros", "signal"] }
1717
rand = "0.8.5"
1818
jsonrpsee = { version = "0.24.7", features = ["macros", "server"] }
19+
insta = { version = "1.41.1", features = ["json"] }
20+
serde_json = { version = "1.0.124", features = ["raw_value"] }

tap_aggregator/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ serde.workspace = true
1717
alloy.workspace = true
1818
anyhow.workspace = true
1919
tokio.workspace = true
20+
serde_json.workspace = true
2021
jsonrpsee = { workspace = true, features = ["server", "macros"] }
2122
clap = { version = "4.5.15", features = ["derive", "env"] }
22-
serde_json = { version = "1.0.124", features = ["raw_value"] }
2323
strum = { version = "0.26.3", features = ["derive"] }
2424
tracing-subscriber = "0.3.17"
2525
log = "0.4.19"

tap_core/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ anymap3 = "1.0.0"
2020
[dev-dependencies]
2121
criterion = { version = "0.5", features = ["async_std"] }
2222
rstest.workspace = true
23+
insta.workspace = true
24+
serde_json.workspace = true
2325

2426

2527
[features]

tap_core/tests/rav_test.rs

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ use std::sync::RwLock;
66
use std::{str::FromStr, sync::Arc};
77

88
use alloy::dyn_abi::Eip712Domain;
9-
use alloy::primitives::Address;
10-
use alloy::signers::local::PrivateKeySigner;
9+
#[allow(deprecated)]
10+
use alloy::primitives::{Address, PrimitiveSignature, Signature};
11+
use alloy::signers::local::{coins_bip39::English, MnemonicBuilder, PrivateKeySigner};
1112
use rstest::*;
1213

1314
use tap_core::manager::context::memory::InMemoryContext;
@@ -39,6 +40,51 @@ fn context() -> InMemoryContext {
3940
)
4041
}
4142

43+
#[rstest]
44+
fn check_for_rav_serialization(domain_separator: Eip712Domain) {
45+
let allocation_id = Address::from_str("0xabababababababababababababababababababab").unwrap();
46+
let wallet = MnemonicBuilder::<English>::default()
47+
.phrase("abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about")
48+
.build()
49+
.unwrap();
50+
let mut receipts = Vec::new();
51+
for value in 50..60 {
52+
receipts.push(
53+
EIP712SignedMessage::new(
54+
&domain_separator,
55+
Receipt {
56+
allocation_id,
57+
value,
58+
nonce: value as u64,
59+
timestamp_ns: value as u64,
60+
},
61+
&wallet,
62+
)
63+
.unwrap(),
64+
);
65+
}
66+
67+
let signed_rav = EIP712SignedMessage::new(
68+
&domain_separator,
69+
ReceiptAggregateVoucher::aggregate_receipts(allocation_id, &receipts, None).unwrap(),
70+
&wallet,
71+
)
72+
.unwrap();
73+
74+
insta::assert_json_snapshot!(receipts);
75+
insta::assert_json_snapshot!(signed_rav);
76+
77+
let raw_sig = r#"{
78+
"r": "0x1596dd0d380ede7aa5dec5ed09ea7d1fa8e4bc8dfdb43a4e965bb4f16906e321",
79+
"s": "0x788b69625a031fbd2e769928b63505387df16e7c51f19ff67c782bfec101a387",
80+
"yParity": "0x1"
81+
}"#;
82+
83+
serde_json::from_str::<PrimitiveSignature>(raw_sig).unwrap();
84+
#[allow(deprecated)]
85+
serde_json::from_str::<Signature>(raw_sig).unwrap();
86+
}
87+
4288
#[rstest]
4389
#[tokio::test]
4490
async fn rav_storage_adapter_test(domain_separator: Eip712Domain, context: InMemoryContext) {
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
source: tap_core/tests/rav_test.rs
3+
expression: signed_rav
4+
snapshot_kind: text
5+
---
6+
{
7+
"message": {
8+
"allocationId": "0xabababababababababababababababababababab",
9+
"timestampNs": 59,
10+
"valueAggregate": 545
11+
},
12+
"signature": {
13+
"r": "0x11d760201bac73d4e772d0999a1f9b5f6b8d8979d94ee29b7cb2659d23f2a551",
14+
"s": "0x1036a994ff414de83f24601ab7cc22e0ece134d2199e0b675d94bd8cf7015226",
15+
"yParity": "0x0",
16+
"v": "0x0"
17+
}
18+
}
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
---
2+
source: tap_core/tests/rav_test.rs
3+
expression: receipts
4+
snapshot_kind: text
5+
---
6+
[
7+
{
8+
"message": {
9+
"allocation_id": "0xabababababababababababababababababababab",
10+
"timestamp_ns": 50,
11+
"nonce": 50,
12+
"value": 50
13+
},
14+
"signature": {
15+
"r": "0x5257bab234e33525cd999db4defc805c2d3b4e51cde3697f43e37ce39473720f",
16+
"s": "0x6c3af14c3d400dfd047fd2da90eb9e8cee863e77cc52742ebcbf080b8d6ec2",
17+
"yParity": "0x1",
18+
"v": "0x1"
19+
}
20+
},
21+
{
22+
"message": {
23+
"allocation_id": "0xabababababababababababababababababababab",
24+
"timestamp_ns": 51,
25+
"nonce": 51,
26+
"value": 51
27+
},
28+
"signature": {
29+
"r": "0x1596dd0d380ede7aa5dec5ed09ea7d1fa8e4bc8dfdb43a4e965bb4f16906e321",
30+
"s": "0x788b69625a031fbd2e769928b63505387df16e7c51f19ff67c782bfec101a387",
31+
"yParity": "0x0",
32+
"v": "0x0"
33+
}
34+
},
35+
{
36+
"message": {
37+
"allocation_id": "0xabababababababababababababababababababab",
38+
"timestamp_ns": 52,
39+
"nonce": 52,
40+
"value": 52
41+
},
42+
"signature": {
43+
"r": "0xb3b8e2c1249fc14183024e28b14f7749ef852c898906c2442f380a26bf07a625",
44+
"s": "0x6925e7dce01d539a658d552e43cfd92d9d204d6997604f8f613977251b964db3",
45+
"yParity": "0x1",
46+
"v": "0x1"
47+
}
48+
},
49+
{
50+
"message": {
51+
"allocation_id": "0xabababababababababababababababababababab",
52+
"timestamp_ns": 53,
53+
"nonce": 53,
54+
"value": 53
55+
},
56+
"signature": {
57+
"r": "0x3b4d08db319497c2cc0d515d25057e28ce44b194a23e84b9d35682f97027c7e3",
58+
"s": "0x232e02eb4b52d302d620867a4c10829e5a307404ea1bcbbd2ee33e8422a18a16",
59+
"yParity": "0x1",
60+
"v": "0x1"
61+
}
62+
},
63+
{
64+
"message": {
65+
"allocation_id": "0xabababababababababababababababababababab",
66+
"timestamp_ns": 54,
67+
"nonce": 54,
68+
"value": 54
69+
},
70+
"signature": {
71+
"r": "0x619d84f659ea3941cdb0656100b2ea8a3d2f5658dbd67f796ebfb8840156530b",
72+
"s": "0x163b236f88207b89452255da8ce196997d8f2f0880081659c780f2093797f75e",
73+
"yParity": "0x1",
74+
"v": "0x1"
75+
}
76+
},
77+
{
78+
"message": {
79+
"allocation_id": "0xabababababababababababababababababababab",
80+
"timestamp_ns": 55,
81+
"nonce": 55,
82+
"value": 55
83+
},
84+
"signature": {
85+
"r": "0x48e1e0e31eaf40eabbcbc3c6d125b7656c0796d51188f89d27194e22f2c5d6bb",
86+
"s": "0xd26efc0ae8cc3646993a20b5aabac1125ecb149ad91d733c702ac9f03222b66",
87+
"yParity": "0x1",
88+
"v": "0x1"
89+
}
90+
},
91+
{
92+
"message": {
93+
"allocation_id": "0xabababababababababababababababababababab",
94+
"timestamp_ns": 56,
95+
"nonce": 56,
96+
"value": 56
97+
},
98+
"signature": {
99+
"r": "0xc3adb8be5db130f563d3a18fc9e742fca84f69a903413e04dc567b9c3aca8626",
100+
"s": "0x564dd73bdd33897c7a085e4eb1bc0ce002b1d65c6006781ab54cd670846fe358",
101+
"yParity": "0x0",
102+
"v": "0x0"
103+
}
104+
},
105+
{
106+
"message": {
107+
"allocation_id": "0xabababababababababababababababababababab",
108+
"timestamp_ns": 57,
109+
"nonce": 57,
110+
"value": 57
111+
},
112+
"signature": {
113+
"r": "0xa0fe51e1b7253daed14f99c9320d0a539ef18b6ead6552947e5c93dde6f40dea",
114+
"s": "0x4277d66d3a8c9f67cddc8d96a71ef8437e47e34a5b5789d7843eb691c3b9864",
115+
"yParity": "0x0",
116+
"v": "0x0"
117+
}
118+
},
119+
{
120+
"message": {
121+
"allocation_id": "0xabababababababababababababababababababab",
122+
"timestamp_ns": 58,
123+
"nonce": 58,
124+
"value": 58
125+
},
126+
"signature": {
127+
"r": "0x26f1657e4b8759867820be12c25e982e15ff9d70aa99fe1fd2587cbb644829de",
128+
"s": "0x5cabbd965f93e544b07e5956c2831148dbf7960b4e2edadfa6ecbf1209dacda4",
129+
"yParity": "0x0",
130+
"v": "0x0"
131+
}
132+
},
133+
{
134+
"message": {
135+
"allocation_id": "0xabababababababababababababababababababab",
136+
"timestamp_ns": 59,
137+
"nonce": 59,
138+
"value": 59
139+
},
140+
"signature": {
141+
"r": "0x90ce08049b9ce9fa38077ebeed0e24558442d8ae001aeff6b9f4b06f4f553c69",
142+
"s": "0x7a873491448ae696555f9d1314b4e78a7cc98a19a6b0c26aad562053dc26a202",
143+
"yParity": "0x1",
144+
"v": "0x1"
145+
}
146+
}
147+
]

0 commit comments

Comments
 (0)