forked from aragon/buidler-aragon
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
1,306 additions
and
205 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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"require": "ts-node/register/files", | ||
"ignore": ["test/fixture-projects/**/*"], | ||
"timeout": 6000 | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
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
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export class ExampleHardhatRuntimeEnvironmentField { | ||
public sayHello() { | ||
return 'hello' | ||
} | ||
} |
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,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 | ||
) | ||
} | ||
) |
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 |
---|---|---|
@@ -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 | ||
} | ||
} |
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 |
---|---|---|
@@ -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 |
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 |
---|---|---|
@@ -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() | ||
}) | ||
} |
Oops, something went wrong.