@0xweb/hardhat 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,31 @@
1
+ # See: https://circleci.com/docs/2.0/configuration-reference
2
+ version: 2.1
3
+
4
+ orbs:
5
+ # See the orb documentation here: https://circleci.com/developer/orbs/orb/circleci/node
6
+ node: circleci/node@5.0.2
7
+
8
+ jobs:
9
+ build-and-test:
10
+ # These next lines define a Docker executor: https://circleci.com/docs/2.0/executor-types/
11
+ # https://circleci.com/developer/images/image/cimg/node
12
+ docker:
13
+ - image: cimg/node:18.0.0
14
+ steps:
15
+ - checkout
16
+ - node/install-packages:
17
+ pkg-manager: npm
18
+ - run:
19
+ name: Build Project
20
+ command: npm run build
21
+ - run:
22
+ name: Run tests
23
+ command: npm run test
24
+
25
+ workflows:
26
+ # Inside the workflow, you provide the jobs you want to run, e.g this workflow runs the build-and-test job above.
27
+ # CircleCI will run this workflow on every commit.
28
+ # https://circleci.com/docs/2.0/configuration-reference/#workflows
29
+ TestRunner:
30
+ jobs:
31
+ - build-and-test
@@ -1,6 +1,7 @@
1
1
  require("@nomiclabs/hardhat-web3");
2
2
  require("@nomiclabs/hardhat-waffle");
3
3
  require("@nomiclabs/hardhat-etherscan");
4
+ require("@0xweb/hardhat");
4
5
 
