Skip to content

Commit

Permalink
Minor refactoring and test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
yanliu38 committed Jan 2, 2025
1 parent 832d7d3 commit 8637ae8
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 16 deletions.
10 changes: 4 additions & 6 deletions common/src/account_transfers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,12 +257,10 @@ pub fn set_fees_sink_accounts(accounts: Option<Vec<IcrcCompatibleAccount>>) {
}

pub fn fees_sink_accounts() -> Vec<IcrcCompatibleAccount> {
FEES_SINK_ACCOUNTS.with(
|fees_sink_accounts| match fees_sink_accounts.borrow().as_ref() {
Some(accounts) => accounts.clone(),
None => vec![MINTING_ACCOUNT.clone()],
},
)
FEES_SINK_ACCOUNTS.with(|sink_accounts| match sink_accounts.borrow().as_ref() {
Some(accounts) => accounts.clone(),
None => vec![MINTING_ACCOUNT.clone()],
})
}

fn full_account_checksum(owner: &[u8], subaccount: &[u8]) -> String {
Expand Down
4 changes: 2 additions & 2 deletions common/src/contract_sign_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ pub struct ContractSignRequestV1 {
region_name: Option<String>, // Optional region name
contract_id: Option<String>, // Optional contract id, if an existing contract is being extended
instance_config: Option<String>, // Optional configuration for the instance deployment, e.g. cloud-init
payment_amount_e9s: u64, // How much is the requester offering to pay for the contract
payment_amount_e9s: TokenAmountE9s, // How much is the requester offering to pay for the contract
payment_entries: Vec<PaymentEntryWithAmount>,
start_timestamp: Option<u64>, // Optionally, only start contract at this unix time (in seconds) UTC. This can be in the past or in the future. Default is now.
request_memo: String, // Reference to this particular request; arbitrary text. Can be used e.g. for administrative purposes
Expand All @@ -133,7 +133,7 @@ impl ContractSignRequest {
region_name: Option<String>,
contract_id: Option<String>,
instance_config: Option<String>,
payment_amount_e9s: u64,
payment_amount_e9s: TokenAmountE9s,
payment_entries: Vec<PaymentEntryWithAmount>,
start_timestamp: Option<u64>,
request_memo: String,
Expand Down
8 changes: 4 additions & 4 deletions common/src/rewards/tests_rewards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ fn test_rewards_distribute_no_eligible_nps() {
let response: serde_json::Value = serde_json::from_str(&result.unwrap()).unwrap();
assert_eq!(
response[0].as_str().unwrap(),
"Distributing reward of 50.0 tokens: no eligible NPs"
"Distributing reward of 50.000000000 tokens: no eligible NPs"
);
}

Expand Down Expand Up @@ -214,7 +214,7 @@ fn test_rewards_distribute_with_eligible_nps() {
let result: Value = serde_json::from_str(&result).unwrap();
assert_eq!(
result[0],
"Distributing reward of 50.0 tokens to 1 NPs = 50.0 tokens per NP"
"Distributing reward of 50.000000000 tokens to 1 NPs = 50.000000000 tokens per NP"
);

// Fast forward 42 blocks, there are rewards for 42 blocks that should be distributed
Expand All @@ -233,7 +233,7 @@ fn test_rewards_distribute_with_eligible_nps() {
// 50 tokens * 42 = 2100
assert_eq!(
result[0],
"Distributing reward of 2100.0 tokens to 1 NPs = 2100.0 tokens per NP"
"Distributing reward of 2100.000000000 tokens to 1 NPs = 2100.000000000 tokens per NP"
);

// Later on, both np1 and np2 should be eligible for rewards. Each should get 25 tokens
Expand Down Expand Up @@ -267,6 +267,6 @@ fn test_rewards_distribute_with_eligible_nps() {
// 50 tokens * 7 = 350
assert_eq!(
result[0],
"Distributing reward of 350.0 tokens to 2 NPs = 175.0 tokens per NP"
"Distributing reward of 350.000000000 tokens to 2 NPs = 175.000000000 tokens per NP"
);
}
8 changes: 4 additions & 4 deletions ic-canister/src/canister_backend/icrc1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,14 @@ pub fn _icrc1_transfer(arg: TransferArg) -> Result<Nat, Icrc1TransferError> {
arg.from_subaccount.map(|subaccount| subaccount.to_vec()),
);

let balance_from_after = account_balance_get(&from);
let balance_from = account_balance_get(&from);
let amount = nat_to_balance(&arg.amount);
if balance_from_after < amount {
if balance_from < amount {
return Err(Icrc1TransferError::InsufficientFunds {
balance: balance_from_after.into(),
balance: balance_from.into(),
});
}
let balance_from_after: TokenAmountE9s = balance_from_after - amount;
let balance_from_after = balance_from - amount;
let to: IcrcCompatibleAccount = arg.to.into();

LEDGER_MAP.with(|ledger| {
Expand Down

0 comments on commit 8637ae8

Please sign in to comment.