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

feat(stellar): add deployment script for testing #428

Open
wants to merge 44 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 39 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
c027d0f
add deployment script
hydrobeam Nov 7, 2024
1e7b955
remove unneeded contracts field
hydrobeam Nov 7, 2024
3994fe1
remove unused comment
hydrobeam Nov 7, 2024
807da9c
add operator contract actions
hydrobeam Nov 7, 2024
2a8987e
remove commented out item
hydrobeam Nov 7, 2024
d2bed2b
replace all instances of sui with stellar
hydrobeam Nov 7, 2024
a5d4a25
fix linting complaints
hydrobeam Nov 7, 2024
931d770
modify uses statement .yaml
hydrobeam Nov 7, 2024
10f26a0
make env vars persistent
hydrobeam Nov 7, 2024
16f147e
cleanup errors in various commands
hydrobeam Nov 7, 2024
9a692fa
rename vars + don't double start network
hydrobeam Nov 7, 2024
afdf858
do not wait for network
hydrobeam Nov 7, 2024
6ea5983
use binary install to save compilation time
hydrobeam Nov 7, 2024
cca6b78
properly set path in gh action
hydrobeam Nov 7, 2024
d31b558
fix linting error
hydrobeam Nov 7, 2024
1b864ca
absolute path for adding to path
hydrobeam Nov 7, 2024
e621a91
use pwd instead
hydrobeam Nov 7, 2024
72e0849
cleanup docs + try vague change to make paths work
hydrobeam Nov 7, 2024
aa32344
use github workspace instead
hydrobeam Nov 7, 2024
14dda78
Merge branch 'main' into feat/stellar/deployment-script
hydrobeam Nov 7, 2024
1d2b132
debugging
hydrobeam Nov 7, 2024
187b289
more debugging
hydrobeam Nov 7, 2024
519380f
remove failing comp
hydrobeam Nov 7, 2024
06bf4a7
just trying anything
hydrobeam Nov 7, 2024
ccd3cba
setup nested repo
hydrobeam Nov 7, 2024
b73971b
give up on it
hydrobeam Nov 7, 2024
e44d82c
don't use relative path for symlink
hydrobeam Nov 7, 2024
bc86cd1
add missing target for rust + docs
hydrobeam Nov 7, 2024
84ff763
inspect .env
hydrobeam Nov 7, 2024
3b65c21
switch order around
hydrobeam Nov 7, 2024
7df3f61
yes env to skip confirmation
hydrobeam Nov 7, 2024
76e910c
put it in the env
hydrobeam Nov 7, 2024
56bbf73
comment out misbehaving lines
hydrobeam Nov 7, 2024
e7e7787
Merge branch 'main' into feat/stellar/deployment-script
hydrobeam Nov 25, 2024
09dcf8a
update protocol version
hydrobeam Nov 25, 2024
b92c7ae
add explicit funding for stellar wallet
hydrobeam Nov 25, 2024
38227fa
pull stellar not soroban
hydrobeam Nov 25, 2024
4f3d910
install sellar cli properly
hydrobeam Nov 26, 2024
59462c4
accomodate pulling from CF
hydrobeam Dec 11, 2024
e06b235
add version file + update for changes
hydrobeam Dec 13, 2024
e6533e2
remove --initialize
hydrobeam Dec 13, 2024
66db0f7
add more contract names
hydrobeam Dec 13, 2024
dcd889e
named variable + use () for cat
hydrobeam Dec 19, 2024
abd26c1
same variable formatting
hydrobeam Dec 19, 2024
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
236 changes: 236 additions & 0 deletions .github/workflows/test-stellar.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,236 @@
name: Test Stellar

on: pull_request

jobs:
check-relevant-changes:
name: Check for Relevant Changes
runs-on: blacksmith-2vcpu-ubuntu-2204
outputs:
run_tests: ${{ steps.filter.outputs.stellar == 'true' || steps.filter.outputs.common == 'true' || steps.filter.outputs.github == 'true' }}
steps:
- uses: actions/checkout@v4
- uses: dorny/paths-filter@v3
id: filter
with:
filters: |
stellar:
- 'stellar/**'
common:
- 'common/**'
github:
- '.github/workflows/test-stellar.yaml'
- name: Summarize Changes
run: |
echo "Changes in stellar: ${{ steps.filter.outputs.stellar }}"
echo "Changes in common: ${{ steps.filter.outputs.common }}"
echo "Changes in github: ${{ steps.filter.outputs.github }}"

test-stellar:
name: Test Stellar
needs: check-relevant-changes
if: ${{ needs.check-relevant-changes.outputs.run_tests == 'true' }}
runs-on: blacksmith-2vcpu-ubuntu-2204
steps:
# this sets up nested repos: https://github.com/actions/checkout?tab=readme-ov-file#checkout-multiple-repos-nested
#
# axelar-contract-deployments
# - axelar-cgp-soroban
#
# future steps depend on this directory structure
- name: Checkout code
uses: actions/checkout@v4

