Skip to content

Commit

Permalink
Clippy: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
arajasek committed Dec 7, 2022
1 parent f32061b commit 906b9ee
Show file tree
Hide file tree
Showing 12 changed files with 36 additions and 42 deletions.
1 change: 0 additions & 1 deletion actors/datacap/src/types.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use fvm_ipld_encoding::tuple::*;
use fvm_ipld_encoding::Cbor;
use fvm_shared::address::Address;
use fvm_shared::econ::TokenAmount;

Expand Down
48 changes: 24 additions & 24 deletions actors/datacap/tests/datacap_actor_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,17 @@ mod mint {
let (mut rt, h) = make_harness();

let amt = TokenAmount::from_whole(1);
let ret = h.mint(&mut rt, &*ALICE, &amt, vec![]).unwrap();
let ret = h.mint(&mut rt, &ALICE, &amt, vec![]).unwrap();
assert_eq!(amt, ret.supply);
assert_eq!(amt, ret.balance);
assert_eq!(amt, h.get_supply(&rt));
assert_eq!(amt, h.get_balance(&rt, &*ALICE));
assert_eq!(amt, h.get_balance(&rt, &ALICE));

let ret = h.mint(&mut rt, &*BOB, &amt, vec![]).unwrap();
let ret = h.mint(&mut rt, &BOB, &amt, vec![]).unwrap();
assert_eq!(&amt * 2, ret.supply);
assert_eq!(amt, ret.balance);
assert_eq!(&amt * 2, h.get_supply(&rt));
assert_eq!(amt, h.get_balance(&rt, &*BOB));
assert_eq!(amt, h.get_balance(&rt, &BOB));

h.check_state(&rt);
}
Expand Down Expand Up @@ -88,7 +88,7 @@ mod mint {
expect_abort_contains_message(
ExitCode::USR_ILLEGAL_ARGUMENT,
"must be a multiple of 1000000000000000000",
h.mint(&mut rt, &*ALICE, &amt, vec![]),
h.mint(&mut rt, &ALICE, &amt, vec![]),
);
rt.reset();
h.check_state(&rt);
Expand All @@ -98,25 +98,25 @@ mod mint {
fn auto_allowance_on_mint() {
let (mut rt, h) = make_harness();
let amt = TokenAmount::from_whole(42);
h.mint(&mut rt, &*ALICE, &amt, vec![*BOB]).unwrap();
let allowance = h.get_allowance_between(&rt, &*ALICE, &*BOB);
h.mint(&mut rt, &ALICE, &amt, vec![*BOB]).unwrap();
let allowance = h.get_allowance_between(&rt, &ALICE, &BOB);
assert!(allowance.eq(&INFINITE_ALLOWANCE));

// mint again
h.mint(&mut rt, &*ALICE, &amt, vec![*BOB]).unwrap();
let allowance2 = h.get_allowance_between(&rt, &*ALICE, &*BOB);
h.mint(&mut rt, &ALICE, &amt, vec![*BOB]).unwrap();
let allowance2 = h.get_allowance_between(&rt, &ALICE, &BOB);
assert!(allowance2.eq(&INFINITE_ALLOWANCE));

// transfer of an allowance *does* deduct allowance even though it is too small to matter in practice
let operator_data = RawBytes::new(vec![1, 2, 3, 4]);
h.transfer_from(&mut rt, &*BOB, &*ALICE, &h.governor, &(2 * amt.clone()), operator_data)
h.transfer_from(&mut rt, &BOB, &ALICE, &h.governor, &(2 * amt.clone()), operator_data)
.unwrap();
let allowance3 = h.get_allowance_between(&rt, &*ALICE, &*BOB);
let allowance3 = h.get_allowance_between(&rt, &ALICE, &BOB);
assert!(allowance3.eq(&INFINITE_ALLOWANCE.clone().sub(2 * amt.clone())));

// minting any amount to this address at the same operator resets at infinite
h.mint(&mut rt, &*ALICE, &TokenAmount::from_whole(1), vec![*BOB]).unwrap();
let allowance = h.get_allowance_between(&rt, &*ALICE, &*BOB);
h.mint(&mut rt, &ALICE, &TokenAmount::from_whole(1), vec![*BOB]).unwrap();
let allowance = h.get_allowance_between(&rt, &ALICE, &BOB);
assert!(allowance.eq(&INFINITE_ALLOWANCE));

h.check_state(&rt);
Expand All @@ -138,20 +138,20 @@ mod transfer {
let operator_data = RawBytes::new(vec![1, 2, 3, 4]);

let amt = TokenAmount::from_whole(1);
h.mint(&mut rt, &*ALICE, &amt, vec![]).unwrap();
h.mint(&mut rt, &ALICE, &amt, vec![]).unwrap();

expect_abort_contains_message(
ExitCode::USR_FORBIDDEN,
"transfer not allowed",
h.transfer(&mut rt, &*ALICE, &*BOB, &amt, operator_data.clone()),
h.transfer(&mut rt, &ALICE, &BOB, &amt, operator_data.clone()),
);
rt.reset();

// Transfer to governor is allowed.
h.transfer(&mut rt, &*ALICE, &h.governor, &amt, operator_data.clone()).unwrap();
h.transfer(&mut rt, &ALICE, &h.governor, &amt, operator_data.clone()).unwrap();

// The governor can transfer out.
h.transfer(&mut rt, &h.governor, &*BOB, &amt, operator_data).unwrap();
h.transfer(&mut rt, &h.governor, &BOB, &amt, operator_data).unwrap();
}

#[test]
Expand All @@ -160,21 +160,21 @@ mod transfer {
let operator_data = RawBytes::new(vec![1, 2, 3, 4]);

let amt = TokenAmount::from_whole(1);
h.mint(&mut rt, &*ALICE, &amt, vec![*BOB]).unwrap();
h.mint(&mut rt, &ALICE, &amt, vec![*BOB]).unwrap();

// operator can't transfer out to third address
expect_abort_contains_message(
ExitCode::USR_FORBIDDEN,
"transfer not allowed",
h.transfer_from(&mut rt, &*BOB, &*ALICE, &*CARLA, &amt, operator_data.clone()),
h.transfer_from(&mut rt, &BOB, &ALICE, &CARLA, &amt, operator_data.clone()),
);
rt.reset();

// operator can't transfer out to self
expect_abort_contains_message(
ExitCode::USR_FORBIDDEN,
"transfer not allowed",
h.transfer_from(&mut rt, &*BOB, &*ALICE, &*BOB, &amt, operator_data.clone()),
h.transfer_from(&mut rt, &BOB, &ALICE, &BOB, &amt, operator_data.clone()),
);
rt.reset();
// even if governor has a delegate operator and enough tokens, delegated transfer
Expand All @@ -183,7 +183,7 @@ mod transfer {
expect_abort_contains_message(
ExitCode::USR_FORBIDDEN,
"transfer not allowed",
h.transfer_from(&mut rt, &*BOB, &h.governor, &*ALICE, &amt, operator_data),
h.transfer_from(&mut rt, &BOB, &h.governor, &ALICE, &amt, operator_data),
);
rt.reset();
}
Expand All @@ -206,7 +206,7 @@ mod destroy {
let (mut rt, h) = make_harness();

let amt = TokenAmount::from_whole(1);
h.mint(&mut rt, &*ALICE, &(2 * amt.clone()), vec![*BOB]).unwrap();
h.mint(&mut rt, &ALICE, &(2 * amt.clone()), vec![*BOB]).unwrap();

// destroying from operator does not work
let params = DestroyParams { owner: *ALICE, amount: amt.clone() };
Expand All @@ -223,8 +223,8 @@ mod destroy {
);

// Destroying from 0 allowance having governor works
assert!(h.get_allowance_between(&rt, &*ALICE, &h.governor).is_zero());
let ret = h.destroy(&mut rt, &*ALICE, &amt).unwrap();
assert!(h.get_allowance_between(&rt, &ALICE, &h.governor).is_zero());
let ret = h.destroy(&mut rt, &ALICE, &amt).unwrap();
assert_eq!(ret.balance, amt); // burned 2 amt - amt = amt
h.check_state(&rt)
}
Expand Down
2 changes: 1 addition & 1 deletion actors/init/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use cid::Cid;
use fvm_ipld_encoding::tuple::*;
use fvm_ipld_encoding::{Cbor, RawBytes};
use fvm_ipld_encoding::RawBytes;
use fvm_shared::address::Address;

/// Init actor Constructor parameters
Expand Down
2 changes: 1 addition & 1 deletion actors/miner/tests/aggregate_network_fee_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fn fee_increases_if_basefee_crosses_threshold() {
let at_no_base_fee = fee_func(10, &zero());
let at_balance_minus_one_base_fee =
fee_func(10, &(&*BATCH_BALANCER - TokenAmount::from_atto(1)));
let at_balance_base_fee = fee_func(10, &*BATCH_BALANCER);
let at_balance_base_fee = fee_func(10, &BATCH_BALANCER);
let at_balance_plus_one_base_fee =
fee_func(10, &(&*BATCH_BALANCER + TokenAmount::from_nano(1)));
let at_balance_plus_two_base_fee =
Expand Down
4 changes: 2 additions & 2 deletions actors/miner/tests/repay_debts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ fn pay_debt_partially_from_vested_funds() {
// send 1 FIL and repay all debt from vesting funds and balance
h.repay_debts(
&mut rt,
&*BIG_BALANCE, // send 1 FIL
&BIG_BALANCE, // send 1 FIL
&amount_locked, // 3 FIL comes from vesting funds
&*BIG_BALANCE, // 1 FIL sent from balance
&BIG_BALANCE, // 1 FIL sent from balance
)
.unwrap();

Expand Down
4 changes: 2 additions & 2 deletions actors/miner/tests/withdraw_balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ fn fails_if_miner_cant_repay_fee_debt() {
h.withdraw_funds(
&mut rt,
h.owner,
&*ONE_PERCENT_BALANCE,
&*ONE_PERCENT_BALANCE,
&ONE_PERCENT_BALANCE,
&ONE_PERCENT_BALANCE,
&TokenAmount::zero(),
),
);
Expand Down
2 changes: 1 addition & 1 deletion actors/multisig/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use std::fmt::Display;

use fvm_ipld_encoding::tuple::*;
use fvm_ipld_encoding::{serde_bytes, Cbor, RawBytes};
use fvm_ipld_encoding::{serde_bytes, RawBytes};
use fvm_ipld_hamt::BytesKey;
use fvm_shared::address::Address;

Expand Down
4 changes: 2 additions & 2 deletions actors/power/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,8 @@ impl State {
pub(super) fn update_smoothed_estimate(&mut self, delta: ChainEpoch) {
let filter_qa_power = AlphaBetaFilter::load(
&self.this_epoch_qa_power_smoothed,
&*DEFAULT_ALPHA,
&*DEFAULT_BETA,
&DEFAULT_ALPHA,
&DEFAULT_BETA,
);
self.this_epoch_qa_power_smoothed =
filter_qa_power.next_estimate(&self.this_epoch_quality_adj_power, delta);
Expand Down
2 changes: 1 addition & 1 deletion actors/power/tests/power_actor_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ fn given_no_miner_claim_update_pledge_total_should_abort() {
h.create_miner_basic(&mut rt, *OWNER, *OWNER, *MINER).unwrap();

// explicitly delete miner claim
h.delete_claim(&mut rt, &*MINER);
h.delete_claim(&mut rt, &MINER);

rt.set_caller(*MINER_ACTOR_CODE_ID, *MINER);
rt.expect_validate_caller_type(vec![Type::Miner]);
Expand Down
1 change: 0 additions & 1 deletion actors/verifreg/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
use cid::Cid;
use fil_actors_runtime::BatchReturn;
use fvm_ipld_encoding::tuple::*;
use fvm_ipld_encoding::Cbor;
use fvm_shared::address::Address;
use fvm_shared::bigint::{bigint_ser, BigInt};
use fvm_shared::clock::ChainEpoch;
Expand Down
2 changes: 1 addition & 1 deletion state/src/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ fn check_verifreg_against_datacap(
}
// Verifreg token balance matches unclaimed allocations.
let pending_alloc_total: DataCap =
verifreg_summary.allocations.iter().map(|(_, alloc)| alloc.size.0).sum();
verifreg_summary.allocations.values().map(|alloc| alloc.size.0).sum();
let verifreg_balance = datacap_summary
.balances
.get(&VERIFIED_REGISTRY_ACTOR_ADDR.id().unwrap())
Expand Down
6 changes: 1 addition & 5 deletions test_vm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,11 +372,7 @@ impl<'bs> VM<'bs> {

pub fn get_state<C: Cbor>(&self, addr: Address) -> Option<C> {
let a_opt = self.get_actor(addr);
if a_opt == None {
return None;
};
let a = a_opt.unwrap();
self.store.get_cbor::<C>(&a.head).unwrap()
a_opt.map(|a| self.store.get_cbor::<C>(&a.head).unwrap().unwrap())
}

pub fn mutate_state<C, F>(&self, addr: Address, f: F)
Expand Down

0 comments on commit 906b9ee

Please sign in to comment.