Skip to content

Commit

Permalink
test: dynamic layout datalake
Browse files Browse the repository at this point in the history
  • Loading branch information
rkdud007 committed Jan 30, 2024
1 parent 5ca725f commit 645d3d4
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
1 change: 1 addition & 0 deletions crates/decoder/src/args_decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub fn tasks_decoder(serialized_tasks_batch: String) -> Result<Vec<Computational
Ok(decoded_tasks)
}

// TODO: Update this to use the new bytes format
pub fn datalake_decoder(serialized_datalakes_batch: String) -> Result<Vec<DatalakeType>> {
let datalakes_type: DynSolType = "bytes[]".parse()?;
let bytes = Vec::from_hex(serialized_datalakes_batch).expect("Invalid hex string");
Expand Down
2 changes: 1 addition & 1 deletion crates/decoder/tests/args_decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,4 @@ fn test_block_datalake_decoder() {
}
}

// TODO: dynamic layout datalake test
// TODO: After Solidity calldata format update, update the datalake decoder and write test
3 changes: 2 additions & 1 deletion crates/types/src/datalake/dynamic_layout_datalake.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use alloy_dyn_abi::DynSolType;
use anyhow::Result;

#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq)]
pub struct DynamicLayoutDatalake {
pub block_number: usize,
pub account_address: String,
Expand Down Expand Up @@ -35,6 +35,7 @@ impl DynamicLayoutDatalake {
"(uint256,address,uint256,uint256,uint256,uint256)".parse()?;

let decoded = datalake_type.abi_decode(serialized)?;

let value = decoded.as_tuple().unwrap();
let block_number = value[0].as_uint().unwrap().0.to_string().parse::<usize>()?;
let account_address = value[1].as_address().unwrap().to_string();
Expand Down
16 changes: 16 additions & 0 deletions crates/types/tests/dynamic_layout_datalake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use types::datalake::dynamic_layout_datalake::DynamicLayoutDatalake;

#[test]
fn test_dynamic_layout_datalake_serialized() {
let datalake_bytes = b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x9c\x1f\xbc\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00{/\x05\xce\x9a\xe3e\xc3\xdb\xf3\x06W\xe2\xdcdI\x98\x9e\x83\xd6\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x05\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01";
let decoded_datalake = DynamicLayoutDatalake::from_serialized(datalake_bytes).unwrap();
let dynamic_layout_datalake = DynamicLayoutDatalake::new(
10231740,
"0x7b2f05cE9aE365c3DBF30657e2DC6449989e83D6".to_string(),
5,
0,
3,
1,
);
assert_eq!(decoded_datalake, dynamic_layout_datalake);
}

0 comments on commit 645d3d4

Please sign in to comment.