5
6
  module.exports = {
6
7
  solidity: {
package/lib/index.js ADDED
@@ -0,0 +1,180 @@
1
+
2
+ // source ./RootModule.js
3
+ (function(){
4
+
5
+ var _src_config = {};
6
+ var _src_constants = {};
7
+
8
+ // source ./ModuleSimplified.js
9
+ var _src_config;
10
+ (function () {
11
+ // ensure AMD is not active for the model, so that any UMD exports as commonjs
12
+ var define = null;
13
+ var exports = _src_config != null ? _src_config : {};
14
+ var module = { exports: exports };
15
+
16
+ "use strict";
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.resolveConfig = void 0;
19
+ function resolveConfig(config) {
20
+ var _a;
21
+ const defaultConfig = {};
22
+ return {
23
+ ...defaultConfig,
24
+ ...((_a = config['0xweb']) !== null && _a !== void 0 ? _a : {}),
25
+ };
26
+ }
27
+ exports.resolveConfig = resolveConfig;
28
+ //# sourceMappingURL=config.js.map
29
+ //# sourceMappingURL=config.ts.map;
30
+
31
+ function __isObj(x) {
32
+ return x != null && typeof x === 'object' && x.constructor === Object;
33
+ }
34
+ if (_src_config === module.exports) {
35
+ // do nothing if
36
+ } else if (__isObj(_src_config) && __isObj(module.exports)) {
37
+ Object.assign(_src_config, module.exports);
38
+ } else {
39
+ _src_config = module.exports;
40
+ }
41
+
42
+ ;
43
+ }());
44
+
45
+ // end:source ./ModuleSimplified.js
46
+
47
+
48
+ // source ./ModuleSimplified.js
49
+ var _src_constants;
50
+ (function () {
51
+ // ensure AMD is not active for the model, so that any UMD exports as commonjs
52
+ var define = null;
53
+ var exports = _src_constants != null ? _src_constants : {};
54
+ var module = { exports: exports };
55
+
56
+ "use strict";
57
+ Object.defineProperty(exports, "__esModule", { value: true });
58
+ exports.TASK_0xWEB_GENERATE = exports.TASK_0xWEB = void 0;
59
+ exports.TASK_0xWEB = '0xweb';
60
+ exports.TASK_0xWEB_GENERATE = '0xweb:generate';
61
+ //# sourceMappingURL=constants.js.map
62
+ //# sourceMappingURL=constants.ts.map;
63
+
64
+ function __isObj(x) {
65
+ return x != null && typeof x === 'object' && x.constructor === Object;
66
+ }
67
+ if (_src_constants === module.exports) {
68
+ // do nothing if
69
+ } else if (__isObj(_src_constants) && __isObj(module.exports)) {
70
+ Object.assign(_src_constants, module.exports);
71
+ } else {
72
+ _src_constants = module.exports;
73
+ }
74
+
75
+ ;
76
+ }());
77
+
78
+ // end:source ./ModuleSimplified.js
79
+
80
+ "use strict";
81
+ Object.defineProperty(exports, "__esModule", { value: true });
82
+ const alot_1 = require("alot");
83
+ const task_names_1 = require("hardhat/builtin-tasks/task-names");
84
+ const config_1 = require("hardhat/config");
85
+ const config_2 = _src_config;
86
+ const constants_1 = _src_constants;
87
+ const atma_io_1 = require("atma-io");
88
+ const _0xweb_1 = require("0xweb");
89
+ const taskArgsStore = { compileAll: false };
90
+ (0, config_1.extendConfig)((config) => {
91
+ config['0xweb'] = (0, config_2.resolveConfig)(config);
92
+ });
93
+ (0, config_1.task)(task_names_1.TASK_COMPILE, 'Compiles the entire project, building all artifacts')
94
+ .addOptionalParam('sources', 'Override the sources directory')
95
+ .addOptionalParam('artifacts', 'Override the artifacts output directory')
96
+ .setAction(async (compilationArgs, { run, config }, runSuper) => {
97
+ if (compilationArgs.sources) {
98
+ config.paths.sources = process.cwd() + compilationArgs.sources;
99
+ }
100
+ if (compilationArgs.artifacts) {
101
+ config.paths.artifacts = process.cwd() + compilationArgs.artifacts;
102
+ }
103
+ await runSuper();
104
+ });
105
+ (0, config_1.subtask)(task_names_1.TASK_COMPILE_SOLIDITY_COMPILE_JOBS, 'Compiles the entire project, building all artifacts')
106
+ .setAction(async (taskArgs, { run }, runSuper) => {
107
+ const compileSolOutput = await runSuper(taskArgs);
108
+ await run(constants_1.TASK_0xWEB_GENERATE, { compileSolOutput });
109
+ return compileSolOutput;
110
+ });
111
+ (0, config_1.subtask)(constants_1.TASK_0xWEB_GENERATE)
112
+ .setAction(async (a, b) => {
113
+ let { compileSolOutput } = a;
114
+ let { config, artifacts } = b;
115
+ const contracts = await getCompiledAbis(config, compileSolOutput);
116
+ const app = new _0xweb_1.App();
117
+ await (0, alot_1.default)(contracts)
118
+ .forEachAsync(async (contract, i) => {
119
+ console.log(`Generation ${contract.name}(${contract.path}) ${i}/${contracts.length}`);
120
+ await app.execute([`install`, `${contract.path}`, '--name', contract.name, '--chain', 'hardhat']);
121
+ })
122
+ .toArrayAsync({ threads: 1 });
123
+ });
124
+ (0, config_1.task)(constants_1.TASK_0xWEB, 'Generate 0xWeb classes for compiled contracts')
125
+ .setAction(async (_, { run }) => {
126
+ taskArgsStore.compileAll = true;
127
+ await run(task_names_1.TASK_COMPILE, { quiet: true });
128
+ });
129
+ (0, config_1.task)(task_names_1.TASK_CLEAN, 'Clears the cache and deletes all artifacts')
130
+ .setAction(async ({ global }, { config }, runSuper) => {
131
+ if (global) {
132
+ return;
133
+ }
134
+ const dir = `/0xweb/hardhat/`;
135
+ if (await atma_io_1.Directory.existsAsync(dir)) {
136
+ await atma_io_1.Directory.removeAsync(dir);
137
+ }
138
+ await runSuper();
139
+ });
140
+ async function getCompiledAbis(config, compileSolOutput) {
141
+ const emitedArtifacts = (0, alot_1.default)(compileSolOutput.artifactsEmittedPerJob).mapMany((a) => {
142
+ return (0, alot_1.default)(a.artifactsEmittedPerFile).mapMany((artifactPerFile) => {
143
+ return (0, alot_1.default)(artifactPerFile.artifactsEmitted).map((artifactName) => {
144
+ return {
145
+ name: artifactName,
146
+ sourceFile: 'file://' + artifactPerFile.file.absolutePath
147
+ };
148
+ }).toArray();
149
+ }).toArray();
150
+ }).toArray();
151
+ let namesHash = (0, alot_1.default)(emitedArtifacts).toDictionary(x => x.name);
152
+ let files = await atma_io_1.Directory.readFilesAsync(`file://${config.paths.artifacts}/`, '**.json');
153
+ let compileAll = taskArgsStore.compileAll;
154
+ let arr = files
155
+ .map(file => {
156
+ let path = file.uri.toString();
157
+ let match = /(?<name>[^\\\/]+)\.sol[\\\/]/.exec(path);
158
+ if (match == null) {
159
+ return null;
160
+ }
161
+ let name = match.groups.name;
162
+ if (compileAll !== true && name in namesHash === false) {
163
+ return null;
164
+ }
165
+ if (new RegExp(`${name}\\.json$`).test(path) === false) {
166
+ return null;
167
+ }
168
+ return {
169
+ name: name,
170
+ path: path
171
+ };
172
+ })
173
+ .filter(Boolean);
174
+ return arr;
175
+ }
176
+ //# sourceMappingURL=index.js.map
177
+ //# sourceMappingURL=index.ts.map
178
+
179
+ }());
180
+ // end:source ./RootModule.js
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@0xweb/hardhat",
3
- "description": "Hardhat addon for 0xweb",
4
- "version": "0.1.0",
5
- "main": "./index.js",
3
+ "description": "Hardhat plugin for 0xweb",
4
+ "version": "0.1.1",
5
+ "main": "./lib/index.js",
6
6
  "author": {
7
7
  "name": "Alex Kit",
8
8
  "email": "alex.kit@atmajs.com"
@@ -18,16 +18,101 @@
18
18
  ],
19
19
  "license": "MIT",
20
20
  "dependencies": {
21
+ "0xweb": "^0.9.25",
22
+ "alot": "^0.3.0",
21
23
  "memd": "^0.3.10"
22
24
  },
23
25
  "peerDependencies": {
24
26
  "@nomiclabs/hardhat-etherscan": ">=3.0.3",
25
27
  "@nomiclabs/hardhat-waffle": ">=2.0.3",
26
28
  "@nomiclabs/hardhat-web3": ">=2.0.0",
27
- "ethers": ">=5.6.4",
28
29
  "hardhat": ">=2.9.3"
29
30
  },
30
31
  "scripts": {
31
-
32
+ "build": "app-bundler",
33
+ "watch": "app-bundler --watch",
34
+ "test": "atma --openssl-legacy-provider test",
35
+ "release": "echo \"Run atma pub -m \"message\"\""
36
+ },
37
+ "devDependencies": {
38
+ "app-bundler": "^0.1.7",
39
+ "atma": "^0.15.17",
40
+ "shellbee": "^0.5.22"
41
+ },
42
+ "app-bundler": {
43
+ "file": "src/index.ts",
44
+ "outputMain": "lib/index.js",
45
+ "package": {
46
+ "module": "commonjs",
47
+ "commonjs": {
48
+ "output": "simplified"
49
+ }
50
+ },
51
+ "extensions": {
52
+ "io": {
53
+ "type": "js"
54
+ }
55
+ },
56
+ "defaultExtensions": {
57
+ "js": "ts"
58
+ },
59
+ "dynamicDependencies": [
60
+ "alot",
61
+ "atma-io",
62
+ "0xweb",
63
+ "^hardhat"
64
+ ],
65
+ "middlewares": {
66
+ "ts": [
67
+ "atma-loader-ts:read"
68
+ ]
69
+ },
70
+ "settings": {
71
+ "atma-loader-ts": {
72
+ "typescript": {
73
+ "compilerOptions": {
74
+ "module": "CommonJS",
75
+ "lib": [
76
+ "ES2019"
77
+ ],
78
+ "target": "ES2019"
79
+ }
80
+ }
81
+ }
82
+ }
83
+ },
84
+ "atma": {
85
+ "plugins": [
86
+ "atma-loader-ts"
87
+ ],
88
+ "settings": {
89
+ "atma-utest": {
90
+ "include": {
91
+ "amd": true,
92
+ "extentionDefault": {
93
+ "js": "ts"
94
+ }
95
+ }
96
+ },
97
+ "include": {
98
+ "amd": true,
99
+ "extentionDefault": {
100
+ "js": "ts"
101
+ }
102
+ },
103
+ "atma-loader-ts": {
104
+ "typescript": {
105
+ "compilerOptions": {
106
+ "#if (TEST)": {
107
+ "module": "AMD"
108
+ },
109
+ "#if (!TEST)": {
110
+ "module": "commonjs"
111
+ },
112
+ "sourceMap": false
113
+ }
114
+ }
115
+ }
116
+ }
32
117
  }
33
118
  }
package/readme.md CHANGED
@@ -1,8 +1,99 @@
1
- # [Hardhat](https://hardhat.org/) addon for [`0xWeb`](https://0xweb.org)
1
+ # [Hardhat](https://hardhat.org/) plugin for [`0xWeb`](https://0xweb.org)
2
2
 
3
3
 
4
- ### Distribution `as-Source-Code`
4
+ ----
5
+ [![npm version](https://badge.fury.io/js/@0xweb%2Fhardhat.svg)](https://badge.fury.io/js/@0xweb%2Fhardhat)
6
+ [![CircleCI](https://circleci.com/gh/0xweb-org/hardhat.svg?style=svg)](https://circleci.com/gh/0xweb-org/hardhat)
7
+
8
+
9
+ The plugin generates `0xWeb` classes for compiled solidity contracts, making the blockchain development transparent.
10
+
11
+ > We use [📦 dequanto library](https://github.com/0xweb-org/dequanto) for the classes
12
+
13
+ ---
14
+ [Documentation 📜](https://docs.0xweb.org/hardhat/info)
15
+ ---
16
+
17
+ # Install
18
+
19
+ ### Install automatically the dependencies and configurations
20
+ ```bash
21
+ # install 0xweb
22
+ $ npm i 0xweb -g
23
+
24
+ # initiallize 0xweb and hardhat project
25
+ $ 0xweb init --hardhat
26
+ ```
27
+
28
+
29
+
30
+ # Compile
31
+
32
+ > `any/directory/Foo.sol`
33
+
34
+ ```solidity
35
+ pragma solidity ^0.8.2;
36
+
37
+ contract Foo {
38
+ string public name;
39
+
40
+ function setName(string memory _name) public {
41
+ name = _name;
42
+ }
43
+ }
44
+
45
+ ```
46
+
47
+ > Plugin adds also ability to specify the `sources` folder. As per default this is `/contracts/**.sol`
48
+
49
+ ```bash
50
+ $ npx hardhat compile --sources ./any/directory/
51
+ ```
52
+
53
+ # Use in local development
54
+
55
+ > `example.ts`
56
+ ```ts
57
+ import { Foo } from '@0xweb/hardhat/Foo/Foo.ts'
58
+ import { HardhatProvider } from '@dequanto/hardhat/HardhatProvider'
59
+
60
+ // automatically deploys the contract to hardhat chain
61
+ const deployer = new HardhatProvider();
62
+ const foo = await deployer.resolve(Foo);
63
+
64
+ // write
65
+ const tx = await foo.setName('Hello world')
66
+ const receipt = await tx.wait();
67
+
68
+ // read
69
+ const text = await foo.name();
70
+
71
+ ```
72
+
73
+ # Use already deployed contracts to any chain
74
+
75
+ If the contract is already deployed, initialize the contract with the Address as normal class. If the contract is deployed to any other chain - set also the client in constructor
76
+
77
+ > `example.ts`
78
+ ```ts
79
+ import { Foo } from '@0xweb/hardhat/Foo/Foo.ts'
80
+ import { EthWeb3Client } from '@dequanto/clients/EthWeb3Client'
81
+
82
+
83
+ const client = new EthWeb3Client();
84
+ const foo = new Foo('0x12345...', client);
85
+
86
+ // write
87
+ const tx = await foo.setName('Hello world');
88
+ const receipt = tx.wait();
89
+ // read
90
+ const text = await foo.name();
91
+ ```
92
+
93
+
94
+ # Additional parameters
5
95
 
6
- A factory class to initialize and configurate the generated contract class by `0xweb` to be used in `Hardhat` network - `in-process` or `localhost`
96
+ - `npx hardhat compile --source /foo/bar/qux` - compiles solidity files which are located outside the `/contracts` folder
97
+ - `npx hardhat compile --artifacts /dist` - set custom folder for artifacts (ABI JSONs and TS contracts)
7
98
 
8
99
  ----
package/src/config.ts ADDED
@@ -0,0 +1,13 @@
1
+ import { HardhatConfig } from 'hardhat/types'
2
+
3
+ import { _0xwebConfig } from './types'
4
+
5
+ export function resolveConfig(config: HardhatConfig): _0xwebConfig {
6
+ const defaultConfig: _0xwebConfig = {
7
+ }
8
+
9
+ return {
10
+ ...defaultConfig,
11
+ ...(config['0xweb'] ?? {}),
12
+ };
13
+ }
@@ -0,0 +1,2 @@
1
+ export const TASK_0xWEB = '0xweb'
2
+ export const TASK_0xWEB_GENERATE = '0xweb:generate'
package/src/index.ts ADDED
@@ -0,0 +1,120 @@
1
+ import alot from 'alot'
2
+ import { TASK_CLEAN, TASK_COMPILE, TASK_COMPILE_SOLIDITY_COMPILE_JOBS } from 'hardhat/builtin-tasks/task-names'
3
+ import { extendConfig, subtask, task } from 'hardhat/config'
4
+ import { resolveConfig } from './config'
5
+ import { TASK_0xWEB, TASK_0xWEB_GENERATE } from './constants'
6
+ import { Directory } from 'atma-io'
7
+ import { App } from '0xweb'
8
+
9
+ const taskArgsStore = { compileAll: false }
10
+
11
+ extendConfig((config) => {
12
+ config['0xweb'] = resolveConfig(config)
13
+ })
14
+
15
+ task(TASK_COMPILE, 'Compiles the entire project, building all artifacts')
16
+ .addOptionalParam('sources', 'Override the sources directory')
17
+ .addOptionalParam('artifacts', 'Override the artifacts output directory')
18
+ .setAction(async (compilationArgs, { run, config }, runSuper) => {
19
+
20
+ if (compilationArgs.sources) {
21
+ config.paths.sources = process.cwd() + compilationArgs.sources;
22
+ }
23
+ if (compilationArgs.artifacts) {
24
+ config.paths.artifacts = process.cwd() + compilationArgs.artifacts;
25
+ }
26
+ await runSuper()
27
+ });
28
+
29
+ subtask(TASK_COMPILE_SOLIDITY_COMPILE_JOBS, 'Compiles the entire project, building all artifacts')
30
+ .setAction(async (taskArgs, { run }, runSuper) => {
31
+ const compileSolOutput = await runSuper(taskArgs)
32
+ await run(TASK_0xWEB_GENERATE, { compileSolOutput })
33
+ return compileSolOutput
34
+ });
35
+
36
+ subtask(TASK_0xWEB_GENERATE)
37
+ .setAction(async (a, b) => {
38
+ let { compileSolOutput } = a;
39
+ let { config, artifacts } = b;
40
+
41
+ const contracts = await getCompiledAbis(config, compileSolOutput)
42
+
43
+ const app = new App();
44
+ await alot(contracts)
45
+ .forEachAsync(async (contract, i) => {
46
+ console.log(`Generation ${contract.name}(${contract.path}) ${i}/${contracts.length}`);
47
+ await app.execute([`install`, `${contract.path}`, '--name', contract.name, '--chain', 'hardhat'])
48
+ })
49
+ .toArrayAsync({ threads: 1 })
50
+ });
51
+
52
+ task(TASK_0xWEB, 'Generate 0xWeb classes for compiled contracts')
53
+ .setAction(async (_, { run }) => {
54
+ taskArgsStore.compileAll = true
55
+ await run(TASK_COMPILE, { quiet: true })
56
+ });
57
+
58
+ task(TASK_CLEAN, 'Clears the cache and deletes all artifacts')
59
+ .setAction(async ({ global }: { global: boolean }, { config }, runSuper) => {
60
+ if (global) {
61
+ return;
62
+ }
63
+ const dir = `/0xweb/hardhat/`;
64
+ if (await Directory.existsAsync(dir)) {
65
+ await Directory.removeAsync(dir);
66
+ }
67
+ await runSuper()
68
+ });
69
+
70
+ async function getCompiledAbis(config: { paths: { artifacts: string } }, compileSolOutput: {
71
+ artifactsEmittedPerJob: {
72
+ artifactsEmittedPerFile: {
73
+ file: {
74
+ sourceName: string
75
+ absolutePath: string
76
+ }
77
+ artifactsEmitted: string[]
78
+ }[]
79
+ }[]
80
+ }): Promise<{ name: string, path: string }[]> {
81
+
82
+ const emitedArtifacts = alot(compileSolOutput.artifactsEmittedPerJob).mapMany((a) => {
83
+ return alot(a.artifactsEmittedPerFile).mapMany((artifactPerFile) => {
84
+ return alot(artifactPerFile.artifactsEmitted).map((artifactName) => {
85
+ return {
86
+ name: artifactName,
87
+ sourceFile: 'file://' + artifactPerFile.file.absolutePath
88
+ };
89
+ }).toArray();
90
+ }).toArray();
91
+ }).toArray();
92
+
93
+ let namesHash = alot(emitedArtifacts).toDictionary(x => x.name);
94
+ let files = await Directory.readFilesAsync(`file://${config.paths.artifacts}/`, '**.json');
95
+ let compileAll = taskArgsStore.compileAll;
96
+ let arr = files
97
+ .map(file => {
98
+ let path = file.uri.toString();
99
+
100
+ let match = /(?<name>[^\\\/]+)\.sol[\\\/]/.exec(path);
101
+ if (match == null) {
102
+ return null;
103
+ }
104
+ let name = match.groups.name;
105
+ if (compileAll !== true && name in namesHash === false) {
106
+ return null;
107
+ }
108
+ if (new RegExp(`${name}\\.json$`).test(path) === false) {
109
+ return null;
110
+ }
111
+
112
+ return {
113
+ name: name,
114
+ path: path
115
+ };
116
+ })
117
+ .filter(Boolean);
118
+
119
+ return arr;
120
+ }
package/src/types.ts ADDED
@@ -0,0 +1,4 @@
1
+
2
+ export interface _0xwebConfig {
3
+
4
+ }
@@ -0,0 +1,25 @@
1
+ import { run } from 'shellbee'
2
+ import { File, Directory } from 'atma-io'
3
+
4
+ const PROJ = `./test/fixtures/hardhat-project/`;
5
+ const PROJ_ARTIFACTS = `${PROJ}/artifacts/`;
6
+ const PROJ_0xWEB = `${PROJ}/0xweb/`;
7
+ UTest({
8
+ async $before () {
9
+ if (Directory.exists(PROJ_ARTIFACTS)) {
10
+ await Directory.removeAsync(PROJ_ARTIFACTS);
11
+ }
12
+ if (Directory.exists(PROJ_0xWEB)) {
13
+ await Directory.removeAsync(PROJ_0xWEB);
14
+ }
15
+ },
16
+ async 'should compile the project' () {
17
+
18
+ let result = await run({
19
+ command: 'node --openssl-legacy-provider compile.js',
20
+ cwd: PROJ
21
+ });
22
+ let content = await File.readAsync(`${PROJ_0xWEB}/hardhat/Foo/Foo.ts`, { skipHooks: true });
23
+ has_(content, 'class Foo extends ContractBase');
24
+ }
25
+ })
package/test/config.js ADDED
@@ -0,0 +1,8 @@
1
+ module.exports = {
2
+ suites: {
3
+ node : {
4
+ exec: 'node',
5
+ tests: 'test/**.spec.ts'
6
+ }
7
+ }
8
+ };
@@ -0,0 +1,10 @@
1
+ {
2
+ "contracts": {
3
+ "hardhat": {
4
+ "file://D:/eth/0xweb-hardhat/test/fixtures/hardhat-project/artifacts/contracts/Foo.sol/Foo.json": {
5
+ "name": "Foo",
6
+ "main": "./0xweb/hardhat/Foo/Foo.ts"
7
+ }
8
+ }
9
+ }
10
+ }
@@ -0,0 +1,6 @@
1
+ const hh = require('hardhat');
2
+
3
+ (async function() {
4
+ await hh.run('compile');
5
+ process.exit();
6
+ }());
@@ -0,0 +1,19 @@
1
+ pragma solidity ^0.8.2;
2
+
3
+ contract Foo {
4
+ string public name;
5
+ event Updated (string newName);
6
+
7
+ constructor(string memory _name) {
8
+ name = _name;
9
+ }
10
+
11
+ function setName(string memory _name) public {
12
+ name = _name;
13
+ emit Updated(name);
14
+ }
15
+
16
+ function getName () public view returns (string memory) {
17
+ return name;
18
+ }
19
+ }
@@ -0,0 +1,21 @@
1
+
2
+ require("@nomiclabs/hardhat-web3");
3
+ require("@nomiclabs/hardhat-waffle");
4
+ require('../../../lib/index');
5
+
6
+ module.exports = {
7
+ solidity: {
8
+ version: "0.8.2",
9
+ settings: {
10
+ optimizer: {
11
+ enabled: true,
12
+ runs: 200
13
+ }
14
+ }
15
+ },
16
+ networks: {
17
+ hardhat: {
18
+ chainId: 1337
19
+ }
20
+ }
21
+ };
@@ -0,0 +1,8 @@
1
+ const hh = require('hardhat');
2
+
3
+ (async function() {
4
+ await hh.run('compile', {
5
+ sources: '/foo/bar'
6
+ });
7
+ process.exit();
8
+ }());
@@ -0,0 +1,25 @@
1
+ import { Config } from '@dequanto/Config';
2
+ import { HardhatProvider } from '@dequanto/hardhat/HardhatProvider';
3
+ import { Foo } from '@0xweb/hardhat/Foo/Foo';
4
+
5
+ (async function () {
6
+
7
+ await Config.fetch()
8
+
9
+ const provider = new HardhatProvider();
10
+ const foo = await provider.resolve<Foo>(Foo, 'Lorem');
11
+
12
+ '> Get initial value'
13
+ let name = await foo.getName();
14
+ console.log(`First:`, name);
15
+
16
+ '> Submit value'
17
+ let tx = await foo.setName(provider.deployer(), 'ResetLorem');
18
+ await tx.wait();
19
+
20
+ '> Get new value'
21
+ name = await foo.getName();
22
+ console.log(`Second:`, name);
23
+
24
+ process.exit();
25
+ }());
@@ -0,0 +1,19 @@
1
+ pragma solidity ^0.8.2;
2
+
3
+ contract Foo {
4
+ string public name;
5
+ event Updated (string newName);
6
+
7
+ constructor(string memory _name) {
8
+ name = _name;
9
+ }
10
+
11
+ function setName(string memory _name) public {
12
+ name = _name;
13
+ emit Updated(name);
14
+ }
15
+
16
+ function getName () public view returns (string memory) {
17
+ return name;
18
+ }
19
+ }
@@ -0,0 +1,67 @@
1
+ import { run } from 'shellbee'
2
+ import { File, Directory } from 'atma-io'
3
+ import alot from 'alot';
4
+
5
+ const PROJ = `./test/fixtures/integration/`;
6
+ const PROJ_ARTIFACTS = `${PROJ}/artifacts/`;
7
+ const PROJ_0xWEB = `${PROJ}/0xweb/`;
8
+ const PROJ_DEQUANTO = `${PROJ}/dequanto/`;
9
+ UTest({
10
+ $config: {
11
+ timeout: 1000 * 60 * 15
12
+ },
13
+ async $before () {
14
+ let clean = [
15
+ PROJ_ARTIFACTS,
16
+ PROJ_0xWEB,
17
+ PROJ_DEQUANTO,
18
+ `${PROJ}/node_modules/`,
19
+ `${PROJ}/package.json`,
20
+ `${PROJ}/hardhat.config.js`,
21
+ ];
22
+ await alot(clean).forEachAsync(async path => {
23
+ const Ctor = /\.\w+$/.test(path) ? File : Directory;
24
+ if (await Ctor.existsAsync(path)) {
25
+ await Ctor.removeAsync(path);
26
+ }
27
+ })
28
+ },
29
+ async $after () {
30
+ await Directory.removeAsync(`${PROJ}/.git/`);
31
+ await File.removeAsync(`${PROJ}/.gitmodules`);
32
+ },
33
+ async 'should initialize and compile the project' () {
34
+ let { stdout } = await run({
35
+ command: `0xweb -v`,
36
+ silent: true
37
+ });
38
+ let has0xWeb = /0xweb@\d+\.\d+\.\d+/.test(stdout.join('\n'));
39
+ if (has0xWeb === false) {
40
+ await run({
41
+ command: 'npm i 0xweb -g',
42
+ cwd: PROJ
43
+ });
44
+ }
45
+ await run({
46
+ command: '0xweb init --hardhat',
47
+ cwd: PROJ
48
+ });
49
+
50
+ await File.replaceAsync(`${PROJ}/hardhat.config.js`, '@0xweb/hardhat', '../../../lib/index');
51
+
52
+ await run({
53
+ command: 'node --openssl-legacy-provider compile.js',
54
+ cwd: PROJ
55
+ });
56
+
57
+ {
58
+ let { stdout } = await run({
59
+ command: 'npx atma --openssl-legacy-provider run example.ts',
60
+ cwd: PROJ
61
+ });
62
+
63
+ has_(stdout.join('\n'), /First: Lorem/g);
64
+ has_(stdout.join('\n'), /Second: ResetLorem/g);
65
+ }
66
+ }
67
+ })
package/tsconfig.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "exclude": ["node_modules"],
3
+ "compilerOptions": {
4
+ "outDir": "ts-temp",
5
+ "lib": ["es2020"],
6
+ "typeRoots": [
7
+ "node_modules/@types",
8
+ "typings",
9
+ "typings/globals",
10
+ "typings-other"
11
+ ],
12
+ "types": ["node", "assertion", "atma-utest"],
13
+ "declaration": true,
14
+ "target": "es2020",
15
+ "module": "commonjs",
16
+ "sourceMap": false,
17
+ "experimentalDecorators": true
18
+ }
19
+ }
@@ -0,0 +1,159 @@
1
+ // Generated by typings
2
+ // Source: https://raw.githubusercontent.com/atmajs/assertion/master/types/assertion.d.ts
3
+ declare module "assertion" {
4
+ export = assert;
5
+ }
6
+
7
+ declare var assert: assertion.IAssert
8
+
9
+ declare var eq_: assertion.equal
10
+ declare var notEq_: assertion.notEqual
11
+ declare var lt_: assertion.lessThan
12
+ declare var lte_: assertion.lessThanOrEqual
13
+ declare var gt_: assertion.greaterThan
14
+ declare var gte_: assertion.greaterThanOrEqual
15
+ declare var deepEq_: assertion.deepEqual
16
+ declare var notDeepEq_: assertion.notDeepEqual
17
+ declare var has_: assertion.has
18
+ declare var hasNot_: assertion.hasNot
19
+ declare var is_: assertion.is
20
+ declare var isNot_: assertion.isNot
21
+
22
+
23
+ declare namespace assertion {
24
+ interface IAssert {
25
+ (expression: boolean, message: string): void
26
+ equal: equal
27
+ notEqual: notEqual
28
+ strictEqual: strictEqual
29
+ notStrictEqual: notStrictEqual
30
+ throws: throws
31
+ notThrows: notThrows
32
+ ifError: ifError
33
+ lessThan: lessThan
34
+ lessThanOrEqual: lessThanOrEqual
35
+
36
+ greaterThan: greaterThan
37
+ greaterThanOrEqual: greaterThanOrEqual
38
+ deepEqual: deepEqual
39
+ notDeepEqual: notDeepEqual
40
+ has: has
41
+ hasNot: hasNot
42
+ is: is
43
+
44
+ on: on
45
+
46
+ /**
47
+ * string: Await Name for better logging
48
+ * number: expectation count
49
+ * object: binded content
50
+ * function: wrap any function
51
+ */
52
+ await (
53
+ arg1?: string | number | Function | object,
54
+ arg2?: string | number | Function | object,
55
+ arg3?: string | number | Function | object,
56
+ arg4?: string | number | Function | object,
57
+ ): Function
58
+
59
+
60
+ /**
61
+ * string: Await Name for better logging
62
+ * number: expectation count, default is `1`
63
+ * object: binded content
64
+ * function: wrap any function
65
+ */
66
+ avoid (
67
+ arg1?: string | number | Function | object,
68
+ arg2?: string | number | Function | object,
69
+ arg3?: string | number | Function | object,
70
+ arg4?: string | number | Function | object,
71
+ );
72
+ }
73
+ interface equal {
74
+ (a: any, b: any, message?: string)
75
+ }
76
+ interface notEqual {
77
+ (a: any, b: any, message?: string)
78
+ }
79
+ interface strictEqual {
80
+ (a: any, b: any, message?: string)
81
+ }
82
+ interface notStrictEqual {
83
+ (a: any, b: any, message?: string)
84
+ }
85
+ interface throws {
86
+ (a: Function, message?: string): Error
87
+ }
88
+ interface notThrows {
89
+ (a: Function, message?: string): Error
90
+ }
91
+ interface ifError {
92
+ (a: any, message?: string)
93
+ }
94
+ interface lessThan {
95
+ (a: any, b: any, message?: string)
96
+ }
97
+ interface lessThanOrEqual {
98
+ (a: any, b: any, message?: string)
99
+ }
100
+ interface greaterThan {
101
+ (a: any, b: any, message?: string)
102
+ }
103
+ interface greaterThanOrEqual {
104
+ (a: any, b: any, message?: string)
105
+ }
106
+ interface deepEqual {
107
+ (a: any, b: any, message?: string)
108
+ }
109
+ interface notDeepEqual {
110
+ (a: any, b: any, message?: string)
111
+ }
112
+ interface has {
113
+ (a: any, b: any, message?: string)
114
+ }
115
+ interface is {
116
+ (a: any, b:
117
+ 'String' |
118
+ 'Number' |
119
+ 'Null' |
120
+ 'Undefined' |
121
+ 'Function' |
122
+ 'RegExp' |
123
+ 'Date' |
124
+ 'Object' |
125
+ 'CustomEvent' |
126
+ null |
127
+ any, message?: string)
128
+ }
129
+ interface isNot {
130
+ (a: any, b:
131
+ 'String' |
132
+ 'Number' |
133
+ 'Null' |
134
+ 'Undefined' |
135
+ 'Function' |
136
+ 'RegExp' |
137
+ 'Date' |
138
+ 'Object' |
139
+ 'CustomEvent' |
140
+ null |
141
+ any, message?: string)
142
+ }
143
+ interface hasNot {
144
+ (a: any, b: any, message?: string)
145
+ }
146
+
147
+
148
+ /** Notice: when `fail` callback is defined the assertion doesn`t throw any error */
149
+ interface on {
150
+ (event: 'start' | 'fail' | 'success', callback: (error?: AssertionError) => void)
151
+ }
152
+
153
+
154
+ interface AssertionError extends Error {
155
+ actual: any
156
+ expected: any
157
+ operator: string
158
+ }
159
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "resolution": "main",
3
+ "tree": {
4
+ "src": "https://raw.githubusercontent.com/atmajs/assertion/master/typings.json",
5
+ "raw": "github:atmajs/assertion/typings.json",
6
+ "main": "types/assertion.d.ts",
7
+ "global": true,
8
+ "name": "assertion"
9
+ }
10
+ }
@@ -0,0 +1,53 @@
1
+ // Generated by typings
2
+ // Source: https://raw.githubusercontent.com/atmajs/utest/master/types/index.d.ts
3
+ declare module "atma-utest" {
4
+ export = UTest;
5
+ }
6
+
7
+ declare var UTest: IUtest;
8
+
9
+ declare interface IUtest {
10
+ (definition: IUTestDefinition): void
11
+
12
+ domtest: IDomTest
13
+ request (url, method, headers, data, callback)
14
+ server: {
15
+ render (template: string, ...args)
16
+ }
17
+
18
+ benchmark (model: IUTestDefinition)
19
+ benchmarkVersions (model: IUTestDefinition)
20
+
21
+ }
22
+
23
+ interface IDomTest {
24
+ (subject: HTMLElement | JQuery | any, testMarkup: string | any): PromiseLike<any>
25
+ use (astName: string): IDomTest
26
+ process (subject: HTMLElement | JQuery | any, testMarkup: string | any): PromiseLike<any>
27
+ }
28
+
29
+ interface IUTestDefinition {
30
+ $config?: {
31
+ timeout?: number
32
+ errorableCallbacks?: boolean
33
+ breakOnError?: boolean
34
+
35
+ 'http.config'?: any
36
+ 'http.eval'?: string
37
+ 'http.include'?: any
38
+ 'http.service'?: any
39
+ 'http.process'?: any
40
+ 'util.process'?: any
41
+ }
42
+ $before?: (done?: Function) => void | PromiseLike<any>
43
+ $after?: (done?: Function) => void | PromiseLike<any>
44
+ $teardown?: (done?: Function) => void | PromiseLike<any>
45
+
46
+
47
+
48
+ [key: string]: ITestCase | IUTestDefinition | any
49
+ }
50
+
51
+ interface ITestCase {
52
+ (done?: Function, ...args: any[]): void | PromiseLike<any> | any
53
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "resolution": "main",
3
+ "tree": {
4
+ "src": "https://raw.githubusercontent.com/atmajs/utest/master/typings.json",
5
+ "raw": "github:atmajs/utest/typings.json",
6
+ "main": "types/index.d.ts",
7
+ "global": true,
8
+ "name": "atma-utest"
9
+ }
10
+ }
@@ -0,0 +1,2 @@
1
+ /// <reference path="globals/assertion/index.d.ts" />
2
+ /// <reference path="globals/atma-utest/index.d.ts" />
package/index.ts DELETED
@@ -1,49 +0,0 @@
1
- import hre from "hardhat";
2
- import memd from 'memd';
3
- import type Ethers from 'ethers'
4
- import { ContractBase } from '@dequanto/contracts/ContractBase';
5
- import { type Constructor } from 'atma-utils/mixin';
6
- import { ChainAccount } from '@dequanto/ChainAccounts';
7
- import { HardhatWeb3Client } from '@dequanto/clients/HardhatWeb3Client';
8
-
9
- export class HardhatWeb {
10
-
11
- @memd.deco.memoize()
12
- static deployer(index: number = 0): ChainAccount {
13
- const ethers: typeof Ethers = (hre as any).ethers;
14
- const accounts: any = hre.config.networks.hardhat.accounts;
15
- const wallet = ethers.Wallet.fromMnemonic(accounts.mnemonic, accounts.path + `/${index}`);
16
- return {
17
- key: wallet.privateKey,
18
- address: wallet.address,
19
- };
20
- }
21
-
22
- @memd.deco.memoize()
23
- static async resolve<T extends ContractBase>(Ctor: Constructor<T>): Promise<T> {
24
-
25
- await ContractProvider.compile();
26
-
27
- const ethers = (hre as any).ethers;
28
-
29
- const Factory: Ethers.ContractFactory = await ethers.getContractFactory(Ctor.name);
30
- const contract = await Factory.deploy();
31
- const receipt = await contract.deployed();
32
-
33
- console.log(`Contract ${Ctor.name} deployed to ${contract.address}`);
34
-
35
- const client = ContractProvider.client();
36
- return new Ctor(contract.address, client);
37
- }
38
-
39
- static client() {
40
- const web3 = (hre as any).web3;
41
- const client = new HardhatWeb3Client({ web3, chainId: 1337 });
42
- return client;
43
- }
44
-
45
- @memd.deco.memoize()
46
- private static async compile () {
47
- await hre.run('compile');
48
- }
49
- }