-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest-deployed-function.sh
More file actions
executable file
·59 lines (47 loc) · 1.91 KB
/
test-deployed-function.sh
File metadata and controls
executable file
·59 lines (47 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/bin/bash
set -e # Fail on any error
set -o pipefail # Ensure piped commands propagate exit codes properly
set -u # Treat unset variables as an error when substituting
# Manually triggers a deployed Cloud Function by emitting a Pubsub event.
# Requires an environment arg (e.g., celo-sepolia, celo).
test_deployed_function() {
# Check if environment and rate feed ID parameters are provided
if [[ $# -ne 2 ]]; then
echo "Usage: $0 <env> <rate_feed_description>"
echo "Example: $0 celo-sepolia PHP/USD"
exit 1
fi
env=$1
rate_feed_id=$2
# Validate rate feed ID format
if ! [[ ${rate_feed_id} =~ ^[A-Z]{3,4}/[A-Z]{3,4}$ ]]; then
echo "❌ Error: Invalid rate feed ID format. It should be in the form of 'PHP/USD' (3-4 digits per currency symbol)."
exit 1
fi
json_key=$(echo "${rate_feed_id}" | tr '[:upper:]' '[:lower:]' | tr '/' '_')
terraform -chdir=infra workspace select "${env}"
# Load the project variables
script_dir=$(dirname "$0")
source "${script_dir}/get-project-vars.sh"
printf "\n"
# Read the relayer addresses JSON file and extract the address
json_file="infra/relayer_addresses.json"
if [[ ! -f ${json_file} ]]; then
echo "❌ Error: ${json_file} file not found in the script directory."
exit 1
fi
address=$(jq -r ".\"${env}\".\"${json_key}\"" "${json_file}")
if [[ ${address} == "null" ]]; then
echo "❌ Error: Address not found for rate feed ID '${rate_feed_id}' in environment '${env}'."
exit 1
fi
echo "🌀 Emitting a Pubsub event to trigger the function..."
printf "\n"
gcloud pubsub topics publish "${topic_name}" --message="{\"rate_feed_name\": \"${rate_feed_id}\", \"relayer_address\": \"${address}\"}"
printf "\n"
echo "✅ Pubsub event emitted!"
printf "\n"
logs_url=$(npm run logs:url 2>/dev/null | tail -n1 || echo "npm run logs:url")
echo "Now check the logs via \`npm run logs\` or in the Cloud Console via ${logs_url}"
}
test_deployed_function "$@"