1+ use fil_actors_runtime:: reward:: FilterEstimate ;
12use fil_actors_runtime:: test_utils:: * ;
2- use fil_actors_runtime:: INIT_ACTOR_ADDR ;
3+ use fil_actors_runtime:: { INIT_ACTOR_ADDR , REWARD_ACTOR_ADDR } ;
34
45use fil_actor_account:: Method as AccountMethod ;
56use fil_actor_miner:: {
67 Actor , Deadline , Deadlines , Method , MinerConstructorParams as ConstructorParams , State ,
78} ;
9+ use fil_actor_reward:: { Method as RewardMethod , ThisEpochRewardReturn } ;
810
911use fvm_ipld_encoding:: { BytesDe , CborStore } ;
1012use fvm_shared:: address:: Address ;
13+ use fvm_shared:: bigint:: BigInt ;
1114use fvm_shared:: econ:: TokenAmount ;
1215use fvm_shared:: error:: ExitCode ;
13- use fvm_shared:: sector:: { RegisteredPoStProof , SectorSize } ;
16+ use fvm_shared:: sector:: { RegisteredPoStProof , SectorSize , StoragePower } ;
1417
1518use cid:: Cid ;
1619use fvm_ipld_encoding:: ipld_block:: IpldBlock ;
17- use num_traits:: Zero ;
20+ use num_traits:: { FromPrimitive , Zero } ;
1821
1922mod util;
2023
@@ -27,10 +30,19 @@ struct TestEnv {
2730 control_addrs : Vec < Address > ,
2831 peer_id : Vec < u8 > ,
2932 multiaddrs : Vec < BytesDe > ,
33+
34+ power : StoragePower ,
35+ reward : TokenAmount ,
36+ epoch_reward_smooth : FilterEstimate ,
37+
3038 rt : MockRuntime ,
3139}
3240
3341fn prepare_env ( ) -> TestEnv {
42+ let reward = TokenAmount :: from_whole ( 10 ) ;
43+ let power = StoragePower :: from_i128 ( 1 << 50 ) . unwrap ( ) ;
44+ let epoch_reward_smooth = FilterEstimate :: new ( reward. atto ( ) . clone ( ) , BigInt :: from ( 0u8 ) ) ;
45+
3446 let mut env = TestEnv {
3547 receiver : Address :: new_id ( 1000 ) ,
3648 owner : Address :: new_id ( 100 ) ,
@@ -39,6 +51,9 @@ fn prepare_env() -> TestEnv {
3951 control_addrs : vec ! [ Address :: new_id( 999 ) , Address :: new_id( 998 ) ] ,
4052 peer_id : vec ! [ 1 , 2 , 3 ] ,
4153 multiaddrs : vec ! [ BytesDe ( vec![ 1 , 2 , 3 ] ) ] ,
54+ power,
55+ reward,
56+ epoch_reward_smooth,
4257 rt : MockRuntime :: default ( ) ,
4358 } ;
4459
@@ -50,6 +65,7 @@ fn prepare_env() -> TestEnv {
5065 env. rt . hash_func = Box :: new ( hash) ;
5166 env. rt . caller . replace ( INIT_ACTOR_ADDR ) ;
5267 env. rt . caller_type . replace ( * INIT_ACTOR_CODE_ID ) ;
68+ env. rt . add_balance ( TokenAmount :: from_atto ( 633318697598976000u64 ) ) ;
5369 env
5470}
5571
@@ -61,16 +77,29 @@ fn constructor_params(env: &TestEnv) -> ConstructorParams {
6177 window_post_proof_type : RegisteredPoStProof :: StackedDRGWindow32GiBV1P1 ,
6278 peer_id : env. peer_id . clone ( ) ,
6379 multi_addresses : env. multiaddrs . clone ( ) ,
80+ network_qap : env. epoch_reward_smooth . clone ( ) ,
6481 }
6582}
6683
6784#[ test]
6885fn simple_construction ( ) {
6986 let env = prepare_env ( ) ;
87+ let current_reward = ThisEpochRewardReturn {
88+ this_epoch_baseline_power : env. power . clone ( ) ,
89+ this_epoch_reward_smoothed : env. epoch_reward_smooth . clone ( ) ,
90+ } ;
7091 let params = constructor_params ( & env) ;
7192
7293 env. rt . set_caller ( * INIT_ACTOR_CODE_ID , INIT_ACTOR_ADDR ) ;
7394 env. rt . expect_validate_caller_addr ( vec ! [ INIT_ACTOR_ADDR ] ) ;
95+ env. rt . expect_send_simple (
96+ REWARD_ACTOR_ADDR ,
97+ RewardMethod :: ThisEpochReward as u64 ,
98+ None ,
99+ TokenAmount :: zero ( ) ,
100+ IpldBlock :: serialize_cbor ( & current_reward) . unwrap ( ) ,
101+ ExitCode :: OK ,
102+ ) ;
74103 env. rt . expect_send_simple (
75104 env. worker ,
76105 AccountMethod :: PubkeyAddress as u64 ,
@@ -87,7 +116,7 @@ fn simple_construction() {
87116 expect_empty ( result) ;
88117 env. rt . verify ( ) ;
89118
90- let state = env. rt . get_state :: < State > ( ) ;
119+ let mut state = env. rt . get_state :: < State > ( ) ;
91120
92121 let info = state. get_info ( & env. rt . store ) . unwrap ( ) ;
93122 assert_eq ! ( env. owner, info. owner) ;
@@ -100,10 +129,21 @@ fn simple_construction() {
100129 assert_eq ! ( 2349 , info. window_post_partition_sectors) ;
101130
102131 assert_eq ! ( TokenAmount :: zero( ) , state. pre_commit_deposits) ;
103- assert_eq ! ( TokenAmount :: zero( ) , state. locked_funds) ;
132+ assert_eq ! ( TokenAmount :: from_atto( 633318697598976000u64 ) , state. locked_funds) ;
133+ assert_eq ! ( 180 , state. load_vesting_funds( & env. rt. store) . unwrap( ) . funds. len( ) ) ;
104134 assert_ne ! ( Cid :: default ( ) , state. pre_committed_sectors) ;
105135 assert_ne ! ( Cid :: default ( ) , state. sectors) ;
106136
137+ // reset create miner deposit vesting funds
138+ state. save_vesting_funds ( & env. rt . store , & fil_actor_miner:: VestingFunds :: new ( ) ) . unwrap ( ) ;
139+ state. locked_funds = TokenAmount :: zero ( ) ;
140+ env. rt . replace_state ( & state) ;
141+
142+ let state = env. rt . get_state :: < State > ( ) ;
143+ let create_depost_vesting_funds = state. load_vesting_funds ( & env. rt . store ) . unwrap ( ) ;
144+ assert ! ( create_depost_vesting_funds. funds. is_empty( ) ) ;
145+ assert ! ( state. locked_funds. is_zero( ) ) ;
146+
107147 // according to original specs-actors test, this is set by running the code; magic...
108148 let proving_period_start = -2222 ;
109149 assert_eq ! ( proving_period_start, state. proving_period_start) ;
@@ -131,6 +171,10 @@ fn simple_construction() {
131171#[ test]
132172fn control_addresses_are_resolved_during_construction ( ) {
133173 let mut env = prepare_env ( ) ;
174+ let current_reward = ThisEpochRewardReturn {
175+ this_epoch_baseline_power : env. power . clone ( ) ,
176+ this_epoch_reward_smoothed : env. epoch_reward_smooth . clone ( ) ,
177+ } ;
134178
135179 let control1 = new_bls_addr ( 1 ) ;
136180 let control1id = Address :: new_id ( 555 ) ;
@@ -146,6 +190,14 @@ fn control_addresses_are_resolved_during_construction() {
146190 let params = constructor_params ( & env) ;
147191 env. rt . set_caller ( * INIT_ACTOR_CODE_ID , INIT_ACTOR_ADDR ) ;
148192 env. rt . expect_validate_caller_addr ( vec ! [ INIT_ACTOR_ADDR ] ) ;
193+ env. rt . expect_send_simple (
194+ REWARD_ACTOR_ADDR ,
195+ RewardMethod :: ThisEpochReward as u64 ,
196+ None ,
197+ TokenAmount :: zero ( ) ,
198+ IpldBlock :: serialize_cbor ( & current_reward) . unwrap ( ) ,
199+ ExitCode :: OK ,
200+ ) ;
149201 env. rt . expect_send_simple (
150202 env. worker ,
151203 AccountMethod :: PubkeyAddress as u64 ,
0 commit comments