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

chore: remove near-sdk-sim from repo #817

Merged
merged 3 commits into from
May 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## [Unreleased]

- Deprecate and remove `near-sdk-sim`. Removes `sim` proxy struct from `#[near_bindgen]`. [PR 817](https://github.com/near/near-sdk-rs/pull/817)
- If `near-sdk-sim` tests can't be migrated to [workspaces-rs](https://github.com/near/workspaces-rs), `4.0.0-pre.9` version of `near-sdk-rs` and `near-sdk-sim` should be used

## [4.0.0-pre.9] - 2022-05-12

### Fixes
Expand Down
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
members = [
"near-sdk",
"near-sdk-macros",
"near-sdk-sim",
"near-contract-standards",
"sys",
]
Expand Down
3 changes: 1 addition & 2 deletions examples/fungible-token/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
Fungible Token (FT)
===================

Example implementation of a [Fungible Token] contract which uses [near-contract-standards] and [simulation] tests.
Example implementation of a [Fungible Token] contract which uses [near-contract-standards].

[Fungible Token]: https://nomicon.io/Standards/Tokens/FungibleTokenCore.html
[near-contract-standards]: https://github.com/near/near-sdk-rs/tree/master/near-contract-standards
[simulation]: https://github.com/near/near-sdk-rs/tree/master/near-sdk-sim

NOTES:
- The maximum balance value is limited by U128 (2**128 - 1).
Expand Down
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.
3 changes: 1 addition & 2 deletions examples/non-fungible-token/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
Non-fungible Token (NFT)
===================

Example implementation of a [non-fungible token] contract which uses [near-contract-standards] and [simulation] tests.
Example implementation of a [non-fungible token] contract which uses [near-contract-standards].

[non-fungible token]: https://nomicon.io/Standards/NonFungibleToken/README.html
[near-contract-standards]: https://github.com/near/near-sdk-rs/tree/master/near-contract-standards
[simulation]: https://github.com/near/near-sdk-rs/tree/master/near-sdk-sim

NOTES:
- The maximum balance value is limited by U128 (2**128 - 1).
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
@@ -1,5 +1,5 @@
/*!
A stub contract that implements nft_on_approve for simulation testing nft_approve.
A stub contract that implements nft_on_approve for e2e testing nft_approve.
*/
use near_contract_standards::non_fungible_token::approval::NonFungibleTokenApprovalReceiver;
use near_contract_standards::non_fungible_token::TokenId;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use crate::core_impl::utils;
use crate::core_impl::{
info_extractor::{AttrSigInfo, ImplItemMethodInfo, MethodType, SerializerType},
serializer,
use crate::core_impl::info_extractor::{
AttrSigInfo, ImplItemMethodInfo, MethodType, SerializerType,
};
use crate::core_impl::utils;
use proc_macro2::TokenStream as TokenStream2;
use quote::quote;
use syn::spanned::Spanned;
use syn::{ReturnType, Signature};
use syn::ReturnType;

impl ImplItemMethodInfo {
/// Generate wrapper method for the given method of the contract.
Expand Down Expand Up @@ -206,55 +205,6 @@ impl ImplItemMethodInfo {
}
}
}

pub(crate) fn generate_sim_method_wrapper(&self) -> TokenStream2 {
let ImplItemMethodInfo { attr_signature_info, .. } = self;

let serialize = serializer::generate_serializer(
attr_signature_info,
&attr_signature_info.input_serializer,
);

let pat_type_list = attr_signature_info.pat_type_list();

let AttrSigInfo {
non_bindgen_attrs,
ident,
// receiver,
// returns,
// result_serializer,
// is_init,
method_type,
original_sig,
..
} = attr_signature_info;
let return_ident = quote! { -> near_sdk::PendingContractTx };
let params = quote! {
&self, #pat_type_list
};
let ident_str = ident.to_string();
let is_view = if matches!(method_type, MethodType::View) {
quote! {true}
} else {
quote! {false}
};

let non_bindgen_attrs = non_bindgen_attrs.iter().fold(TokenStream2::new(), |acc, value| {
quote! {
#acc
#value
}
});
let Signature { generics, .. } = original_sig;
quote! {
#[cfg(not(target_arch = "wasm32"))]
#non_bindgen_attrs
pub fn #ident#generics(#params) #return_ident {
let __args = #serialize;
near_sdk::PendingContractTx::new_from_bytes(self.account_id.clone(), #ident_str, __args, #is_view)
}
}
}
}

