Skip to content

Commit

Permalink
Rework contract init
Browse files Browse the repository at this point in the history
  • Loading branch information
Ifropc committed Sep 25, 2024
1 parent 2298378 commit fff708a
Show file tree
Hide file tree
Showing 11 changed files with 214 additions and 92 deletions.
18 changes: 13 additions & 5 deletions FULL_HELP_DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ Tools for smart contract developers
* `fetch` — Fetch a contract's Wasm binary
* `id` — Generate the contract id for a given contract or asset
* `info` — Access info about contracts
* `init` — Initialize a Soroban project with an example contract
* `init` — Initialize a Soroban contract
* `inspect` — Inspect a WASM file listing contract functions, meta, etc
* `install` — Install a WASM file to the ledger without creating a contract instance
* `invoke` — Invoke a contract function
Expand Down Expand Up @@ -611,7 +611,9 @@ Outputs no data when no data is present in the contract.

## `stellar contract init`

Initialize a Soroban project with an example contract
Initialize a Soroban contract.

When running with empty or non-existent `--project-path`, this command will generate a template Cargo workspace project and add a sample contract package. When running in the existing Cargo project, it will add a new package for a sample contract with a given `--name`.

**Usage:** `stellar contract init [OPTIONS] <PROJECT_PATH>`

Expand All @@ -621,9 +623,15 @@ Initialize a Soroban project with an example contract

###### **Options:**

* `-w`, `--with-example` — This argument has been removed and will be not be recognized by the future versions of CLI. You can still clone examples from the repo https://github.com/stellar/soroban-examples
* `--frontend-template` — This argument has been removed and will be not be recognized by the future versions of CLI. You can search for frontend templates using github tags, such as soroban-template or soroban-frontend-template
* `--overwrite` — Overwrite all existing files.
* `--name <NAME>` — An optional flag to specify a new contract's name.

Default value: `hello-world`
* `-w`, `--with-example` — This argument has been deprecated and will be removed in the future versions of CLI. You can still clone examples from the repo https://github.com/stellar/soroban-examples
* `--frontend-template` — This argument has been deprecated and will be removed in the future versions of CLI. You can search for frontend templates using github tags, such as soroban-template or soroban-frontend-template
* `--overwrite` — This argument has been deprecated and will be removed in the future versions of CLI. init command no longer overwrites existing files.

Possible values: `true`, `false`




Expand Down
63 changes: 62 additions & 1 deletion cmd/crates/soroban-test/tests/it/init.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use assert_fs::prelude::*;
use predicates::prelude::predicate;
use soroban_test::TestEnv;
use soroban_test::{AssertExt, TestEnv};

#[test]
fn init() {
Expand All @@ -24,3 +24,64 @@ fn init() {
== Some(&format!("{major}.0.0"))
}));
}

#[test]
fn init_and_deploy() {
let name = "hello_world";
let sandbox = TestEnv::default();

sandbox
.new_assert_cmd("contract")
.arg("init")
.arg("--name")
.arg(name)
.arg("project")
.assert()
.success();

let manifest_path = sandbox
.dir()
.join(format!("project/contracts/{name}/Cargo.toml"));
assert!(manifest_path.exists());

sandbox
.new_assert_cmd("contract")
.arg("build")
.arg("--manifest-path")
.arg(manifest_path)
.assert()
.success();

let target_dir = sandbox
.dir()
.join("project/target/wasm32-unknown-unknown/release");
assert!(target_dir.exists());

let assert = sandbox
.new_assert_cmd("contract")
.arg("deploy")
.arg("--wasm")
.arg(target_dir.join(format!("{name}.wasm")))
.assert();

let contract = assert.stdout_as_str();

assert.success();

let assert = sandbox
.new_assert_cmd("contract")
.arg("invoke")
.arg("--id")
.arg(contract)
.arg("--")
.arg("hello")
.arg("--to")
.arg("bar")
.assert();

let output = assert.stdout_as_str();

assert_eq!(output, r#"["Hello","bar"]"#);

assert.success();
}
Loading

0 comments on commit fff708a

Please sign in to comment.