-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest-local-function.sh
More file actions
executable file
·47 lines (41 loc) · 1.51 KB
/
test-local-function.sh
File metadata and controls
executable file
·47 lines (41 loc) · 1.51 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
#!/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
# If no parameters are provided, use default values
if [[ $# -ne 2 ]]; then
rate_feed_name="PHP/USD"
relayer_address="0x3bC1f31B8150dc65B9fB9E8B69604C40EaA97C2F"
else
rate_feed_name="$1"
relayer_address="$2"
fi
# Manually triggers a local Cloud Function by faking a Pubsub event.
test_local_function() {
# Load the project variables
script_dir=$(dirname "$0")
source "${script_dir}/get-project-vars.sh"
printf "\n"
# Create the JSON payload and encode it in base64
json_data="{ \"rate_feed_name\": \"${rate_feed_name}\", \"relayer_address\": \"${relayer_address}\" }"
base64_data=$(echo -n "${json_data}" | base64)
curl localhost:8080/projects/"${project_name}"/topics/"${topic_name}" \
-X POST \
-H "Content-Type: application/json" \
-w "\n" \
-d '{
"message": {
"attributes": {
"googclient_schemaencoding": "JSON",
"googclient_schemarevisionid": "a75ff1fd"
},
"data": "'"${base64_data}"'",
"messageId": "11844765153650126",
"message_id": "11844765153650126",
"publishTime": "2024-07-26T11:09:00.513Z",
"publish_time": "2024-07-26T11:09:00.513Z"
},
"subscription": "projects/oracle-relayer-87ee/subscriptions/eventarc-europe-west1-relay-function-540785-sub-226"
}'
}
test_local_function