feat: add executor encoder test
This commit is contained in:
@@ -78,3 +78,58 @@ impl StrategyEncoder for ExecutorEncoder {
|
||||
"swap(uint256, bytes)"
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use num_bigint::BigUint;
|
||||
use tycho_core::{dto::ProtocolComponent, Bytes};
|
||||
|
||||
use super::*;
|
||||
use crate::encoding::models::Swap;
|
||||
|
||||
#[test]
|
||||
fn test_executor_encoder() {
|
||||
let encoder = ExecutorEncoder {};
|
||||
|
||||
let token_in = Bytes::from("0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2");
|
||||
let token_out = Bytes::from("0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174");
|
||||
|
||||
let swap = Swap {
|
||||
component: ProtocolComponent {
|
||||
id: "0x5c6ee304399dbdb9c8ef030ab642b10820db8f56000200000000000000000014"
|
||||
.to_string(),
|
||||
protocol_system: "vm:balancer_v2".to_string(),
|
||||
..Default::default()
|
||||
},
|
||||
token_in: token_in.clone(),
|
||||
token_out: token_out.clone(),
|
||||
split: 0.5,
|
||||
};
|
||||
|
||||
let solution = Solution {
|
||||
exact_out: false,
|
||||
given_token: token_in,
|
||||
given_amount: BigUint::from(1000000000000000000u64),
|
||||
expected_amount: BigUint::from(1000000000000000000u64),
|
||||
checked_token: token_out,
|
||||
check_amount: None,
|
||||
sender: Bytes::from_str("0x0000000000000000000000000000000000000000").unwrap(),
|
||||
receiver: Bytes::from_str("0x0000000000000000000000000000000000000000").unwrap(),
|
||||
swaps: vec![swap],
|
||||
straight_to_pool: true,
|
||||
router_address: Some(
|
||||
Bytes::from_str("0x0000000000000000000000000000000000000002").unwrap(),
|
||||
),
|
||||
slippage: None,
|
||||
native_action: None,
|
||||
};
|
||||
|
||||
let (_, executor_address) = encoder
|
||||
.encode_strategy(solution)
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
executor_address,
|
||||
Address::from_str("0x543778987b293C7E8Cf0722BB2e935ba6f4068D4").unwrap()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user