Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue #1406: Update lib.rs to see the expected output when deploying the Increment contract #1418

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions soroban-hello-world/contracts/hello-world/src/test.rs
Original file line number Diff line number Diff line change
@@ -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"),
]
);
}
26 changes: 26 additions & 0 deletions soroban-hello-world/contracts/increment/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;