-
Notifications
You must be signed in to change notification settings - Fork 2
179 lines (148 loc) · 6.05 KB
/
test.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
name: Build and Test
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
test:
name: Build and Test
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
token: ${{ github.token }}
- name: Install Rust (simplified for act)
if: ${{ env.ACT }}
run: |
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
source "$HOME/.cargo/env"
# Install the specific toolchain version from rust-toolchain.toml if it exists
if [ -f "rust-toolchain.toml" ]; then
TOOLCHAIN=$(grep -oP 'channel\s*=\s*"\K[^"]+' rust-toolchain.toml || echo "stable")
rustup toolchain install $TOOLCHAIN
rustup default $TOOLCHAIN
else
rustup default stable
fi
rustup component add rustfmt clippy
- name: Install Rust (GitHub Actions)
if: ${{ !env.ACT }}
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
components: rustfmt, clippy
- name: Cache dependencies
uses: actions/cache@v3
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-
- name: Cleanup existing containers
run: |
# Stop and remove any existing containers with the same names
docker stop miden-node miden-node-init miden-node-genesis 2>/dev/null || true
docker rm miden-node miden-node-init miden-node-genesis 2>/dev/null || true
- name: Checkout Miden Node v0.7.2
uses: actions/checkout@v3
with:
repository: 0xPolygonMiden/miden-node
path: miden-node
ref: v0.7.2
token: ${{ github.token }}
- name: Clone Miden Node (fallback)
if: ${{ failure() }}
run: |
git clone --depth 1 --branch v0.7.2 https://github.com/0xPolygonMiden/miden-node.git miden-node
- name: Build Miden Node Docker Image
run: |
cd miden-node
# Build the Docker image using the commands from the Makefile
CREATED=$(date) && \
VERSION=$(cat bin/node/Cargo.toml | grep -m 1 '^version' | cut -d '"' -f 2) && \
COMMIT=$(git rev-parse HEAD) && \
docker build --build-arg CREATED="$CREATED" \
--build-arg VERSION="$VERSION" \
--build-arg COMMIT="$COMMIT" \
-f bin/node/Dockerfile \
-t miden-node-image .
- name: Initialize and Start Miden Node
run: |
# Clean up any existing data directory
rm -rf data
# Create a directory for node data
mkdir -p data
# Create a Docker container for initialization
docker run --name miden-node-init \
-v "$(pwd):/workspace" \
-w /workspace \
miden-node-image \
miden-node init --config-path miden-node.toml --genesis-path genesis.toml
# Create genesis data
docker run --name miden-node-genesis \
-v "$(pwd):/workspace" \
-w /workspace \
miden-node-image \
miden-node make-genesis --inputs-path genesis.toml --output-path genesis.dat --force
# Clean up initialization containers
docker rm miden-node-init miden-node-genesis
# Start the node
docker run --name miden-node \
-p 57291:57291 \
-v "$(pwd):/workspace" \
-w /workspace \
-d miden-node-image \
miden-node start --config miden-node.toml node
# Wait for the node to start
echo "Waiting for Miden node to start..."
sleep 30
# Check if the node is running
if ! docker ps | grep miden-node > /dev/null; then
echo "Miden node failed to start"
docker logs miden-node || true
exit 1
else
echo "Miden node started successfully"
docker logs miden-node
fi
- name: Build Project
run: |
# Source cargo environment if running with act
if [ -n "$ACT" ]; then
source "$HOME/.cargo/env"
fi
cargo build --verbose
- name: Run tests
run: |
# Source cargo environment if running with act
if [ -n "$ACT" ]; then
source "$HOME/.cargo/env"
fi
# Set environment variables to connect to the Docker container
export MIDEN_NODE_URL=http://localhost:57291
export RUST_BACKTRACE=1
# Run tests one at a time to avoid database conflicts
echo "Running test_oracle_get_entry..."
cargo test --package pm-accounts --test test_oracle test_oracle_get_entry --verbose -- --nocapture
echo "Running test_oracle_register_publisher..."
cargo test --package pm-accounts --test test_oracle test_oracle_register_publisher --verbose -- --nocapture
echo "Running test_oracle_get_median..."
cargo test --package pm-accounts --test test_oracle test_oracle_get_median --verbose -- --nocapture
echo "Running test_publisher tests..."
cargo test --package pm-accounts --test test_publisher --verbose -- --nocapture
- name: Show Node Logs
if: always()
run: |
docker logs miden-node || true
- name: Stop Miden Node
if: always()
run: |
docker stop miden-node || true
docker rm miden-node || true