Skip to content

Commit

Permalink
move HostInterface to core, which is the consumer of this interface
Browse files Browse the repository at this point in the history
  • Loading branch information
poszu committed Jan 3, 2025
1 parent 9af534b commit b6e6d59
Show file tree
Hide file tree
Showing 22 changed files with 46 additions and 504 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

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

13 changes: 13 additions & 0 deletions core/src/host.rs
Original file line number Diff line number Diff line change
@@ -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<u8>) -> Address;
fn deploy(&mut self, code: Vec<u8>) -> Result<Address, Box<dyn Error>>;
}
1 change: 1 addition & 0 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#![warn(unused_extern_crates)]

pub mod disassembler;
pub mod host;
pub mod io;
pub mod runtime;
pub mod syscall;
Expand Down
9 changes: 4 additions & 5 deletions core/src/runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion core/src/syscall/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
};
Expand Down
2 changes: 1 addition & 1 deletion examples/Cargo.lock

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

77 changes: 0 additions & 77 deletions examples/fibonacci/program/Cargo.lock

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

77 changes: 0 additions & 77 deletions examples/hello_world/program/Cargo.lock

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

Loading

0 comments on commit b6e6d59

Please sign in to comment.