Skip to content

Commit bacf044

Browse files
authored
Use idiomatic math operations (#591)
1 parent b7ad2c5 commit bacf044

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

actors/miner/tests/prove_commit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ fn invalid_proof_rejected() {
421421
//require.NoError(t, err)
422422
//assert.Equal(t, []uint64{uint64(sectorNo)}, newSectors)
423423
// Verify pledge lock-up
424-
assert!(st.initial_pledge > TokenAmount::zero());
424+
assert!(st.initial_pledge.is_positive());
425425
rt.reset();
426426

427427
// Duplicate proof (sector no-longer pre-committed)

actors/miner/tests/util.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ impl ActorHarness {
503503

504504
let state = self.get_state(rt);
505505
// burn networkFee
506-
if state.fee_debt > TokenAmount::zero() || params.sectors.len() > 1 {
506+
if state.fee_debt.is_positive() || params.sectors.len() > 1 {
507507
let expected_network_fee =
508508
aggregate_pre_commit_network_fee(params.sectors.len() as i64, base_fee);
509509
let expected_burn = expected_network_fee + state.fee_debt;
@@ -589,7 +589,7 @@ impl ActorHarness {
589589
// in the original test the else branch does some redundant checks which we can omit.
590590

591591
let state = self.get_state(rt);
592-
if state.fee_debt > TokenAmount::zero() {
592+
if state.fee_debt.is_positive() {
593593
rt.expect_send(
594594
*BURNT_FUNDS_ACTOR_ADDR,
595595
METHOD_SEND,
@@ -939,7 +939,7 @@ impl ActorHarness {
939939
}
940940
}
941941

942-
if expected_pledge != TokenAmount::zero() {
942+
if !expected_pledge.is_zero() {
943943
rt.expect_send(
944944
*STORAGE_POWER_ACTOR_ADDR,
945945
PowerMethod::UpdatePledgeTotal as u64,
@@ -1029,7 +1029,7 @@ impl ActorHarness {
10291029
penalty_total += cfg.repaid_fee_debt.clone();
10301030
penalty_total += cfg.expired_precommit_penalty.clone();
10311031

1032-
if penalty_total != TokenAmount::zero() {
1032+
if !penalty_total.is_zero() {
10331033
rt.expect_send(
10341034
*BURNT_FUNDS_ACTOR_ADDR,
10351035
METHOD_SEND,
@@ -1053,7 +1053,7 @@ impl ActorHarness {
10531053
pledge_delta += cfg.expired_sectors_pledge_delta;
10541054
pledge_delta -= immediately_vesting_funds(rt, &state);
10551055

1056-
if pledge_delta != TokenAmount::zero() {
1056+
if !pledge_delta.is_zero() {
10571057
rt.expect_send(
10581058
*STORAGE_POWER_ACTOR_ADDR,
10591059
PowerMethod::UpdatePledgeTotal as u64,
@@ -1407,7 +1407,7 @@ impl ActorHarness {
14071407
ExitCode::OK,
14081408
);
14091409

1410-
if penalty > TokenAmount::zero() {
1410+
if penalty.is_positive() {
14111411
rt.expect_send(
14121412
*BURNT_FUNDS_ACTOR_ADDR,
14131413
METHOD_SEND,
@@ -1587,7 +1587,7 @@ impl ActorHarness {
15871587
rt.set_caller(*ACCOUNT_ACTOR_CODE_ID, self.worker);
15881588
rt.expect_validate_caller_addr(self.caller_addrs());
15891589

1590-
if expected_debt_repaid > TokenAmount::zero() {
1590+
if expected_debt_repaid.is_positive() {
15911591
rt.expect_send(
15921592
*BURNT_FUNDS_ACTOR_ADDR,
15931593
METHOD_SEND,
@@ -1924,7 +1924,7 @@ impl ActorHarness {
19241924
}
19251925

19261926
let total_repaid = expected_repaid_from_vest + expected_repaid_from_balance;
1927-
if total_repaid > TokenAmount::zero() {
1927+
if total_repaid.is_positive() {
19281928
rt.expect_send(
19291929
*BURNT_FUNDS_ACTOR_ADDR,
19301930
METHOD_SEND,

actors/reward/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ impl Actor {
121121

122122
let total_reward = rt.transaction(|st: &mut State, rt| {
123123
let mut block_reward: TokenAmount =
124-
(&st.this_epoch_reward * params.win_count).div_rem(EXPECTED_LEADERS_PER_EPOCH).0;
124+
(&st.this_epoch_reward * params.win_count).div_floor(EXPECTED_LEADERS_PER_EPOCH);
125125
let mut total_reward = &params.gas_reward + &block_reward;
126126
let curr_balance = rt.current_balance();
127127
if total_reward > curr_balance {

actors/reward/src/state.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ impl Reward {
174174
if elapsed >= vest_duration {
175175
self.value.clone()
176176
} else {
177-
(self.value.clone() * elapsed as u64).div_rem(vest_duration).0
177+
(self.value.clone() * elapsed as u64).div_floor(vest_duration)
178178
}
179179
}
180180
}

0 commit comments

Comments
 (0)