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

use near-abi-rs #23

Merged
merged 17 commits into from
Aug 26, 2022
2 changes: 1 addition & 1 deletion cargo-near/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ schemars = "0.8"

[dependencies.near-abi]
git = "https://github.com/near/near-abi-rs"
rev = "4844ef4ff3e5cf3c3a8aa6565c3195a2339a345f"
rev = "983346e8ce2a8304645a92ba7735f9a6eacceda7"
features = ["__chunked-entries"]
austinabell marked this conversation as resolved.
Show resolved Hide resolved

[dev-dependencies]
Expand Down
4 changes: 2 additions & 2 deletions cargo-near/src/abi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ fn extract_metadata(crate_metadata: &CrateMetadata) -> near_abi::AbiMetadata {
}

fn strip_docs(abi_root: &mut near_abi::AbiRoot) {
for function in &mut abi_root.abi.functions {
for function in &mut abi_root.body.functions {
function.doc = None;
}
for schema in &mut abi_root.abi.root_schema.definitions.values_mut() {
for schema in &mut abi_root.body.root_schema.definitions.values_mut() {
if let schemars::schema::Schema::Object(schemars::schema::SchemaObject {
metadata: Some(metadata),
..
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ quote = "1.0"

[dependencies.near-abi]
git = "https://github.com/near/near-abi-rs"
rev = "4844ef4ff3e5cf3c3a8aa6565c3195a2339a345f"
rev = "983346e8ce2a8304645a92ba7735f9a6eacceda7"
2 changes: 1 addition & 1 deletion integration-tests/templates/_Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ schemars = "0.8"

[dependencies.near-sdk]
git = "https://github.com/near/near-sdk-rs.git"
rev = "0d4a4ac3f7bf759f10430b6ecf0864d87114798d"
rev = "5054d1180f6a1e2358f96498c0cb4c89c0a2c3cd"
features = ["abi"]

[workspace]
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/templates/_Cargo_no_abi_feature.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ schemars = "0.8"

[dependencies.near-sdk]
git = "https://github.com/near/near-sdk-rs.git"
rev = "0d4a4ac3f7bf759f10430b6ecf0864d87114798d"
rev = "5054d1180f6a1e2358f96498c0cb4c89c0a2c3cd"

[workspace]
members = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ schemars = "0.8"

[dependencies.near-sdk]
git = "https://github.com/near/near-sdk-rs.git"
rev = "0d4a4ac3f7bf759f10430b6ecf0864d87114798d"
rev = "5054d1180f6a1e2358f96498c0cb4c89c0a2c3cd"
features = ["abi"]

[workspace]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ schemars = "0.8"

[dependencies.near-sdk]
git = "https://github.com/near/near-sdk-rs.git"
rev = "0d4a4ac3f7bf759f10430b6ecf0864d87114798d"
rev = "5054d1180f6a1e2358f96498c0cb4c89c0a2c3cd"
features = ["abi", "unstable"]

[workspace]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ schemars = "0.8"

[dependencies.near-sdk]
git = "https://github.com/near/near-sdk-rs.git"
rev = "0d4a4ac3f7bf759f10430b6ecf0864d87114798d"
rev = "5054d1180f6a1e2358f96498c0cb4c89c0a2c3cd"
default-features = false
features = ["abi"]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ serde = { version = "1", features = ["derive"] }
schemars = "0.8"

[patch.crates-io]
near-sdk = { git = "https://github.com/near/near-sdk-rs.git", rev = "0d4a4ac3f7bf759f10430b6ecf0864d87114798d" }
near-sdk = { git = "https://github.com/near/near-sdk-rs.git", rev = "5054d1180f6a1e2358f96498c0cb4c89c0a2c3cd" }

[workspace]
members = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ schemars = "0.8"

[target.'cfg(windows)'.dependencies.near-sdk]
git = "https://github.com/near/near-sdk-rs.git"
rev = "0d4a4ac3f7bf759f10430b6ecf0864d87114798d"
rev = "5054d1180f6a1e2358f96498c0cb4c89c0a2c3cd"
features = ["abi"]

[target.'cfg(unix)'.dependencies.near-sdk]
git = "https://github.com/near/near-sdk-rs.git"
rev = "0d4a4ac3f7bf759f10430b6ecf0864d87114798d"
rev = "5054d1180f6a1e2358f96498c0cb4c89c0a2c3cd"
features = ["abi"]

[workspace]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ schemars = "0.8"
[dependencies.near]
package = "near-sdk"
git = "https://github.com/near/near-sdk-rs.git"
rev = "0d4a4ac3f7bf759f10430b6ecf0864d87114798d"
rev = "5054d1180f6a1e2358f96498c0cb4c89c0a2c3cd"
features = ["abi"]

[workspace]
Expand Down
38 changes: 19 additions & 19 deletions integration-tests/tests/cargo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fn clone_git_repo(version: &str) -> anyhow::Result<TempDir> {
#[test]
#[named]
fn test_dependency_local_path() -> anyhow::Result<()> {
let near_sdk_dir = clone_git_repo("0d4a4ac3f7bf759f10430b6ecf0864d87114798d")?;
let near_sdk_dir = clone_git_repo("5054d1180f6a1e2358f96498c0cb4c89c0a2c3cd")?;
let near_sdk_dep_path = near_sdk_dir.path().join("near-sdk");

// near-sdk = { path = "::path::", features = ["abi"] }
Expand All @@ -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(())
Expand All @@ -40,7 +40,7 @@ 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("0d4a4ac3f7bf759f10430b6ecf0864d87114798d")?;
let near_sdk_dir = clone_git_repo("5054d1180f6a1e2358f96498c0cb4c89c0a2c3cd")?;
let near_sdk_dep_path = near_sdk_dir.path().join("near-sdk");

// near-sdk = { path = "::path::", version = "4.1.0-pre.1", features = ["abi"] }
Expand All @@ -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(())
Expand All @@ -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(())
Expand All @@ -87,8 +87,8 @@ fn test_dependency_no_default_features() -> 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(())
Expand All @@ -104,8 +104,8 @@ fn test_dependency_multiple_features() -> 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(())
Expand All @@ -127,8 +127,8 @@ fn test_dependency_platform_specific() -> 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(())
Expand Down Expand Up @@ -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(())
Expand All @@ -172,15 +172,15 @@ fn test_dependency_patch() -> anyhow::Result<()> {
// near-sdk = { version = "4.1.0-pre.1", features = ["abi"] }
//
// [patch.crates-io]
// near-sdk = { git = "https://github.com/near/near-sdk-rs.git", rev = "0d4a4ac3f7bf759f10430b6ecf0864d87114798d" }
// near-sdk = { git = "https://github.com/near/near-sdk-rs.git", rev = "5054d1180f6a1e2358f96498c0cb4c89c0a2c3cd" }
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(())
Expand Down
40 changes: 20 additions & 20 deletions integration-tests/tests/tests/borsh_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,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(),
Expand Down Expand Up @@ -83,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(),
Expand Down Expand Up @@ -127,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(),
Expand All @@ -151,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(),
Expand All @@ -172,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 {
Expand Down Expand Up @@ -205,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 {
Expand Down Expand Up @@ -249,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<bool, 8>".to_string(),
Expand Down Expand Up @@ -314,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(),
Expand Down Expand Up @@ -373,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(),
Expand Down Expand Up @@ -468,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(),
Expand Down
16 changes: 8 additions & 8 deletions integration-tests/tests/tests/callbacks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<bool>();
Expand Down Expand Up @@ -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::<String>();
Expand Down Expand Up @@ -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::<bool>();
Expand Down Expand Up @@ -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::<bool>();
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/tests/tests/e2e.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<u32>();
assert_eq!(
function,
Expand Down
Loading