Selaa lähdekoodia

pre-requisities for running the build

nidhi-singh02 3 kuukautta sitten
vanhempi
sitoutus
deb9023d15

+ 0 - 20
target_chains/ethereum/contracts/.env.template

@@ -68,23 +68,3 @@ WORMHOLE_CHAIN_NAME=YOUR_CHAIN_NAME_HERE
 # Example: CLUSTER=mainnet
 CLUSTER=YOUR_CLUSTER_HERE
 
-# =============================================================================
-# EXAMPLE VALUES FOR REFERENCE
-# =============================================================================
-# 
-# For local testing (Anvil), you can use:
-#   PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
-#   RPC_URL=http://localhost:8545
-#   INIT_SIGNERS=0x58CC3AE5C097b213cE3c81979e1B9f9570746AA5
-#   INIT_CHAIN_ID=2
-#   INIT_GOV_CHAIN_ID=1
-#   INIT_GOV_CONTRACT=0x0000000000000000000000000000000000000000000000000000000000000004
-#
-# For testnet/mainnet deployment:
-#   - Get your private key from your wallet (never commit this!)
-#   - Use appropriate RPC URL (Alchemy, Infura, QuickNode, etc.)
-#   - Get Etherscan API key from https://etherscan.io/apis
-#   - Use actual guardian addresses from your network
-#   - Set proper chain IDs and governance contracts
-#
-# ⚠️  SECURITY WARNING: Never commit your actual .env file to version control!

+ 1 - 2
target_chains/ethereum/contracts/.env.test

@@ -1,7 +1,6 @@
 # =============================================================================
 # FOUNDRY TEST CONFIGURATION
 # This file contains test values for local development and testing
-# Uses Foundry-native environment variable formats
 # =============================================================================
 
 # Deployment Configuration (Anvil/Local Testing)
@@ -13,7 +12,7 @@ ETHERSCAN_API_KEY=test_api_key_not_needed_for_local
 # WORMHOLE TEST CONFIGURATION  
 # =============================================================================
 
-# Guardian Configuration (comma-separated addresses - Foundry native)
+# Guardian Configuration (comma-separated addresses)
 INIT_SIGNERS=0x58CC3AE5C097b213cE3c81979e1B9f9570746AA5,0x025ceeba2ab2a27d53d963393999eeebe83dc4ae
 INIT_CHAIN_ID=2
 INIT_GOV_CHAIN_ID=1

+ 0 - 190
target_chains/ethereum/contracts/FOUNDRY_ENV_GUIDE.md

@@ -1,190 +0,0 @@
-# Foundry Environment Variables Guide
-
-This guide shows the **recommended Foundry-native approaches** for reading environment variables in deployment scripts, without custom parsers.
-
-## 🎯 Recommended Approaches
-
-### 1. **Comma-Separated Arrays** ⭐ **BEST FOR MOST CASES**
-
-**Use Case:** Arrays of addresses, numbers, or simple types
-
-**Environment Format:**
-
-```bash
-# Multiple addresses
-INIT_SIGNERS=0x58CC3AE5C097b213cE3c81979e1B9f9570746AA5,0x025ceeba2ab2a27d53d963393999eeebe83dc4ae
-
-# Multiple numbers
-CHAIN_IDS=1,137,56,43114
-
-# Multiple strings (if supported)
-NETWORKS=ethereum,polygon,bsc
-```
-
-**Solidity Code:**
-
-```solidity
-// Read address array
-address[] memory signers = vm.envAddress("INIT_SIGNERS", ",");
-
-// Read uint array
-uint256[] memory chainIds = vm.envUint("CHAIN_IDS", ",");
-
-// Convert addresses to bytes32 if needed
-bytes32[] memory guardians = new bytes32[](signers.length);
-for (uint i = 0; i < signers.length; i++) {
-    guardians[i] = bytes32(uint256(uint160(signers[i])));
-}
-```
-
-**✅ Advantages:**
-
-- Native Foundry support
-- Clean, readable format
-- No parsing needed
-- Works with all basic types
-
-### 2. **JSON with vm.parseJson** (For Complex Data)
-
-**Use Case:** Complex nested data structures
-
-**Environment Format:**
-
-```bash
-# Simple array
-INIT_SIGNERS='["0x58CC3AE5C097b213cE3c81979e1B9f9570746AA5","0x025ceeba2ab2a27d53d963393999eeebe83dc4ae"]'
-
-# Complex object
-CONFIG='{"guardians":["0x..."],"chainId":1,"enabled":true}'
-```
-
-**Solidity Code:**
-
-```solidity
-// Simple array
-string memory signersJson = vm.envString("INIT_SIGNERS");
-address[] memory signers = abi.decode(vm.parseJson(signersJson), (address[]));
-
-// Complex object with key selection
-string memory configJson = vm.envString("CONFIG");
-address[] memory guardians = abi.decode(vm.parseJson(configJson, ".guardians"), (address[]));
-uint256 chainId = abi.decode(vm.parseJson(configJson, ".chainId"), (uint256));
-bool enabled = abi.decode(vm.parseJson(configJson, ".enabled"), (bool));
-```
-
-**⚠️ Requirements:**
-
-- JSON must be properly formatted
-- Use single quotes in .env files to prevent shell parsing issues
-- May need escaping for complex nested structures
-
-### 3. **Individual Environment Variables** (Simple & Reliable)
-
-**Use Case:** When you have a known, small number of values
-
-**Environment Format:**
-
-```bash
-GUARDIAN_1=0x58CC3AE5C097b213cE3c81979e1B9f9570746AA5
-GUARDIAN_2=0x025ceeba2ab2a27d53d963393999eeebe83dc4ae
-GUARDIAN_COUNT=2
-```
-
-**Solidity Code:**
-
-```solidity
-uint256 guardianCount = vm.envUint("GUARDIAN_COUNT");
-bytes32[] memory guardians = new bytes32[](guardianCount);
-
-for (uint i = 0; i < guardianCount; i++) {
-    string memory key = string(abi.encodePacked("GUARDIAN_", vm.toString(i + 1)));
-    address guardian = vm.envAddress(key);
-    guardians[i] = bytes32(uint256(uint160(guardian)));
-}
-```
-
-**✅ Advantages:**
-
-- Most reliable
-- Easy to debug
-- No parsing issues
-- Clear variable names
-
-## 📋 Available Foundry VM Methods
-
-```solidity
-// Basic types
-vm.envString("KEY")          // string
-vm.envAddress("KEY")         // address
-vm.envUint("KEY")            // uint256
-vm.envInt("KEY")             // int256
-vm.envBytes32("KEY")         // bytes32
-vm.envBytes("KEY")           // bytes
-vm.envBool("KEY")            // bool
-
-// Arrays with delimiter
-vm.envAddress("KEY", ",")    // address[]
-vm.envUint("KEY", ",")       // uint256[]
-vm.envInt("KEY", ",")        // int256[]
-vm.envBytes32("KEY", ",")    // bytes32[]
-vm.envString("KEY", ",")     // string[]
-
-// With default values
-vm.envOr("KEY", defaultValue)
-
-// JSON parsing
-vm.parseJson(jsonString)           // Parse entire JSON
-vm.parseJson(jsonString, ".key")   // Parse specific key
-```
-
-## 🛠️ Our Implementation
-
-**Current Deploy.s.sol uses Approach #1 (Comma-Separated):**
-
-```solidity
-// ✅ Clean, native Foundry approach
-address[] memory signerAddresses = vm.envAddress("INIT_SIGNERS", ",");
-
-// Convert to bytes32 for Wormhole
-bytes32[] memory initialSigners = new bytes32[](signerAddresses.length);
-for (uint i = 0; i < signerAddresses.length; i++) {
-    initialSigners[i] = bytes32(uint256(uint160(signerAddresses[i])));
-}
-```
-
-**Environment Format:**
-
-```bash
-INIT_SIGNERS=0x58CC3AE5C097b213cE3c81979e1B9f9570746AA5,0x025ceeba2ab2a27d53d963393999eeebe83dc4ae
-```
-
-## 🚫 What to Avoid
-
-- ❌ Custom string parsing functions
-- ❌ Complex regex operations
-- ❌ Manual hex conversion (use vm.envAddress instead)
-- ❌ Hardcoded values in scripts
-- ❌ Unescaped JSON in environment files
-
-## 💡 Best Practices
-
-1. **Use comma-separated for simple arrays**
-2. **Use individual vars for small, known sets**
-3. **Use JSON only for complex nested data**
-4. **Always validate environment variables exist**
-5. **Use `vm.envOr()` for optional values with defaults**
-6. **Keep environment files well-documented**
-7. **Test with different environment configurations**
-
-## 🧪 Testing
-
-```bash
-# Test with current environment
-forge script script/Deploy.s.sol
-
-# Test with specific environment file
-cp .env.test .env && forge script script/Deploy.s.sol
-
-# Test individual components
-forge script script/Deploy.s.sol --sig "deployWormhole()"
-```

