Skip to content

Commit

Permalink
feat: split deploy tests in integration and runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
adjisb committed Dec 7, 2023
1 parent af5a206 commit a63c971
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 6 deletions.
19 changes: 15 additions & 4 deletions packages/deploy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,20 @@ where:
We assume that the imported contracts are well tested in their own package by
having enough unit tests and more that 80% coverage. This repo contains
integrations tests, tests for the deployment process and tests that verify the
integrity of the system. For example in the case of the `SignedMultiGiveaway`
contract we check the roles and the users assigned to them are correctly
configured.
runtime integrity of the system. For example in the case of the
`SignedMultiGiveaway` contract we check the roles and the users assigned to them
are correctly configured.

There are three directories to distinguish the type of test:

- runtime_test: tests that check the runtime consistency of the contracts. They
must be able to run on a live network, a forked network or after a local
deploy.
- integration_test: tests used to check some functionality of imported contract
when they interact together. They are meant to be run in a forked network or
on a local deploy, they don't necessarily work on a live network.
- test: tests in this folder are always executed they must run at least on a
local deploy.

To test the deployment process:

Expand All @@ -61,7 +72,7 @@ To test the deployment process:
`fork:deploy NETWORK` where NETWORK is `mainnet`,`polygon` ,`goerli`,`mumbai`,
etc.

The tests the integrity of the system:
To test the integrity of the system:

- using hardhat local node and `hardhat-deploy` deployment scripts: `yarn test`
- on a live network over contracts that are already deployed:
Expand Down
1 change: 1 addition & 0 deletions packages/deploy/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
addNodeAndMnemonic,
skipDeploymentsOnLiveNetworks,
} from './utils/hardhatConfig';
import './tasks/specialTests';
import './tasks/importedPackages';

// Package name : solidity source code path
Expand Down
4 changes: 3 additions & 1 deletion packages/deploy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
],
"scripts": {
"compile": "hardhat compile",
"test": "cross-env NODE_OPTIONS=\"--max-old-space-size=8192 node --unhandled-rejections=strict\" HARDHAT_COMPILE=true hardhat test",
"test": "cross-env NODE_OPTIONS=\"--max-old-space-size=8192 node --unhandled-rejections=strict\" HARDHAT_COMPILE=true yarn hardhat test && yarn test:integration && yarn test:runtime",
"test:integration": "cross-env NODE_OPTIONS=\"--max-old-space-size=8192 node --unhandled-rejections=strict\" HARDHAT_COMPILE=true hardhat test --integration",
"test:runtime": "cross-env NODE_OPTIONS=\"--max-old-space-size=8192 node --unhandled-rejections=strict\" HARDHAT_COMPILE=true hardhat test --runtime",
"void:deploy": "cross-env NODE_OPTIONS=\"--max-old-space-size=8192 --unhandled-rejections=strict\" hardhat deploy",
"deploy": "npm run void:deploy",
"hardhat": "hardhat",
Expand Down
2 changes: 1 addition & 1 deletion packages/deploy/tasks/importedPackages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ declare module 'hardhat/types/runtime' {
}
declare module 'hardhat/types/config' {
interface HardhatUserConfig {
importedPackages: {[name: string]: string};
importedPackages: {[name: string]: string | string[]};
}
}

Expand Down
15 changes: 15 additions & 0 deletions packages/deploy/tasks/specialTests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import {task} from 'hardhat/config';
import {TASK_TEST} from 'hardhat/builtin-tasks/task-names';
import path from 'path';

task(TASK_TEST)
.addFlag('runtime', 'run runtime tests')
.addFlag('integration', 'run integration tests')
.setAction(async (args, {config}, runSuper) => {
if (args.runtime) {
config.paths.tests = path.resolve(config.paths.root, 'runtime_test');
} else if (args.integration) {
config.paths.tests = path.resolve(config.paths.root, 'integration_test');
}
return await runSuper(args);
});
2 changes: 2 additions & 0 deletions packages/deploy/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
"./deploy_mocks",
"./utils",
"./tasks",
"./integration_test",
"./runtime_test",
"./test"
]
}

0 comments on commit a63c971

Please sign in to comment.