diff --git a/protostar-rust/tests/data/deploy_test/Scarb.toml b/protostar-rust/tests/data/deploy_test/Scarb.toml new file mode 100644 index 000000000..a8b7e7d6f --- /dev/null +++ b/protostar-rust/tests/data/deploy_test/Scarb.toml @@ -0,0 +1,11 @@ +[package] +name = "deploy_test" +version = "0.1.0" + +[[target.starknet-contract]] +sierra = true + +[dependencies] +starknet = "2.0.0-rc2" + +[tool.protostar] diff --git a/protostar-rust/tests/data/deploy_test/src/lib.cairo b/protostar-rust/tests/data/deploy_test/src/lib.cairo new file mode 100644 index 000000000..d7698f094 --- /dev/null +++ b/protostar-rust/tests/data/deploy_test/src/lib.cairo @@ -0,0 +1,19 @@ +#[starknet::contract] +mod HelloStarknet { + #[storage] + struct Storage { + balance: felt252, + } + + // Increases the balance by the given amount. + #[external] + fn increase_balance(ref self: ContractState, amount: felt252) { + self.balance.write(self.balance.read() + amount); + } + + // Returns the current balance. + #[external] + fn get_balance(self: @ContractState) -> felt252 { + self.balance.read() + } +} diff --git a/protostar-rust/tests/data/deploy_test/tests/test_deploy.cairo b/protostar-rust/tests/data/deploy_test/tests/test_deploy.cairo new file mode 100644 index 000000000..bc33d6860 --- /dev/null +++ b/protostar-rust/tests/data/deploy_test/tests/test_deploy.cairo @@ -0,0 +1,19 @@ +use result::ResultTrait; +use protostar_print::PrintTrait; +use array::ArrayTrait; +use cheatcodes::PreparedContract; + +#[test] +fn test_deploy_simple() { + let calldata = ArrayTrait::::new(); + let class_hash = declare('deploy_test').expect('Could not declare'); + + let contract_address = deploy( + PreparedContract { + class_hash, + constructor_calldata: @calldata, + contract_address: 'addr' + } + ).expect('Could not deploy'); + assert(contract_address == 'addr', 'incorrect contract_address'); +} diff --git a/protostar-rust/tests/e2e/running.rs b/protostar-rust/tests/e2e/running.rs index 33e64a61a..ecd617a3a 100644 --- a/protostar-rust/tests/e2e/running.rs +++ b/protostar-rust/tests/e2e/running.rs @@ -157,6 +157,25 @@ fn run_with_multiple_contracts() { "#}); } +#[test] +fn with_deploy() { + let temp = assert_fs::TempDir::new().unwrap(); + temp.copy_from("tests/data/deploy_test", &["**/*"]).unwrap(); + + let snapbox = runner(); + + snapbox + .current_dir(&temp) + .assert() + .success() + .stdout_matches(indoc! {r#"Collected 1 test(s) and 2 test file(s) + Running 0 test(s) from src/lib.cairo + Running 1 test(s) from tests/test_deploy.cairo + [PASS] test_deploy::test_deploy::test_deploy_simple + Tests: 1 passed, 0 failed + "#}); +} + #[test] fn with_print() { let temp = assert_fs::TempDir::new().unwrap();