Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
alexytsu committed Jul 27, 2023
1 parent 9d46a24 commit 56c231f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
3 changes: 2 additions & 1 deletion state/src/check.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::collections::BTreeMap;
use std::collections::HashMap;
use std::fmt::Debug;

Expand Down Expand Up @@ -114,7 +115,7 @@ macro_rules! get_state {
// It could be replaced with a custom mapping trait (while Rust doesn't support
// abstract collection traits).
pub fn check_state_invariants<BS: Blockstore>(
manifest: &BiBTreeMap<Cid, Type>,
manifest: &BTreeMap<Cid, Type>,
policy: &Policy,
tree: Tree<'_, BS>,
expected_balance_total: &TokenAmount,
Expand Down
14 changes: 7 additions & 7 deletions test_vm/src/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -783,22 +783,22 @@ pub fn change_beneficiary(
);
}

pub fn check_invariants<BS: Blockstore>(vm: &TestVM<'_, BS>) -> anyhow::Result<MessageAccumulator> {
pub fn check_invariants(vm: &dyn VM, policy: &Policy) -> anyhow::Result<MessageAccumulator> {
check_state_invariants(
&vm.actor_manifest(),
&vm.policy(),
policy,
Tree::load(&DynBlockstore::wrap(vm.blockstore()), &vm.state_root()).unwrap(),
&vm.total_fil(),
&vm.circulating_supply(),
vm.epoch() - 1,
)
}

pub fn assert_invariants<BS: Blockstore>(vm: &TestVM<'_, BS>) {
check_invariants(vm).unwrap().assert_empty()
pub fn assert_invariants(vm: &dyn VM, policy: &Policy) {
check_invariants(vm, policy).unwrap().assert_empty()
}

pub fn expect_invariants<BS: Blockstore>(vm: &TestVM<'_, BS>, expected_patterns: &[Regex]) {
check_invariants(vm).unwrap().assert_expected(expected_patterns)
pub fn expect_invariants(vm: &dyn VM, policy: &Policy, expected_patterns: &[Regex]) {
check_invariants(vm, policy).unwrap().assert_expected(expected_patterns)
}

pub fn get_network_stats(vm: &dyn VM) -> NetworkStats {
Expand Down
21 changes: 14 additions & 7 deletions test_vm/src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
* TODO(alexytsu): It should eventually be moved to an external location so that it can be shared
* with the anorth/fvm-workbench implementation
*/
use std::{error::Error, fmt};
use std::{collections::BTreeMap, error::Error, fmt};

use cid::Cid;
use fil_actors_runtime::runtime::Primitives;
use fil_actors_runtime::runtime::{builtins::Type, Primitives};
use fvm_ipld_blockstore::Blockstore;
use fvm_ipld_encoding::{
ipld_block::IpldBlock,
Expand All @@ -28,6 +28,12 @@ pub trait VM {
/// Get the current chain epoch
fn epoch(&self) -> ChainEpoch;

/// Sets the epoch to the specified value
fn set_epoch(&self, epoch: ChainEpoch);

/// Get information about an actor
fn actor(&self, address: &Address) -> Option<ActorState>;

/// Get the balance of the specified actor
fn balance(&self, address: &Address) -> TokenAmount;

Expand All @@ -54,17 +60,18 @@ pub trait VM {
params: Option<IpldBlock>,
) -> Result<MessageResult, VMError>;

/// Sets the epoch to the specified value
fn set_epoch(&self, epoch: ChainEpoch);

/// Take all the invocations that have been made since the last call to this method
fn take_invocations(&self) -> Vec<InvocationTrace>;

/// Get information about an actor
fn actor(&self, address: &Address) -> Option<ActorState>;
// TODO: set circulating supply
fn circulating_supply(&self) -> TokenAmount;

/// Provides access to VM primitives
fn primitives(&self) -> &dyn Primitives;

fn actor_manifest(&self) -> BTreeMap<Cid, Type>;

fn state_root(&self) -> Cid;
}

#[derive(Debug)]
Expand Down

0 comments on commit 56c231f

Please sign in to comment.