Created
October 22, 2025 10:42
-
-
Save ezynda3/16e2bcd0e0ae6ba3caf68d34e785a500 to your computer and use it in GitHub Desktop.
Test Mongo DB Bash Helpers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" | |
| cd "$PROJECT_ROOT" | |
| source .env | |
| source script/helperFunctions.sh | |
| export ENABLE_MONGODB_LOGGING="true" | |
| TEST_CONTRACT="THROWAWAY_TEST_Simple" | |
| TEST_NETWORK="mainnet" | |
| TEST_VERSION="8.8.8" | |
| TEST_ADDRESS="0xCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC" | |
| TEST_ENV="staging" | |
| echo "==========================================" | |
| echo "MongoDB Helper Functions Test" | |
| echo "==========================================" | |
| echo "" | |
| echo "Date: $(date)" | |
| echo "MongoDB URI: ${MONGODB_URI:0:30}..." | |
| echo "" | |
| echo "Step 1: Create test record" | |
| echo "----------------------------" | |
| bun script/deploy/update-deployment-logs.ts add \ | |
| --env "$TEST_ENV" \ | |
| --contract "$TEST_CONTRACT" \ | |
| --network "$TEST_NETWORK" \ | |
| --version "$TEST_VERSION" \ | |
| --address "$TEST_ADDRESS" \ | |
| --optimizer-runs "200" \ | |
| --timestamp "$(date -u +"%Y-%m-%dT%H:%M:%SZ")" \ | |
| --constructor-args "simple-test" \ | |
| --verified "false" | |
| echo "✓ Test record created" | |
| echo "" | |
| echo "Step 2: Query with queryMongoDeployment()" | |
| echo "-------------------------------------------" | |
| RESULT=$(queryMongoDeployment "$TEST_CONTRACT" "$TEST_NETWORK" "$TEST_ENV" "$TEST_VERSION") | |
| echo "Result:" | |
| echo "$RESULT" | jq . | |
| echo "" | |
| echo "Step 3: Check exists with checkMongoDeploymentExists()" | |
| echo "--------------------------------------------------------" | |
| if checkMongoDeploymentExists "$TEST_CONTRACT" "$TEST_NETWORK" "$TEST_ENV" "$TEST_VERSION"; then | |
| echo "✓ Record exists" | |
| else | |
| echo "✗ Record not found" | |
| fi | |
| echo "" | |
| echo "Step 4: Get latest with getLatestMongoDeployment()" | |
| echo "----------------------------------------------------" | |
| LATEST=$(getLatestMongoDeployment "$TEST_CONTRACT" "$TEST_NETWORK" "$TEST_ENV") | |
| echo "Result:" | |
| echo "$LATEST" | jq '.contractName, .version, .address' | |
| echo "" | |
| echo "Step 5: Find with findContractInMasterLog()" | |
| echo "---------------------------------------------" | |
| FIND_RESULT=$(findContractInMasterLog "$TEST_CONTRACT" "$TEST_NETWORK" "$TEST_ENV" "$TEST_VERSION") | |
| echo "Result:" | |
| echo "$FIND_RESULT" | jq . | |
| echo "" | |
| echo "Step 6: Update record" | |
| echo "---------------------" | |
| bun script/deploy/update-deployment-logs.ts update \ | |
| --env "$TEST_ENV" \ | |
| --contract "$TEST_CONTRACT" \ | |
| --network "$TEST_NETWORK" \ | |
| --version "$TEST_VERSION" \ | |
| --address "$TEST_ADDRESS" \ | |
| --verified "true" | |
| echo "✓ Record updated to verified=true" | |
| echo "" | |
| echo "Step 7: Verify update" | |
| echo "---------------------" | |
| UPDATED=$(queryMongoDeployment "$TEST_CONTRACT" "$TEST_NETWORK" "$TEST_ENV" "$TEST_VERSION") | |
| VERIFIED=$(echo "$UPDATED" | jq -r '.verified') | |
| echo "Verified status: $VERIFIED" | |
| echo "" | |
| echo "Step 8: Find by address with findContractInMasterLogByAddress()" | |
| echo "-----------------------------------------------------------------" | |
| ADDRESS_RESULT=$(findContractInMasterLogByAddress "$TEST_NETWORK" "$TEST_ENV" "$TEST_ADDRESS") | |
| echo "Result:" | |
| echo "$ADDRESS_RESULT" | jq . | |
| echo "" | |
| echo "Step 9: Get version with getContractVersionFromMasterLog()" | |
| echo "------------------------------------------------------------" | |
| VERSION_RESULT=$(getContractVersionFromMasterLog "$TEST_NETWORK" "$TEST_ENV" "$TEST_CONTRACT" "$TEST_ADDRESS") | |
| echo "Version: $VERSION_RESULT" | |
| echo "" | |
| echo "Step 10: Get highest version with getHighestDeployedContractVersionFromMasterLog()" | |
| echo "------------------------------------------------------------------------------------" | |
| HIGHEST=$(getHighestDeployedContractVersionFromMasterLog "$TEST_NETWORK" "$TEST_ENV" "$TEST_CONTRACT") | |
| echo "Highest version: $HIGHEST" | |
| echo "" | |
| echo "Step 11: Cleanup test records" | |
| echo "------------------------------" | |
| bun -e "import { MongoClient } from 'mongodb'; const client = new MongoClient(process.env.MONGODB_URI || ''); await client.connect(); const db = client.db('sc_public'); const collection = db.collection('ContractDeployments'); const result = await collection.deleteMany({ contractName: { \$regex: '^THROWAWAY_TEST_' }, environment: 'staging' }); console.log(\`✓ Deleted \${result.deletedCount} test record(s)\`); await client.close();" | |
| echo "" | |
| echo "==========================================" | |
| echo "Test Complete" | |
| echo "==========================================" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment