Skip to content

Commit

Permalink
chore: release v0.6.0 (#130)
Browse files Browse the repository at this point in the history
## 🤖 New release
* `cargo-near`: 0.5.2 -> 0.6.0 (⚠️ API breaking changes)

### ⚠️ `cargo-near` breaking changes

```
--- failure constructible_struct_adds_field: externally-constructible struct adds field ---

Description:
A pub struct constructible with a struct literal has a new pub field. Existing struct literals must be updated to include the new field.
        ref: https://doc.rust-lang.org/reference/expressions/struct-expr.html
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.27.0/src/lints/constructible_struct_adds_field.ron

Failed in:
  field CliBuildCommand.no_release in /tmp/.tmpsYxSqi/cargo-near/cargo-near/src/commands/build_command/mod.rs:3
  field CliBuildCommand.no_embed_abi in /tmp/.tmpsYxSqi/cargo-near/cargo-near/src/commands/build_command/mod.rs:3
  field CliBuildCommand.no_doc in /tmp/.tmpsYxSqi/cargo-near/cargo-near/src/commands/build_command/mod.rs:3
  field InteractiveClapContextScopeForBuildCommand.no_release in /tmp/.tmpsYxSqi/cargo-near/cargo-near/src/commands/build_command/mod.rs:3
  field InteractiveClapContextScopeForBuildCommand.no_embed_abi in /tmp/.tmpsYxSqi/cargo-near/cargo-near/src/commands/build_command/mod.rs:3
  field InteractiveClapContextScopeForBuildCommand.no_doc in /tmp/.tmpsYxSqi/cargo-near/cargo-near/src/commands/build_command/mod.rs:3
  field BuildCommand.no_release in /tmp/.tmpsYxSqi/cargo-near/cargo-near/src/commands/build_command/mod.rs:9
  field BuildCommand.no_embed_abi in /tmp/.tmpsYxSqi/cargo-near/cargo-near/src/commands/build_command/mod.rs:15
  field BuildCommand.no_doc in /tmp/.tmpsYxSqi/cargo-near/cargo-near/src/commands/build_command/mod.rs:18

--- failure struct_pub_field_missing: pub struct's pub field removed or renamed ---

Description:
A publicly-visible struct has at least one public field that is no longer available under its prior name. It may have been renamed or removed entirely.
        ref: https://doc.rust-lang.org/cargo/reference/semver.html#item-remove
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.27.0/src/lints/struct_pub_field_missing.ron

Failed in:
  field release of struct InteractiveClapContextScopeForBuildCommand, previously in file /tmp/.tmpZefZn7/cargo-near/src/commands/build_command/mod.rs:3
  field embed_abi of struct InteractiveClapContextScopeForBuildCommand, previously in file /tmp/.tmpZefZn7/cargo-near/src/commands/build_command/mod.rs:3
  field doc of struct InteractiveClapContextScopeForBuildCommand, previously in file /tmp/.tmpZefZn7/cargo-near/src/commands/build_command/mod.rs:3
  field release of struct BuildCommand, previously in file /tmp/.tmpZefZn7/cargo-near/src/commands/build_command/mod.rs:9
  field embed_abi of struct BuildCommand, previously in file /tmp/.tmpZefZn7/cargo-near/src/commands/build_command/mod.rs:12
  field doc of struct BuildCommand, previously in file /tmp/.tmpZefZn7/cargo-near/src/commands/build_command/mod.rs:15
  field release of struct CliBuildCommand, previously in file /tmp/.tmpZefZn7/cargo-near/src/commands/build_command/mod.rs:3
  field embed_abi of struct CliBuildCommand, previously in file /tmp/.tmpZefZn7/cargo-near/src/commands/build_command/mod.rs:3
  field doc of struct CliBuildCommand, previously in file /tmp/.tmpZefZn7/cargo-near/src/commands/build_command/mod.rs:3
```

<details><summary><i><b>Changelog</b></i></summary><p>

<blockquote>

##
[0.6.0](cargo-near-v0.5.2...cargo-near-v0.6.0)
- 2024-02-03

### Added
- Use hello-world contract instead of the status-message contract for
the new project starter
- Enable by default release mode, embedded ABIs with doc strings
</blockquote>


</p></details>

---
This PR was generated with
[release-plz](https://github.com/MarcoIeni/release-plz/).
  • Loading branch information
frol authored Feb 3, 2024
1 parent 97ccb9f commit 0859150
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 146 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.6.0](https://github.com/near/cargo-near/compare/cargo-near-v0.5.2...cargo-near-v0.6.0) - 2024-02-03

### Added
- Use hello-world contract instead of the status-message contract for the new project starter
- Enable by default release mode, embedded ABIs with doc strings

## [0.5.2](https://github.com/near/cargo-near/compare/cargo-near-v0.5.1...cargo-near-v0.5.2) - 2024-01-27

### Other
Expand Down
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cargo-near/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cargo-near"
version = "0.5.2"
version = "0.6.0"
authors = ["Near Inc <[email protected]>"]
edition = "2021"
rust-version = "1.72.0"
Expand Down
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 0859150

Please sign in to comment.