Skip to content

Commit

Permalink
chore: replace unnecessary usage of heap allocated strings in the tes…
Browse files Browse the repository at this point in the history
…ts (#634)
  • Loading branch information
aleksuss authored Feb 3, 2023
1 parent 60165ad commit 5675e75
Show file tree
Hide file tree
Showing 17 changed files with 117 additions and 138 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ wget https://github.com/aurora-is-near/aurora-engine/releases/download/latest/ma
### Installing the Aurora CLI tool

```sh
npm install -g aurora-is-near/aurora-cli
npm install -g @auroraisnear/cli
```

### Deploying the EVM with the CLI
Expand Down
1 change: 0 additions & 1 deletion engine-precompiles/src/modexp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,6 @@ fn saturating_round(x: U256) -> u64 {
fn parse_lengths(input: &[u8]) -> (u64, u64, u64) {
let parse = |start: usize| -> u64 {
// I don't understand why I need a closure here, but doesn't compile without one
#[allow(clippy::redundant_closure)]
saturating_round(parse_bytes(input, start, 32, |x| U256::from(x)))
};
let base_len = parse(0);
Expand Down
2 changes: 1 addition & 1 deletion engine-sdk/src/caching.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use aurora_engine_types::BTreeMap;

/// A naive cache storing all key-value pairs it learns about..
/// A naive cache storing all key-value pairs it learns about.
#[derive(Default)]
pub struct FullCache<K, V> {
inner: BTreeMap<K, V>,
Expand Down
4 changes: 2 additions & 2 deletions engine-sdk/src/near_runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl Runtime {
const GAS_FOR_STATE_MIGRATION: NearGas = NearGas::new(100_000_000_000_000);

/// Deploy code from given key in place of the current contract.
/// Not implemented in terms of higher level traits (eg IO) for efficiency reasons.
/// Not implemented in terms of higher level traits (e.g. IO) for efficiency reasons.
pub fn self_deploy(code_key: &[u8]) {
unsafe {
// Load current account id into register 0.
Expand Down Expand Up @@ -107,7 +107,7 @@ impl StorageIntermediate for RegisterIndex {
unsafe {
let result = exports::register_len(self.0);
// By convention, an unused register will return a length of U64::MAX
// (see https://nomicon.io/RuntimeSpec/Components/BindingsSpec/RegistersAPI.html).
// (see https://nomicon.io/RuntimeSpec/Components/BindingsSpec/RegistersAPI).
if result < u64::MAX {
result as usize
} else {
Expand Down
16 changes: 6 additions & 10 deletions engine-tests/src/test_utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ use crate::test_utils::solidity::{ContractConstructor, DeployedContract};

// TODO(Copied from #84): Make sure that there is only one Signer after both PR are merged.

pub fn origin() -> String {
"aurora".to_string()
}

pub(crate) const ORIGIN: &str = "aurora";
pub(crate) const SUBMIT: &str = "submit";
pub(crate) const CALL: &str = "call";
pub(crate) const DEPLOY_ERC20: &str = "deploy_erc20_token";
Expand Down Expand Up @@ -539,7 +536,6 @@ impl AuroraRunner {

impl Default for AuroraRunner {
fn default() -> Self {
let aurora_account_id = "aurora".to_string();
let evm_wasm_bytes = if cfg!(feature = "mainnet-test") {
std::fs::read("../bin/aurora-mainnet-test.wasm").unwrap()
} else if cfg!(feature = "testnet-test") {
Expand All @@ -554,16 +550,16 @@ impl Default for AuroraRunner {
let wasm_config = runtime_config.wasm_config.clone();

Self {
aurora_account_id: aurora_account_id.clone(),
aurora_account_id: ORIGIN.to_string(),
chain_id: 1313161556, // NEAR localnet,
code: ContractCode::new(evm_wasm_bytes, None),
cache: Default::default(),
ext: mocked_external::MockedExternalWithTrie::new(Default::default()),
context: VMContext {
current_account_id: as_account_id(&aurora_account_id),
signer_account_id: as_account_id(&aurora_account_id),
current_account_id: as_account_id(ORIGIN),
signer_account_id: as_account_id(ORIGIN),
signer_account_pk: vec![],
predecessor_account_id: as_account_id(&aurora_account_id),
predecessor_account_id: as_account_id(ORIGIN),
input: vec![],
block_index: 0,
block_timestamp: 0,
Expand Down Expand Up @@ -803,7 +799,7 @@ pub(crate) fn parse_eth_gas(output: &VMOutcome) -> u64 {
pub(crate) fn validate_address_balance_and_nonce(
runner: &AuroraRunner,
address: Address,
expected_balance: crate::prelude::Wei,
expected_balance: Wei,
expected_nonce: U256,
) {
assert_eq!(runner.get_balance(address), expected_balance, "balance");
Expand Down
4 changes: 2 additions & 2 deletions engine-tests/src/tests/contract_call.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::prelude::{parameters::SubmitResult, vec, Address, Wei, H256, U256};
use crate::test_utils::{origin, AuroraRunner, Signer};
use crate::test_utils::{AuroraRunner, Signer, ORIGIN};

use crate::test_utils;
use crate::test_utils::exit_precompile::{Tester, TesterConstructor, DEST_ACCOUNT, DEST_ADDRESS};
Expand All @@ -25,7 +25,7 @@ fn setup_test() -> (AuroraRunner, Signer, Address, Tester) {
)
.into();

runner.mint(token, tester.contract.address, 1_000_000_000, origin());
runner.mint(token, tester.contract.address, 1_000_000_000, ORIGIN);

(runner, signer, token, tester)
}
Expand Down
6 changes: 3 additions & 3 deletions engine-tests/src/tests/eip1559.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const EXAMPLE_TX_HEX: &str = "02f8c101010a8207d0833d090094cccccccccccccccccccccc
// TODO(#170): generally support Ethereum tests
#[test]
fn test_eip_1559_tx_encoding_decoding() {
let secret_key = exmaple_signer().secret_key;
let secret_key = example_signer().secret_key;
let transaction = example_transaction();

let signed_tx = test_utils::sign_eip_1559_transaction(transaction, &secret_key);
Expand Down Expand Up @@ -52,7 +52,7 @@ fn test_eip_1559_tx_encoding_decoding() {
#[test]
fn test_eip_1559_example() {
let mut runner = test_utils::deploy_evm();
let mut signer = exmaple_signer();
let mut signer = example_signer();
let signer_address = test_utils::address_from_secret_key(&signer.secret_key);
let contract_address = test_utils::address_from_hex(CONTRACT_ADDRESS);
let contract_code = hex::decode(CONTRACT_CODE).unwrap();
Expand Down Expand Up @@ -112,7 +112,7 @@ fn encode_tx(signed_tx: &SignedTransaction1559) -> Vec<u8> {
.collect()
}

fn exmaple_signer() -> test_utils::Signer {
fn example_signer() -> test_utils::Signer {
let secret_key =
libsecp256k1::SecretKey::parse_slice(&hex::decode(SECRET_KEY).unwrap()).unwrap();

Expand Down
Loading

0 comments on commit 5675e75

Please sign in to comment.