Skip to content

Commit

Permalink
build: new e2e tests copied from cli ts-tests
Browse files Browse the repository at this point in the history
This test setup is a little silly right now, using the contract client
generated from today's `soroban contract bindings typescript` command
rather than the contract client that was just added to `contract_spec`.
This is just to make sure everything is hooked up right before we start
moving logic around.
  • Loading branch information
chadoh committed Dec 12, 2023
1 parent 4a5c925 commit 64987d4
Show file tree
Hide file tree
Showing 22 changed files with 4,218 additions and 0 deletions.
129 changes: 129 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
# paths = ["/path/to/override"] # path dependency overrides

[alias] # command aliases
install_soroban = "install --git https://github.com/AhaLabs/soroban-tools --branch fix/bindings-ts/expiration --root ./target soroban-cli --debug"
# b = "build --target wasm32-unknown-unknown --release"
# c = "check"
# t = "test"
# r = "run"
# rr = "run --release"
# recursive_example = "rr --example recursions"
# space_example = ["run", "--release", "--", "\"command list\""]

[build]
# jobs = 1 # number of parallel jobs, defaults to # of CPUs
# rustc = "rustc" # the rust compiler tool
# rustc-wrapper = "…" # run this wrapper instead of `rustc`
# rustc-workspace-wrapper = "…" # run this wrapper instead of `rustc` for workspace members
# rustdoc = "rustdoc" # the doc generator tool
# target = "wasm32-unknown-unknown" # build for the target triple (ignored by `cargo install`)
# target-dir = "target" # path of where to place all generated artifacts
# rustdocflags = ["…", "…"] # custom flags to pass to rustdoc
# incremental = true # whether or not to enable incremental compilation
# dep-info-basedir = "…" # path for the base directory for targets in depfiles

# [doc]
# browser = "chromium" # browser to use with `cargo doc --open`,
# # overrides the `BROWSER` environment variable

# [env]
# # Set ENV_VAR_NAME=value for any process run by Cargo
# ENV_VAR_NAME = "value"
# # Set even if already present in environment
# ENV_VAR_NAME_2 = { value = "value", force = true }
# # Value is relative to .cargo directory containing `config.toml`, make absolute
# ENV_VAR_NAME_3 = { value = "relative/path", relative = true }

# [future-incompat-report]
# frequency = 'always' # when to display a notification about a future incompat report

# [cargo-new]
# vcs = "none" # VCS to use ('git', 'hg', 'pijul', 'fossil', 'none')

# [http]
# debug = false # HTTP debugging
# proxy = "host:port" # HTTP proxy in libcurl format
# ssl-version = "tlsv1.3" # TLS version to use
# ssl-version.max = "tlsv1.3" # maximum TLS version
# ssl-version.min = "tlsv1.1" # minimum TLS version
# timeout = 30 # timeout for each HTTP request, in seconds
# low-speed-limit = 10 # network timeout threshold (bytes/sec)
# cainfo = "cert.pem" # path to Certificate Authority (CA) bundle
# check-revoke = true # check for SSL certificate revocation
# multiplexing = true # HTTP/2 multiplexing
# user-agent = "…" # the user-agent header

# [install]
# root = "/some/path" # `cargo install` destination directory

# [net]
# retry = 2 # network retries
# git-fetch-with-cli = true # use the `git` executable for git operations
# offline = true # do not access the network

# [net.ssh]
# known-hosts = ["..."] # known SSH host keys

# [patch.<registry>]
# # Same keys as for [patch] in Cargo.toml

# [profile.<name>] # Modify profile settings via config.
# inherits = "dev" # Inherits settings from [profile.dev].
# opt-level = 0 # Optimization level.
# debug = true # Include debug info.
# split-debuginfo = '...' # Debug info splitting behavior.
# debug-assertions = true # Enables debug assertions.
# overflow-checks = true # Enables runtime integer overflow checks.
# lto = false # Sets link-time optimization.
# panic = 'unwind' # The panic strategy.
# incremental = true # Incremental compilation.
# codegen-units = 16 # Number of code generation units.
# rpath = false # Sets the rpath linking option.
# [profile.<name>.build-override] # Overrides build-script settings.
# # Same keys for a normal profile.
# [profile.<name>.package.<name>] # Override profile for a package.
# # Same keys for a normal profile (minus `panic`, `lto`, and `rpath`).

# [registries.<name>] # registries other than crates.io
# index = "…" # URL of the registry index
# token = "…" # authentication token for the registry

# [registry]
# default = "…" # name of the default registry
# token = "…" # authentication token for crates.io

# [source.<name>] # source definition and replacement
# replace-with = "…" # replace this source with the given named source
# directory = "…" # path to a directory source
# registry = "…" # URL to a registry source
# local-registry = "…" # path to a local registry source
# git = "…" # URL of a git repository source
# branch = "…" # branch name for the git repository
# tag = "…" # tag name for the git repository
# rev = "…" # revision for the git repository

# [target.<triple>]
# linker = "…" # linker to use
# runner = "…" # wrapper to run executables
# rustflags = ["…", "…"] # custom flags for `rustc`

