Skip to content

Commit

Permalink
Use idiomatic math operations (#591)
Browse files Browse the repository at this point in the history
  • Loading branch information
Stebalien authored Sep 1, 2022
1 parent b7ad2c5 commit bacf044
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion actors/miner/tests/prove_commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ fn invalid_proof_rejected() {
//require.NoError(t, err)
//assert.Equal(t, []uint64{uint64(sectorNo)}, newSectors)
// Verify pledge lock-up
assert!(st.initial_pledge > TokenAmount::zero());
assert!(st.initial_pledge.is_positive());
rt.reset();

// Duplicate proof (sector no-longer pre-committed)
Expand Down
16 changes: 8 additions & 8 deletions actors/miner/tests/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ impl ActorHarness {

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

let state = self.get_state(rt);
if state.fee_debt > TokenAmount::zero() {
if state.fee_debt.is_positive() {
rt.expect_send(
*BURNT_FUNDS_ACTOR_ADDR,
METHOD_SEND,
Expand Down Expand Up @@ -939,7 +939,7 @@ impl ActorHarness {
}
}

if expected_pledge != TokenAmount::zero() {
if !expected_pledge.is_zero() {
rt.expect_send(
*STORAGE_POWER_ACTOR_ADDR,
PowerMethod::UpdatePledgeTotal as u64,
Expand Down Expand Up @@ -1029,7 +1029,7 @@ impl ActorHarness {
penalty_total += cfg.repaid_fee_debt.clone();
penalty_total += cfg.expired_precommit_penalty.clone();

if penalty_total != TokenAmount::zero() {
if !penalty_total.is_zero() {
rt.expect_send(
*BURNT_FUNDS_ACTOR_ADDR,
METHOD_SEND,
Expand All @@ -1053,7 +1053,7 @@ impl ActorHarness {
pledge_delta += cfg.expired_sectors_pledge_delta;
pledge_delta -= immediately_vesting_funds(rt, &state);

if pledge_delta != TokenAmount::zero() {
if !pledge_delta.is_zero() {
rt.expect_send(
*STORAGE_POWER_ACTOR_ADDR,
PowerMethod::UpdatePledgeTotal as u64,
Expand Down Expand Up @@ -1407,7 +1407,7 @@ impl ActorHarness {
ExitCode::OK,
);

if penalty > TokenAmount::zero() {
if penalty.is_positive() {
rt.expect_send(
*BURNT_FUNDS_ACTOR_ADDR,
METHOD_SEND,
Expand Down Expand Up @@ -1587,7 +1587,7 @@ impl ActorHarness {
rt.set_caller(*ACCOUNT_ACTOR_CODE_ID, self.worker);
rt.expect_validate_caller_addr(self.caller_addrs());

if expected_debt_repaid > TokenAmount::zero() {
if expected_debt_repaid.is_positive() {
rt.expect_send(
*BURNT_FUNDS_ACTOR_ADDR,
METHOD_SEND,
Expand Down Expand Up @@ -1924,7 +1924,7 @@ impl ActorHarness {
}

let total_repaid = expected_repaid_from_vest + expected_repaid_from_balance;
if total_repaid > TokenAmount::zero() {
if total_repaid.is_positive() {
rt.expect_send(
*BURNT_FUNDS_ACTOR_ADDR,
METHOD_SEND,
Expand Down
2 changes: 1 addition & 1 deletion actors/reward/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ impl Actor {

let total_reward = rt.transaction(|st: &mut State, rt| {
let mut block_reward: TokenAmount =
(&st.this_epoch_reward * params.win_count).div_rem(EXPECTED_LEADERS_PER_EPOCH).0;
(&st.this_epoch_reward * params.win_count).div_floor(EXPECTED_LEADERS_PER_EPOCH);
let mut total_reward = &params.gas_reward + &block_reward;
let curr_balance = rt.current_balance();
if total_reward > curr_balance {
Expand Down
2 changes: 1 addition & 1 deletion actors/reward/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ impl Reward {
if elapsed >= vest_duration {
self.value.clone()
} else {
(self.value.clone() * elapsed as u64).div_rem(vest_duration).0
(self.value.clone() * elapsed as u64).div_floor(vest_duration)
}
}
}
Expand Down

0 comments on commit bacf044

Please sign in to comment.