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

Add a script to populate the Setter contract #52

Merged
merged 8 commits into from
May 15, 2024
Merged
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
18 changes: 15 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,23 @@ jobs:
- uses: actions/checkout@v3
- run: rustup update ${{ matrix.toolchain }} && rustup default ${{ matrix.toolchain }}
- run: rustup target add wasm32-unknown-unknown
- uses: stellar/binaries@v16
- uses: stellar/binaries@v22
with:
name: soroban-cli
version: 0.8.7
version: '20.0.0-rc.4.1'
# version 21 is not available in stellar/binaries yet
#version: '21.0.0-preview.1'
- name: build
run: cd ContractExamples && cargo build --verbose
- name: unit tests
run: cd ContractExamples && cargo test --verbose
run: cd ContractExamples && cargo test --verbose
# v21 is not available in stellar/binaries yet
#- name: populating Setter
# run: |
# soroban network add \
# --global testnet \
# --rpc-url https://soroban-testnet.stellar.org:443 \
# --network-passphrase "Test SDF Network ; September 2015"
# soroban keys generate --global alice --network testnet
# cd ContractExamples
# ./scripts/setter-populate.sh
2 changes: 1 addition & 1 deletion ContractExamples/contracts/setter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ fetcher.

## How to use

1. Make sure that you have installed Soroban by following the [Getting Started]
1. Make sure that you have installed Soroban by following the [Getting Started][]
guide.

1. Deploy the setter contract:
Expand Down
8 changes: 8 additions & 0 deletions ContractExamples/contracts/setter/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
#![no_std]
/**
* A test contract for better understanding of the ledger layout of Soroban contracts.
*
* Igor Konnov, 2024.
*
* @license
* [Apache-2.0](https://github.com/freespek/solarkraft/blob/main/LICENSE)
*/

use soroban_sdk::{contract, contractimpl, contracttype, log, symbol_short, vec, Address, Bytes, BytesN, Env, Map, Symbol, Vec};

Expand Down
8 changes: 8 additions & 0 deletions ContractExamples/contracts/setter/src/test.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
#![cfg(test)]
/**
* Unit tests for Setter.
*
* Igor Konnov, 2024.
*
* @license
* [Apache-2.0](https://github.com/freespek/solarkraft/blob/main/LICENSE)
*/

use super::*;
use soroban_sdk::{
Expand Down
59 changes: 59 additions & 0 deletions ContractExamples/scripts/setter-populate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/env bash
#
# Deploy the setter contract and populate its state with data.
#
# Igor Konnov, 2024
#
# @license
# [Apache-2.0](https://github.com/freespek/solarkraft/blob/main/LICENSE)


set -e

dir=$(cd `dirname $0`; pwd -P)

cd ${dir}/..

NET=testnet
(soroban network ls | grep -q $NET) || (echo "add testnet via soroban network"; exit 1)

ACCOUNT=alice
soroban keys address $ACCOUNT || (echo "add the account $ALICE via soroban keys generate"; exit 1)


set -x

soroban contract build
soroban contract deploy --wasm target/wasm32-unknown-unknown/release/setter.wasm \
--source $ACCOUNT --network $NET | tee >.setter.id

soroban contract invoke --id $(cat .setter.id) --source $ACCOUNT --network $NET \
-- set_bool --v true
soroban contract invoke --id $(cat .setter.id) --source $ACCOUNT --network $NET \
-- set_u32 --v 42
soroban contract invoke --id $(cat .setter.id) --source $ACCOUNT --network $NET \
-- set_i32 --v '-42'
soroban contract invoke --id $(cat .setter.id) --source $ACCOUNT --network $NET \
-- set_u64 --v 42
soroban contract invoke --id $(cat .setter.id) --source $ACCOUNT --network $NET \
-- set_i64 --v '-42'
soroban contract invoke --id $(cat .setter.id) --source $ACCOUNT --network $NET \
-- set_u128 --v 42
soroban contract invoke --id $(cat .setter.id) --source $ACCOUNT --network $NET \
-- set_i128 --v '-42'
soroban contract invoke --id $(cat .setter.id) --source $ACCOUNT --network $NET \
-- set_sym --v hello
soroban contract invoke --id $(cat .setter.id) --source $ACCOUNT --network $NET \
-- set_bytes --v beef
soroban contract invoke --id $(cat .setter.id) --source $ACCOUNT --network $NET \
-- set_bytes32 --v beef0123456789beef0123456789beef0123456789ab
soroban contract invoke --id $(cat .setter.id) --source $ACCOUNT --network $NET \
-- set_vec --v '[ 1, -2, 3 ]'
soroban contract invoke --id $(cat .setter.id) --source $ACCOUNT --network $NET \
-- set_map --v '{ "2": 3, "4": 5 }'
soroban contract invoke --id $(cat .setter.id) --source $ACCOUNT --network $NET \
-- set_address --v GDIY6AQQ75WMD4W46EYB7O6UYMHOCGQHLAQGQTKHDX4J2DYQCHVCR4W4
soroban contract invoke --id $(cat .setter.id) --source $ACCOUNT --network $NET \
-- set_my_struct --v '{ "a": 1, "b": "-100" }'
soroban contract invoke --id $(cat .setter.id) --source $ACCOUNT --network $NET \
-- set_my_enum --v A
Loading