From 9507fc4e68677199171a8a7b263458d435ae15a2 Mon Sep 17 00:00:00 2001 From: Leigh McCulloch <351529+leighmcculloch@users.noreply.github.com> Date: Tue, 24 Sep 2024 17:57:50 +1000 Subject: [PATCH 1/4] Add `register` and `register_at` fns to replace `register_contract`, `register_contract_with_constructor`, `register_contract_wasm`, `register_contract_wasm_with_constructor` (#1343) ### What Add `register` and `register_at` fns. Deprecate `register_contract` and `register_contract_wasm`. Unexport `register_contract_with_constructor` and `register_contract_wasm_with_constructor`. ### Why To reorient the register functions around what we expect the common cases to be: - registering without a contract id specified - registering with a constructor specified It's always been odd that the first parameter to most `register_contract` calls is `None`. It's confusing to look at the first time you see it, and for the most part most developers do not need to set a value for the contract id. Most contracts need initialization, and therefore I think most contracts over time will gain constructors. To do so in a way that is backwards compatible with previous releases. Close https://github.com/stellar/rs-soroban-sdk/issues/1341 ### Known limitations It would be better imo if we could add the constructor arguments to the existing `register_contract` and `register_contract_wasm` fns, but that would be a breaking change. The `deploy_with_constructor` functions still exist which is inconsistent, but harder to align because to change the `deploy` function to always accept constructor args would be a breaking change. It's possible to update code that uses the existing register functions using a regex find and replace, but it's not the most trivial regex to work out. If folks wish to resolve the deprecation warning they'll need to update potentially every test they've written. That in itself is not a great developer experience. The old and new way don't look that different, and so for existing Soroban developers, the change from the old to new way may be confusing at a glance. This PR doesn't touch the register stellar asset contract functions at all. Ideas? --- soroban-sdk/README.md | 2 +- soroban-sdk/src/deploy.rs | 4 +- soroban-sdk/src/env.rs | 198 +++++++++++++----- soroban-sdk/src/events.rs | 2 +- soroban-sdk/src/ledger.rs | 2 +- soroban-sdk/src/lib.rs | 20 +- soroban-sdk/src/prng.rs | 14 +- soroban-sdk/src/storage.rs | 2 +- soroban-sdk/src/tests/auth/auth_10_one.rs | 2 +- .../src/tests/auth/auth_15_one_repeat.rs | 2 +- .../auth/auth_17_no_consume_requirement.rs | 2 +- .../tests/auth/auth_20_deep_one_address.rs | 8 +- .../auth/auth_30_deep_one_address_repeat.rs | 8 +- ...auth_35_deep_one_address_repeat_grouped.rs | 8 +- .../tests/auth/auth_40_multi_one_address.rs | 8 +- soroban-sdk/src/tests/budget.rs | 2 +- soroban-sdk/src/tests/contract_add_i32.rs | 2 +- soroban-sdk/src/tests/contract_assert.rs | 4 +- soroban-sdk/src/tests/contract_docs.rs | 2 +- soroban-sdk/src/tests/contract_duration.rs | 2 +- soroban-sdk/src/tests/contract_fn.rs | 2 +- soroban-sdk/src/tests/contract_invoke.rs | 6 +- .../src/tests/contract_invoke_arg_count.rs | 12 +- .../contract_overlapping_type_fn_names.rs | 2 +- soroban-sdk/src/tests/contract_snapshot.rs | 4 +- soroban-sdk/src/tests/contract_store.rs | 4 +- soroban-sdk/src/tests/contract_timepoint.rs | 2 +- soroban-sdk/src/tests/contract_udt_enum.rs | 2 +- soroban-sdk/src/tests/contract_udt_option.rs | 2 +- soroban-sdk/src/tests/contract_udt_struct.rs | 4 +- .../src/tests/contract_udt_struct_tuple.rs | 2 +- soroban-sdk/src/tests/contractimport.rs | 20 +- .../src/tests/contractimport_with_error.rs | 4 +- soroban-sdk/src/tests/env.rs | 30 +-- soroban-sdk/src/tests/max_ttl.rs | 2 +- soroban-sdk/src/tests/prng.rs | 30 +-- soroban-sdk/src/tests/storage_testutils.rs | 10 +- soroban-sdk/src/tests/token_client.rs | 4 +- soroban-sdk/src/testutils.rs | 30 +++ tests/account/src/lib.rs | 4 +- tests/add_i128/src/lib.rs | 2 +- tests/add_u128/src/lib.rs | 2 +- tests/add_u64/src/lib.rs | 2 +- tests/alloc/src/lib.rs | 2 +- tests/auth/src/lib.rs | 32 +-- tests/constructor/src/lib.rs | 10 +- tests/empty/src/lib.rs | 2 +- tests/empty2/src/lib.rs | 2 +- tests/errors/src/lib.rs | 12 +- tests/events/src/lib.rs | 2 +- tests/fuzz/fuzz/fuzz_targets/fuzz_target_1.rs | 7 +- tests/import_contract/src/lib.rs | 4 +- tests/invoke_contract/src/lib.rs | 4 +- tests/logging/src/lib.rs | 2 +- tests/modular/src/test.rs | 2 +- tests/multiimpl/src/lib.rs | 2 +- tests/udt/src/lib.rs | 2 +- tests/workspace_contract/src/lib.rs | 2 +- 58 files changed, 344 insertions(+), 219 deletions(-) diff --git a/soroban-sdk/README.md b/soroban-sdk/README.md index 2aef6d4c3..83953317f 100644 --- a/soroban-sdk/README.md +++ b/soroban-sdk/README.md @@ -26,7 +26,7 @@ fn test() { # #[cfg(feature = "testutils")] # fn main() { let env = Env::default(); - let contract_id = env.register_contract(None, HelloContract); + let contract_id = env.register(HelloContract, ()); let client = HelloContractClient::new(&env, &contract_id); let words = client.hello(&symbol_short!("Dev")); diff --git a/soroban-sdk/src/deploy.rs b/soroban-sdk/src/deploy.rs index 71646d5ef..640b9399e 100644 --- a/soroban-sdk/src/deploy.rs +++ b/soroban-sdk/src/deploy.rs @@ -36,7 +36,7 @@ //! # #[cfg(feature = "testutils")] //! # fn main() { //! let env = Env::default(); -//! let contract_address = env.register_contract(None, Contract); +//! let contract_address = env.register(Contract, ()); //! let contract = ContractClient::new(&env, &contract_address); //! // Upload the contract code before deploying its instance. //! let wasm_hash = env.deployer().upload_contract_wasm(DEPLOYED_WASM); @@ -71,7 +71,7 @@ //! # #[cfg(feature = "testutils")] //! # fn main() { //! let env = Env::default(); -//! let contract_address = env.register_contract(None, Contract); +//! let contract_address = env.register(Contract, ()); //! let contract = ContractClient::new(&env, &contract_address); //! // Upload the contract code before deploying its instance. //! let wasm_hash = env.deployer().upload_contract_wasm(DEPLOYED_WASM_WITH_CTOR); diff --git a/soroban-sdk/src/env.rs b/soroban-sdk/src/env.rs index bc4ffec17..1d04b3a56 100644 --- a/soroban-sdk/src/env.rs +++ b/soroban-sdk/src/env.rs @@ -455,7 +455,7 @@ use crate::{ testutils::{ budget::Budget, Address as _, AuthSnapshot, AuthorizedInvocation, ConstructorArgs, ContractFunctionSet, EventsSnapshot, Generators, Ledger as _, MockAuth, MockAuthContract, - Snapshot, StellarAssetContract, StellarAssetIssuer, + Register, Snapshot, StellarAssetContract, StellarAssetIssuer, }, Bytes, BytesN, }; @@ -576,6 +576,136 @@ impl Env { env } + /// Register a contract with the [Env] for testing. + /// + /// Pass the contract type when the contract is defined in the current crate + /// and is being registered natively. Pass the contract wasm bytes when the + /// contract has been loaded as wasm. + /// + /// Pass the arguments for the contract's constructor, or `()` if none. + /// + /// Returns the address of the registered contract that is the same as the + /// contract id passed in. + /// + /// If you need to specify the address the contract should be registered at, + /// use [`register_at`]. + /// + /// ### Examples + /// Register a contract defined in the current crate, by specifying the type + /// name: + /// ``` + /// use soroban_sdk::{contract, contractimpl, testutils::Address as _, Address, BytesN, Env, Symbol}; + /// + /// #[contract] + /// pub struct Contract; + /// + /// #[contractimpl] + /// impl Contract { + /// pub fn __constructor(_env: Env, _input: u32) { + /// } + /// } + /// + /// #[test] + /// fn test() { + /// # } + /// # fn main() { + /// let env = Env::default(); + /// let contract_id = env.register(Contract, (123_u32,)); + /// } + /// ``` + /// Register a contract wasm, by specifying the wasm bytes: + /// ``` + /// use soroban_sdk::{testutils::Address as _, Address, BytesN, Env}; + /// + /// const WASM: &[u8] = include_bytes!("../doctest_fixtures/contract.wasm"); + /// + /// #[test] + /// fn test() { + /// # } + /// # fn main() { + /// let env = Env::default(); + /// let contract_id = env.register(WASM, ()); + /// } + /// ``` + pub fn register<'a, C, A>(&self, contract: C, constructor_args: A) -> Address + where + C: Register, + A: ConstructorArgs, + { + contract.register(self, None, constructor_args) + } + + /// Register a contract with the [Env] for testing. + /// + /// Passing a contract ID for the first arguments registers the contract + /// with that contract ID. + /// + /// Registering a contract that is already registered replaces it. + /// Use re-registration with caution as it does not exist in the real + /// (on-chain) environment. Specifically, the new contract's constructor + /// will be called again during re-registration. That behavior only exists + /// for this test utility and is not reproducible on-chain, where contract + /// Wasm updates don't cause constructor to be called. + /// + /// Pass the contract type when the contract is defined in the current crate + /// and is being registered natively. Pass the contract wasm bytes when the + /// contract has been loaded as wasm. + /// + /// Returns the address of the registered contract that is the same as the + /// contract id passed in. + /// + /// ### Examples + /// Register a contract defined in the current crate, by specifying the type + /// name: + /// ``` + /// use soroban_sdk::{contract, contractimpl, testutils::Address as _, Address, BytesN, Env, Symbol}; + /// + /// #[contract] + /// pub struct Contract; + /// + /// #[contractimpl] + /// impl Contract { + /// pub fn __constructor(_env: Env, _input: u32) { + /// } + /// } + /// + /// #[test] + /// fn test() { + /// # } + /// # fn main() { + /// let env = Env::default(); + /// let contract_id = Address::generate(&env); + /// env.register_at(&contract_id, Contract, (123_u32,)); + /// } + /// ``` + /// Register a contract wasm, by specifying the wasm bytes: + /// ``` + /// use soroban_sdk::{testutils::Address as _, Address, BytesN, Env}; + /// + /// const WASM: &[u8] = include_bytes!("../doctest_fixtures/contract.wasm"); + /// + /// #[test] + /// fn test() { + /// # } + /// # fn main() { + /// let env = Env::default(); + /// let contract_id = Address::generate(&env); + /// env.register_at(&contract_id, WASM, ()); + /// } + /// ``` + pub fn register_at( + &self, + contract_id: &Address, + contract: C, + constructor_args: A, + ) -> Address + where + C: Register, + A: ConstructorArgs, + { + contract.register(self, contract_id, constructor_args) + } + /// Register a contract with the [Env] for testing. /// /// Passing a contract ID for the first arguments registers the contract @@ -583,8 +713,7 @@ impl Env { /// contract ID that is assigned to the contract. /// /// If a contract has a constructor defined, then it will be called with - /// no arguments. If a constructor takes arguments, use - /// `register_contract_with_constructor`. + /// no arguments. If a constructor takes arguments, use `register`. /// /// Registering a contract that is already registered replaces it. /// Use re-registration with caution as it does not exist in the real @@ -617,6 +746,7 @@ impl Env { /// let contract_id = env.register_contract(None, HelloContract); /// } /// ``` + #[deprecated(note = "use `register`")] pub fn register_contract<'a, T: ContractFunctionSet + 'static>( &self, contract_id: impl Into>, @@ -642,30 +772,7 @@ impl Env { /// Wasm updates don't cause constructor to be called. /// /// Returns the address of the registered contract. - /// - /// ### Examples - /// ``` - /// use soroban_sdk::{contract, contractimpl, BytesN, Env, Symbol}; - /// - /// #[contract] - /// pub struct Contract; - /// - /// #[contractimpl] - /// impl Contract { - /// pub fn __constructor(_env: Env, _input: u32) { - /// } - /// } - /// - /// #[test] - /// fn test() { - /// # } - /// # fn main() { - /// let env = Env::default(); - /// let contract_id = env.register_contract_with_constructor( - /// None, Contract, (123_u32,)); - /// } - /// ``` - pub fn register_contract_with_constructor< + pub(crate) fn register_contract_with_constructor< 'a, T: ContractFunctionSet + 'static, A: ConstructorArgs, @@ -742,6 +849,7 @@ impl Env { /// env.register_contract_wasm(None, WASM); /// } /// ``` + #[deprecated(note = "use `register`")] pub fn register_contract_wasm<'a>( &self, contract_id: impl Into>, @@ -772,33 +880,17 @@ impl Env { /// Wasm updates don't cause constructor to be called. /// /// Returns the address of the registered contract. - /// - /// ### Examples - /// ``` - /// use soroban_sdk::{BytesN, Env, IntoVal}; - /// // This is Wasm for `constructor` test contract from this repo. - /// const WASM: &[u8] = include_bytes!("../doctest_fixtures/contract_with_constructor.wasm"); - /// - /// #[test] - /// fn test() { - /// # } - /// # fn main() { - /// let env = Env::default(); - /// env.register_contract_wasm_with_constructor( - /// None, WASM, (10_u32, 100_i64).into_val(&env)); - /// } - /// ``` - pub fn register_contract_wasm_with_constructor<'a>( + pub(crate) fn register_contract_wasm_with_constructor<'a>( &self, contract_id: impl Into>, contract_wasm: impl IntoVal, - constructor_args: Vec, + constructor_args: impl ConstructorArgs, ) -> Address { let wasm_hash: BytesN<32> = self.deployer().upload_contract_wasm(contract_wasm); self.register_contract_with_optional_contract_id_and_executable( contract_id, xdr::ContractExecutable::Wasm(xdr::Hash(wasm_hash.into())), - constructor_args, + constructor_args.into_val(self), ) } @@ -995,7 +1087,7 @@ impl Env { /// # } /// # fn main() { /// let env = Env::default(); - /// let contract_id = env.register_contract(None, HelloContract); + /// let contract_id = env.register(HelloContract, ()); /// /// let client = HelloContractClient::new(&env, &contract_id); /// let addr = Address::generate(&env); @@ -1014,7 +1106,7 @@ impl Env { /// ``` pub fn mock_auths(&self, auths: &[MockAuth]) { for a in auths { - self.register_contract(a.address, MockAuthContract); + self.register_at(a.address, MockAuthContract, ()); } let auths = auths .iter() @@ -1064,7 +1156,7 @@ impl Env { /// # } /// # fn main() { /// let env = Env::default(); - /// let contract_id = env.register_contract(None, HelloContract); + /// let contract_id = env.register(HelloContract, ()); /// /// env.mock_all_auths(); /// @@ -1117,8 +1209,8 @@ impl Env { /// # } /// # fn main() { /// let env = Env::default(); - /// let contract_a = env.register_contract(None, ContractA); - /// let contract_b = env.register_contract(None, ContractB); + /// let contract_a = env.register(ContractA, ()); + /// let contract_b = env.register(ContractB, ()); /// // The regular `env.mock_all_auths()` would result in the call /// // failure. /// env.mock_all_auths_allowing_non_root_auth(); @@ -1178,7 +1270,7 @@ impl Env { /// # fn main() { /// extern crate std; /// let env = Env::default(); - /// let contract_id = env.register_contract(None, Contract); + /// let contract_id = env.register(Contract, ()); /// let client = ContractClient::new(&env, &contract_id); /// env.mock_all_auths(); /// let address = Address::generate(&env); @@ -1282,7 +1374,7 @@ impl Env { /// # } /// # fn main() { /// let e: Env = Default::default(); - /// let account_contract = NoopAccountContractClient::new(&e, &e.register_contract(None, NoopAccountContract)); + /// let account_contract = NoopAccountContractClient::new(&e, &e.register(NoopAccountContract, ())); /// // Non-succesful call of `__check_auth` with a `contracterror` error. /// assert_eq!( /// e.try_invoke_contract_check_auth::( diff --git a/soroban-sdk/src/events.rs b/soroban-sdk/src/events.rs index 241779357..6d6e9a986 100644 --- a/soroban-sdk/src/events.rs +++ b/soroban-sdk/src/events.rs @@ -43,7 +43,7 @@ const TOPIC_BYTES_LENGTH_LIMIT: u32 = 32; /// # #[cfg(feature = "testutils")] /// # fn main() { /// # let env = Env::default(); -/// # let contract_id = env.register_contract(None, Contract); +/// # let contract_id = env.register(Contract, ()); /// # ContractClient::new(&env, &contract_id).f(); /// # } /// # #[cfg(not(feature = "testutils"))] diff --git a/soroban-sdk/src/ledger.rs b/soroban-sdk/src/ledger.rs index a91801610..4b6b5a5a0 100644 --- a/soroban-sdk/src/ledger.rs +++ b/soroban-sdk/src/ledger.rs @@ -31,7 +31,7 @@ use crate::{env::internal, unwrap::UnwrapInfallible, BytesN, Env, TryIntoVal}; /// # #[cfg(feature = "testutils")] /// # fn main() { /// # let env = Env::default(); -/// # let contract_id = env.register_contract(None, Contract); +/// # let contract_id = env.register(Contract, ()); /// # ContractClient::new(&env, &contract_id).f(); /// # } /// # #[cfg(not(feature = "testutils"))] diff --git a/soroban-sdk/src/lib.rs b/soroban-sdk/src/lib.rs index c032484ea..a4b8aa5cb 100644 --- a/soroban-sdk/src/lib.rs +++ b/soroban-sdk/src/lib.rs @@ -26,7 +26,7 @@ //! # #[cfg(feature = "testutils")] //! # fn main() { //! let env = Env::default(); -//! let contract_id = env.register_contract(None, HelloContract); +//! let contract_id = env.register(HelloContract, ()); //! let client = HelloContractClient::new(&env, &contract_id); //! //! let words = client.hello(&symbol_short!("Dev")); @@ -197,7 +197,7 @@ pub use soroban_sdk_macros::symbol_short; /// let env = Env::default(); /// /// // Register the contract defined in this crate. -/// let contract_id = env.register_contract(None, Contract); +/// let contract_id = env.register(Contract, ()); /// /// // Create a client for calling the contract. /// let client = ContractClient::new(&env, &contract_id); @@ -244,7 +244,7 @@ pub use soroban_sdk_macros::symbol_short; /// let env = Env::default(); /// /// // Register the contract defined in this crate. -/// let contract_id = env.register_contract(None, Contract); +/// let contract_id = env.register(Contract, ()); /// /// // Create a client for calling the contract. /// let client = ContractClient::new(&env, &contract_id); @@ -296,7 +296,7 @@ pub use soroban_sdk_macros::contracterror; /// let contract_a_id = env.register_contract_wasm(None, contract_a::WASM); /// /// // Register contract B defined in this crate. -/// let contract_b_id = env.register_contract(None, ContractB); +/// let contract_b_id = env.register(ContractB, ()); /// /// // Create a client for calling contract B. /// let client = ContractBClient::new(&env, &contract_b_id); @@ -342,7 +342,7 @@ pub use soroban_sdk_macros::contractimport; /// # #[cfg(feature = "testutils")] /// # fn main() { /// let env = Env::default(); -/// let contract_id = env.register_contract(None, HelloContract); +/// let contract_id = env.register(HelloContract, ()); /// let client = HelloContractClient::new(&env, &contract_id); /// /// let words = client.hello(&symbol_short!("Dev")); @@ -383,7 +383,7 @@ pub use soroban_sdk_macros::contract; /// # #[cfg(feature = "testutils")] /// # fn main() { /// let env = Env::default(); -/// let contract_id = env.register_contract(None, HelloContract); +/// let contract_id = env.register(HelloContract, ()); /// let client = HelloContractClient::new(&env, &contract_id); /// /// let words = client.hello(&symbol_short!("Dev")); @@ -423,7 +423,7 @@ pub use soroban_sdk_macros::contractimpl; /// # #[cfg(feature = "testutils")] /// # fn main() { /// let env = Env::default(); -/// let contract_id = env.register_contract(None, HelloContract); +/// let contract_id = env.register(HelloContract, ()); /// let client = HelloContractClient::new(&env, &contract_id); /// /// let words = client.hello(&symbol_short!("Dev")); @@ -503,7 +503,7 @@ pub use soroban_sdk_macros::contractmeta; /// # #[cfg(feature = "testutils")] /// # fn main() { /// let env = Env::default(); -/// let contract_id = env.register_contract(None, Contract); +/// let contract_id = env.register(Contract, ()); /// let client = ContractClient::new(&env, &contract_id); /// /// assert_eq!(client.increment(&1), 1); @@ -577,7 +577,7 @@ pub use soroban_sdk_macros::contractmeta; /// # #[cfg(feature = "testutils")] /// # fn main() { /// let env = Env::default(); -/// let contract_id = env.register_contract(None, Contract); +/// let contract_id = env.register(Contract, ()); /// let client = ContractClient::new(&env, &contract_id); /// /// assert_eq!(client.get(), None); @@ -637,7 +637,7 @@ pub use soroban_sdk_macros::contracttype; /// let env = Env::default(); /// /// // Register the hello contract. -/// let contract_id = env.register_contract(None, HelloContract); +/// let contract_id = env.register(HelloContract, ()); /// /// // Create a client for the hello contract, that was constructed using /// // the trait. diff --git a/soroban-sdk/src/prng.rs b/soroban-sdk/src/prng.rs index 8b0425c9f..b91e0df1c 100644 --- a/soroban-sdk/src/prng.rs +++ b/soroban-sdk/src/prng.rs @@ -120,7 +120,7 @@ impl Prng { /// # #[cfg(feature = "testutils")] /// # fn main() { /// # let env = Env::default(); - /// # let contract_id = env.register_contract(None, Contract); + /// # let contract_id = env.register(Contract, ()); /// # env.as_contract(&contract_id, || { /// # env.prng().seed(Bytes::from_array(&env, &[1; 32])); /// let mut value: u64 = 0; @@ -143,7 +143,7 @@ impl Prng { /// # #[cfg(feature = "testutils")] /// # fn main() { /// # let env = Env::default(); - /// # let contract_id = env.register_contract(None, Contract); + /// # let contract_id = env.register(Contract, ()); /// # env.as_contract(&contract_id, || { /// # env.prng().seed(Bytes::from_array(&env, &[1; 32])); /// let mut value = [0u8; 32]; @@ -188,7 +188,7 @@ impl Prng { /// # #[cfg(feature = "testutils")] /// # fn main() { /// # let env = Env::default(); - /// # let contract_id = env.register_contract(None, Contract); + /// # let contract_id = env.register(Contract, ()); /// # env.as_contract(&contract_id, || { /// # env.prng().seed(Bytes::from_array(&env, &[1; 32])); /// let value: u64 = env.prng().gen(); @@ -210,7 +210,7 @@ impl Prng { /// # #[cfg(feature = "testutils")] /// # fn main() { /// # let env = Env::default(); - /// # let contract_id = env.register_contract(None, Contract); + /// # let contract_id = env.register(Contract, ()); /// # env.as_contract(&contract_id, || { /// # env.prng().seed(Bytes::from_array(&env, &[1; 32])); /// let value: [u8; 32] = env.prng().gen(); @@ -258,7 +258,7 @@ impl Prng { /// # #[cfg(feature = "testutils")] /// # fn main() { /// # let env = Env::default(); - /// # let contract_id = env.register_contract(None, Contract); + /// # let contract_id = env.register(Contract, ()); /// # env.as_contract(&contract_id, || { /// # env.prng().seed(Bytes::from_array(&env, &[1; 32])); /// // Get a value of length 32 bytes. @@ -307,7 +307,7 @@ impl Prng { /// # #[cfg(feature = "testutils")] /// # fn main() { /// # let env = Env::default(); - /// # let contract_id = env.register_contract(None, Contract); + /// # let contract_id = env.register(Contract, ()); /// # env.as_contract(&contract_id, || { /// # env.prng().seed(Bytes::from_array(&env, &[1; 32])); /// // Get a value in the range of 1 to 100, inclusive. @@ -347,7 +347,7 @@ impl Prng { /// # #[cfg(feature = "testutils")] /// # fn main() { /// # let env = Env::default(); - /// # let contract_id = env.register_contract(None, Contract); + /// # let contract_id = env.register(Contract, ()); /// # env.as_contract(&contract_id, || { /// # env.prng().seed(Bytes::from_array(&env, &[1; 32])); /// // Get a value in the range of 1 to 100, inclusive. diff --git a/soroban-sdk/src/storage.rs b/soroban-sdk/src/storage.rs index 9bd0a3ea0..f2e74ec46 100644 --- a/soroban-sdk/src/storage.rs +++ b/soroban-sdk/src/storage.rs @@ -53,7 +53,7 @@ use crate::{ /// # #[cfg(feature = "testutils")] /// # fn main() { /// # let env = Env::default(); -/// # let contract_id = env.register_contract(None, Contract); +/// # let contract_id = env.register(Contract, ()); /// # ContractClient::new(&env, &contract_id).f(); /// # } /// # #[cfg(not(feature = "testutils"))] diff --git a/soroban-sdk/src/tests/auth/auth_10_one.rs b/soroban-sdk/src/tests/auth/auth_10_one.rs index f23ffecff..6de963a0b 100644 --- a/soroban-sdk/src/tests/auth/auth_10_one.rs +++ b/soroban-sdk/src/tests/auth/auth_10_one.rs @@ -22,7 +22,7 @@ impl Contract { #[test] fn test() { let e = Env::default(); - let contract_id = e.register_contract(None, Contract); + let contract_id = e.register(Contract, ()); let client = ContractClient::new(&e, &contract_id); let a = Address::generate(&e); diff --git a/soroban-sdk/src/tests/auth/auth_15_one_repeat.rs b/soroban-sdk/src/tests/auth/auth_15_one_repeat.rs index d299b08b8..ba37f4e4d 100644 --- a/soroban-sdk/src/tests/auth/auth_15_one_repeat.rs +++ b/soroban-sdk/src/tests/auth/auth_15_one_repeat.rs @@ -26,7 +26,7 @@ impl Contract { #[test] fn test() { let e = Env::default(); - let contract_id = e.register_contract(None, Contract); + let contract_id = e.register(Contract, ()); let client = ContractClient::new(&e, &contract_id); let a = Address::generate(&e); diff --git a/soroban-sdk/src/tests/auth/auth_17_no_consume_requirement.rs b/soroban-sdk/src/tests/auth/auth_17_no_consume_requirement.rs index 663f61063..f1d6a5cf8 100644 --- a/soroban-sdk/src/tests/auth/auth_17_no_consume_requirement.rs +++ b/soroban-sdk/src/tests/auth/auth_17_no_consume_requirement.rs @@ -31,7 +31,7 @@ impl Contract { #[test] fn test() { let e = Env::default(); - let contract_id = e.register_contract(None, Contract); + let contract_id = e.register(Contract, ()); let client = ContractClient::new(&e, &contract_id); let a = Address::generate(&e); diff --git a/soroban-sdk/src/tests/auth/auth_20_deep_one_address.rs b/soroban-sdk/src/tests/auth/auth_20_deep_one_address.rs index 4adcdc7c8..99183ec29 100644 --- a/soroban-sdk/src/tests/auth/auth_20_deep_one_address.rs +++ b/soroban-sdk/src/tests/auth/auth_20_deep_one_address.rs @@ -31,8 +31,8 @@ impl ContractB { #[test] fn test() { let e = Env::default(); - let contract_a_id = e.register_contract(None, ContractA); - let contract_b_id = e.register_contract(None, ContractB); + let contract_a_id = e.register(ContractA, ()); + let contract_b_id = e.register(ContractB, ()); let client = ContractAClient::new(&e, &contract_a_id); let a = Address::generate(&e); @@ -61,8 +61,8 @@ fn test() { #[should_panic = "HostError: Error(Auth, InvalidAction)"] fn test_auth_tree() { let e = Env::default(); - let contract_a_id = e.register_contract(None, ContractA); - let contract_b_id = e.register_contract(None, ContractB); + let contract_a_id = e.register(ContractA, ()); + let contract_b_id = e.register(ContractB, ()); let client = ContractAClient::new(&e, &contract_a_id); let a = Address::generate(&e); diff --git a/soroban-sdk/src/tests/auth/auth_30_deep_one_address_repeat.rs b/soroban-sdk/src/tests/auth/auth_30_deep_one_address_repeat.rs index 10a02ed61..b9c11140b 100644 --- a/soroban-sdk/src/tests/auth/auth_30_deep_one_address_repeat.rs +++ b/soroban-sdk/src/tests/auth/auth_30_deep_one_address_repeat.rs @@ -32,8 +32,8 @@ impl ContractB { #[test] fn test() { let e = Env::default(); - let contract_a_id = e.register_contract(None, ContractA); - let contract_b_id = e.register_contract(None, ContractB); + let contract_a_id = e.register(ContractA, ()); + let contract_b_id = e.register(ContractB, ()); let client = ContractAClient::new(&e, &contract_a_id); let a = Address::generate(&e); @@ -76,8 +76,8 @@ fn test() { #[should_panic = "HostError: Error(Auth, InvalidAction)"] fn test_auth_tree() { let e = Env::default(); - let contract_a_id = e.register_contract(None, ContractA); - let contract_b_id = e.register_contract(None, ContractB); + let contract_a_id = e.register(ContractA, ()); + let contract_b_id = e.register(ContractB, ()); let client = ContractAClient::new(&e, &contract_a_id); let a = Address::generate(&e); diff --git a/soroban-sdk/src/tests/auth/auth_35_deep_one_address_repeat_grouped.rs b/soroban-sdk/src/tests/auth/auth_35_deep_one_address_repeat_grouped.rs index 7cd8e5cb9..e70448866 100644 --- a/soroban-sdk/src/tests/auth/auth_35_deep_one_address_repeat_grouped.rs +++ b/soroban-sdk/src/tests/auth/auth_35_deep_one_address_repeat_grouped.rs @@ -32,8 +32,8 @@ impl ContractB { #[test] fn test() { let e = Env::default(); - let contract_a_id = e.register_contract(None, ContractA); - let contract_b_id = e.register_contract(None, ContractB); + let contract_a_id = e.register(ContractA, ()); + let contract_b_id = e.register(ContractB, ()); let client = ContractAClient::new(&e, &contract_a_id); let a = Address::generate(&e); @@ -76,8 +76,8 @@ fn test() { #[should_panic = "HostError: Error(Auth, InvalidAction)"] fn test_auth_tree() { let e = Env::default(); - let contract_a_id = e.register_contract(None, ContractA); - let contract_b_id = e.register_contract(None, ContractB); + let contract_a_id = e.register(ContractA, ()); + let contract_b_id = e.register(ContractB, ()); let client = ContractAClient::new(&e, &contract_a_id); let a = Address::generate(&e); diff --git a/soroban-sdk/src/tests/auth/auth_40_multi_one_address.rs b/soroban-sdk/src/tests/auth/auth_40_multi_one_address.rs index e9d151475..c797227f9 100644 --- a/soroban-sdk/src/tests/auth/auth_40_multi_one_address.rs +++ b/soroban-sdk/src/tests/auth/auth_40_multi_one_address.rs @@ -32,8 +32,8 @@ impl ContractB { #[test] fn test_auth_not_allowed_with_separated_tree() { let e = Env::default(); - let contract_a_id = e.register_contract(None, ContractA); - let contract_b_id = e.register_contract(None, ContractB); + let contract_a_id = e.register(ContractA, ()); + let contract_b_id = e.register(ContractB, ()); let client = ContractAClient::new(&e, &contract_a_id); let a = Address::generate(&e); @@ -66,8 +66,8 @@ fn test_auth_not_allowed_with_separated_tree() { #[test] fn test_auth_as_tree() { let e = Env::default(); - let contract_a_id = e.register_contract(None, ContractA); - let contract_b_id = e.register_contract(None, ContractB); + let contract_a_id = e.register(ContractA, ()); + let contract_b_id = e.register(ContractB, ()); let client = ContractAClient::new(&e, &contract_a_id); let a = Address::generate(&e); diff --git a/soroban-sdk/src/tests/budget.rs b/soroban-sdk/src/tests/budget.rs index be8ba657c..8391b8990 100644 --- a/soroban-sdk/src/tests/budget.rs +++ b/soroban-sdk/src/tests/budget.rs @@ -18,7 +18,7 @@ impl Contract { #[test] fn test_budget() { let e = Env::default(); - let contract_id = e.register_contract(None, Contract); + let contract_id = e.register(Contract, ()); let client = ContractClient::new(&e, &contract_id); e.budget().reset_default(); diff --git a/soroban-sdk/src/tests/contract_add_i32.rs b/soroban-sdk/src/tests/contract_add_i32.rs index 813dcf9ac..9721f8cb3 100644 --- a/soroban-sdk/src/tests/contract_add_i32.rs +++ b/soroban-sdk/src/tests/contract_add_i32.rs @@ -18,7 +18,7 @@ impl Contract { #[test] fn test_functional() { let e = Env::default(); - let contract_id = e.register_contract(None, Contract); + let contract_id = e.register(Contract, ()); let a = 10i32; let b = 12i32; diff --git a/soroban-sdk/src/tests/contract_assert.rs b/soroban-sdk/src/tests/contract_assert.rs index ffb295d8e..d92681331 100644 --- a/soroban-sdk/src/tests/contract_assert.rs +++ b/soroban-sdk/src/tests/contract_assert.rs @@ -22,7 +22,7 @@ impl Contract { #[should_panic(expected = "Error(Contract, #1")] fn test_invoke_expect_error() { let e = Env::default(); - let contract_id = e.register_contract(None, Contract); + let contract_id = e.register(Contract, ()); ContractClient::new(&e, &contract_id).assert(&0); } @@ -30,7 +30,7 @@ fn test_invoke_expect_error() { #[test] fn test_try_invoke() { let e = Env::default(); - let contract_id = e.register_contract(None, Contract); + let contract_id = e.register(Contract, ()); let res = ContractClient::new(&e, &contract_id).try_assert(&0); assert_eq!(res, Err(Ok(soroban_sdk::Error::from_contract_error(1)))); diff --git a/soroban-sdk/src/tests/contract_docs.rs b/soroban-sdk/src/tests/contract_docs.rs index 89fbe201d..eeac38cc5 100644 --- a/soroban-sdk/src/tests/contract_docs.rs +++ b/soroban-sdk/src/tests/contract_docs.rs @@ -18,7 +18,7 @@ mod fn_ { #[test] fn test_functional() { let env = Env::default(); - let contract_id = env.register_contract(None, Contract); + let contract_id = env.register(Contract, ()); let client = ContractClient::new(&env, &contract_id); client.add(); } diff --git a/soroban-sdk/src/tests/contract_duration.rs b/soroban-sdk/src/tests/contract_duration.rs index 8b991f4f4..03804c477 100644 --- a/soroban-sdk/src/tests/contract_duration.rs +++ b/soroban-sdk/src/tests/contract_duration.rs @@ -12,7 +12,7 @@ impl Contract { #[test] fn test_functional() { let env = Env::default(); - let contract_id = env.register_contract(None, Contract); + let contract_id = env.register(Contract, ()); let client = ContractClient::new(&env, &contract_id); let t: Duration = xdr::ScVal::Duration(xdr::Duration(0)).into_val(&env); diff --git a/soroban-sdk/src/tests/contract_fn.rs b/soroban-sdk/src/tests/contract_fn.rs index 352ded1b5..7eaf18164 100644 --- a/soroban-sdk/src/tests/contract_fn.rs +++ b/soroban-sdk/src/tests/contract_fn.rs @@ -18,7 +18,7 @@ impl Contract { #[test] fn test_functional() { let e = Env::default(); - let contract_id = e.register_contract(None, Contract); + let contract_id = e.register(Contract, ()); let a = 10i32; let b = 12i32; diff --git a/soroban-sdk/src/tests/contract_invoke.rs b/soroban-sdk/src/tests/contract_invoke.rs index 7ce8ce29f..6567bfcc5 100644 --- a/soroban-sdk/src/tests/contract_invoke.rs +++ b/soroban-sdk/src/tests/contract_invoke.rs @@ -15,7 +15,7 @@ impl Contract { #[should_panic(expected = "I panicked")] fn test_invoke_expect_string() { let e = Env::default(); - let contract_id = e.register_contract(None, Contract); + let contract_id = e.register(Contract, ()); ContractClient::new(&e, &contract_id).panic(); } @@ -24,7 +24,7 @@ fn test_invoke_expect_string() { #[should_panic(expected = "Error(WasmVm, InvalidAction)")] fn test_invoke_expect_error() { let e = Env::default(); - let contract_id = e.register_contract(None, Contract); + let contract_id = e.register(Contract, ()); ContractClient::new(&e, &contract_id).panic(); } @@ -34,7 +34,7 @@ fn test_try_invoke() { use soroban_env_host::xdr::{ScErrorCode, ScErrorType}; let e = Env::default(); - let contract_id = e.register_contract(None, Contract); + let contract_id = e.register(Contract, ()); let res = ContractClient::new(&e, &contract_id).try_panic(); assert_eq!( diff --git a/soroban-sdk/src/tests/contract_invoke_arg_count.rs b/soroban-sdk/src/tests/contract_invoke_arg_count.rs index 32cd30c09..ee5d43dc9 100644 --- a/soroban-sdk/src/tests/contract_invoke_arg_count.rs +++ b/soroban-sdk/src/tests/contract_invoke_arg_count.rs @@ -32,9 +32,9 @@ impl AddContract { fn test_correct_arg_count() { let e = Env::default(); - let add_contract_id = e.register_contract(None, AddContract); + let add_contract_id = e.register(AddContract, ()); - let contract_id = e.register_contract(None, Contract); + let contract_id = e.register(Contract, ()); let client = ContractClient::new(&e, &contract_id); let x = 10i32; @@ -48,9 +48,9 @@ fn test_correct_arg_count() { fn test_too_few_args() { let e = Env::default(); - let add_contract_id = e.register_contract(None, AddContract); + let add_contract_id = e.register(AddContract, ()); - let contract_id = e.register_contract(None, Contract); + let contract_id = e.register(Contract, ()); let client = ContractClient::new(&e, &contract_id); let x = 10i32; @@ -62,9 +62,9 @@ fn test_too_few_args() { fn test_too_many_args() { let e = Env::default(); - let add_contract_id = e.register_contract(None, AddContract); + let add_contract_id = e.register(AddContract, ()); - let contract_id = e.register_contract(None, Contract); + let contract_id = e.register(Contract, ()); let client = ContractClient::new(&e, &contract_id); let x = 10i32; diff --git a/soroban-sdk/src/tests/contract_overlapping_type_fn_names.rs b/soroban-sdk/src/tests/contract_overlapping_type_fn_names.rs index cc46c4475..ad3411993 100644 --- a/soroban-sdk/src/tests/contract_overlapping_type_fn_names.rs +++ b/soroban-sdk/src/tests/contract_overlapping_type_fn_names.rs @@ -20,7 +20,7 @@ impl Contract { #[test] fn test_functional() { let env = Env::default(); - let contract_id = env.register_contract(None, Contract); + let contract_id = env.register(Contract, ()); let client = ContractClient::new(&env, &contract_id); let s = client.state(); diff --git a/soroban-sdk/src/tests/contract_snapshot.rs b/soroban-sdk/src/tests/contract_snapshot.rs index 3a4086f71..8014cd62b 100644 --- a/soroban-sdk/src/tests/contract_snapshot.rs +++ b/soroban-sdk/src/tests/contract_snapshot.rs @@ -17,7 +17,7 @@ impl Contract { #[test] fn test() { let e = Env::default(); - let contract_id = e.register_contract(None, Contract); + let contract_id = e.register(Contract, ()); let contract_id_xdr = xdr::ScAddress::try_from(&contract_id).unwrap(); let client = ContractClient::new(&e, &contract_id); @@ -28,7 +28,7 @@ fn test() { let e = Env::from_ledger_snapshot(snapshot); let contract_id = Address::try_from_val(&e, &contract_id_xdr).unwrap(); - e.register_contract(&contract_id, Contract); + e.register_at(&contract_id, Contract, ()); let client = ContractClient::new(&e, &contract_id); assert_eq!(client.get(&2), 4); diff --git a/soroban-sdk/src/tests/contract_store.rs b/soroban-sdk/src/tests/contract_store.rs index a8d8efac3..f929789f5 100644 --- a/soroban-sdk/src/tests/contract_store.rs +++ b/soroban-sdk/src/tests/contract_store.rs @@ -61,7 +61,7 @@ fn test_storage() { e.ledger().set_min_temp_entry_ttl(50); e.ledger().set_max_entry_ttl(20_000); - let contract_id = e.register_contract(None, Contract); + let contract_id = e.register(Contract, ()); let client = ContractClient::new(&e, &contract_id); // Smoke test instance bump before putting any data into it. @@ -186,7 +186,7 @@ fn test_temp_storage_extension_past_max_ttl_panics() { let e = Env::default(); e.ledger().set_min_temp_entry_ttl(50); e.ledger().set_max_entry_ttl(20_000); - let contract_id = e.register_contract(None, Contract); + let contract_id = e.register(Contract, ()); let client = ContractClient::new(&e, &contract_id); e.as_contract(&contract_id, || { e.storage().temporary().set(&DataKey::Key(11), &2222_i32); diff --git a/soroban-sdk/src/tests/contract_timepoint.rs b/soroban-sdk/src/tests/contract_timepoint.rs index ea1b6069a..19a777b04 100644 --- a/soroban-sdk/src/tests/contract_timepoint.rs +++ b/soroban-sdk/src/tests/contract_timepoint.rs @@ -12,7 +12,7 @@ impl Contract { #[test] fn test_functional() { let env = Env::default(); - let contract_id = env.register_contract(None, Contract); + let contract_id = env.register(Contract, ()); let client = ContractClient::new(&env, &contract_id); let t: Timepoint = xdr::ScVal::Timepoint(xdr::TimePoint(0)).into_val(&env); diff --git a/soroban-sdk/src/tests/contract_udt_enum.rs b/soroban-sdk/src/tests/contract_udt_enum.rs index 31f2275f2..7e194c236 100644 --- a/soroban-sdk/src/tests/contract_udt_enum.rs +++ b/soroban-sdk/src/tests/contract_udt_enum.rs @@ -34,7 +34,7 @@ impl Contract { #[test] fn test_functional() { let env = Env::default(); - let contract_id = env.register_contract(None, Contract); + let contract_id = env.register(Contract, ()); let client = ContractClient::new(&env, &contract_id); let a = Udt::Aaa; diff --git a/soroban-sdk/src/tests/contract_udt_option.rs b/soroban-sdk/src/tests/contract_udt_option.rs index 18cde33d2..ae55979c8 100644 --- a/soroban-sdk/src/tests/contract_udt_option.rs +++ b/soroban-sdk/src/tests/contract_udt_option.rs @@ -21,7 +21,7 @@ impl Contract { #[test] fn test_functional() { let env = Env::default(); - let contract_id = env.register_contract(None, Contract); + let contract_id = env.register(Contract, ()); let a = Udt { a: 5, b: None }; let b = Udt { a: 10, b: Some(1) }; diff --git a/soroban-sdk/src/tests/contract_udt_struct.rs b/soroban-sdk/src/tests/contract_udt_struct.rs index f602b5ec4..af6ce8363 100644 --- a/soroban-sdk/src/tests/contract_udt_struct.rs +++ b/soroban-sdk/src/tests/contract_udt_struct.rs @@ -47,7 +47,7 @@ impl Contract { #[test] fn test_functional() { let env = Env::default(); - let contract_id = env.register_contract(None, Contract); + let contract_id = env.register(Contract, ()); let a = Udt { a: 5, b: 7 }; let b = Udt { a: 10, b: 14 }; @@ -58,7 +58,7 @@ fn test_functional() { #[test] fn test_long_names_functional() { let env = Env::default(); - let contract_id = env.register_contract(None, Contract); + let contract_id = env.register(Contract, ()); let a = UdtWithLongName { this_is_a_very_long_name_12345: 1_000_000_000_000, diff --git a/soroban-sdk/src/tests/contract_udt_struct_tuple.rs b/soroban-sdk/src/tests/contract_udt_struct_tuple.rs index f7e623991..872a8221d 100644 --- a/soroban-sdk/src/tests/contract_udt_struct_tuple.rs +++ b/soroban-sdk/src/tests/contract_udt_struct_tuple.rs @@ -35,7 +35,7 @@ fn test_conversion() { #[test] fn test_functional() { let env = Env::default(); - let contract_id = env.register_contract(None, Contract); + let contract_id = env.register(Contract, ()); let a = Udt(5, 7); let b = Udt(10, 14); diff --git a/soroban-sdk/src/tests/contractimport.rs b/soroban-sdk/src/tests/contractimport.rs index 064188346..bccd95dcc 100644 --- a/soroban-sdk/src/tests/contractimport.rs +++ b/soroban-sdk/src/tests/contractimport.rs @@ -46,9 +46,9 @@ impl Contract { fn test_functional() { let e = Env::default(); - let add_contract_id = e.register_contract_wasm(None, addcontract::WASM); + let add_contract_id = e.register(addcontract::WASM, ()); - let contract_id = e.register_contract(None, Contract); + let contract_id = e.register(Contract, ()); let client = ContractClient::new(&e, &contract_id); let x = 10u64; @@ -62,9 +62,9 @@ fn test_register_at_id() { let e = Env::default(); let add_contract_id = Address::from_contract_id(&e, [1; 32]); - e.register_contract_wasm(&add_contract_id, addcontract::WASM); + e.register_at(&add_contract_id, addcontract::WASM, ()); - let contract_id = e.register_contract(None, Contract); + let contract_id = e.register(Contract, ()); let client = ContractClient::new(&e, &contract_id); let x = 10u64; @@ -76,12 +76,12 @@ fn test_register_at_id() { #[test] fn test_reregister_wasm() { let e = Env::default(); - let add_contract_id = e.register_contract_wasm(None, addcontract_u128::WASM); + let add_contract_id = e.register(addcontract_u128::WASM, ()); // Reregister the contract with different code replacing the code. This is // the contract we expect to be executed. - e.register_contract_wasm(&add_contract_id, addcontract::WASM); + e.register_at(&add_contract_id, addcontract::WASM, ()); - let contract_id = e.register_contract(None, Contract); + let contract_id = e.register(Contract, ()); let client = ContractClient::new(&e, &contract_id); let x = 10u64; @@ -95,12 +95,12 @@ fn test_reregister_over_wasm_with_rust_impl() { let e = Env::default(); // Register a contract with wasm. - let other_contract_id = e.register_contract_wasm(None, addcontract::WASM); + let other_contract_id = e.register(addcontract::WASM, ()); // Reregister the contract with a rust impl instead that does something // different. - e.register_contract(&other_contract_id, subcontract::Contract); + e.register_at(&other_contract_id, subcontract::Contract, ()); - let contract_id = e.register_contract(None, Contract); + let contract_id = e.register(Contract, ()); let client = ContractClient::new(&e, &contract_id); let x = 12u64; diff --git a/soroban-sdk/src/tests/contractimport_with_error.rs b/soroban-sdk/src/tests/contractimport_with_error.rs index 30da50697..13ab9e69b 100644 --- a/soroban-sdk/src/tests/contractimport_with_error.rs +++ b/soroban-sdk/src/tests/contractimport_with_error.rs @@ -22,9 +22,9 @@ impl Contract { fn test_functional() { let e = Env::default(); - let err_contract_id = e.register_contract_wasm(None, errcontract::WASM); + let err_contract_id = e.register(errcontract::WASM, ()); - let contract_id = e.register_contract(None, Contract); + let contract_id = e.register(Contract, ()); let client = ContractClient::new(&e, &contract_id); let z = client.hello_with(&err_contract_id, &0); diff --git a/soroban-sdk/src/tests/env.rs b/soroban-sdk/src/tests/env.rs index 1042045d0..d5adb0f07 100644 --- a/soroban-sdk/src/tests/env.rs +++ b/soroban-sdk/src/tests/env.rs @@ -44,8 +44,8 @@ fn default_and_from_snapshot_same_settings() { assert!(env1.host().source_account_address().unwrap().is_some()); assert!(env2.host().source_account_address().unwrap().is_some()); - let c1addr = env1.register_contract(None, Contract); - let c2addr = env2.register_contract(None, Contract); + let c1addr = env1.register(Contract, ()); + let c2addr = env2.register(Contract, ()); let c1client = ContractClient::new(&env1, &c1addr); let c2client = ContractClient::new(&env2, &c2addr); @@ -83,21 +83,21 @@ fn register_contract_deploys_predictable_contract_ids() { let env1 = Env::default(); let env2 = Env::from_snapshot(env1.to_snapshot()); - let env1addr1 = env1.register_contract(None, Contract); + let env1addr1 = env1.register(Contract, ()); println!("env1 addr1 {:?}", env1addr1.contract_id()); - let env1addr2 = env1.register_contract(None, Contract); + let env1addr2 = env1.register(Contract, ()); println!("env1 addr2 {:?}", env1addr2.contract_id()); - let env2addr1 = env2.register_contract(None, Contract); + let env2addr1 = env2.register(Contract, ()); println!("env2 addr1 {:?}", env2addr1.contract_id()); - let env2addr2 = env2.register_contract(None, Contract); + let env2addr2 = env2.register(Contract, ()); println!("env2 addr2 {:?}", env2addr2.contract_id()); let env3 = Env::from_snapshot(env1.to_snapshot()); - let env1addr3 = env1.register_contract(None, Contract); + let env1addr3 = env1.register(Contract, ()); println!("env1 addr3 {:?}", env1addr3.contract_id()); - let env2addr3 = env2.register_contract(None, Contract); + let env2addr3 = env2.register(Contract, ()); println!("env2 addr3 {:?}", env2addr3.contract_id()); - let env3addr3 = env3.register_contract(None, Contract); + let env3addr3 = env3.register(Contract, ()); println!("env3 addr3 {:?}", env3addr3.contract_id()); // Check that contracts deployed in the envs are consistent and predictable. @@ -132,9 +132,9 @@ fn test_snapshot_file() { assert!(!p2.exists()); { let e3 = Env::default(); // When dropped will be written to p1. - let _ = e3.register_contract(None, Contract); + let _ = e3.register(Contract, ()); } // Env dropped, written to p1. - let c = e1.register_contract(None, Contract); + let c = e1.register(Contract, ()); assert!(p1.exists()); assert!(!p2.exists()); e1.as_contract(&c, || {}); @@ -163,11 +163,11 @@ fn test_snapshot_file_disabled() { let _ = std::fs::remove_file(&p2); { let e1 = Env::default(); - let _ = e1.register_contract(None, Contract); + let _ = e1.register(Contract, ()); let e2 = Env::new_with_config(EnvTestConfig { capture_snapshot_at_drop: false, }); - let _ = e2.register_contract(None, Contract); + let _ = e2.register(Contract, ()); assert!(!p1.exists()); assert!(!p2.exists()); } @@ -190,12 +190,12 @@ fn test_snapshot_file_disabled_after_creation() { let _ = std::fs::remove_file(&p2); { let e1 = Env::default(); - let _ = e1.register_contract(None, Contract); + let _ = e1.register(Contract, ()); let mut e2 = Env::default(); e2.set_config(EnvTestConfig { capture_snapshot_at_drop: false, }); - let _ = e2.register_contract(None, Contract); + let _ = e2.register(Contract, ()); assert!(!p1.exists()); assert!(!p2.exists()); } diff --git a/soroban-sdk/src/tests/max_ttl.rs b/soroban-sdk/src/tests/max_ttl.rs index 1cab646de..3f4c41763 100644 --- a/soroban-sdk/src/tests/max_ttl.rs +++ b/soroban-sdk/src/tests/max_ttl.rs @@ -7,7 +7,7 @@ pub struct Contract; #[test] fn max() { let e = Env::default(); - let contract_id = e.register_contract(None, Contract); + let contract_id = e.register(Contract, ()); e.ledger().set_sequence_number(1); e.ledger().set_max_entry_ttl(5); diff --git a/soroban-sdk/src/tests/prng.rs b/soroban-sdk/src/tests/prng.rs index 28213b859..ac8790a98 100644 --- a/soroban-sdk/src/tests/prng.rs +++ b/soroban-sdk/src/tests/prng.rs @@ -9,7 +9,7 @@ pub struct TestPrngContract; fn test_prng_seed() { let e = Env::default(); e.host().set_base_prng_seed([0; 32]).unwrap(); - let id = e.register_contract(None, TestPrngContract); + let id = e.register(TestPrngContract, ()); e.as_contract(&id, || { e.prng().seed(bytes!( &e, @@ -19,7 +19,7 @@ fn test_prng_seed() { }); let e = Env::default(); - let id = e.register_contract(None, TestPrngContract); + let id = e.register(TestPrngContract, ()); e.host().set_base_prng_seed([2; 32]).unwrap(); e.as_contract(&id, || { e.prng().seed(bytes!( @@ -33,7 +33,7 @@ fn test_prng_seed() { #[test] fn test_prng_shuffle() { let e = Env::default(); - let id = e.register_contract(None, TestPrngContract); + let id = e.register(TestPrngContract, ()); e.as_contract(&id, || { let v = vec![&e, 1, 2, 3]; @@ -49,7 +49,7 @@ fn test_prng_shuffle() { #[test] fn test_vec_shuffle() { let e = Env::default(); - let id = e.register_contract(None, TestPrngContract); + let id = e.register(TestPrngContract, ()); e.as_contract(&id, || { let v = vec![&e, 1, 2, 3]; @@ -69,7 +69,7 @@ fn test_vec_shuffle() { #[test] fn test_prng_fill_u64() { let e = Env::default(); - let id = e.register_contract(None, TestPrngContract); + let id = e.register(TestPrngContract, ()); e.as_contract(&id, || { let mut v: u64 = 0; @@ -83,7 +83,7 @@ fn test_prng_fill_u64() { #[test] fn test_prng_gen_u64() { let e = Env::default(); - let id = e.register_contract(None, TestPrngContract); + let id = e.register(TestPrngContract, ()); e.as_contract(&id, || { assert_eq!(e.prng().gen::(), 6775509081846337106); @@ -94,7 +94,7 @@ fn test_prng_gen_u64() { #[test] fn test_prng_gen_range_u64() { let e = Env::default(); - let id = e.register_contract(None, TestPrngContract); + let id = e.register(TestPrngContract, ()); e.as_contract(&id, || { assert_eq!(e.prng().gen_range::(..), 6775509081846337106); @@ -114,7 +114,7 @@ fn test_prng_gen_range_u64() { #[should_panic(expected = "Error(Value, InvalidInput)")] fn test_prng_gen_range_u64_panic_on_invalid_range() { let e = Env::default(); - let id = e.register_contract(None, TestPrngContract); + let id = e.register(TestPrngContract, ()); e.as_contract(&id, || { e.prng().gen_range::(u64::MAX..u64::MAX); @@ -124,7 +124,7 @@ fn test_prng_gen_range_u64_panic_on_invalid_range() { #[test] fn test_prng_fill_bytes() { let e = Env::default(); - let id = e.register_contract(None, TestPrngContract); + let id = e.register(TestPrngContract, ()); e.as_contract(&id, || { let mut v = Bytes::from_array(&e, &[0u8; 32]); @@ -156,7 +156,7 @@ fn test_prng_fill_bytes() { #[test] fn test_prng_gen_len_bytes() { let e = Env::default(); - let id = e.register_contract(None, TestPrngContract); + let id = e.register(TestPrngContract, ()); e.as_contract(&id, || { assert_eq!( @@ -185,7 +185,7 @@ fn test_prng_gen_len_bytes() { #[test] fn test_prng_fill_bytesn() { let e = Env::default(); - let id = e.register_contract(None, TestPrngContract); + let id = e.register(TestPrngContract, ()); e.as_contract(&id, || { let mut v = BytesN::from_array(&e, &[0u8; 32]); @@ -217,7 +217,7 @@ fn test_prng_fill_bytesn() { #[test] fn test_prng_gen_bytesn() { let e = Env::default(); - let id = e.register_contract(None, TestPrngContract); + let id = e.register(TestPrngContract, ()); e.as_contract(&id, || { assert_eq!( @@ -246,7 +246,7 @@ fn test_prng_gen_bytesn() { #[test] fn test_prng_fill_slice() { let e = Env::default(); - let id = e.register_contract(None, TestPrngContract); + let id = e.register(TestPrngContract, ()); e.as_contract(&id, || { let mut buf = [0u8; 32]; @@ -273,7 +273,7 @@ fn test_prng_fill_slice() { #[test] fn test_prng_fill_array() { let e = Env::default(); - let id = e.register_contract(None, TestPrngContract); + let id = e.register(TestPrngContract, ()); e.as_contract(&id, || { let mut v = [0u8; 32]; @@ -299,7 +299,7 @@ fn test_prng_fill_array() { #[test] fn test_prng_gen_array() { let e = Env::default(); - let id = e.register_contract(None, TestPrngContract); + let id = e.register(TestPrngContract, ()); e.as_contract(&id, || { assert_eq!( diff --git a/soroban-sdk/src/tests/storage_testutils.rs b/soroban-sdk/src/tests/storage_testutils.rs index 0c730cef7..411f8a231 100644 --- a/soroban-sdk/src/tests/storage_testutils.rs +++ b/soroban-sdk/src/tests/storage_testutils.rs @@ -12,7 +12,7 @@ pub struct Contract; #[test] fn all() { let e = Env::default(); - let id = e.register_contract(None, Contract); + let id = e.register(Contract, ()); e.as_contract(&id, || { e.storage().instance().set(&1, &2); @@ -49,8 +49,8 @@ fn ttl_getters() { e.ledger().set_min_persistent_entry_ttl(100); e.ledger().set_min_temp_entry_ttl(10); - let contract_a = e.register_contract(None, Contract); - let contract_b = e.register_contract(None, Contract); + let contract_a = e.register(Contract, ()); + let contract_b = e.register(Contract, ()); let setup = || { e.storage().persistent().set(&1, &3); e.storage().temporary().set(&2, &4); @@ -113,7 +113,7 @@ fn temp_entry_expiration() { let e = Env::default(); e.ledger().set_sequence_number(1000); e.ledger().set_min_temp_entry_ttl(100); - let contract = e.register_contract(None, Contract); + let contract = e.register(Contract, ()); e.as_contract(&contract, || { e.storage().temporary().set(&1, &2); @@ -145,7 +145,7 @@ fn test_persistent_entry_expiration() { e.ledger().set_sequence_number(1000); e.ledger().set_min_persistent_entry_ttl(100); - let contract = e.register_contract(None, Contract); + let contract = e.register(Contract, ()); e.as_contract(&contract, || { e.storage().persistent().set(&1, &2); diff --git a/soroban-sdk/src/tests/token_client.rs b/soroban-sdk/src/tests/token_client.rs index bf12fa2ef..9d4ab68f0 100644 --- a/soroban-sdk/src/tests/token_client.rs +++ b/soroban-sdk/src/tests/token_client.rs @@ -73,7 +73,7 @@ fn test_mock_all_auth() { let sac = env.register_stellar_asset_contract_v2(admin); let token_contract_id = sac.address(); - let contract_id = env.register_contract(None, TestContract); + let contract_id = env.register(TestContract, ()); let client = TestContractClient::new(&env, &contract_id); client.init(&token_contract_id); @@ -121,7 +121,7 @@ fn test_mock_auth() { let admin = Address::generate(&env); let token_contract_id = env.register_stellar_asset_contract_v2(admin).address(); - let contract_id = env.register_contract(None, TestContract); + let contract_id = env.register(TestContract, ()); let client = TestContractClient::new(&env, &contract_id); client.init(&token_contract_id); diff --git a/soroban-sdk/src/testutils.rs b/soroban-sdk/src/testutils.rs index 61b7e0ef3..8aa6e0c3b 100644 --- a/soroban-sdk/src/testutils.rs +++ b/soroban-sdk/src/testutils.rs @@ -23,6 +23,36 @@ use soroban_ledger_snapshot::LedgerSnapshot; pub use crate::env::EnvTestConfig; +pub trait Register { + fn register<'i, I, A>(self, env: &Env, id: I, args: A) -> crate::Address + where + I: Into>, + A: ConstructorArgs; +} + +impl Register for C +where + C: ContractFunctionSet + 'static, +{ + fn register<'i, I, A>(self, env: &Env, id: I, args: A) -> crate::Address + where + I: Into>, + A: ConstructorArgs, + { + env.register_contract_with_constructor(id, self, args) + } +} + +impl<'w> Register for &'w [u8] { + fn register<'i, I, A>(self, env: &Env, id: I, args: A) -> crate::Address + where + I: Into>, + A: ConstructorArgs, + { + env.register_contract_wasm_with_constructor(id, self, args) + } +} + pub trait ConstructorArgs: IntoVal> {} impl ConstructorArgs for Vec {} diff --git a/tests/account/src/lib.rs b/tests/account/src/lib.rs index bce7c204b..7ddbe9026 100644 --- a/tests/account/src/lib.rs +++ b/tests/account/src/lib.rs @@ -44,8 +44,8 @@ mod test { #[test] fn test() { let e = Env::default(); - let test_contract_id = e.register_contract(None, TestContract); - let contract_id = e.register_contract(None, Contract); + let test_contract_id = e.register(TestContract, ()); + let contract_id = e.register(Contract, ()); e.set_auths(&[MockAuth { address: &contract_id, diff --git a/tests/add_i128/src/lib.rs b/tests/add_i128/src/lib.rs index a611b5820..765c743f2 100644 --- a/tests/add_i128/src/lib.rs +++ b/tests/add_i128/src/lib.rs @@ -20,7 +20,7 @@ mod test { #[test] fn test_add() { let e = Env::default(); - let contract_id = e.register_contract(None, Contract); + let contract_id = e.register(Contract, ()); let client = ContractClient::new(&e, &contract_id); let x = 2i128.pow(70); diff --git a/tests/add_u128/src/lib.rs b/tests/add_u128/src/lib.rs index 9f20679cd..595ff53c2 100644 --- a/tests/add_u128/src/lib.rs +++ b/tests/add_u128/src/lib.rs @@ -20,7 +20,7 @@ mod test { #[test] fn test_add() { let e = Env::default(); - let contract_id = e.register_contract(None, Contract); + let contract_id = e.register(Contract, ()); let client = ContractClient::new(&e, &contract_id); let x = 2u128.pow(70); diff --git a/tests/add_u64/src/lib.rs b/tests/add_u64/src/lib.rs index 3a2bcd97e..78dc60692 100644 --- a/tests/add_u64/src/lib.rs +++ b/tests/add_u64/src/lib.rs @@ -20,7 +20,7 @@ mod test { #[test] fn test_add() { let e = Env::default(); - let contract_id = e.register_contract(None, Contract); + let contract_id = e.register(Contract, ()); let client = ContractClient::new(&e, &contract_id); let x = 10u64; diff --git a/tests/alloc/src/lib.rs b/tests/alloc/src/lib.rs index 49e722fd5..99953bea0 100644 --- a/tests/alloc/src/lib.rs +++ b/tests/alloc/src/lib.rs @@ -30,7 +30,7 @@ mod test { #[test] fn test_add() { let e = Env::default(); - let contract_id = e.register_contract(None, Contract); + let contract_id = e.register(Contract, ()); let client = ContractClient::new(&e, &contract_id); let list = client.num_list(&5); diff --git a/tests/auth/src/lib.rs b/tests/auth/src/lib.rs index ffd7f3ae9..175207c33 100644 --- a/tests/auth/src/lib.rs +++ b/tests/auth/src/lib.rs @@ -33,7 +33,7 @@ mod test_a { fn test_with_mock_all_auth() { let e = Env::default(); - let contract_id = e.register_contract(None, ContractA); + let contract_id = e.register(ContractA, ()); let client = ContractAClient::new(&e, &contract_id); let a = Address::generate(&e); @@ -60,7 +60,7 @@ mod test_a { fn test_with_mock_auth() { let e = Env::default(); - let contract_id = e.register_contract(None, ContractA); + let contract_id = e.register(ContractA, ()); let client = ContractAClient::new(&e, &contract_id); let a = Address::generate(&e); @@ -97,10 +97,10 @@ mod test_a { fn test_with_real_contract_auth_approve() { let e = Env::default(); - let contract_id = e.register_contract(None, ContractA); + let contract_id = e.register(ContractA, ()); let client = ContractAClient::new(&e, &contract_id); - let a = e.register_contract(None, auth_approve::Contract); + let a = e.register(auth_approve::Contract, ()); let a_xdr: ScAddress = (&a).try_into().unwrap(); let r = client @@ -143,10 +143,10 @@ mod test_a { fn test_with_real_contract_auth_decline() { let e = Env::default(); - let contract_id = e.register_contract(None, ContractA); + let contract_id = e.register(ContractA, ()); let client = ContractAClient::new(&e, &contract_id); - let a = e.register_contract(None, auth_decline::Contract); + let a = e.register(auth_decline::Contract, ()); let a_xdr: ScAddress = (&a).try_into().unwrap(); let r = client @@ -251,8 +251,8 @@ mod test_b { fn test_with_mock_all_auth() { let e = Env::default(); - let contract_a_id = e.register_contract(None, ContractA); - let contract_b_id = e.register_contract(None, ContractB); + let contract_a_id = e.register(ContractA, ()); + let contract_b_id = e.register(ContractB, ()); let client = ContractBClient::new(&e, &contract_b_id); let a = Address::generate(&e); @@ -286,8 +286,8 @@ mod test_b { fn test_with_mock_auth() { let e = Env::default(); - let contract_a_id = e.register_contract(None, ContractA); - let contract_b_id = e.register_contract(None, ContractB); + let contract_a_id = e.register(ContractA, ()); + let contract_b_id = e.register(ContractB, ()); let client = ContractBClient::new(&e, &contract_b_id); let a = Address::generate(&e); @@ -336,11 +336,11 @@ mod test_b { fn test_with_real_contract_auth_approve() { let e = Env::default(); - let contract_a_id = e.register_contract(None, ContractA); - let contract_b_id = e.register_contract(None, ContractB); + let contract_a_id = e.register(ContractA, ()); + let contract_b_id = e.register(ContractB, ()); let client = ContractBClient::new(&e, &contract_b_id); - let a = e.register_contract(None, auth_approve::Contract); + let a = e.register(auth_approve::Contract, ()); let a_xdr: ScAddress = (&a).try_into().unwrap(); let r = client @@ -399,11 +399,11 @@ mod test_b { fn test_with_real_contract_auth_decline() { let e = Env::default(); - let contract_a_id = e.register_contract(None, ContractA); - let contract_b_id = e.register_contract(None, ContractB); + let contract_a_id = e.register(ContractA, ()); + let contract_b_id = e.register(ContractB, ()); let client = ContractBClient::new(&e, &contract_b_id); - let a = e.register_contract(None, auth_decline::Contract); + let a = e.register(auth_decline::Contract, ()); let a_xdr: ScAddress = (&a).try_into().unwrap(); let r = client diff --git a/tests/constructor/src/lib.rs b/tests/constructor/src/lib.rs index cdaa2a33f..3868bf933 100644 --- a/tests/constructor/src/lib.rs +++ b/tests/constructor/src/lib.rs @@ -37,7 +37,7 @@ impl Contract { #[test] fn test_constructor() { let env = Env::default(); - let contract_id = env.register_contract_with_constructor(None, Contract, (100_u32, 1000_i64)); + let contract_id = env.register(Contract, (100_u32, 1000_i64)); let client = ContractClient::new(&env, &contract_id); assert_eq!(client.get_data(&DataKey::Persistent(100)), Some(1000)); assert_eq!(client.get_data(&DataKey::Temp(200)), Some(2000)); @@ -52,26 +52,26 @@ fn test_constructor() { #[should_panic(expected = "constructor invocation has failed with error")] fn test_passing_no_constructor_arguments_causes_panic() { let env = Env::default(); - let _ = env.register_contract(None, Contract); + let _ = env.register(Contract, ()); } #[test] #[should_panic(expected = "constructor invocation has failed with error")] fn test_missing_constructor_arguments_causes_panic() { let env = Env::default(); - let _ = env.register_contract_with_constructor(None, Contract, (100_u32,)); + let _ = env.register(Contract, (100_u32,)); } #[test] #[should_panic(expected = "constructor invocation has failed with error")] fn test_passing_extra_constructor_arguments_causes_panic() { let env = Env::default(); - let _ = env.register_contract_with_constructor(None, Contract, (100_u32, 1000_i64, 123_u32)); + let _ = env.register(Contract, (100_u32, 1000_i64, 123_u32)); } #[test] #[should_panic(expected = "constructor invocation has failed with error")] fn test_passing_incorrectly_typed_constructor_arguments_causes_panic() { let env = Env::default(); - let _ = env.register_contract_with_constructor(None, Contract, (100_u32, 1000_u32)); + let _ = env.register(Contract, (100_u32, 1000_u32)); } diff --git a/tests/empty/src/lib.rs b/tests/empty/src/lib.rs index f8912a36d..27638b625 100644 --- a/tests/empty/src/lib.rs +++ b/tests/empty/src/lib.rs @@ -18,7 +18,7 @@ mod test { #[test] fn test_hello() { let e = Env::default(); - let contract_id = e.register_contract(None, Contract); + let contract_id = e.register(Contract, ()); let client = ContractClient::new(&e, &contract_id); client.empty(); diff --git a/tests/empty2/src/lib.rs b/tests/empty2/src/lib.rs index eac8bc747..e86d9cd36 100644 --- a/tests/empty2/src/lib.rs +++ b/tests/empty2/src/lib.rs @@ -16,7 +16,7 @@ mod test { #[test] fn test_hello() { let e = Env::default(); - let contract_id = e.register_contract(None, Contract); + let contract_id = e.register(Contract, ()); let _client = ContractClient::new(&e, &contract_id); } } diff --git a/tests/errors/src/lib.rs b/tests/errors/src/lib.rs index 4091cca10..dd18ece77 100644 --- a/tests/errors/src/lib.rs +++ b/tests/errors/src/lib.rs @@ -51,7 +51,7 @@ mod test { #[test] fn hello_ok() { let e = Env::default(); - let contract_id = e.register_contract(None, Contract); + let contract_id = e.register(Contract, ()); let client = ContractClient::new(&e, &contract_id); let res = client.hello(&0); @@ -62,7 +62,7 @@ mod test { #[test] fn try_hello_ok() { let e = Env::default(); - let contract_id = e.register_contract(None, Contract); + let contract_id = e.register(Contract, ()); let client = ContractClient::new(&e, &contract_id); let res = client.try_hello(&0); @@ -73,7 +73,7 @@ mod test { #[test] fn try_hello_error() { let e = Env::default(); - let contract_id = e.register_contract(None, Contract); + let contract_id = e.register(Contract, ()); let client = ContractClient::new(&e, &contract_id); let res = client.try_hello(&1); @@ -84,7 +84,7 @@ mod test { #[test] fn try_hello_error_panic() { let e = Env::default(); - let contract_id = e.register_contract(None, Contract); + let contract_id = e.register(Contract, ()); let client = ContractClient::new(&e, &contract_id); let res = client.try_hello(&2); @@ -95,7 +95,7 @@ mod test { #[test] fn try_hello_error_panic_string() { let e = Env::default(); - let contract_id = e.register_contract(None, Contract); + let contract_id = e.register(Contract, ()); let client = ContractClient::new(&e, &contract_id); let res = client.try_hello(&3); @@ -106,7 +106,7 @@ mod test { #[test] fn try_hello_error_unexpected_contract_error() { let e = Env::default(); - let contract_id = e.register_contract(None, Contract); + let contract_id = e.register(Contract, ()); let client = ContractClient::new(&e, &contract_id); let res = client.try_hello(&4); diff --git a/tests/events/src/lib.rs b/tests/events/src/lib.rs index c0b2b41f6..00748d182 100644 --- a/tests/events/src/lib.rs +++ b/tests/events/src/lib.rs @@ -28,7 +28,7 @@ mod test { #[test] fn test_pub_event() { let env = Env::default(); - let contract_id = env.register_contract(None, Contract); + let contract_id = env.register(Contract, ()); let client = ContractClient::new(&env, &contract_id); client.hello(); diff --git a/tests/fuzz/fuzz/fuzz_targets/fuzz_target_1.rs b/tests/fuzz/fuzz/fuzz_targets/fuzz_target_1.rs index 9cfed4463..04025122e 100644 --- a/tests/fuzz/fuzz/fuzz_targets/fuzz_target_1.rs +++ b/tests/fuzz/fuzz/fuzz_targets/fuzz_target_1.rs @@ -2,7 +2,10 @@ use libfuzzer_sys::fuzz_target; -use soroban_sdk::{testutils::arbitrary::{arbitrary,Arbitrary,SorobanArbitrary}, Env, IntoVal, U256}; +use soroban_sdk::{ + testutils::arbitrary::{arbitrary, Arbitrary, SorobanArbitrary}, + Env, IntoVal, U256, +}; use test_fuzz::{Contract, ContractClient}; @@ -18,7 +21,7 @@ fuzz_target!(|input: Input| { let a: U256 = input.a.into_val(&env); let b: U256 = input.b.into_val(&env); - let contract_id = env.register_contract(None, Contract); + let contract_id = env.register(Contract, ()); let client = ContractClient::new(&env, &contract_id); let _ = client.run(&a, &b); diff --git a/tests/import_contract/src/lib.rs b/tests/import_contract/src/lib.rs index 7ce18bafa..19daa3de2 100644 --- a/tests/import_contract/src/lib.rs +++ b/tests/import_contract/src/lib.rs @@ -26,9 +26,9 @@ mod test { #[test] fn test_add() { let e = Env::default(); - let add_contract_id = e.register_contract_wasm(None, addcontract::WASM); + let add_contract_id = e.register(addcontract::WASM, ()); - let contract_id = e.register_contract(None, Contract); + let contract_id = e.register(Contract, ()); let client = ContractClient::new(&e, &contract_id); let x = 10u64; diff --git a/tests/invoke_contract/src/lib.rs b/tests/invoke_contract/src/lib.rs index c1e1801f4..7450bd6c0 100644 --- a/tests/invoke_contract/src/lib.rs +++ b/tests/invoke_contract/src/lib.rs @@ -36,9 +36,9 @@ mod test { fn test_add() { let e = Env::default(); - let add_contract_id = e.register_contract(None, AddContract); + let add_contract_id = e.register(AddContract, ()); - let contract_id = e.register_contract(None, Contract); + let contract_id = e.register(Contract, ()); let client = ContractClient::new(&e, &contract_id); let x = 10i32; diff --git a/tests/logging/src/lib.rs b/tests/logging/src/lib.rs index 83b4c8a08..99d498bdd 100644 --- a/tests/logging/src/lib.rs +++ b/tests/logging/src/lib.rs @@ -37,7 +37,7 @@ mod test { #[test] fn test_logging() { let env = Env::default(); - let contract_id = env.register_contract(None, Contract); + let contract_id = env.register(Contract, ()); let client = ContractClient::new(&env, &contract_id); client.hello(); diff --git a/tests/modular/src/test.rs b/tests/modular/src/test.rs index 74988fe18..c8677d5ff 100644 --- a/tests/modular/src/test.rs +++ b/tests/modular/src/test.rs @@ -7,7 +7,7 @@ use soroban_sdk::Env; fn test() { let env = Env::default(); - let id = env.register_contract(None, Contract); + let id = env.register(Contract, ()); let client = ContractClient::new(&env, &id); assert_eq!(client.zero(), 0); diff --git a/tests/multiimpl/src/lib.rs b/tests/multiimpl/src/lib.rs index e9c578ef5..976f911ae 100644 --- a/tests/multiimpl/src/lib.rs +++ b/tests/multiimpl/src/lib.rs @@ -32,7 +32,7 @@ mod test { #[test] fn test_hello() { let e = Env::default(); - let contract_id = e.register_contract(None, Contract); + let contract_id = e.register(Contract, ()); let client = ContractClient::new(&e, &contract_id); client.empty(); diff --git a/tests/udt/src/lib.rs b/tests/udt/src/lib.rs index 2b4c640b2..7ac903344 100644 --- a/tests/udt/src/lib.rs +++ b/tests/udt/src/lib.rs @@ -79,7 +79,7 @@ mod test { #[test] fn test_add() { let e = Env::default(); - let contract_id = e.register_contract(None, Contract); + let contract_id = e.register(Contract, ()); let client = ContractClient::new(&e, &contract_id); let udt = UdtStruct { diff --git a/tests/workspace_contract/src/lib.rs b/tests/workspace_contract/src/lib.rs index 864c51c54..a62c353a9 100644 --- a/tests/workspace_contract/src/lib.rs +++ b/tests/workspace_contract/src/lib.rs @@ -22,7 +22,7 @@ mod test { fn test_add() { let e = Env::default(); - let contract_id = e.register_contract(None, Contract); + let contract_id = e.register(Contract, ()); let client = ContractClient::new(&e, &contract_id); let z = client.value(); From 8fc9f5334dece34b6baab31261a7773295746235 Mon Sep 17 00:00:00 2001 From: Leigh McCulloch <351529+leighmcculloch@users.noreply.github.com> Date: Fri, 27 Sep 2024 07:40:11 +1000 Subject: [PATCH 2/4] Add infallible From conversions for types to ScVal (#1338) ### What Add infallible From conversions for types to ScVal, replacing the existing fallible TryFrom conversions. ### Why When I look through tests I see lots of `try_into().unwrap()` when converting types to their ScVal values. This is unnecessary, we know that the conversions will succeed because the host won't give the SDK types that aren't valid and couldn't be converted. It's just a result of the way the Rust types are setup we can't guarantee the type is always convertible, but in practice they are. Note that this is _not_ really a breaking change, because in the Rust core lib there is a blanket impl for all From conversions to also provide a TryFrom conversion. The only behaviour change is that if there were cases that would fail conversion previously a panic will occur instead of an error when using a TryFrom to do the conversion. In all cases there is no expected failure because the Env guarantees valid host types to be created and we're converting host types to ScVal types. --- soroban-sdk/src/address.rs | 37 ++++++++++++++++---------------- soroban-sdk/src/bytes.rs | 19 +++++++++------- soroban-sdk/src/map.rs | 21 ++++++++++-------- soroban-sdk/src/num.rs | 21 ++++++++++-------- soroban-sdk/src/string.rs | 19 +++++++++------- soroban-sdk/src/symbol.rs | 25 ++++++++++++---------- soroban-sdk/src/vec.rs | 44 +++++++++++++++++++------------------- 7 files changed, 101 insertions(+), 85 deletions(-) diff --git a/soroban-sdk/src/address.rs b/soroban-sdk/src/address.rs index dfed7f87a..e735a6f23 100644 --- a/soroban-sdk/src/address.rs +++ b/soroban-sdk/src/address.rs @@ -124,18 +124,21 @@ impl TryFromVal for Val { } #[cfg(not(target_family = "wasm"))] -impl TryFrom<&Address> for ScVal { - type Error = ConversionError; - fn try_from(v: &Address) -> Result { - Ok(ScVal::try_from_val(&v.env, &v.obj.to_val())?) +impl From<&Address> for ScVal { + fn from(v: &Address) -> Self { + // This conversion occurs only in test utilities, and theoretically all + // values should convert to an ScVal because the Env won't let the host + // type to exist otherwise, unwrapping. Even if there are edge cases + // that don't, this is a trade off for a better test developer + // experience. + ScVal::try_from_val(&v.env, &v.obj.to_val()).unwrap() } } #[cfg(not(target_family = "wasm"))] -impl TryFrom
for ScVal { - type Error = ConversionError; - fn try_from(v: Address) -> Result { - (&v).try_into() +impl From
for ScVal { + fn from(v: Address) -> Self { + (&v).into() } } @@ -152,21 +155,19 @@ impl TryFromVal for Address { } #[cfg(not(target_family = "wasm"))] -impl TryFrom<&Address> for ScAddress { - type Error = ConversionError; - fn try_from(v: &Address) -> Result { - match ScVal::try_from_val(&v.env, &v.obj.to_val())? { - ScVal::Address(a) => Ok(a), - _ => Err(ConversionError), +impl From<&Address> for ScAddress { + fn from(v: &Address) -> Self { + match ScVal::try_from_val(&v.env, &v.obj.to_val()).unwrap() { + ScVal::Address(a) => a, + _ => panic!("expected ScVal::Address"), } } } #[cfg(not(target_family = "wasm"))] -impl TryFrom
for ScAddress { - type Error = ConversionError; - fn try_from(v: Address) -> Result { - (&v).try_into() +impl From
for ScAddress { + fn from(v: Address) -> Self { + (&v).into() } } diff --git a/soroban-sdk/src/bytes.rs b/soroban-sdk/src/bytes.rs index 1605341bd..b654d66a9 100644 --- a/soroban-sdk/src/bytes.rs +++ b/soroban-sdk/src/bytes.rs @@ -232,18 +232,21 @@ impl From<&Bytes> for Bytes { } #[cfg(not(target_family = "wasm"))] -impl TryFrom<&Bytes> for ScVal { - type Error = ConversionError; - fn try_from(v: &Bytes) -> Result { - Ok(ScVal::try_from_val(&v.env, &v.obj.to_val())?) +impl From<&Bytes> for ScVal { + fn from(v: &Bytes) -> Self { + // This conversion occurs only in test utilities, and theoretically all + // values should convert to an ScVal because the Env won't let the host + // type to exist otherwise, unwrapping. Even if there are edge cases + // that don't, this is a trade off for a better test developer + // experience. + ScVal::try_from_val(&v.env, &v.obj.to_val()).unwrap() } } #[cfg(not(target_family = "wasm"))] -impl TryFrom for ScVal { - type Error = ConversionError; - fn try_from(v: Bytes) -> Result { - (&v).try_into() +impl From for ScVal { + fn from(v: Bytes) -> Self { + (&v).into() } } diff --git a/soroban-sdk/src/map.rs b/soroban-sdk/src/map.rs index cf0f3877f..05582a77f 100644 --- a/soroban-sdk/src/map.rs +++ b/soroban-sdk/src/map.rs @@ -225,18 +225,21 @@ where } #[cfg(not(target_family = "wasm"))] -impl TryFrom<&Map> for ScVal { - type Error = ConversionError; - fn try_from(v: &Map) -> Result { - Ok(ScVal::try_from_val(&v.env, &v.obj.to_val())?) +impl From<&Map> for ScVal { + fn from(v: &Map) -> Self { + // This conversion occurs only in test utilities, and theoretically all + // values should convert to an ScVal because the Env won't let the host + // type to exist otherwise, unwrapping. Even if there are edge cases + // that don't, this is a trade off for a better test developer + // experience. + ScVal::try_from_val(&v.env, &v.obj.to_val()).unwrap() } } #[cfg(not(target_family = "wasm"))] -impl TryFrom> for ScVal { - type Error = ConversionError; - fn try_from(v: Map) -> Result { - (&v).try_into() +impl From> for ScVal { + fn from(v: Map) -> Self { + (&v).into() } } @@ -244,7 +247,7 @@ impl TryFrom> for ScVal { impl TryFromVal> for ScVal { type Error = ConversionError; fn try_from_val(_e: &Env, v: &Map) -> Result { - v.try_into() + Ok(v.into()) } } diff --git a/soroban-sdk/src/num.rs b/soroban-sdk/src/num.rs index 1071943e6..d3f69cbde 100644 --- a/soroban-sdk/src/num.rs +++ b/soroban-sdk/src/num.rs @@ -89,22 +89,25 @@ macro_rules! impl_num_wrapping_val_type { } #[cfg(not(target_family = "wasm"))] - impl TryFrom<&$wrapper> for ScVal { - type Error = ConversionError; - fn try_from(v: &$wrapper) -> Result { + impl From<&$wrapper> for ScVal { + fn from(v: &$wrapper) -> Self { + // This conversion occurs only in test utilities, and theoretically all + // values should convert to an ScVal because the Env won't let the host + // type to exist otherwise, unwrapping. Even if there are edge cases + // that don't, this is a trade off for a better test developer + // experience. if let Ok(ss) = <$small>::try_from(v.val) { - ScVal::try_from(ss) + ScVal::try_from(ss).unwrap() } else { - Ok(ScVal::try_from_val(&v.env, &v.to_val())?) + ScVal::try_from_val(&v.env, &v.to_val()).unwrap() } } } #[cfg(not(target_family = "wasm"))] - impl TryFrom<$wrapper> for ScVal { - type Error = ConversionError; - fn try_from(v: $wrapper) -> Result { - (&v).try_into() + impl From<$wrapper> for ScVal { + fn from(v: $wrapper) -> Self { + (&v).into() } } diff --git a/soroban-sdk/src/string.rs b/soroban-sdk/src/string.rs index 1c48ecb30..671624865 100644 --- a/soroban-sdk/src/string.rs +++ b/soroban-sdk/src/string.rs @@ -137,18 +137,21 @@ impl From<&String> for String { } #[cfg(not(target_family = "wasm"))] -impl TryFrom<&String> for ScVal { - type Error = ConversionError; - fn try_from(v: &String) -> Result { - Ok(ScVal::try_from_val(&v.env, &v.obj.to_val())?) +impl From<&String> for ScVal { + fn from(v: &String) -> Self { + // This conversion occurs only in test utilities, and theoretically all + // values should convert to an ScVal because the Env won't let the host + // type to exist otherwise, unwrapping. Even if there are edge cases + // that don't, this is a trade off for a better test developer + // experience. + ScVal::try_from_val(&v.env, &v.obj.to_val()).unwrap() } } #[cfg(not(target_family = "wasm"))] -impl TryFrom for ScVal { - type Error = ConversionError; - fn try_from(v: String) -> Result { - (&v).try_into() +impl From for ScVal { + fn from(v: String) -> Self { + (&v).into() } } diff --git a/soroban-sdk/src/symbol.rs b/soroban-sdk/src/symbol.rs index 7f11fd3be..6389d382b 100644 --- a/soroban-sdk/src/symbol.rs +++ b/soroban-sdk/src/symbol.rs @@ -136,23 +136,26 @@ impl TryFromVal for Symbol { } #[cfg(not(target_family = "wasm"))] -impl TryFrom<&Symbol> for ScVal { - type Error = ConversionError; - fn try_from(v: &Symbol) -> Result { +impl From<&Symbol> for ScVal { + fn from(v: &Symbol) -> Self { + // This conversion occurs only in test utilities, and theoretically all + // values should convert to an ScVal because the Env won't let the host + // type to exist otherwise, unwrapping. Even if there are edge cases + // that don't, this is a trade off for a better test developer + // experience. if let Ok(ss) = SymbolSmall::try_from(v.val) { - Ok(ScVal::try_from(ss)?) + ScVal::try_from(ss).unwrap() } else { - let e: Env = v.env.clone().try_into()?; - Ok(ScVal::try_from_val(&e, &v.to_val())?) + let e: Env = v.env.clone().try_into().unwrap(); + ScVal::try_from_val(&e, &v.to_val()).unwrap() } } } #[cfg(not(target_family = "wasm"))] -impl TryFrom for ScVal { - type Error = ConversionError; - fn try_from(v: Symbol) -> Result { - (&v).try_into() +impl From for ScVal { + fn from(v: Symbol) -> Self { + (&v).into() } } @@ -160,7 +163,7 @@ impl TryFrom for ScVal { impl TryFromVal for ScVal { type Error = ConversionError; fn try_from_val(_e: &Env, v: &Symbol) -> Result { - v.try_into() + Ok(v.into()) } } diff --git a/soroban-sdk/src/vec.rs b/soroban-sdk/src/vec.rs index 46f66bc9b..d7ae8eefb 100644 --- a/soroban-sdk/src/vec.rs +++ b/soroban-sdk/src/vec.rs @@ -231,46 +231,46 @@ where use super::xdr::{ScVal, ScVec, VecM}; #[cfg(not(target_family = "wasm"))] -impl TryFrom<&Vec> for ScVal { - type Error = ConversionError; - fn try_from(v: &Vec) -> Result { - Ok(ScVal::try_from_val(&v.env, &v.obj.to_val())?) +impl From<&Vec> for ScVal { + fn from(v: &Vec) -> Self { + // This conversion occurs only in test utilities, and theoretically all + // values should convert to an ScVal because the Env won't let the host + // type to exist otherwise, unwrapping. Even if there are edge cases + // that don't, this is a trade off for a better test developer + // experience. + ScVal::try_from_val(&v.env, &v.obj.to_val()).unwrap() } } #[cfg(not(target_family = "wasm"))] -impl TryFrom<&Vec> for ScVec { - type Error = ConversionError; - fn try_from(v: &Vec) -> Result { - if let ScVal::Vec(Some(vec)) = ScVal::try_from(v)? { - Ok(vec) +impl From<&Vec> for ScVec { + fn from(v: &Vec) -> Self { + if let ScVal::Vec(Some(vec)) = ScVal::try_from(v).unwrap() { + vec } else { - Err(ConversionError) + panic!("expected ScVec") } } } #[cfg(not(target_family = "wasm"))] -impl TryFrom> for VecM { - type Error = ConversionError; - fn try_from(v: Vec) -> Result { - Ok(ScVec::try_from(v)?.0) +impl From> for VecM { + fn from(v: Vec) -> Self { + ScVec::from(v).0 } } #[cfg(not(target_family = "wasm"))] -impl TryFrom> for ScVal { - type Error = ConversionError; - fn try_from(v: Vec) -> Result { - (&v).try_into() +impl From> for ScVal { + fn from(v: Vec) -> Self { + (&v).into() } } #[cfg(not(target_family = "wasm"))] -impl TryFrom> for ScVec { - type Error = ConversionError; - fn try_from(v: Vec) -> Result { - (&v).try_into() +impl From> for ScVec { + fn from(v: Vec) -> Self { + (&v).into() } } From 627e1643cabb49ec2d2648937a4d2a5e5c2cab3b Mon Sep 17 00:00:00 2001 From: Leigh McCulloch <351529+leighmcculloch@users.noreply.github.com> Date: Fri, 27 Sep 2024 10:49:49 +1000 Subject: [PATCH 3/4] Remove need for Copy on error enums (#1292) ### What Remove need for Copy/Clone/etc on error enums and int enums. ### Why Less compiler errors for folks just getting started. The generated code currently requires that error enums impl the Copy trait because they use a copy within. That copy is unnecessary and this change removes it, removing the need for Copy to be derived on error enums. I was confident that the copy had been put there as an optimisation, but when I looked into the code that was relying on it I found not optimisation was in use. When I tried to add the optimisation, I couldn't find a contract size difference. A while ago we in https://github.com/stellar/rs-soroban-sdk/pull/1293 added better error messages for needing copy, which was a good fix at the time, I just think we can remove the need for this all together. Close #630 --- soroban-sdk-macros/src/derive_enum_int.rs | 9 +- .../src/derive_error_enum_int.rs | 17 +- soroban-sdk/src/tests.rs | 1 + .../src/tests/contract_udt_enum_error.rs | 57 +++++ .../src/tests/contractimport_with_error.rs | 4 +- .../contract_udt_enum_error/test_error.1.json | 216 ++++++++++++++++++ .../test_success.1.json | 148 ++++++++++++ tests/errors/src/lib.rs | 41 ++-- 8 files changed, 464 insertions(+), 29 deletions(-) create mode 100644 soroban-sdk/src/tests/contract_udt_enum_error.rs create mode 100644 soroban-sdk/test_snapshots/tests/contract_udt_enum_error/test_error.1.json create mode 100644 soroban-sdk/test_snapshots/tests/contract_udt_enum_error/test_success.1.json diff --git a/soroban-sdk-macros/src/derive_enum_int.rs b/soroban-sdk-macros/src/derive_enum_int.rs index 6cc326c16..27e68b01a 100644 --- a/soroban-sdk-macros/src/derive_enum_int.rs +++ b/soroban-sdk-macros/src/derive_enum_int.rs @@ -94,7 +94,6 @@ pub fn derive_type_enum_int( // Output. let mut output = quote! { #spec_gen - const _: () = { fn assert_copy(v: #enum_ident) -> impl Copy { v } }; impl #path::TryFromVal<#path::Env, #path::Val> for #enum_ident { type Error = #path::ConversionError; @@ -144,7 +143,9 @@ pub fn derive_type_enum_int( type Error = #path::xdr::Error; #[inline(always)] fn try_into(self) -> Result<#path::xdr::ScVal, #path::xdr::Error> { - Ok((*self as u32).into()) + Ok(match self { + #(#try_intos,)* + }) } } @@ -152,7 +153,9 @@ pub fn derive_type_enum_int( type Error = #path::xdr::Error; #[inline(always)] fn try_into(self) -> Result<#path::xdr::ScVal, #path::xdr::Error> { - Ok((self as u32).into()) + Ok(match self { + #(#try_intos,)* + }) } } diff --git a/soroban-sdk-macros/src/derive_error_enum_int.rs b/soroban-sdk-macros/src/derive_error_enum_int.rs index bfa45f301..fd1dd9016 100644 --- a/soroban-sdk-macros/src/derive_error_enum_int.rs +++ b/soroban-sdk-macros/src/derive_error_enum_int.rs @@ -92,7 +92,6 @@ pub fn derive_type_error_enum_int( // Output. quote! { #spec_gen - const _: () = { fn assert_copy(v: #enum_ident) -> impl Copy { v } }; impl TryFrom<#path::Error> for #enum_ident { type Error = #path::Error; @@ -121,16 +120,16 @@ pub fn derive_type_error_enum_int( impl From<#enum_ident> for #path::Error { #[inline(always)] fn from(val: #enum_ident) -> #path::Error { - match val { - #(#into_errors,)* - } + <_ as From<&#enum_ident>>::from(&val) } } impl From<&#enum_ident> for #path::Error { #[inline(always)] fn from(val: &#enum_ident) -> #path::Error { - <_ as From<#enum_ident>>::from(*val) + match val { + #(#into_errors,)* + } } } @@ -159,16 +158,16 @@ pub fn derive_type_error_enum_int( impl From<#enum_ident> for #path::InvokeError { #[inline(always)] fn from(val: #enum_ident) -> #path::InvokeError { - match val { - #(#into_invoke_errors,)* - } + <_ as From<&#enum_ident>>::from(&val) } } impl From<&#enum_ident> for #path::InvokeError { #[inline(always)] fn from(val: &#enum_ident) -> #path::InvokeError { - <_ as From<#enum_ident>>::from(*val) + match val { + #(#into_invoke_errors,)* + } } } diff --git a/soroban-sdk/src/tests.rs b/soroban-sdk/src/tests.rs index 6cb330d43..468ee5111 100644 --- a/soroban-sdk/src/tests.rs +++ b/soroban-sdk/src/tests.rs @@ -17,6 +17,7 @@ mod contract_snapshot; mod contract_store; mod contract_timepoint; mod contract_udt_enum; +mod contract_udt_enum_error; mod contract_udt_option; mod contract_udt_struct; mod contract_udt_struct_tuple; diff --git a/soroban-sdk/src/tests/contract_udt_enum_error.rs b/soroban-sdk/src/tests/contract_udt_enum_error.rs new file mode 100644 index 000000000..fbe61034f --- /dev/null +++ b/soroban-sdk/src/tests/contract_udt_enum_error.rs @@ -0,0 +1,57 @@ +use crate::{self as soroban_sdk}; +use soroban_sdk::{contract, contracterror, contractimpl, contracttype, Env}; + +#[contract] +pub struct Contract; + +#[contracttype] +pub enum Flag { + A = 0, + B = 1, +} + +#[contracterror] +pub enum Error { + AnError = 1, +} + +#[contractimpl] +impl Contract { + pub fn f(flag: Flag) -> Result<(), Error> { + match flag { + Flag::A => Ok(()), + Flag::B => Err(Error::AnError), + } + } +} + +// The assertions in the following tests intentionally don't use assert_eq, and +// unwraps the object using Rust's pattern matching, so that no derives like +// Debug, Eq, PartialEq, etc are required on the error enum type because this +// test serves to ensure that none of the generated code for the error type or +// the client that uses it is dependent on derives that may or may not be +// available. + +#[test] +fn test_success() { + let env = Env::default(); + let contract_id = env.register(Contract, ()); + let client = ContractClient::new(&env, &contract_id); + + // See comment above about why this assertion is a match. + let Ok(Ok(())) = client.try_f(&Flag::A) else { + panic!("unexpected value returned"); + }; +} + +#[test] +fn test_error() { + let env = Env::default(); + let contract_id = env.register(Contract, ()); + let client = ContractClient::new(&env, &contract_id); + + // See comment above about why this assertion is a match. + let Err(Ok(Error::AnError)) = client.try_f(&Flag::B) else { + panic!("unexpected value returned"); + }; +} diff --git a/soroban-sdk/src/tests/contractimport_with_error.rs b/soroban-sdk/src/tests/contractimport_with_error.rs index 13ab9e69b..fba3aa1f3 100644 --- a/soroban-sdk/src/tests/contractimport_with_error.rs +++ b/soroban-sdk/src/tests/contractimport_with_error.rs @@ -13,7 +13,7 @@ pub struct Contract; #[contractimpl] impl Contract { - pub fn hello_with(env: Env, contract_id: Address, flag: u32) -> Symbol { + pub fn hello_with(env: Env, contract_id: Address, flag: errcontract::Flag) -> Symbol { errcontract::Client::new(&env, &contract_id).hello(&flag) } } @@ -27,6 +27,6 @@ fn test_functional() { let contract_id = e.register(Contract, ()); let client = ContractClient::new(&e, &contract_id); - let z = client.hello_with(&err_contract_id, &0); + let z = client.hello_with(&err_contract_id, &errcontract::Flag::A); assert!(z == symbol_short!("hello")); } diff --git a/soroban-sdk/test_snapshots/tests/contract_udt_enum_error/test_error.1.json b/soroban-sdk/test_snapshots/tests/contract_udt_enum_error/test_error.1.json new file mode 100644 index 000000000..4d0c8fda5 --- /dev/null +++ b/soroban-sdk/test_snapshots/tests/contract_udt_enum_error/test_error.1.json @@ -0,0 +1,216 @@ +{ + "generators": { + "address": 1, + "nonce": 0 + }, + "auth": [ + [], + [] + ], + "ledger": { + "protocol_version": 22, + "sequence_number": 0, + "timestamp": 0, + "network_id": "0000000000000000000000000000000000000000000000000000000000000000", + "base_reserve": 0, + "min_persistent_entry_ttl": 4096, + "min_temp_entry_ttl": 16, + "max_entry_ttl": 6312000, + "ledger_entries": [ + [ + { + "contract_data": { + "contract": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD2KM", + "key": "ledger_key_contract_instance", + "durability": "persistent" + } + }, + [ + { + "last_modified_ledger_seq": 0, + "data": { + "contract_data": { + "ext": "v0", + "contract": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD2KM", + "key": "ledger_key_contract_instance", + "durability": "persistent", + "val": { + "contract_instance": { + "executable": { + "wasm": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" + }, + "storage": null + } + } + } + }, + "ext": "v0" + }, + 4095 + ] + ], + [ + { + "contract_code": { + "hash": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" + } + }, + [ + { + "last_modified_ledger_seq": 0, + "data": { + "contract_code": { + "ext": "v0", + "hash": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", + "code": "" + } + }, + "ext": "v0" + }, + 4095 + ] + ] + ] + }, + "events": [ + { + "event": { + "ext": "v0", + "contract_id": null, + "type_": "diagnostic", + "body": { + "v0": { + "topics": [ + { + "symbol": "fn_call" + }, + { + "bytes": "0000000000000000000000000000000000000000000000000000000000000001" + }, + { + "symbol": "__constructor" + } + ], + "data": "void" + } + } + }, + "failed_call": false + }, + { + "event": { + "ext": "v0", + "contract_id": null, + "type_": "diagnostic", + "body": { + "v0": { + "topics": [ + { + "symbol": "fn_call" + }, + { + "bytes": "0000000000000000000000000000000000000000000000000000000000000001" + }, + { + "symbol": "f" + } + ], + "data": { + "u32": 1 + } + } + } + }, + "failed_call": false + }, + { + "event": { + "ext": "v0", + "contract_id": "0000000000000000000000000000000000000000000000000000000000000001", + "type_": "diagnostic", + "body": { + "v0": { + "topics": [ + { + "symbol": "fn_return" + }, + { + "symbol": "f" + } + ], + "data": { + "error": { + "contract": 1 + } + } + } + } + }, + "failed_call": true + }, + { + "event": { + "ext": "v0", + "contract_id": "0000000000000000000000000000000000000000000000000000000000000001", + "type_": "diagnostic", + "body": { + "v0": { + "topics": [ + { + "symbol": "error" + }, + { + "error": { + "contract": 1 + } + } + ], + "data": { + "string": "escalating Ok(ScErrorType::Contract) frame-exit to Err" + } + } + } + }, + "failed_call": true + }, + { + "event": { + "ext": "v0", + "contract_id": null, + "type_": "diagnostic", + "body": { + "v0": { + "topics": [ + { + "symbol": "error" + }, + { + "error": { + "contract": 1 + } + } + ], + "data": { + "vec": [ + { + "string": "contract try_call failed" + }, + { + "symbol": "f" + }, + { + "vec": [ + { + "u32": 1 + } + ] + } + ] + } + } + } + }, + "failed_call": false + } + ] +} \ No newline at end of file diff --git a/soroban-sdk/test_snapshots/tests/contract_udt_enum_error/test_success.1.json b/soroban-sdk/test_snapshots/tests/contract_udt_enum_error/test_success.1.json new file mode 100644 index 000000000..17ed13020 --- /dev/null +++ b/soroban-sdk/test_snapshots/tests/contract_udt_enum_error/test_success.1.json @@ -0,0 +1,148 @@ +{ + "generators": { + "address": 1, + "nonce": 0 + }, + "auth": [ + [], + [] + ], + "ledger": { + "protocol_version": 22, + "sequence_number": 0, + "timestamp": 0, + "network_id": "0000000000000000000000000000000000000000000000000000000000000000", + "base_reserve": 0, + "min_persistent_entry_ttl": 4096, + "min_temp_entry_ttl": 16, + "max_entry_ttl": 6312000, + "ledger_entries": [ + [ + { + "contract_data": { + "contract": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD2KM", + "key": "ledger_key_contract_instance", + "durability": "persistent" + } + }, + [ + { + "last_modified_ledger_seq": 0, + "data": { + "contract_data": { + "ext": "v0", + "contract": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD2KM", + "key": "ledger_key_contract_instance", + "durability": "persistent", + "val": { + "contract_instance": { + "executable": { + "wasm": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" + }, + "storage": null + } + } + } + }, + "ext": "v0" + }, + 4095 + ] + ], + [ + { + "contract_code": { + "hash": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" + } + }, + [ + { + "last_modified_ledger_seq": 0, + "data": { + "contract_code": { + "ext": "v0", + "hash": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", + "code": "" + } + }, + "ext": "v0" + }, + 4095 + ] + ] + ] + }, + "events": [ + { + "event": { + "ext": "v0", + "contract_id": null, + "type_": "diagnostic", + "body": { + "v0": { + "topics": [ + { + "symbol": "fn_call" + }, + { + "bytes": "0000000000000000000000000000000000000000000000000000000000000001" + }, + { + "symbol": "__constructor" + } + ], + "data": "void" + } + } + }, + "failed_call": false + }, + { + "event": { + "ext": "v0", + "contract_id": null, + "type_": "diagnostic", + "body": { + "v0": { + "topics": [ + { + "symbol": "fn_call" + }, + { + "bytes": "0000000000000000000000000000000000000000000000000000000000000001" + }, + { + "symbol": "f" + } + ], + "data": { + "u32": 0 + } + } + } + }, + "failed_call": false + }, + { + "event": { + "ext": "v0", + "contract_id": "0000000000000000000000000000000000000000000000000000000000000001", + "type_": "diagnostic", + "body": { + "v0": { + "topics": [ + { + "symbol": "fn_return" + }, + { + "symbol": "f" + } + ], + "data": "void" + } + } + }, + "failed_call": false + } + ] +} \ No newline at end of file diff --git a/tests/errors/src/lib.rs b/tests/errors/src/lib.rs index dd18ece77..a18757674 100644 --- a/tests/errors/src/lib.rs +++ b/tests/errors/src/lib.rs @@ -1,32 +1,43 @@ #![no_std] use soroban_sdk::{ - contract, contracterror, contractimpl, panic_with_error, symbol_short, Env, Symbol, + contract, contracterror, contractimpl, contracttype, panic_with_error, symbol_short, Env, + Symbol, }; #[contract] pub struct Contract; +#[contracttype] +#[derive(PartialEq)] +pub enum Flag { + A = 0, + B = 1, + C = 2, + D = 3, + E = 4, +} + #[contracterror] -#[derive(Copy, Clone, Debug, Eq, PartialEq)] +#[derive(Debug, Eq, PartialEq)] pub enum Error { AnError = 1, } #[contractimpl] impl Contract { - pub fn hello(env: Env, flag: u32) -> Result { + pub fn hello(env: Env, flag: Flag) -> Result { env.storage() .persistent() .set(&symbol_short!("persisted"), &true); - if flag == 0 { + if flag == Flag::A { Ok(symbol_short!("hello")) - } else if flag == 1 { + } else if flag == Flag::B { Err(Error::AnError) - } else if flag == 2 { + } else if flag == Flag::C { panic_with_error!(&env, Error::AnError) - } else if flag == 3 { + } else if flag == Flag::D { panic!("an error") - } else if flag == 4 { + } else if flag == Flag::E { panic_with_error!(&env, soroban_sdk::Error::from_contract_error(9)) } else { unimplemented!() @@ -46,7 +57,7 @@ impl Contract { mod test { use soroban_sdk::{symbol_short, xdr, Env, InvokeError}; - use crate::{Contract, ContractClient, Error}; + use crate::{Contract, ContractClient, Error, Flag}; #[test] fn hello_ok() { @@ -54,7 +65,7 @@ mod test { let contract_id = e.register(Contract, ()); let client = ContractClient::new(&e, &contract_id); - let res = client.hello(&0); + let res = client.hello(&Flag::A); assert_eq!(res, symbol_short!("hello")); assert!(client.persisted()); } @@ -65,7 +76,7 @@ mod test { let contract_id = e.register(Contract, ()); let client = ContractClient::new(&e, &contract_id); - let res = client.try_hello(&0); + let res = client.try_hello(&Flag::A); assert_eq!(res, Ok(Ok(symbol_short!("hello")))); assert!(client.persisted()); } @@ -76,7 +87,7 @@ mod test { let contract_id = e.register(Contract, ()); let client = ContractClient::new(&e, &contract_id); - let res = client.try_hello(&1); + let res = client.try_hello(&Flag::B); assert_eq!(res, Err(Ok(Error::AnError))); assert!(!client.persisted()); } @@ -87,7 +98,7 @@ mod test { let contract_id = e.register(Contract, ()); let client = ContractClient::new(&e, &contract_id); - let res = client.try_hello(&2); + let res = client.try_hello(&Flag::C); assert_eq!(res, Err(Ok(Error::AnError))); assert!(!client.persisted()); } @@ -98,7 +109,7 @@ mod test { let contract_id = e.register(Contract, ()); let client = ContractClient::new(&e, &contract_id); - let res = client.try_hello(&3); + let res = client.try_hello(&Flag::D); assert_eq!(res, Err(Err(InvokeError::Abort))); assert!(!client.persisted()); } @@ -109,7 +120,7 @@ mod test { let contract_id = e.register(Contract, ()); let client = ContractClient::new(&e, &contract_id); - let res = client.try_hello(&4); + let res = client.try_hello(&Flag::E); assert_eq!(res, Err(Err(InvokeError::Contract(9)))); assert!(!client.persisted()); } From abbba125c6a3bd1708cb695e29b33225022c9392 Mon Sep 17 00:00:00 2001 From: Leigh McCulloch <351529+leighmcculloch@users.noreply.github.com> Date: Fri, 27 Sep 2024 14:20:00 +1000 Subject: [PATCH 4/4] Update env, xdr (#1351) ### What Update env, xdr ### Why Routine. And required by the stellar-cli. --- Cargo.lock | 327 ++++++++++++++++++++++------------ Cargo.toml | 10 +- deny.toml | 3 +- soroban-sdk-macros/Cargo.toml | 2 +- 4 files changed, 223 insertions(+), 119 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d5cd71e27..0e0e67143 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,21 +2,6 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "addr2line" -version = "0.21.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" -dependencies = [ - "gimli", -] - -[[package]] -name = "adler" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" - [[package]] name = "ahash" version = "0.8.11" @@ -54,43 +39,140 @@ dependencies = [ ] [[package]] -name = "arrayvec" -version = "0.7.6" +name = "ark-bls12-381" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" +checksum = "c775f0d12169cba7aae4caeb547bb6a50781c7449a8aa53793827c9ec4abf488" +dependencies = [ + "ark-ec", + "ark-ff", + "ark-serialize", + "ark-std", +] [[package]] -name = "autocfg" -version = "1.1.0" +name = "ark-ec" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +checksum = "defd9a439d56ac24968cca0571f598a61bc8c55f71d50a89cda591cb750670ba" +dependencies = [ + "ark-ff", + "ark-poly", + "ark-serialize", + "ark-std", + "derivative", + "hashbrown 0.13.2", + "itertools", + "num-traits", + "zeroize", +] [[package]] -name = "backtrace" -version = "0.3.69" +name = "ark-ff" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2089b7e3f35b9dd2d0ed921ead4f6d318c27680d4a5bd167b3ee120edb105837" +checksum = "ec847af850f44ad29048935519032c33da8aa03340876d351dfab5660d2966ba" dependencies = [ - "addr2line", - "cc", - "cfg-if", - "libc", - "miniz_oxide", - "object", - "rustc-demangle", + "ark-ff-asm", + "ark-ff-macros", + "ark-serialize", + "ark-std", + "derivative", + "digest", + "itertools", + "num-bigint", + "num-traits", + "paste", + "rustc_version", + "zeroize", ] [[package]] -name = "base16ct" -version = "0.2.0" +name = "ark-ff-asm" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" +checksum = "3ed4aa4fe255d0bc6d79373f7e31d2ea147bcf486cba1be5ba7ea85abdb92348" +dependencies = [ + "quote", + "syn 1.0.109", +] + +[[package]] +name = "ark-ff-macros" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7abe79b0e4288889c4574159ab790824d0033b9fdcb2a112a3182fac2e514565" +dependencies = [ + "num-bigint", + "num-traits", + "proc-macro2", + "quote", + "syn 1.0.109", +] [[package]] -name = "base32" +name = "ark-poly" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d320bfc44ee185d899ccbadfa8bc31aab923ce1558716e1997a1e74057fe86bf" +dependencies = [ + "ark-ff", + "ark-serialize", + "ark-std", + "derivative", + "hashbrown 0.13.2", +] + +[[package]] +name = "ark-serialize" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adb7b85a02b83d2f22f89bd5cac66c9c89474240cb6207cb1efc16d098e822a5" +dependencies = [ + "ark-serialize-derive", + "ark-std", + "digest", + "num-bigint", +] + +[[package]] +name = "ark-serialize-derive" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae3281bc6d0fd7e549af32b52511e1302185bd688fd3359fa36423346ff682ea" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "ark-std" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23ce669cd6c8588f79e15cf450314f9638f967fc5770ff1c7c1deb0925ea7cfa" +checksum = "94893f1e0c6eeab764ade8dc4c0db24caf4fe7cbbaafc0eba0a9030f447b5185" +dependencies = [ + "num-traits", + "rand", +] + +[[package]] +name = "arrayvec" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" + +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + +[[package]] +name = "base16ct" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" [[package]] name = "base64" @@ -161,7 +243,7 @@ dependencies = [ "num-bigint", "proc-macro2", "quote", - "syn", + "syn 2.0.39", ] [[package]] @@ -253,7 +335,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "37e366bff8cd32dd8754b0991fb66b279dc48f598c3a18914852a6673deef583" dependencies = [ "quote", - "syn", + "syn 2.0.39", ] [[package]] @@ -280,7 +362,7 @@ checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.39", ] [[package]] @@ -304,7 +386,7 @@ dependencies = [ "proc-macro2", "quote", "strsim", - "syn", + "syn 2.0.39", ] [[package]] @@ -315,9 +397,15 @@ checksum = "836a9bbc7ad63342d6d6e7b815ccab164bc77a2d95d84bc3117a8c0d5c98e2d5" dependencies = [ "darling_core", "quote", - "syn", + "syn 2.0.39", ] +[[package]] +name = "data-encoding" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8566979429cf69b49a5c740c60791108e86440e8be149bbea4fe54d2c32d6e2" + [[package]] name = "der" version = "0.7.8" @@ -338,6 +426,17 @@ dependencies = [ "serde", ] +[[package]] +name = "derivative" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "derive_arbitrary" version = "1.3.2" @@ -346,7 +445,7 @@ checksum = "67e77553c4162a157adbf834ebae5b415acbecbeafc7a74b0e886657506a7611" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.39", ] [[package]] @@ -375,9 +474,9 @@ checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650" [[package]] name = "ecdsa" -version = "0.16.7" +version = "0.16.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0997c976637b606099b9985693efa3581e84e41f5c11ba5255f88711058ad428" +checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" dependencies = [ "der", "digest", @@ -515,12 +614,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "gimli" -version = "0.28.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" - [[package]] name = "group" version = "0.13.0" @@ -538,6 +631,15 @@ version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" +[[package]] +name = "hashbrown" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" +dependencies = [ + "ahash", +] + [[package]] name = "hashbrown" version = "0.14.3" @@ -630,9 +732,9 @@ checksum = "8e04e2fd2b8188ea827b32ef11de88377086d690286ab35747ef7f9bf3ccb590" [[package]] name = "itertools" -version = "0.11.0" +version = "0.10.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1c173a5686ce8bfa551b3563d0c2170bf24ca44da99c7ca4bfdab5418c3fe57" +checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" dependencies = [ "either", ] @@ -654,9 +756,9 @@ dependencies = [ [[package]] name = "k256" -version = "0.13.1" +version = "0.13.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cadb76004ed8e97623117f3df85b17aaa6626ab0b0831e6573f104df16cd1bcc" +checksum = "f6e3919bbaa2945715f0bb6d3934a173d1e9a59ac23767fbaaef277265a7411b" dependencies = [ "cfg-if", "ecdsa", @@ -703,21 +805,6 @@ version = "0.4.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" -[[package]] -name = "memchr" -version = "2.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" - -[[package]] -name = "miniz_oxide" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7810e0be55b428ada41041c41f32c9f1a42817901b4ccf45fa3d4b6561e74c7" -dependencies = [ - "adler", -] - [[package]] name = "multi-stash" version = "0.2.0" @@ -743,7 +830,7 @@ checksum = "cfb77679af88f8b125209d354a202862602672222e7f2313fdd6dc349bad4712" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.39", ] [[package]] @@ -766,15 +853,6 @@ dependencies = [ "libm", ] -[[package]] -name = "object" -version = "0.32.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9cf5f9dd3933bd50a9e1f149ec995f39ae2c496d31fd772c1fd45ebc27e902b0" -dependencies = [ - "memchr", -] - [[package]] name = "once_cell" version = "1.18.0" @@ -838,7 +916,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae005bd773ab59b4725093fd7df83fd7892f7d8eafb48dbd7de6e024e4215f9d" dependencies = [ "proc-macro2", - "syn", + "syn 2.0.39", ] [[package]] @@ -968,12 +1046,6 @@ dependencies = [ "subtle", ] -[[package]] -name = "rustc-demangle" -version = "0.1.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" - [[package]] name = "rustc_version" version = "0.4.0" @@ -1050,7 +1122,7 @@ checksum = "d6c7207fbec9faa48073f3e3074cbe553af6ea512d7c21ba46e434e70ea9fbc1" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.39", ] [[package]] @@ -1090,7 +1162,7 @@ dependencies = [ "darling", "proc-macro2", "quote", - "syn", + "syn 2.0.39", ] [[package]] @@ -1133,18 +1205,18 @@ checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "soroban-builtin-sdk-macros" version = "22.0.0" -source = "git+https://github.com/stellar/rs-soroban-env?rev=75b782119942a4c8be8003f2901db38b30b6db2d#75b782119942a4c8be8003f2901db38b30b6db2d" +source = "git+https://github.com/stellar/rs-soroban-env?rev=60e9be87a157cc9b5132056e1314faabd485b5fb#60e9be87a157cc9b5132056e1314faabd485b5fb" dependencies = [ "itertools", "proc-macro2", "quote", - "syn", + "syn 2.0.39", ] [[package]] name = "soroban-env-common" version = "22.0.0" -source = "git+https://github.com/stellar/rs-soroban-env?rev=75b782119942a4c8be8003f2901db38b30b6db2d#75b782119942a4c8be8003f2901db38b30b6db2d" +source = "git+https://github.com/stellar/rs-soroban-env?rev=60e9be87a157cc9b5132056e1314faabd485b5fb#60e9be87a157cc9b5132056e1314faabd485b5fb" dependencies = [ "arbitrary", "crate-git-revision", @@ -1162,7 +1234,7 @@ dependencies = [ [[package]] name = "soroban-env-guest" version = "22.0.0" -source = "git+https://github.com/stellar/rs-soroban-env?rev=75b782119942a4c8be8003f2901db38b30b6db2d#75b782119942a4c8be8003f2901db38b30b6db2d" +source = "git+https://github.com/stellar/rs-soroban-env?rev=60e9be87a157cc9b5132056e1314faabd485b5fb#60e9be87a157cc9b5132056e1314faabd485b5fb" dependencies = [ "soroban-env-common", "static_assertions", @@ -1171,9 +1243,12 @@ dependencies = [ [[package]] name = "soroban-env-host" version = "22.0.0" -source = "git+https://github.com/stellar/rs-soroban-env?rev=75b782119942a4c8be8003f2901db38b30b6db2d#75b782119942a4c8be8003f2901db38b30b6db2d" +source = "git+https://github.com/stellar/rs-soroban-env?rev=60e9be87a157cc9b5132056e1314faabd485b5fb#60e9be87a157cc9b5132056e1314faabd485b5fb" dependencies = [ - "backtrace", + "ark-bls12-381", + "ark-ec", + "ark-ff", + "ark-serialize", "curve25519-dalek", "ecdsa", "ed25519-dalek", @@ -1203,7 +1278,7 @@ dependencies = [ [[package]] name = "soroban-env-macros" version = "22.0.0" -source = "git+https://github.com/stellar/rs-soroban-env?rev=75b782119942a4c8be8003f2901db38b30b6db2d#75b782119942a4c8be8003f2901db38b30b6db2d" +source = "git+https://github.com/stellar/rs-soroban-env?rev=60e9be87a157cc9b5132056e1314faabd485b5fb#60e9be87a157cc9b5132056e1314faabd485b5fb" dependencies = [ "itertools", "proc-macro2", @@ -1211,7 +1286,7 @@ dependencies = [ "serde", "serde_json", "stellar-xdr", - "syn", + "syn 2.0.39", ] [[package]] @@ -1266,7 +1341,7 @@ dependencies = [ "soroban-spec", "soroban-spec-rust", "stellar-xdr", - "syn", + "syn 2.0.39", ] [[package]] @@ -1291,7 +1366,7 @@ dependencies = [ "sha2", "soroban-spec", "stellar-xdr", - "syn", + "syn 2.0.39", "thiserror", ] @@ -1304,8 +1379,9 @@ dependencies = [ [[package]] name = "soroban-wasmi" -version = "0.36.0-soroban.22.0.0" -source = "git+https://github.com/stellar/wasmi?rev=122a74a7c491929e5ac9de876099154ef7c06d06#122a74a7c491929e5ac9de876099154ef7c06d06" +version = "0.36.1-soroban.22.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7044ea0ee6ff67039df1f232f0d3d98121f69a0409e944774912fc5f043c280f" dependencies = [ "arrayvec", "multi-stash", @@ -1342,19 +1418,19 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" [[package]] name = "stellar-strkey" -version = "0.0.8" +version = "0.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12d2bf45e114117ea91d820a846fd1afbe3ba7d717988fee094ce8227a3bf8bd" +checksum = "5e3aa3ed00e70082cb43febc1c2afa5056b9bb3e348bbb43d0cd0aa88a611144" dependencies = [ - "base32", "crate-git-revision", + "data-encoding", "thiserror", ] [[package]] name = "stellar-xdr" version = "22.0.0" -source = "git+https://github.com/stellar/rs-stellar-xdr?rev=39d7dbb0c12bd422ee43a6e2e3277789da4eaac8#39d7dbb0c12bd422ee43a6e2e3277789da4eaac8" +source = "git+https://github.com/stellar/rs-stellar-xdr?rev=67be5955a15f1d3a4df83fe86e6ae107f687141b#67be5955a15f1d3a4df83fe86e6ae107f687141b" dependencies = [ "arbitrary", "base64 0.13.1", @@ -1389,6 +1465,17 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + [[package]] name = "syn" version = "2.0.39" @@ -1578,7 +1665,7 @@ checksum = "266b2e40bc00e5a6c09c3584011e08b06f123c00362c92b975ba9843aaaa14b8" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.39", ] [[package]] @@ -1670,7 +1757,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn", + "syn 2.0.39", "wasm-bindgen-shared", ] @@ -1692,7 +1779,7 @@ checksum = "f0eb82fcb7930ae6219a7ecfd55b217f5f0893484b7a13022ebb2b2bf20b5283" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.39", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -1705,8 +1792,9 @@ checksum = "7ab9b36309365056cd639da3134bf87fa8f3d86008abf99e612384a6eecd459f" [[package]] name = "wasmi_collections" -version = "0.36.0-soroban.22.0.0" -source = "git+https://github.com/stellar/wasmi?rev=122a74a7c491929e5ac9de876099154ef7c06d06#122a74a7c491929e5ac9de876099154ef7c06d06" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d1ff23df2c456c8b5d9a0ae7eed03a40f0c4520466b4aa87135c5fc557476e8" dependencies = [ "ahash", "hashbrown 0.14.3", @@ -1715,8 +1803,9 @@ dependencies = [ [[package]] name = "wasmi_core" -version = "0.36.0-soroban.22.0.0" -source = "git+https://github.com/stellar/wasmi?rev=122a74a7c491929e5ac9de876099154ef7c06d06#122a74a7c491929e5ac9de876099154ef7c06d06" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac1b21ded145eb313d44a5895442c28e18904fb95718dc83893779f55945d342" dependencies = [ "downcast-rs", "libm", @@ -1907,7 +1996,7 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.39", ] [[package]] @@ -1915,3 +2004,17 @@ name = "zeroize" version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" +dependencies = [ + "zeroize_derive", +] + +[[package]] +name = "zeroize_derive" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.39", +] diff --git a/Cargo.toml b/Cargo.toml index 8ac1707fb..b0ffc52f4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,27 +26,27 @@ soroban-token-sdk = { version = "22.0.0-rc.1", path = "soroban-token-sdk" } [workspace.dependencies.soroban-env-common] version = "=22.0.0" git = "https://github.com/stellar/rs-soroban-env" -rev = "75b782119942a4c8be8003f2901db38b30b6db2d" +rev = "60e9be87a157cc9b5132056e1314faabd485b5fb" [workspace.dependencies.soroban-env-guest] version = "=22.0.0" git = "https://github.com/stellar/rs-soroban-env" -rev = "75b782119942a4c8be8003f2901db38b30b6db2d" +rev = "60e9be87a157cc9b5132056e1314faabd485b5fb" [workspace.dependencies.soroban-env-host] version = "=22.0.0" git = "https://github.com/stellar/rs-soroban-env" -rev = "75b782119942a4c8be8003f2901db38b30b6db2d" +rev = "60e9be87a157cc9b5132056e1314faabd485b5fb" [workspace.dependencies.stellar-strkey] -version = "=0.0.8" +version = "=0.0.9" [workspace.dependencies.stellar-xdr] version = "=22.0.0" default-features = false features = ["curr"] git = "https://github.com/stellar/rs-stellar-xdr" -rev = "39d7dbb0c12bd422ee43a6e2e3277789da4eaac8" +rev = "67be5955a15f1d3a4df83fe86e6ae107f687141b" #[patch."https://github.com/stellar/rs-soroban-env"] #soroban-env-common = { path = "../rs-soroban-env/soroban-env-common" } diff --git a/deny.toml b/deny.toml index b18f9481b..bfb266ad9 100644 --- a/deny.toml +++ b/deny.toml @@ -243,7 +243,8 @@ deny = [ # Certain crates/versions that will be skipped when doing duplicate detection. skip = [ - #{ name = "ansi_term", version = "=0.11.0" }, + { name = "hashbrown", version = "=0.13.2" }, + { name = "syn", version = "=1.0.109" }, ] # Similarly to `skip` allows you to skip certain crates during duplicate # detection. Unlike skip, it also includes the entire tree of transitive diff --git a/soroban-sdk-macros/Cargo.toml b/soroban-sdk-macros/Cargo.toml index 927ce56c5..3eb14e68a 100644 --- a/soroban-sdk-macros/Cargo.toml +++ b/soroban-sdk-macros/Cargo.toml @@ -26,7 +26,7 @@ stellar-xdr = { workspace = true, features = ["curr", "std"] } syn = {version="2.0",features=["full"]} quote = "1.0" proc-macro2 = "1.0" -itertools = "0.11.0" +itertools = "0.10.0" darling = "0.20.0" sha2 = "0.10.7"