From c027d0f06ed14e96bbedc5cee6af0da0aad2054c Mon Sep 17 00:00:00 2001 From: Laith Bahodi Date: Thu, 7 Nov 2024 10:42:53 -0500 Subject: [PATCH] add deployment script + adjust some values in utils.js to enable it to work with httpcalls --- .github/workflows/test-stellar.yaml | 215 ++++++++++++++++++++++++++++ stellar/generate-bindings.js | 2 +- stellar/utils.js | 10 +- 3 files changed, 222 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/test-stellar.yaml diff --git a/.github/workflows/test-stellar.yaml b/.github/workflows/test-stellar.yaml new file mode 100644 index 00000000..c2ba1468 --- /dev/null +++ b/.github/workflows/test-stellar.yaml @@ -0,0 +1,215 @@ +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.sui == '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: | + sui: + - 'stellar/**' + common: + - 'common/**' + github: + # - '.github/actions/setup-stellar/**' + - '.github/workflows/test-stellar.yaml' + - name: Summarize Changes + run: | + echo "Changes in stellar: ${{ steps.filter.outputs.sui }}" + 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: + - name: Checkout code + uses: actions/checkout@v4 + + - 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 + with: + toolchain: 1.81.0 + + - name: Install Stellar CLI + shell: bash + run: | + cargo install --locked stellar-cli --features opt --version ~21 + + - name: Pull stellar/quickstart docker image + run: | + docker pull stellar/quickstart + + - name: Setup Stellar standalone network + run: | + docker run -d --rm -it \ + -p 8000:8000 \ + --name stellar \ + stellar/quickstart:testing \ + --local \ + --enable-soroban-rpc \ + --protocol-version 21 + + RPC_URL="http://localhost:8000" + NETWORK_PASSPHRASE="Standalone Network ; February 2017" + + - name: Add as configured network + run: | + stellar network add standalone \ + --rpc-url $RPC_URL \ + --network-passphrase $NETWORK_PASSPHRASE + + - 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: Prepare local.json + run: | + echo '{ + "chains": { + "stellar": { + "name": "Stellar", + "axelarId": "stellar", + "networkType": "localnet", + "chainType": "stellar", + "tokenSymbol": "XLM", + "rpc": "http://127.0.0.1:8000", + "horizonRpc": "http://127.0.0.1:8000", + "contracts": { + "AxelarGateway": {} + } + } + } + }' > ./axelar-chains-config/info/local.json + + - name: Start Stellar network + run: | + stellar network container start local + + - name: Wait for Stellar network + uses: nev7n/wait_for_response@v1 + with: + url: 'http://localhost:8000' + responseCode: 200 + timeout: 60000 + interval: 1000 + + # Create .env file with default hardhat private key that's prefunded + - name: Prepare .env + run: | + echo "PRIVATE_KEY=STELLAR_PRIVATE_KEY" >> .env + echo 'ENV=local' >> .env + # echo 'SKIP_EXISTING = true' >> .env + + - name: Display local.json + run: cat ./axelar-chains-config/info/local.json + + # - name: Request SUI from faucet + # run: node stellar/faucet.js + + ###### Compile Wasm Contracts ###### + + - name: Checkout axelar-cgp-soroban repo + uses: actions/checkout@v4 + with: + repository: axelarnetwork/axelar-cgp-soroban + + - name: Compile WASM contracts + run: | + stellar contract build --manifest-path=axelar-cgp-soroban/Cargo.toml + cd axelar-cgp-soroban + ./optmize.sh + cd .. + WASM_DIR=axelar-cgp-soroban/target/wasm32-unknown-unknown/release + echo "WASM_DIR=${WASM_DIR}" >> $GITHUB_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 + + - name: Deploy axelar_operators + run: | + CONTRACT=axelar_operators + node stellar/deploy-contract deploy $CONTRACT --wasm-path $WASM_DIR/$CONTRACT.optimized.wasm --initialize + + ###### Command: Gateway ###### + # - 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: Store Capability Object in Operators + run: node sui/operators.js storeCap + + - name: Add Operator + run: node sui/operators.js add $SUI_ADDRESS + + - name: Collect Gas with Operator + run: node sui/operators.js collectGas --amount 1 + + - name: Refund Gas with Operator + run: node sui/operators.js refund 0x32034b47cb29d162d9d803cc405356f4ac0ec07fe847ace431385fe8acf3e6e5-2 --amount 1 + + - name: Remove Operator + run: node sui/operators.js remove $SUI_ADDRESS + + ###### Command: Generate Keypair ###### + - name: Generate Keypair + run: node sui/generate-keypair.js + + + ###### 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 + + - 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 diff --git a/stellar/generate-bindings.js b/stellar/generate-bindings.js index aa17f6e4..6708b5a2 100644 --- a/stellar/generate-bindings.js +++ b/stellar/generate-bindings.js @@ -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(); diff --git a/stellar/utils.js b/stellar/utils.js index b664365b..3a5f3062 100644 --- a/stellar/utils.js +++ b/stellar/utils.js @@ -24,7 +24,7 @@ const stellarCmd = 'stellar'; function getNetworkPassphrase(networkType) { switch (networkType) { case 'local': - return Networks.SANDBOX; + return Networks.STANDALONE; case 'futurenet': return Networks.FUTURENET; case 'testnet': @@ -147,7 +147,7 @@ async function sendTransaction(tx, server, action, options = {}) { } async function broadcast(operation, wallet, chain, action, options = {}) { - const server = new SorobanRpc.Server(chain.rpc); + const server = new SorobanRpc.Server(chain.rpc, { allowHttp: true }); if (options.estimateCost) { const tx = await buildTransaction(operation, server, wallet, chain.networkType, options); @@ -167,8 +167,10 @@ function getAssetCode(balance, chain) { async function getWallet(chain, options) { const keypair = Keypair.fromSecret(options.privateKey); const address = keypair.publicKey(); - const provider = new SorobanRpc.Server(chain.rpc); - const horizonServer = new Horizon.Server(chain.horizonRpc); + const provider = new SorobanRpc.Server(chain.rpc, { + allowHttp: true, + }); + const horizonServer = new Horizon.Server(chain.horizonRpc, { allowHttp: true }); printInfo('Wallet address', address); const account = await provider.getAccount(address);