From 3694f60743f17f251a24774c2a12a6dd0f138e31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?dj8yf0=CE=BCl?= Date: Mon, 9 Oct 2023 10:27:57 +0300 Subject: [PATCH] chore: update `near-sdk`, `near-abi`, `borsh` version --- Cargo.lock | 64 ++++- cargo-near/Cargo.toml | 2 +- integration-tests/Cargo.toml | 4 +- integration-tests/src/lib.rs | 16 +- integration-tests/templates/_Cargo.toml | 3 +- integration-tests/tests/abi/borsh_schema.rs | 248 +++++++++----------- 6 files changed, 188 insertions(+), 149 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 54ad25e3..7125e094 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -428,6 +428,16 @@ dependencies = [ "hashbrown 0.13.2", ] +[[package]] +name = "borsh" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e6cb63579996213e822f6d828b0a47e1d23b1e8708f52d18a6b1af5670dd207" +dependencies = [ + "borsh-derive 1.0.0", + "cfg_aliases", +] + [[package]] name = "borsh-derive" version = "0.9.3" @@ -454,6 +464,20 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "borsh-derive" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35b4db62e0515621636e47f425d78a40bdea94c2d23713428fb12194cf5459a4" +dependencies = [ + "once_cell", + "proc-macro-crate 1.3.1", + "proc-macro2", + "quote", + "syn 2.0.37", + "syn_derive", +] + [[package]] name = "borsh-derive-internal" version = "0.9.3" @@ -611,7 +635,7 @@ dependencies = [ "env_logger", "libloading", "log", - "near-abi", + "near-abi 0.3.0", "rustc_version", "schemars", "serde_json", @@ -639,7 +663,7 @@ dependencies = [ "interactive-clap-derive", "libloading", "log", - "near-abi", + "near-abi 0.4.0", "near-cli-rs", "rustc_version", "schemars", @@ -656,7 +680,7 @@ dependencies = [ name = "cargo-near-integration-tests" version = "0.1.0" dependencies = [ - "borsh 0.9.3", + "borsh 1.0.0", "camino", "cargo-near 0.4.0", "clap 4.4.6", @@ -665,7 +689,7 @@ dependencies = [ "function_name", "git2", "minifier", - "near-abi", + "near-abi 0.4.0", "near-workspaces", "prettyplease", "proc-macro2", @@ -744,6 +768,12 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "cfg_aliases" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e" + [[package]] name = "chrono" version = "0.4.31" @@ -2461,6 +2491,18 @@ dependencies = [ "serde", ] +[[package]] +name = "near-abi" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5bd176820187cfb134a5147330fe803357bf5dab9a14f891d1702beb3d471dfb" +dependencies = [ + "borsh 1.0.0", + "schemars", + "semver", + "serde", +] + [[package]] name = "near-account-id" version = "0.14.0" @@ -2883,7 +2925,7 @@ dependencies = [ "base64 0.13.1", "borsh 0.9.3", "bs58 0.4.0", - "near-abi", + "near-abi 0.3.0", "near-crypto 0.14.0", "near-primitives 0.14.0", "near-primitives-core 0.14.0", @@ -4536,6 +4578,18 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "syn_derive" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1329189c02ff984e9736652b1631330da25eaa6bc639089ed4915d25446cbe7b" +dependencies = [ + "proc-macro-error", + "proc-macro2", + "quote", + "syn 2.0.37", +] + [[package]] name = "tap" version = "1.0.1" diff --git a/cargo-near/Cargo.toml b/cargo-near/Cargo.toml index b26c3307..0a52edef 100644 --- a/cargo-near/Cargo.toml +++ b/cargo-near/Cargo.toml @@ -28,7 +28,7 @@ serde_json = "1.0" sha2 = "0.10" symbolic-debuginfo = "8.8" schemars = "0.8" -near-abi = { version = "0.3.0", features = ["__chunked-entries"] } +near-abi = { version = "0.4.0", features = ["__chunked-entries"] } libloading = "0.7.3" zstd = "0.11" atty = "0.2.14" diff --git a/integration-tests/Cargo.toml b/integration-tests/Cargo.toml index fcf97a7f..98ee9060 100644 --- a/integration-tests/Cargo.toml +++ b/integration-tests/Cargo.toml @@ -6,10 +6,10 @@ publish = false [dependencies] const_format = "0.2" -near-abi = "0.3.0" +near-abi = "0.4.0" [dev-dependencies] -borsh = "0.9" +borsh = { version = "1.0.0", features = ["derive", "unstable__schema"]} camino = "1.1.1" cargo-near = { path = "../cargo-near" } color-eyre = "0.6" diff --git a/integration-tests/src/lib.rs b/integration-tests/src/lib.rs index cd98e3f2..e5032fe3 100644 --- a/integration-tests/src/lib.rs +++ b/integration-tests/src/lib.rs @@ -1,8 +1,12 @@ use const_format::formatcp; -pub const SDK_VERSION: &str = "4.1.0"; -pub const SDK_GIT_REV: &str = "10b0dea3b1a214d789cc90314aa814a4181610ad"; +// NOTE: this version is version of near-sdk in master branch from 5.x.x development cycle +pub const SDK_VERSION: &str = "4.1.1"; +pub const SDK_GIT_REV: &str = "15bfb0e6d54ff386478d137074027c2cb863df03"; pub const SDK_VERSION_TOML: &str = formatcp!(r#"version = "{SDK_VERSION}""#); +pub const SDK_GIT_VERSION_TOML_COMMA: &str = formatcp!( + r#"version = "{SDK_VERSION}", git = "https://github.com/near/near-sdk-rs.git", rev = "{SDK_GIT_REV}""# +); pub const SDK_GIT_VERSION_TOML_TABLE: &str = formatcp!( r#" version = "{SDK_VERSION}" @@ -27,6 +31,7 @@ macro_rules! invoke_cargo_near { cargo_vars.insert("sdk-version", $crate::SDK_VERSION); cargo_vars.insert("sdk-git-rev", $crate::SDK_GIT_REV); cargo_vars.insert("sdk-version-toml", $crate::SDK_VERSION_TOML); + cargo_vars.insert("sdk-git-version-toml-comma", $crate::SDK_GIT_VERSION_TOML_COMMA); cargo_vars.insert("sdk-git-version-toml-table", $crate::SDK_GIT_VERSION_TOML_TABLE); cargo_vars.insert("name", function_name!()); for (k, v) in cargo_vars { @@ -109,15 +114,12 @@ macro_rules! generate_abi_fn_with { $crate::generate_abi_with! { $(Cargo: $cargo_path;)? $(Vars: $cargo_vars;)? $(Opts: $cli_opts;)? Code: - // fixme! remove after borsh fixes trait qualification - // fixme! https://github.com/near/borsh-rs/issues/112 - use near_sdk::borsh::BorshSchema; - - use near_sdk::borsh::{self, BorshDeserialize, BorshSerialize}; + use near_sdk::borsh::{BorshDeserialize, BorshSerialize}; use near_sdk::near_bindgen; #[near_bindgen] #[derive(Default, BorshDeserialize, BorshSerialize)] + #[borsh(crate = "near_sdk::borsh")] pub struct Contract {} #[near_bindgen] diff --git a/integration-tests/templates/_Cargo.toml b/integration-tests/templates/_Cargo.toml index 19ba358f..bd7efb2f 100644 --- a/integration-tests/templates/_Cargo.toml +++ b/integration-tests/templates/_Cargo.toml @@ -7,7 +7,8 @@ edition = "2021" crate-type = ["cdylib"] [dependencies] -near-sdk = { features = ["unstable"], ::sdk-version-toml:: } +# near-sdk = { features = ["unstable"], ::sdk-version-toml:: } +near-sdk = { features = ["unstable"], ::sdk-git-version-toml-comma:: } serde = { version = "1", features = ["derive"] } schemars = "0.8" diff --git a/integration-tests/tests/abi/borsh_schema.rs b/integration-tests/tests/abi/borsh_schema.rs index 4648dc79..fa181e87 100644 --- a/integration-tests/tests/abi/borsh_schema.rs +++ b/integration-tests/tests/abi/borsh_schema.rs @@ -2,7 +2,7 @@ use crate::util::AsBorshSchema; use borsh::schema::{BorshSchemaContainer, Definition, Fields}; use cargo_near_integration_tests::{generate_abi, generate_abi_fn}; use function_name::named; -use std::collections::HashMap; +use std::collections::BTreeMap; #[test] #[named] @@ -22,30 +22,30 @@ fn test_borsh_schema_numeric_primitives_signed() -> cargo_near::CliResult { let function = &abi_root.body.functions[0]; let params = function.params.borsh_schemas()?; assert_eq!(params.len(), 5); - let i8_schema = BorshSchemaContainer { - declaration: "i8".to_string(), - definitions: HashMap::new(), - }; - let i16_schema = BorshSchemaContainer { - declaration: "i16".to_string(), - definitions: HashMap::new(), - }; - let i32_schema = BorshSchemaContainer { - declaration: "i32".to_string(), - definitions: HashMap::new(), - }; - let i64_schema = BorshSchemaContainer { - declaration: "i64".to_string(), - definitions: HashMap::new(), - }; - let i128_schema = BorshSchemaContainer { - declaration: "i128".to_string(), - definitions: HashMap::new(), - }; + let i8_schema = BorshSchemaContainer::new( + "i8".to_string(), + BTreeMap::from([("i8".to_string(), Definition::Primitive(1))]), + ); + let i16_schema = BorshSchemaContainer::new( + "i16".to_string(), + BTreeMap::from([("i16".to_string(), Definition::Primitive(2))]), + ); + let i32_schema = BorshSchemaContainer::new( + "i32".to_string(), + BTreeMap::from([("i32".to_string(), Definition::Primitive(4))]), + ); + let i64_schema = BorshSchemaContainer::new( + "i64".to_string(), + BTreeMap::from([("i64".to_string(), Definition::Primitive(8))]), + ); + let i128_schema = BorshSchemaContainer::new( + "i128".to_string(), + BTreeMap::from([("i128".to_string(), Definition::Primitive(16))]), + ); // borsh-rs does not support isize schema; need https://github.com/near/borsh-rs/pull/99 to come in first // let isize_schema = BorshSchemaContainer { // declaration: "i64".to_string(), - // definitions: HashMap::new(), + // definitions: BTreeMap::new(), // }; assert_eq!(¶ms[0].type_schema, &i8_schema); assert_eq!(¶ms[1].type_schema, &i16_schema); @@ -74,30 +74,15 @@ fn test_borsh_schema_numeric_primitives_unsigned() -> cargo_near::CliResult { let function = &abi_root.body.functions[0]; let params = function.params.borsh_schemas()?; assert_eq!(params.len(), 5); - let u8_schema = BorshSchemaContainer { - declaration: "u8".to_string(), - definitions: HashMap::new(), - }; - let u16_schema = BorshSchemaContainer { - declaration: "u16".to_string(), - definitions: HashMap::new(), - }; - let u32_schema = BorshSchemaContainer { - declaration: "u32".to_string(), - definitions: HashMap::new(), - }; - let u64_schema = BorshSchemaContainer { - declaration: "u64".to_string(), - definitions: HashMap::new(), - }; - let u128_schema = BorshSchemaContainer { - declaration: "u128".to_string(), - definitions: HashMap::new(), - }; + let u8_schema = BorshSchemaContainer::new("u8".to_string(), BTreeMap::new()); + let u16_schema = BorshSchemaContainer::new("u16".to_string(), BTreeMap::new()); + let u32_schema = BorshSchemaContainer::new("u32".to_string(), BTreeMap::new()); + let u64_schema = BorshSchemaContainer::new("u64".to_string(), BTreeMap::new()); + let u128_schema = BorshSchemaContainer::new("u128".to_string(), BTreeMap::new()); // borsh-rs does not support usize schema; need https://github.com/near/borsh-rs/pull/99 to come in first // let usize_schema = BorshSchemaContainer { // declaration: "u64".to_string(), - // definitions: HashMap::new(), + // definitions: BTreeMap::new(), // }; assert_eq!(¶ms[0].type_schema, &u8_schema); assert_eq!(¶ms[1].type_schema, &u16_schema); @@ -119,14 +104,8 @@ fn test_borsh_schema_numeric_primitives_float() -> cargo_near::CliResult { let function = &abi_root.body.functions[0]; let params = function.params.borsh_schemas()?; assert_eq!(params.len(), 2); - let f32_schema = BorshSchemaContainer { - declaration: "f32".to_string(), - definitions: HashMap::new(), - }; - let f64_schema = BorshSchemaContainer { - declaration: "f64".to_string(), - definitions: HashMap::new(), - }; + let f32_schema = BorshSchemaContainer::new("f32".to_string(), BTreeMap::new()); + let f64_schema = BorshSchemaContainer::new("f64".to_string(), BTreeMap::new()); assert_eq!(¶ms[0].type_schema, &f32_schema); assert_eq!(¶ms[1].type_schema, &f64_schema); @@ -144,10 +123,7 @@ fn test_borsh_schema_string() -> cargo_near::CliResult { let function = &abi_root.body.functions[0]; let params = function.params.borsh_schemas()?; assert_eq!(params.len(), 3); - let string_schema = BorshSchemaContainer { - declaration: "string".to_string(), - definitions: HashMap::new(), - }; + let string_schema = BorshSchemaContainer::new("string".to_string(), BTreeMap::new()); assert_eq!(¶ms[0].type_schema, &string_schema); assert_eq!(¶ms[1].type_schema, &string_schema); assert_eq!(¶ms[2].type_schema, &string_schema); @@ -169,16 +145,10 @@ fn test_borsh_schema_other_primitives() -> cargo_near::CliResult { // char is unsupported by borsh spec // let char_schema = BorshSchemaContainer { // declaration: "char".to_string(), - // definitions: HashMap::new(), + // definitions: BTreeMap::new(), // }; - let bool_schema = BorshSchemaContainer { - declaration: "bool".to_string(), - definitions: HashMap::new(), - }; - let unit_schema = BorshSchemaContainer { - declaration: "nil".to_string(), - definitions: HashMap::new(), - }; + let bool_schema = BorshSchemaContainer::new("bool".to_string(), BTreeMap::new()); + let unit_schema = BorshSchemaContainer::new("nil".to_string(), BTreeMap::new()); assert_eq!(¶ms[0].type_schema, &bool_schema); assert_eq!(¶ms[1].type_schema, &unit_schema); @@ -203,26 +173,26 @@ fn test_borsh_schema_tuples() -> cargo_near::CliResult { // Needs https://github.com/near/borsh-rs/pull/100 to come in first // let tuple1_schema = BorshSchemaContainer { // declaration: "Tuple".to_string(), - // definitions: HashMap::new(), + // definitions: BTreeMap::new(), // }; - let tuple2_schema = BorshSchemaContainer { - declaration: "Tuple".to_string(), - definitions: HashMap::from([( + let tuple2_schema = BorshSchemaContainer::new( + "Tuple".to_string(), + BTreeMap::from([( "Tuple".to_string(), Definition::Tuple { elements: vec!["bool".to_string(), "bool".to_string()], }, )]), - }; - let tuple3_schema = BorshSchemaContainer { - declaration: "Tuple".to_string(), - definitions: HashMap::from([( + ); + let tuple3_schema = BorshSchemaContainer::new( + "Tuple".to_string(), + BTreeMap::from([( "Tuple".to_string(), Definition::Tuple { elements: vec!["bool".to_string(), "bool".to_string(), "bool".to_string()], }, )]), - }; + ); assert_eq!(¶ms[0].type_schema, &tuple2_schema); assert_eq!(¶ms[1].type_schema, &tuple3_schema); @@ -245,35 +215,39 @@ fn test_borsh_schema_arrays() -> cargo_near::CliResult { let function = &abi_root.body.functions[0]; let params = function.params.borsh_schemas()?; assert_eq!(params.len(), 3); - let array8_schema = BorshSchemaContainer { - declaration: "Array".to_string(), - definitions: HashMap::from([( + let array8_schema = BorshSchemaContainer::new( + "Array".to_string(), + BTreeMap::from([( "Array".to_string(), - Definition::Array { - length: 8, + Definition::Sequence { + length_width: Definition::ARRAY_LENGTH_WIDTH, + length_range: 8..=8, elements: "bool".to_string(), }, )]), - }; - let array16_schema = BorshSchemaContainer { - declaration: "Array".to_string(), - definitions: HashMap::from([( + ); + let array16_schema = BorshSchemaContainer::new( + "Array".to_string(), + BTreeMap::from([( "Array".to_string(), - Definition::Array { - length: 16, + Definition::Sequence { + length_width: Definition::ARRAY_LENGTH_WIDTH, + length_range: 16..=16, elements: "bool".to_string(), }, )]), - }; - let array_unlim_schema = BorshSchemaContainer { - declaration: "Vec".to_string(), - definitions: HashMap::from([( + ); + let array_unlim_schema = BorshSchemaContainer::new( + "Vec".to_string(), + BTreeMap::from([( "Vec".to_string(), Definition::Sequence { + length_width: Definition::DEFAULT_LENGTH_WIDTH, + length_range: Definition::DEFAULT_LENGTH_RANGE, elements: "bool".to_string(), }, )]), - }; + ); assert_eq!(¶ms[0].type_schema, &array8_schema); assert_eq!(¶ms[1].type_schema, &array16_schema); assert_eq!(¶ms[2].type_schema, &array_unlim_schema); @@ -285,19 +259,17 @@ fn test_borsh_schema_arrays() -> cargo_near::CliResult { #[named] fn test_borsh_schema_struct() -> cargo_near::CliResult { let abi_root = generate_abi! { - // fixme! remove after borsh fixes trait qualification - // fixme! https://github.com/near/borsh-rs/issues/112 - use near_sdk::borsh::BorshSchema; - - use near_sdk::borsh::{self, BorshDeserialize, BorshSerialize}; + use near_sdk::borsh::{BorshDeserialize, BorshSerialize}; use near_sdk::{near_bindgen, NearSchema}; #[derive(NearSchema, BorshSerialize, BorshDeserialize)] #[abi(borsh)] + #[borsh(crate = "near_sdk::borsh")] pub struct Pair(u32, u32); #[derive(NearSchema, BorshSerialize, BorshDeserialize)] #[abi(borsh)] + #[borsh(crate = "near_sdk::borsh")] pub struct PairNamed { first: u32, second: u32 @@ -305,6 +277,7 @@ fn test_borsh_schema_struct() -> cargo_near::CliResult { #[near_bindgen] #[derive(Default, BorshDeserialize, BorshSerialize)] + #[borsh(crate = "near_sdk::borsh")] pub struct Contract {} #[near_bindgen] @@ -317,27 +290,33 @@ fn test_borsh_schema_struct() -> cargo_near::CliResult { let function = &abi_root.body.functions[0]; let params = function.params.borsh_schemas()?; assert_eq!(params.len(), 2); - let pair_def_schema = BorshSchemaContainer { - declaration: "Pair".to_string(), - definitions: HashMap::from([( - "Pair".to_string(), - Definition::Struct { - fields: Fields::UnnamedFields(vec!["u32".to_string(), "u32".to_string()]), - }, - )]), - }; - let pair_named_def_schema = BorshSchemaContainer { - declaration: "PairNamed".to_string(), - definitions: HashMap::from([( - "PairNamed".to_string(), - Definition::Struct { - fields: Fields::NamedFields(vec![ - ("first".to_string(), "u32".to_string()), - ("second".to_string(), "u32".to_string()), - ]), - }, - )]), - }; + let pair_def_schema = BorshSchemaContainer::new( + "Pair".to_string(), + BTreeMap::from([ + ( + "Pair".to_string(), + Definition::Struct { + fields: Fields::UnnamedFields(vec!["u32".to_string(), "u32".to_string()]), + }, + ), + ("u32".to_string(), Definition::Primitive(4)), + ]), + ); + let pair_named_def_schema = BorshSchemaContainer::new( + "PairNamed".to_string(), + BTreeMap::from([ + ( + "PairNamed".to_string(), + Definition::Struct { + fields: Fields::NamedFields(vec![ + ("first".to_string(), "u32".to_string()), + ("second".to_string(), "u32".to_string()), + ]), + }, + ), + ("u32".to_string(), Definition::Primitive(4)), + ]), + ); assert_eq!(¶ms[0].type_schema, &pair_def_schema); assert_eq!(¶ms[1].type_schema, &pair_named_def_schema); @@ -383,15 +362,16 @@ fn test_borsh_schema_enum() -> cargo_near::CliResult { let function = &abi_root.body.functions[0]; let params = function.params.borsh_schemas()?; assert_eq!(params.len(), 2); - let ip_addr_kind_def_schema = BorshSchemaContainer { - declaration: "IpAddrKind".to_string(), - definitions: HashMap::from([ + let ip_addr_kind_def_schema = BorshSchemaContainer::new( + "IpAddrKind".to_string(), + BTreeMap::from([ ( "IpAddrKind".to_string(), Definition::Enum { + tag_width: 1, variants: vec![ - ("V4".to_string(), "IpAddrKindV4".to_string()), - ("V6".to_string(), "IpAddrKindV6".to_string()), + (0, "V4".to_string(), "IpAddrKindV4".to_string()), + (1, "V6".to_string(), "IpAddrKindV6".to_string()), ], }, ), @@ -408,16 +388,17 @@ fn test_borsh_schema_enum() -> cargo_near::CliResult { }, ), ]), - }; - let ip_addr_def_schema = BorshSchemaContainer { - declaration: "IpAddr".to_string(), - definitions: HashMap::from([ + ); + let ip_addr_def_schema = BorshSchemaContainer::new( + "IpAddr".to_string(), + BTreeMap::from([ ( "IpAddr".to_string(), Definition::Enum { + tag_width: 1, variants: vec![ - ("V4".to_string(), "IpAddrV4".to_string()), - ("V6".to_string(), "IpAddrV6".to_string()), + (0, "V4".to_string(), "IpAddrV4".to_string()), + (1, "V6".to_string(), "IpAddrV6".to_string()), ], }, ), @@ -439,7 +420,7 @@ fn test_borsh_schema_enum() -> cargo_near::CliResult { }, ), ]), - }; + ); assert_eq!(¶ms[0].type_schema, &ip_addr_kind_def_schema); assert_eq!(¶ms[1].type_schema, &ip_addr_def_schema); @@ -485,9 +466,9 @@ fn test_borsh_schema_complex() -> cargo_near::CliResult { let function = &abi_root.body.functions[0]; let params = function.params.borsh_schemas()?; assert_eq!(params.len(), 1); - let ip_addr_def_schema = BorshSchemaContainer { - declaration: "IpAddr".to_string(), - definitions: HashMap::from([ + let ip_addr_def_schema = BorshSchemaContainer::new( + "IpAddr".to_string(), + BTreeMap::from([ ( "IpAddr".to_string(), Definition::Struct { @@ -500,9 +481,10 @@ fn test_borsh_schema_complex() -> cargo_near::CliResult { ( "IpAddrKind".to_string(), Definition::Enum { + tag_width: 1, variants: vec![ - ("V4".to_string(), "IpAddrKindV4".to_string()), - ("V6".to_string(), "IpAddrKindV6".to_string()), + (0, "V4".to_string(), "IpAddrKindV4".to_string()), + (1, "V6".to_string(), "IpAddrKindV6".to_string()), ], }, ), @@ -519,7 +501,7 @@ fn test_borsh_schema_complex() -> cargo_near::CliResult { }, ), ]), - }; + ); assert_eq!(¶ms[0].type_schema, &ip_addr_def_schema); Ok(())