Skip to content

Commit

Permalink
clippy formatting fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sisuresh committed Jun 21, 2024
1 parent 2373d14 commit 6705a74
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 50 deletions.
4 changes: 1 addition & 3 deletions soroban-env-host/src/host/comparison.rs
Original file line number Diff line number Diff line change
Expand Up @@ -565,9 +565,7 @@ mod tests {
.unwrap()
});

let iter = pairs_xdr_sorted
.into_iter()
.zip(pairs_host_sorted.into_iter());
let iter = pairs_xdr_sorted.into_iter().zip(pairs_host_sorted);

for ((xdr1, _), (xdr2, _)) in iter {
assert_eq!(xdr1, xdr2);
Expand Down
2 changes: 1 addition & 1 deletion soroban-env-host/src/test/budget_metering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ fn test_metered_collection() -> Result<(), HostError> {
let res = v
.iter()
.filter(|i| i.abs() > 3)
.map(|i| Ok(i.abs() as u64))
.map(|i| Ok(i.unsigned_abs() as u64))
.metered_collect::<Result<Vec<u64>, HostError>>(&budget)??;
assert_eq!(res, vec![4, 6, 11]);
Ok(())
Expand Down
4 changes: 2 additions & 2 deletions soroban-env-host/src/test/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ fn test_bytes_out_of_cpu_budget() -> Result<(), HostError> {
host.as_budget().reset_unlimited_cpu()?;
let mut b1 = host.bytes_new_from_slice(&[2; 1])?;
loop {
let res = host.bytes_append(b1, b1.clone());
let res = host.bytes_append(b1, b1);
if res.is_err() {
assert!(HostError::result_matches_err(
res,
Expand All @@ -436,7 +436,7 @@ fn test_bytes_out_of_mem_budget() -> Result<(), HostError> {
host.as_budget().reset_unlimited_mem()?;
let mut b1 = host.bytes_new_from_slice(&[2; 1])?;
loop {
let res = host.bytes_append(b1, b1.clone());
let res = host.bytes_append(b1, b1);
if res.is_err() {
assert!(HostError::result_matches_err(
res,
Expand Down
4 changes: 2 additions & 2 deletions soroban-env-host/src/test/e2e_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ fn invoke_host_function_helper(
LedgerKey::ContractData(LedgerKeyContractData {
contract: cd.contract.clone(),
key: cd.key.clone(),
durability: cd.durability.clone(),
durability: cd.durability,
})
}
LedgerEntryData::ContractCode(code) => {
Expand Down Expand Up @@ -313,7 +313,7 @@ fn invoke_host_function_recording_helper(
auth_entries,
ledger_info.clone(),
snapshot,
prng_seed.clone(),
*prng_seed,
&mut diagnostic_events,
)?;
Ok(InvokeHostFunctionRecordingHelperResult {
Expand Down
2 changes: 1 addition & 1 deletion soroban-env-host/src/test/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ fn too_many_event_topics() -> Result<(), HostError> {
// created, recording the contract event a cheap operation.
budget.reset_default()?;
for i in 0..100 {
host.contract_event(topics.clone(), Val::from_u32(i).to_val())?;
host.contract_event(topics, Val::from_u32(i).to_val())?;
}
assert_le!(budget.get_cpu_insns_consumed()?, 200_000);
assert_le!(budget.get_mem_bytes_consumed()?, 10000);
Expand Down
4 changes: 2 additions & 2 deletions soroban-env-host/src/test/lifecycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1027,7 +1027,7 @@ mod cap_54_55_56 {
let wasm = get_contract_wasm_ref(&host, contract_id);
let module_cache = host.try_borrow_module_cache()?;
if let Some(module_cache) = &*module_cache {
assert!(module_cache.get_module(&*host, &wasm).is_ok());
assert!(module_cache.get_module(&host, &wasm).is_ok());
} else {
panic!("expected module cache");
}
Expand Down Expand Up @@ -1345,7 +1345,7 @@ mod cap_54_55_56 {

// Check that the module cache did not get populated with the new wasm.
if let Some(module_cache) = &*host.try_borrow_module_cache()? {
assert!(module_cache.get_module(&*host, &wasm_hash)?.is_none());
assert!(module_cache.get_module(&host, &wasm_hash)?.is_none());
} else {
panic!("expected module cache");
}
Expand Down
11 changes: 7 additions & 4 deletions soroban-env-host/src/test/observe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ impl Observations {
let path = full_path(protocol, testname);
let obs: BTreeMap<String, String> = if path.exists() {
println!("reading {}", path.display());
let file = File::open(&path).expect(&format!("unable to open {}", path.display()));
serde_json::from_reader(file).expect(&format!("failed to parse {}", path.display()))
let file =
File::open(&path).unwrap_or_else(|_| panic!("unable to open {}", path.display()));
serde_json::from_reader(file)
.unwrap_or_else(|_| panic!("failed to parse {}", path.display()))
} else {
BTreeMap::new()
};
Expand All @@ -72,9 +74,10 @@ impl Observations {
fn save(&self, protocol: u32, testname: &str) {
let path = full_path(protocol, testname);
println!("writing {}", path.display());
let file = File::create(&path).expect(&format!("unable to create {}", path.display()));
let file =
File::create(&path).unwrap_or_else(|_| panic!("unable to create {}", path.display()));
serde_json::to_writer_pretty(file, &self.0)
.expect(&format!("error writing {}", path.display()));
.unwrap_or_else(|_| panic!("error writing {}", path.display()));
}

// Check records the new observation by appending it to the vector
Expand Down
8 changes: 4 additions & 4 deletions soroban-env-host/src/test/prng.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ fn chacha_test_vectors() {
// This just checks that the ChaCha library we're using conforms to
// test vectors found in RFC 7539.
let mut seed = [0; 32];
let mut chacha_0 = ChaCha20Rng::from_seed(seed.into());
let mut chacha_0 = ChaCha20Rng::from_seed(seed);
// Test vectors 1 and 2 use a 0-seeded ChaCha
let ref_out1 = hex!("76b8e0ada0f13d90405d6ae55386bd28bdd219b8a08ded1aa836efcc8b770dc7da41597c5157488d7724e03fb8d84a376a43b8f41518a11cc387b669b2ee6586");
let ref_out2 = hex!("9f07e7be5551387a98ba977c732d080dcb0f29a048e3656912c6533e32ee7aed29b721769ce64e43d57133b074d839d531ed1f28510afb45ace10a1f4b794d6f");
Expand All @@ -358,7 +358,7 @@ fn chacha_test_vectors() {

// Test vector 3 uses a 1-seeded ChaCha
seed[31] = 1;
let mut chacha_1 = ChaCha20Rng::from_seed(seed.into());
let mut chacha_1 = ChaCha20Rng::from_seed(seed);
let ref_out3 = hex!("3aeb5224ecf849929b9d828db1ced4dd832025e8018b8160b82284f3c949aa5a8eca00bbb4a73bdad192b5c42f73f2fd4e273644c8b36125a64addeb006c13a0");
chacha_1.fill_bytes(&mut out); // advance from block 0 to block 1
chacha_1.fill_bytes(&mut out);
Expand All @@ -367,7 +367,7 @@ fn chacha_test_vectors() {
// Test vector 4 uses a high-ff-seeded ChaCha
seed[31] = 0;
seed[1] = 0xff;
let mut chacha_ff = ChaCha20Rng::from_seed(seed.into());
let mut chacha_ff = ChaCha20Rng::from_seed(seed);
let ref_out4 = hex!("72d54dfbf12ec44b362692df94137f328fea8da73990265ec1bbbea1ae9af0ca13b25aa26cb4a648cb9b9d1be65b2c0924a66c54d545ec1b7374f4872e99f096");
chacha_ff.fill_bytes(&mut out); // advance from block 0 to block 2
chacha_ff.fill_bytes(&mut out);
Expand All @@ -376,7 +376,7 @@ fn chacha_test_vectors() {

// Test vector 5 uses a different "nonce" (a.k.a. "stream number")
seed[1] = 0;
let mut chacha_stream_2 = ChaCha20Rng::from_seed(seed.into());
let mut chacha_stream_2 = ChaCha20Rng::from_seed(seed);
chacha_stream_2.set_stream(0x0200_0000_0000_0000u64);
let ref_out5 = hex!("c2c64d378cd536374ae204b9ef933fcd1a8b2288b3dfa49672ab765b54ee27c78a970e0e955c14f3a88e741b97c286f75f8fc299e8148362fa198a39531bed6d");
chacha_stream_2.fill_bytes(&mut out);
Expand Down
2 changes: 1 addition & 1 deletion soroban-env-host/src/test/stellar_asset_contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2297,7 +2297,7 @@ fn test_classic_account_multisig_auth() {
&test.user_key_3,
&test.user_key_4,
];
out_of_order_signers.sort_by_key(|k| k.verifying_key().as_bytes().clone());
out_of_order_signers.sort_by_key(|k| *k.verifying_key().as_bytes());
out_of_order_signers.swap(1, 2);
assert!(contract
.transfer(
Expand Down
2 changes: 1 addition & 1 deletion soroban-env-host/src/test/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ fn test_storage(host: &Host, contract_id: AddressObject, storage: &str) {
true
);

let max_live_until_ledger: u32 = host.max_live_until_ledger().unwrap().into();
let max_live_until_ledger: u32 = host.max_live_until_ledger().unwrap();
let ledger_seq: u32 = host.get_ledger_sequence().unwrap().into();
let max_extend = max_live_until_ledger - ledger_seq;
let threshold: u32 = 1;
Expand Down
10 changes: 3 additions & 7 deletions soroban-env-host/src/testutils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,6 @@ pub(crate) mod wasm {
let num_pages = num_vals * 8 / 0x10_000 + 1;
let mut me = ModEmitter::from_configs(num_pages, 128);
let bytes: Vec<u8> = (0..num_vals)
.into_iter()
.map(|_| initial.get_payload().to_le_bytes())
.flat_map(|a| a.into_iter())
.collect();
Expand All @@ -754,19 +753,16 @@ pub(crate) mod wasm {
let mut me = ModEmitter::from_configs(num_pages, 128);

let key_bytes: Vec<u8> = (0..num_vals)
.into_iter()
.map(|i| format!("{:0>width$}", i, width = 8))
.flat_map(|s| s.into_bytes().into_iter())
.collect();

let val_bytes: Vec<u8> = (0..num_vals)
.into_iter()
.map(|_| initial.get_payload().to_le_bytes())
.flat_map(|a| a.into_iter())
.collect();

let slices: Vec<u8> = (0..num_vals)
.into_iter()
.map(|ptr| {
let slice = 8_u64 << 32 | (ptr * 8) as u64;
slice.to_le_bytes()
Expand All @@ -776,8 +772,8 @@ pub(crate) mod wasm {

let bytes: Vec<u8> = key_bytes
.into_iter()
.chain(val_bytes.into_iter())
.chain(slices.into_iter())
.chain(val_bytes)
.chain(slices)
.collect();

me.define_data_segment(0, bytes);
Expand Down Expand Up @@ -917,7 +913,7 @@ pub(crate) mod wasm {
let me = ModEmitter::default_with_test_protocol();
let fe = me.func_with_arity_and_ret(Arity(0), Arity(0), 0);
let (mut me, fid) = fe.finish();
me.export_func(fid.clone(), "start");
me.export_func(fid, "start");
me.start(fid);
me.finish_no_validate()
}
Expand Down
Loading

0 comments on commit 6705a74

Please sign in to comment.