Skip to content

Commit

Permalink
fix: sdk import usage
Browse files Browse the repository at this point in the history
  • Loading branch information
thepiwo committed Nov 26, 2024
1 parent abd11f0 commit 5609660
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 16 deletions.
7 changes: 4 additions & 3 deletions docs/cli/test.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ const { assert } = require("chai");
Helper and utilities for AEproject use, e.g. prefunded wallets, network definition and utility functions for SDK initialization and snapshotting.

```js
const { networks, utils, wallets } = require("@aeternity/aeproject");
const { getFileSystem } = require("@aeternity/aepp-sdk");
const { utils } = require("@aeternity/aeproject");
import * as AeppSdk from "@aeternity/aepp-sdk";
const { Contract, getFileSystem } = require("@aeternity/aepp-sdk");
```

Read [AEproject Library](../lib.md) for a more detailed explanation about the usage of these imports.
Expand All @@ -40,7 +41,7 @@ before(async () => ...)
Initialize the default SDK instance with provided utils:

```js
aeSdk = utils.getSdk();
aeSdk = utils.getSdk(AeppSdk, {});
```

Get the filesystem definition for (custom) `includes` of the given contract:
Expand Down
3 changes: 2 additions & 1 deletion docs/lib.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ utils.getContractContent(contractPath);
Read the contract source from given path, just a wrapper for `fs.readFileSync` using `utf-8` encoding.

```javascript
utils.getSdk();
import * as AeppSdk from "@aeternity/aepp-sdk";
utils.getSdk(AeppSdk, {});
```

Initialize the æternity SDK, pre-configured for optimal use in an AEproject project using æternity node devmode.
Expand Down
1 change: 1 addition & 0 deletions docs/migration-from-4.x.x-to-5.x.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ npm install -g @aeternity/aeproject
- **dropped commonjs support**, newly created projects will be created as esm projects, old cjs projects will not continue to work with newer aeproject versions, to keep using old cjs projects, `@aeternity/aeproject@4` will continue to work for now.
- `node@16` is no longer supported, please update to v18 or higher
- updated to `@aeternity/aepp-sdk@14` to the latest version, see the [migration guide](https://github.com/aeternity/aepp-sdk-js/blob/v14.0.0/docs/guides/migration/14.md) for additional reference.
- the aeproject provided `utils.getSdk({})` has to be adjusted to pass a reference to the sdk used `utils.getSdk(AeppSdk, {})` where AeppSdk can be imported using `import * as AeppSdk from "@aeternity/aepp-sdk";`

## Removed from libs

Expand Down
9 changes: 4 additions & 5 deletions src/init/update-artifacts/test/exampleTest.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { utils } from "@aeternity/aeproject";
import { getFileSystem } from "@aeternity/aepp-sdk";
import * as AeppSdk from "@aeternity/aepp-sdk";
import { Contract, getFileSystem } from "@aeternity/aepp-sdk";
import * as chai from "chai";
import { assert } from "chai";
import chaiAsPromised from "chai-as-promised";
import * as chai from "chai";
const { Contract } = require("@aeternity/aepp-sdk");
import { before, describe, afterEach, it } from "mocha";

chai.use(chaiAsPromised);
Expand All @@ -15,8 +15,7 @@ describe("ExampleContract", () => {
let contract;

before(async () => {
aeSdk = utils.getSdk();

aeSdk = utils.getSdk(AeppSdk, {});
// a filesystem object must be passed to the compiler if the contract uses custom includes
const fileSystem = await getFileSystem(EXAMPLE_CONTRACT_SOURCE);

Expand Down
12 changes: 6 additions & 6 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs from "fs";

import { AeSdk, MemoryAccount, Node, CompilerHttp, Encoded } from "@aeternity/aepp-sdk";
import * as AeppSdkType from "@aeternity/aepp-sdk";
import { AeSdk, MemoryAccount, Encoded } from "@aeternity/aepp-sdk";
import { readFile } from "fs/promises";

export const networks = JSON.parse(
Expand All @@ -26,13 +26,13 @@ export function getDefaultAccounts(): MemoryAccount[] {
);
}

export function getSdk(options: {}): AeSdk {
const instance = new Node(networks.devmode.nodeUrl, options);
export function getSdk(AeppSdk: typeof AeppSdkType, options: {}): AeSdk {
const instance = new AeppSdk.Node(networks.devmode.nodeUrl, options);

return new AeSdk({
return new AeppSdk.AeSdk({
accounts: getDefaultAccounts(),
nodes: [{ name: "node", instance }],
onCompiler: new CompilerHttp(networks.devmode.compilerUrl, options),
onCompiler: new AeppSdk.CompilerHttp(networks.devmode.compilerUrl, options),
interval: 50,
});
}
Expand Down
4 changes: 3 additions & 1 deletion tests/lib.test.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import * as utils from "./../src/lib/utils";

import { exec, cwd, prepareLocal, cleanLocal, linkLocalLib } from "./util";
import * as AeppSdk from "@aeternity/aepp-sdk";

import { MemoryAccount } from "@aeternity/aepp-sdk";

describe("library usage", () => {
Expand All @@ -13,7 +15,7 @@ describe("library usage", () => {

await exec("aeproject env", { cwd });

aeSdk = utils.getSdk();
aeSdk = utils.getSdk(AeppSdk, {});
});

afterAll(async () => {
Expand Down

0 comments on commit 5609660

Please sign in to comment.