-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
276 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
target | ||
target | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
use common::datalake::{ | ||
block_sampled::BlockSampledDatalake, dynamic_layout::DynamicLayoutDatalake, | ||
}; | ||
|
||
#[test] | ||
fn test_block_datalake_for_header() { | ||
let blocksample_datalake = "0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000009eb0f600000000000000000000000000000000000000000000000000000000009eb100000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000002010f000000000000000000000000000000000000000000000000000000000000"; | ||
let decoded_datalake = | ||
BlockSampledDatalake::deserialize(blocksample_datalake.to_string()).unwrap(); | ||
let block_datalake = | ||
BlockSampledDatalake::new(10399990, 10400000, "header.base_fee_per_gas".to_string(), 1); | ||
assert_eq!( | ||
decoded_datalake.serialize().unwrap(), | ||
block_datalake.serialize().unwrap() | ||
); | ||
|
||
assert_eq!(decoded_datalake.serialize().unwrap(), blocksample_datalake); | ||
} | ||
|
||
#[test] | ||
fn test_block_datalake_for_header_massive() { | ||
let blocksample_datalake = "0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000009d2a6000000000000000000000000000000000000000000000000000000000009eb100000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000002010f000000000000000000000000000000000000000000000000000000000000"; | ||
let decoded_datalake: BlockSampledDatalake = | ||
BlockSampledDatalake::deserialize(blocksample_datalake.to_string()).unwrap(); | ||
let block_datalake = | ||
BlockSampledDatalake::new(10300000, 10400000, "header.base_fee_per_gas".to_string(), 1); | ||
assert_eq!( | ||
decoded_datalake.serialize().unwrap(), | ||
block_datalake.serialize().unwrap() | ||
); | ||
|
||
assert_eq!(decoded_datalake.serialize().unwrap(), blocksample_datalake); | ||
} | ||
|
||
#[test] | ||
fn test_block_datalake_for_account() { | ||
let blocksample_datalake = "0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000009eb0f600000000000000000000000000000000000000000000000000000000009eb100000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000016027b2f05ce9ae365c3dbf30657e2dc6449989e83d60000000000000000000000"; | ||
let decoded_datalake = | ||
BlockSampledDatalake::deserialize(blocksample_datalake.to_string()).unwrap(); | ||
let block_datalake = BlockSampledDatalake::new( | ||
10399990, | ||
10400000, | ||
"account.0x7b2f05ce9ae365c3dbf30657e2dc6449989e83d6.nonce".to_string(), | ||
1, | ||
); | ||
assert_eq!(decoded_datalake, block_datalake); | ||
assert_eq!(decoded_datalake.serialize().unwrap(), blocksample_datalake); | ||
} | ||
|
||
#[test] | ||
fn test_block_datalake_for_storage() { | ||
let blocksample_datalake = "0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000009eb0f600000000000000000000000000000000000000000000000000000000009eb100000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000035037b2f05ce9ae365c3dbf30657e2dc6449989e83d600000000000000000000000000000000000000000000000000000000000000ff0000000000000000000000"; | ||
let decoded_datalake = | ||
BlockSampledDatalake::deserialize(blocksample_datalake.to_string()).unwrap(); | ||
let block_datalake = BlockSampledDatalake::new( | ||
10399990, | ||
10400000, | ||
"storage.0x7b2f05ce9ae365c3dbf30657e2dc6449989e83d6.0x00000000000000000000000000000000000000000000000000000000000000ff".to_string(), | ||
1, | ||
); | ||
assert_eq!(decoded_datalake, block_datalake); | ||
assert_eq!(decoded_datalake.serialize().unwrap(), blocksample_datalake); | ||
} | ||
|
||
#[test] | ||
fn test_dynamic_layout_datalake_serialized() { | ||
let dynamic_layout_datalake = "0x000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000009eb0f60000000000000000000000007b2f05ce9ae365c3dbf30657e2dc6449989e83d60000000000000000000000000000000000000000000000000000000000000005000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000001"; | ||
let decoded_datalake = | ||
DynamicLayoutDatalake::deserialize(dynamic_layout_datalake.to_string()).unwrap(); | ||
let dynamic_layout_datalake = DynamicLayoutDatalake::new( | ||
10399990, | ||
"0x7b2f05cE9aE365c3DBF30657e2DC6449989e83D6".to_string(), | ||
5, | ||
0, | ||
3, | ||
1, | ||
); | ||
assert_eq!(decoded_datalake, dynamic_layout_datalake); | ||
assert_eq!( | ||
decoded_datalake.serialize().unwrap(), | ||
dynamic_layout_datalake.serialize().unwrap() | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use alloy_dyn_abi::DynSolType; | ||
use alloy_primitives::hex::FromHex; | ||
use common::task::ComputationalTask; | ||
|
||
#[test] | ||
fn test_task_from_serialized() { | ||
let serialized_tasks_batch = "0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000060617667000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006073756d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000606d696e00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000606d6178000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000000"; | ||
let tasks_type: DynSolType = "bytes[]".parse().unwrap(); | ||
let bytes = Vec::from_hex(serialized_tasks_batch).expect("Invalid hex string"); | ||
let serialized_tasks = tasks_type.abi_decode(&bytes).unwrap(); | ||
let mut computational_task_result = Vec::new(); | ||
|
||
if let Some(tasks) = serialized_tasks.as_array() { | ||
for task in tasks { | ||
let computational_task = | ||
ComputationalTask::deserialize_aggregate_fn(task.as_bytes().unwrap()).unwrap(); | ||
computational_task_result.push(computational_task); | ||
} | ||
} | ||
|
||
assert_eq!(computational_task_result.len(), 4); | ||
assert_eq!( | ||
computational_task_result[0].aggregate_fn_id, | ||
"avg".to_string() | ||
); | ||
assert_eq!(computational_task_result[0].aggregate_fn_ctx, None); | ||
assert_eq!( | ||
computational_task_result[1].aggregate_fn_id, | ||
"sum".to_string() | ||
); | ||
assert_eq!(computational_task_result[1].aggregate_fn_ctx, None); | ||
assert_eq!( | ||
computational_task_result[2].aggregate_fn_id, | ||
"min".to_string() | ||
); | ||
assert_eq!(computational_task_result[2].aggregate_fn_ctx, None); | ||
assert_eq!( | ||
computational_task_result[3].aggregate_fn_id, | ||
"max".to_string() | ||
); | ||
assert_eq!(computational_task_result[3].aggregate_fn_ctx, None); | ||
} |
Oops, something went wrong.