Skip to content

Commit

Permalink
feat: add example contracts
Browse files Browse the repository at this point in the history
The `stellar contract init` command no longer works with
`--frontend-template` (stellar/stellar-cli#1625)

This means that templates like this one need to hard-code their own list
of contracts.
  • Loading branch information
chadoh committed Dec 9, 2024
1 parent 68bd0a8 commit 20e4435
Show file tree
Hide file tree
Showing 10 changed files with 3,409 additions and 0 deletions.
1,618 changes: 1,618 additions & 0 deletions contracts/hello_world/Cargo.lock

Large diffs are not rendered by default.

29 changes: 29 additions & 0 deletions contracts/hello_world/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[package]
name = "soroban-hello-world-contract"
version = "0.0.0"
edition = "2021"
publish = false

[lib]
crate-type = ["cdylib"]
doctest = false

[dependencies]
soroban-sdk = { version = "22.0.1" }

[dev-dependencies]
soroban-sdk = { version = "22.0.1", features = ["testutils"] }

[profile.release]
opt-level = "z"
overflow-checks = true
debug = 0
strip = "symbols"
debug-assertions = false
panic = "abort"
codegen-units = 1
lto = true

[profile.release-with-logs]
inherits = "release"
debug-assertions = true
16 changes: 16 additions & 0 deletions contracts/hello_world/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
default: build

all: test

test: build
cargo test

build:
stellar contract build
@ls -l target/wasm32-unknown-unknown/release/*.wasm

fmt:
cargo fmt --all

clean:
cargo clean
14 changes: 14 additions & 0 deletions contracts/hello_world/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#![no_std]
use soroban_sdk::{contract, contractimpl, vec, Env, String, Vec};

#[contract]
pub struct HelloContract;

#[contractimpl]
impl HelloContract {
pub fn hello(env: Env, to: String) -> Vec<String> {
vec![&env, String::from_str(&env, "Hello"), to]
}
}

mod test;
21 changes: 21 additions & 0 deletions 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(HelloContract, ());
let client = HelloContractClient::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"),
]
);
}
Loading

0 comments on commit 20e4435

Please sign in to comment.