From 505f1b6f32127302ab1de738b5f9b012666bcc49 Mon Sep 17 00:00:00 2001 From: MartinquaXD Date: Thu, 16 Jan 2025 13:46:27 +0000 Subject: [PATCH] Add unit test for solady storage computation --- .../trade_verifier/balance_overrides.rs | 53 ++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/crates/shared/src/price_estimation/trade_verifier/balance_overrides.rs b/crates/shared/src/price_estimation/trade_verifier/balance_overrides.rs index bb549b5aea..d12d3c9621 100644 --- a/crates/shared/src/price_estimation/trade_verifier/balance_overrides.rs +++ b/crates/shared/src/price_estimation/trade_verifier/balance_overrides.rs @@ -302,7 +302,7 @@ mod tests { // You can verify the state override computation is correct by running: // ``` - // curl -X POST $RPC -H 'Content-Type: application/data' --data '{ + // curl -X POST $RPC -H 'Content-Type: application/json' --data '{ // "jsonrpc": "2.0", // "id": 0, // "method": "eth_call", @@ -339,4 +339,55 @@ mod tests { None, ); } + + #[tokio::test] + async fn balance_override_computation_solady() { + let balance_overrides = BalanceOverrides { + hardcoded: hashmap! { + addr!("0000000000c5dc95539589fbd24be07c6c14eca4") => Strategy::SoladyMapping, + }, + ..Default::default() + }; + + assert_eq!( + balance_overrides + .state_override(BalanceOverrideRequest { + token: addr!("0000000000c5dc95539589fbd24be07c6c14eca4"), + holder: addr!("d8dA6BF26964aF9D7eEd9e03E53415D37aA96045"), + amount: 0x42_u64.into(), + }) + .await, + Some(StateOverride { + state_diff: Some(hashmap! { + H256(hex!("f6a6656ed2d14bad3cdd3e8871db3f535a136a1b6cd5ae2dced8eb813f3d4e4f")) => + H256(hex!("0000000000000000000000000000000000000000000000000000000000000042")), + }), + ..Default::default() + }), + ); + + // You can verify the state override computation is correct by running: + // ``` + // curl -X POST $RPC -H 'Content-Type: application/json' --data '{ + // "jsonrpc": "2.0", + // "id": 0, + // "method": "eth_call", + // "params": [ + // { + // "to": "0x0000000000c5dc95539589fbd24be07c6c14eca4", + // "data": "0x70a08231000000000000000000000000d8dA6BF26964aF9D7eEd9e03E53415D37aA96045" + // }, + // "latest", + // { + // "0x0000000000c5dc95539589fbd24be07c6c14eca4": { + // "stateDiff": { + // "f6a6656ed2d14bad3cdd3e8871db3f535a136a1b6cd5ae2dced8eb813f3d4e4f": + // "0x0000000000000000000000000000000000000000000000000000000000000042" + // } + // } + // } + // ] + // }' + // ``` + } }