Skip to content

Commit 145afa8

Browse files
committed
feat: add tests for interface-invoke
1 parent 18c410e commit 145afa8

File tree

18 files changed

+250
-1
lines changed

18 files changed

+250
-1
lines changed

packages/js/client/src/__tests__/Web3ApiClient.spec.ts

+89-1
Original file line numberDiff line numberDiff line change
@@ -2137,7 +2137,7 @@ enum Logger_LogLevel @imported(
21372137
const client = await getClient({
21382138
interfaces: [
21392139
{
2140-
interface: "w3://ens/interface.eth",
2140+
interface: interfaceUri,
21412141
implementations: [implementationUri],
21422142
}
21432143
],
@@ -2164,5 +2164,93 @@ enum Logger_LogLevel @imported(
21642164
expect((query.data as any).queryImplementations).toEqual([implementationUri]);
21652165
});
21662166

2167+
it("e2e Interface invoke method ", async () => {
2168+
const interfaceUri = "w3://ens/interface.eth"
2169+
2170+
const implementationApi = await buildAndDeployApi(
2171+
`${GetPathToTestApis()}/interface-invoke/test-implementation`,
2172+
ipfsProvider,
2173+
ensAddress
2174+
);
2175+
const implementationUri = `w3://ens/testnet/${implementationApi.ensDomain}`;
2176+
2177+
const client = await getClient({
2178+
interfaces: [
2179+
{
2180+
interface: interfaceUri,
2181+
implementations: [implementationUri],
2182+
}
2183+
],
2184+
});
2185+
2186+
const api = await buildAndDeployApi(
2187+
`${GetPathToTestApis()}/interface-invoke/test-api`,
2188+
ipfsProvider,
2189+
ensAddress
2190+
);
2191+
const apiUri = `w3://ens/testnet/${api.ensDomain}`;
2192+
2193+
const query = await client.query<{
2194+
queryMethod: string;
2195+
abstractQueryMethod: string;
2196+
}>({
2197+
uri: apiUri,
2198+
query: `
2199+
query {
2200+
queryMethod(
2201+
arg: $argument1
2202+
)
2203+
abstractQueryMethod(
2204+
arg: $argument2
2205+
)
2206+
}
2207+
`,
2208+
variables: {
2209+
argument1: {
2210+
uint8: 1,
2211+
str: "Test String 1",
2212+
},
2213+
argument2: {
2214+
str: "Test String 2",
2215+
},
2216+
},
2217+
});
2218+
2219+
expect(query.errors).toBeFalsy();
2220+
expect(query.data).toBeTruthy();
2221+
expect(query.data?.queryMethod).toEqual({
2222+
uint8: 1,
2223+
str: "Test String 1",
2224+
});
2225+
2226+
expect(query.data?.abstractQueryMethod).toBe("Test String 2");
2227+
2228+
const mutation = await client.query<{
2229+
mutationMethod: string;
2230+
abstractMutationMethod: string;
2231+
}>({
2232+
uri: implementationUri,
2233+
query: `
2234+
mutation {
2235+
mutationMethod(
2236+
arg: $argument1
2237+
)
2238+
abstractMutationMethod(
2239+
arg: $argument2
2240+
)
2241+
}
2242+
`,
2243+
variables: {
2244+
argument1: 1,
2245+
argument2: 2,
2246+
},
2247+
});
2248+
2249+
expect(mutation.errors).toBeFalsy();
2250+
expect(mutation.data).toBeTruthy();
2251+
expect(mutation.data?.mutationMethod).toBe(1);
2252+
expect(mutation.data?.abstractMutationMethod).toBe(2);
2253+
});
2254+
21672255
});
21682256

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { Input_mutationMethod, Input_abstractMutationMethod, Interface, Interface_Mutation_Factory } from "./w3";
2+
3+
export function mutationMethod(input: Input_mutationMethod): u8 {
4+
const uris = Interface.getImplementations();
5+
const impl = new Interface_Mutation_Factory(uris[0])
6+
return impl.mutationMethod(input.arg);
7+
}
8+
9+
export function abstractMutationMethod(input: Input_abstractMutationMethod): u8 {
10+
const uris = Interface.getImplementations();
11+
const impl = new Interface_Mutation_Factory(uris[0])
12+
return impl.abstractMutationMethod(input.arg);
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#import { Mutation } into Interface from "w3://ens/interface.eth"
2+
#use { getImplementations } for Interface
3+
4+
type Mutation implements Interface_Mutation {
5+
mutationMethod(
6+
arg: UInt8!
7+
): UInt8!
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "test-case-interface-invoke",
3+
"private": true,
4+
"dependencies": {
5+
"@web3api/wasm-as": "0.0.1-prealpha.40",
6+
"assemblyscript": "0.19.1"
7+
}
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { Input_queryMethod, Input_abstractQueryMethod, ImplementationType, Interface_Query_Factory, Interface } from "./w3";
2+
3+
export function queryMethod(input: Input_queryMethod): ImplementationType {
4+
const uris = Interface.getImplementations();
5+
const impl = new Interface_Query_Factory(uris[0])
6+
return impl.queryMethod(input.arg);
7+
}
8+
9+
export function abstractQueryMethod(input: Input_abstractQueryMethod): String {
10+
const uris = Interface.getImplementations();
11+
const impl = new Interface_Query_Factory(uris[0])
12+
return impl.abstractQueryMethod(input.arg);
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#import { Query, InterfaceType } into Interface from "w3://ens/interface.eth"
2+
#use { getImplementations } for Interface
3+
4+
type Query implements Interface_Query {
5+
queryMethod(
6+
arg: ImplementationType!
7+
): ImplementationType!
8+
}
9+
10+
type ImplementationType implements Interface_InterfaceType {
11+
str: String!
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
format: 0.0.1-prealpha.2
2+
config:
3+
node_version: "14.16.0"
4+
linked_packages:
5+
- name: "@web3api/wasm-as"
6+
path: ../../../../../wasm/as
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
format: 0.0.1-prealpha.5
2+
build: ./web3api.build.yaml
3+
language: wasm/assemblyscript
4+
modules:
5+
query:
6+
schema: ./query/schema.graphql
7+
module: ./query/index.ts
8+
mutation:
9+
schema: ./mutation/schema.graphql
10+
module: ./mutation/index.ts
11+
import_redirects:
12+
- uri: w3://ens/interface.eth
13+
schema: ../test-interface/build/schema.graphql
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { Input_mutationMethod, Input_abstractMutationMethod } from "./w3";
2+
3+
export function mutationMethod(input: Input_mutationMethod): u8 {
4+
return input.arg;
5+
}
6+
7+
export function abstractMutationMethod(input: Input_abstractMutationMethod): u8 {
8+
return input.arg;
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#import { Mutation } into Interface from "w3://ens/interface.eth"
2+
3+
type Mutation implements Interface_Mutation {
4+
mutationMethod(
5+
arg: UInt8!
6+
): UInt8!
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "test-case-interface-invoke",
3+
"private": true,
4+
"dependencies": {
5+
"@web3api/wasm-as": "0.0.1-prealpha.40",
6+
"assemblyscript": "0.19.1"
7+
}
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { Input_queryMethod, Input_abstractQueryMethod, ImplementationType } from "./w3";
2+
3+
export function queryMethod(input: Input_queryMethod): ImplementationType {
4+
return input.arg;
5+
}
6+
7+
export function abstractQueryMethod(input: Input_abstractQueryMethod): String {
8+
return input.arg.str;
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#import { Query, InterfaceType } into Interface from "w3://ens/interface.eth"
2+
3+
type Query implements Interface_Query {
4+
queryMethod(
5+
arg: ImplementationType!
6+
): ImplementationType!
7+
}
8+
9+
type ImplementationType implements Interface_InterfaceType {
10+
str: String!
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
format: 0.0.1-prealpha.2
2+
config:
3+
node_version: "14.16.0"
4+
linked_packages:
5+
- name: "@web3api/wasm-as"
6+
path: ../../../../../wasm/as
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
format: 0.0.1-prealpha.5
2+
build: ./web3api.build.yaml
3+
language: wasm/assemblyscript
4+
modules:
5+
query:
6+
schema: ./query/schema.graphql
7+
module: ./query/index.ts
8+
mutation:
9+
schema: ./mutation/schema.graphql
10+
module: ./mutation/index.ts
11+
import_redirects:
12+
- uri: w3://ens/interface.eth
13+
schema: ../test-interface/build/schema.graphql
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
type Mutation {
2+
abstractMutationMethod(
3+
arg: UInt8!
4+
): UInt8!
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
type Query {
2+
abstractQueryMethod(
3+
arg: Argument!
4+
): String!
5+
}
6+
7+
type Argument {
8+
str: String!
9+
}
10+
11+
type InterfaceType {
12+
uint8: UInt8!
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
format: 0.0.1-prealpha.4
2+
language: interface
3+
modules:
4+
mutation:
5+
schema: ./mutation/schema.graphql
6+
query:
7+
schema: ./query/schema.graphql

0 commit comments

Comments
 (0)