You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+2-102Lines changed: 2 additions & 102 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -115,8 +115,6 @@ The following configuration values can be added to the `.env` file:
115
115
116
116
#### Optional (DUX-specific config, no performance improvements):
117
117
118
-
- Set `GOERLI_FORK_API_KEY` to a valid [Infura](https://docs.infura.io/infura/networks/ethereum/how-to/secure-a-project/project-id) API key for Hardhat to use during e2e testing
119
-
120
118
- Set `MIGRATION_WEBHOOK_URL` for sending migration requests to discord
121
119
122
120
- Set `GASLESS_WEBHOOK_URL` for sending gasless vote requests to discord
@@ -135,9 +133,9 @@ The following configuration values can be added to the `.env` file:
135
133
136
134
### Tests
137
135
138
-
The Governance portal includes two test suites: Jest and Cypress
136
+
The Governance portal includes two test suites: Jest and E2E (TODO)
139
137
140
-
Jest tests under the folder `__tests__` currently execute unit tests of the platform. The e2e Cypress tests are under the `cypress` folder.
138
+
Jest tests under the folder `__tests__` currently execute unit tests of the platform.
141
139
142
140
#### Test commands
143
141
@@ -151,100 +149,6 @@ npm run test
151
149
npm run test:ci
152
150
```
153
151
154
-
Cypress:
155
-
156
-
```bash
157
-
# opens a cypress browser for the e2e
158
-
npm run e2e
159
-
160
-
# runs e2e tests in a headless manner, for CI systems
161
-
npm run e2e:headless
162
-
```
163
-
164
-
#### Goerli fork
165
-
166
-
By default, e2e tests run on a fork of Goerli. We do this because the governance contracts are deployed in Goerli for testing purposes. We also need to start the governance polling database services in a docker container so that the database and the forked chains are in sync. Please follow these steps:
167
-
168
-
1. First we want to spin up our networks: the forked Goerli and the forked Arbitrum Testnet (for testing gasless voting). The following command will start the two networks on ports 8545 and 8546 respectively.
169
-
170
-
```bash
171
-
npm run hardhat:gasless:config
172
-
```
173
-
174
-
2. When you see the accounts & keys displayed in the terminal, you can now start the dockerized database services. You may need to pull down the latest images from docker if you don't have them. In a new terminal window type these two commands:
175
-
176
-
```bash
177
-
docker-compose pull
178
-
179
-
docker-compose up
180
-
```
181
-
182
-
This will download two images, the first is a pre-seeded postgres database containing all the data you need to get started. The second one contains the API and ETL services required to work with our tests. This allows the test database to listen for events on the testchain, and return the requested data to the frontend, just as it is done in production. Wait a few minutes for the images to download and the services to start. When you see the following message displayed it means the services are ready and you can proceed to the next step:
183
-
184
-
`"Running a GraphQL API server at http://localhost:3001"`
185
-
186
-
Note: when you're finished running tests, you can remove the docker images by running `docker-compose down`. This will reset the database to its original state the next time you run the tests.
187
-
188
-
3. Now that our testchains and our database services are running, we can start the e2e tests. Run the following command in yet another new terminal window to start cypress:
189
-
190
-
```
191
-
npm run e2e
192
-
```
193
-
194
-
Note: Make sure to fill in the `GOERLI_FORK_API_KEY` environment variable.
195
-
196
-
You can use this local network from MetaMask, by switching to the "localhost:8545" network, with chain ID: `31337`. In order to get a wallet with some MKR and ETH you can run the script: `npm run fund` that will send some MKR and ETH to the first 50 wallets under the `/cypress/support/constants/keypairs.json`.
197
-
198
-
For more information about the fund process, take a look at `/scripts/setup.js`
199
-
200
-
**Writing e2e**:
201
-
202
-
Please refer to: https://docs.cypress.io/guides/references/best-practices and check current test examples under the cypress folder.
203
-
204
-
At the beginning of each test or describe-block, we run two commands to fork the hardhat networks & reset the database. This ensures that the tests are run from a clean slate and using the same blockchain and database state beforehand. Add the functions into a `before` or `beforeEach` block like this:
205
-
206
-
```js
207
-
before(() => {
208
-
forkNetwork(); // Restarts the blockchain & re-funds all the accounts
209
-
resetDatabase(); // Wipes the db and starts over from its initial state
210
-
});
211
-
```
212
-
213
-
**Windows support**
214
-
215
-
If you are using Windows and WSL you will need to install XLaunch to be able to launch a client for the UI, remember to disable access control.
216
-
217
-
#### Adding Data to the DB for Tests
218
-
219
-
The docker image of the gov polling db starts out with a very minimal amount of data (to conserve space), but you may require some extra data for tests. For example, you may want to add some additional polls, or add some delegates. Most of the tables in the DB have primary key constraints to other tables, which makes manually adding data via an `UPDATE` query time consuming and unstable. The easiest way to add data in a safe way is to have the gov polling db add this data on its own, the way it's done in production. The process works like this:
220
-
221
-
1. Spock adds block information (number & hash) to a row in a database.
222
-
2. Spock extracts the transactions from the block and scans these for specific events.
223
-
3. If an event is found, the corresponding event transformer is run to handle the event data, inserting the data into tables.
224
-
225
-
So, if we want to add a specific poll, first we locate the block in which the event was emitted (use Etherscan). We add the blocknumber to the list of blocknumbers in the `docker-compose.yml` file. Adding it to the `SEED_BLOCKS` environmental var (see example below).
226
-
227
-
```yml
228
-
spock:
229
-
image: makerdaodux/govpolldb-app:latest
230
-
container_name: spock-test-container
231
-
command: ['yarn', 'start-all']
232
-
environment:
233
-
- SEED_BLOCKS=5815619,6495082
234
-
depends_on:
235
-
postgres:
236
-
condition: service_healthy
237
-
ports: - '3001:3001'
238
-
```
239
-
240
-
Now, when the docker image is started or restarted, spock looks for the environmental variable and parses the block numbers that have been added. It then runs the process described above on each block, adding any events it finds to the respective tables.
241
-
242
-
NB: This data will not be persisted in the docker image when the image is shut down using the `docker-compose stop` command, but it will be recreated every time the ETL service is restarted, as long as it remains part of the `SEED_BLOCKS` env var.
243
-
244
-
**Future Enhancements:**
245
-
246
-
In time, this list of blocks will grow too large to maintain in this file. We can either permanently update the image with the data from these blocks, or move this list to an external file and load it into the env var that way.
247
-
248
152
### CI/CD
249
153
250
154
The CI/CD system is integrated with Github Actions.
@@ -255,14 +159,10 @@ After each push the system will execute:
255
159
256
160
- Unit test, execute Jest test suite
257
161
258
-
- E2E, executy cypress test suite and record results at https://dashboard.cypress.io/projects/uckcr1/runs
259
-
260
162
```bash
261
163
npm run start:ci
262
164
```
263
165
264
-
The command `npm run start:ci` launches a detached process with hardhat, executes e2e in a headless mode and kills the hardhat process.
0 commit comments