- name: Checkout axelar-cgp-soroban repo
uses: actions/checkout@v4
with:
repository: axelarnetwork/axelar-cgp-soroban
path: axelar-cgp-soroban

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18' # Hardcoded to ensure consistency.
cache: 'npm'
registry-url: 'https://registry.npmjs.org'

- name: Install dependencies
shell: bash
run: npm ci

- name: Install stable toolchain
uses: dtolnay/rust-toolchain@stable
with:
toolchain: 1.81.0
targets: wasm32-unknown-unknown

# install binary to avoid lengthy compilation process
- name: Install Stellar CLI
shell: bash
run: |
# setup bin/ directory
mkdir bin
cd bin

# Query latest release from official Stellar repo
URL=$(curl -s https://api.github.com/repos/stellar/stellar-cli/releases/latest | jq -r .assets[].browser_download_url | grep 'stellar.*x86_64-unknown-linux')

# download + extract binary
wget -q $URL
tar -xzf $(basename $URL)

echo "$GITHUB_WORKSPACE/bin" >> $GITHUB_PATH

- name: Setup Stellar local network
run: |
docker pull stellar/quickstart
docker run -d --rm -it \
-p 8000:8000 \
--name stellar \
stellar/quickstart:testing \
--local \
--enable-soroban-rpc \
--protocol-version 22

RPC_URL="http://localhost:8000/soroban/rpc"
NETWORK_PASSPHRASE="Standalone Network ; February 2017"
echo "RPC_URL=${RPC_URL}" >> $GITHUB_ENV
echo "NETWORK_PASSPHRASE=${NETWORK_PASSPHRASE}" >> $GITHUB_ENV

- name: Add as configured network
shell: bash
run: |
stellar network add local \
--rpc-url "$RPC_URL" \
--network-passphrase "$NETWORK_PASSPHRASE"

- name: Prepare local.json
run: |
echo '{
"chains": {
"stellar": {
"name": "Stellar",
"axelarId": "stellar",
"networkType": "local",
"chainType": "stellar",
"tokenSymbol": "XLM",
"rpc": "http://127.0.0.1:8000/soroban/rpc",
"horizonRpc": "http://127.0.0.1:8000",
"contracts": {}
}
}
}' > ./axelar-chains-config/info/local.json

- name: Display local.json
run: cat ./axelar-chains-config/info/local.json

###### Acquire WASM Contracts ######
- name: Configure CF credentials
run: |
cd $HOME; mkdir ~/.aws; touch ~/.aws/credentials; touch ~/.aws/config
echo "[default]
aws_access_key_id = ${{ secrets.cf-bucket-access-key-id }}
aws_secret_access_key = ${{ secrets.cf-bucket-secret-access-key }}" > ~/.aws/credentials
echo "[default]
region=auto
output=json" > ~/.aws/config

- name: Fetch WASM contracts from CF
env:
S3_BUCKET_NAME: ${{ vars.CF_BUCKET_NAME }}
ENDPOINT_URL: ${{ secrets.cf-endpoint-url }}
CF_BUCKET_ROOT_KEY: ${{ vars.CF_BUCKET_ROOT_KEY }}
hydrobeam marked this conversation as resolved.
Show resolved Hide resolved
run: |
export CF_WASM_BUCKET_ROOT_KEY="${CF_BUCKET_ROOT_KEY}/${{ env.PACKAGE_NAME }}/${{ env.PACKAGE_VERSION }}/wasm"
for name in axelar_gateway axelar_operators axelar_gas_service; do
hydrobeam marked this conversation as resolved.
Show resolved Hide resolved
aws s3api get-object --bucket $S3_BUCKET_NAME --key "$CF_WASM_BUCKET_ROOT_KEY/$FILE_KEY" --body "$name.optimized.wasm" --acl public-read --endpoint-url $ENDPOINT_URL
done

ls

WASM_DIR=./
echo "WASM_DIR=${WASM_DIR}" >> $GITHUB_ENV

- name: Setup Stellar wallet
run: |
stellar keys generate test \
--rpc-url "$RPC_URL" \
--network-passphrase "$NETWORK_PASSPHRASE"

STELLAR_PRIVATE_KEY=$(stellar keys show test)
STELLAR_ADDRESS=$(stellar keys address test)
echo "STELLAR_PRIVATE_KEY=${STELLAR_PRIVATE_KEY}" >> $GITHUB_ENV
echo "STELLAR_ADDRESS=${STELLAR_ADDRESS}" >> $GITHUB_ENV

- name: Fund Stellar wallet
run: node stellar/faucet --recipient $STELLAR_ADDRESS
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't we just use --fund parameter to fund the stellar wallet?
You can test it with

stellar keys generate --global test10 --network testnet --fund
stellar keys address test10

and go to stellar.expert and check the balance of the wallet address.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is possible to fund it during wallet creation but I was thinking that this would act like a test for the faucet command.


