From 3d22a19ea787351abc8b68dba2d92bc6b609b7bf Mon Sep 17 00:00:00 2001 From: marc0olo Date: Mon, 14 Mar 2022 15:28:44 +0100 Subject: [PATCH] chore: adapt to naming convention of sdk examples --- docs/cli/test.md | 12 +++++----- docs/migration-from-3.x.x-to-4.x.x.md | 18 +++++++-------- src/init/update-artifacts/test/exampleTest.js | 10 ++++----- src/lib/utils.js | 22 +++++++++---------- 4 files changed, 31 insertions(+), 31 deletions(-) diff --git a/docs/cli/test.md b/docs/cli/test.md index f46ee976..fb3c99bb 100644 --- a/docs/cli/test.md +++ b/docs/cli/test.md @@ -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); }); ``` diff --git a/docs/migration-from-3.x.x-to-4.x.x.md b/docs/migration-from-3.x.x-to-4.x.x.md index 5a16e53c..417aad5f 100644 --- a/docs/migration-from-3.x.x-to-4.x.x.md +++ b/docs/migration-from-3.x.x-to-4.x.x.md @@ -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 @@ -30,7 +30,7 @@ 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'); ``` @@ -38,11 +38,11 @@ const { networks, utils, wallets } = require('@aeternity/aeproject'); - `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 @@ -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` diff --git a/src/init/update-artifacts/test/exampleTest.js b/src/init/update-artifacts/test/exampleTest.js index 2666d9c2..4ce223c4 100644 --- a/src/init/update-artifacts/test/exampleTest.js +++ b/src/init/update-artifacts/test/exampleTest.js @@ -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); @@ -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 () => { diff --git a/src/lib/utils.js b/src/lib/utils.js index 6048b173..764fb6a5 100644 --- a/src/lib/utils.js +++ b/src/lib/utils.js @@ -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')) { @@ -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); } }; @@ -120,5 +120,5 @@ module.exports = { awaitKeyBlocks, createSnapshot, rollbackSnapshot, - getClient, + getSdk, };