Skip to content

Commit e7df572

Browse files
committed
fix tests
1 parent 2aed34b commit e7df572

File tree

4 files changed

+22
-31
lines changed

4 files changed

+22
-31
lines changed

actors/miner/src/lib.rs

+7-15
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,12 @@ impl Actor {
186186
check_valid_post_proof_type(rt.policy(), params.window_post_proof_type)?;
187187

188188
let balance = rt.current_balance();
189-
let deposit = calculate_create_miner_deposit(rt, params.network_qap)?;
189+
let sector_size = params
190+
.window_post_proof_type
191+
.sector_size()
192+
.map_err(|e| actor_error!(illegal_argument, "invalid sector size: {}", e))?;
193+
194+
let deposit = calculate_create_miner_deposit(rt, params.network_qap, sector_size)?;
190195
if balance < deposit {
191196
return Err(actor_error!(insufficient_funds;
192197
"not enough balance to lock for create miner deposit: \
@@ -5618,6 +5623,7 @@ fn activate_new_sector_infos(
56185623
pub fn calculate_create_miner_deposit(
56195624
rt: &impl Runtime,
56205625
network_qap: FilterEstimate,
5626+
sector_size: SectorSize,
56215627
) -> Result<TokenAmount, ActorError> {
56225628
// set network pledge inputs
56235629
let rew = request_current_epoch_block_reward(rt)?;
@@ -5632,20 +5638,6 @@ pub fn calculate_create_miner_deposit(
56325638
ramp_duration_epochs: pwr.ramp_duration_epochs,
56335639
};
56345640

5635-
/// set sector size with min power
5636-
#[cfg(feature = "min-power-2k")]
5637-
let sector_size = SectorSize::_2KiB;
5638-
#[cfg(feature = "min-power-2g")]
5639-
let sector_size = SectorSize::_8MiB;
5640-
#[cfg(feature = "min-power-32g")]
5641-
let sector_size = SectorSize::_512MiB;
5642-
#[cfg(not(any(
5643-
feature = "min-power-2k",
5644-
feature = "min-power-2g",
5645-
feature = "min-power-32g"
5646-
)))]
5647-
let sector_size = SectorSize::_32GiB;
5648-
56495641
let sector_number = MINIMUM_CONSENSUS_POWER / sector_size as i64;
56505642
let power = qa_power_for_weight(sector_size, MIN_SECTOR_EXPIRATION, &BigInt::zero());
56515643
let sector_initial_pledge = initial_pledge_for_power(

actors/miner/tests/miner_actor_test_construction.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ fn prepare_env() -> TestEnv {
6464
env.rt.caller.replace(INIT_ACTOR_ADDR);
6565
env.rt.caller_type.replace(*INIT_ACTOR_CODE_ID);
6666
// add balance for create miner deposit
67-
env.rt.add_balance(TokenAmount::from_atto(633318697598976000u64));
67+
env.rt.add_balance(TokenAmount::from_atto(798245441765376000u64));
6868
env
6969
}
7070

@@ -146,18 +146,18 @@ fn simple_construction() {
146146

147147
assert_eq!(TokenAmount::zero(), state.pre_commit_deposits);
148148
assert_eq!(TokenAmount::from_atto(633318697598976000u64), state.locked_funds);
149-
assert_eq!(180, state.load_vesting_funds(&env.rt.store).unwrap().funds.len());
149+
assert_eq!(180, state.vesting_funds.load(&env.rt.store).unwrap().len());
150150
assert_ne!(Cid::default(), state.pre_committed_sectors);
151151
assert_ne!(Cid::default(), state.sectors);
152152

153153
// reset create miner deposit vesting funds
154-
state.save_vesting_funds(&env.rt.store, &fil_actor_miner::VestingFunds::new()).unwrap();
154+
state.vesting_funds = Default::default();
155155
state.locked_funds = TokenAmount::zero();
156156
env.rt.replace_state(&state);
157157

158158
let state = env.rt.get_state::<State>();
159-
let create_depost_vesting_funds = state.load_vesting_funds(&env.rt.store).unwrap();
160-
assert!(create_depost_vesting_funds.funds.is_empty());
159+
let create_depost_vesting_funds = state.vesting_funds.load(&env.rt.store).unwrap();
160+
assert!(create_depost_vesting_funds.is_empty());
161161
assert!(state.locked_funds.is_zero());
162162

163163
// according to original specs-actors test, this is set by running the code; magic...

actors/miner/tests/util.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,6 @@ pub struct ActorHarness {
156156
pub epoch_reward_smooth: FilterEstimate,
157157
pub epoch_qa_power_smooth: FilterEstimate,
158158

159-
pub base_fee: TokenAmount,
160159
pub create_depost: TokenAmount,
161160

162161
pub options: HarnessOptions,
@@ -208,8 +207,8 @@ impl ActorHarness {
208207
epoch_reward_smooth: FilterEstimate::new(rwd.atto().clone(), BigInt::from(0)),
209208
epoch_qa_power_smooth: FilterEstimate::new(pwr, BigInt::from(0)),
210209

211-
base_fee: TokenAmount::zero(),
212-
create_depost: TokenAmount::from_atto(633318697598976000u64),
210+
create_depost: TokenAmount::from_atto(798245441765376000u64),
211+
213212
options,
214213
}
215214
}
@@ -228,22 +227,22 @@ impl ActorHarness {
228227

229228
pub fn check_create_miner_depost_and_reset_state(&self, rt: &MockRuntime) {
230229
let mut st = self.get_state(&rt);
231-
let create_depost_vesting_funds = st.load_vesting_funds(&rt.store).unwrap();
230+
let create_depost_vesting_funds = st.vesting_funds.load(&rt.store).unwrap();
232231

233232
// create miner deposit
234-
assert!(create_depost_vesting_funds.funds.len() == 180);
233+
assert!(create_depost_vesting_funds.len() == 180);
235234
assert!(st.locked_funds == self.create_depost);
236235

237236
// reset create miner deposit vesting funds
238-
st.save_vesting_funds(&rt.store(), &VestingFunds::new()).unwrap();
237+
st.vesting_funds = Default::default();
239238
st.locked_funds = TokenAmount::zero();
240239
rt.replace_state(&st);
241240
rt.set_balance(rt.get_balance() - &self.create_depost);
242241

243242
let st = self.get_state(&rt);
244-
let create_depost_vesting_funds = st.load_vesting_funds(&rt.store).unwrap();
243+
let create_depost_vesting_funds = st.vesting_funds.load(&rt.store).unwrap();
245244

246-
assert!(create_depost_vesting_funds.funds.is_empty());
245+
assert!(create_depost_vesting_funds.is_empty());
247246
assert!(st.locked_funds.is_zero());
248247
}
249248

integration_tests/src/util/workflows.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -160,16 +160,16 @@ pub fn create_miner_internal(
160160
let wrap_store = DynBlockstore::wrap(v.blockstore());
161161
vm_api::util::mutate_state(v, &res.id_address, |st: &mut MinerState| {
162162
// checkcreate miner deposit
163-
assert!(st.load_vesting_funds(&wrap_store).unwrap().funds.len() == 180);
163+
assert!(st.vesting_funds.load(&wrap_store).unwrap().len() == 180);
164164
assert!(st.locked_funds == TokenAmount::from_atto(CREATE_MINER_DEPOSIT));
165165

166166
// reset create miner deposit vesting funds
167-
st.save_vesting_funds(&wrap_store, &fil_actor_miner::VestingFunds::new()).unwrap();
167+
st.vesting_funds = Default::default();
168168
st.locked_funds = TokenAmount::zero();
169169
});
170170

171171
let state: MinerState = get_state(v, &res.id_address).unwrap();
172-
assert!(state.load_vesting_funds(&wrap_store).unwrap().funds.is_empty());
172+
assert!(state.vesting_funds.load(&wrap_store).unwrap().is_empty());
173173
assert!(state.locked_funds.is_zero());
174174

175175
let mut actor_state = v.actor(&res.id_address).unwrap();

0 commit comments

Comments
 (0)