Skip to content

Commit

Permalink
Rupan/market actor tests (#426)
Browse files Browse the repository at this point in the history
* Initial code stuff

* Implemented most tests. 2 are failing becuase of a simple overflow issue. The others can be tested until miner actor fucntionality is complete

* SOme formatting

* Adding changes

* Adding some missing codes

* Adding cron_tick function

* Misc changes

* Adding more changes

* Fmt changes

* Removing excess stuff

* Update

* Adding fmt changes

* CLiipy fix

* Adding time related fucntionality

* MOre chnages

* Adding chnages

* readding submodule

* Market actor update

* Lint fixes

* Adding minor chnages

* Minor updates

* Lock commit

* Fixing lock file issue

* Adding tipset meta data

* Correcting submodule
  • Loading branch information
RajarupanSampanthan authored Jun 25, 2020
1 parent 68c026a commit 8de380d
Show file tree
Hide file tree
Showing 7 changed files with 573 additions and 15 deletions.
1 change: 0 additions & 1 deletion utils/test_utils/src/chain_structures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use crypto::{Signature, Signer, VRFProof};
use encoding::{from_slice, to_vec};
use forest_libp2p::blocksync::{BlockSyncResponse, TipsetBundle};
use forest_libp2p::rpc::RPCResponse;

use message::{SignedMessage, UnsignedMessage};
use num_bigint::BigUint;
use std::error::Error;
Expand Down
9 changes: 4 additions & 5 deletions vm/actor/src/builtin/market/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,6 @@ impl Actor {
let miner_addr = *rt.message().from();
let mut total_deal_space_time = BigUint::zero();
let mut total_verified_deal_space_time = BigUint::zero();

rt.transaction::<State, Result<(), ActorError>, _>(|st, rt| {
// if there are no dealIDs, it is a CommittedCapacity sector
// and the totalDealSpaceTime should be zero
Expand Down Expand Up @@ -367,7 +366,6 @@ impl Actor {
st.states = states
.flush()
.map_err(|e| ActorError::new(ExitCode::ErrIllegalState, e.into()))?;

Ok(())
})??;

Expand Down Expand Up @@ -478,6 +476,7 @@ impl Actor {
RT: Runtime<BS>,
{
rt.validate_immediate_caller_is(std::iter::once(&*CRON_ACTOR_ADDR))?;

let mut amount_slashed = BigUint::zero();
let mut timed_out_verified_deals: Vec<DealProposal> = Vec::new();

Expand All @@ -501,7 +500,8 @@ impl Actor {
let mut lt = BalanceTable::from_root(rt.store(), &st.locked_table)
.map_err(|e| ActorError::new(ExitCode::ErrIllegalState, e.into()))?;

let mut i = st.last_cron + 1;
// TODO Adjust when Epoch becomes i32
let mut i = st.last_cron.unwrap() + 1;
while i <= rt.curr_epoch() {
dbe.for_each(i, |id| {
let mut state: DealState = states
Expand Down Expand Up @@ -609,7 +609,7 @@ impl Actor {

st.deal_ops_by_epoch = nd_bec;

st.last_cron = rt.curr_epoch();
st.last_cron = OptionalEpoch(Some(rt.curr_epoch()));

Ok(())
})??;
Expand All @@ -633,7 +633,6 @@ impl Actor {
&Serialized::default(),
&amount_slashed,
)?;

Ok(())
}
}
Expand Down
16 changes: 12 additions & 4 deletions vm/actor/src/builtin/market/policy.rs
Original file line number Diff line number Diff line change
@@ -1,37 +1,45 @@
// Copyright 2020 ChainSafe Systems
// SPDX-License-Identifier: Apache-2.0, MIT

use crate::network::EPOCHS_IN_YEAR;
use clock::ChainEpoch;
use fil_types::PaddedPieceSize;
use num_traits::Zero;
use vm::TokenAmount;

// The maximum supply of Filecoin that will ever exist (in token units)
const TOTAL_FILECOIN: u64 = 2_000_000_000;
const TOKEN_PRECISION: u64 = 1_000_000_000_000_000_000;

/// DealUpdatesInterval is the number of blocks between payouts for deals
pub const DEAL_UPDATED_INTERVAL: u64 = 100;

pub(super) fn deal_duration_bounds(_size: PaddedPieceSize) -> (ChainEpoch, ChainEpoch) {
(0, 10000) // PARAM_FINISH
(0, EPOCHS_IN_YEAR) // PARAM_FINISH
}

pub(super) fn deal_price_per_epoch_bounds(
_size: PaddedPieceSize,
_duration: ChainEpoch,
) -> (TokenAmount, TokenAmount) {
(TokenAmount::zero(), TokenAmount::from(1u32 << 20)) // PARAM_FINISH
let v = TokenAmount::from(TOTAL_FILECOIN) * TokenAmount::from(TOKEN_PRECISION);
(TokenAmount::zero(), v) // PARAM_FINISH
}

pub(super) fn deal_provider_collateral_bounds(
_piece_size: PaddedPieceSize,
_duration: ChainEpoch,
) -> (TokenAmount, TokenAmount) {
(TokenAmount::zero(), TokenAmount::from(1u32 << 20)) // PARAM_FINISH
let v = TokenAmount::from(TOTAL_FILECOIN) * TokenAmount::from(TOKEN_PRECISION);
(TokenAmount::zero(), v) // PARAM_FINISH
}

pub(super) fn deal_client_collateral_bounds(
_piece_size: PaddedPieceSize,
_duration: ChainEpoch,
) -> (TokenAmount, TokenAmount) {
(TokenAmount::zero(), TokenAmount::from(1u32 << 20)) // PARAM_FINISH
let v = TokenAmount::from(TOTAL_FILECOIN) * TokenAmount::from(TOKEN_PRECISION);
(TokenAmount::zero(), v) // PARAM_FINISH
}

pub(super) fn collateral_penalty_for_deal_activation_missed(
Expand Down
7 changes: 3 additions & 4 deletions vm/actor/src/builtin/market/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub struct State {
/// Metadata cached for efficient iteration over deals.
/// SetMultimap<Address>
pub deal_ops_by_epoch: Cid,
pub last_cron: ChainEpoch,
pub last_cron: OptionalEpoch,
}

impl State {
Expand All @@ -45,7 +45,7 @@ impl State {
locked_table: empty_map,
next_id: 0,
deal_ops_by_epoch: empty_mset,
last_cron: ChainEpoch::default(),
last_cron: OptionalEpoch::default(),
}
}

Expand Down Expand Up @@ -291,7 +291,7 @@ impl State {

Ok(())
}
fn get_escrow_balance<BS: BlockStore>(
pub fn get_escrow_balance<BS: BlockStore>(
&self,
store: &BS,
a: &Address,
Expand Down Expand Up @@ -422,7 +422,6 @@ impl State {
// Subtract from locked and escrow tables
et.must_subtract(addr, &amount)?;
lt.must_subtract(addr, &amount)?;

Ok(())
}

Expand Down
2 changes: 1 addition & 1 deletion vm/actor/src/util/optional_epoch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer};
use std::convert::TryInto;
use std::ops::Deref;

#[derive(PartialEq, Eq, Copy, Clone, Debug)]
#[derive(PartialEq, Eq, Copy, Clone, Debug, Default)]
pub struct OptionalEpoch(pub Option<ChainEpoch>);

impl Deref for OptionalEpoch {
Expand Down
16 changes: 16 additions & 0 deletions vm/actor/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ impl<'a, BS: BlockStore> MockRuntime<'a, BS> {
*self.expect_validate_caller_addr.borrow_mut() = Some(addr.to_vec());
}

#[allow(dead_code)]
pub fn expect_validate_caller_type(&self, types: &[Cid]) {
assert!(types.len() > 0, "addrs must be non-empty");
*self.expect_validate_caller_type.borrow_mut() = Some(types.to_vec());
}

#[allow(dead_code)]
pub fn expect_validate_caller_any(&self) {
self.expect_validate_caller_any.set(true);
Expand Down Expand Up @@ -258,6 +264,16 @@ impl<'a, BS: BlockStore> MockRuntime<'a, BS> {
self.caller_type = code_id.clone();
self.actor_code_cids.insert(address, code_id);
}

#[allow(dead_code)]
pub fn set_value(&mut self, value: TokenAmount) {
self.message = UnsignedMessage::builder()
.to(self.message.to().clone())
.from(self.message.from().clone())
.value(value)
.build()
.unwrap();
}
}

impl<BS: BlockStore> Runtime<BS> for MockRuntime<'_, BS> {
Expand Down
Loading

0 comments on commit 8de380d

Please sign in to comment.