diff --git a/.gitignore b/.gitignore index d01bd1a..1a1224b 100644 --- a/.gitignore +++ b/.gitignore @@ -18,4 +18,7 @@ Cargo.lock # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore # and can be added to the global gitignore or merged into this file. For a more nuclear # option (not recommended) you can uncomment the following to ignore the entire idea folder. -#.idea/ \ No newline at end of file +#.idea/ + +# soroban-sdk test snapshots; see https://developers.stellar.org/docs/build/guides/testing/detecting-changes-with-test-snapshots +test_snapshots diff --git a/Cargo.toml b/Cargo.toml index 7a44651..036cb5c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,8 +9,8 @@ exclude = [ ] [workspace.dependencies] -soroban-sdk = "21.6.0" -soroban-token-sdk = "21.6.0" +soroban-sdk = "22.0.0-rc.2" +soroban-token-sdk = "22.0.0-rc.2" [profile.release] opt-level = "z" diff --git a/atomic-swap/src/test.rs b/atomic-swap/src/test.rs index ba44cb9..2cc8d43 100644 --- a/atomic-swap/src/test.rs +++ b/atomic-swap/src/test.rs @@ -19,7 +19,7 @@ fn create_token_contract<'a>(e: &Env, admin: &Address) -> (TokenClient<'a>, Toke } fn create_atomic_swap_contract(e: &Env) -> AtomicSwapContractClient { - AtomicSwapContractClient::new(e, &e.register_contract(None, AtomicSwapContract {})) + AtomicSwapContractClient::new(e, &e.register(AtomicSwapContract {}, ())) } #[test] diff --git a/constructor-args/Cargo.toml b/constructor-args/Cargo.toml new file mode 100644 index 0000000..3d0bbe2 --- /dev/null +++ b/constructor-args/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "constructor-args" +version = "21.5.0" +authors = ["Stellar Development Foundation "] +license = "Apache-2.0" +edition = "2021" +publish = false + +[lib] +crate-type = ["cdylib"] +doctest = false + +[dependencies] +soroban-sdk = { workspace = true } + +[dev-dependencies] +soroban-sdk = { workspace = true, features = ["testutils"] } diff --git a/constructor-args/src/lib.rs b/constructor-args/src/lib.rs new file mode 100644 index 0000000..0d1ff7b --- /dev/null +++ b/constructor-args/src/lib.rs @@ -0,0 +1,20 @@ +#![no_std] +use soroban_sdk::{contract, contractimpl, symbol_short, Env, Symbol}; + +#[contract] +pub struct ImmutableCounter; +const COUNTER: Symbol = symbol_short!("COUNTER"); + +#[contractimpl] +impl ImmutableCounter { + /// Example constructor + pub fn __constructor(env: Env, counter: u32) { + env.storage().persistent().set(&COUNTER, &counter); + } + /// Counter value + pub fn counter(env: Env) -> u32 { + env.storage().persistent().get(&COUNTER).unwrap() + } +} + +mod test; diff --git a/constructor-args/src/test.rs b/constructor-args/src/test.rs new file mode 100644 index 0000000..38070c7 --- /dev/null +++ b/constructor-args/src/test.rs @@ -0,0 +1,12 @@ +#![cfg(test)] + +use super::*; +use soroban_sdk::{vec, xdr::ScVal, Env}; + +#[test] +fn constructor_args() { + let env = Env::default(); + let contract_id = env.register(ImmutableCounter, vec![&env, ScVal::U32(42)]); + let client = ImmutableCounterClient::new(&env, &contract_id); + assert_eq!(42u32, client.counter()); +} diff --git a/custom-types/src/test.rs b/custom-types/src/test.rs index 4756c2e..e5fdf36 100644 --- a/custom-types/src/test.rs +++ b/custom-types/src/test.rs @@ -6,7 +6,7 @@ use soroban_sdk::Env; #[test] fn test() { let env = Env::default(); - let contract_id = env.register_contract(None, CustomTypesContract); + let contract_id = env.register(CustomTypesContract, ()); let client = CustomTypesContractClient::new(&env, &contract_id); assert_eq!(client.u32_fail_on_even(&1), 1); } diff --git a/increment/src/test.rs b/increment/src/test.rs index 29ec9dc..5c17aa4 100644 --- a/increment/src/test.rs +++ b/increment/src/test.rs @@ -8,7 +8,7 @@ extern crate std; #[test] fn test() { let env = Env::default(); - let contract_id = env.register_contract(None, IncrementContract); + let contract_id = env.register(IncrementContract, ()); let client = IncrementContractClient::new(&env, &contract_id); assert_eq!(client.increment(), 1); diff --git a/needs-a-signature/src/test.rs b/needs-a-signature/src/test.rs index 791f060..a1f055d 100644 --- a/needs-a-signature/src/test.rs +++ b/needs-a-signature/src/test.rs @@ -10,8 +10,8 @@ fn test() { env.mock_all_auths(); let user = Address::generate(&env); - let contract_id = env.register_contract(None, SignedContract); - let signing_contract_id = env.register_contract(None, SigningContract); + let contract_id = env.register(SignedContract, ()); + let signing_contract_id = env.register(SigningContract, ()); let client = SignedContractClient::new(&env, &contract_id); let words = client.hello(&String::from_str(&env, "Dev"), &user, &signing_contract_id); diff --git a/this-one-signs/src/test.rs b/this-one-signs/src/test.rs index 39e8928..bec5694 100644 --- a/this-one-signs/src/test.rs +++ b/this-one-signs/src/test.rs @@ -6,7 +6,7 @@ use soroban_sdk::{vec, Env, String}; #[test] fn test() { let env = Env::default(); - let contract_id = env.register_contract(None, SigningContract); + let contract_id = env.register(SigningContract, ()); let client = SigningContractClient::new(&env, &contract_id); let words = client.hello(&String::from_str(&env, "Dev")); diff --git a/this-one-signs/test_snapshots/test/test.1.json b/this-one-signs/test_snapshots/test/test.1.json deleted file mode 100644 index 8334644..0000000 --- a/this-one-signs/test_snapshots/test/test.1.json +++ /dev/null @@ -1,132 +0,0 @@ -{ - "generators": { - "address": 1, - "nonce": 0 - }, - "auth": [ - [] - ], - "ledger": { - "protocol_version": 21, - "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": "hello" - } - ], - "data": { - "string": "Dev" - } - } - } - }, - "failed_call": false - }, - { - "event": { - "ext": "v0", - "contract_id": "0000000000000000000000000000000000000000000000000000000000000001", - "type_": "diagnostic", - "body": { - "v0": { - "topics": [ - { - "symbol": "fn_return" - }, - { - "symbol": "hello" - } - ], - "data": { - "vec": [ - { - "string": "Hello" - }, - { - "string": "Dev" - } - ] - } - } - } - }, - "failed_call": false - } - ] -} \ No newline at end of file diff --git a/token/src/test.rs b/token/src/test.rs index c3718c0..5597e37 100644 --- a/token/src/test.rs +++ b/token/src/test.rs @@ -9,7 +9,7 @@ use soroban_sdk::{ }; fn create_token<'a>(e: &Env, admin: &Address) -> TokenClient<'a> { - let token = TokenClient::new(e, &e.register_contract(None, Token {})); + let token = TokenClient::new(e, &e.register(Token {}, ())); token.initialize(admin, &7, &"name".into_val(e), &"symbol".into_val(e)); token } @@ -246,7 +246,7 @@ fn initialize_already_initialized() { fn decimal_is_over_eighteen() { let e = Env::default(); let admin = Address::generate(&e); - let token = TokenClient::new(&e, &e.register_contract(None, Token {})); + let token = TokenClient::new(&e, &e.register(Token {}, ())); token.initialize(&admin, &19, &"name".into_val(&e), &"symbol".into_val(&e)); }