feat: add executor encoder test

This commit is contained in:
royvardhan
2025-01-29 22:26:24 +05:30
parent 5c396512cf
commit ad70a0d5a8
3 changed files with 58 additions and 3 deletions

4
Cargo.lock generated
View File

@@ -2941,7 +2941,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "157c5a9d7ea5c2ed2d9fb8f495b64759f7816c7eaea54ba3978f0d63000162e3"
dependencies = [
"anyhow",
"itertools 0.10.5",
"itertools 0.13.0",
"proc-macro2",
"quote",
"syn 2.0.96",
@@ -3011,7 +3011,7 @@ dependencies = [
"once_cell",
"socket2",
"tracing",
"windows-sys 0.52.0",
"windows-sys 0.59.0",
]
[[package]]

View File

@@ -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()
);
}
}

View File

@@ -12,7 +12,7 @@ pub struct Solution {
/// Amount of the given token.
pub given_amount: BigUint,
/// The token being bought (exact in) or sold (exact out).
checked_token: Bytes,
pub checked_token: Bytes,
/// Expected amount of the bought token (exact in) or sold token (exact out).
pub expected_amount: BigUint,
/// Minimum amount to be checked for the solution to be valid.