From 9c5089decba5c6a26bfcf28ec9666cf8c3475ef1 Mon Sep 17 00:00:00 2001 From: Vlad Frolov Date: Fri, 23 Feb 2024 00:02:59 +0100 Subject: [PATCH] refactor: Slimmed down the dependencies by default --- examples/adder/Cargo.toml | 2 +- examples/fungible-token/Cargo.toml | 2 +- examples/fungible-token/ft/Cargo.toml | 1 - examples/lockable-fungible-token/Cargo.toml | 3 +- examples/mission-control/src/account.rs | 18 +- examples/mission-control/src/asset.rs | 14 +- examples/status-message/Cargo.toml | 3 + examples/status-message/src/lib.rs | 6 +- near-contract-standards/Cargo.toml | 5 +- .../src/fungible_token/metadata.rs | 6 +- .../src/non_fungible_token/metadata.rs | 28 +- .../src/non_fungible_token/token.rs | 6 +- .../src/storage_management/mod.rs | 10 +- near-sdk-macros/src/lib.rs | 239 +++++++++--------- near-sdk/Cargo.toml | 11 +- near-sdk/src/lib.rs | 15 +- 16 files changed, 194 insertions(+), 175 deletions(-) diff --git a/examples/adder/Cargo.toml b/examples/adder/Cargo.toml index 3e8e6aba5..b309ed907 100644 --- a/examples/adder/Cargo.toml +++ b/examples/adder/Cargo.toml @@ -8,7 +8,7 @@ edition = "2021" crate-type = ["cdylib"] [dependencies] -near-sdk = { path = "../../near-sdk", features = ["unstable"] } +near-sdk = { path = "../../near-sdk" } [dev-dependencies] near-workspaces = { version = "0.9.0", default-features = false, features = ["install"] } diff --git a/examples/fungible-token/Cargo.toml b/examples/fungible-token/Cargo.toml index dea299ad6..33bf5162b 100644 --- a/examples/fungible-token/Cargo.toml +++ b/examples/fungible-token/Cargo.toml @@ -6,7 +6,7 @@ edition = "2021" [dev-dependencies] anyhow = "1.0" -near-sdk = { path = "../../near-sdk" } +near-sdk = { path = "../../near-sdk", features = ["unit-testing"] } tokio = { version = "1.14", features = ["full"] } near-workspaces = { version = "0.9.0", default-features = false, features = ["install"] } diff --git a/examples/fungible-token/ft/Cargo.toml b/examples/fungible-token/ft/Cargo.toml index 0f7f98ec7..664d923b0 100644 --- a/examples/fungible-token/ft/Cargo.toml +++ b/examples/fungible-token/ft/Cargo.toml @@ -10,4 +10,3 @@ crate-type = ["cdylib"] [dependencies] near-sdk = { path = "../../../near-sdk" } near-contract-standards = { path = "../../../near-contract-standards" } -schemars = "0.8" diff --git a/examples/lockable-fungible-token/Cargo.toml b/examples/lockable-fungible-token/Cargo.toml index 03501f72e..5b455b985 100644 --- a/examples/lockable-fungible-token/Cargo.toml +++ b/examples/lockable-fungible-token/Cargo.toml @@ -8,11 +8,12 @@ edition = "2021" crate-type = ["cdylib"] [dependencies] -near-sdk = { path = "../../near-sdk" } +near-sdk = { path = "../../near-sdk", features = ["legacy"] } [dev-dependencies] anyhow = "1.0" tokio = { version = "1.14", features = ["full"] } +near-sdk = { path = "../../near-sdk", features = ["unit-testing"] } near-workspaces = { version = "0.9.0", default-features = false, features = ["install"] } [profile.release] diff --git a/examples/mission-control/src/account.rs b/examples/mission-control/src/account.rs index 4c17f3a7c..720dae057 100644 --- a/examples/mission-control/src/account.rs +++ b/examples/mission-control/src/account.rs @@ -1,11 +1,13 @@ -use crate::asset::*; -use crate::rate::*; -use near_sdk::borsh::{BorshDeserialize, BorshSerialize}; -use near_sdk::schemars::JsonSchema; -use near_sdk::serde::{Deserialize, Serialize}; use std::collections::HashMap; use std::ops; +use near_sdk::NearSchema; +use near_sdk::borsh::{BorshDeserialize, BorshSerialize}; +use near_sdk::serde::{Deserialize, Serialize}; + +use crate::asset::*; +use crate::rate::*; + #[derive( PartialEq, Eq, @@ -18,17 +20,15 @@ use std::ops; Debug, BorshDeserialize, BorshSerialize, - JsonSchema, + NearSchema, )] #[serde(crate = "near_sdk::serde")] #[borsh(crate = "near_sdk::borsh")] -#[schemars(crate = "near_sdk::schemars")] pub struct Quantity(pub i32); -#[derive(Clone, Serialize, Deserialize, BorshDeserialize, BorshSerialize, JsonSchema)] +#[derive(Clone, Serialize, Deserialize, BorshDeserialize, BorshSerialize, NearSchema)] #[serde(crate = "near_sdk::serde")] #[borsh(crate = "near_sdk::borsh")] -#[schemars(crate = "near_sdk::schemars")] pub struct Account(pub HashMap); pub enum Tranx { diff --git a/examples/mission-control/src/asset.rs b/examples/mission-control/src/asset.rs index 35890214f..2eddc3aeb 100644 --- a/examples/mission-control/src/asset.rs +++ b/examples/mission-control/src/asset.rs @@ -1,5 +1,5 @@ +use near_sdk::NearSchema; use near_sdk::borsh::{BorshDeserialize, BorshSerialize}; -use near_sdk::schemars::JsonSchema; use near_sdk::serde::{Deserialize, Serialize}; #[derive( @@ -14,11 +14,10 @@ use near_sdk::serde::{Deserialize, Serialize}; Deserialize, BorshDeserialize, BorshSerialize, - JsonSchema, + NearSchema, )] #[serde(crate = "near_sdk::serde")] #[borsh(crate = "near_sdk::borsh")] -#[schemars(crate = "near_sdk::schemars")] pub enum Resource { Battery, RgbSensor, @@ -38,11 +37,10 @@ pub enum Resource { Deserialize, BorshDeserialize, BorshSerialize, - JsonSchema, + NearSchema, )] #[serde(crate = "near_sdk::serde")] #[borsh(crate = "near_sdk::borsh")] -#[schemars(crate = "near_sdk::schemars")] pub enum Reward { Score, Token, @@ -63,11 +61,10 @@ pub enum Reward { Deserialize, BorshDeserialize, BorshSerialize, - JsonSchema, + NearSchema, )] #[serde(crate = "near_sdk::serde")] #[borsh(crate = "near_sdk::borsh")] -#[schemars(crate = "near_sdk::schemars")] pub enum Asset { Resource(Resource), Reward(Reward), @@ -85,11 +82,10 @@ pub enum Asset { Ord, BorshDeserialize, BorshSerialize, - JsonSchema, + NearSchema )] #[serde(crate = "near_sdk::serde")] #[borsh(crate = "near_sdk::borsh")] -#[schemars(crate = "near_sdk::schemars")] pub enum Exchange { MissionTimeWithResource, MissionTimeWithTrust, diff --git a/examples/status-message/Cargo.toml b/examples/status-message/Cargo.toml index 28e4fd7eb..e72a5ba0e 100644 --- a/examples/status-message/Cargo.toml +++ b/examples/status-message/Cargo.toml @@ -10,6 +10,9 @@ crate-type = ["cdylib"] [dependencies] near-sdk = { path = "../../near-sdk" } +[dev-dependencies] +near-sdk = { path = "../../near-sdk", features = ["unit-testing"] } + [profile.release] codegen-units = 1 # Tell `rustc` to optimize for small code size. diff --git a/examples/status-message/src/lib.rs b/examples/status-message/src/lib.rs index b0e8e7dbb..002af6cba 100644 --- a/examples/status-message/src/lib.rs +++ b/examples/status-message/src/lib.rs @@ -1,5 +1,5 @@ use near_sdk::borsh::{BorshDeserialize, BorshSerialize}; -use near_sdk::collections::LookupMap; +use near_sdk::store::LookupMap; use near_sdk::{env, log, near_bindgen, AccountId, BorshStorageKey}; #[derive(BorshSerialize, BorshStorageKey)] @@ -25,10 +25,10 @@ impl StatusMessage { pub fn set_status(&mut self, message: String) { let account_id = env::signer_account_id(); log!("{} set_status with message {}", account_id, message); - self.records.insert(&account_id, &message); + self.records.insert(account_id, message); } - pub fn get_status(&self, account_id: AccountId) -> Option { + pub fn get_status(&self, account_id: AccountId) -> Option<&String> { log!("get_status for account_id {}", account_id); self.records.get(&account_id) } diff --git a/near-contract-standards/Cargo.toml b/near-contract-standards/Cargo.toml index 198b2a7bf..e5e31c9b0 100644 --- a/near-contract-standards/Cargo.toml +++ b/near-contract-standards/Cargo.toml @@ -15,6 +15,9 @@ NEAR smart contracts standard library. [dependencies] near-sdk = { path = "../near-sdk", version = "~5.0.0-alpha.3", default-features = false, features = ["legacy"] } +[dev-dependencies] +near-sdk = { path = "../near-sdk", default-features = false, features = ["unit-testing"] } + [features] -default = ["abi"] +default = [] abi = ["near-sdk/abi"] diff --git a/near-contract-standards/src/fungible_token/metadata.rs b/near-contract-standards/src/fungible_token/metadata.rs index 19c711af8..5269ded39 100644 --- a/near-contract-standards/src/fungible_token/metadata.rs +++ b/near-contract-standards/src/fungible_token/metadata.rs @@ -1,15 +1,13 @@ use near_sdk::borsh::{BorshDeserialize, BorshSerialize}; use near_sdk::json_types::Base64VecU8; -use near_sdk::schemars; use near_sdk::serde::{Deserialize, Serialize}; -use near_sdk::{ext_contract, require}; +use near_sdk::{ext_contract, require, NearSchema}; pub const FT_METADATA_SPEC: &str = "ft-1.0.0"; -#[derive(BorshDeserialize, BorshSerialize, Clone, Deserialize, Serialize)] +#[derive(Clone, BorshDeserialize, BorshSerialize, Deserialize, Serialize, NearSchema)] #[serde(crate = "near_sdk::serde")] #[borsh(crate = "near_sdk::borsh")] -#[cfg_attr(feature = "abi", derive(schemars::JsonSchema))] pub struct FungibleTokenMetadata { pub spec: String, pub name: String, diff --git a/near-contract-standards/src/non_fungible_token/metadata.rs b/near-contract-standards/src/non_fungible_token/metadata.rs index 72f51c500..a46d08341 100644 --- a/near-contract-standards/src/non_fungible_token/metadata.rs +++ b/near-contract-standards/src/non_fungible_token/metadata.rs @@ -1,15 +1,23 @@ use near_sdk::borsh::{BorshDeserialize, BorshSerialize}; use near_sdk::json_types::Base64VecU8; -use near_sdk::require; -use near_sdk::schemars; use near_sdk::serde::{Deserialize, Serialize}; +use near_sdk::{require, NearSchema}; /// This spec can be treated like a version of the standard. pub const NFT_METADATA_SPEC: &str = "nft-1.0.0"; /// Metadata for the NFT contract itself. -#[derive(BorshDeserialize, BorshSerialize, Serialize, Deserialize, Clone, Debug, PartialEq, Eq)] -#[cfg_attr(feature = "abi", derive(schemars::JsonSchema))] +#[derive( + Clone, + Debug, + PartialEq, + Eq, + BorshDeserialize, + BorshSerialize, + Serialize, + Deserialize, + NearSchema, +)] #[serde(crate = "near_sdk::serde")] #[borsh(crate = "near_sdk::borsh")] pub struct NFTContractMetadata { @@ -24,9 +32,17 @@ pub struct NFTContractMetadata { /// Metadata on the individual token level. #[derive( - Debug, Clone, Serialize, Deserialize, PartialEq, Eq, BorshDeserialize, BorshSerialize, Default, + Debug, + Clone, + Default, + PartialEq, + Eq, + Serialize, + Deserialize, + BorshDeserialize, + BorshSerialize, + NearSchema, )] -#[cfg_attr(feature = "abi", derive(schemars::JsonSchema))] #[serde(crate = "near_sdk::serde")] #[borsh(crate = "near_sdk::borsh")] pub struct TokenMetadata { diff --git a/near-contract-standards/src/non_fungible_token/token.rs b/near-contract-standards/src/non_fungible_token/token.rs index efe3bf350..cd0ebfd44 100644 --- a/near-contract-standards/src/non_fungible_token/token.rs +++ b/near-contract-standards/src/non_fungible_token/token.rs @@ -1,14 +1,12 @@ use crate::non_fungible_token::metadata::TokenMetadata; -use near_sdk::schemars; use near_sdk::serde::{Deserialize, Serialize}; -use near_sdk::AccountId; +use near_sdk::{AccountId, NearSchema}; use std::collections::HashMap; /// Note that token IDs for NFTs are strings on NEAR. It's still fine to use autoincrementing numbers as unique IDs if desired, but they should be stringified. This is to make IDs more future-proof as chain-agnostic conventions and standards arise, and allows for more flexibility with considerations like bridging NFTs across chains, etc. pub type TokenId = String; /// In this implementation, the Token struct takes two extensions standards (metadata and approval) as optional fields, as they are frequently used in modern NFTs. -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] -#[cfg_attr(feature = "abi", derive(schemars::JsonSchema))] +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, NearSchema)] #[serde(crate = "near_sdk::serde")] pub struct Token { pub token_id: TokenId, diff --git a/near-contract-standards/src/storage_management/mod.rs b/near-contract-standards/src/storage_management/mod.rs index d39dc5278..02146dc54 100644 --- a/near-contract-standards/src/storage_management/mod.rs +++ b/near-contract-standards/src/storage_management/mod.rs @@ -1,20 +1,18 @@ use near_sdk::borsh::{BorshDeserialize, BorshSerialize}; -use near_sdk::schemars; use near_sdk::serde::{Deserialize, Serialize}; -use near_sdk::{AccountId, NearToken}; -#[derive(BorshDeserialize, BorshSerialize, Serialize, Deserialize)] +use near_sdk::{AccountId, NearSchema, NearToken}; + +#[derive(BorshDeserialize, BorshSerialize, Serialize, Deserialize, NearSchema)] #[serde(crate = "near_sdk::serde")] #[borsh(crate = "near_sdk::borsh")] -#[cfg_attr(feature = "abi", derive(schemars::JsonSchema))] pub struct StorageBalance { pub total: NearToken, pub available: NearToken, } -#[derive(BorshDeserialize, BorshSerialize, Serialize, Deserialize)] +#[derive(BorshDeserialize, BorshSerialize, Serialize, Deserialize, NearSchema)] #[serde(crate = "near_sdk::serde")] #[borsh(crate = "near_sdk::borsh")] -#[cfg_attr(feature = "abi", derive(schemars::JsonSchema))] pub struct StorageBalanceBounds { pub min: NearToken, pub max: Option, diff --git a/near-sdk-macros/src/lib.rs b/near-sdk-macros/src/lib.rs index d6039ea45..c6a4c105f 100644 --- a/near-sdk-macros/src/lib.rs +++ b/near-sdk-macros/src/lib.rs @@ -321,156 +321,163 @@ pub fn init(_attr: TokenStream, item: TokenStream) -> TokenStream { } #[cfg(feature = "abi")] -use darling::FromDeriveInput; #[derive(darling::FromDeriveInput, Debug)] #[darling(attributes(abi), forward_attrs(serde, borsh_skip, schemars, validate))] -#[cfg(feature = "abi")] struct DeriveNearSchema { attrs: Vec, json: Option, borsh: Option, } -#[cfg(feature = "abi")] #[proc_macro_derive(NearSchema, attributes(abi, serde, borsh, schemars, validate))] -pub fn derive_near_schema(input: TokenStream) -> TokenStream { - let derive_input = syn::parse_macro_input!(input as syn::DeriveInput); - let args = match DeriveNearSchema::from_derive_input(&derive_input) { - Ok(v) => v, - Err(e) => { - return TokenStream::from(e.write_errors()); - } - }; - - if args.borsh.is_none() - && args.json.is_none() - && derive_input.attrs.iter().any(|attr| attr.path().is_ident("abi")) +pub fn derive_near_schema(#[allow(unused)] input: TokenStream) -> TokenStream { + #[cfg(not(feature = "abi"))] { - return TokenStream::from( - syn::Error::new_spanned( - derive_input.to_token_stream(), - "At least one of `json` or `borsh` inside of `#[abi(...)]` must be specified", - ) - .to_compile_error(), - ); + TokenStream::from(quote! {}) } - // #[abi(json, borsh)] - let (json_schema, borsh_schema) = (args.json.unwrap_or(false), args.borsh.unwrap_or(false)); - let mut input = derive_input; - input.attrs = args.attrs; - - let strip_unknown_attr = |attrs: &mut Vec| { - attrs.retain(|attr| { - ["serde", "schemars", "validate", "borsh"] - .iter() - .any(|&path| attr.path().is_ident(path)) - }); - }; + #[cfg(feature = "abi")] + { + use darling::FromDeriveInput; - match &mut input.data { - syn::Data::Struct(data) => { - for field in &mut data.fields { - strip_unknown_attr(&mut field.attrs); - } - } - syn::Data::Enum(data) => { - for variant in &mut data.variants { - strip_unknown_attr(&mut variant.attrs); - for field in &mut variant.fields { - strip_unknown_attr(&mut field.attrs); - } + let derive_input = syn::parse_macro_input!(input as syn::DeriveInput); + let args = match DeriveNearSchema::from_derive_input(&derive_input) { + Ok(v) => v, + Err(e) => { + return TokenStream::from(e.write_errors()); } - } - syn::Data::Union(_) => { + }; + + if args.borsh.is_none() + && args.json.is_none() + && derive_input.attrs.iter().any(|attr| attr.path().is_ident("abi")) + { return TokenStream::from( syn::Error::new_spanned( - input.to_token_stream(), - "`NearSchema` does not support derive for unions", + derive_input.to_token_stream(), + "At least one of `json` or `borsh` inside of `#[abi(...)]` must be specified", ) .to_compile_error(), - ) + ); } - } - // or #[abi(json)] - let json_schema = json_schema || !borsh_schema; + // #[abi(json, borsh)] + let (json_schema, borsh_schema) = (args.json.unwrap_or(false), args.borsh.unwrap_or(false)); + let mut input = derive_input; + input.attrs = args.attrs; + + let strip_unknown_attr = |attrs: &mut Vec| { + attrs.retain(|attr| { + ["serde", "schemars", "validate", "borsh"] + .iter() + .any(|&path| attr.path().is_ident(path)) + }); + }; - let derive = { - let mut derive = quote! {}; - if borsh_schema { - derive = quote! { - #[derive(::near_sdk::borsh::BorshSchema)] - #[borsh(crate = "::near_sdk::borsh")] - }; - } - if json_schema { - derive = quote! { - #derive - #[derive(::near_sdk::schemars::JsonSchema)] - #[schemars(crate = "::near_sdk::schemars")] - }; + match &mut input.data { + syn::Data::Struct(data) => { + for field in &mut data.fields { + strip_unknown_attr(&mut field.attrs); + } + } + syn::Data::Enum(data) => { + for variant in &mut data.variants { + strip_unknown_attr(&mut variant.attrs); + for field in &mut variant.fields { + strip_unknown_attr(&mut field.attrs); + } + } + } + syn::Data::Union(_) => { + return TokenStream::from( + syn::Error::new_spanned( + input.to_token_stream(), + "`NearSchema` does not support derive for unions", + ) + .to_compile_error(), + ) + } } - derive - }; - let input_ident = &input.ident; + // or #[abi(json)] + let json_schema = json_schema || !borsh_schema; - let input_ident_proxy = quote::format_ident!("{}__NEAR_SCHEMA_PROXY", input_ident); + let derive = { + let mut derive = quote! {}; + if borsh_schema { + derive = quote! { + #[derive(::near_sdk::borsh::BorshSchema)] + #[borsh(crate = "::near_sdk::borsh")] + }; + } + if json_schema { + derive = quote! { + #derive + #[derive(::near_sdk::schemars::JsonSchema)] + #[schemars(crate = "::near_sdk::schemars")] + }; + } + derive + }; - let json_impl = if json_schema { - quote! { - #[automatically_derived] - impl ::near_sdk::schemars::JsonSchema for #input_ident_proxy { - fn schema_name() -> ::std::string::String { - stringify!(#input_ident).to_string() - } + let input_ident = &input.ident; - fn json_schema(gen: &mut ::near_sdk::schemars::gen::SchemaGenerator) -> ::near_sdk::schemars::schema::Schema { - <#input_ident as ::near_sdk::schemars::JsonSchema>::json_schema(gen) + let input_ident_proxy = quote::format_ident!("{}__NEAR_SCHEMA_PROXY", input_ident); + + let json_impl = if json_schema { + quote! { + #[automatically_derived] + impl ::near_sdk::schemars::JsonSchema for #input_ident_proxy { + fn schema_name() -> ::std::string::String { + stringify!(#input_ident).to_string() + } + + fn json_schema(gen: &mut ::near_sdk::schemars::gen::SchemaGenerator) -> ::near_sdk::schemars::schema::Schema { + <#input_ident as ::near_sdk::schemars::JsonSchema>::json_schema(gen) + } } } - } - } else { - quote! {} - }; + } else { + quote! {} + }; - let borsh_impl = if borsh_schema { - quote! { - #[automatically_derived] - impl ::near_sdk::borsh::BorshSchema for #input_ident_proxy { - fn declaration() -> ::near_sdk::borsh::schema::Declaration { - stringify!(#input_ident).to_string() - } + let borsh_impl = if borsh_schema { + quote! { + #[automatically_derived] + impl ::near_sdk::borsh::BorshSchema for #input_ident_proxy { + fn declaration() -> ::near_sdk::borsh::schema::Declaration { + stringify!(#input_ident).to_string() + } - fn add_definitions_recursively( - definitions: &mut ::near_sdk::borsh::__private::maybestd::collections::BTreeMap< - ::near_sdk::borsh::schema::Declaration, - ::near_sdk::borsh::schema::Definition - >, - ) { - <#input_ident as ::near_sdk::borsh::BorshSchema>::add_definitions_recursively(definitions); + fn add_definitions_recursively( + definitions: &mut ::near_sdk::borsh::__private::maybestd::collections::BTreeMap< + ::near_sdk::borsh::schema::Declaration, + ::near_sdk::borsh::schema::Definition + >, + ) { + <#input_ident as ::near_sdk::borsh::BorshSchema>::add_definitions_recursively(definitions); + } } } - } - } else { - quote! {} - }; + } else { + quote! {} + }; - TokenStream::from(quote! { - #[cfg(not(target_arch = "wasm32"))] - const _: () = { - #[allow(non_camel_case_types)] - type #input_ident_proxy = #input_ident; - { - #derive - #input - - #json_impl - #borsh_impl + TokenStream::from(quote! { + #[cfg(not(target_arch = "wasm32"))] + const _: () = { + #[allow(non_camel_case_types)] + type #input_ident_proxy = #input_ident; + { + #derive + #input + + #json_impl + #borsh_impl + }; }; - }; - }) + }) + } } /// `PanicOnDefault` generates implementation for `Default` trait that panics with the following diff --git a/near-sdk/Cargo.toml b/near-sdk/Cargo.toml index ae781debd..76e5bd82c 100644 --- a/near-sdk/Cargo.toml +++ b/near-sdk/Cargo.toml @@ -26,20 +26,20 @@ near-sys = { path = "../near-sys", version = "0.2.1" } base64 = "0.13" borsh = { version = "1.0.0", features = ["derive"] } bs58 = "0.4" -schemars = { version = "0.8.8", optional = true } -# Export dependencies for contracts -wee_alloc = { version = "0.4.5", default-features = false, optional = true } # Used for caching, might be worth porting only functionality needed. once_cell = { version = "1.17", default-features = false } -near-abi = { version = "0.4.0", features = ["__chunked-entries"], optional = true } near-account-id = { version="1.0.0", features = ["serde", "borsh"] } near-gas = { version = "0.2.3", features = ["serde", "borsh"] } near-token = { version = "0.2.0", features = ["serde", "borsh"] } +[target.'cfg(target_arch = "wasm32")'.dependencies] +wee_alloc = { version = "0.4.5", default-features = false, optional = true } [target.'cfg(not(target_arch = "wasm32"))'.dependencies] +schemars = { version = "0.8.8", optional = true } +near-abi = { version = "0.4.0", features = ["__chunked-entries"], optional = true } near-vm-runner = { version = "0.20", optional = true } near-primitives-core = { version = "0.20", optional = true } near-primitives = { version = "0.20", optional = true } @@ -47,6 +47,7 @@ near-crypto = { version = "0.20", optional = true } near-parameters = { version = "0.20", optional = true } [dev-dependencies] +near-sdk = { path = ".", features = ["legacy", "unit-testing"] } rand = "0.8.4" trybuild = "1.0" rustversion = "1.0" @@ -62,7 +63,7 @@ near-abi = { version = "0.4.0", features = ["__chunked-entries"] } symbolic-debuginfo = "8.8" [features] -default = ["wee_alloc", "unit-testing", "legacy", "abi"] +default = ["wee_alloc"] expensive-debug = [] unstable = [] legacy = [] diff --git a/near-sdk/src/lib.rs b/near-sdk/src/lib.rs index 5042b7533..2a97f93ce 100644 --- a/near-sdk/src/lib.rs +++ b/near-sdk/src/lib.rs @@ -7,10 +7,9 @@ #[cfg(test)] extern crate quickcheck; -#[cfg(feature = "abi")] -pub use near_sdk_macros::NearSchema; pub use near_sdk_macros::{ - ext_contract, near_bindgen, BorshStorageKey, EventMetadata, FunctionError, PanicOnDefault, + ext_contract, near_bindgen, BorshStorageKey, EventMetadata, FunctionError, NearSchema, + PanicOnDefault, }; pub mod store; @@ -36,21 +35,21 @@ pub mod json_types; mod types; pub use crate::types::*; -#[cfg(all(not(target_arch = "wasm32"), feature = "unit-testing"))] +#[cfg(all(feature = "unit-testing", not(target_arch = "wasm32")))] pub use environment::mock; -#[cfg(all(not(target_arch = "wasm32"), feature = "unit-testing"))] +#[cfg(all(feature = "unit-testing", not(target_arch = "wasm32")))] pub use environment::mock::test_vm_config; -#[cfg(all(not(target_arch = "wasm32"), feature = "unit-testing"))] +#[cfg(all(feature = "unit-testing", not(target_arch = "wasm32")))] // Re-export to avoid breakages pub use environment::mock::MockedBlockchain; -#[cfg(all(not(target_arch = "wasm32"), feature = "unit-testing"))] +#[cfg(all(feature = "unit-testing", not(target_arch = "wasm32")))] pub use test_utils::context::VMContext; pub mod utils; pub use crate::utils::storage_key_impl::IntoStorageKey; pub use crate::utils::*; -#[cfg(all(not(target_arch = "wasm32"), feature = "unit-testing"))] +#[cfg(all(feature = "unit-testing", not(target_arch = "wasm32")))] pub mod test_utils; // Set up global allocator by default if custom-allocator feature is not set in wasm32 architecture.