Skip to content

Commit df1e3e2

Browse files
test(ethereum): Update v2swap fixture to include expanded command details
Update the fixture to reflect improved Uniswap Universal Router visualization with expanded field details for V2 Swap, Pay Portion, and Unwrap commands.
1 parent 3b41edf commit df1e3e2

File tree

7 files changed

+627
-113
lines changed

7 files changed

+627
-113
lines changed

src/chain_parsers/visualsign-ethereum/src/protocols/uniswap/config.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
//! Currently, only V1.2 is implemented. Future versions should be added as separate
1616
//! contract type markers below.
1717
18-
use alloy_primitives::Address;
1918
use crate::registry::{ContractRegistry, ContractType};
20-
use crate::token_metadata::{TokenMetadata, ErcStandard};
19+
use crate::token_metadata::{ErcStandard, TokenMetadata};
20+
use alloy_primitives::Address;
2121

2222
/// Contract type marker for Uniswap Universal Router V1.2
2323
///

src/chain_parsers/visualsign-ethereum/src/protocols/uniswap/contracts/permit2.rs

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#![allow(unused_imports)]
99

1010
use alloy_primitives::Address;
11-
use alloy_sol_types::{sol, SolCall};
11+
use alloy_sol_types::{SolCall, sol};
1212
use chrono::{TimeZone, Utc};
1313
use visualsign::{SignablePayloadField, SignablePayloadFieldCommon, SignablePayloadFieldTextV2};
1414

@@ -108,11 +108,7 @@ impl Permit2Visualizer {
108108

109109
let text = format!(
110110
"Approve {} {} {} to spend {} (expires: {})",
111-
call.spender,
112-
amount_str,
113-
token_symbol,
114-
token_symbol,
115-
expiration_str
111+
call.spender, amount_str, token_symbol, token_symbol, expiration_str
116112
);
117113

118114
SignablePayloadField::TextV2 {
@@ -136,29 +132,40 @@ impl Permit2Visualizer {
136132
.unwrap_or_else(|| format!("{:?}", token));
137133

138134
// Format amount with proper decimals
139-
let amount_u128: u128 = call.permitSingle.details.amount.to_string().parse().unwrap_or(0);
135+
let amount_u128: u128 = call
136+
.permitSingle
137+
.details
138+
.amount
139+
.to_string()
140+
.parse()
141+
.unwrap_or(0);
140142
let (amount_str, _) = registry
141143
.and_then(|r| r.format_token_amount(chain_id, token, amount_u128))
142-
.unwrap_or_else(|| (call.permitSingle.details.amount.to_string(), token_symbol.clone()));
144+
.unwrap_or_else(|| {
145+
(
146+
call.permitSingle.details.amount.to_string(),
147+
token_symbol.clone(),
148+
)
149+
});
143150

144151
// Format expiration timestamp
145-
let expiration_u64: u64 = call.permitSingle.details.expiration.to_string().parse().unwrap_or(0);
152+
let expiration_u64: u64 = call
153+
.permitSingle
154+
.details
155+
.expiration
156+
.to_string()
157+
.parse()
158+
.unwrap_or(0);
146159
let expiration_str = if expiration_u64 == u64::MAX {
147160
"never".to_string()
148161
} else {
149-
let dt = Utc
150-
.timestamp_opt(expiration_u64 as i64, 0)
151-
.unwrap();
162+
let dt = Utc.timestamp_opt(expiration_u64 as i64, 0).unwrap();
152163
dt.format("%Y-%m-%d %H:%M UTC").to_string()
153164
};
154165

155166
let text = format!(
156167
"Permit {} to spend {} {} from {} (expires: {})",
157-
call.permitSingle.spender,
158-
amount_str,
159-
token_symbol,
160-
call.owner,
161-
expiration_str
168+
call.permitSingle.spender, amount_str, token_symbol, call.owner, expiration_str
162169
);
163170

164171
SignablePayloadField::TextV2 {
@@ -214,7 +221,10 @@ mod tests {
214221
#[test]
215222
fn test_visualize_too_short() {
216223
let visualizer = Permit2Visualizer;
217-
assert_eq!(visualizer.visualize_tx_commands(&[0x01, 0x02], 1, None), None);
224+
assert_eq!(
225+
visualizer.visualize_tx_commands(&[0x01, 0x02], 1, None),
226+
None
227+
);
218228
}
219229

220230
// TODO: Add tests for Permit2 functions once implemented
@@ -247,7 +257,8 @@ impl crate::visualizer::ContractVisualizer for Permit2ContractVisualizer {
247257
fn visualize(
248258
&self,
249259
context: &crate::context::VisualizerContext,
250-
) -> Result<Option<Vec<visualsign::AnnotatedPayloadField>>, visualsign::vsptrait::VisualSignError> {
260+
) -> Result<Option<Vec<visualsign::AnnotatedPayloadField>>, visualsign::vsptrait::VisualSignError>
261+
{
251262
let contract_registry = crate::registry::ContractRegistry::with_default_protocols();
252263

253264
if let Some(field) = self.inner.visualize_tx_commands(

0 commit comments

Comments
 (0)