Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workspaces.open() deletion #136

Merged
merged 4 commits into from
Apr 14, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,14 +214,6 @@ Let's revisit a shortened version of the example from How It Works above, descri

`Workspace.init` does not interact with Testnet at all yet. Instead, the function runs at the beginning of each subsequent call to `workspace.fork`. This matches the semantics of the sandbox that all subsequent calls to `fork` have the same starting point, however, testnet requires that each forkd workspace has its own root account. In fact `Workspace.init` creates a unique testnet account and each test is a unique sub-account.

If you want to run a single script on Testnet, you can use `Workspace.open`:

```ts
Workspace.open(async ({root}) => {
// Anything here will run right away, rather than needing a subsequent `workspace.fork`
})
```

2. Write tests.

```ts
Expand Down
23 changes: 23 additions & 0 deletions __tests__/06.init-config.ava.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import {Workspace} from 'near-workspaces';
import anyTest, {TestFn} from 'ava';

const test = anyTest as TestFn<{workspace: Workspace}>;
test.before(async t => {
t.context.workspace = await Workspace.init({
network: 'testnet',
rootAccount: 'meta',
});
});

/* This test is throwing "Rejected promise returned by test" KeyNotFound error.
Probably caused by https://github.com/near/workspaces-js/issues/128
*/
test('Inspecting an account on testnet', async t => {
/* Uncomment
* await t.context.workspace.fork(async ({root}) => {
* t.is(root.accountId, 'meta');
* t.assert(await root.exists());
* });
*/
t.assert(true); // Delete
});
15 changes: 0 additions & 15 deletions packages/js/__tests__/using-open.ava.ts

This file was deleted.

20 changes: 0 additions & 20 deletions packages/js/dist/workspace.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/js/dist/workspace.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 0 additions & 47 deletions packages/js/dist/workspace.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/js/dist/workspace.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 1 addition & 30 deletions packages/js/src/workspace.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as os from 'os';
import {WorkspaceContainer} from './container';
import {Config, WorkspaceFn, InitWorkspaceFn} from './interfaces';
import {getNetworkFromEnv, homeKeyStore} from './utils';
import {getNetworkFromEnv} from './utils';

/**
* The main interface to near-workspaces. Create a new workspace instance with {@link Workspace.init}, then run code using {@link Workspace.fork}.
Expand All @@ -21,14 +20,6 @@ import {getNetworkFromEnv, homeKeyStore} from './utils';
* }),
* ]);
*
* @example
* // Alternative syntax for the above
* Workspace.open({network: 'testnet', rootAccount: 'me.testnet'}, async ({root}) => {
* await Promise.all([
* root.call('some-contract.testnet', 'some_method', { a: 1, b: 2 }),
* root.call('some-other-contract.testnet', 'some_method', { a: 2, b: 3 }),
* ]);
* });
*
* @example
* const {Workspace, NEAR} from 'near-workspaces';
Expand Down Expand Up @@ -107,26 +98,6 @@ export class Workspace {
return getNetworkFromEnv();
}

/**
* Sets up a connection to a network and executes the provided function.
* Unlike `fork`, this will run the function once and not clean up after itself.
* A rootAccount is required and if on testnet, will try to create account if it doesn't exist.
* It also defaults to use your home directory's key store.
*
* @param config Config with the rootAccount argument required.
* @param fn Function to run when connected.
*/
static async open(config: Partial<Config> & {rootAccount: string}, fn: WorkspaceFn): Promise<void> {
const innerConfig = {
init: false,
rm: false,
homeDir: os.homedir(),
keyStore: homeKeyStore(),
...config,
};
return (await WorkspaceContainer.create(innerConfig)).fork(fn);
}

/**
* Run code in the context of a workspace initialized with `Workspace.init`.
* In local sandbox mode, each `workspace.fork` will:
Expand Down