From 2605b4a78b6a9acf50d18233d089448a4af5c1ed Mon Sep 17 00:00:00 2001 From: Sergey Kuznetsov Date: Wed, 12 Aug 2026 11:30:22 +0100 Subject: [PATCH] Fix clippy and doc test errors --- crates/xrpl-host-functions/src/lib.rs | 6 +-- crates/xrpl-wasm-vm/tests/host_calls.rs | 4 +- crates/xrpl-wasm-vm/tests/support/mod.rs | 54 ++++++++++++++++-------- 3 files changed, 42 insertions(+), 22 deletions(-) diff --git a/crates/xrpl-host-functions/src/lib.rs b/crates/xrpl-host-functions/src/lib.rs index e8ae0e7392..e2106fa54f 100644 --- a/crates/xrpl-host-functions/src/lib.rs +++ b/crates/xrpl-host-functions/src/lib.rs @@ -129,7 +129,7 @@ host_functions! { fn get_tx_nested_field(&self, locator: &[u8], out: &mut [u8]) -> HostResult; /// The serialized bytes of a nested field of the current (escrow) ledger object, - /// reached by a `locator`, as with [`Self::get_tx_nested_field`]. + /// reached by a `locator`, as with [`HostFunctions::get_tx_nested_field`]. #[gas = 110] #[wasm_name = "home_le_inner"] fn get_current_ledger_obj_nested_field( @@ -157,7 +157,7 @@ host_functions! { fn get_tx_array_len(&self, field: i32) -> HostResult; /// The number of elements in an array field of the current (escrow) ledger - /// object, as with [`Self::get_tx_array_len`]. + /// object, as with [`HostFunctions::get_tx_array_len`]. #[gas = 40] #[wasm_name = "home_le_arr_len"] fn get_current_ledger_obj_array_len(&self, field: i32) -> HostResult; @@ -175,7 +175,7 @@ host_functions! { fn get_tx_nested_array_len(&self, locator: &[u8]) -> HostResult; /// The number of elements in a nested array field of the current (escrow) ledger - /// object, reached by a `locator`, as with [`Self::get_tx_nested_array_len`]. + /// object, reached by a `locator`, as with [`HostFunctions::get_tx_nested_array_len`]. #[gas = 70] #[wasm_name = "home_le_inner_arr_len"] fn get_current_ledger_obj_nested_array_len(&self, locator: &[u8]) -> HostResult; diff --git a/crates/xrpl-wasm-vm/tests/host_calls.rs b/crates/xrpl-wasm-vm/tests/host_calls.rs index 251b452b46..a315b7095c 100644 --- a/crates/xrpl-wasm-vm/tests/host_calls.rs +++ b/crates/xrpl-wasm-vm/tests/host_calls.rs @@ -982,7 +982,7 @@ fn float_add_reads_both_operands_and_the_mode() { ); assert_eq!(status(&wat, &host), 8, "the result length"); assert_eq!( - *host.float_binops_asked.borrow(), + *host.float_binary_ops_asked.borrow(), vec![("add", vec![0u8; 8], vec![0u8; 8], 2)] ); } @@ -999,7 +999,7 @@ fn float_root_reads_the_float_the_degree_and_the_mode() { ); assert_eq!(status(&wat, &host), 8, "the result length"); assert_eq!( - *host.float_unops_asked.borrow(), + *host.float_unary_ops_asked.borrow(), vec![("root", vec![0u8; 8], 3, 1)] ); } diff --git a/crates/xrpl-wasm-vm/tests/support/mod.rs b/crates/xrpl-wasm-vm/tests/support/mod.rs index 780322b772..43651cbb0c 100644 --- a/crates/xrpl-wasm-vm/tests/support/mod.rs +++ b/crates/xrpl-wasm-vm/tests/support/mod.rs @@ -91,6 +91,26 @@ pub struct Trace { pub data: Vec, } +/// The `(message, signature, pubkey)` `check_signature` takes. +pub type SigCheck = (Vec, Vec, Vec); + +/// The `(subject, issuer, type)` `credential_keylet` takes. +pub type CredentialKey = (Vec, Vec, Vec); + +/// The `(account1, account2, currency)` `trust_line_keylet` takes. +pub type TrustLineKey = (Vec, Vec, Vec); + +/// The `(account, destination, seq)` `paychannel_keylet` takes. +pub type PaychannelKey = (Vec, Vec, i32); + +/// One call to a float operator over two floats — `float_add`, `float_subtract`, +/// `float_multiply`, `float_divide` — as `(operator, x, y, mode)`. +pub type FloatBinaryCall = (&'static str, Vec, Vec, i32); + +/// One call to a float operator over a float and an integer — `float_root`, +/// `float_power` — as `(operator, x, n, mode)`. +pub type FloatUnaryCall = (&'static str, Vec, i32, i32); + /// A `HostFunctions` implementation that answers from what the test put in it and /// records what it was asked. The ABI's receiver is `&self`, so the recording goes /// behind `RefCell`, as a real mutating host's would. @@ -172,7 +192,7 @@ pub struct FakeHost { /// What `check_signature` answers, whatever it is given. pub sig_valid: HostResult, /// Every (message, signature, pubkey) `check_signature` was asked to verify. - pub sigs_checked: RefCell, Vec, Vec)>>, + pub sigs_checked: RefCell>, /// What `account_keylet` answers, by account bytes. An unlisted account answers /// `InvalidAccount`. pub account_keylets: HashMap, Answer>, @@ -190,9 +210,9 @@ pub struct FakeHost { pub check_keylets_asked: RefCell, i32)>>, /// What `credential_keylet` answers, by (subject, issuer, type) bytes. An unlisted /// key answers `InvalidAccount`. - pub credential_keylets: HashMap<(Vec, Vec, Vec), Answer>, + pub credential_keylets: HashMap, /// Every (subject, issuer, type) `credential_keylet` was asked for. - pub credential_keylets_asked: RefCell, Vec, Vec)>>, + pub credential_keylets_asked: RefCell>, /// What `delegate_keylet` answers, by (account, authorize) bytes. An unlisted key /// answers `InvalidAccount`. pub delegate_keylets: HashMap<(Vec, Vec), Answer>, @@ -215,9 +235,9 @@ pub struct FakeHost { pub escrow_keylets_asked: RefCell, i32)>>, /// What `trust_line_keylet` answers, by (account1, account2, currency) bytes. An /// unlisted key answers `InvalidAccount`. - pub trust_line_keylets: HashMap<(Vec, Vec, Vec), Answer>, + pub trust_line_keylets: HashMap, /// Every (account1, account2, currency) `trust_line_keylet` was asked for. - pub trust_line_keylets_asked: RefCell, Vec, Vec)>>, + pub trust_line_keylets_asked: RefCell>, /// What `mptoken_issuance_keylet` answers, by (issuer bytes, seq). An unlisted key /// answers `InvalidAccount`. pub mpt_issuance_keylets: HashMap<(Vec, i32), Answer>, @@ -245,9 +265,9 @@ pub struct FakeHost { pub oracle_keylets_asked: RefCell, i32)>>, /// What `paychannel_keylet` answers, by (account, destination, seq). An unlisted /// key answers `InvalidAccount`. - pub paychannel_keylets: HashMap<(Vec, Vec, i32), Answer>, + pub paychannel_keylets: HashMap, /// Every (account, destination, seq) `paychannel_keylet` was asked for. - pub paychannel_keylets_asked: RefCell, Vec, i32)>>, + pub paychannel_keylets_asked: RefCell>, /// What `permissioned_domain_keylet` answers, by (account bytes, seq). An unlisted /// key answers `InvalidAccount`. pub domain_keylets: HashMap<(Vec, i32), Answer>, @@ -335,10 +355,10 @@ pub struct FakeHost { pub float_compare_asked: RefCell, Vec)>>, /// Every `(x, y, mode)` the four binary float operators were asked for, tagged by /// operator name. - pub float_binops_asked: RefCell, Vec, i32)>>, + pub float_binary_ops_asked: RefCell>, /// Every `(x, n, mode)` `float_root` and `float_power` were asked for, tagged by /// operator name. - pub float_unops_asked: RefCell, i32, i32)>>, + pub float_unary_ops_asked: RefCell>, } impl Default for FakeHost { @@ -453,8 +473,8 @@ impl Default for FakeHost { float_from_mant_exp_asked: RefCell::new(Vec::new()), float_compare_answer: Ok(0), float_compare_asked: RefCell::new(Vec::new()), - float_binops_asked: RefCell::new(Vec::new()), - float_unops_asked: RefCell::new(Vec::new()), + float_binary_ops_asked: RefCell::new(Vec::new()), + float_unary_ops_asked: RefCell::new(Vec::new()), } } } @@ -1327,42 +1347,42 @@ impl HostFunctions for FakeHost { } fn float_add(&self, x: &[u8], y: &[u8], mode: i32, out: &mut [u8]) -> HostResult { - self.float_binops_asked + self.float_binary_ops_asked .borrow_mut() .push(("add", x.to_vec(), y.to_vec(), mode)); self.float_answer.fill(out) } fn float_subtract(&self, x: &[u8], y: &[u8], mode: i32, out: &mut [u8]) -> HostResult { - self.float_binops_asked + self.float_binary_ops_asked .borrow_mut() .push(("sub", x.to_vec(), y.to_vec(), mode)); self.float_answer.fill(out) } fn float_multiply(&self, x: &[u8], y: &[u8], mode: i32, out: &mut [u8]) -> HostResult { - self.float_binops_asked + self.float_binary_ops_asked .borrow_mut() .push(("mult", x.to_vec(), y.to_vec(), mode)); self.float_answer.fill(out) } fn float_divide(&self, x: &[u8], y: &[u8], mode: i32, out: &mut [u8]) -> HostResult { - self.float_binops_asked + self.float_binary_ops_asked .borrow_mut() .push(("div", x.to_vec(), y.to_vec(), mode)); self.float_answer.fill(out) } fn float_root(&self, x: &[u8], n: i32, mode: i32, out: &mut [u8]) -> HostResult { - self.float_unops_asked + self.float_unary_ops_asked .borrow_mut() .push(("root", x.to_vec(), n, mode)); self.float_answer.fill(out) } fn float_power(&self, x: &[u8], n: i32, mode: i32, out: &mut [u8]) -> HostResult { - self.float_unops_asked + self.float_unary_ops_asked .borrow_mut() .push(("pow", x.to_vec(), n, mode)); self.float_answer.fill(out)