From 66fc86ba5c88265c09e89338da119cabb9656b5a Mon Sep 17 00:00:00 2001 From: Julianemeka Date: Fri, 26 Jun 2026 06:59:01 +0000 Subject: [PATCH] docs: add local Soroban contract deployment guide Closes #330 - Document prerequisites (Rust, stellar-cli, Docker) - Cover build, test, environment config, deploy, and interact steps - Add troubleshooting table for common local-dev issues --- docs/local-deployment.md | 152 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 152 insertions(+) create mode 100644 docs/local-deployment.md diff --git a/docs/local-deployment.md b/docs/local-deployment.md new file mode 100644 index 0000000..a985cf8 --- /dev/null +++ b/docs/local-deployment.md @@ -0,0 +1,152 @@ +# Local Soroban Contract Deployment Guide + +This guide walks through deploying CosmosVote contracts to a local Soroban environment for development and iteration. + +## Prerequisites + +```bash +# Rust with WASM target +rustup target add wasm32-unknown-unknown + +# Stellar CLI +cargo install --locked stellar-cli + +# Docker (for local Soroban node) +docker --version +``` + +## 1. Start a Local Soroban Node + +```bash +docker compose up -d +``` + +This starts a local Stellar/Soroban node at `http://localhost:8000`. + +Verify it is running: + +```bash +curl http://localhost:8000/info +``` + +## 2. Build WASM Binaries + +```bash +make build +``` + +Artifacts are written to `target/wasm32-unknown-unknown/release/`. + +Run tests before deploying: + +```bash +make test +``` + +## 3. Configure Environment + +```bash +cp .env.example .env +``` + +Edit `.env` for local deployment: + +```bash +NETWORK=local +STELLAR_RPC_URL=http://localhost:8000 +STELLAR_SECRET_KEY= +``` + +Generate a local keypair if needed: + +```bash +stellar keys generate --global alice --network local +stellar keys address alice +``` + +Fund the account on local network: + +```bash +stellar keys fund alice --network local +``` + +## 4. Deploy Contracts + +```bash +./scripts/deploy.sh +``` + +The script deploys the token contract first, then the governance contract, and prints both contract IDs. Copy them into your `.env`: + +```bash +TOKEN_CONTRACT_ID= +GOVERNANCE_CONTRACT_ID= +``` + +## 5. Run Tests and Build WASM + +```bash +# All tests +make test + +# Governance contract only +cargo test -p cosmosvote-governance --features testutils + +# Token contract only +cargo test -p cosmosvote-token --features testutils + +# Property-based tests +cargo test prop_ --all --features testutils + +# Verify WASM builds +bash scripts/test_wasm.sh +``` + +## 6. Interact with Deployed Contracts + +Initialize the governance contract after deploy: + +```bash +stellar contract invoke \ + --id "$GOVERNANCE_CONTRACT_ID" \ + --source alice \ + --network local \ + -- initialize \ + --admin alice \ + --voting_token "$TOKEN_CONTRACT_ID" \ + --min_proposal_balance 0 \ + --proposal_cooldown 0 \ + --restrict_admin_vote false +``` + +Create a proposal: + +```bash +stellar contract invoke \ + --id "$GOVERNANCE_CONTRACT_ID" \ + --source alice \ + --network local \ + -- create_proposal \ + --proposer alice \ + --title "My First Proposal" \ + --description "Testing local deployment" \ + --quorum 1000 \ + --duration 3600 +``` + +## 7. Teardown + +```bash +docker compose down +``` + +## Troubleshooting + +| Problem | Fix | +|---------|-----| +| `STELLAR_SECRET_KEY must be set` | Set the variable in `.env` | +| `connection refused` on port 8000 | Run `docker compose up -d` first | +| WASM build fails | Run `rustup target add wasm32-unknown-unknown` | +| `Error: account not found` | Fund the account with `stellar keys fund alice --network local` | +| Contracts already deployed | Re-run `./scripts/deploy.sh`; it will deploy fresh instances | +| Test failures after contract change | Run `make clean && make build && make test` |