Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: use near-abi 0.3.0 #954

Merged
merged 5 commits into from
Nov 4, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/adder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ workspaces = "0.5.0"
serde_json = "1.0"
tokio = { version = "1.14", features = ["full"] }
anyhow = "1.0"
near-abi = { version = "0.3.0", features = ["__chunked-entries"] }
near-abi = "0.3.0"
zstd = "0.11"

[profile.release]
Expand Down
12 changes: 6 additions & 6 deletions examples/adder/res/adder_abi.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
{
"schema_version": "0.2.0",
"schema_version": "0.3.0",
"metadata": {
"name": "adder",
"version": "0.1.0",
"authors": [
"Near Inc <[email protected]>"
],
"build": {
"compiler": "rustc 1.61.0",
"compiler": "rustc 1.64.0",
"builder": "cargo-near 0.2.0"
},
"wasm_hash": "B4XgA4rGVyaCWyDv2h1XAN5QMbtdJN1frRwoxELUMvDe"
"wasm_hash": "ExHz7YdyukYzaDX5RYKei6BWdpmvH7FWVqEvYC79y9BB"
},
"body": {
"functions": [
{
"name": "add",
"doc": " Adds two pairs point-wise.",
"is_view": true,
"kind": "view",
"params": {
"serialization_type": "json",
"args": [
Expand All @@ -44,7 +44,7 @@
},
{
"name": "add_borsh",
"is_view": true,
"kind": "view",
"params": {
"serialization_type": "borsh",
"args": [
Expand Down Expand Up @@ -95,7 +95,7 @@
},
{
"name": "add_callback",
"is_view": true,
"kind": "view",
"callbacks": [
{
"serialization_type": "json",
Expand Down
21 changes: 13 additions & 8 deletions examples/adder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ mod tests {
let abi_root =
serde_json::from_slice::<AbiRoot>(&zstd::decode_all(&res.result[..])?).unwrap();

assert_eq!(abi_root.schema_version, "0.1.0");
assert_eq!(abi_root.schema_version, "0.3.0");
assert_eq!(abi_root.metadata.name, Some("adder".to_string()));
assert_eq!(abi_root.metadata.version, Some("0.1.0".to_string()));
assert_eq!(
Expand All @@ -75,13 +75,18 @@ mod tests {

assert_eq!(add_function.name, "add".to_string());
assert_eq!(add_function.doc, Some(" Adds two pairs point-wise.".to_string()));
assert!(add_function.is_view);
assert!(!add_function.is_init);
assert!(!add_function.is_payable);
assert!(!add_function.is_private);
assert_eq!(add_function.params.len(), 2);
assert_eq!(add_function.params[0].name, "a".to_string());
assert_eq!(add_function.params[1].name, "b".to_string());
assert_eq!(add_function.kind, AbiFunctionKind::View);
assert_eq!(add_function.modifiers, vec![]);
match &add_function.params {
AbiParameters::Json { args } => {
assert_eq!(args.len(), 2);
assert_eq!(args[0].name, "a".to_string());
assert_eq!(args[1].name, "b".to_string());
}
AbiParameters::Borsh { .. } => {
assert!(false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it is not actually unreachable if the thing we are trying to test happens to have borsh serialization though

Copy link
Contributor

@miraclx miraclx Nov 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, but isn't that the point of the test? Asserting that it is JSON serialized and not borsh? (at least in this case)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, but unreacheable! to me is something you know (statically) will never be reached, but can't convince compiler to be the case. This test, on the other hand, depends on some external input (a wasm file) and tests its properties.

This is arguing very subtle semantics and honestly it feels like AbiParameters should just have json()? and borsh()? methods instead of this match/fail pattern.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fair, wasn't a strong opinion. I'm not sure if we're at the point where we need those helper methods, so we can proceed as-is. 👍🏽

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case, still seems like panic!() might be more readable?

}
}

Ok(())
}
Expand Down