Skip to content

Commit 34dc970

Browse files
authored
chore: use log macro (#15)
1 parent 8b499be commit 34dc970

File tree

6 files changed

+11
-24
lines changed

6 files changed

+11
-24
lines changed

conversion_proxy/src/lib.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use near_sdk::json_types::{ValidAccountId, U128, U64};
33
use near_sdk::serde::{Deserialize, Serialize};
44
use near_sdk::serde_json::json;
55
use near_sdk::{
6-
env, near_bindgen, serde_json, AccountId, Balance, Gas, Promise, PromiseResult, Timestamp,
6+
env, near_bindgen, serde_json, AccountId, Balance, Gas, Promise, PromiseResult, Timestamp, log,
77
};
88

99
near_sdk::setup_alloc!();
@@ -216,12 +216,9 @@ impl ConversionProxy {
216216
);
217217
true
218218
} else {
219-
env::log(
220-
format!(
221-
"Failed to transfer to account {}. Returning attached deposit of {} to {}",
222-
payment_address, deposit.0, predecessor_account_id
223-
)
224-
.as_bytes(),
219+
log!(
220+
"Failed to transfer to account {}. Returning attached deposit of {} to {}",
221+
payment_address, deposit.0, predecessor_account_id
225222
);
226223
Promise::new(predecessor_account_id).transfer(deposit.into());
227224
false

fungible_conversion_proxy/src/lib.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use near_sdk::json_types::{Base64VecU8, ValidAccountId, U128, U64};
33
use near_sdk::serde::{Deserialize, Serialize};
44
use near_sdk::serde_json::json;
55
use near_sdk::{
6-
env, near_bindgen, serde_json, AccountId, Balance, Gas, Promise, PromiseResult, Timestamp,
6+
env, near_bindgen, serde_json, AccountId, Balance, Gas, Promise, PromiseResult, Timestamp, log,
77
};
88
near_sdk::setup_alloc!();
99

@@ -291,11 +291,9 @@ impl FungibleConversionProxy {
291291
);
292292
change.0.to_string() // return change for `ft_resolve_transfer` on the token contract
293293
} else {
294-
env::log(
295-
format!(
294+
log!(
296295
"Failed to transfer to account {}. Returning attached deposit of {} of token {} to {}",
297-
args.to, deposit.0, token_address, payer)
298-
.as_bytes(),
296+
args.to, deposit.0, token_address, payer
299297
);
300298
deposit.0.to_string() // return full amount for `ft_resolve_transfer` on the token contract
301299
}

fungible_proxy/src/lib.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use near_sdk::borsh::{self, BorshDeserialize, BorshSerialize};
22
use near_sdk::json_types::{ValidAccountId, U128};
3+
use near_sdk::log;
34
use near_sdk::serde::{Deserialize, Serialize};
45
use near_sdk::serde_json::json;
56
use near_sdk::{
@@ -180,12 +181,7 @@ impl FungibleProxy {
180181
} else {
181182
// return full amount for `ft_resolve_transfer` on the token contract
182183
let change = (amount.0 + args.fee_amount.0).to_string();
183-
env::log(
184-
format!(
185-
"Failed to transfer to account {}. Returning attached amount of {} of token {} to {}",
186-
args.to, change, token_address, payer)
187-
.as_bytes(),
188-
);
184+
log!("Failed to transfer to account {}. Returning attached amount of {} of token {} to {}", args.to, change, token_address, payer);
189185
change
190186
}
191187
}

mocks/src/fpo_oracle_mock.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ pub struct FPOContract {}
2929
impl FPOContract {
3030
#[allow(unused_variables)]
3131
pub fn get_entry(&self, pair: String, provider: AccountId) -> Option<PriceEntry> {
32-
env::log(format!("get_entry OK").as_bytes());
3332
match &*pair {
3433
"NEAR/USD" => Some(PriceEntry {
3534
// 1 NEAR = 1.234 USD, 10 nanoseconds ago

mocks/src/fungible_token_mock.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,9 @@ impl FungibleTokenContract {
6666
U128::from(old_sender_balance.0 - amt),
6767
);
6868
self.set_balance(receiver_id, U128::from(old_receiver_balance.0 + amt));
69-
70-
env::log(format!("ft_transfer OK").as_bytes());
7169
}
7270

7371
pub fn ft_metadata(&self) -> Option<FungibleTokenMetadata> {
74-
env::log(format!("ft_metadata OK").as_bytes());
7572
Some(FungibleTokenMetadata {
7673
spec: "ft-1.0.0".into(),
7774
name: "USD Coin".into(),

tests/sim/fungible_proxy.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ fn test_transfer_receiver_send_failed() {
219219
);
220220
result.assert_success();
221221
assert_eq!(result.logs().len(), 1, "Wrong number of logs");
222-
assert_eq!(result.logs()[0], format!("Failed to transfer to account bob. Returning attached amount of 500000000 of token mockedft to alice"));
222+
assert_eq!(result.logs()[0], "Failed to transfer to account bob. Returning attached amount of 500000000 of token mockedft to alice");
223223

224224
// The mocked fungible token does not handle change
225225
let change = result.unwrap_json::<String>().parse::<u128>().unwrap();
@@ -259,7 +259,7 @@ fn test_transfer_fee_receiver_send_failed() {
259259
);
260260
result.assert_success();
261261
assert_eq!(result.logs().len(), 1, "Wrong number of logs");
262-
assert_eq!(result.logs()[0], format!("Failed to transfer to account bob. Returning attached amount of 500000000 of token mockedft to alice"));
262+
assert_eq!(result.logs()[0], "Failed to transfer to account bob. Returning attached amount of 500000000 of token mockedft to alice");
263263

264264
// The mocked fungible token does not handle change
265265
let change = result.unwrap_json::<String>().parse::<u128>().unwrap();

0 commit comments

Comments
 (0)