Skip to content

Commit

Permalink
chore: adapt to naming convention of sdk examples
Browse files Browse the repository at this point in the history
  • Loading branch information
marc0olo committed Mar 14, 2022
1 parent c218415 commit 3d22a19
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 31 deletions.
12 changes: 6 additions & 6 deletions docs/cli/test.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,27 @@ In the `test/exampleTest.js` file you can find an example for unit testing using
`const { assert } = require('chai');`
Javascript testing framework used with [mocha](https://mochajs.org/) for assertions, documented at https://www.chaijs.com/api/assert/

`const { networks, utils, wallets } = require('@aeternity/aeproject');` Helper and utilities for aeproject use, e.g. prefunded wallets, network definition and utility functions for client initialization and snapshotting.
`const { networks, utils, wallets } = require('@aeternity/aeproject');` Helper and utilities for aeproject use, e.g. prefunded wallets, network definition and utility functions for SDK initialization and snapshotting.

### 2. Client and Snapshotting Setup
### 2. SDK and Snapshotting Setup

`before(...)` used in mocha for initializations needed to be done once before all tests

`client = await utils.getClient();` use included utils to initialize default aeternity client
`aeSdk = await utils.getSdk();` use included utils to initialize default SDK instance

`const filesystem = utils.getFilesystem(EXAMPLE_CONTRACT_SOURCE);` use utils to get filesystem definition for given contract

`const source = utils.getContractContent(EXAMPLE_CONTRACT_SOURCE);` read contract source from filesystem

`contract = await client.getContractInstance({ source, filesystem });` initialize contract instance with client
`contract = await aeSdk.getContractInstance({ source, filesystem });` initialize contract instance with aeSdk

`await contract.deploy();` deploy initialized contract

`await utils.createSnapshot(client);` create snapshot once before all tests, so we can rollback to a clean state after each test
`await utils.createSnapshot(aeSdk);` create snapshot once before all tests, so we can rollback to a clean state after each test

```javascript
afterEach(async () => {
await utils.rollbackSnapshot(client);
await utils.rollbackSnapshot(aeSdk);
});
```

Expand Down
18 changes: 9 additions & 9 deletions docs/migration-from-3.x.x-to-4.x.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ Following commands have been removed and cannot be used anymore. Most of them di

- `aeproject compatibility` (discontinued)
- `aeproject compile`
- manual compilation isn't needed for use of aeproject, alternatively use [aecli](https://github.com/aeternity/aepp-cli-js) or the [sdk](https://github.com/aeternity/aepp-sdk-js) programmatically
- manual compilation isn't needed for use of aeproject, alternatively use the [CLI](https://github.com/aeternity/aepp-cli-js) or the [SDK](https://github.com/aeternity/aepp-sdk-js) programmatically
- `aeproject deploy`
- deployment isn't supported in aeproject anymore, alternatively use [aecli](https://github.com/aeternity/aepp-cli-js) or the [sdk](https://github.com/aeternity/aepp-sdk-js) programmatically
- deployment isn't supported in aeproject anymore, alternatively use the [CLI](https://github.com/aeternity/aepp-cli-js) or the [SDK](https://github.com/aeternity/aepp-sdk-js) programmatically
- `aeproject export` (discontinued)
- `aeproject tx-inspector`
- manual tx inspection is moved to [aecli](https://github.com/aeternity/aepp-cli-js)
- manual tx inspection is moved to the [CLI](https://github.com/aeternity/aepp-cli-js)
### Changed commands
- `aeproject init`
- added the `folder` argument to create a new folder for the project initialization
Expand All @@ -30,19 +30,19 @@ Testing is now handled locally in the project using `mocha` and `chai` as direct

`@aeternity/aeproject` is added itself as dependency and includes some library-functions that can be used in testing.

```
```js
const { networks, utils, wallets } = require('@aeternity/aeproject');
```

- `networks` includes network definitions for local development, testnet and mainnet
- `wallets` includes example wallets that are prefunded in local development
- `utils` includes helper functions for testing
- `getFilesystem(source)` to get the filesystem definition for a given contract for deployment
- `getClient()` get a default client for local development
- `getSdk()` get an instance of the SDK for local development
- initialized with all prefunded wallets for `onAccount` to be used calling from different accounts
- `awaitKeyBlocks(client, number)` await a certain number of key-blocks
- `createSnapshot(client)` create a snapshot for local testing
- `rollbackSnapshot(client)` rollback to previously created snapshot in local testing
- `awaitKeyBlocks(aeSdk, number)` await a certain number of key-blocks
- `createSnapshot(aeSdk)` create a snapshot for local testing
- `rollbackSnapshot(aeSdk)` rollback to previously created snapshot in local testing

## Migration of old projects
1. Upgrade your project
Expand All @@ -63,4 +63,4 @@ const { networks, utils, wallets } = require('@aeternity/aeproject');
- local testing network is now `devmode` instead of `local`
- replace `defaultWallets` import with `const { wallets } = require('@aeternity/aeproject');` for prefunded wallets
- replace `contractUtils` import with `const { utils } = require('@aeternity/aeproject');` for utils
- consider using the new helpers for getting a client and creating snapshots similar to `test/exampleTest.js`
- consider using the new helpers for initializing the SDK and creating snapshots similar to `test/exampleTest.js`
10 changes: 5 additions & 5 deletions src/init/update-artifacts/test/exampleTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ const { utils, wallets } = require('@aeternity/aeproject');
const EXAMPLE_CONTRACT_SOURCE = './contracts/ExampleContract.aes';

describe('ExampleContract', () => {
let client;
let aeSdk;
let contract;

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

// a filesystem object must be passed to the compiler if the contract uses custom includes
const filesystem = utils.getFilesystem(EXAMPLE_CONTRACT_SOURCE);
Expand All @@ -17,16 +17,16 @@ describe('ExampleContract', () => {
const source = utils.getContractContent(EXAMPLE_CONTRACT_SOURCE);

// initialize the contract instance
contract = await client.getContractInstance({ source, filesystem });
contract = await aeSdk.getContractInstance({ source, filesystem });
await contract.deploy();

// create a snapshot of the blockchain state
await utils.createSnapshot(client);
await utils.createSnapshot(aeSdk);
});

// after each test roll back to initial state
afterEach(async () => {
await utils.rollbackSnapshot(client);
await utils.rollbackSnapshot(aeSdk);
});

it('ExampleContract: set and get', async () => {
Expand Down
22 changes: 11 additions & 11 deletions src/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ async function get(url) {
});
}

const getClient = async () => {
const getSdk = async () => {
const instance = await Node({ url: networks.devmode.nodeUrl, ignoreVersion: true })
.catch((error) => {
if (error.message && error.message.includes('ECONNREFUSED')) {
Expand All @@ -93,24 +93,24 @@ const getClient = async () => {
});
};

const awaitKeyBlocks = async (client, n = 1) => {
const height = await client.height();
const awaitKeyBlocks = async (aeSdk, n = 1) => {
const height = await aeSdk.height();
await get(`http://localhost:3001/emit_kb?n=${n}`);
await client.awaitHeight(height + n);
await aeSdk.awaitHeight(height + n);
};

let snapshotHeight = -1;

const createSnapshot = async (client) => {
snapshotHeight = await client.height();
await awaitKeyBlocks(client, 1);
const createSnapshot = async (aeSdk) => {
snapshotHeight = await aeSdk.height();
await awaitKeyBlocks(aeSdk, 1);
};

const rollbackSnapshot = async (client) => {
const currentBlockHeight = await client.height();
const rollbackSnapshot = async (aeSdk) => {
const currentBlockHeight = await aeSdk.height();
if (currentBlockHeight > snapshotHeight) {
await get(`http://localhost:3001/rollback?height=${snapshotHeight}`);
await awaitKeyBlocks(client, 1);
await awaitKeyBlocks(aeSdk, 1);
}
};

Expand All @@ -120,5 +120,5 @@ module.exports = {
awaitKeyBlocks,
createSnapshot,
rollbackSnapshot,
getClient,
getSdk,
};

0 comments on commit 3d22a19

Please sign in to comment.