Skip to content

Commit

Permalink
Add test project
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriel authored and 0xGabi committed Jul 7, 2021
1 parent 870e14d commit c8c2ae6
Show file tree
Hide file tree
Showing 12 changed files with 1,306 additions and 205 deletions.
5 changes: 5 additions & 0 deletions .mocharc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"require": "ts-node/register/files",
"ignore": ["test/fixture-projects/**/*"],
"timeout": 6000
}
110 changes: 0 additions & 110 deletions CONTRIBUTING.md

This file was deleted.

9 changes: 0 additions & 9 deletions bootstrap-paths.js

This file was deleted.

24 changes: 8 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "@aragon/buidler-aragon",
"name": "@1hive/hardhat-aragon",
"version": "0.2.9",
"description": "Aragon Buidler plugin",
"description": "Aragon Hardhat plugin",
"main": "dist/src/index.js",
"author": "Aragon Association <legal@aragon.org>",
"author": "1hive <info@1hive.org>",
"license": "GPL-3.0-or-later",
"keywords": [
"aragon",
"buidler",
"hardhat",
"plugin",
"ethereum"
],
Expand Down Expand Up @@ -37,7 +37,6 @@
"@solidity-parser/parser": "^0.6.0",
"chalk": "^3.0.0",
"chokidar": "^3.3.1",
"ethers": "^4.0.46",
"ethjs-ens": "^2.0.1",
"execa": "^4.0.0",
"fs-extra": "^8.1.0",
Expand Down Expand Up @@ -65,7 +64,6 @@
"@types/node-fetch": "^2.5.5",
"@types/semver": "^7.1.0",
"@types/sinon": "^7.5.2",
"@types/web3": "^1.2.2",
"@typescript-eslint/eslint-plugin": "^2.16.0",
"@typescript-eslint/parser": "^2.16.0",
"bignumber.js": "^9.0.0",
Expand All @@ -74,7 +72,8 @@
"eslint": "^6.8.0",
"eslint-config-prettier": "^6.9.0",
"eslint-plugin-prettier": "^3.1.2",
"ethers": "^4.0.46",
"ethers": "^5.1.4",
"hardhat": "^2.2.1",
"kill-port": "^1.6.0",
"nyc": "^15.0.1",
"prettier": "^1.19.1",
Expand All @@ -83,14 +82,7 @@
"ts-node": "^8.5.4",
"typechain": "^1.0.3",
"typechain-target-truffle": "^1.0.2",
"typescript": "^3.7.4",
"web3": "^1.2.0"
"typescript": "^3.7.4"
},
"peerDependencies": {
"@nomiclabs/buidler": "^1.3.0",
"@nomiclabs/buidler-etherscan": "^1.3.0",
"@nomiclabs/buidler-truffle5": "^1.3.0",
"@nomiclabs/buidler-web3": "^1.3.0",
"web3": "^1.2.0"
}
"peerDependencies": {}
}
5 changes: 5 additions & 0 deletions src/ExampleHardhatRuntimeEnvironmentField.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export class ExampleHardhatRuntimeEnvironmentField {
public sayHello() {
return 'hello'
}
}
106 changes: 85 additions & 21 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,91 @@
import { extendConfig } from 'hardhat/config'
import '../bootstrap-paths'
import { configExtender } from './config'
import { extendConfig, extendEnvironment, task } from 'hardhat/config'
import { lazyObject } from 'hardhat/plugins'
import { HardhatConfig, HardhatUserConfig } from 'hardhat/types'
import path from 'path'

// TODO: Don't use any type below, try to use something like these...
// import { ResolvedHardhatConfig, HardhatConfig } from 'hardhat/types'
import { ExampleHardhatRuntimeEnvironmentField } from './ExampleHardhatRuntimeEnvironmentField'
// This import is needed to let the TypeScript compiler know that it should include your type
// extensions in your npm package's types file.
import './type-extensions'

