Skip to content

Commit

Permalink
Merge pull request #497 from polywrap/prealpha-dev
Browse files Browse the repository at this point in the history
prep 0.0.1-prealpha.46
  • Loading branch information
dOrgJelli authored Oct 8, 2021
2 parents b8a2364 + a50ca20 commit 30b590d
Show file tree
Hide file tree
Showing 16 changed files with 297 additions and 11 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Web3API 0.0.1-prealpha.46
## Bugs
* `@web3api/core-js`: Properly check for "undefined" values in query arguments.
* `@web3api/wasm-as`: Improved MsgPack deserialization of integers (signed & unsigned).

# Web3API 0.0.1-prealpha.45
## Features
* `@web3api/tracing-js`: Support service name configuration.
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.1-prealpha.45
0.0.1-prealpha.46
6 changes: 3 additions & 3 deletions packages/js/client/src/wasm/WasmWeb3Api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ export class WasmWeb3Api extends Api {

const abort = (message: string) => {
throw new Error(
`WasmWeb3Api: Thread aborted execution.\nURI: ${this._uri.uri}\n` +
`Module: ${module}\nMethod: ${method}\n` +
`WasmWeb3Api: Wasm module aborted execution.\nURI: ${this._uri.uri}\n` +
`Module: ${invokableModule}\nMethod: ${method}\n` +
`Input: ${JSON.stringify(input, null, 2)}\nMessage: ${message}.\n`
);
};
Expand Down Expand Up @@ -127,7 +127,7 @@ export class WasmWeb3Api extends Api {
case "InvokeError": {
throw Error(
`WasmWeb3Api: invocation exception encountered.\n` +
`uri: ${this._uri.uri}\nmodule: ${module}\n` +
`uri: ${this._uri.uri}\nmodule: ${invokableModule}\n` +
`method: ${method}\n` +
`input: ${JSON.stringify(input, null, 2)}\n` +
`exception: ${invokeResult.invokeError}`
Expand Down
16 changes: 16 additions & 0 deletions packages/js/core/src/__tests__/parse-query.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,22 @@ describe("parseQuery", () => {
).toThrowError(/Missing variable/);
});

it("succeeds when variables is defined by falsy", () => {
const doc = createQueryDocument(`
mutation {
someMethod(
arg1: $arg_1
)
}
`);

expect(() =>
parseQuery(dummy, doc, {
arg_1: 0,
})
).not.toThrowError(/Missing variable/);
});

it("fails when duplicate input arguments are provided", () => {
const doc = createQueryDocument(`
mutation {
Expand Down
2 changes: 1 addition & 1 deletion packages/js/core/src/algorithms/filter-results.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const filterResults = Tracer.traceFunc(
const res: any = result;

for (const key of Object.keys(filter)) {
if (res[key]) {
if (res[key] !== undefined) {
if (typeof filter[key] === "boolean") {
filtered[key] = res[key];
} else {
Expand Down
2 changes: 1 addition & 1 deletion packages/js/core/src/algorithms/parse-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ const extractValue = Tracer.traceFunc(
);
}

if (!variables[node.name.value]) {
if (variables[node.name.value] === undefined) {
throw Error(`Missing variable: ${node.name.value}`);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/js/plugins/ethereum/src/__tests__/e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {

import { ethers } from "ethers";
import { keccak256 } from "js-sha3";
import axios from "axios"
import axios from "axios";

const { hash: namehash } = require("eth-ens-namehash");
const contracts = {
Expand Down
3 changes: 3 additions & 0 deletions packages/js/plugins/http/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
"devDependencies": {
"@types/jest": "26.0.8",
"@web3api/client-js": "0.0.1-prealpha.45",
"@web3api/ens-plugin-js": "0.0.1-prealpha.45",
"@web3api/ipfs-plugin-js": "0.0.1-prealpha.45",
"@web3api/test-env-js": "0.0.1-prealpha.45",
"jest": "26.6.3",
"nock": "13.0.7",
"rimraf": "3.0.2",
Expand Down
133 changes: 130 additions & 3 deletions packages/js/plugins/http/src/__tests__/e2e/e2e.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
import { Web3ApiClient } from "@web3api/client-js"
import { httpPlugin } from "../..";
import { Response } from "../../w3";
import nock from "nock"

import { Web3ApiClient } from "@web3api/client-js"
import { ensPlugin } from "@web3api/ens-plugin-js";
import { ipfsPlugin } from "@web3api/ipfs-plugin-js";
import { ethereumPlugin } from "@web3api/ethereum-plugin-js";
import {
initTestEnvironment,
stopTestEnvironment,
buildAndDeployApi
} from "@web3api/test-env-js";
import axios from "axios";
import nock from "nock";

jest.setTimeout(360000)

const defaultReplyHeaders = {
'access-control-allow-origin': '*',
Expand Down Expand Up @@ -261,6 +273,121 @@ describe("e2e tests for HttpPlugin", () => {
expect(response.errors).toBeDefined()
});

})
});

describe("integration", () => {

let client: Web3ApiClient;
let uri: string;
let ensAddress: string;

beforeAll(async () => {
const { ethereum, ipfs } = await initTestEnvironment();
const { data } = await axios.get("http://localhost:4040/deploy-ens");

ensAddress = data.ensAddress

client = new Web3ApiClient({
plugins: [
{
uri: "w3://ens/http.web3api.eth",
plugin: httpPlugin(),
},
{
uri: "w3://ens/ethereum.web3api.eth",
plugin: ethereumPlugin({
networks: {
testnet: {
provider: ethereum
}
},
defaultNetwork: "testnet"
}),
},
{
uri: "w3://ens/ipfs.web3api.eth",
plugin: ipfsPlugin({
provider: ipfs,
fallbackProviders: ["https://ipfs.io"]
})
},
{
uri: "w3://ens/ens.web3api.eth",
plugin: ensPlugin({
addresses: {
testnet: ensAddress
}
})
}
],
});

const api = await buildAndDeployApi(
`${__dirname}/integration`,
ipfs,
ensAddress
);

uri = `ens/testnet/${api.ensDomain}`;
});

afterAll(async () => {
await stopTestEnvironment();
});

it("get", async () => {
nock("http://www.example.com", { reqheaders: { 'X-Request-Header': "req-foo" } })
.defaultReplyHeaders(defaultReplyHeaders)
.get("/api")
.query({ query: "foo" })
.reply(200, '{data: "test-response"}', { 'X-Response-Header': "resp-foo" })

const response = await client.query<{ get: Response }>({
uri,
query: `query {
get(
url: "http://www.example.com/api"
request: {
responseType: TEXT
urlParams: [{key: "query", value: "foo"}]
headers: [{key: "X-Request-Header", value: "req-foo"}]
}
)
}`
});

expect(response.data).toBeDefined()
expect(response.errors).toBeUndefined()
expect(response.data?.get.status).toBe(200)
});

it("post", async () => {
nock("http://www.example.com", { reqheaders: { 'X-Request-Header': "req-foo" } })
.defaultReplyHeaders(defaultReplyHeaders)
.post("/api", "{data: 'test-request'}")
.query({ query: "foo" })
.reply(200, '{data: "test-response"}', { 'X-Response-Header': "resp-foo" })

const response = await client.query<{ post: Response }>({
uri,
query: `query {
post(
url: "http://www.example.com/api"
request: {
responseType: TEXT
body: "{data: 'test-request'}"
urlParams: [{key: "query", value: "foo"}]
headers: [{key: "X-Request-Header", value: "req-foo"}]
}
)
}`
});

expect(response.data).toBeTruthy();
expect(response.errors).toBeFalsy();

expect(response.data?.post.status).toBe(200);
expect(response.data?.post.body).toBeTruthy();
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
build
node_modules
w3
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "http-js-plugin-integration-test",
"description": "HTTP JS Plugin Integration Test",
"private": true,
"version": "0.0.1-prealpha.45",
"scripts": {
"build": "yarn build:web3api",
"build:web3api": "npx w3 build",
"test:env:up": "npx w3 test-env up",
"test:env:down": "npx w3 test-env down",
"deploy": "yarn deploy:web3api",
"deploy:web3api": "npx w3 build --ipfs http://localhost:5001 --test-ens simplestorage.eth"
},
"dependencies": {
"@web3api/wasm-as": "0.0.1-prealpha.45"
},
"devDependencies": {
"@web3api/cli": "0.0.1-prealpha.45"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import {
HTTP_Query,
HTTP_Response,
Input_get,
Input_post,
} from "./w3";

export function get(input: Input_get): HTTP_Response | null {
return HTTP_Query.get({
url: input.url,
request: input.request
});
}

export function post(input: Input_post): HTTP_Response | null {
return HTTP_Query.post({
url: input.url,
request: input.request
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#import { Query, Request, Response } into HTTP from "w3://ens/http.web3api.eth"

type Query {
get(
url: String!
request: HTTP_Request
): HTTP_Response

post(
url: String!
request: HTTP_Request
): HTTP_Response
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
format: 0.0.1-prealpha.2
config:
node_version: "14.16.0"
linked_packages:
- name: "@web3api/wasm-as"
path: ../../../../../../../wasm/as
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
format: 0.0.1-prealpha.5
build: ./web3api.build.yaml
language: wasm/assemblyscript
modules:
query:
schema: ./src/query/schema.graphql
module: ./src/query/index.ts
Loading

0 comments on commit 30b590d

Please sign in to comment.