diff --git a/cargo-near/Cargo.toml b/cargo-near/Cargo.toml index 4f37be3d..619eb141 100644 --- a/cargo-near/Cargo.toml +++ b/cargo-near/Cargo.toml @@ -16,7 +16,6 @@ cargo_metadata = "0.14" clap = { version = "3.2", features = ["derive", "env"] } colored = "2.0" env_logger = "0.9" -near-sdk = { version = "4.1.0-pre.1", features = ["abi"] } log = "0.4" prettyplease = "0.1" toml = "0.5" @@ -24,8 +23,9 @@ serde_json = "1.0" symbolic-debuginfo = "8.8" syn = "1.0" quote = "1.0" +schemars = "0.8" +near-abi = { version = "0.1.0-pre.0", features = ["__chunked-entries"] } [dev-dependencies] function_name = "0.3" proc-macro2 = "1.0" -schemars = "0.8" diff --git a/cargo-near/src/abi/generation.rs b/cargo-near/src/abi/generation.rs index a0e7dba0..f354bd4e 100644 --- a/cargo-near/src/abi/generation.rs +++ b/cargo-near/src/abi/generation.rs @@ -125,7 +125,7 @@ pub(crate) fn generate_main_rs(dylib_path: &Path) -> anyhow::Result { let near_abi_function_defs = near_abi_symbols.iter().map(|s| { let name = format_ident!("{}", s); quote! { - fn #name() -> near_sdk::__private::AbiRoot; + fn #name() -> near_sdk::__private::ChunkedAbiEntry; } }); let near_abi_function_invocations = near_abi_symbols.iter().map(|s| { @@ -141,9 +141,8 @@ pub(crate) fn generate_main_rs(dylib_path: &Path) -> anyhow::Result { } fn main() -> Result<(), std::io::Error> { - let root_abis = vec![#(#near_abi_function_invocations),*]; - let combined_root_abi = near_sdk::__private::AbiRoot::combine(root_abis); - let contents = serde_json::to_string_pretty(&combined_root_abi)?; + let abi_entries = vec![#(#near_abi_function_invocations),*]; + let contents = serde_json::to_string_pretty(&abi_entries)?; print!("{}", contents); Ok(()) } diff --git a/cargo-near/src/abi/mod.rs b/cargo-near/src/abi/mod.rs index 766ffc0c..147567d5 100644 --- a/cargo-near/src/abi/mod.rs +++ b/cargo-near/src/abi/mod.rs @@ -1,7 +1,5 @@ use crate::cargo::{manifest::CargoManifestPath, metadata::CrateMetadata}; use crate::util; -use near_sdk::__private::schemars::schema::{Schema, SchemaObject}; -use near_sdk::__private::{AbiMetadata, AbiRoot}; use std::collections::HashMap; use std::{fs, path::PathBuf}; @@ -50,22 +48,23 @@ pub(crate) fn execute( )], )?; - let mut near_abi: AbiRoot = serde_json::from_slice(&stdout)?; - let metadata = extract_metadata(&crate_metadata); - near_abi.metadata = metadata; + let mut contract_abi = near_abi::__private::ChunkedAbiEntry::combine( + serde_json::from_slice::>(&stdout)?.into_iter(), + )? + .into_abi_root(extract_metadata(&crate_metadata)); if !generate_docs { - strip_docs(&mut near_abi); + strip_docs(&mut contract_abi); } - let near_abi_json = serde_json::to_string_pretty(&near_abi)?; + let near_abi_json = serde_json::to_string_pretty(&contract_abi)?; let out_path_abi = crate_metadata.target_directory.join(ABI_FILE); fs::write(&out_path_abi, near_abi_json)?; Ok(AbiResult { path: out_path_abi }) } -fn extract_metadata(crate_metadata: &CrateMetadata) -> AbiMetadata { +fn extract_metadata(crate_metadata: &CrateMetadata) -> near_abi::AbiMetadata { let package = &crate_metadata.root_package; - AbiMetadata { + near_abi::AbiMetadata { name: Some(package.name.clone()), version: Some(package.version.to_string()), authors: package.authors.clone(), @@ -73,12 +72,12 @@ fn extract_metadata(crate_metadata: &CrateMetadata) -> AbiMetadata { } } -fn strip_docs(abi_root: &mut AbiRoot) { - for function in &mut abi_root.abi.functions { +fn strip_docs(abi_root: &mut near_abi::AbiRoot) { + for function in &mut abi_root.body.functions { function.doc = None; } - for schema in &mut abi_root.abi.root_schema.definitions.values_mut() { - if let Schema::Object(SchemaObject { + for schema in &mut abi_root.body.root_schema.definitions.values_mut() { + if let schemars::schema::Schema::Object(schemars::schema::SchemaObject { metadata: Some(metadata), .. }) = schema diff --git a/integration-tests/Cargo.toml b/integration-tests/Cargo.toml index 799d73f8..fe6bd6de 100644 --- a/integration-tests/Cargo.toml +++ b/integration-tests/Cargo.toml @@ -6,10 +6,10 @@ publish = false [dev-dependencies] anyhow = "1.0" +borsh = "0.9" cargo-near = { path = "../cargo-near" } function_name = "0.3" git2 = "0.14" -near-sdk = { version = "4.1.0-pre.1", features = ["abi"] } prettyplease = "0.1" proc-macro2 = "1.0" schemars = "0.8" @@ -17,3 +17,4 @@ serde_json = "1.0" syn = "1.0" tempfile = "3.3" quote = "1.0" +near-abi = "0.1.0-pre.0" diff --git a/integration-tests/src/lib.rs b/integration-tests/src/lib.rs index 60f73d20..2a6d1155 100644 --- a/integration-tests/src/lib.rs +++ b/integration-tests/src/lib.rs @@ -26,7 +26,7 @@ macro_rules! generate_abi { doc: false, }))?; - let abi_root: near_sdk::__private::AbiRoot = + let abi_root: near_abi::AbiRoot = serde_json::from_slice(&fs::read(workspace_dir.join(function_name!()).join("target").join("near").join("abi.json"))?)?; abi_root }}; diff --git a/integration-tests/templates/_Cargo.toml b/integration-tests/templates/_Cargo.toml index f4d80bcc..e3bcb980 100644 --- a/integration-tests/templates/_Cargo.toml +++ b/integration-tests/templates/_Cargo.toml @@ -7,7 +7,7 @@ edition = "2021" crate-type = ["cdylib"] [dependencies] -near-sdk = { version = "4.1.0-pre.1", features = ["abi"] } +near-sdk = { version = "4.1.0-pre.2", features = ["abi"] } serde = { version = "1", features = ["derive"] } schemars = "0.8" diff --git a/integration-tests/templates/_Cargo_no_abi_feature.toml b/integration-tests/templates/_Cargo_no_abi_feature.toml index fece7838..62629112 100644 --- a/integration-tests/templates/_Cargo_no_abi_feature.toml +++ b/integration-tests/templates/_Cargo_no_abi_feature.toml @@ -7,7 +7,7 @@ edition = "2021" crate-type = ["cdylib"] [dependencies] -near-sdk = { version = "4.1.0-pre.1" } +near-sdk = { version = "4.1.0-pre.2" } serde = { version = "1", features = ["derive"] } schemars = "0.8" diff --git a/integration-tests/templates/sdk-dependency/_Cargo_explicit.toml b/integration-tests/templates/sdk-dependency/_Cargo_explicit.toml index 5c4a0144..f7bc7042 100644 --- a/integration-tests/templates/sdk-dependency/_Cargo_explicit.toml +++ b/integration-tests/templates/sdk-dependency/_Cargo_explicit.toml @@ -11,7 +11,7 @@ serde = { version = "1", features = ["derive"] } schemars = "0.8" [dependencies.near-sdk] -version = "4.1.0-pre.1" +version = "4.1.0-pre.2" features = ["abi"] [workspace] diff --git a/integration-tests/templates/sdk-dependency/_Cargo_local_path_with_version.toml b/integration-tests/templates/sdk-dependency/_Cargo_local_path_with_version.toml index 01eff5b1..b5b3c937 100644 --- a/integration-tests/templates/sdk-dependency/_Cargo_local_path_with_version.toml +++ b/integration-tests/templates/sdk-dependency/_Cargo_local_path_with_version.toml @@ -7,7 +7,7 @@ edition = "2021" crate-type = ["cdylib"] [dependencies] -near-sdk = { path = "::path::", version = "4.1.0-pre.1", features = ["abi"] } +near-sdk = { path = "::path::", version = "4.1.0-pre.2", features = ["abi"] } serde = { version = "1", features = ["derive"] } schemars = "0.8" diff --git a/integration-tests/templates/sdk-dependency/_Cargo_multiple_features.toml b/integration-tests/templates/sdk-dependency/_Cargo_multiple_features.toml index b1e1d669..ff79a015 100644 --- a/integration-tests/templates/sdk-dependency/_Cargo_multiple_features.toml +++ b/integration-tests/templates/sdk-dependency/_Cargo_multiple_features.toml @@ -7,7 +7,7 @@ edition = "2021" crate-type = ["cdylib"] [dependencies] -near-sdk = { version = "4.1.0-pre.1", features = ["abi", "unstable"] } +near-sdk = { version = "4.1.0-pre.2", features = ["abi", "unstable"] } serde = { version = "1", features = ["derive"] } schemars = "0.8" diff --git a/integration-tests/templates/sdk-dependency/_Cargo_no_default_features.toml b/integration-tests/templates/sdk-dependency/_Cargo_no_default_features.toml index 27ec603c..dc87a94a 100644 --- a/integration-tests/templates/sdk-dependency/_Cargo_no_default_features.toml +++ b/integration-tests/templates/sdk-dependency/_Cargo_no_default_features.toml @@ -7,7 +7,7 @@ edition = "2021" crate-type = ["cdylib"] [dependencies] -near-sdk = { version = "4.1.0-pre.1", default-features = false, features = ["abi"] } +near-sdk = { version = "4.1.0-pre.2", default-features = false, features = ["abi"] } serde = { version = "1", features = ["derive"] } schemars = "0.8" diff --git a/integration-tests/templates/sdk-dependency/_Cargo_patch.toml b/integration-tests/templates/sdk-dependency/_Cargo_patch.toml index 424bb108..ff50f417 100644 --- a/integration-tests/templates/sdk-dependency/_Cargo_patch.toml +++ b/integration-tests/templates/sdk-dependency/_Cargo_patch.toml @@ -7,12 +7,12 @@ edition = "2021" crate-type = ["cdylib"] [dependencies] -near-sdk = { version = "4.1.0-pre.1", features = ["abi"] } +near-sdk = { version = "4.1.0-pre.2", features = ["abi"] } serde = { version = "1", features = ["derive"] } schemars = "0.8" [patch.crates-io] -near-sdk = { git = "https://github.com/near/near-sdk-rs.git", rev = "aa151597033872d44d5639933540ce6f1eca505a" } +near-sdk = { git = "https://github.com/near/near-sdk-rs.git", rev = "83cb1c40403e4156bd6d1d258237bbdf03326afc" } [workspace] members = [] diff --git a/integration-tests/templates/sdk-dependency/_Cargo_platform_specific.toml b/integration-tests/templates/sdk-dependency/_Cargo_platform_specific.toml index 18b05261..a73e8de7 100644 --- a/integration-tests/templates/sdk-dependency/_Cargo_platform_specific.toml +++ b/integration-tests/templates/sdk-dependency/_Cargo_platform_specific.toml @@ -11,10 +11,10 @@ serde = { version = "1", features = ["derive"] } schemars = "0.8" [target.'cfg(windows)'.dependencies] -near-sdk = { version = "4.1.0-pre.1", features = ["abi"] } +near-sdk = { version = "4.1.0-pre.2", features = ["abi"] } [target.'cfg(unix)'.dependencies] -near-sdk = { version = "4.1.0-pre.1", features = ["abi"] } +near-sdk = { version = "4.1.0-pre.2", features = ["abi"] } [workspace] members = [] diff --git a/integration-tests/templates/sdk-dependency/_Cargo_renamed.toml b/integration-tests/templates/sdk-dependency/_Cargo_renamed.toml index 6c3bd69c..0ff84f34 100644 --- a/integration-tests/templates/sdk-dependency/_Cargo_renamed.toml +++ b/integration-tests/templates/sdk-dependency/_Cargo_renamed.toml @@ -7,7 +7,7 @@ edition = "2021" crate-type = ["cdylib"] [dependencies] -near = { version = "4.1.0-pre.1", package = "near-sdk", features = ["abi"] } +near = { version = "4.1.0-pre.2", package = "near-sdk", features = ["abi"] } serde = { version = "1", features = ["derive"] } schemars = "0.8" diff --git a/integration-tests/tests/cargo/mod.rs b/integration-tests/tests/cargo/mod.rs index 9d6a2009..bba06439 100644 --- a/integration-tests/tests/cargo/mod.rs +++ b/integration-tests/tests/cargo/mod.rs @@ -19,7 +19,7 @@ fn clone_git_repo(version: &str) -> anyhow::Result { #[test] #[named] fn test_dependency_local_path() -> anyhow::Result<()> { - let near_sdk_dir = clone_git_repo("aa151597033872d44d5639933540ce6f1eca505a")?; + let near_sdk_dir = clone_git_repo("83cb1c40403e4156bd6d1d258237bbdf03326afc")?; let near_sdk_dep_path = near_sdk_dir.path().join("near-sdk"); // near-sdk = { path = "::path::", features = ["abi"] } @@ -30,8 +30,8 @@ fn test_dependency_local_path() -> anyhow::Result<()> { pub fn foo(&self, a: bool, b: u32) {} }; - assert_eq!(abi_root.abi.functions.len(), 1); - let function = &abi_root.abi.functions[0]; + assert_eq!(abi_root.body.functions.len(), 1); + let function = &abi_root.body.functions[0]; assert_eq!(function.params.len(), 2); Ok(()) @@ -40,10 +40,10 @@ fn test_dependency_local_path() -> anyhow::Result<()> { #[test] #[named] fn test_dependency_local_path_with_version() -> anyhow::Result<()> { - let near_sdk_dir = clone_git_repo("aa151597033872d44d5639933540ce6f1eca505a")?; + let near_sdk_dir = clone_git_repo("83cb1c40403e4156bd6d1d258237bbdf03326afc")?; let near_sdk_dep_path = near_sdk_dir.path().join("near-sdk"); - // near-sdk = { path = "::path::", version = "4.1.0-pre.1", features = ["abi"] } + // near-sdk = { path = "::path::", version = "4.1.0-pre.2", features = ["abi"] } let abi_root = generate_abi_fn! { with Cargo "/templates/sdk-dependency/_Cargo_local_path_with_version.toml", and vars HashMap::from([("path", near_sdk_dep_path.to_str().unwrap())]); @@ -51,8 +51,8 @@ fn test_dependency_local_path_with_version() -> anyhow::Result<()> { pub fn foo(&self, a: bool, b: u32) {} }; - assert_eq!(abi_root.abi.functions.len(), 1); - let function = &abi_root.abi.functions[0]; + assert_eq!(abi_root.body.functions.len(), 1); + let function = &abi_root.body.functions[0]; assert_eq!(function.params.len(), 2); Ok(()) @@ -62,7 +62,7 @@ fn test_dependency_local_path_with_version() -> anyhow::Result<()> { #[named] fn test_dependency_explicit() -> anyhow::Result<()> { // [dependencies.near-sdk] - // version = "4.1.0-pre.1" + // version = "4.1.0-pre.2" // features = ["abi"] let abi_root = generate_abi_fn! { with Cargo "/templates/sdk-dependency/_Cargo_explicit.toml"; @@ -70,8 +70,8 @@ fn test_dependency_explicit() -> anyhow::Result<()> { pub fn foo(&self, a: bool, b: u32) {} }; - assert_eq!(abi_root.abi.functions.len(), 1); - let function = &abi_root.abi.functions[0]; + assert_eq!(abi_root.body.functions.len(), 1); + let function = &abi_root.body.functions[0]; assert_eq!(function.params.len(), 2); Ok(()) @@ -80,15 +80,15 @@ fn test_dependency_explicit() -> anyhow::Result<()> { #[test] #[named] fn test_dependency_no_default_features() -> anyhow::Result<()> { - // near-sdk = { version = "4.1.0-pre.1", default-features = false, features = ["abi"] } + // near-sdk = { version = "4.1.0-pre.2", default-features = false, features = ["abi"] } let abi_root = generate_abi_fn! { with Cargo "/templates/sdk-dependency/_Cargo_no_default_features.toml"; pub fn foo(&self, a: bool, b: u32) {} }; - assert_eq!(abi_root.abi.functions.len(), 1); - let function = &abi_root.abi.functions[0]; + assert_eq!(abi_root.body.functions.len(), 1); + let function = &abi_root.body.functions[0]; assert_eq!(function.params.len(), 2); Ok(()) @@ -97,15 +97,15 @@ fn test_dependency_no_default_features() -> anyhow::Result<()> { #[test] #[named] fn test_dependency_multiple_features() -> anyhow::Result<()> { - // near-sdk = { version = "4.1.0-pre.1", features = ["abi", "unstable"] } + // near-sdk = { version = "4.1.0-pre.2", features = ["abi", "unstable"] } let abi_root = generate_abi_fn! { with Cargo "/templates/sdk-dependency/_Cargo_multiple_features.toml"; pub fn foo(&self, a: bool, b: u32) {} }; - assert_eq!(abi_root.abi.functions.len(), 1); - let function = &abi_root.abi.functions[0]; + assert_eq!(abi_root.body.functions.len(), 1); + let function = &abi_root.body.functions[0]; assert_eq!(function.params.len(), 2); Ok(()) @@ -117,18 +117,18 @@ fn test_dependency_multiple_features() -> anyhow::Result<()> { #[named] fn test_dependency_platform_specific() -> anyhow::Result<()> { // [target.'cfg(windows)'.dependencies] - // near-sdk = { version = "4.1.0-pre.1", features = ["abi"] } + // near-sdk = { version = "4.1.0-pre.2", features = ["abi"] } // // [target.'cfg(unix)'.dependencies] - // near-sdk = { version = "4.1.0-pre.1", features = ["abi"] } + // near-sdk = { version = "4.1.0-pre.2", features = ["abi"] } let abi_root = generate_abi_fn! { with Cargo "/templates/sdk-dependency/_Cargo_platform_specific.toml"; pub fn foo(&self, a: bool, b: u32) {} }; - assert_eq!(abi_root.abi.functions.len(), 1); - let function = &abi_root.abi.functions[0]; + assert_eq!(abi_root.body.functions.len(), 1); + let function = &abi_root.body.functions[0]; assert_eq!(function.params.len(), 2); Ok(()) @@ -139,7 +139,7 @@ fn test_dependency_platform_specific() -> anyhow::Result<()> { #[test] #[named] fn test_dependency_renamed() -> anyhow::Result<()> { - // near = { version = "4.1.0-pre.1", package = "near-sdk", features = ["abi"] } + // near = { version = "4.1.0-pre.2", package = "near-sdk", features = ["abi"] } let abi_root = generate_abi! { with Cargo "/templates/sdk-dependency/_Cargo_renamed.toml"; @@ -156,8 +156,8 @@ fn test_dependency_renamed() -> anyhow::Result<()> { } }; - assert_eq!(abi_root.abi.functions.len(), 1); - let function = &abi_root.abi.functions[0]; + assert_eq!(abi_root.body.functions.len(), 1); + let function = &abi_root.body.functions[0]; assert_eq!(function.params.len(), 2); Ok(()) @@ -169,18 +169,18 @@ fn test_dependency_renamed() -> anyhow::Result<()> { #[named] fn test_dependency_patch() -> anyhow::Result<()> { // [dependencies] - // near-sdk = { version = "4.1.0-pre.1", features = ["abi"] } + // near-sdk = { version = "4.1.0-pre.2", features = ["abi"] } // // [patch.crates-io] - // near-sdk = { git = "https://github.com/near/near-sdk-rs.git", rev = "aa151597033872d44d5639933540ce6f1eca505a" } + // near-sdk = { git = "https://github.com/near/near-sdk-rs.git", rev = "83cb1c40403e4156bd6d1d258237bbdf03326afc" } let abi_root = generate_abi_fn! { with Cargo "/templates/sdk-dependency/_Cargo_patch.toml"; pub fn foo(&self, a: bool, b: u32) {} }; - assert_eq!(abi_root.abi.functions.len(), 1); - let function = &abi_root.abi.functions[0]; + assert_eq!(abi_root.body.functions.len(), 1); + let function = &abi_root.body.functions[0]; assert_eq!(function.params.len(), 2); Ok(()) diff --git a/integration-tests/tests/tests/borsh_schema.rs b/integration-tests/tests/tests/borsh_schema.rs index 4f74b413..8a9428a2 100644 --- a/integration-tests/tests/tests/borsh_schema.rs +++ b/integration-tests/tests/tests/borsh_schema.rs @@ -1,9 +1,7 @@ +use borsh::schema::{BorshSchemaContainer, Definition, Fields}; use cargo_near_integration_tests::{generate_abi, generate_abi_fn}; use function_name::named; -use near_sdk::{ - __private::{AbiParameter, AbiType}, - borsh::schema::{BorshSchemaContainer, Definition, Fields}, -}; +use near_abi::{AbiParameter, AbiType}; use std::{collections::HashMap, fs}; trait AsBorshSchema { @@ -34,8 +32,8 @@ fn test_borsh_schema_numeric_primitives_signed() -> anyhow::Result<()> { ) {} }; - assert_eq!(abi_root.abi.functions.len(), 1); - let function = &abi_root.abi.functions[0]; + assert_eq!(abi_root.body.functions.len(), 1); + let function = &abi_root.body.functions[0]; assert_eq!(function.params.len(), 5); let i8_schema = BorshSchemaContainer { declaration: "i8".to_string(), @@ -85,8 +83,8 @@ fn test_borsh_schema_numeric_primitives_unsigned() -> anyhow::Result<()> { ) {} }; - assert_eq!(abi_root.abi.functions.len(), 1); - let function = &abi_root.abi.functions[0]; + assert_eq!(abi_root.body.functions.len(), 1); + let function = &abi_root.body.functions[0]; assert_eq!(function.params.len(), 5); let u8_schema = BorshSchemaContainer { declaration: "u8".to_string(), @@ -129,8 +127,8 @@ fn test_borsh_schema_numeric_primitives_float() -> anyhow::Result<()> { pub fn foo(&self, #[serializer(borsh)] a: f32, #[serializer(borsh)] b: f64) {} }; - assert_eq!(abi_root.abi.functions.len(), 1); - let function = &abi_root.abi.functions[0]; + assert_eq!(abi_root.body.functions.len(), 1); + let function = &abi_root.body.functions[0]; assert_eq!(function.params.len(), 2); let f32_schema = BorshSchemaContainer { declaration: "f32".to_string(), @@ -153,8 +151,8 @@ fn test_borsh_schema_string() -> anyhow::Result<()> { pub fn foo(&self, #[serializer(borsh)] a: String, #[serializer(borsh)] b: &str, #[serializer(borsh)] c: &'static str) {} }; - assert_eq!(abi_root.abi.functions.len(), 1); - let function = &abi_root.abi.functions[0]; + assert_eq!(abi_root.body.functions.len(), 1); + let function = &abi_root.body.functions[0]; assert_eq!(function.params.len(), 3); let string_schema = BorshSchemaContainer { declaration: "string".to_string(), @@ -174,8 +172,8 @@ fn test_borsh_schema_other_primitives() -> anyhow::Result<()> { pub fn foo(&self, #[serializer(borsh)] b: bool, #[serializer(borsh)] c: ()) {} }; - assert_eq!(abi_root.abi.functions.len(), 1); - let function = &abi_root.abi.functions[0]; + assert_eq!(abi_root.body.functions.len(), 1); + let function = &abi_root.body.functions[0]; assert_eq!(function.params.len(), 2); // char is unsupported by borsh spec // let char_schema = BorshSchemaContainer { @@ -207,8 +205,8 @@ fn test_borsh_schema_tuples() -> anyhow::Result<()> { ) {} }; - assert_eq!(abi_root.abi.functions.len(), 1); - let function = &abi_root.abi.functions[0]; + assert_eq!(abi_root.body.functions.len(), 1); + let function = &abi_root.body.functions[0]; assert_eq!(function.params.len(), 2); // Needs https://github.com/near/borsh-rs/pull/100 to come in first // let tuple1_schema = BorshSchemaContainer { @@ -251,8 +249,8 @@ fn test_borsh_schema_arrays() -> anyhow::Result<()> { ) {} }; - assert_eq!(abi_root.abi.functions.len(), 1); - let function = &abi_root.abi.functions[0]; + assert_eq!(abi_root.body.functions.len(), 1); + let function = &abi_root.body.functions[0]; assert_eq!(function.params.len(), 3); let array8_schema = BorshSchemaContainer { declaration: "Array".to_string(), @@ -316,8 +314,8 @@ fn test_borsh_schema_struct() -> anyhow::Result<()> { } }; - assert_eq!(abi_root.abi.functions.len(), 1); - let function = &abi_root.abi.functions[0]; + assert_eq!(abi_root.body.functions.len(), 1); + let function = &abi_root.body.functions[0]; assert_eq!(function.params.len(), 2); let pair_def_schema = BorshSchemaContainer { declaration: "Pair".to_string(), @@ -375,8 +373,8 @@ fn test_borsh_schema_enum() -> anyhow::Result<()> { } }; - assert_eq!(abi_root.abi.functions.len(), 1); - let function = &abi_root.abi.functions[0]; + assert_eq!(abi_root.body.functions.len(), 1); + let function = &abi_root.body.functions[0]; assert_eq!(function.params.len(), 2); let ip_addr_kind_def_schema = BorshSchemaContainer { declaration: "IpAddrKind".to_string(), @@ -470,8 +468,8 @@ fn test_borsh_schema_complex() -> anyhow::Result<()> { } }; - assert_eq!(abi_root.abi.functions.len(), 1); - let function = &abi_root.abi.functions[0]; + assert_eq!(abi_root.body.functions.len(), 1); + let function = &abi_root.body.functions[0]; assert_eq!(function.params.len(), 1); let ip_addr_def_schema = BorshSchemaContainer { declaration: "IpAddr".to_string(), diff --git a/integration-tests/tests/tests/callbacks.rs b/integration-tests/tests/tests/callbacks.rs index fba8fe58..e0515413 100644 --- a/integration-tests/tests/tests/callbacks.rs +++ b/integration-tests/tests/tests/callbacks.rs @@ -1,6 +1,6 @@ use cargo_near_integration_tests::generate_abi_fn; use function_name::named; -use near_sdk::__private::{AbiParameter, AbiType}; +use near_abi::{AbiParameter, AbiType}; use schemars::gen::SchemaGenerator; use std::fs; @@ -11,8 +11,8 @@ fn test_callbacks_unwrapped() -> anyhow::Result<()> { pub fn foo(&self, #[callback_unwrap] a: bool, #[callback_unwrap] b: u32) {} }; - assert_eq!(abi_root.abi.functions.len(), 1); - let function = &abi_root.abi.functions[0]; + assert_eq!(abi_root.body.functions.len(), 1); + let function = &abi_root.body.functions[0]; assert_eq!(function.params.len(), 0); assert_eq!(function.callbacks.len(), 2); let bool_schema = SchemaGenerator::default().subschema_for::(); @@ -44,8 +44,8 @@ fn test_callbacks_result() -> anyhow::Result<()> { ) {} }; - assert_eq!(abi_root.abi.functions.len(), 1); - let function = &abi_root.abi.functions[0]; + assert_eq!(abi_root.body.functions.len(), 1); + let function = &abi_root.body.functions[0]; assert_eq!(function.params.len(), 0); assert_eq!(function.callbacks.len(), 2); let string_schema = SchemaGenerator::default().subschema_for::(); @@ -77,8 +77,8 @@ fn test_callbacks_vec() -> anyhow::Result<()> { ) {} }; - assert_eq!(abi_root.abi.functions.len(), 1); - let function = &abi_root.abi.functions[0]; + assert_eq!(abi_root.body.functions.len(), 1); + let function = &abi_root.body.functions[0]; assert_eq!(function.params.len(), 0); assert_eq!(function.callbacks.len(), 1); let bool_schema = SchemaGenerator::default().subschema_for::(); @@ -113,8 +113,8 @@ fn test_callbacks_mixed_with_params() -> anyhow::Result<()> { ) {} }; - assert_eq!(abi_root.abi.functions.len(), 1); - let function = &abi_root.abi.functions[0]; + assert_eq!(abi_root.body.functions.len(), 1); + let function = &abi_root.body.functions[0]; assert_eq!(function.params.len(), 2); assert_eq!(function.callbacks.len(), 2); let bool_schema = SchemaGenerator::default().subschema_for::(); diff --git a/integration-tests/tests/tests/e2e.rs b/integration-tests/tests/tests/e2e.rs index ebbbb951..0b53fddc 100644 --- a/integration-tests/tests/tests/e2e.rs +++ b/integration-tests/tests/tests/e2e.rs @@ -1,6 +1,6 @@ use cargo_near_integration_tests::generate_abi_fn; use function_name::named; -use near_sdk::__private::{AbiFunction, AbiParameter, AbiType}; +use near_abi::{AbiFunction, AbiParameter, AbiType}; use schemars::gen::SchemaGenerator; use std::fs; @@ -13,8 +13,8 @@ fn test_simple_function() -> anyhow::Result<()> { } }; - assert_eq!(abi_root.abi.functions.len(), 1); - let function = &abi_root.abi.functions[0]; + assert_eq!(abi_root.body.functions.len(), 1); + let function = &abi_root.body.functions[0]; let u32_schema = SchemaGenerator::default().subschema_for::(); assert_eq!( function, diff --git a/integration-tests/tests/tests/json_schema.rs b/integration-tests/tests/tests/json_schema.rs index 6facff05..d6f0b193 100644 --- a/integration-tests/tests/tests/json_schema.rs +++ b/integration-tests/tests/tests/json_schema.rs @@ -1,6 +1,6 @@ use cargo_near_integration_tests::{generate_abi, generate_abi_fn}; use function_name::named; -use near_sdk::__private::{AbiParameter, AbiType}; +use near_abi::{AbiParameter, AbiType}; use schemars::schema::Schema; use std::fs; @@ -25,8 +25,8 @@ fn test_schema_numeric_primitives_signed() -> anyhow::Result<()> { pub fn foo(&self, a: i8, b: i16, c: i32, d: i64, e: i128, f: isize) {} }; - assert_eq!(abi_root.abi.functions.len(), 1); - let function = &abi_root.abi.functions[0]; + assert_eq!(abi_root.body.functions.len(), 1); + let function = &abi_root.body.functions[0]; assert_eq!(function.params.len(), 6); // `format` is an open-ended keyword so one can define their own custom formats. // See https://json-schema.org/draft/2020-12/json-schema-validation.html#name-custom-format-attributes. @@ -98,8 +98,8 @@ fn test_schema_numeric_primitives_unsigned() -> anyhow::Result<()> { pub fn foo(&self, a: u8, b: u16, c: u32, d: u64, e: u128, f: usize) {} }; - assert_eq!(abi_root.abi.functions.len(), 1); - let function = &abi_root.abi.functions[0]; + assert_eq!(abi_root.body.functions.len(), 1); + let function = &abi_root.body.functions[0]; assert_eq!(function.params.len(), 6); // `format` is an open-ended keyword so one can define their own custom formats. // See https://json-schema.org/draft/2020-12/json-schema-validation.html#name-custom-format-attributes. @@ -177,8 +177,8 @@ fn test_schema_numeric_primitives_float() -> anyhow::Result<()> { pub fn foo(&self, a: f32, b: f64) {} }; - assert_eq!(abi_root.abi.functions.len(), 1); - let function = &abi_root.abi.functions[0]; + assert_eq!(abi_root.body.functions.len(), 1); + let function = &abi_root.body.functions[0]; assert_eq!(function.params.len(), 2); // `format` is an open-ended keyword so one can define their own custom formats. // See https://json-schema.org/draft/2020-12/json-schema-validation.html#name-custom-format-attributes. @@ -214,8 +214,8 @@ fn test_schema_string() -> anyhow::Result<()> { pub fn foo(&self, a: String, b: &str, c: &'static str) {} }; - assert_eq!(abi_root.abi.functions.len(), 1); - let function = &abi_root.abi.functions[0]; + assert_eq!(abi_root.body.functions.len(), 1); + let function = &abi_root.body.functions[0]; assert_eq!(function.params.len(), 3); let string_schema: Schema = serde_json::from_str( r#" @@ -238,8 +238,8 @@ fn test_schema_other_primitives() -> anyhow::Result<()> { pub fn foo(&self, a: char, b: bool, c: ()) {} }; - assert_eq!(abi_root.abi.functions.len(), 1); - let function = &abi_root.abi.functions[0]; + assert_eq!(abi_root.body.functions.len(), 1); + let function = &abi_root.body.functions[0]; assert_eq!(function.params.len(), 3); let char_schema: Schema = serde_json::from_str( r#" @@ -278,8 +278,8 @@ fn test_schema_tuples() -> anyhow::Result<()> { pub fn foo(&self, a: (bool,), b: (bool, bool), c: (bool, bool, bool)) {} }; - assert_eq!(abi_root.abi.functions.len(), 1); - let function = &abi_root.abi.functions[0]; + assert_eq!(abi_root.body.functions.len(), 1); + let function = &abi_root.body.functions[0]; assert_eq!(function.params.len(), 3); let tuple1_schema: Schema = serde_json::from_str( r#" @@ -346,8 +346,8 @@ fn test_schema_arrays() -> anyhow::Result<()> { pub fn foo(&self, a: [bool; 8], b: [bool; 16], c: &[bool]) {} }; - assert_eq!(abi_root.abi.functions.len(), 1); - let function = &abi_root.abi.functions[0]; + assert_eq!(abi_root.body.functions.len(), 1); + let function = &abi_root.body.functions[0]; assert_eq!(function.params.len(), 3); let array8_schema: Schema = serde_json::from_str( r#" @@ -418,8 +418,8 @@ fn test_schema_struct() -> anyhow::Result<()> { } }; - assert_eq!(abi_root.abi.functions.len(), 1); - let function = &abi_root.abi.functions[0]; + assert_eq!(abi_root.body.functions.len(), 1); + let function = &abi_root.body.functions[0]; assert_eq!(function.params.len(), 2); let pair_def_schema: Schema = serde_json::from_str( r##" @@ -484,9 +484,9 @@ fn test_schema_struct() -> anyhow::Result<()> { } "#, )?; - assert_eq!(abi_root.abi.root_schema.definitions["Pair"], pair_schema); + assert_eq!(abi_root.body.root_schema.definitions["Pair"], pair_schema); assert_eq!( - abi_root.abi.root_schema.definitions["PairNamed"], + abi_root.body.root_schema.definitions["PairNamed"], pair_named_schema ); @@ -524,8 +524,8 @@ fn test_schema_enum() -> anyhow::Result<()> { } }; - assert_eq!(abi_root.abi.functions.len(), 1); - let function = &abi_root.abi.functions[0]; + assert_eq!(abi_root.body.functions.len(), 1); + let function = &abi_root.body.functions[0]; assert_eq!(function.params.len(), 2); let ip_addr_kind_def_schema: Schema = serde_json::from_str( r##" @@ -612,11 +612,11 @@ fn test_schema_enum() -> anyhow::Result<()> { "#, )?; assert_eq!( - abi_root.abi.root_schema.definitions["IpAddrKind"], + abi_root.body.root_schema.definitions["IpAddrKind"], ip_addr_kind_schema ); assert_eq!( - abi_root.abi.root_schema.definitions["IpAddr"], + abi_root.body.root_schema.definitions["IpAddr"], ip_addr_schema ); @@ -654,8 +654,8 @@ fn test_schema_complex() -> anyhow::Result<()> { } }; - assert_eq!(abi_root.abi.functions.len(), 1); - let function = &abi_root.abi.functions[0]; + assert_eq!(abi_root.body.functions.len(), 1); + let function = &abi_root.body.functions[0]; assert_eq!(function.params.len(), 2); let ip_addr_kind_def_schema: Schema = serde_json::from_str( r##" @@ -705,11 +705,11 @@ fn test_schema_complex() -> anyhow::Result<()> { "##, )?; assert_eq!( - abi_root.abi.root_schema.definitions["IpAddrKind"], + abi_root.body.root_schema.definitions["IpAddrKind"], ip_addr_kind_schema ); assert_eq!( - abi_root.abi.root_schema.definitions["IpAddr"], + abi_root.body.root_schema.definitions["IpAddr"], ip_addr_schema ); diff --git a/integration-tests/tests/tests/modifiers.rs b/integration-tests/tests/tests/modifiers.rs index 3a48353f..d4ce75fe 100644 --- a/integration-tests/tests/tests/modifiers.rs +++ b/integration-tests/tests/tests/modifiers.rs @@ -11,8 +11,8 @@ fn test_view_function() -> anyhow::Result<()> { } }; - assert_eq!(abi_root.abi.functions.len(), 1); - let function = &abi_root.abi.functions[0]; + assert_eq!(abi_root.body.functions.len(), 1); + let function = &abi_root.body.functions[0]; assert!(function.is_view); assert!(!function.is_init); assert!(!function.is_payable); @@ -30,8 +30,8 @@ fn test_call_function() -> anyhow::Result<()> { } }; - assert_eq!(abi_root.abi.functions.len(), 1); - let function = &abi_root.abi.functions[0]; + assert_eq!(abi_root.body.functions.len(), 1); + let function = &abi_root.body.functions[0]; assert!(!function.is_view); Ok(()) @@ -47,8 +47,8 @@ fn test_init_function() -> anyhow::Result<()> { } }; - assert_eq!(abi_root.abi.functions.len(), 1); - let function = &abi_root.abi.functions[0]; + assert_eq!(abi_root.body.functions.len(), 1); + let function = &abi_root.body.functions[0]; assert!(function.is_init); assert!(function.result.is_none()); @@ -65,8 +65,8 @@ fn test_payable_function() -> anyhow::Result<()> { } }; - assert_eq!(abi_root.abi.functions.len(), 1); - let function = &abi_root.abi.functions[0]; + assert_eq!(abi_root.body.functions.len(), 1); + let function = &abi_root.body.functions[0]; assert!(function.is_payable); Ok(()) @@ -82,8 +82,8 @@ fn test_private_function() -> anyhow::Result<()> { } }; - assert_eq!(abi_root.abi.functions.len(), 1); - let function = &abi_root.abi.functions[0]; + assert_eq!(abi_root.body.functions.len(), 1); + let function = &abi_root.body.functions[0]; assert!(function.is_private); Ok(()) diff --git a/integration-tests/tests/tests/result.rs b/integration-tests/tests/tests/result.rs index 3da922e3..bc8e8e2f 100644 --- a/integration-tests/tests/tests/result.rs +++ b/integration-tests/tests/tests/result.rs @@ -1,6 +1,6 @@ use cargo_near_integration_tests::generate_abi_fn; use function_name::named; -use near_sdk::__private::AbiType; +use near_abi::AbiType; use schemars::gen::SchemaGenerator; use std::fs; @@ -11,8 +11,8 @@ fn test_result_default() -> anyhow::Result<()> { pub fn foo(&self) {} }; - assert_eq!(abi_root.abi.functions.len(), 1); - let function = &abi_root.abi.functions[0]; + assert_eq!(abi_root.body.functions.len(), 1); + let function = &abi_root.body.functions[0]; assert!(function.result.is_none()); Ok(()) @@ -27,8 +27,8 @@ fn test_result_type() -> anyhow::Result<()> { } }; - assert_eq!(abi_root.abi.functions.len(), 1); - let function = &abi_root.abi.functions[0]; + assert_eq!(abi_root.body.functions.len(), 1); + let function = &abi_root.body.functions[0]; let u32_schema = SchemaGenerator::default().subschema_for::(); assert_eq!( function.result, @@ -50,8 +50,8 @@ fn test_result_handle_result() -> anyhow::Result<()> { } }; - assert_eq!(abi_root.abi.functions.len(), 1); - let function = &abi_root.abi.functions[0]; + assert_eq!(abi_root.body.functions.len(), 1); + let function = &abi_root.body.functions[0]; let u32_schema = SchemaGenerator::default().subschema_for::(); assert_eq!( function.result,