Skip to content

Commit

Permalink
test: add test_usv4_try_from_invalid test
Browse files Browse the repository at this point in the history
  • Loading branch information
zizou0x committed Dec 23, 2024
1 parent 84a8881 commit ca28bf5
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/evm/protocol/uniswap_v4/tycho_decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ mod tests {
use std::{collections::HashMap, str::FromStr};

use chrono::DateTime;
use rstest::rstest;
use tycho_core::{
dto::{Chain, ChangeType, ProtocolComponent, ResponseProtocolState},
hex_bytes::Bytes,
Expand Down Expand Up @@ -215,4 +216,48 @@ mod tests {
);
assert_eq!(result, expected);
}

#[tokio::test]
#[rstest]
#[case::missing_liquidity("liquidity")]
#[case::missing_sqrt_price("sqrt_price")]
#[case::missing_tick("tick")]
#[case::missing_tick_liquidity("tick_liquidities")]
#[case::missing_fee("fee")]
#[case::missing_fee("protocol_fees/one2zero")]
#[case::missing_fee("protocol_fees/zero2one")]
async fn test_usv4_try_from_invalid(#[case] missing_attribute: String) {
// remove missing attribute
let mut attributes = usv4_attributes();
attributes.remove(&missing_attribute);

if missing_attribute == "tick_liquidities" {
attributes.remove("ticks/60/net_liquidity");
}

if missing_attribute == "sqrt_price" {
attributes.remove("sqrt_price_x96");
}

if missing_attribute == "fee" {
attributes.remove("fee");
}

let snapshot = ComponentWithState {
state: ResponseProtocolState {
component_id: "State1".to_owned(),
attributes,
balances: HashMap::new(),
},
component: usv4_component(),
};

let result = UniswapV4State::try_from_with_block(snapshot, header(), &HashMap::new()).await;

assert!(result.is_err());
assert!(matches!(
result.err().unwrap(),
InvalidSnapshotError::MissingAttribute(attr) if attr == missing_attribute
));
}
}

0 comments on commit ca28bf5

Please sign in to comment.