Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(env): Update method name parameters in env to string equivalents #515

Merged
merged 7 commits into from
Aug 5, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion HELP.md
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ mod ext_calculator {
Promise::new(receiver_id.clone())
.function_call(
b"mult",
json!({ "a": a, "b": b }).to_string().as_bytes(),
json!({ "a": a, "b": b }).to_string(),
austinabell marked this conversation as resolved.
Show resolved Hide resolved
deposit,
gas,
)
Expand Down
Binary file not shown.
Binary file modified examples/fungible-token/res/defi.wasm
Binary file not shown.
Binary file modified examples/fungible-token/res/fungible_token.wasm
Binary file not shown.
19 changes: 5 additions & 14 deletions examples/fungible-token/tests/sim/with_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,8 @@ fn simulate_simple_transfer() {

// Transfer from root to alice.
// Uses default gas amount, `near_sdk_sim::DEFAULT_GAS`
call!(
root,
ft.ft_transfer(alice.account_id(), transfer_amount.into(), None),
deposit = 1
)
.assert_success();
call!(root, ft.ft_transfer(alice.account_id(), transfer_amount.into(), None), deposit = 1)
.assert_success();

let root_balance: U128 = view!(ft.ft_balance_of(root.account_id())).unwrap_json();
let alice_balance: U128 = view!(ft.ft_balance_of(alice.account_id())).unwrap_json();
Expand Down Expand Up @@ -100,8 +96,7 @@ fn simulate_transfer_call_with_burned_amount() {
"amount": transfer_amount.to_string(),
"msg": "10",
})
.to_string()
.into_bytes(),
.to_string(),
DEFAULT_GAS / 2,
1,
)
Expand All @@ -110,8 +105,7 @@ fn simulate_transfer_call_with_burned_amount() {
json!({
"force": true
})
.to_string()
.into_bytes(),
.to_string(),
DEFAULT_GAS / 2,
1,
)
Expand All @@ -128,10 +122,7 @@ fn simulate_transfer_call_with_burned_amount() {
let callback_outcome = outcome.get_receipt_results().remove(1).unwrap();

assert_eq!(callback_outcome.logs()[0], "The account of the sender was deleted");
assert_eq!(
callback_outcome.logs()[1],
format!("Account @{} burned {}", root.account_id(), 10)
);
assert_eq!(callback_outcome.logs()[1], format!("Account @{} burned {}", root.account_id(), 10));

let used_amount: U128 = callback_outcome.unwrap_json();
// Sender deleted the account. Even though the returned amount was 10, it was not refunded back
Expand Down
Binary file modified examples/non-fungible-token/res/approval_receiver.wasm
Binary file not shown.
Binary file modified examples/non-fungible-token/res/non_fungible_token.wasm
Binary file not shown.
Binary file modified examples/non-fungible-token/res/token_receiver.wasm
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ mod tests {
let args = near_sdk::serde_json::to_vec(&args)
.expect("Failed to serialize the cross contract args using JSON.");
near_sdk::Promise::new(AccountId::new_unchecked(__account_id.to_string())).function_call(
b"merge_sort".to_vec(),
"merge_sort".to_string(),
args,
__balance,
__gas,
Expand All @@ -79,7 +79,7 @@ mod tests {
pub fn merge<T: ToString>(__account_id: &T, __balance: near_sdk::Balance, __gas: near_sdk::Gas) -> near_sdk::Promise {
let args = vec![];
near_sdk::Promise::new(AccountId::new_unchecked(__account_id.to_string())).function_call(
b"merge".to_vec(),
"merge".to_string(),
args,
__balance,
__gas,
Expand Down Expand Up @@ -122,7 +122,7 @@ mod tests {
let args = near_sdk::borsh::BorshSerialize::try_to_vec(&args)
.expect("Failed to serialize the cross contract args using Borsh.");
near_sdk::Promise::new(AccountId::new_unchecked(__account_id.to_string())).function_call(
b"test".to_vec(),
"test".to_string(),
args,
__balance,
__gas,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl TraitItemMethodInfo {
#serialize
near_sdk::Promise::new(AccountId::new_unchecked(__account_id.to_string()))
.function_call(
#ident_byte_str.to_vec(),
#ident_byte_str.to_string(),
args,
__balance,
__gas,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
use super::AttrSigInfo;
use syn::export::Span;
use syn::spanned::Spanned;
use syn::{Error, LitByteStr, TraitItemMethod};
use syn::{Error, LitStr, TraitItemMethod};

/// Information extracted from trait method.
pub struct TraitItemMethodInfo {
/// Attributes and signature information.
pub attr_sig_info: AttrSigInfo,
/// The original AST of the trait item method.
pub original: TraitItemMethod,
/// Byte representation of method name, e.g. `b"my_method"`.
pub ident_byte_str: LitByteStr,
/// String representation of method name, e.g. `"my_method"`.
pub ident_byte_str: LitStr,
}

impl TraitItemMethodInfo {
Expand All @@ -28,8 +28,7 @@ impl TraitItemMethodInfo {

let attr_sig_info = AttrSigInfo::new(attrs, sig)?;

let ident_byte_str =
LitByteStr::new(attr_sig_info.ident.to_string().as_bytes(), Span::call_site());
let ident_byte_str = LitStr::new(&attr_sig_info.ident.to_string(), Span::call_site());

Ok(Self { attr_sig_info, original: original.clone(), ident_byte_str })
}
Expand Down
4 changes: 2 additions & 2 deletions near-sdk/src/environment/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ pub fn promise_batch_action_deploy_contract(promise_index: u64, code: &[u8]) {

pub fn promise_batch_action_function_call(
promise_index: PromiseIndex,
method_name: &[u8],
method_name: &str,
arguments: &[u8],
amount: Balance,
gas: Gas,
Expand Down Expand Up @@ -384,7 +384,7 @@ pub fn promise_batch_action_add_key_with_function_call(
nonce: u64,
allowance: Balance,
receiver_id: &AccountId,
method_names: &[u8],
method_names: &str,
) {
let receiver_id: &str = receiver_id.as_ref();
unsafe {
Expand Down
12 changes: 6 additions & 6 deletions near-sdk/src/promise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub enum PromiseAction {
code: Vec<u8>,
},
FunctionCall {
method_name: Vec<u8>,
method_name: String,
arguments: Vec<u8>,
amount: Balance,
gas: Gas,
Expand All @@ -32,7 +32,7 @@ pub enum PromiseAction {
public_key: PublicKey,
allowance: Balance,
receiver_id: AccountId,
method_names: Vec<u8>,
method_names: String,
nonce: u64,
},
DeleteKey {
Expand Down Expand Up @@ -242,7 +242,7 @@ impl Promise {
/// A low-level interface for making a function call to the account that this promise acts on.
pub fn function_call(
self,
method_name: Vec<u8>,
method_name: String,
arguments: Vec<u8>,
amount: Balance,
gas: Gas,
Expand Down Expand Up @@ -272,13 +272,13 @@ impl Promise {

/// Add an access key that is restricted to only calling a smart contract on some account using
/// only a restricted set of methods. Here `method_names` is a comma separated list of methods,
/// e.g. `b"method_a,method_b"`.
/// e.g. `"method_a,method_b".to_string()`.
pub fn add_access_key(
self,
public_key: PublicKey,
allowance: Balance,
receiver_id: AccountId,
method_names: Vec<u8>,
method_names: String,
) -> Self {
self.add_access_key_with_nonce(public_key, allowance, receiver_id, method_names, 0)
}
Expand All @@ -289,7 +289,7 @@ impl Promise {
public_key: PublicKey,
allowance: Balance,
receiver_id: AccountId,
method_names: Vec<u8>,
method_names: String,
nonce: u64,
) -> Self {
self.add_action(PromiseAction::AddAccessKey {
Expand Down