export default function(): void {
// Resolve tsconfig-paths at runtime.
require('../bootstrap-paths.js')
export const TASK_PUBLISH = 'publish'

// Plugin dependencies.
// usePlugin('hardhat-etherscan')
function normalizePath(
config: HardhatConfig,
userPath: string | undefined,
defaultPath: string
): string {
if (userPath === undefined) {
userPath = path.join(config.paths.root, defaultPath)
} else {
if (!path.isAbsolute(userPath)) {
userPath = path.normalize(path.join(config.paths.root, userPath))
}
}
return userPath
}

// Task definitions.
// Note: buidler sets up the environment by appending tasks to it. This happens when a task() function is called. Therefore, task() must be called on every test run, not only for the first time. However, when node imports a file with require the module body will only be run once on the first time and then use the cached result.
/* eslint-disable @typescript-eslint/no-var-requires */
const { setupPublishTask } = require('./tasks/publish')
setupPublishTask()
/* eslint-enable @typescript-eslint/no-var-requires */
extendConfig(
(config: HardhatConfig, userConfig: Readonly<HardhatUserConfig>) => {
config.paths.dist = normalizePath(config, userConfig.paths?.dist, 'dist')
}
)

// Environment extensions.
// No extensions atm.
extendEnvironment(hre => {
// We add a field to the Hardhat Runtime Environment here.
// We use lazyObject to avoid initializing things until they are actually
// needed.
hre.example = lazyObject(() => new ExampleHardhatRuntimeEnvironmentField())
})

// Default configuration values.
extendConfig(configExtender)
}
task(TASK_PUBLISH, 'Publish a new app version')
.addPositionalParam(
'bump',
'Type of bump (major, minor or patch) or semantic version',
undefined,
types.string
)
.addOptionalParam(
'contract',
'Contract address previously deployed.',
undefined,
types.string
)
.addOptionalParam(
'managerAddress',
'Owner of the APM repo. Must be provided in the initial release',
undefined,
types.string
)
.addOptionalParam(
'ipfsApiUrl',
'IPFS API URL to connect to an ipfs daemon API server',
'http://localhost:5001',
types.string
)
.addFlag(
'onlyContent',
'Prevents contract compilation, deployment and artifact generation.'
)
.addFlag('skipValidation', 'Skip validation of artifacts files.')
.addFlag('dryRun', 'Output tx data without broadcasting')
.setAction(
async (
params,
hre: HardhatRuntimeEnvironment
): Promise<apm.PublishVersionTxData> => {
// Do param type verification here and call publishTask with clean params
return await publishTask(
{
bumpOrVersion: params.bump,
existingContractAddress: params.contract,
managerAddress: params.managerAddress,
ipfsApiUrl: params.ipfsApiUrl,
onlyContent: params.onlyContent,
skipValidation: params.skipValidation,
dryRun: params.dryRun
},
hre
)
}
)
34 changes: 34 additions & 0 deletions src/type-extensions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// If your plugin extends types from another plugin, you should import the plugin here.

// To extend one of Hardhat's types, you need to import the module where it has been defined, and redeclare it.
import 'hardhat/types/config'
import 'hardhat/types/runtime'

import { ExampleHardhatRuntimeEnvironmentField } from './ExampleHardhatRuntimeEnvironmentField'

declare module 'hardhat/types/config' {
// This is an example of an extension to one of the Hardhat config values.

// We extendr the UserConfig type, which represents the config as writen
// by the users. Things are normally optional here.
export interface ProjectPathsUserConfig {
dist?: string
}

// We also extend the Config type, which represents the configuration
// after it has been resolved. This is the type used during the execution
// of tasks, tests and scripts.
// Normally, you don't want things to be optional here. As you can apply
// default values using the extendConfig function.
export interface ProjectPathsConfig {
dist: string
}
}

declare module 'hardhat/types/runtime' {
// This is an example of an extension to the Hardhat Runtime Environment.
// This new field will be available in tasks' actions, scripts, and tests.
export interface HardhatRuntimeEnvironment {
example: ExampleHardhatRuntimeEnvironmentField
}
}
14 changes: 14 additions & 0 deletions test/fixture-project/hardhat-project/hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// We load the plugin here.
import { HardhatUserConfig } from 'hardhat/types'

import '../../../src/index'

const config: HardhatUserConfig = {
solidity: '0.7.3',
defaultNetwork: 'hardhat',
paths: {
newPath: 'asd'
}
}

export default config
21 changes: 21 additions & 0 deletions test/helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { resetHardhatContext } from 'hardhat/plugins-testing'
import { HardhatRuntimeEnvironment } from 'hardhat/types'
import path from 'path'

declare module 'mocha' {
interface Context {
hre: HardhatRuntimeEnvironment
}
}

export function useEnvironment(fixtureProjectName: string) {
beforeEach('Loading hardhat environment', function() {
process.chdir(path.join(__dirname, 'fixture-projects', fixtureProjectName))

this.hre = require('hardhat')
})

afterEach('Resetting hardhat', function() {
resetHardhatContext()
})
}
Loading

0 comments on commit c8c2ae6

Please sign in to comment.