diff --git a/Cargo.lock b/Cargo.lock index 2e5e70fe..6a85f4ac 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -188,7 +188,6 @@ version = "0.6.2" dependencies = [ "blake3", "hex", - "mockall", "parity-scale-codec", ] diff --git a/core/src/host.rs b/core/src/host.rs new file mode 100644 index 00000000..7e817451 --- /dev/null +++ b/core/src/host.rs @@ -0,0 +1,13 @@ +use std::error::Error; + +use athena_interface::{Address, AthenaMessage, ExecutionResult, StorageStatus}; + +#[mockall::automock] +pub trait HostInterface { + fn get_storage(&self, addr: &Address, key: &[u8; 32]) -> [u8; 32]; + fn set_storage(&mut self, addr: &Address, key: &[u8; 32], value: &[u8; 32]) -> StorageStatus; + fn get_balance(&self, addr: &Address) -> u64; + fn call(&mut self, msg: AthenaMessage) -> ExecutionResult; + fn spawn(&mut self, blob: Vec) -> Address; + fn deploy(&mut self, code: Vec) -> Result>; +} diff --git a/core/src/lib.rs b/core/src/lib.rs index b908c77f..0bb34c5b 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -14,6 +14,7 @@ #![warn(unused_extern_crates)] pub mod disassembler; +pub mod host; pub mod io; pub mod runtime; pub mod syscall; diff --git a/core/src/runtime/mod.rs b/core/src/runtime/mod.rs index 05ddb61f..ab909515 100644 --- a/core/src/runtime/mod.rs +++ b/core/src/runtime/mod.rs @@ -29,9 +29,10 @@ use std::sync::Arc; use thiserror::Error; +use crate::host::HostInterface; use crate::utils::AthenaCoreOpts; -use athena_interface::{AthenaContext, HostInterface, StatusCode}; +use athena_interface::{AthenaContext, StatusCode}; /// An implementation of a runtime for the Athena RISC-V VM. /// @@ -833,10 +834,8 @@ impl<'host> Runtime<'host> { #[cfg(test)] pub mod tests { - use crate::{runtime::ExecutionError, utils::with_max_gas}; - use athena_interface::{ - Address, AthenaContext, ExecutionResult, MockHostInterface, StatusCode, ADDRESS_LENGTH, - }; + use crate::{host::MockHostInterface, runtime::ExecutionError, utils::with_max_gas}; + use athena_interface::{Address, AthenaContext, ExecutionResult, StatusCode, ADDRESS_LENGTH}; use crate::{ runtime::Register, diff --git a/core/src/syscall/host.rs b/core/src/syscall/host.rs index 99bccd65..2c945736 100644 --- a/core/src/syscall/host.rs +++ b/core/src/syscall/host.rs @@ -245,9 +245,10 @@ impl Syscall for SyscallHostDeploy { #[cfg(test)] mod tests { - use athena_interface::{Address, AthenaContext, ExecutionResult, MockHostInterface}; + use athena_interface::{Address, AthenaContext, ExecutionResult}; use crate::{ + host::MockHostInterface, runtime::{self, Program}, utils::{with_max_gas, AthenaCoreOpts}, }; diff --git a/examples/Cargo.lock b/examples/Cargo.lock index 1123ca33..00490612 100644 --- a/examples/Cargo.lock +++ b/examples/Cargo.lock @@ -116,7 +116,6 @@ version = "0.6.2" dependencies = [ "blake3", "hex", - "mockall", "parity-scale-codec", ] @@ -138,6 +137,7 @@ name = "athena-sdk" version = "0.6.2" dependencies = [ "anyhow", + "athena-builder", "athena-core", "athena-interface", "vergen-git2", diff --git a/examples/fibonacci/program/Cargo.lock b/examples/fibonacci/program/Cargo.lock index 7f9e3c80..630dd998 100644 --- a/examples/fibonacci/program/Cargo.lock +++ b/examples/fibonacci/program/Cargo.lock @@ -2,12 +2,6 @@ # It is not intended for manual editing. version = 4 -[[package]] -name = "anstyle" -version = "1.0.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8365de52b16c035ff4fcafe0092ba9390540e3e352870ac09933bebcaa2c8c56" - [[package]] name = "arrayref" version = "0.3.9" @@ -26,7 +20,6 @@ version = "0.6.2" dependencies = [ "blake3", "hex", - "mockall", "parity-scale-codec", ] @@ -117,12 +110,6 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7c74b8349d32d297c9134b8c88677813a227df8f779daa29bfc29c183fe3dca6" -[[package]] -name = "downcast" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1435fa1053d8b2fbbe9be7e97eca7f33d37b28409959813daefc1446a14247f1" - [[package]] name = "equivalent" version = "1.0.1" @@ -136,12 +123,6 @@ dependencies = [ "athena-vm", ] -[[package]] -name = "fragile" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c2141d6d6c8512188a7891b4b01590a45f6dac67afb4f255c4124dbb86d4eaa" - [[package]] name = "funty" version = "2.0.0" @@ -204,32 +185,6 @@ version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" -[[package]] -name = "mockall" -version = "0.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39a6bfcc6c8c7eed5ee98b9c3e33adc726054389233e201c95dab2d41a3839d2" -dependencies = [ - "cfg-if", - "downcast", - "fragile", - "mockall_derive", - "predicates", - "predicates-tree", -] - -[[package]] -name = "mockall_derive" -version = "0.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25ca3004c2efe9011bd4e461bd8256445052b9615405b4f7ea43fc8ca5c20898" -dependencies = [ - "cfg-if", - "proc-macro2", - "quote", - "syn 2.0.85", -] - [[package]] name = "parity-scale-codec" version = "3.6.12" @@ -265,32 +220,6 @@ dependencies = [ "zerocopy", ] -[[package]] -name = "predicates" -version = "3.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e9086cc7640c29a356d1a29fd134380bee9d8f79a17410aa76e7ad295f42c97" -dependencies = [ - "anstyle", - "predicates-core", -] - -[[package]] -name = "predicates-core" -version = "1.0.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae8177bee8e75d6846599c6b9ff679ed51e882816914eec639944d7c9aa11931" - -[[package]] -name = "predicates-tree" -version = "1.0.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41b740d195ed3166cd147c8047ec98db0e22ec019eb8eeb76d343b795304fb13" -dependencies = [ - "predicates-core", - "termtree", -] - [[package]] name = "proc-macro-crate" version = "3.2.0" @@ -408,12 +337,6 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" -[[package]] -name = "termtree" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3369f5ac52d5eb6ab48c6b4ffdc8efbcad6b89c765749064ba298f2c68a16a76" - [[package]] name = "toml_datetime" version = "0.6.8" diff --git a/examples/hello_world/program/Cargo.lock b/examples/hello_world/program/Cargo.lock index 038a405e..2fca425f 100644 --- a/examples/hello_world/program/Cargo.lock +++ b/examples/hello_world/program/Cargo.lock @@ -2,12 +2,6 @@ # It is not intended for manual editing. version = 4 -[[package]] -name = "anstyle" -version = "1.0.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8365de52b16c035ff4fcafe0092ba9390540e3e352870ac09933bebcaa2c8c56" - [[package]] name = "arrayref" version = "0.3.9" @@ -26,7 +20,6 @@ version = "0.6.2" dependencies = [ "blake3", "hex", - "mockall", "parity-scale-codec", ] @@ -117,24 +110,12 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7c74b8349d32d297c9134b8c88677813a227df8f779daa29bfc29c183fe3dca6" -[[package]] -name = "downcast" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1435fa1053d8b2fbbe9be7e97eca7f33d37b28409959813daefc1446a14247f1" - [[package]] name = "equivalent" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" -[[package]] -name = "fragile" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c2141d6d6c8512188a7891b4b01590a45f6dac67afb4f255c4124dbb86d4eaa" - [[package]] name = "funty" version = "2.0.0" @@ -204,32 +185,6 @@ version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" -[[package]] -name = "mockall" -version = "0.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39a6bfcc6c8c7eed5ee98b9c3e33adc726054389233e201c95dab2d41a3839d2" -dependencies = [ - "cfg-if", - "downcast", - "fragile", - "mockall_derive", - "predicates", - "predicates-tree", -] - -[[package]] -name = "mockall_derive" -version = "0.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25ca3004c2efe9011bd4e461bd8256445052b9615405b4f7ea43fc8ca5c20898" -dependencies = [ - "cfg-if", - "proc-macro2", - "quote", - "syn 2.0.85", -] - [[package]] name = "parity-scale-codec" version = "3.6.12" @@ -265,32 +220,6 @@ dependencies = [ "zerocopy", ] -[[package]] -name = "predicates" -version = "3.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e9086cc7640c29a356d1a29fd134380bee9d8f79a17410aa76e7ad295f42c97" -dependencies = [ - "anstyle", - "predicates-core", -] - -[[package]] -name = "predicates-core" -version = "1.0.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae8177bee8e75d6846599c6b9ff679ed51e882816914eec639944d7c9aa11931" - -[[package]] -name = "predicates-tree" -version = "1.0.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41b740d195ed3166cd147c8047ec98db0e22ec019eb8eeb76d343b795304fb13" -dependencies = [ - "predicates-core", - "termtree", -] - [[package]] name = "proc-macro-crate" version = "3.2.0" @@ -408,12 +337,6 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" -[[package]] -name = "termtree" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3369f5ac52d5eb6ab48c6b4ffdc8efbcad6b89c765749064ba298f2c68a16a76" - [[package]] name = "toml_datetime" version = "0.6.8" diff --git a/examples/io/program/Cargo.lock b/examples/io/program/Cargo.lock index 5ffb1bf2..d3c07db1 100644 --- a/examples/io/program/Cargo.lock +++ b/examples/io/program/Cargo.lock @@ -2,12 +2,6 @@ # It is not intended for manual editing. version = 4 -[[package]] -name = "anstyle" -version = "1.0.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8365de52b16c035ff4fcafe0092ba9390540e3e352870ac09933bebcaa2c8c56" - [[package]] name = "arrayref" version = "0.3.9" @@ -26,7 +20,6 @@ version = "0.6.2" dependencies = [ "blake3", "hex", - "mockall", "parity-scale-codec", ] @@ -117,24 +110,12 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7c74b8349d32d297c9134b8c88677813a227df8f779daa29bfc29c183fe3dca6" -[[package]] -name = "downcast" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1435fa1053d8b2fbbe9be7e97eca7f33d37b28409959813daefc1446a14247f1" - [[package]] name = "equivalent" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" -[[package]] -name = "fragile" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c2141d6d6c8512188a7891b4b01590a45f6dac67afb4f255c4124dbb86d4eaa" - [[package]] name = "funty" version = "2.0.0" @@ -205,32 +186,6 @@ version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" -[[package]] -name = "mockall" -version = "0.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39a6bfcc6c8c7eed5ee98b9c3e33adc726054389233e201c95dab2d41a3839d2" -dependencies = [ - "cfg-if", - "downcast", - "fragile", - "mockall_derive", - "predicates", - "predicates-tree", -] - -[[package]] -name = "mockall_derive" -version = "0.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25ca3004c2efe9011bd4e461bd8256445052b9615405b4f7ea43fc8ca5c20898" -dependencies = [ - "cfg-if", - "proc-macro2", - "quote", - "syn 2.0.85", -] - [[package]] name = "parity-scale-codec" version = "3.6.12" @@ -266,32 +221,6 @@ dependencies = [ "zerocopy", ] -[[package]] -name = "predicates" -version = "3.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e9086cc7640c29a356d1a29fd134380bee9d8f79a17410aa76e7ad295f42c97" -dependencies = [ - "anstyle", - "predicates-core", -] - -[[package]] -name = "predicates-core" -version = "1.0.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae8177bee8e75d6846599c6b9ff679ed51e882816914eec639944d7c9aa11931" - -[[package]] -name = "predicates-tree" -version = "1.0.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41b740d195ed3166cd147c8047ec98db0e22ec019eb8eeb76d343b795304fb13" -dependencies = [ - "predicates-core", - "termtree", -] - [[package]] name = "proc-macro-crate" version = "3.2.0" @@ -409,12 +338,6 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" -[[package]] -name = "termtree" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3369f5ac52d5eb6ab48c6b4ffdc8efbcad6b89c765749064ba298f2c68a16a76" - [[package]] name = "toml_datetime" version = "0.6.8" diff --git a/examples/wallet/program/Cargo.lock b/examples/wallet/program/Cargo.lock index 4a998b44..440cff9a 100644 --- a/examples/wallet/program/Cargo.lock +++ b/examples/wallet/program/Cargo.lock @@ -2,12 +2,6 @@ # It is not intended for manual editing. version = 4 -[[package]] -name = "anstyle" -version = "1.0.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bec1de6f59aedf83baf9ff929c98f2ad654b97c9510f4e70cf6f661d49fd5b1" - [[package]] name = "arrayref" version = "0.3.8" @@ -26,7 +20,6 @@ version = "0.6.2" dependencies = [ "blake3", "hex", - "mockall", "parity-scale-codec", ] @@ -143,24 +136,12 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7c74b8349d32d297c9134b8c88677813a227df8f779daa29bfc29c183fe3dca6" -[[package]] -name = "downcast" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1435fa1053d8b2fbbe9be7e97eca7f33d37b28409959813daefc1446a14247f1" - [[package]] name = "equivalent" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" -[[package]] -name = "fragile" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c2141d6d6c8512188a7891b4b01590a45f6dac67afb4f255c4124dbb86d4eaa" - [[package]] name = "funty" version = "2.0.0" @@ -223,32 +204,6 @@ version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" -[[package]] -name = "mockall" -version = "0.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39a6bfcc6c8c7eed5ee98b9c3e33adc726054389233e201c95dab2d41a3839d2" -dependencies = [ - "cfg-if", - "downcast", - "fragile", - "mockall_derive", - "predicates", - "predicates-tree", -] - -[[package]] -name = "mockall_derive" -version = "0.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25ca3004c2efe9011bd4e461bd8256445052b9615405b4f7ea43fc8ca5c20898" -dependencies = [ - "cfg-if", - "proc-macro2", - "quote", - "syn 2.0.82", -] - [[package]] name = "parity-scale-codec" version = "3.6.12" @@ -284,32 +239,6 @@ dependencies = [ "zerocopy", ] -[[package]] -name = "predicates" -version = "3.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e9086cc7640c29a356d1a29fd134380bee9d8f79a17410aa76e7ad295f42c97" -dependencies = [ - "anstyle", - "predicates-core", -] - -[[package]] -name = "predicates-core" -version = "1.0.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae8177bee8e75d6846599c6b9ff679ed51e882816914eec639944d7c9aa11931" - -[[package]] -name = "predicates-tree" -version = "1.0.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41b740d195ed3166cd147c8047ec98db0e22ec019eb8eeb76d343b795304fb13" -dependencies = [ - "predicates-core", - "termtree", -] - [[package]] name = "proc-macro-crate" version = "3.1.0" @@ -427,12 +356,6 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" -[[package]] -name = "termtree" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3369f5ac52d5eb6ab48c6b4ffdc8efbcad6b89c765749064ba298f2c68a16a76" - [[package]] name = "toml_datetime" version = "0.6.8" diff --git a/examples/wallet/script/src/host.rs b/examples/wallet/script/src/host.rs index 581f1f24..309b5655 100644 --- a/examples/wallet/script/src/host.rs +++ b/examples/wallet/script/src/host.rs @@ -3,10 +3,10 @@ use std::{collections::BTreeMap, error::Error}; use athena_interface::{ - payload::ExecutionPayload, Address, AthenaMessage, Balance, Bytes32, ExecutionResult, - HostInterface, StatusCode, StorageStatus, + payload::ExecutionPayload, Address, AthenaMessage, Balance, Bytes32, ExecutionResult, StatusCode, + StorageStatus, }; -use athena_runner::{vm::AthenaRevision, AthenaVm}; +use athena_runner::{host::HostInterface, vm::AthenaRevision, AthenaVm}; // Stores some of the context that a running host would store to keep // track of what's going on in the VM execution diff --git a/examples/wallet/script/src/main.rs b/examples/wallet/script/src/main.rs index c51477d7..e9d48f93 100644 --- a/examples/wallet/script/src/main.rs +++ b/examples/wallet/script/src/main.rs @@ -9,8 +9,8 @@ use host::*; use std::error::Error; -use athena_interface::{Address, AthenaContext, Encode, HostInterface, MethodSelector}; -use athena_sdk::{AthenaStdin, ExecutionClient}; +use athena_interface::{Address, AthenaContext, Encode, MethodSelector}; +use athena_sdk::{host::HostInterface, AthenaStdin, ExecutionClient}; use athena_vm_sdk::{wallet::SpendArguments, Pubkey}; /// The ELF (executable and linkable format) file for the Athena RISC-V VM. @@ -103,13 +103,13 @@ fn main() { #[cfg(test)] mod tests { - use athena_interface::MockHostInterface; use athena_interface::{ payload::ExecutionPayloadBuilder, payload::Payload, Address, AthenaMessage, Balance, Encode, MessageKind, MethodSelector, StatusCode, }; use athena_runner::vm::AthenaRevision; use athena_runner::AthenaVm; + use athena_sdk::host::MockHostInterface; use athena_sdk::{AthenaStdin, ExecutionClient}; use athena_vm_sdk::Pubkey; use ed25519_dalek::ed25519::signature::Signer; diff --git a/ffi/vmlib/src/lib.rs b/ffi/vmlib/src/lib.rs index 8db494c6..bb956064 100644 --- a/ffi/vmlib/src/lib.rs +++ b/ffi/vmlib/src/lib.rs @@ -8,10 +8,10 @@ use athcon_vm::{ SetOptionError, }; use athena_interface::{ - Address, AthenaMessage, Balance, Bytes32, ExecutionResult, HostInterface, MessageKind, - StatusCode, StorageStatus, TransactionContext, + Address, AthenaMessage, Balance, Bytes32, ExecutionResult, MessageKind, StatusCode, + StorageStatus, TransactionContext, }; -use athena_runner::{vm::AthenaRevision, AthenaVm}; +use athena_runner::{host::HostInterface, vm::AthenaRevision, AthenaVm}; #[athcon_declare_vm("Athena", "athena1", "0.1.0")] pub struct AthenaVMWrapper { diff --git a/interface/Cargo.toml b/interface/Cargo.toml index 00742f41..3677914e 100644 --- a/interface/Cargo.toml +++ b/interface/Cargo.toml @@ -11,4 +11,3 @@ edition.workspace = true blake3 = "1.5.5" hex = "0.4.3" parity-scale-codec = { version = "3.6.12", features = ["derive"] } -mockall = "0.13.1" diff --git a/interface/src/lib.rs b/interface/src/lib.rs index afc91020..4bd3286b 100644 --- a/interface/src/lib.rs +++ b/interface/src/lib.rs @@ -8,7 +8,7 @@ pub use context::*; pub use parity_scale_codec::{Decode, Encode}; -use std::{convert::TryFrom, error::Error, fmt}; +use std::{convert::TryFrom, fmt}; pub const ADDRESS_LENGTH: usize = 24; pub const BYTES32_LENGTH: usize = 32; @@ -287,16 +287,6 @@ impl ExecutionResult { } } -#[mockall::automock] -pub trait HostInterface { - fn get_storage(&self, addr: &Address, key: &Bytes32) -> Bytes32; - fn set_storage(&mut self, addr: &Address, key: &Bytes32, value: &Bytes32) -> StorageStatus; - fn get_balance(&self, addr: &Address) -> Balance; - fn call(&mut self, msg: AthenaMessage) -> ExecutionResult; - fn spawn(&mut self, blob: Vec) -> Address; - fn deploy(&mut self, code: Vec) -> Result>; -} - #[cfg(test)] mod tests { use super::*; diff --git a/runner/src/lib.rs b/runner/src/lib.rs index aaa62422..13f910fe 100644 --- a/runner/src/lib.rs +++ b/runner/src/lib.rs @@ -1,3 +1,4 @@ pub mod vm; +pub use athena_sdk::host; pub use vm::AthenaVm; diff --git a/runner/src/vm.rs b/runner/src/vm.rs index 28540cad..3ae3495e 100644 --- a/runner/src/vm.rs +++ b/runner/src/vm.rs @@ -1,10 +1,10 @@ use athena_core::runtime::ExecutionError; use athena_interface::{ payload::{ExecutionPayload, Payload}, - AthenaContext, AthenaMessage, Decode, ExecutionResult, HostInterface, StatusCode, + AthenaContext, AthenaMessage, Decode, ExecutionResult, StatusCode, }; -use athena_sdk::{AthenaStdin, ExecutionClient}; +use athena_sdk::{host::HostInterface, AthenaStdin, ExecutionClient}; // currently unused #[derive(Debug, Clone, Copy)] @@ -135,8 +135,9 @@ mod tests { use super::*; use athena_interface::{ payload::{ExecutionPayloadBuilder, Payload}, - Address, AthenaMessage, Balance, Encode, MessageKind, MethodSelector, MockHostInterface, + Address, AthenaMessage, Balance, Encode, MessageKind, MethodSelector, }; + use athena_sdk::host::MockHostInterface; const ADDRESS_ALICE: Address = Address([1u8; 24]); fn setup_logger() { diff --git a/sdk/src/lib.rs b/sdk/src/lib.rs index c066f198..9669928a 100644 --- a/sdk/src/lib.rs +++ b/sdk/src/lib.rs @@ -2,10 +2,11 @@ //! //! A library for interacting with the Athena RISC-V VM. +pub use athena_core::host; pub use athena_core::io::{AthenaPublicValues, AthenaStdin}; use athena_core::runtime::{ExecutionError, Program, Runtime}; use athena_core::utils::AthenaCoreOpts; -use athena_interface::{AthenaContext, HostInterface, MethodSelector}; +use athena_interface::{AthenaContext, MethodSelector}; /// A client for interacting with Athena. pub struct ExecutionClient; @@ -50,7 +51,7 @@ impl ExecutionClient { &self, elf: &[u8], stdin: AthenaStdin, - host: Option<&mut dyn HostInterface>, + host: Option<&mut dyn host::HostInterface>, max_gas: Option, context: Option, ) -> Result<(AthenaPublicValues, Option), ExecutionError> { @@ -77,7 +78,7 @@ impl ExecutionClient { elf: &[u8], selector: &MethodSelector, stdin: AthenaStdin, - host: Option<&mut dyn HostInterface>, + host: Option<&mut dyn host::HostInterface>, max_gas: Option, context: Option, ) -> Result<(AthenaPublicValues, Option), ExecutionError> { @@ -118,7 +119,7 @@ impl ExecutionClient { &self, elf: &[u8], stdin: AthenaStdin, - host: Option<&mut dyn HostInterface>, + host: Option<&mut dyn host::HostInterface>, max_gas: Option, context: Option, gdb_port: u16, @@ -162,7 +163,7 @@ impl ExecutionClient { elf: &[u8], function: &str, stdin: AthenaStdin, - host: Option<&mut dyn HostInterface>, + host: Option<&mut dyn host::HostInterface>, max_gas: Option, context: Option, gdb_port: u16, diff --git a/tests/entrypoint/Cargo.lock b/tests/entrypoint/Cargo.lock index fbbf2373..ebfe8ee3 100644 --- a/tests/entrypoint/Cargo.lock +++ b/tests/entrypoint/Cargo.lock @@ -2,12 +2,6 @@ # It is not intended for manual editing. version = 4 -[[package]] -name = "anstyle" -version = "1.0.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8365de52b16c035ff4fcafe0092ba9390540e3e352870ac09933bebcaa2c8c56" - [[package]] name = "arrayref" version = "0.3.9" @@ -26,7 +20,6 @@ version = "0.6.2" dependencies = [ "blake3", "hex", - "mockall", "parity-scale-codec", ] @@ -143,12 +136,6 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7c74b8349d32d297c9134b8c88677813a227df8f779daa29bfc29c183fe3dca6" -[[package]] -name = "downcast" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1435fa1053d8b2fbbe9be7e97eca7f33d37b28409959813daefc1446a14247f1" - [[package]] name = "entrypoint-test" version = "0.1.0" @@ -164,12 +151,6 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" -[[package]] -name = "fragile" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c2141d6d6c8512188a7891b4b01590a45f6dac67afb4f255c4124dbb86d4eaa" - [[package]] name = "funty" version = "2.0.0" @@ -232,32 +213,6 @@ version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" -[[package]] -name = "mockall" -version = "0.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39a6bfcc6c8c7eed5ee98b9c3e33adc726054389233e201c95dab2d41a3839d2" -dependencies = [ - "cfg-if", - "downcast", - "fragile", - "mockall_derive", - "predicates", - "predicates-tree", -] - -[[package]] -name = "mockall_derive" -version = "0.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25ca3004c2efe9011bd4e461bd8256445052b9615405b4f7ea43fc8ca5c20898" -dependencies = [ - "cfg-if", - "proc-macro2", - "quote", - "syn 2.0.85", -] - [[package]] name = "parity-scale-codec" version = "3.6.12" @@ -293,32 +248,6 @@ dependencies = [ "zerocopy", ] -[[package]] -name = "predicates" -version = "3.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e9086cc7640c29a356d1a29fd134380bee9d8f79a17410aa76e7ad295f42c97" -dependencies = [ - "anstyle", - "predicates-core", -] - -[[package]] -name = "predicates-core" -version = "1.0.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae8177bee8e75d6846599c6b9ff679ed51e882816914eec639944d7c9aa11931" - -[[package]] -name = "predicates-tree" -version = "1.0.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41b740d195ed3166cd147c8047ec98db0e22ec019eb8eeb76d343b795304fb13" -dependencies = [ - "predicates-core", - "termtree", -] - [[package]] name = "proc-macro-crate" version = "3.2.0" @@ -436,12 +365,6 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" -[[package]] -name = "termtree" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3369f5ac52d5eb6ab48c6b4ffdc8efbcad6b89c765749064ba298f2c68a16a76" - [[package]] name = "toml_datetime" version = "0.6.8" diff --git a/tests/host/tests/host.rs b/tests/host/tests/host.rs index b9c70abd..aa27fc34 100644 --- a/tests/host/tests/host.rs +++ b/tests/host/tests/host.rs @@ -1,10 +1,9 @@ use std::{collections::BTreeMap, error::Error}; use athena_interface::{ - Address, AthenaContext, AthenaMessage, Balance, Bytes32, ExecutionResult, HostInterface, - StorageStatus, + Address, AthenaContext, AthenaMessage, Balance, Bytes32, ExecutionResult, StorageStatus, }; -use athena_sdk::{AthenaStdin, ExecutionClient}; +use athena_sdk::{host::HostInterface, AthenaStdin, ExecutionClient}; #[derive(Default)] struct Host { diff --git a/tests/panic/Cargo.lock b/tests/panic/Cargo.lock index 5e032158..8089865d 100644 --- a/tests/panic/Cargo.lock +++ b/tests/panic/Cargo.lock @@ -2,12 +2,6 @@ # It is not intended for manual editing. version = 4 -[[package]] -name = "anstyle" -version = "1.0.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bec1de6f59aedf83baf9ff929c98f2ad654b97c9510f4e70cf6f661d49fd5b1" - [[package]] name = "arrayref" version = "0.3.8" @@ -26,7 +20,6 @@ version = "0.6.2" dependencies = [ "blake3", "hex", - "mockall", "parity-scale-codec", ] @@ -117,24 +110,12 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7c74b8349d32d297c9134b8c88677813a227df8f779daa29bfc29c183fe3dca6" -[[package]] -name = "downcast" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1435fa1053d8b2fbbe9be7e97eca7f33d37b28409959813daefc1446a14247f1" - [[package]] name = "equivalent" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" -[[package]] -name = "fragile" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c2141d6d6c8512188a7891b4b01590a45f6dac67afb4f255c4124dbb86d4eaa" - [[package]] name = "funty" version = "2.0.0" @@ -197,32 +178,6 @@ version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" -[[package]] -name = "mockall" -version = "0.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39a6bfcc6c8c7eed5ee98b9c3e33adc726054389233e201c95dab2d41a3839d2" -dependencies = [ - "cfg-if", - "downcast", - "fragile", - "mockall_derive", - "predicates", - "predicates-tree", -] - -[[package]] -name = "mockall_derive" -version = "0.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25ca3004c2efe9011bd4e461bd8256445052b9615405b4f7ea43fc8ca5c20898" -dependencies = [ - "cfg-if", - "proc-macro2", - "quote", - "syn 2.0.87", -] - [[package]] name = "panic-test" version = "0.1.0" @@ -265,32 +220,6 @@ dependencies = [ "zerocopy", ] -[[package]] -name = "predicates" -version = "3.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e9086cc7640c29a356d1a29fd134380bee9d8f79a17410aa76e7ad295f42c97" -dependencies = [ - "anstyle", - "predicates-core", -] - -[[package]] -name = "predicates-core" -version = "1.0.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae8177bee8e75d6846599c6b9ff679ed51e882816914eec639944d7c9aa11931" - -[[package]] -name = "predicates-tree" -version = "1.0.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41b740d195ed3166cd147c8047ec98db0e22ec019eb8eeb76d343b795304fb13" -dependencies = [ - "predicates-core", - "termtree", -] - [[package]] name = "proc-macro-crate" version = "3.2.0" @@ -408,12 +337,6 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" -[[package]] -name = "termtree" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3369f5ac52d5eb6ab48c6b4ffdc8efbcad6b89c765749064ba298f2c68a16a76" - [[package]] name = "toml_datetime" version = "0.6.8" diff --git a/tests/recursive_call/tests/test.rs b/tests/recursive_call/tests/test.rs index 426ce04c..1ccf78a9 100644 --- a/tests/recursive_call/tests/test.rs +++ b/tests/recursive_call/tests/test.rs @@ -2,10 +2,10 @@ use std::error::Error; use athena_interface::{ payload::ExecutionPayload, Address, AthenaContext, AthenaMessage, Balance, Bytes32, - ExecutionResult, HostInterface, StorageStatus, + ExecutionResult, StorageStatus, }; use athena_runner::{vm::AthenaRevision, AthenaVm}; -use athena_sdk::{AthenaStdin, ExecutionClient}; +use athena_sdk::{host::HostInterface, AthenaStdin, ExecutionClient}; struct Host { code: Vec,