# [target.<cfg>]
# runner = "…" # wrapper to run executables
# rustflags = ["…", "…"] # custom flags for `rustc`

# [target.<triple>.<links>] # `links` build script override
# rustc-link-lib = ["foo"]
# rustc-link-search = ["/path/to/foo"]
# rustc-flags = ["-L", "/some/path"]
# rustc-cfg = ['key="value"']
# rustc-env = {key = "value"}
# rustc-cdylib-link-arg = ["…"]
# metadata_key1 = "value"
# metadata_key2 = "value"

# [term]
# quiet = false # whether cargo output is quiet
# verbose = false # whether cargo provides verbose output
# color = 'auto' # whether cargo colorizes output
# progress.when = 'auto' # whether cargo shows progress bar
# progress.width = 80 # width of progress bar
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@
js-stellar-base/

test/unit/out/

target/
2 changes: 2 additions & 0 deletions test/e2e/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SOROBAN_NETWORK_PASSPHRASE="Standalone Network ; February 2017"
SOROBAN_RPC_URL="http://localhost:8000/soroban/rpc"
11 changes: 11 additions & 0 deletions test/e2e/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* eslint-env node */
module.exports = {
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'],
parser: '@typescript-eslint/parser',
parserOptions: { project: './tsconfig.json' },
plugins: ['@typescript-eslint'],
root: true,
rules: {
"@typescript-eslint/no-floating-promises": ["error"]
},
};
5 changes: 5 additions & 0 deletions test/e2e/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
build
node_modules
yarn.lock
contract-*.txt
.soroban
1 change: 1 addition & 0 deletions test/e2e/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v20.6.0
84 changes: 84 additions & 0 deletions test/e2e/initialize.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#!/bin/bash

# read .env file, but prefer explicitly set environment variables
IFS=$'\n'
for l in $(cat .env); do
IFS='=' read -ra VARVAL <<< "$l"
# If variable with such name already exists, preserves its value
eval "export ${VARVAL[0]}=\${${VARVAL[0]}:-${VARVAL[1]}}"
done
unset IFS

if [[ -f "../../target/bin/soroban" ]]; then
echo "Using soroban binary from ../../target/bin"
else
if [[ $(pwd) =~ "e2e" ]]; then
echo "Building pinned soroban binary"
(cd ../.. && cargo install_soroban)
else
echo "Building pinned soroban binary in $(pwd)"
cargo install_soroban
fi
fi

NETWORK_STATUS=$(curl -s -X POST "$SOROBAN_RPC_URL" -H "Content-Type: application/json" -d '{ "jsonrpc": "2.0", "id": 8675309, "method": "getHealth" }' | sed 's/.*"status":"\(.*\)".*/\1/') || { echo "Make sure you're running local RPC network on localhost:8000" && exit 1; }
echo Network
echo " RPC: $SOROBAN_RPC_URL"
echo " Passphrase: \"$SOROBAN_NETWORK_PASSPHRASE\""
echo " Status: $NETWORK_STATUS"

# Print command before executing, from https://stackoverflow.com/a/23342259/249801
# Discussion: https://github.com/stellar/soroban-tools/pull/1034#pullrequestreview-1690667116
exe() { echo"${@/eval/}" ; "$@" ; }

function fund_all() {
exe eval "./soroban config identity fund"
exe eval "./soroban config identity generate alice"
exe eval "./soroban config identity fund alice"
exe eval "./soroban config identity generate bob"
exe eval "./soroban config identity fund bob"
}
function upload() {
exe eval "(./soroban contract $1 --wasm $2 --ignore-checks) > $3"
}
function deploy() {
exe eval "(./soroban contract deploy --wasm-hash $(cat $1) --ignore-checks) > $2"
}
function deploy_all() {
upload deploy ./wasms/test_custom_types.wasm contract-id-custom-types.txt
upload deploy ./wasms/test_hello_world.wasm contract-id-hello-world.txt
upload deploy ./wasms/test_swap.wasm contract-id-swap.txt
upload install ./wasms/test_token.wasm contract-token-hash.txt
deploy contract-token-hash.txt contract-id-token-a.txt
deploy contract-token-hash.txt contract-id-token-b.txt
}
function initialize() {
exe eval "./soroban contract invoke --id $(cat $1) -- initialize --admin $(./soroban config identity address) --decimal 0 --name 'Token $2' --symbol '$2'"
}
function initialize_all() {
initialize contract-id-token-a.txt A
initialize contract-id-token-b.txt B
}
function bind() {
exe eval "./soroban contract bindings typescript --contract-id $(cat $1) --output-dir ./node_modules/$2 --overwrite"
}
function bind_all() {
bind contract-id-custom-types.txt test-custom-types
bind contract-id-hello-world.txt test-hello-world
bind contract-id-swap.txt test-swap
bind contract-id-token-a.txt token
}

function mint() {
exe eval "./soroban contract invoke --id $(cat $1) -- mint --amount 2000000 --to $(./soroban config identity address $2)"
}
function mint_all() {
mint contract-id-token-a.txt alice
mint contract-id-token-b.txt bob
}

# fund_all
# deploy_all
# initialize_all
# mint_all
bind_all
Loading

0 comments on commit 64987d4

Please sign in to comment.