Skip to content

Commit

Permalink
Merge pull request #1 from ensdomains/prepare-for-new-contracts
Browse files Browse the repository at this point in the history
Slightly refactor test-env
  • Loading branch information
talentlessguy authored Jan 16, 2025
2 parents 0e566d4 + 7ccc8df commit 1b15f53
Show file tree
Hide file tree
Showing 7 changed files with 222 additions and 583 deletions.
56 changes: 15 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

## How it works

The testing environment used here is implemented in the stateless and stateful tests for ENS app.
The environment consists of two parts: the ganache Ethereum node, and the docker graph instance.
Which environment type you use is dependent on your testing circumstances.
The testing environment used here is implemented in the stateless and stateful tests for ENS app. The environment consists of two parts: the ganache Ethereum node, and the docker graph instance. Which environment type you use is dependent on your testing circumstances.

## Configuration

Expand All @@ -16,12 +14,7 @@ You can add a JSDoc type import to import the config type.
* @type {import('@ensdomains/ens-test-env').ENSTestEnvConfig}
**/
module.exports = {
deployCommand: 'yarn hardhat deploy',
tenderly: {
user: 'ens',
project: 'core',
key: 'tenderly-key',
},
deployCommand: 'pnpm hardhat deploy',
archive: {
subgraphId: 'QmXxAE7Urtv6TPa8o8XmPwLVQNbH6r35hRKHP63udTxTNa',
epochTime: 1646894980,
Expand All @@ -39,11 +32,7 @@ module.exports = {
},
fork: {
url: 'https://example.com',
},
wallet: {
mnemonic: 'test test test test test test test test test test test junk',
unlockedAccounts: ['0x0000000000000000000000000000000000000000'],
},
}
},
graph: {
bypassLocal: false,
Expand All @@ -69,29 +58,17 @@ module.exports = {

### Stateless

For most testing situations you can use the default settings, which will create a fresh mainnet
fork from a specified block as well as deploying a fresh subgraph with the same specified block
as it's start block.
For most testing situations you can use the default settings, which will create a fresh mainnet fork from a specified block as well as deploying a fresh subgraph with the same specified block as it's start block.

Tests should ideally be designed to be stateless where possible, which entails not using hardcoded
addresses and not relying on any specific blockchain/graph state. This allows for a much higher
test reliability and low maintenance.
Tests should ideally be designed to be stateless where possible, which entails not using hardcoded addresses and not relying on any specific blockchain/graph state. This allows for a much higher test reliability and low maintenance.

### Stateful

Some tests may require a specific existing state, for example if a test relies on an old deployment
of a contract which can no longer be accurately replicated from a fresh mainnet fork. The stateful
environment uses pre-existing subgraph data at a specified block to allow full state access prior
to the mainnet fork.
Some tests may require a specific existing state, for example if a test relies on an old deployment of a contract which can no longer be accurately replicated from a fresh mainnet fork. The stateful environment uses pre-existing subgraph data at a specified block to allow full state access prior to the mainnet fork.

The stateful environment can also be used to more closely replicate a production environment for
true full end-to-end tests. You may also want to use this environment for testing with your own
personal wallet without using mainnet.
The stateful environment can also be used to more closely replicate a production environment for true full end-to-end tests. You may also want to use this environment for testing with your own personal wallet without using mainnet.

The downside of using the stateful environment is that a test can potentially become unreliable if
one of it's dependencies changes. Alongside reliability, running a stateful test most of the time
will require access to a specific private key. Given this, you should try to avoid writing stateful
tests wherever possible.
The downside of using the stateful environment is that a test can potentially become unreliable if one of it's dependencies changes. Alongside reliability, running a stateful test most of the time will require access to a specific private key. Given this, you should try to avoid writing stateful tests wherever possible.

## Contract deployments

Expand All @@ -101,20 +78,17 @@ deployment script should be left in the repo to serve as an archive.

## Updating the graph-node dataset

Generally, you will want to set a graft variable in the `subgraph.yaml` file for the subgraph. You
can find more about the ENS subgraph [here](https://github.com/ensdomains/ens-subgraph). You'll also
documentation for grafting available [here](https://thegraph.com/docs/en/developer/create-subgraph-hosted/#grafting-onto-existing-subgraphs).
Generally, you will want to set a graft variable in the `subgraph.yaml` file for the subgraph. You can find more about the ENS subgraph [here](https://github.com/ensdomains/ens-subgraph). You'll also documentation for grafting available [here](https://thegraph.com/docs/en/developer/create-subgraph-hosted/#grafting-onto-existing-subgraphs).

To update the graph-node dataset, the BLOCK_HEIGHT variable must be changed within the `.env` file.
It should be set to the same value as the graft block.
To update the graph-node dataset, the BLOCK_HEIGHT variable must be changed within the `.env` file. It should be set to the same value as the graft block.

If the dataset is a dependency for a local test, you will need to first let your local graph-node
dataset update so that your test can pass.

Once your data is up to date, you can run

```bash
yarn ens-test-env data --compress
pnpm ens-test-env data --compress
```

in this directory, which will give you a archive file for your dataset.
Expand All @@ -123,7 +97,7 @@ in this directory, which will give you a archive file for your dataset.

```js
const file = `data_${BLOCK_HEIGHT}_${SUBGRAPH_ID}_${EPOCH_TIME}_${NETWORK}.archive`
// e.g. data_14119046_QmTmU4syjQb8gfNq8TCQGv441qp2zQMNKnQ4smjKhpLQ6F_1643850493_ropsten.archive.tar.lz4
// e.g. data_14119046_QmTmU4syjQb8gfNq8TCQGv441qp2zQMNKnQ4smjKhpLQ6F_1643850493_ropsten.archive.tar.gz
```

## Running the environment
Expand All @@ -132,9 +106,9 @@ After this you can run:

```bash
# Start
yarn ens-test-env start
pnpm ens-test-env start
# Load data only
yarn ens-test-env data --load
pnpm ens-test-env data --load
# Export generated data
yarn ens-test-env data --compress
pnpm ens-test-env data --compress
```
12 changes: 6 additions & 6 deletions src/ens-test-env.example.config.js → ens-test-env.config.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const path = require('path')
import path from 'node:path'

/**
* @type {import('./config').ENSTestEnvConfig}
* @type {import('./src/config').ENSTestEnvConfig}
* */
module.exports = {
deployCommand: 'yarn hardhat deploy',
buildCommand: 'yarn build',
export default {
deployCommand: 'pnpm hardhat deploy',
buildCommand: 'pnpm build',
labelHashes: [
{
hash: '0x4f5b812789fc606be1b3b16908db13fc7a9adf7ca72641f84d75b47069d3d7f0',
Expand All @@ -23,6 +23,6 @@ module.exports = {
],
paths: {
data: './data',
composeFile: './docker-compose.yml',
composeFile: './src/docker-compose.yml',
},
}
23 changes: 9 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,31 +1,25 @@
{
"name": "@ensdomains/ens-test-env",
"type": "module",
"version": "0.5.0-beta.2",
"version": "0.5.0-beta.5",
"files": [
"src"
],
"types": "src/index.d.ts",
"scripts": {
"ver": "pnpm version --no-workspaces-update",
"publish:local": "yalc publish --push --up"
},
"engines": {
"node": ">=18"
},
"dependencies": {
"@ethersproject/wallet": "^5.6.0",
"ansi-colors": "^4.1.1",
"cli-progress": "^3.10.0",
"commander": "^9.3.0",
"concurrently": "^7.1.0",
"docker-compose": "^0.24.7",
"commander": "^13.0.0",
"concurrently": "^9.1.2",
"docker-compose": "^1.1.0",
"dotenv": "^16.0.1",
"js-yaml": "^4.1.0",
"lz4": "^0.6.5",
"picocolors": "^1.1.1",
"progress-stream": "^2.0.0",
"tar-fs": "^2.1.1",
"wait-on": "^6.0.1"
"tar-fs": "^3.0.8",
"wait-on": "^8.0.2"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^6.7.5",
Expand All @@ -43,5 +37,6 @@
"yalc": "^1.0.0-pre.53"
},
"preferUnplugged": true,
"bin": "./src/index.js"
"bin": "./src/index.js",
"packageManager": "pnpm@9.4.0+sha512.f549b8a52c9d2b8536762f99c0722205efc5af913e77835dbccc3b0b0b2ca9e7dc8022b78062c17291c48e88749c70ce88eb5a74f1fa8c4bf5e18bb46c8bd83a"
}
Loading

0 comments on commit 1b15f53

Please sign in to comment.