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..2ee5fd3 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.3.1" +soroban-token-sdk = "22.0.0-rc.3.1" [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/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/lib.rs b/increment/src/lib.rs index 0a0d0f8..453605d 100644 --- a/increment/src/lib.rs +++ b/increment/src/lib.rs @@ -8,10 +8,19 @@ pub struct IncrementContract; #[contractimpl] impl IncrementContract { - /// Increment increments an internal counter, and returns the value. + /// Initialize the counter with a value + pub fn __constructor(env: Env, counter: u32) { + env.storage().instance().set(&COUNTER, &counter); + } + + /// Increment internal counter, return the value pub fn increment(env: Env) -> u32 { // Get the current count. - let mut count: u32 = env.storage().instance().get(&COUNTER).unwrap_or(0); // If no value set, assume 0. + let mut count: u32 = env + .storage() + .instance() + .get(&COUNTER) + .expect("counter not set!"); log!(&env, "count: {}", count); // Increment the count. @@ -29,6 +38,11 @@ impl IncrementContract { // Return the count to the caller. count } + + /// Get current counter value + pub fn get(env: Env) -> u32 { + env.storage().instance().get(&COUNTER).unwrap() + } } mod test; diff --git a/increment/src/test.rs b/increment/src/test.rs index 29ec9dc..cd07675 100644 --- a/increment/src/test.rs +++ b/increment/src/test.rs @@ -1,19 +1,20 @@ #![cfg(test)] use super::{IncrementContract, IncrementContractClient}; -use soroban_sdk::{testutils::Logs, Env}; +use soroban_sdk::{testutils::Logs, vec, xdr::ScVal, Env}; extern crate std; #[test] -fn test() { +fn construct_get_increment() { let env = Env::default(); - let contract_id = env.register_contract(None, IncrementContract); + let contract_id = env.register(IncrementContract, vec![&env, ScVal::U32(42)]); let client = IncrementContractClient::new(&env, &contract_id); - assert_eq!(client.increment(), 1); - assert_eq!(client.increment(), 2); - assert_eq!(client.increment(), 3); + assert_eq!(client.get(), 42); + assert_eq!(client.increment(), 43); + assert_eq!(client.increment(), 44); + assert_eq!(client.increment(), 45); std::println!("{}", env.logs().all().join("\n")); } 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)); }