-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: allow tests to run in parallel
- Loading branch information
Showing
5 changed files
with
335 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,36 @@ | ||
import { wallet } from './services/fuel-core/chainConfig.json'; | ||
import { hexlify } from '@ethersproject/bytes'; | ||
|
||
process.env.GENESIS_SECRET = wallet.privateKey; | ||
import faucets from './services/fuel-core/faucets.json'; | ||
|
||
/** | ||
* Gets the private key for the current Jest worker. | ||
* | ||
* The PK is basically the current worker's ID. This allows us to | ||
* have a unique faucet wallet for each file being tested and prevents | ||
* tests from trying to access to the same coins and fail. | ||
* | ||
* Both `faucets.json` and `initial_state.coins` in `chainConfig.json` | ||
* were manually generated to support at most 16 workers. | ||
* | ||
* For each wallet in `faucets.json`, there are three coins for each | ||
* of the following Asset IDs: | ||
* - 0x0000000000000000000000000000000000000000000000000000000000000000 | ||
* - 0x0101010101010101010101010101010101010101010101010101010101010101 | ||
* - 0x0202020202020202020202020202020202020202020202020202020202020202 | ||
* | ||
* See: https://jestjs.io/docs/environment-variables#jest_worker_id | ||
*/ | ||
const getPrivateKeyForCurrentWorker = () => { | ||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
const workerId = Number.parseInt(process.env.JEST_WORKER_ID!, 10); | ||
|
||
if (workerId > faucets.length) { | ||
throw new Error(`At most ${faucets.length} workers are supported.`); | ||
} | ||
|
||
const privateKey = hexlify([workerId]); | ||
|
||
return privateKey; | ||
}; | ||
|
||
process.env.GENESIS_SECRET = getPrivateKeyForCurrentWorker(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.