+ 21 - 7
target_chains/ethereum/contracts/README.md

@@ -4,7 +4,19 @@ This directory contains The Pyth contract on Ethereum and utilities to deploy it
 
 ## Installation
 
-The contracts are built and tested using Foundry. Follow the [Foundry installation instructions](https://book.getfoundry.sh/getting-started/installation) to install it if you do not already have it.
+The contracts are built and tested using Foundry. You can either:
+
+1. **Use the setup script (recommended)**: 
+Go to the `contracts` directory and Run `npm run setup` to automatically install Foundry v0.3.0 AND all forge dependencies.
+
+2. **Manual installation**: 
+a) Follow the [Foundry installation instructions](https://book.getfoundry.sh/getting-started/installation) and install version v0.3.0.
+
+b) Next, from the `contracts` directory, run the following command to install forge dependencies:
+
+```
+npm run install-forge-deps
+```
 
 Next, run the following command from the repo root to install required dependencies for the contract:
 
@@ -13,11 +25,7 @@ pnpm i
 pnpm turbo build --filter @pythnetwork/pyth-evm-contract
 ```
 
-Next, from the `contracts` directory, run the following command to install forge dependencies:
 
-```
-npm run install-forge-deps
-```
 
 ## Testing
 
@@ -34,7 +42,7 @@ npm run coverage
 
 Open `coverage/index.html` in your web browser to see the results.
 
-## Deployment
+## Deployment and Governance tests
 
 To deploy the contracts, you'll need to set up your environment variables and use the Foundry deployment script.
 
@@ -55,7 +63,13 @@ anvil
 npm run deploy-local
 ```
 
-3. Deploy to a live network:
+3. Run the test suite:
+
+```bash
+npm run test
+```
+
+4. Deploy to a live network:
 
 ```bash
 # Make sure your .env file has the correct RPC_URL and PRIVATE_KEY

+ 2 - 1
target_chains/ethereum/contracts/package.json

@@ -11,9 +11,10 @@
     "prettier-plugin-solidity": "catalog:"
   },
   "scripts": {
+    "setup-foundry": "./setup-foundry.sh",
+    "setup": "npm run setup-foundry && npm run install-forge-deps",
     "build": "forge build",
     "test": "forge test",
-    "test-contract": "forge test",
     "deploy": "forge script script/Deploy.s.sol --rpc-url $RPC_URL --broadcast --verify",
     "deploy-local": "forge script script/Deploy.s.sol --rpc-url http://localhost:8545 --broadcast",
     "sync-guardian-sets": "forge script script/SyncGuardianSets.s.sol --rpc-url $RPC_URL --broadcast",

+ 28 - 0
target_chains/ethereum/contracts/setup-foundry.sh

@@ -0,0 +1,28 @@
+#!/bin/bash
+# Complete Forge setup script - installs Foundry and dependencies
+set -e
+
+FOUNDRY_VERSION="v0.3.0"
+
+echo "Setting up complete Forge environment with Foundry ${FOUNDRY_VERSION}..."
+
+# Check if foundryup is available
+if ! command -v foundryup &> /dev/null; then
+    echo "Installing foundryup..."
+    curl -L https://foundry.paradigm.xyz | bash
+    export PATH="$HOME/.foundry/bin:$PATH"
+fi
+
+# Install the specific version
+echo "Installing Foundry ${FOUNDRY_VERSION}..."
+foundryup --version $FOUNDRY_VERSION
+
+# Verify installation
+echo "Verifying installation..."
+forge --version
+cast --version
+anvil --version
+
+echo "Foundry ${FOUNDRY_VERSION} installed successfully!"
+
+echo "Setup complete! You can now run install-forge-deps."