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 4137b41 commit 840af02
Show file tree
Hide file tree
Showing 11 changed files with 222 additions and 703 deletions.
17 changes: 10 additions & 7 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,14 +623,15 @@ Initialize a Soroban project with an example contract

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

* `-w`, `--with-example <WITH_EXAMPLE>` — An optional flag to specify Soroban example contracts to include. A hello-world contract will be included by default.
* `--name <NAME>` — An optional flag to specify a new contract's name.

Possible values: `account`, `alloc`, `atomic_multiswap`, `atomic_swap`, `auth`, `cross_contract`, `custom_types`, `deep_contract_auth`, `deployer`, `errors`, `eth_abi`, `events`, `fuzzing`, `increment`, `liquidity_pool`, `logging`, `mint-lock`, `other_custom_types`, `simple_account`, `single_offer`, `timelock`, `token`, `ttl`, `upgradeable_contract`, `workspace`
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.

* `--frontend-template <FRONTEND_TEMPLATE>` — An optional flag to pass in a url for a frontend template repository.
Possible values: `true`, `false`

Default value: ``
* `--overwrite` — Overwrite all existing files.



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 840af02

Please sign in to comment.