From e704caf4fcd8d4b78723bf2bc18287da084cf60a Mon Sep 17 00:00:00 2001 From: "Joshua J. Bouw" Date: Tue, 24 Jan 2023 11:31:30 +0400 Subject: [PATCH] fix: clippy --- engine-precompiles/src/set_gas_token.rs | 2 +- engine-tests/src/tests/standalone/sanity.rs | 4 ++-- engine/src/engine.rs | 25 ++++++++++++--------- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/engine-precompiles/src/set_gas_token.rs b/engine-precompiles/src/set_gas_token.rs index 3dbcd0ae3..9ff1d9d8b 100644 --- a/engine-precompiles/src/set_gas_token.rs +++ b/engine-precompiles/src/set_gas_token.rs @@ -1,9 +1,9 @@ +use crate::prelude::{vec, Cow}; use crate::set_gas_token::events::SetGasTokenLog; use crate::{EvmPrecompileResult, Precompile, PrecompileOutput}; use aurora_engine_types::types::{Address, EthGas}; use evm::backend::Log; use evm::{Context, ExitError}; -use std::borrow::Cow; pub use consts::SET_GAS_TOKEN_ADDRESS; diff --git a/engine-tests/src/tests/standalone/sanity.rs b/engine-tests/src/tests/standalone/sanity.rs index 26197c6a3..db3d72a9a 100644 --- a/engine-tests/src/tests/standalone/sanity.rs +++ b/engine-tests/src/tests/standalone/sanity.rs @@ -2,7 +2,7 @@ use aurora_engine::engine; use aurora_engine_sdk::env::DEFAULT_PREPAID_GAS; use aurora_engine_test_doubles::io::{Storage, StoragePointer}; use aurora_engine_test_doubles::promise::PromiseTracker; -use aurora_engine_types::types::{Address, Wei}; +use aurora_engine_types::types::{Address, EthGas, Wei}; use aurora_engine_types::{account_id::AccountId, H160, H256, U256}; use std::sync::RwLock; @@ -41,7 +41,7 @@ fn test_deploy_code() { origin, Wei::zero(), evm_deploy(&code_to_deploy), - u64::MAX, + EthGas::MAX, Vec::new(), &mut handler, ); diff --git a/engine/src/engine.rs b/engine/src/engine.rs index 7a363afbc..a435286a4 100644 --- a/engine/src/engine.rs +++ b/engine/src/engine.rs @@ -428,7 +428,6 @@ pub struct Engine<'env, I: IO, E: Env> { state: EngineState, origin: Address, gas_price: U256, - gas_token: GasToken, current_account_id: AccountId, io: I, env: &'env E, @@ -464,7 +463,6 @@ impl<'env, I: IO + Copy, E: Env> Engine<'env, I, E> { state, origin, gas_price: U256::zero(), - gas_token: GasToken::ETH, current_account_id, io, env, @@ -509,7 +507,7 @@ impl<'env, I: IO + Copy, E: Env> Engine<'env, I, E> { // This part is questionable. set_balance(&mut self.io, sender, &new_balance); } - GasToken::ERC20(addr) => { + GasToken::ERC20(_addr) => { // TODO: Needs SputnikVM balance check todo!() } @@ -814,7 +812,7 @@ impl<'env, I: IO + Copy, E: Env> Engine<'env, I, E> { &erc20_token, Wei::zero(), setup_receive_erc20_tokens_input(args, &recipient), - u64::MAX, + EthGas::MAX, Vec::new(), // TODO: are there values we should put here? handler, ) @@ -986,10 +984,13 @@ pub fn submit( return Err(EngineErrorKind::GasPayment(err).into()); } }; - let gas_limit: EthGas = transaction - .gas_limit - .try_into() - .map_err(|_| EngineErrorKind::GasOverflow)?; + let gas_limit: EthGas = { + let gas_limit: u64 = transaction + .gas_limit + .try_into() + .map_err(|_| EngineErrorKind::GasOverflow)?; + EthGas::new(gas_limit) + }; let access_list = transaction .access_list .into_iter() @@ -1564,7 +1565,7 @@ unsafe fn schedule_promise_callback( handler.promise_attach_callback(base_id, promise) } -impl<'env, I: IO + Copy, E: Env> evm::backend::Backend for Engine<'env, I, E> { +impl<'env, I: IO + Copy, E: Env> Backend for Engine<'env, I, E> { /// Returns the "effective" gas price (as defined by EIP-1559) fn gas_price(&self) -> U256 { self.gas_price @@ -1851,6 +1852,7 @@ impl<'env, J: IO + Copy, E: Env> ApplyBackend for Engine<'env, J, E> { } #[cfg(test)] +#[cfg(feature = "std")] mod tests { use super::*; use crate::parameters::{FunctionCallArgsV1, FunctionCallArgsV2}; @@ -2139,7 +2141,10 @@ mod tests { data: vec![], access_list: vec![], }; - let actual_result = engine.charge_gas(&origin, &transaction).unwrap(); + // TODO: Add other tests than just ETH as a gas token. + let actual_result = engine + .charge_gas(&origin, &transaction, GasToken::ETH) + .unwrap(); let expected_result = GasPaymentResult { prepaid_amount: Wei::zero(),