-
Notifications
You must be signed in to change notification settings - Fork 112
218 lines (188 loc) · 8.04 KB
/
rosetta.yml
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
name: Rosetta API
on:
schedule:
- cron: "0 1 * * *" # Daily at 1:00 AM
pull_request:
branches: [ main, release/** ]
paths: [ hedera-mirror-rosetta/** ]
push:
branches: [ main, release/** ]
paths: [ hedera-mirror-rosetta/** ]
tags: [ v* ]
defaults:
run:
working-directory: ./hedera-mirror-rosetta
env:
IMAGE: hedera-mirror-rosetta-image
MODULE: hedera-mirror-rosetta
jobs:
image:
if: github.event_name == 'push' || github.event_name == 'schedule' || (github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]')
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Set GIT_REF
run: |
if [ "{{ github.event_name }}" = "pull_request" ]; then
# for pull request, GITHUB_SHA is the last merge commit on the GITHUB_REF branch. We want to use
# the PR branch HEAD sha instead
GIT_REF="{{ github.event.pull_request.head.sha }}"
else
GIT_REF="${GITHUB_SHA}"
fi
echo "GIT_REF=${GIT_REF}" >> $GITHUB_ENV
- name: Build Mirror Node All-in-One Docker Image and Export
uses: docker/build-push-action@v5
with:
build-args: GIT_REF=${{ env.GIT_REF }}
cache-from: type=gha
cache-to: type=gha,mode=max
context: ./hedera-mirror-rosetta/container
outputs: type=docker,dest=/tmp/${{ env.MODULE }}.tar
provenance: false
tags: ${{ env.MODULE }}:latest
- name: Upload Artifact
uses: actions/upload-artifact@v3
with:
name: ${{ env.IMAGE }}
path: /tmp/${{ env.MODULE }}.tar
if-no-files-found: error
validate:
runs-on: ubuntu-latest
needs: image
strategy:
matrix:
online-only: [ 'true', 'false' ]
timeout-minutes: 15
env:
OFFLINE_URL: http://localhost:5700
ROSETTA_CLI_VERSION: v0.10.3
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Download Artifact
uses: actions/download-artifact@v3
with:
name: ${{ env.IMAGE }}
path: /tmp
- name: Load Mirror Node ALl-in-One Docker Image
run: |
docker load --input /tmp/${MODULE}.tar
docker image ls -a
- name: Importer Configuration
run: echo "${{ secrets.ROSETTA_IMPORTER_CONFIG }}" | base64 -d > /tmp/application_importer.yml
- name: Rosetta Configuration
run: echo "${{ secrets.ROSETTA_ROSETTA_CONFIG }}" | base64 -d > /tmp/application_rosetta.yml
- name: Set Importer StartDate
run: |
# grep extracts the date up to minute, e.g., 2021-11-15T16:48:, so as to always round down to the whole minute
# and avoid importer saves the first account balance file but not the account balance entries
startdate=$(date --date='15 minutes ago' -Iseconds -u | grep -o -e '^[0-9T:-]\+:')
startdate="${startdate}00Z"
echo "STARTDATE=$startdate" >> $GITHUB_ENV
echo "Set importer startDate to $startdate"
- name: Run Mirror Node in Online Mode
run: |
ONLINE_CONTAINER_ID=$(docker run -d -e HEDERA_MIRROR_IMPORTER_STARTDATE=$STARTDATE \
-e NETWORK=testnet \
-e HEDERA_MIRROR_ROSETTA_RESPONSE_MAXTRANSACTIONSINBLOCK=4 \
-v /tmp/application_importer.yml:/app/importer/application.yml \
-v /tmp/application_rosetta.yml:/app/rosetta/application.yml \
-p 5700:5700 "${MODULE}:latest")
echo "ONLINE_CONTAINER_ID=$ONLINE_CONTAINER_ID" >> $GITHUB_ENV
- name: Run Mirror Node in Offline Mode
if: matrix.online-only != 'true'
run: |
# create an isolated network for offline mode and insert an iptables rule to drop any packets from the
# isolated network
docker network create --gateway 192.168.10.1 --subnet 192.168.10.0/24 isolated
sudo iptables -I DOCKER-USER --destination 0.0.0.0/0 --source 192.168.10.0/24 -j DROP
OFFLINE_CONTAINER_ID=$(docker run -d -e MODE=offline -e NETWORK=testnet --network isolated \
-v /tmp/application_rosetta.yml:/app/rosetta/application.yml \
-p 5701:5700 "${MODULE}:latest")
echo "OFFLINE_CONTAINER_ID=$OFFLINE_CONTAINER_ID" >> $GITHUB_ENV
echo "OFFLINE_URL=http://localhost:5701" >> $GITHUB_ENV
- name: Wait for Mirror Node to start syncing
run: ./scripts/wait-for-mirror-node.sh
env:
MAX_WAIT_SECONDS: 240
- name: Rosetta CLI Configuration
run: |
# add prefunded accounts for construction validation, override construction offline_url
echo "${{ secrets.ROSETTA_PREFUNDED_ACCOUNTS }}" | base64 -d > /tmp/accounts.json
cd ./scripts/validation/testnet/
jq --slurpfile accounts /tmp/accounts.json \
'.construction.prefunded_accounts=$accounts[0] | .construction.offline_url="${{ env.OFFLINE_URL }}"' \
validation.json > /tmp/validation.json
# set start index to genesis index + 1
body="{\"network_identifier\": $(cat validation.json | jq -c -M '.network')}"
startIndex=$(curl -sL -d "${body}" http://localhost:5700/network/status | jq '.genesis_block_identifier.index+1')
echo "Setting data start_index to $startIndex"
jq --argjson startIndex $startIndex '.data.start_index=$startIndex' /tmp/validation.json > validation.json
- name: Run Rosetta CLI Validation
working-directory: ./hedera-mirror-rosetta/scripts/validation
run: |
echo "Installing Rosetta CLI"
curl -sSfL https://raw.githubusercontent.com/coinbase/rosetta-cli/master/scripts/install.sh | \
sh -s -- -b . "${ROSETTA_CLI_VERSION}"
./run-validation.sh testnet construction > /tmp/construction-validation.log 2>&1 &
pid=$!
./run-validation.sh testnet data && code=0 || code=$?
[[ $code -eq 0 ]] && { wait $pid || code=$?; }
cat /tmp/construction-validation.log
exit $code
- name: Run Rosetta BDD Tests
working-directory: ./hedera-mirror-rosetta/test/bdd-client
run: |
export GOROOT=$GOROOT_1_21_X64
export PATH=$GOROOT/bin:$PATH
jq -r '.[] | {"privateKey": .privkey, "id": .account_identifier.address}' /tmp/accounts.json | \
jq -s '. | {operators: .} | .server.offlineUrl="${{ env.OFFLINE_URL }}" | {test: .} | {rosetta: .}
| {mirror: .} | {hedera: .}' | \
yq eval -P > application.yml
go test -v
- name: Run Rosetta Postman API Tests
working-directory: ./charts/hedera-mirror-rosetta
run: |
npm install -g newman
newman run postman.json
- name: Show Container Log
if: ${{ failure() && (env.OFFLINE_CONTAINER_ID != '' || env.ONLINE_CONTAINER_ID != '') }}
run: |
echo "Logs for offline container ${OFFLINE_CONTAINER_ID}"
[[ -n "${OFFLINE_CONTAINER_ID}" ]] && docker logs ${OFFLINE_CONTAINER_ID} || true
echo "Logs for online container ${ONLINE_CONTAINER_ID}"
[[ -n "${ONLINE_CONTAINER_ID}" ]] && docker logs ${ONLINE_CONTAINER_ID} || true
delete-image:
runs-on: ubuntu-latest
needs: validate
if: ${{ always() }}
steps:
- name: Delete Artifact
uses: geekyeggo/delete-artifact@v2
with:
name: ${{ env.IMAGE }}
failOnError: false
gosec:
runs-on: ubuntu-latest
env:
GO111MODULE: on
steps:
- uses: actions/checkout@v4
with:
path: tmp
- name: Copy hedera-mirror-rosetta to workspace root
working-directory: .
run: |
cp -r tmp/hedera-mirror-rosetta/* .
rm -fr tmp
- name: Run Gosec Security Scanner
uses: securego/[email protected]
with:
args: ./...