Skip to content

Commit

Permalink
build: use dotenv
Browse files Browse the repository at this point in the history
  • Loading branch information
chadoh committed Oct 23, 2023
1 parent 0472d49 commit c671e50
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 36 deletions.
2 changes: 2 additions & 0 deletions cmd/crates/soroban-spec-typescript/ts-tests/.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"
60 changes: 60 additions & 0 deletions cmd/crates/soroban-spec-typescript/ts-tests/initialize.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/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

echo Network
echo " RPC: $SOROBAN_RPC_URL"
echo " Passphrase: \"$SOROBAN_NETWORK_PASSPHRASE\""

# 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"
}
function upload() {
exe eval "(./soroban contract $1 --wasm $2) > $3"
}
function deploy() {
exe eval "(./soroban contract deploy --wasm-hash $(cat $1)) > $2"
}
function deploy_all() {
upload deploy ../../../../target/wasm32-unknown-unknown/test-wasms/test_custom_types.wasm contract-id-custom-types.txt
upload deploy ../../../../target/wasm32-unknown-unknown/test-wasms/test_hello_world.wasm contract-id-hello-world.txt
upload deploy ../../../../target/wasm32-unknown-unknown/test-wasms/test_swap.wasm contract-id-swap.txt
upload install ../../../../target/wasm32-unknown-unknown/test-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
}

curl -X POST "http://localhost:8000/soroban/rpc" || { echo "Make sure you're running standalone RPC network on localhost:8000" && exit 1; }
fund_all
deploy_all
initialize_all
bind_all
13 changes: 13 additions & 0 deletions cmd/crates/soroban-spec-typescript/ts-tests/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 20 additions & 36 deletions cmd/crates/soroban-spec-typescript/ts-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,26 @@
"private": true,
"type": "module",
"scripts": {
"postinstall": "curl -X POST \"http://localhost:8000/soroban/rpc\" && npm run fund && npm run deploy && npm run initialize && npm run bindings || { echo \"Make sure you're running standalone RPC network on localhost:8000\" && exit 1; }",
"fund:root": "./soroban config identity fund",
"fund:alice": "./soroban config identity generate alice && ./soroban config identity fund alice",
"fund": "npm run fund:root && npm run fund:alice",
"bindings:custom-types": "./soroban contract bindings typescript --contract-id $(cat contract-id-custom-types.txt) --output-dir ./node_modules/test-custom-types --overwrite",
"bindings:hello-world": "./soroban contract bindings typescript --contract-id $(cat contract-id-hello-world.txt) --output-dir ./node_modules/test-hello-world --overwrite",
"bindings:swap": "./soroban contract bindings typescript --contract-id $(cat contract-id-swap.txt) --output-dir ./node_modules/test-swap --overwrite",
"bindings:token": "./soroban contract bindings typescript --contract-id $(cat contract-id-token-a.txt) --output-dir ./node_modules/token --overwrite",
"bindings": "npm run bindings:custom-types && npm run bindings:hello-world && npm run bindings:swap && npm run bindings:token",
"deploy:custom-types": "(./soroban contract deploy --wasm ../../../../target/wasm32-unknown-unknown/test-wasms/test_custom_types.wasm) > contract-id-custom-types.txt",
"deploy:hello-world": "(./soroban contract deploy --wasm ../../../../target/wasm32-unknown-unknown/test-wasms/test_hello_world.wasm) > contract-id-hello-world.txt",
"deploy:swap": "(./soroban contract deploy --wasm ../../../../target/wasm32-unknown-unknown/test-wasms/test_swap.wasm) > contract-id-swap.txt",
"install:token": "(./soroban contract install --wasm ../../../../target/wasm32-unknown-unknown/test-wasms/test_token.wasm) > contract-token-hash.txt",
"deploy:token:a": "(./soroban contract deploy --wasm-hash $(cat contract-token-hash.txt)) > contract-id-token-a.txt",
"deploy:token:b": "(./soroban contract deploy --wasm-hash $(cat contract-token-hash.txt)) > contract-id-token-b.txt",
"deploy:token": "npm run install:token && npm run deploy:token:a && npm run deploy:token:b",
"deploy": "npm run deploy:custom-types && npm run deploy:hello-world && npm run deploy:swap && npm run deploy:token",
"initialize:token:a": "./soroban contract invoke --id $(cat contract-id-token-a.txt) -- initialize --admin $(./soroban config identity address) --decimal 0 --name 'Token A' --symbol 'A'",
"initialize:token:b": "./soroban contract invoke --id $(cat contract-id-token-b.txt) -- initialize --admin $(./soroban config identity address) --decimal 0 --name 'Token B' --symbol 'B'",
"initialize:tokens": "npm run initialize:token:a && npm run initialize:token:b",
"initialize": "npm run deploy:token && npm run initialize:tokens",
"postinstall": "./initialize.sh",
"test": "ava"
},
"devDependencies": {
"@ava/typescript": "^4.1.0",
"@types/node": "^20.4.9",
"ava": "^5.3.1",
"soroban-client": "1.0.0-beta.2",
"typescript": "^5.1.6"
},
"ava": {
"typescript": {
"rewritePaths": {
"src/": "build/"
},
"compile": "tsc"
}
}
"devDependencies": {
"@ava/typescript": "^4.1.0",
"@types/node": "^20.4.9",
"ava": "^5.3.1",
"dotenv": "^16.3.1",
"soroban-client": "1.0.0-beta.2",
"typescript": "^5.1.6"
},
"ava": {
"typescript": {
"rewritePaths": {
"src/": "build/"
},
"compile": "tsc"
},
"require": [
"dotenv/config"
]
}
}

0 comments on commit c671e50

Please sign in to comment.