@@ -8,6 +8,7 @@ use std::ops::Neg;
88use anyhow:: anyhow;
99use cid:: Cid ;
1010use fil_actors_runtime:: reward:: FilterEstimate ;
11+ use fil_actors_runtime:: runtime:: policy_constants:: MINIMUM_CONSENSUS_POWER ;
1112use fvm_ipld_amt:: Amt ;
1213use fvm_ipld_bitfield:: iter:: Ranges ;
1314use fvm_ipld_bitfield:: { BitField , UnvalidatedBitField , Validate } ;
@@ -38,7 +39,7 @@ use fvm_shared::{ActorID, HAMT_BIT_WIDTH, METHOD_SEND};
3839use itertools:: Itertools ;
3940use lazy_static:: lazy_static;
4041use multihash_codetable:: MultihashDigest ;
41- use num_traits:: { FromPrimitive , Signed } ;
42+ use num_traits:: Signed ;
4243
4344use fil_actor_account:: Method as AccountMethod ;
4445use fil_actor_market:: {
@@ -132,6 +133,24 @@ pub fn setup() -> (ActorHarness, MockRuntime) {
132133 ( h, rt)
133134}
134135
136+ pub fn minimum_initial_pledge (
137+ rt : & MockRuntime ,
138+ baseline_power : & StoragePower ,
139+ reward_estimated : & FilterEstimate ,
140+ ) -> TokenAmount {
141+ let pwr = CurrentTotalPowerReturn :: default ( ) ;
142+
143+ initial_pledge_for_power (
144+ & BigInt :: from ( MINIMUM_CONSENSUS_POWER ) ,
145+ baseline_power,
146+ reward_estimated,
147+ & pwr. quality_adj_power_smoothed ,
148+ & rt. circulating_supply . borrow ( ) ,
149+ * rt. epoch . borrow ( ) - pwr. ramp_start_epoch ,
150+ pwr. ramp_duration_epochs ,
151+ )
152+ }
153+
135154pub struct ActorHarness {
136155 pub receiver : Address ,
137156 pub owner : Address ,
@@ -155,8 +174,6 @@ pub struct ActorHarness {
155174 pub epoch_reward_smooth : FilterEstimate ,
156175 pub epoch_qa_power_smooth : FilterEstimate ,
157176
158- pub create_depost : TokenAmount ,
159-
160177 pub options : HarnessOptions ,
161178}
162179
@@ -206,8 +223,6 @@ impl ActorHarness {
206223 epoch_reward_smooth : FilterEstimate :: new ( rwd. atto ( ) . clone ( ) , BigInt :: from ( 0 ) ) ,
207224 epoch_qa_power_smooth : FilterEstimate :: new ( pwr, BigInt :: from ( 0 ) ) ,
208225
209- create_depost : TokenAmount :: from_atto ( 798245441765376000u64 ) ,
210-
211226 options,
212227 }
213228 }
@@ -224,24 +239,27 @@ impl ActorHarness {
224239 check_state_invariants_from_mock_runtime ( rt) ;
225240 }
226241
227- pub fn check_create_miner_depost_and_reset_state ( & self , rt : & MockRuntime ) {
242+ pub fn check_create_miner_deposit_and_reset_state ( & self , rt : & MockRuntime ) {
243+ let create_deposit =
244+ minimum_initial_pledge ( rt, & self . baseline_power , & self . epoch_reward_smooth ) ;
245+
228246 let mut st = self . get_state ( & rt) ;
229- let create_depost_vesting_funds = st. vesting_funds . load ( & rt. store ) . unwrap ( ) ;
247+ let create_deposit_vesting_funds = st. vesting_funds . load ( & rt. store ) . unwrap ( ) ;
230248
231249 // create miner deposit
232- assert ! ( create_depost_vesting_funds . len( ) == 180 ) ;
233- assert ! ( st. locked_funds == self . create_depost ) ;
250+ assert ! ( create_deposit_vesting_funds . len( ) == 180 ) ;
251+ assert ! ( st. locked_funds == create_deposit ) ;
234252
235253 // reset create miner deposit vesting funds
236254 st. vesting_funds = Default :: default ( ) ;
237255 st. locked_funds = TokenAmount :: zero ( ) ;
238256 rt. replace_state ( & st) ;
239- rt. set_balance ( rt. get_balance ( ) - & self . create_depost ) ;
257+ rt. set_balance ( rt. get_balance ( ) - & create_deposit ) ;
240258
241259 let st = self . get_state ( & rt) ;
242- let create_depost_vesting_funds = st. vesting_funds . load ( & rt. store ) . unwrap ( ) ;
260+ let create_deposit_vesting_funds = st. vesting_funds . load ( & rt. store ) . unwrap ( ) ;
243261
244- assert ! ( create_depost_vesting_funds . is_empty( ) ) ;
262+ assert ! ( create_deposit_vesting_funds . is_empty( ) ) ;
245263 assert ! ( st. locked_funds. is_zero( ) ) ;
246264 }
247265
@@ -271,23 +289,12 @@ impl ActorHarness {
271289 }
272290
273291 pub fn construct_and_verify ( & self , rt : & MockRuntime ) {
274- let reward = TokenAmount :: from_whole ( 10 ) ;
275- let power = StoragePower :: from_i128 ( 1 << 50 ) . unwrap ( ) ;
276- let epoch_reward_smooth = FilterEstimate :: new ( reward. atto ( ) . clone ( ) , BigInt :: from ( 0u8 ) ) ;
277-
278292 let current_reward = ThisEpochRewardReturn {
279- this_epoch_baseline_power : power . clone ( ) ,
280- this_epoch_reward_smoothed : epoch_reward_smooth. clone ( ) ,
293+ this_epoch_baseline_power : self . baseline_power . clone ( ) ,
294+ this_epoch_reward_smoothed : self . epoch_reward_smooth . clone ( ) ,
281295 } ;
282296
283- let current_total_power = CurrentTotalPowerReturn {
284- raw_byte_power : Default :: default ( ) ,
285- quality_adj_power : Default :: default ( ) ,
286- pledge_collateral : Default :: default ( ) ,
287- quality_adj_power_smoothed : Default :: default ( ) ,
288- ramp_start_epoch : Default :: default ( ) ,
289- ramp_duration_epochs : Default :: default ( ) ,
290- } ;
297+ let current_total_power = CurrentTotalPowerReturn :: default ( ) ;
291298
292299 let params = ConstructorParams {
293300 owner : self . owner ,
@@ -296,7 +303,6 @@ impl ActorHarness {
296303 window_post_proof_type : self . window_post_proof_type ,
297304 peer_id : vec ! [ 0 ] ,
298305 multi_addresses : vec ! [ ] ,
299- network_qap : epoch_reward_smooth,
300306 } ;
301307
302308 rt. actor_code_cids . borrow_mut ( ) . insert ( self . owner , * ACCOUNT_ACTOR_CODE_ID ) ;
@@ -305,7 +311,9 @@ impl ActorHarness {
305311 rt. actor_code_cids . borrow_mut ( ) . insert ( * a, * ACCOUNT_ACTOR_CODE_ID ) ;
306312 }
307313
308- rt. add_balance ( self . create_depost . clone ( ) ) ;
314+ // set circulating supply non-zero so we get non-zero fees
315+ rt. set_circulating_supply ( TokenAmount :: from_whole ( 500_000 ) ) ;
316+ rt. add_balance ( minimum_initial_pledge ( rt, & self . baseline_power , & self . epoch_reward_smooth ) ) ;
309317 rt. set_caller ( * INIT_ACTOR_CODE_ID , INIT_ACTOR_ADDR ) ;
310318 rt. expect_validate_caller_addr ( vec ! [ INIT_ACTOR_ADDR ] ) ;
311319 rt. expect_send_simple (
@@ -332,15 +340,13 @@ impl ActorHarness {
332340 IpldBlock :: serialize_cbor ( & self . worker_key ) . unwrap ( ) ,
333341 ExitCode :: OK ,
334342 ) ;
335- // set circulating supply non-zero so we get non-zero fees
336- rt. set_circulating_supply ( TokenAmount :: from_whole ( 500_000 ) ) ;
337343
338344 let result = rt
339345 . call :: < Actor > ( Method :: Constructor as u64 , IpldBlock :: serialize_cbor ( & params) . unwrap ( ) )
340346 . unwrap ( ) ;
341347 expect_empty ( result) ;
342348 rt. verify ( ) ;
343- self . check_create_miner_depost_and_reset_state ( rt) ;
349+ self . check_create_miner_deposit_and_reset_state ( rt) ;
344350 }
345351
346352 pub fn set_peer_id ( & self , rt : & MockRuntime , new_id : Vec < u8 > ) {
0 commit comments