diff --git a/soroban-hello-world/contracts/hello-world/src/test.rs b/soroban-hello-world/contracts/hello-world/src/test.rs new file mode 100644 index 000000000..af69a7ecb --- /dev/null +++ b/soroban-hello-world/contracts/hello-world/src/test.rs @@ -0,0 +1,21 @@ +#![cfg(test)] + +use super::*; +use soroban_sdk::{vec, Env, String}; + +#[test] +fn test() { + let env = Env::default(); + let contract_id = env.register_contract(None, Contract); + let client = ContractClient::new(&env, &contract_id); + + let words = client.hello(&String::from_str(&env, "Dev")); + assert_eq!( + words, + vec![ + &env, + String::from_str(&env, "Hello"), + String::from_str(&env, "Dev"), + ] + ); +} diff --git a/soroban-hello-world/contracts/increment/src/lib.rs b/soroban-hello-world/contracts/increment/src/lib.rs new file mode 100644 index 000000000..1e914d808 --- /dev/null +++ b/soroban-hello-world/contracts/increment/src/lib.rs @@ -0,0 +1,26 @@ +#![no_std] +use soroban_sdk::{contract, contractimpl, log, symbol_short, Env, Symbol}; + +const COUNTER: Symbol = symbol_short!("COUNTER"); + +#[contract] +pub struct Contract; + +#[contractimpl] +impl Contract { + pub fn increment(env: Env) -> u32 { + let mut count: u32 = env.storage().instance().get(&COUNTER).unwrap_or(0); + + count += 1; + + log!(&env, "count: {}", count); + + env.storage().instance().set(&COUNTER, &count); + + env.storage().instance().extend_tt1(100, 100); + + count + } +} + +mod test;