Skip to content

Commit 8637ae8

Browse files
committed
Minor refactoring and test fixes
1 parent 832d7d3 commit 8637ae8

File tree

4 files changed

+14
-16
lines changed

4 files changed

+14
-16
lines changed

common/src/account_transfers.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -257,12 +257,10 @@ pub fn set_fees_sink_accounts(accounts: Option<Vec<IcrcCompatibleAccount>>) {
257257
}
258258

259259
pub fn fees_sink_accounts() -> Vec<IcrcCompatibleAccount> {
260-
FEES_SINK_ACCOUNTS.with(
261-
|fees_sink_accounts| match fees_sink_accounts.borrow().as_ref() {
262-
Some(accounts) => accounts.clone(),
263-
None => vec![MINTING_ACCOUNT.clone()],
264-
},
265-
)
260+
FEES_SINK_ACCOUNTS.with(|sink_accounts| match sink_accounts.borrow().as_ref() {
261+
Some(accounts) => accounts.clone(),
262+
None => vec![MINTING_ACCOUNT.clone()],
263+
})
266264
}
267265

268266
fn full_account_checksum(owner: &[u8], subaccount: &[u8]) -> String {

common/src/contract_sign_request.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ pub struct ContractSignRequestV1 {
116116
region_name: Option<String>, // Optional region name
117117
contract_id: Option<String>, // Optional contract id, if an existing contract is being extended
118118
instance_config: Option<String>, // Optional configuration for the instance deployment, e.g. cloud-init
119-
payment_amount_e9s: u64, // How much is the requester offering to pay for the contract
119+
payment_amount_e9s: TokenAmountE9s, // How much is the requester offering to pay for the contract
120120
payment_entries: Vec<PaymentEntryWithAmount>,
121121
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.
122122
request_memo: String, // Reference to this particular request; arbitrary text. Can be used e.g. for administrative purposes
@@ -133,7 +133,7 @@ impl ContractSignRequest {
133133
region_name: Option<String>,
134134
contract_id: Option<String>,
135135
instance_config: Option<String>,
136-
payment_amount_e9s: u64,
136+
payment_amount_e9s: TokenAmountE9s,
137137
payment_entries: Vec<PaymentEntryWithAmount>,
138138
start_timestamp: Option<u64>,
139139
request_memo: String,

common/src/rewards/tests_rewards.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ fn test_rewards_distribute_no_eligible_nps() {
175175
let response: serde_json::Value = serde_json::from_str(&result.unwrap()).unwrap();
176176
assert_eq!(
177177
response[0].as_str().unwrap(),
178-
"Distributing reward of 50.0 tokens: no eligible NPs"
178+
"Distributing reward of 50.000000000 tokens: no eligible NPs"
179179
);
180180
}
181181

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

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

239239
// Later on, both np1 and np2 should be eligible for rewards. Each should get 25 tokens
@@ -267,6 +267,6 @@ fn test_rewards_distribute_with_eligible_nps() {
267267
// 50 tokens * 7 = 350
268268
assert_eq!(
269269
result[0],
270-
"Distributing reward of 350.0 tokens to 2 NPs = 175.0 tokens per NP"
270+
"Distributing reward of 350.000000000 tokens to 2 NPs = 175.000000000 tokens per NP"
271271
);
272272
}

ic-canister/src/canister_backend/icrc1.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,14 @@ pub fn _icrc1_transfer(arg: TransferArg) -> Result<Nat, Icrc1TransferError> {
9292
arg.from_subaccount.map(|subaccount| subaccount.to_vec()),
9393
);
9494

95-
let balance_from_after = account_balance_get(&from);
95+
let balance_from = account_balance_get(&from);
9696
let amount = nat_to_balance(&arg.amount);
97-
if balance_from_after < amount {
97+
if balance_from < amount {
9898
return Err(Icrc1TransferError::InsufficientFunds {
99-
balance: balance_from_after.into(),
99+
balance: balance_from.into(),
100100
});
101101
}
102-
let balance_from_after: TokenAmountE9s = balance_from_after - amount;
102+
let balance_from_after = balance_from - amount;
103103
let to: IcrcCompatibleAccount = arg.to.into();
104104

105105
LEDGER_MAP.with(|ledger| {

0 commit comments

Comments
 (0)