Skip to content

Commit

Permalink
use implicit execution for cron_tick
Browse files Browse the repository at this point in the history
  • Loading branch information
alexytsu committed Oct 11, 2023
1 parent 755ff97 commit 0517295
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
3 changes: 2 additions & 1 deletion integration_tests/src/util/workflows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ use fil_actors_runtime::VERIFIED_REGISTRY_ACTOR_ADDR;
use fil_actors_runtime::{DATACAP_TOKEN_ACTOR_ID, VERIFIED_REGISTRY_ACTOR_ID};
use vm_api::trace::ExpectInvocation;
use vm_api::util::apply_ok;
use vm_api::util::apply_ok_implicit;
use vm_api::util::get_state;
use vm_api::util::DynBlockstore;
use vm_api::VM;
Expand All @@ -86,7 +87,7 @@ use super::miner_dline_info;
use super::sector_deadline;

pub fn cron_tick(v: &dyn VM) {
apply_ok(
apply_ok_implicit(
v,
&SYSTEM_ACTOR_ADDR,
&CRON_ACTOR_ADDR,
Expand Down
27 changes: 27 additions & 0 deletions vm_api/src/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,33 @@ pub fn apply_code<S: Serialize>(
assert_eq!(code, res.code, "expected code {}, got {} ({})", code, res.code, res.message);
res.ret.map_or(RawBytes::default(), |b| RawBytes::new(b.data))
}

pub fn apply_ok_implicit<S: Serialize>(
v: &dyn VM,
from: &Address,
to: &Address,
value: &TokenAmount,
method: MethodNum,
params: Option<S>,
) -> RawBytes {
apply_code_implicit(v, from, to, value, method, params, ExitCode::OK)
}

pub fn apply_code_implicit<S: Serialize>(
v: &dyn VM,
from: &Address,
to: &Address,
value: &TokenAmount,
method: MethodNum,
params: Option<S>,
code: ExitCode,
) -> RawBytes {
let params = params.map(|p| IpldBlock::serialize_cbor(&p).unwrap().unwrap());
let res = v.execute_message_implicit(from, to, value, method, params).unwrap();
assert_eq!(code, res.code, "expected code {}, got {} ({})", code, res.code, res.message);
res.ret.map_or(RawBytes::default(), |b| RawBytes::new(b.data))
}

pub fn get_state<T: DeserializeOwned>(v: &dyn VM, a: &Address) -> Option<T> {
let cid = v.actor(a).unwrap().state;
v.blockstore().get(&cid).unwrap().map(|slice| fvm_ipld_encoding::from_slice(&slice).unwrap())
Expand Down

0 comments on commit 0517295

Please sign in to comment.