Skip to content

Commit

Permalink
test runtime: use Rc<MemoryBlockstore>. (#599)
Browse files Browse the repository at this point in the history
With the real FvmRuntime, we expect that cloning the &Blockstore
returned by Runtime#store() would simply clone the reference.

This is because inside the FVM, blockstore calls proxy out to
FVM syscalls; the proxy itself holds no state, and cloning it is
unimportant.

However, in the MockRuntime, we were using a physical MemoryBlockstore.
Cloning it would return a new physical copy, thus breaking the expectation.

This commit makes MockRuntime use an Rc<MemoryBlockstore>, so all clones
will point to the same MemoryBlockstore, thus preserving the expectation.

Co-authored-by: Raúl Kripalani <raul@protocol.ai>
  • Loading branch information
Stebalien and raulk authored Sep 2, 2022
1 parent 2b446ef commit b5c101a
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion actors/market/tests/harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ pub fn assert_deal_deleted(rt: &mut MockRuntime, deal_id: DealID, p: DealProposa
let pending_deals: Hamt<&fvm_ipld_blockstore::MemoryBlockstore, DealProposal> =
fil_actors_runtime::make_map_with_root_and_bitwidth(
&st.pending_proposals,
&rt.store,
&*rt.store,
PROPOSALS_AMT_BITWIDTH,
)
.unwrap();
Expand Down
2 changes: 1 addition & 1 deletion actors/miner/tests/expiration_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ fn empty_expiration_queue_with_quantizing(
let empty_array =
Amt::<(), _>::new_with_bit_width(&rt.store, TEST_AMT_BITWIDTH).flush().unwrap();

ExpirationQueue::new(&rt.store, &empty_array, quant).unwrap()
ExpirationQueue::new(&*rt.store, &empty_array, quant).unwrap()
}

fn empty_expiration_queue(rt: &MockRuntime) -> ExpirationQueue<MemoryBlockstore> {
Expand Down
2 changes: 1 addition & 1 deletion actors/miner/tests/miner_actor_test_bitfield_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ fn empty_bitfield_queue_with_quantizing(
) -> BitFieldQueue<MemoryBlockstore> {
let cid = Amt::<(), _>::new_with_bit_width(&rt.store, bitwidth).flush().unwrap();

BitFieldQueue::new(&rt.store, &cid, quant).unwrap()
BitFieldQueue::new(&*rt.store, &cid, quant).unwrap()
}

fn empty_bitfield_queue(rt: &MockRuntime, bitwidth: u32) -> BitFieldQueue<MemoryBlockstore> {
Expand Down
4 changes: 2 additions & 2 deletions actors/verifreg/tests/harness/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,15 +217,15 @@ impl Harness {

fn load_verifiers(rt: &MockRuntime) -> Map<MemoryBlockstore, BigIntDe> {
let state: State = rt.get_state();
make_map_with_root_and_bitwidth::<_, BigIntDe>(&state.verifiers, &rt.store, HAMT_BIT_WIDTH)
make_map_with_root_and_bitwidth::<_, BigIntDe>(&state.verifiers, &*rt.store, HAMT_BIT_WIDTH)
.unwrap()
}

fn load_clients(rt: &MockRuntime) -> Map<MemoryBlockstore, BigIntDe> {
let state: State = rt.get_state();
make_map_with_root_and_bitwidth::<_, BigIntDe>(
&state.verified_clients,
&rt.store,
&*rt.store,
HAMT_BIT_WIDTH,
)
.unwrap()
Expand Down
7 changes: 4 additions & 3 deletions runtime/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use core::fmt;
use std::cell::RefCell;
use std::collections::{BTreeMap, HashMap, VecDeque};
use std::rc::Rc;

use anyhow::anyhow;
use cid::multihash::{Code, Multihash as OtherMultihash};
Expand Down Expand Up @@ -122,7 +123,7 @@ pub struct MockRuntime {

// VM Impl
pub in_call: bool,
pub store: MemoryBlockstore,
pub store: Rc<MemoryBlockstore>,
pub in_transaction: bool,

// Expectations
Expand Down Expand Up @@ -665,7 +666,7 @@ impl MessageInfo for MockRuntime {
}
}

impl Runtime<MemoryBlockstore> for MockRuntime {
impl Runtime<Rc<MemoryBlockstore>> for MockRuntime {
fn network_version(&self) -> NetworkVersion {
self.network_version
}
Expand Down Expand Up @@ -884,7 +885,7 @@ impl Runtime<MemoryBlockstore> for MockRuntime {
ret
}

fn store(&self) -> &MemoryBlockstore {
fn store(&self) -> &Rc<MemoryBlockstore> {
&self.store
}

Expand Down

0 comments on commit b5c101a

Please sign in to comment.