Skip to content

Commit

Permalink
fixed compilation errors connected to the previous change of --doc ->…
Browse files Browse the repository at this point in the history
… --no-doc
  • Loading branch information
frol committed Feb 3, 2024
1 parent 9be9ef4 commit 0a7fdb0
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 143 deletions.
2 changes: 1 addition & 1 deletion cargo-near/src/commands/abi_command/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ pub fn run(args: super::AbiCommand) -> near_cli_rs::CliResult {
} else {
AbiFormat::Json
};
let contract_abi = generate_abi(&crate_metadata, args.doc, false, color)?;
let contract_abi = generate_abi(&crate_metadata, !args.no_doc, false, color)?;
let AbiResult { path } =
write_to_file(&contract_abi, &crate_metadata, format, AbiCompression::NoOp)?;

Expand Down
4 changes: 2 additions & 2 deletions cargo-near/src/commands/abi_command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub mod abi;
pub struct AbiCommand {
/// Include rustdocs in the ABI file
#[interactive_clap(long)]
pub doc: bool,
pub no_doc: bool,
/// Generate compact (minified) JSON
#[interactive_clap(long)]
pub compact_abi: bool,
Expand Down Expand Up @@ -34,7 +34,7 @@ impl AbiCommandlContext {
scope: &<AbiCommand as interactive_clap::ToInteractiveClapContextScope>::InteractiveClapContextScope,
) -> color_eyre::eyre::Result<Self> {
let args = AbiCommand {
doc: scope.doc,
no_doc: scope.no_doc,
compact_abi: scope.compact_abi,
out_dir: scope.out_dir.clone(),
manifest_path: scope.manifest_path.clone(),
Expand Down
3 changes: 2 additions & 1 deletion cargo-near/src/commands/build_command/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ pub fn run(args: super::BuildCommand) -> color_eyre::eyre::Result<util::Compilat
let mut abi = None;
let mut min_abi_path = None;
if !args.no_abi {
let mut contract_abi = abi::generate_abi(&crate_metadata, !args.no_doc, true, color.clone())?;
let mut contract_abi =
abi::generate_abi(&crate_metadata, !args.no_doc, true, color.clone())?;
contract_abi.metadata.build = Some(BuildInfo {
compiler: format!("rustc {}", rustc_version::version()?),
builder: format!("cargo-near {}", env!("CARGO_PKG_VERSION")),
Expand Down
8 changes: 4 additions & 4 deletions integration-tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ macro_rules! invoke_cargo_near {
match cli_args.cmd {
Some(cargo_near::commands::CliNearCommand::Abi(cmd)) => {
let args = cargo_near::commands::abi_command::AbiCommand {
doc: cmd.doc,
no_doc: cmd.no_doc,
compact_abi: cmd.compact_abi,
out_dir: cmd.out_dir,
manifest_path: Some(cargo_path.into()),
Expand All @@ -73,10 +73,10 @@ macro_rules! invoke_cargo_near {
},
Some(cargo_near::commands::CliNearCommand::Build(cmd)) => {
let args = cargo_near::commands::build_command::BuildCommand {
release: cmd.release,
embed_abi: cmd.embed_abi,
doc: cmd.doc,
no_release: cmd.no_release,
no_abi: cmd.no_abi,
no_embed_abi: cmd.no_embed_abi,
no_doc: cmd.no_doc,
out_dir: cmd.out_dir,
manifest_path: Some(cargo_path.into()),
color: cmd.color,
Expand Down
6 changes: 3 additions & 3 deletions integration-tests/tests/abi/opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use std::fs;

#[test]
#[named]
fn test_abi_opt_doc() -> cargo_near::CliResult {
fn test_abi_no_doc() -> cargo_near::CliResult {
let abi_root = generate_abi_fn_with! {
Opts: "--doc";
Opts: "--no-doc";
Code:
/// Adds `a` and `b`.
pub fn add(&self, a: u32, b: u32) -> u32 {
Expand All @@ -16,7 +16,7 @@ fn test_abi_opt_doc() -> cargo_near::CliResult {

assert_eq!(abi_root.body.functions.len(), 2);
let function = &abi_root.body.functions[0];
assert_eq!(function.doc.as_ref().unwrap(), " Adds `a` and `b`.");
assert!(function.doc.is_none());

Ok(())
}
Expand Down
48 changes: 0 additions & 48 deletions integration-tests/tests/build/embed.rs

This file was deleted.

19 changes: 13 additions & 6 deletions integration-tests/tests/build/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use crate::util;
use cargo_near_integration_tests::build_fn;
use function_name::named;

mod embed;
mod opts;

#[tokio::test]
Expand All @@ -14,12 +13,20 @@ async fn test_build_simple() -> cargo_near::CliResult {
a + b
}
};
let functions = build_result.abi_root.unwrap().body.functions;
assert_eq!(functions.len(), 2);
assert_eq!(functions[0].name, "add");
assert_eq!(functions[0].doc, None);
let mut abi_root = build_result.abi_root.unwrap();
assert_eq!(abi_root.body.functions.len(), 2);
let function = &abi_root.body.functions[0];
assert_eq!(function.name, "add");
assert_eq!(function.doc.as_ref().unwrap(), " Adds `a` and `b`.");

assert!(build_result.abi_compressed.is_none());
// WASM hash is not included in the embedded ABI
abi_root.metadata.wasm_hash = None;
assert_eq!(
util::fetch_contract_abi(&build_result.wasm).await?,
abi_root
);

assert!(build_result.abi_compressed.is_some());

util::test_add(&build_result.wasm).await?;

Expand Down
103 changes: 25 additions & 78 deletions integration-tests/tests/build/opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,30 @@ fn test_build_no_abi() -> cargo_near::CliResult {
Ok(())
}

#[tokio::test]
#[named]
async fn test_build_no_embed_abi() -> cargo_near::CliResult {
let build_result = build_fn_with! {
Opts: "--no-embed-abi";
Code:
pub fn add(&self, a: u32, b: u32) -> u32 {
a + b
}
};

let worker = near_workspaces::sandbox().await?;
let contract = worker.dev_deploy(&build_result.wasm).await?;
let outcome = contract.call("__contract_abi").view().await;
outcome.unwrap_err();

Ok(())
}

#[test]
#[named]
fn test_build_opt_doc() -> cargo_near::CliResult {
fn test_build_no_doc() -> cargo_near::CliResult {
let build_result = build_fn_with! {
Opts: "--doc";
Opts: "--no-doc";
Code:
/// Adds `a` and `b`.
pub fn add(&self, a: u32, b: u32) -> u32 {
Expand All @@ -34,7 +53,7 @@ fn test_build_opt_doc() -> cargo_near::CliResult {
let abi_root = build_result.abi_root.unwrap();
assert_eq!(abi_root.body.functions.len(), 2);
let function = &abi_root.body.functions[0];
assert_eq!(function.doc.as_ref().unwrap(), " Adds `a` and `b`.");
assert!(function.doc.is_none());

Ok(())
}
Expand Down Expand Up @@ -66,9 +85,9 @@ fn test_build_opt_out_dir() -> cargo_near::CliResult {

#[tokio::test]
#[named]
async fn test_build_opt_release() -> cargo_near::CliResult {
async fn test_build_no_release() -> cargo_near::CliResult {
let build_result = build_fn_with! {
Opts: "--release";
Opts: "--no-release";
Code:
pub fn add(&self, a: u32, b: u32) -> u32 {
a + b
Expand All @@ -77,80 +96,8 @@ async fn test_build_opt_release() -> cargo_near::CliResult {

let abi_root = build_result.abi_root.unwrap();
assert_eq!(abi_root.body.functions.len(), 2);
assert!(build_result.abi_compressed.is_none());
assert!(build_result.abi_compressed.is_some());
util::test_add(&build_result.wasm).await?;

Ok(())
}

#[tokio::test]
#[named]
async fn test_build_opt_doc_embed() -> cargo_near::CliResult {
let build_result = build_fn_with! {
Opts: "--doc --embed-abi";
Code:
/// Adds `a` and `b`.
pub fn add(&self, a: u32, b: u32) -> u32 {
a + b
}
};

let mut abi_root = build_result.abi_root.unwrap();
assert_eq!(abi_root.body.functions.len(), 2);
let function = &abi_root.body.functions[0];
assert_eq!(function.doc.as_ref().unwrap(), " Adds `a` and `b`.");

// WASM hash is not included in the embedded ABI
abi_root.metadata.wasm_hash = None;
assert_eq!(
util::fetch_contract_abi(&build_result.wasm).await?,
abi_root
);

Ok(())
}

#[test]
#[named]
fn test_build_opt_no_abi_doc() -> cargo_near::CliResult {
fn run_test() -> cargo_near::CliResult {
build_fn_with! {
Opts: "--no-abi --doc";
Code:
/// Adds `a` and `b`.
pub fn add(&self, a: u32, b: u32) -> u32 {
a + b
}
};
Ok(())
}

assert!(run_test()
.unwrap_err()
.to_string()
.contains("error: the argument '--no-abi' cannot be used with '--doc'"));

Ok(())
}

#[test]
#[named]
fn test_build_opt_no_abi_embed() -> cargo_near::CliResult {
fn run_test() -> cargo_near::CliResult {
build_fn_with! {
Opts: "--no-abi --embed-abi";
Code:
/// Adds `a` and `b`.
pub fn add(&self, a: u32, b: u32) -> u32 {
a + b
}
};
Ok(())
}
assert!(run_test()
.unwrap_err()
.to_string()
.contains("error: the argument '--no-abi' cannot be used with '--embed-abi'"));

Ok(())
}

0 comments on commit 0a7fdb0

Please sign in to comment.