@@ -8,64 +8,46 @@ It allows user to initiate the test environment through a javascript function (i
88
99# Usage
1010
11- Initialization with the simple-storage wrapper.
11+ ## Init test env
12+
13+ Spin up docker containers for Ganache and IPFS.
1214
1315``` typescript
14- import path from " path" ;
15- import { PolywrapClient } from " @polywrap/client-js" ;
16- import {
17- buildWrapper ,
18- initTestEnvironment ,
19- stopTestEnvironment ,
20- providers ,
21- ensAddresses
22- } from " @polywrap/test-env-js" ;
23- import * as App from " ../types/wrap" ;
24-
25- // test wrapper in a test environment
26- export async function foo({
27- // spin up docker containers for Ganache and IPFS.
2816 await initTestEnvironment ();
29- const CONNECTION = { networkNameOrChainId: " testnet" };
17+ ```
18+
19+ ## Stop test env
20+
21+ Stop docker containers for Ganache and IPFS.
22+
23+ ``` typescript
24+ await stopTestEnvironment ();
25+ ```
26+
27+ ## Build a wrapper
3028
29+ Build a local wrapper project.
30+
31+ ``` typescript
3132 // get path to the wrapper in testing
3233 const wrapperPath: string = path .join (path .resolve (__dirname ), " .." );
3334
3435 // build current wrapper with CLI, invoking codegen before build
3536 await buildWrapper (wrapperPath , undefined , true );
3637
3738 // get URI to the local wrapper build
38- const wrapperUri = ` fs/${wrapperPath }/build ` ;
39-
40- // invoke the wrapper to deploy a contract to the test env
41- const deployContractResponse = await App .SimpleStorage_Module .deployContract (
42- { connection: CONNECTION },
43- client ,
44- wrapperUri
45- );
46- const contractAddress = deployContractResponse .data as string ;
47-
48- // invoke the wrapper to query a contract in the test env
49- const response = await App .SimpleStorage_Module .getData (
50- {
51- address: contractAddr ,
52- connection: CONNECTION ,
53- },
54- client ,
55- wrapperUri
56- );
57- });
58-
39+ const wrapperUri = ` wrap://fs/${wrapperPath }/build ` ;
5940```
6041
61- # API Outline
42+ ## Execute the CLI
6243
63- - ensAddresses, providers - constant addresses and urls
64- - runCLI - run arbitrary Polywrap CLI commands
65- - initTestEnvironment - spin up Ganache and IPFS Docker instances
66- - stopTestEnvironment - stop Docker
67- - buildWrapper - compile wasm and bindings
68- - buildAndDeployWrapper - deploy wrapper to the testnet ENS
44+ Execute a command with the Polywrap CLI.
45+
46+ ``` typescript
47+ const { exitCode, stderr, stdout } = await runCLI ({
48+ args: [" infra" , " up" , " --verbose" ],
49+ });
50+ ```
6951
7052## Constants
7153
@@ -138,11 +120,13 @@ export const stopTestEnvironment = async (
138120 * Build the wrapper located at the given path
139121 *
140122 * @param wrapperAbsPath - absolute path of wrapper to build
141- * @param manifestPathOverride ? - path to p
123+ * @param manifestPathOverride ? - path to polywrap manifest
124+ * @param codegen ? - run codegen before build
142125 */
143126export async function buildWrapper(
144127 wrapperAbsPath : string ,
145- manifestPathOverride ? : string
128+ manifestPathOverride ? : string ,
129+ codegen ? : boolean
146130): Promise <void >
147131```
148132
@@ -157,6 +141,7 @@ export async function buildWrapper(
157141 * @param ipfsProvider - ipfs provider to use for deployment
158142 * @param ethereumProvider - ethereum provider to use for ENS registration
159143 * @param ensName? - an ENS domain name to register and assign to the wrapper
144+ * @param codegen? - run codegen before build
160145 *
161146 * @returns registered ens domain name and IPFS hash
162147 */
@@ -165,28 +150,19 @@ export async function buildAndDeployWrapper({
165150 ipfsProvider,
166151 ethereumProvider,
167152 ensName,
153+ codegen,
168154}: {
169155 wrapperAbsPath: string;
170156 ipfsProvider: string;
171157 ethereumProvider: string;
172158 ensName?: string;
159+ codegen?: boolean;
173160}): Promise<{
174161 ensDomain: string;
175162 ipfsCid: string;
176163}>
177164` ` `
178165
179- ` ` ` typescript title="Example: buildAndDeployWrapper with default infrastructure module"
180- import { buildAndDeployWrapper, providers } from "@polywrap/test-env-js";
181-
182- const { ensDomain, ipfsCid } = await buildAndDeployWrapper({
183- wrapperAbsPath: "...",
184- ipfsProvider: providers.ipfs,
185- ethereumProvider: providers.ethereum,
186- });
187- const ensUri = ` ens / testnet / $ {ensDomain }` ;
188- ` ` `
189-
190166### buildAndDeployWrapperToHttp
191167
192168` ` ` typescript
@@ -197,17 +173,20 @@ const ensUri = `ens/testnet/${ensDomain}`;
197173 * @param wrapperAbsPath - absolute path of wrapper to build
198174 * @param httpProvider - http provider used for deployment and domain registration
199175 * @param name? - a domain name to register and assign to the wrapper
176+ * @param codegen? - run codegen before build
200177 *
201178 * @returns http uri
202179 */
203180export async function buildAndDeployWrapperToHttp({
204181 wrapperAbsPath,
205182 httpProvider,
206183 name,
184+ codegen,
207185}: {
208186 wrapperAbsPath: string;
209187 httpProvider: string;
210188 name?: string;
189+ codegen?: boolean;
211190}): Promise<{ uri: string }>
212191` ` `
213192
@@ -217,10 +196,11 @@ export async function buildAndDeployWrapperToHttp({
217196/**
218197 * Runs the polywrap CLI programmatically.
219198 *
220- * @param args - an array of command line arguments
221- * @param cwd? - a current working directory
222- * @param cli? - a path to a Polywrap CLI binary
223- * @param env? - a map of environmental variables
199+ * @param options - an object containing:
200+ * args - an array of command line arguments
201+ * cwd? - a current working directory
202+ * cli? - a path to a Polywrap CLI binary
203+ * env? - a map of environmental variables
224204 *
225205 * @returns exit code, standard output, and standard error logs
226206 */
@@ -234,10 +214,4 @@ export const runCLI = async (options: {
234214 stdout: string;
235215 stderr: string;
236216}>
237- ` ` `
238-
239- ` ` ` typescript title="Example: runCLI calling the 'infra' command"
240- const { exitCode, stderr, stdout } = await runCLI({
241- args: ["infra", "up", "--modules=eth-ens-ipfs", "--verbose"]
242- });
243217` ` `
0 commit comments