Skip to content

Commit b467d94

Browse files
committed
refactor: use u256 for values to improve maintainability
Signed-off-by: Joseph Livesey <[email protected]>
1 parent 9867802 commit b467d94

File tree

22 files changed

+574
-242
lines changed

22 files changed

+574
-242
lines changed

tap_aggregator/src/aggregator/v1.rs

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,12 @@ fn check_receipt_timestamps(
130130

131131
#[cfg(test)]
132132
mod tests {
133-
use std::str::FromStr;
134-
135133
use rstest::*;
136134
use tap_core::{signed_message::Eip712SignedMessage, tap_eip712_domain};
137135
use tap_graph::{Receipt, ReceiptAggregateVoucher};
138136
use thegraph_core::alloy::{
139137
dyn_abi::Eip712Domain,
140-
primitives::{Address, U256},
138+
primitives::{address, Address, U256},
141139
signers::{local::PrivateKeySigner, Signature},
142140
};
143141

@@ -153,10 +151,10 @@ mod tests {
153151
#[fixture]
154152
fn allocation_ids() -> Vec<Address> {
155153
vec![
156-
Address::from_str("0xabababababababababababababababababababab").unwrap(),
157-
Address::from_str("0xdeaddeaddeaddeaddeaddeaddeaddeaddeaddead").unwrap(),
158-
Address::from_str("0xbeefbeefbeefbeefbeefbeefbeefbeefbeefbeef").unwrap(),
159-
Address::from_str("0x1234567890abcdef1234567890abcdef12345678").unwrap(),
154+
address!("0xabababababababababababababababababababab"),
155+
address!("0xdeaddeaddeaddeaddeaddeaddeaddeaddeaddead"),
156+
address!("0xbeefbeefbeefbeefbeefbeefbeefbeefbeefbeef"),
157+
address!("0x1234567890abcdef1234567890abcdef12345678"),
160158
]
161159
}
162160

@@ -175,7 +173,7 @@ mod tests {
175173
// Create a test receipt
176174
let receipt = Eip712SignedMessage::new(
177175
&domain_separator,
178-
Receipt::new(allocation_ids[0], 42).unwrap(),
176+
Receipt::new(allocation_ids[0], U256::from(42)).unwrap(),
179177
&keys.0,
180178
)
181179
.unwrap();
@@ -236,7 +234,7 @@ mod tests {
236234
let mut receipts = Vec::new();
237235
let receipt = Eip712SignedMessage::new(
238236
&domain_separator,
239-
Receipt::new(allocation_ids[0], 42).unwrap(),
237+
Receipt::new(allocation_ids[0], U256::from(42)).unwrap(),
240238
&keys.0,
241239
)
242240
.unwrap();
@@ -258,13 +256,13 @@ mod tests {
258256
let receipts = vec![
259257
Eip712SignedMessage::new(
260258
&domain_separator,
261-
Receipt::new(allocation_ids[0], 42).unwrap(),
259+
Receipt::new(allocation_ids[0], U256::from(42)).unwrap(),
262260
&keys.0,
263261
)
264262
.unwrap(),
265263
Eip712SignedMessage::new(
266264
&domain_separator,
267-
Receipt::new(allocation_ids[0], 43).unwrap(),
265+
Receipt::new(allocation_ids[0], U256::from(43)).unwrap(),
268266
&keys.0,
269267
)
270268
.unwrap(),
@@ -293,7 +291,7 @@ mod tests {
293291
allocation_id: allocation_ids[0],
294292
timestamp_ns: i,
295293
nonce: 0,
296-
value: 42,
294+
value: U256::from(42),
297295
},
298296
&keys.0,
299297
)
@@ -307,7 +305,7 @@ mod tests {
307305
ReceiptAggregateVoucher {
308306
allocationId: allocation_ids[0],
309307
timestampNs: receipt_timestamp_range.clone().min().unwrap() - 1,
310-
valueAggregate: 42,
308+
valueAggregate: U256::from(42),
311309
},
312310
&keys.0,
313311
)
@@ -321,7 +319,7 @@ mod tests {
321319
ReceiptAggregateVoucher {
322320
allocationId: allocation_ids[0],
323321
timestampNs: receipt_timestamp_range.clone().min().unwrap(),
324-
valueAggregate: 42,
322+
valueAggregate: U256::from(42),
325323
},
326324
&keys.0,
327325
)
@@ -335,7 +333,7 @@ mod tests {
335333
ReceiptAggregateVoucher {
336334
allocationId: allocation_ids[0],
337335
timestampNs: receipt_timestamp_range.clone().max().unwrap() + 1,
338-
valueAggregate: 42,
336+
valueAggregate: U256::from(42),
339337
},
340338
&keys.0,
341339
)
@@ -355,19 +353,19 @@ mod tests {
355353
let receipts = vec![
356354
Eip712SignedMessage::new(
357355
&domain_separator,
358-
Receipt::new(allocation_ids[0], 42).unwrap(),
356+
Receipt::new(allocation_ids[0], U256::from(42)).unwrap(),
359357
&keys.0,
360358
)
361359
.unwrap(),
362360
Eip712SignedMessage::new(
363361
&domain_separator,
364-
Receipt::new(allocation_ids[0], 43).unwrap(),
362+
Receipt::new(allocation_ids[0], U256::from(43)).unwrap(),
365363
&keys.0,
366364
)
367365
.unwrap(),
368366
Eip712SignedMessage::new(
369367
&domain_separator,
370-
Receipt::new(allocation_ids[1], 44).unwrap(),
368+
Receipt::new(allocation_ids[1], U256::from(44)).unwrap(),
371369
&keys.0,
372370
)
373371
.unwrap(),
@@ -389,19 +387,19 @@ mod tests {
389387
let receipts = vec![
390388
Eip712SignedMessage::new(
391389
&domain_separator,
392-
Receipt::new(allocation_ids[0], 42).unwrap(),
390+
Receipt::new(allocation_ids[0], U256::from(42)).unwrap(),
393391
&keys.0,
394392
)
395393
.unwrap(),
396394
Eip712SignedMessage::new(
397395
&domain_separator,
398-
Receipt::new(allocation_ids[0], 43).unwrap(),
396+
Receipt::new(allocation_ids[0], U256::from(43)).unwrap(),
399397
&keys.0,
400398
)
401399
.unwrap(),
402400
Eip712SignedMessage::new(
403401
&domain_separator,
404-
Receipt::new(allocation_ids[0], 44).unwrap(),
402+
Receipt::new(allocation_ids[0], U256::from(44)).unwrap(),
405403
&keys.0,
406404
)
407405
.unwrap(),

tap_aggregator/src/aggregator/v2.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ mod tests {
312312
service_provider,
313313
timestamp_ns: i,
314314
nonce: 0,
315-
value: 42,
315+
value: U256::from(42),
316316
},
317317
&keys.0,
318318
)
@@ -329,7 +329,7 @@ mod tests {
329329
payer,
330330
serviceProvider: service_provider,
331331
timestampNs: receipt_timestamp_range.clone().min().unwrap() - 1,
332-
valueAggregate: 42,
332+
valueAggregate: U256::from(42),
333333
metadata: Bytes::new(),
334334
},
335335
&keys.0,
@@ -347,7 +347,7 @@ mod tests {
347347
payer,
348348
serviceProvider: service_provider,
349349
timestampNs: receipt_timestamp_range.clone().min().unwrap(),
350-
valueAggregate: 42,
350+
valueAggregate: U256::from(42),
351351
metadata: Bytes::new(),
352352
},
353353
&keys.0,
@@ -365,7 +365,7 @@ mod tests {
365365
payer,
366366
serviceProvider: service_provider,
367367
timestampNs: receipt_timestamp_range.clone().max().unwrap() + 1,
368-
valueAggregate: 42,
368+
valueAggregate: U256::from(42),
369369
metadata: Bytes::new(),
370370
},
371371
&keys.0,

0 commit comments

Comments
 (0)