- name: Prepare .env
run: |
echo "PRIVATE_KEY = '$STELLAR_PRIVATE_KEY'" >> .env
echo "ENV = 'local'" >> .env
echo "YES = 'true'" >> .env

###### Command: Deploy Contract ######
- name: Deploy axelar_gateway
run: |
CONTRACT=axelar_gateway
node stellar/deploy-contract deploy $CONTRACT --wasm-path $WASM_DIR/$CONTRACT.optimized.wasm --initialize
hydrobeam marked this conversation as resolved.
Show resolved Hide resolved

- name: Deploy axelar_operators
run: |
CONTRACT=axelar_operators
node stellar/deploy-contract deploy $CONTRACT --wasm-path $WASM_DIR/$CONTRACT.optimized.wasm --initialize
hydrobeam marked this conversation as resolved.
Show resolved Hide resolved

###### Command: Gateway ######
# FIXME:
# - name: Gateway Approve
# run: |
# node stellar/gateway approve avalanche 0x32034b47cb29d162d9d803cc405356f4ac0ec07fe847ace431385fe8acf3e6e5-2 0x4F4495243837681061C4743b74B3eEdf548D56A5 wallet 0x1234

- name: Gateway Call Contract
run: node stellar/gateway.js call-contract avalanche 0x4F4495243837681061C4743b74B3eEdf548D56A5 0x1234

- name: Gateway Rotate Signers
run: |
node stellar/gateway rotate --new-nonce test --signers wallet
node stellar/gateway rotate --new-nonce test2 --current-nonce test --signers wallet

- name: Upgrade gateway contract
run: |
CONTRACT=axelar_gateway
node stellar/deploy-contract.js upgrade $CONTRACT --wasm-path $WASM_DIR/$CONTRACT.optimized.wasm

###### Command: Operators ######

- name: Execute is_operator action
run: node stellar/operators.js --action is_operator --args $STELLAR_ADDRESS

- name: Execute add_operator action
run: node stellar/operators.js --action add_operator --args $STELLAR_ADDRESS

- name: Execute remove_operator action
run: node stellar/operators.js --action remove_operator --args $STELLAR_ADDRESS

# TODO: needs gas-service contract
# - name: Execute refund action
# run: node stellar/operators.js --action refund

# FIXME: find proper way to execute this
# - name: Execute execute action
# run: node stellar/operators.js --action execute --target $STELLAR_ADDRESS --method "is_operator"

# TODO: currently fails
# - name: is_operator with estimate_cost
# run: node stellar/operators.js --action is_operator --args $STELLAR_ADDRESS --estimate-cost

###### Command: Generate Bindings #####
- name: generate operators bindings
run: |
CONTRACT=axelar_operators
node stellar/generate-bindings.js --wasm-path $WASM_DIR/$CONTRACT.optimized.wasm --contract-id $(jq .chains.stellar.contracts.$CONTRACT.address axelar-chains-config/info/local.json) --output-dir ./stellar/bindings/$CONTRACT
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

generate bindings script is not working properly as of now. did you run it sucessfully?


- name: generate gateway bindings
run: |
CONTRACT=axelar_gateway
node stellar/generate-bindings.js --wasm-path $WASM_DIR/$CONTRACT.optimized.wasm --contract-id $(jq .chains.stellar.contracts.$CONTRACT.address axelar-chains-config/info/local.json) --output-dir ./stellar/bindings/$CONTRACT
2 changes: 1 addition & 1 deletion stellar/generate-bindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function main() {

program.action((options) => {
const config = loadConfig(options.env);
processCommand(options, config, config.stellar);
processCommand(options, config, config.chains.stellar);
});

program.parse();
Expand Down
10 changes: 6 additions & 4 deletions stellar/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const ASSET_TYPE_NATIVE = 'native';
function getNetworkPassphrase(networkType) {
switch (networkType) {
case 'local':
return Networks.SANDBOX;
return Networks.STANDALONE;
case 'futurenet':
return Networks.FUTURENET;
case 'testnet':
Expand Down Expand Up @@ -148,7 +148,7 @@ async function sendTransaction(tx, server, action, options = {}) {
}

async function broadcast(operation, wallet, chain, action, options = {}) {
const server = new rpc.Server(chain.rpc);
const server = new rpc.Server(chain.rpc, { allowHttp: true });

if (options.estimateCost) {
const tx = await buildTransaction(operation, server, wallet, chain.networkType, options);
Expand All @@ -168,8 +168,10 @@ function getAssetCode(balance, chain) {
async function getWallet(chain, options) {
const keypair = Keypair.fromSecret(options.privateKey);
const address = keypair.publicKey();
const provider = new rpc.Server(chain.rpc);
const horizonServer = new Horizon.Server(chain.horizonRpc);
const provider = new rpc.Server(chain.rpc, {
allowHttp: true,
});
const horizonServer = new Horizon.Server(chain.horizonRpc, { allowHttp: true });
const balances = await getBalances(horizonServer, address);

printInfo('Wallet address', address);
Expand Down
Loading