fn init_method_wrapper(
Expand Down
72 changes: 0 additions & 72 deletions near-sdk-macros/src/core_impl/code_generator/item_impl_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,6 @@ impl ItemImplInfo {
res
}

pub fn generate_sim_method_wrapper(&self) -> TokenStream2 {
use quote::{format_ident, quote};
let orig_name = self.ty.clone().into_token_stream();
let mut name = quote! {Contract};
if let Ok(input) = syn::parse::<Ident>(orig_name.into()) {
let new_name = format_ident!("{}Contract", input);
name = quote! {#new_name};
};
let mut res = TokenStream2::new();
for method in &self.methods {
if method.is_public || self.is_trait_impl {
res.extend(method.generate_sim_method_wrapper());
}
}
quote! {
#[cfg(not(target_arch = "wasm32"))]
impl #name {
#res
}
}
}

pub fn generate_ext_wrapper_code(&self) -> TokenStream2 {
match syn::parse::<Ident>(self.ty.to_token_stream().into()) {
Ok(n) => generate_ext_function_wrappers(
Expand Down Expand Up @@ -725,56 +703,6 @@ mod tests {
assert_eq!(expected.to_string(), actual.to_string());
}

#[test]
fn marshall_one_arg() {
let impl_type: Type = syn::parse_str("Hello").unwrap();
let mut method: ImplItemMethod = syn::parse_str("pub fn method(&self, k: String) { }").unwrap();
let method_info = ImplItemMethodInfo::new(&mut method, impl_type).unwrap();
let actual = method_info.generate_sim_method_wrapper();
let expected = quote!(
#[cfg(not(target_arch = "wasm32"))]
pub fn method(&self, k: String,) -> near_sdk::PendingContractTx {
let __args = {#[derive(near_sdk :: serde :: Serialize)]
#[serde(crate = "near_sdk::serde")]
struct Input<'nearinput> {
k: &'nearinput String,
}
let __args = Input { k: &k, };
near_sdk::serde_json::to_vec(&__args)
.expect("Failed to serialize the cross contract args using JSON.")
};
near_sdk::PendingContractTx::new_from_bytes(self.account_id.clone(), "method", __args, true)
}
);
assert_eq!(expected.to_string(), actual.to_string());
}

#[test]
fn marshall_borsh() {
let impl_type: Type = syn::parse_str("Hello").unwrap();
let mut method: ImplItemMethod = syn::parse_str(r#"
pub fn borsh_test(&mut self, #[serializer(borsh)] a: String) {}
"#).unwrap();
let method_info = ImplItemMethodInfo::new(&mut method, impl_type).unwrap();
let actual = method_info.generate_sim_method_wrapper();
let expected = quote!(
#[cfg(not(target_arch = "wasm32"))]
pub fn borsh_test(&self, a: String,) -> near_sdk::PendingContractTx {
let __args = {
#[derive(near_sdk :: borsh :: BorshSerialize)]
struct Input<'nearinput> {
a: &'nearinput String,
}
let __args = Input { a: &a, };
near_sdk::borsh::BorshSerialize::try_to_vec(&__args)
.expect("Failed to serialize the cross contract args using Borsh.")
};
near_sdk::PendingContractTx::new_from_bytes(self.account_id.clone(), "borsh_test", __args, false)
}
);
assert_eq!(expected.to_string(), actual.to_string());
}

#[test]
fn handle_result_json() {
let impl_type: Type = syn::parse_str("Hello").unwrap();
Expand Down
3 changes: 0 additions & 3 deletions near-sdk-macros/src/core_impl/code_generator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ pub use item_trait_info::*;
mod item_impl_info;
pub use item_impl_info::*;

mod sim_proxy;
pub use sim_proxy::generate_sim_proxy_struct;

pub(crate) mod ext;

pub(crate) mod serializer;
12 changes: 0 additions & 12 deletions near-sdk-macros/src/core_impl/code_generator/sim_proxy.rs

This file was deleted.

7 changes: 0 additions & 7 deletions near-sdk-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,16 @@ use syn::{File, ItemEnum, ItemImpl, ItemStruct, ItemTrait};
#[proc_macro_attribute]
pub fn near_bindgen(_attr: TokenStream, item: TokenStream) -> TokenStream {
if let Ok(input) = syn::parse::<ItemStruct>(item.clone()) {
let struct_proxy = generate_sim_proxy_struct(&input.ident);
let ext_gen = generate_ext_structs(&input.ident, Some(&input.generics));
TokenStream::from(quote! {
#input
#ext_gen
#struct_proxy
})
} else if let Ok(input) = syn::parse::<ItemEnum>(item.clone()) {
let enum_proxy = generate_sim_proxy_struct(&input.ident);
let ext_gen = generate_ext_structs(&input.ident, Some(&input.generics));
TokenStream::from(quote! {
#input
#ext_gen
#enum_proxy
})
} else if let Ok(mut input) = syn::parse::<ItemImpl>(item) {
let item_impl_info = match ItemImplInfo::new(&mut input) {
Expand All @@ -69,13 +65,10 @@ pub fn near_bindgen(_attr: TokenStream, item: TokenStream) -> TokenStream {
}
};
let generated_code = item_impl_info.wrapper_code();
// Add helper type for simulation testing only if not wasm32
let marshalled_code = item_impl_info.generate_sim_method_wrapper();

// Add wrapper methods for ext call API
let ext_generated_code = item_impl_info.generate_ext_wrapper_code();
TokenStream::from(quote! {
#marshalled_code
#ext_generated_code
#input
#generated_code
Expand Down
Loading