Skip to content

Commit b72f12a

Browse files
authored
Merge pull request #222 from Web3-API/prealpha-dev
Prep v0.0.1-prealpha.6
2 parents ab2a18b + 0c5292b commit b72f12a

132 files changed

Lines changed: 2187 additions & 243 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGELOG.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,29 @@
1-
TODO
1+
# Web3API 0.0.1-prealpha.6
2+
## Features
3+
* Web3API React Integration: `@web3api/react`
4+
* Add the `Web3ApiProvider` HOC to the root of your application.
5+
* Use the `useWeb3ApiQuery` hook to execute queries.
6+
* Web3API CLI e2e tests.
7+
* `@web3api/test-env-js` package for common testing logic.
8+
* `@web3api/test-cases` for common test cases.
9+
10+
## Bug Fixes
11+
* Remove unused `workerize-loader` package & logic.
12+
13+
# Web3API 0.0.1-prealpha.5
14+
## Features
15+
* `w3 build --watch` support, enabling the automatic rebuilding of Web3APIs whenever project files have changed.
16+
17+
# Web3API 0.0.1-prealpha.4
18+
## Features
19+
* Enum Support
20+
21+
## Bug Fixes
22+
* `w3 create ...` CLI Fix (closes: [#167](https://github.com/Web3-API/monorepo/issues/167))
23+
24+
# Web3API 0.0.1-prealpha.2
25+
## Bug Fixes
26+
* Fix typescript plugin template's package.json
27+
28+
# Web3API 0.0.1-prealpha.1
29+
Pre-Alpha Initial Release

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.0.1-prealpha.5
1+
0.0.1-prealpha.6

demos/simple-storage/dapp/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,6 @@
2121
npm-debug.log*
2222
yarn-debug.log*
2323
yarn-error.log*
24+
25+
# Web3API Worker Thread
26+
thread.js

demos/simple-storage/dapp/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
"@testing-library/react": "^9.3.2",
2020
"@testing-library/user-event": "^7.1.2",
2121
"@types/node": "^12.0.0",
22-
"@types/react": "^16.9.0",
23-
"@types/react-dom": "^16.9.0",
2422
"@types/react-lottie": "1.2.5",
2523
"eslint": "^6.6.0",
2624
"typescript": "3.7.2"
@@ -35,6 +33,10 @@
3533
"prestart": "yarn install:web3api",
3634
"install:web3api": "npx web3api-worker-install ./public"
3735
},
36+
"resolutions": {
37+
"@types/react": "^16.9.0",
38+
"@types/react-dom": "^16.9.0"
39+
},
3840
"eslintConfig": {
3941
"root": true,
4042
"extends": "react-app"

demos/simple-storage/protocol/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
},
1111
"scripts": {
1212
"build": "npx w3 build",
13+
"contracts:deploy": "node ./deploy-contracts.js",
1314
"test:env:up": "npx w3 test-env up && yarn contracts:deploy",
1415
"test:env:down": "npx w3 test-env down"
1516
},

package.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,18 @@
2121
"scripts": {
2222
"reset": "yarn clean && yarn && yarn build",
2323
"clean": "rimraf ./**/node_modules ./**/build ./**/coverage",
24-
"build": "lerna run build --no-private --ignore @web3api/cli && yarn build:cli",
25-
"build:cli": "lerna run build --scope @web3api/cli",
24+
"build": "lerna run build --no-private --ignore @web3api/cli && lerna run build --scope @web3api/cli",
2625
"lint": "lerna run lint",
2726
"lint:fix": "lerna run lint -- --fix",
2827
"lint:ci": "lerna run lint --parallel",
29-
"test": "lerna run test --no-private",
30-
"test:ci": "lerna run test:ci --no-private --parallel",
28+
"test": "lerna run test --no-private --ignore @web3api/client-js && lerna run test --scope @web3api/client-js",
29+
"test:ci": "lerna run test:ci --no-private --ignore @web3api/client-js && lerna run test:ci --scope @web3api/client-js",
3130
"version:apply": "npx lerna version $(cat VERSION) --exact --no-git-tag-version --yes",
3231
"postversion:apply": "git add . && git commit -m \"build(release): migrate to `cat ./VERSION`\"",
3332
"publish:npm": "lerna publish from-package --no-private --yes --registry https://registry.npmjs.org/ --no-verify-access"
3433
},
3534
"devDependencies": {
36-
"lerna": "3.22.1",
35+
"lerna": "3.22.1",
3736
"rimraf": "3.0.2",
3837
"@typescript-eslint/eslint-plugin": "4.11.1",
3938
"@typescript-eslint/parser": "4.11.1",

packages/cli/jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module.exports = {
22
collectCoverage: true,
33
preset: "ts-jest",
44
testEnvironment: "node",
5-
testMatch: ["**/__tests__/?(*.)+(spec|test).[jt]s?(x)"],
5+
testMatch: ["**/__tests__/**/?(*.)+(spec|test).[jt]s?(x)"],
66
globals: {
77
"ts-jest": {
88
diagnostics: false,

packages/cli/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"devDependencies": {
4949
"@types/jest": "26.0.8",
5050
"@types/node": "12.6.9",
51+
"@web3api/test-env-js": "0.0.1-prealpha.5",
5152
"jest": "26.2.2",
5253
"rimraf": "3.0.2",
5354
"ts-jest": "26.1.4",
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
import path from "path";
2+
import { clearStyle } from "./utils";
3+
4+
import { runCLI } from "@web3api/test-env-js";
5+
6+
const HELP = `
7+
w3 build [options] [<web3api-manifest>]
8+
9+
Options:
10+
-h, --help Show usage information
11+
-i, --ipfs [<node>] Upload build results to an IPFS node (default: dev-server's node)
12+
-o, --output-dir <path> Output directory for build results (default: build/)
13+
-e, --test-ens <[address,]domain> Publish the package to a test ENS domain locally (requires --ipfs)
14+
-w, --watch Automatically rebuild when changes are made (default: false)
15+
16+
`;
17+
18+
describe("e2e tests for build command", () => {
19+
const projectRoot = path.resolve(__dirname, "../project/");
20+
21+
test("Should show help text", async () => {
22+
const { exitCode: code, stdout: output, stderr: error } = await runCLI({
23+
args: ["build", "--help"],
24+
cwd: projectRoot
25+
}, "../../../bin/w3");
26+
27+
expect(code).toEqual(0);
28+
expect(error).toBe("");
29+
expect(clearStyle(output)).toEqual(HELP);
30+
});
31+
32+
test("Should throw error for invalid params - outputDir", async () => {
33+
const { exitCode: code, stdout: output, stderr: error } = await runCLI({
34+
args: ["build", "--output-dir"],
35+
cwd: projectRoot
36+
}, "../../../bin/w3");
37+
38+
expect(code).toEqual(0);
39+
expect(error).toBe("");
40+
expect(clearStyle(output))
41+
.toEqual(`--output-dir option missing <path> argument
42+
${HELP}`);
43+
});
44+
45+
test("Should throw error for invalid params - testEns", async () => {
46+
const { exitCode: code, stdout: output, stderr: error } = await runCLI({
47+
args: ["build", "--test-ens"],
48+
cwd: projectRoot
49+
}, "../../../bin/w3");
50+
51+
expect(code).toEqual(0);
52+
expect(error).toBe("");
53+
expect(clearStyle(output))
54+
.toEqual(`--test-ens option missing <[address,]domain> argument
55+
${HELP}`);
56+
});
57+
58+
test("Should throw error for invalid params - ipfs", async () => {
59+
const { exitCode: code, stdout: output, stderr: error } = await runCLI({
60+
args: ["build", "--test-ens", "test.eth"],
61+
cwd: projectRoot
62+
}, "../../../bin/w3");
63+
64+
expect(code).toEqual(0);
65+
expect(error).toBe("");
66+
expect(clearStyle(output))
67+
.toEqual(`--test-ens option requires the --ipfs [<node>] option
68+
${HELP}`);
69+
});
70+
71+
test("Should throw error for invalid web3api - invalid route", async () => {
72+
const { exitCode: code, stdout: output, stderr: error } = await runCLI({
73+
args: ["build", "invalid-web3api-1.yaml"],
74+
cwd: projectRoot
75+
}, "../../../bin/w3");
76+
77+
expect(code).toEqual(1);
78+
expect(error).toBe("");
79+
expect(clearStyle(output)).toContain(`- Compile Web3API
80+
- Load web3api from invalid-web3api-1.yaml
81+
✔ Load web3api from invalid-web3api-1.yaml
82+
✖ Failed to compile Web3API: ENOENT: no such file or directory, open '${projectRoot}/src/wrong/schema.graphql'
83+
`);
84+
});
85+
86+
test("Should throw error for invalid web3api - invalid field", async () => {
87+
const { exitCode: code, stdout: output, stderr: error } = await runCLI({
88+
args: ["build", "invalid-web3api-2.yaml"],
89+
cwd: projectRoot
90+
}, "../../../bin/w3");
91+
92+
expect(code).toEqual(1);
93+
expect(error).toBe("");
94+
expect(clearStyle(output)).toContain(`- Compile Web3API
95+
- Load web3api from invalid-web3api-2.yaml
96+
✖ Failed to load web3api from invalid-web3api-2.yaml: Field wrong_mutation is not accepted in the schema. Please check the accepted fields here:`);
97+
});
98+
99+
test("Successfully build the project", async () => {
100+
const { exitCode: code, stdout: output, stderr: error } = await runCLI({
101+
args: ["build"],
102+
cwd: projectRoot
103+
}, "../../../bin/w3");
104+
105+
expect(code).toEqual(0);
106+
expect(error).toBe("");
107+
expect(clearStyle(output)).toEqual(`- Compile Web3API
108+
- Load web3api from web3api.yaml
109+
✔ Load web3api from web3api.yaml
110+
Compiling WASM module: ./src/mutation/index.ts => ${projectRoot}/build/mutation.wasm
111+
- Compile Web3API
112+
Compiling WASM module: ./src/query/index.ts => ${projectRoot}/build/query.wasm
113+
- Compile Web3API
114+
- Output web3api to build/web3api.yaml
115+
✔ Output web3api to build/web3api.yaml
116+
✔ Compile Web3API
117+
`);
118+
});
119+
});
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
import path from "path";
2+
import { defaultGenerationFile, defaultManifest } from "../../commands/codegen";
3+
import { clearStyle } from "./utils";
4+
5+
import { runCLI } from "@web3api/test-env-js";
6+
7+
const HELP = `
8+
w3 codegen [<generation-file>] [options]
9+
10+
Generation file:
11+
Path to the generation file (default: ${defaultGenerationFile})
12+
13+
Options:
14+
-h, --help Show usage information
15+
-m, --manifest-path <path> Path to the Web3API manifest file (default: ${defaultManifest.join(
16+
" | "
17+
)})
18+
-i, --ipfs [<node>] IPFS node to load external schemas (default: dev-server's node)
19+
-o, --output-dir <path> Output directory for generated types (default: types/)
20+
-e, --ens [<address>] ENS address to lookup external schemas (default: 0x0000...2e1e)
21+
22+
`;
23+
24+
describe("e2e tests for codegen command", () => {
25+
const projectRoot = path.resolve(__dirname, "../project/");
26+
27+
test("Should show help text", async () => {
28+
const { exitCode: code, stdout: output, stderr: error } = await runCLI({
29+
args: ["codegen", "--help"],
30+
cwd: projectRoot
31+
}, "../../../bin/w3");
32+
33+
expect(code).toEqual(0);
34+
expect(error).toBe("");
35+
expect(clearStyle(output)).toEqual(HELP);
36+
});
37+
38+
test("Should throw error for invalid params - outputDir", async () => {
39+
const { exitCode: code, stdout: output, stderr: error } = await runCLI({
40+
args: ["codegen", "--output-dir"],
41+
cwd: projectRoot
42+
}, "../../../bin/w3");
43+
44+
expect(code).toEqual(0);
45+
expect(error).toBe("");
46+
expect(clearStyle(output))
47+
.toEqual(`--output-dir option missing <path> argument
48+
${HELP}`);
49+
});
50+
51+
test("Should throw error for invalid params - ens", async () => {
52+
const { exitCode: code, stdout: output, stderr: error } = await runCLI({
53+
args: ["codegen", "--ens"],
54+
cwd: projectRoot
55+
}, "../../../bin/w3");
56+
57+
expect(code).toEqual(0);
58+
expect(error).toBe("");
59+
expect(clearStyle(output))
60+
.toEqual(`--ens option missing <[address,]domain> argument
61+
${HELP}`);
62+
});
63+
64+
test("Should throw error for invalid generation file - wrong file", async () => {
65+
const { exitCode: code, stdout: output, stderr: error } = await runCLI({
66+
args: ["codegen", `web3api-invalid.gen.js`],
67+
cwd: projectRoot
68+
}, "../../../bin/w3");
69+
70+
expect(code).toEqual(1);
71+
expect(error).toBe("");
72+
expect(clearStyle(output)).toContain(`- Generate types
73+
- Load web3api from web3api.yaml
74+
✔ Load web3api from web3api.yaml
75+
✖ Failed to generate types: Cannot find module '${projectRoot}/web3api-invalid.gen.js'`);
76+
});
77+
78+
test("Should throw error for invalid generation file - no run() method", async () => {
79+
const { exitCode: code, stdout: output, stderr: error } = await runCLI({
80+
args: ["codegen", `web3api-norun.gen.js`],
81+
cwd: projectRoot
82+
}, "../../../bin/w3");
83+
84+
expect(code).toEqual(1);
85+
expect(error).toBe("");
86+
expect(clearStyle(output)).toContain(`- Generate types
87+
- Load web3api from web3api.yaml
88+
✔ Load web3api from web3api.yaml
89+
✖ Failed to generate types: The generation file provided doesn't have the 'run' method.`);
90+
});
91+
92+
test("Should successfully generate types", async () => {
93+
const rimraf = require("rimraf");
94+
rimraf.sync(`${projectRoot}/types`);
95+
96+
const { exitCode: code, stdout: output, stderr: error } = await runCLI({
97+
args: ["codegen"],
98+
cwd: projectRoot
99+
}, "../../../bin/w3");
100+
101+
expect(code).toEqual(0);
102+
expect(error).toBe("");
103+
expect(clearStyle(output)).toEqual(`- Generate types
104+
- Load web3api from web3api.yaml
105+
✔ Load web3api from web3api.yaml
106+
Generating types from ./templates/schema.mustache
107+
- Generate types
108+
Generating types from ./templates/schema.mustache
109+
- Generate types
110+
Generating types from ./templates/schema.mustache
111+
- Generate types
112+
✔ Generate types
113+
🔥 Types were generated successfully 🔥
114+
`);
115+
116+
rimraf.sync(`${projectRoot}/types`);
117+
});
118+
});

0 commit comments

Comments
 (0)