-
Notifications
You must be signed in to change notification settings - Fork 124
Auto-build contracts when WASM not provided in deploy/upload. #2378
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a210120
Auto-build contracts when WASM not provided in deploy/upload.
fnando 620c336
Add tests.
fnando 50fec44
Add support for meta/optimization.
fnando 7ea2b1f
Address copilot feedback.
fnando caea9f8
Address copilot feedback.
fnando 1eece8e
Fix checks.
fnando d9d05c2
Prevent --package from being used with --wasm/--wasm-hash.
fnando File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| mod auto_build; | ||
| mod bindings; | ||
| mod constructor; | ||
| mod contract; | ||
|
|
||
249 changes: 249 additions & 0 deletions
249
cmd/crates/soroban-test/tests/it/integration/auto_build.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,249 @@ | ||
| use soroban_test::{AssertExt, TestEnv}; | ||
| use std::path::PathBuf; | ||
|
|
||
| #[tokio::test] | ||
| async fn deploy_without_wasm_auto_builds() { | ||
| let sandbox = TestEnv::new(); | ||
| let cargo_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")); | ||
| let fixture_path = cargo_dir.join("tests/fixtures/test-wasms/hello_world"); | ||
|
|
||
| // Deploy without --wasm flag should auto-build the contract | ||
| let contract_id = sandbox | ||
| .new_assert_cmd("contract") | ||
| .current_dir(&fixture_path) | ||
| .arg("deploy") | ||
| .arg("--source-account") | ||
| .arg("test") | ||
| .assert() | ||
| .success() | ||
| .stdout_as_str(); | ||
|
|
||
| // Verify contract was deployed by invoking a function | ||
| sandbox | ||
| .invoke_with_test(&["--id", &contract_id, "--", "hello", "--world=world"]) | ||
| .await | ||
| .unwrap(); | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn deploy_workspace_without_package_builds_all() { | ||
| let sandbox = TestEnv::new(); | ||
| let cargo_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")); | ||
| let fixture_path = cargo_dir.join("tests/fixtures/workspace"); | ||
|
|
||
| // Deploy in workspace without --wasm and without --package builds and deploys all contracts | ||
| sandbox | ||
| .new_assert_cmd("contract") | ||
| .current_dir(&fixture_path) | ||
| .arg("deploy") | ||
| .arg("--source-account") | ||
| .arg("test") | ||
| .assert() | ||
| .success() | ||
| .stderr(predicates::str::contains("Build Complete")); | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn deploy_workspace_with_package_auto_builds() { | ||
| let sandbox = TestEnv::new(); | ||
| let cargo_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")); | ||
| let fixture_path = cargo_dir.join("tests/fixtures/workspace"); | ||
|
|
||
| // Deploy in workspace with --package should auto-build the specified contract | ||
| let contract_id = sandbox | ||
| .new_assert_cmd("contract") | ||
| .current_dir(&fixture_path) | ||
| .arg("deploy") | ||
| .arg("--source-account") | ||
| .arg("test") | ||
| .arg("--package") | ||
| .arg("add") | ||
| .assert() | ||
| .success() | ||
| .stdout_as_str(); | ||
|
|
||
| // Verify contract was deployed | ||
| assert!(!contract_id.is_empty(), "Expected contract ID"); | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn upload_without_wasm_auto_builds() { | ||
| let sandbox = TestEnv::new(); | ||
| let cargo_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")); | ||
| let fixture_path = cargo_dir.join("tests/fixtures/test-wasms/hello_world"); | ||
|
|
||
| // Upload without --wasm flag should auto-build the contract | ||
| let wasm_hash = sandbox | ||
| .new_assert_cmd("contract") | ||
| .current_dir(&fixture_path) | ||
| .arg("upload") | ||
| .arg("--source-account") | ||
| .arg("test") | ||
| .assert() | ||
| .success() | ||
| .stdout_as_str(); | ||
|
|
||
| // Verify a hash was returned | ||
| assert_eq!(wasm_hash.len(), 64, "Expected 64-character hex hash"); | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn upload_workspace_without_package_builds_all() { | ||
| let sandbox = TestEnv::new(); | ||
| let cargo_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")); | ||
| let fixture_path = cargo_dir.join("tests/fixtures/workspace"); | ||
|
|
||
| // Upload in workspace without --wasm and without --package builds and uploads all contracts | ||
| sandbox | ||
| .new_assert_cmd("contract") | ||
| .current_dir(&fixture_path) | ||
| .arg("upload") | ||
| .arg("--source-account") | ||
| .arg("test") | ||
| .assert() | ||
| .success() | ||
| .stderr(predicates::str::contains("Build Complete")); | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn upload_workspace_with_package_auto_builds() { | ||
| let sandbox = TestEnv::new(); | ||
| let cargo_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")); | ||
| let fixture_path = cargo_dir.join("tests/fixtures/workspace"); | ||
|
|
||
| // Upload in workspace with --package should auto-build the specified contract | ||
| let wasm_hash = sandbox | ||
| .new_assert_cmd("contract") | ||
| .current_dir(&fixture_path) | ||
| .arg("upload") | ||
| .arg("--source-account") | ||
| .arg("test") | ||
| .arg("--package") | ||
| .arg("call") | ||
| .assert() | ||
| .success() | ||
| .stdout_as_str(); | ||
|
|
||
| // Verify a hash was returned | ||
| assert_eq!(wasm_hash.len(), 64, "Expected 64-character hex hash"); | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn deploy_outside_cargo_project_requires_wasm() { | ||
| let sandbox = TestEnv::new(); | ||
|
|
||
| // Deploy outside a Cargo project without --wasm should fail | ||
| sandbox | ||
| .new_assert_cmd("contract") | ||
| .arg("deploy") | ||
| .arg("--source-account") | ||
| .arg("test") | ||
| .assert() | ||
| .failure() | ||
| .stderr(predicates::str::contains( | ||
| "--wasm or --wasm-hash is required when not in a Cargo workspace", | ||
| )); | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn upload_outside_cargo_project_requires_wasm() { | ||
| let sandbox = TestEnv::new(); | ||
|
|
||
| // Upload outside a Cargo project without --wasm should fail | ||
| sandbox | ||
| .new_assert_cmd("contract") | ||
| .arg("upload") | ||
| .arg("--source-account") | ||
| .arg("test") | ||
| .assert() | ||
| .failure() | ||
| .stderr(predicates::str::contains( | ||
| "--wasm is required when not in a Cargo workspace", | ||
| )); | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn deploy_build_only_rejected_without_wasm() { | ||
| let sandbox = TestEnv::new(); | ||
| let cargo_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")); | ||
| let fixture_path = cargo_dir.join("tests/fixtures/test-wasms/hello_world"); | ||
|
|
||
| // --build-only should fail when auto-building (no --wasm or --wasm-hash) | ||
| sandbox | ||
| .new_assert_cmd("contract") | ||
| .current_dir(&fixture_path) | ||
| .arg("deploy") | ||
| .arg("--source-account") | ||
| .arg("test") | ||
| .arg("--build-only") | ||
| .assert() | ||
| .failure() | ||
| .stderr(predicates::str::contains( | ||
| "--build-only is not supported without --wasm or --wasm-hash", | ||
| )); | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn upload_build_only_rejected_without_wasm() { | ||
| let sandbox = TestEnv::new(); | ||
| let cargo_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")); | ||
| let fixture_path = cargo_dir.join("tests/fixtures/test-wasms/hello_world"); | ||
|
|
||
| // --build-only should fail when auto-building (no --wasm) | ||
| sandbox | ||
| .new_assert_cmd("contract") | ||
| .current_dir(&fixture_path) | ||
| .arg("upload") | ||
| .arg("--source-account") | ||
| .arg("test") | ||
| .arg("--build-only") | ||
| .assert() | ||
| .failure() | ||
| .stderr(predicates::str::contains( | ||
| "--build-only is not supported without --wasm", | ||
| )); | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn deploy_auto_build_with_meta() { | ||
| let sandbox = TestEnv::new(); | ||
| let cargo_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")); | ||
| let fixture_path = cargo_dir.join("tests/fixtures/test-wasms/hello_world"); | ||
|
|
||
| // Deploy with --meta should pass metadata through to build | ||
| let contract_id = sandbox | ||
| .new_assert_cmd("contract") | ||
| .current_dir(&fixture_path) | ||
| .arg("deploy") | ||
| .arg("--source-account") | ||
| .arg("test") | ||
| .arg("--meta") | ||
| .arg("key=value") | ||
| .assert() | ||
| .success() | ||
| .stdout_as_str(); | ||
|
|
||
| assert!(!contract_id.is_empty(), "Expected contract ID"); | ||
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn upload_auto_build_with_meta() { | ||
| let sandbox = TestEnv::new(); | ||
| let cargo_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")); | ||
| let fixture_path = cargo_dir.join("tests/fixtures/test-wasms/hello_world"); | ||
|
|
||
| // Upload with --meta should pass metadata through to build | ||
| let wasm_hash = sandbox | ||
| .new_assert_cmd("contract") | ||
| .current_dir(&fixture_path) | ||
| .arg("upload") | ||
| .arg("--source-account") | ||
| .arg("test") | ||
| .arg("--meta") | ||
| .arg("key=value") | ||
| .assert() | ||
| .success() | ||
| .stdout_as_str(); | ||
|
|
||
| assert_eq!(wasm_hash.len(), 64, "Expected 64-character hex hash"); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.