Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test(engine): Increase unit test coverage #618

Merged
merged 1 commit into from
Oct 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions engine-precompiles/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ ethabi = { version = "17.1", default-features = false }
hex = { version = "0.4", default-features = false, features = ["alloc"] }

[dev-dependencies]
aurora-engine-test-doubles = { path = "../engine-test-doubles" }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
rand = "0.7.3"
Expand Down
124 changes: 124 additions & 0 deletions engine-precompiles/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,130 @@ mod tests {
}
}

#[test]
fn test_paused_precompiles_throws_error() {
use crate::{
AllPrecompiles, Context, EvmPrecompileResult, ExitError, Precompile, PrecompileOutput,
Precompiles,
};
use aurora_engine_sdk::env::Fixed;
use aurora_engine_sdk::promise::Noop;
use aurora_engine_test_doubles::io::StoragePointer;
use aurora_engine_types::types::EthGas;
use evm::executor::stack::{PrecompileFailure, PrecompileHandle, PrecompileSet};
use evm::{ExitFatal, ExitReason, Transfer};

struct MockPrecompile;

impl Precompile for MockPrecompile {
fn required_gas(input: &[u8]) -> Result<EthGas, ExitError>
where
Self: Sized,
{
Ok(EthGas::new(0))
}

fn run(
&self,
input: &[u8],
target_gas: Option<EthGas>,
context: &Context,
is_static: bool,
) -> EvmPrecompileResult {
Ok(PrecompileOutput::default())
}
}

struct MockPrecompileHandle {
code_address: H160,
}

impl MockPrecompileHandle {
pub fn new(code_address: H160) -> Self {
Self { code_address }
}
}

impl PrecompileHandle for MockPrecompileHandle {
fn call(
&mut self,
to: H160,
transfer: Option<Transfer>,
input: Vec<u8>,
gas_limit: Option<u64>,
is_static: bool,
context: &Context,
) -> (ExitReason, Vec<u8>) {
unimplemented!()
}

fn record_cost(&mut self, cost: u64) -> Result<(), ExitError> {
unimplemented!()
}

fn remaining_gas(&self) -> u64 {
unimplemented!()
}

fn log(
&mut self,
address: H160,
topics: Vec<aurora_engine_types::H256>,
data: Vec<u8>,
) -> Result<(), ExitError> {
unimplemented!()
}

fn code_address(&self) -> H160 {
self.code_address
}

fn input(&self) -> &[u8] {
unimplemented!()
}

fn context(&self) -> &Context {
unimplemented!()
}

fn is_static(&self) -> bool {
unimplemented!()
}

fn gas_limit(&self) -> Option<u64> {
unimplemented!()
}
}

let precompile_address = Address::default();
let precompile: AllPrecompiles<StoragePointer, Fixed, Noop> =
AllPrecompiles::Generic(Box::new(MockPrecompile));

let precompiles: Precompiles<StoragePointer, Fixed, Noop> = Precompiles {
all_precompiles: {
let mut map = prelude::BTreeMap::new();
map.insert(precompile_address, precompile);
map
},
paused_precompiles: {
let mut set = prelude::BTreeSet::new();
set.insert(precompile_address);
set
},
};
let mut precompile_handle = MockPrecompileHandle::new(precompile_address.raw());

let result = precompiles
.execute(&mut precompile_handle)
.expect("result must contain error but is empty");
let actual_failure = result.expect_err("result must contain failure but is successful");
let expected_failure = PrecompileFailure::Fatal {
exit_status: ExitFatal::Other(prelude::Cow::Borrowed("ERR_PAUSED")),
};

assert_eq!(expected_failure, actual_failure);
}

fn u8_to_address(x: u8) -> Address {
let mut bytes = [0u8; 20];
bytes[19] = x;
Expand Down
1 change: 0 additions & 1 deletion engine-standalone-storage/src/sync/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,6 @@ fn non_submit_execute<'db>(
} else {
engine.receive_erc20_tokens(
&env.predecessor_account_id,
&env.signer_account_id,
args,
&env.current_account_id,
&mut handler,
Expand Down
6 changes: 3 additions & 3 deletions engine-test-doubles/src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ impl StorageIntermediate for Value {

#[derive(Debug, Default)]
pub struct Storage {
input: Vec<u8>,
output: Vec<u8>,
kv_store: HashMap<Vec<u8>, Vec<u8>>,
pub input: Vec<u8>,
pub output: Vec<u8>,
pub kv_store: HashMap<Vec<u8>, Vec<u8>>,
}

/// In-memory implementation of [IO].
Expand Down
1 change: 1 addition & 0 deletions engine-test-doubles/src/promise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use aurora_engine_types::parameters::{PromiseBatchAction, PromiseCreateArgs};
use aurora_engine_types::types::PromiseResult;
use std::collections::HashMap;

#[derive(Debug, PartialEq)]
pub enum PromiseArgs {
Create(PromiseCreateArgs),
#[allow(dead_code)]
Expand Down
2 changes: 2 additions & 0 deletions engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ aurora-engine-test-doubles = { path = "../engine-test-doubles" }
serde_json = "1"
rand = "0.7.3"
test-case = "2.1"
sha3 = "0.10"
digest = "0.10"

[features]
default = ["std"]
Expand Down
Loading