Skip to content

Commit

Permalink
Additional Documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
MitchPierias committed Apr 22, 2019
1 parent 32e1032 commit 6e3f72b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 24 deletions.
23 changes: 21 additions & 2 deletions src/eosManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,32 @@ import fetch from 'node-fetch';
import { TextEncoder, TextDecoder } from 'util';
import { Api, JsonRpc } from 'eosjs';
import { JsSignatureProvider } from 'eosjs/dist/eosjs-jssig';

import { Account } from './accounts';

/**
* Manages client connection and communication with a local EOSIO node
*/
export class EOSManager {

/** Defaults to `eosio` administration account */
static adminAccount: Account;
/** Development signature provider */
static signatureProvider: JsSignatureProvider;
/** Configured EOSjs client */
static api: Api;
/** RPC connection with the local EOSIO node at `http://127.0.0.1:8888` */
static rpc: JsonRpc;

/**
* Initializes a default connection to the local EOSIO node on port `8888` and
* assigns the default `eosio` account with administration keys
* @author Kevin Brown <github.com/thekevinbrown>
*/
static initWithDefaults = () => {
// Create eosio account and configure signature provider
const adminPrivateKey = '5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3';
EOSManager.adminAccount = new Account('eosio', adminPrivateKey);
EOSManager.signatureProvider = new JsSignatureProvider([adminPrivateKey]);

// Typecasting as any here to prevent a problem with the types disagreeing for fetch,
// when this is actually following the getting started docs on EOSJS.
EOSManager.rpc = new JsonRpc('http://127.0.0.1:8888', { fetch: fetch as any });
Expand All @@ -28,6 +40,13 @@ export class EOSManager {
});
};

/**
* Executes a transaction against a connected EOSjs client
* @author Kevin Brown <github.com/thekevinbrown>
* @param transaction EOSIO transaction object
* @param eos Connected EOSjs client
* @param options Additional transaction options
*/
static transact = (
transaction: any,
eos = EOSManager.api,
Expand Down
6 changes: 3 additions & 3 deletions src/gitignoreManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ const gitignoreFilePath = path.join(configDirectory, '.gitignore');
const encoding = 'utf8';

/**
* @class GitIgnoreManager
* Manages the `.gitignore` file and configuration
*/
export class GitIgnoreManager {

/**
* Create if Missing
* @desc Creates a base configuration `.gitignore` file when it doesn't exit
* Creates a `.gitignore` file when it doesn't exist
* and configures the base ignore files
*/
public static async createIfMissing() {
if (!(await exists(gitignoreFilePath))) {
Expand Down
29 changes: 10 additions & 19 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import { TableRowsResult } from './contracts';
chai.use(deepEqualInAnyOrder);

/**
* Sleep Until Block
* @desc Pauses the current process until the specified EOS block number occurs
* Pauses the current process until the specified EOS block number occurs
* @note Assumes blocks will always be produced every 500ms
* @author Kevin Brown <github.com/thekevinbrown>
* @param number Process sleep duration
Expand All @@ -20,32 +19,29 @@ export const untilBlocknumber = async (number: number) => {
// Loops until current head block number reaches desired
let { head_block_num } = await EOSManager.rpc.get_info();
while (head_block_num < number) {
// Sleep for block and update current block number
// Sleep for block duration and update current block number
await sleep((number - head_block_num) * 500);
({ head_block_num } = await EOSManager.rpc.get_info());
}
};

/**
* Sleep Process
* @desc Pauses the current process for the specified duration
* Pauses the current process for the specified duration
* @author Kevin Brown <github.com/thekevinbrown>
* @param delayInMs Process sleep duration
*/
export const sleep = async (delayInMs: number) =>
new Promise(resolve => setTimeout(resolve, delayInMs));

/**
* Sleep Block
* @desc Pauses the current process for the 500ms EOS block time
* Pauses the current process for the 500ms EOS block time
* @note The process will wake during and not on the next block
* @author Kevin Brown <github.com/thekevinbrown>
*/
export const nextBlock = () => sleep(500);

/**
* Assert table rows equal expected
* @desc Compares table rows against expected rows
* Performs a comparison of table row query results against expected rows
* @author Kevin Brown <github.com/thekevinbrown>
* @param getTableRowsResult Get table rows result promise
* @param expected Expected table row query results
Expand All @@ -63,8 +59,7 @@ export const assertRowsEqual = async <RowType>(
};

/**
* Assert table rows eventually equal expected
* @desc Compares table rows against expected rows irrespective of order
* Compares table rows against expected rows irrespective of order
* @author Mitch Pierias <github.com/MitchPierias>
* @param getTableRowsResult Get table rows result promise
* @param expected Expected table row query results
Expand All @@ -83,8 +78,7 @@ export const assertRowsEqualLazy = async <RowType>(
};

/**
* Assert table row result count
* @desc Validates the number of rows returned is equal to the expected count
* Validates the number of rows returned is equal to the expected count
* @author Kevin Brown <github.com/thekevinbrown>
* @param getTableRowsResult Get table rows result promise
* @param expectedRowCount Expected number of table rows
Expand All @@ -105,8 +99,7 @@ export const assertRowCount = async (
};

/**
* Assert EOS Error
* @desc Asserts EOS throws an error and validates the error output name matches the expected `eosErrorName`
* Asserts EOS throws an error and validates the error output name matches the expected `eosErrorName`
* @author Kevin Brown <github.com/thekevinbrown>
* @param operation Operation promise
* @param eosErrorName Expected EOS error name
Expand Down Expand Up @@ -138,17 +131,15 @@ export const assertEOSError = async (
};

/**
* Assert EOS Exception
* @desc Asserts operation throws an `eosio_assert_message_exception` error
* Asserts operation throws an `eosio_assert_message_exception` error
* @author Kevin Brown <github.com/thekevinbrown>
* @param operation Operation promise
*/
export const assertEOSException = (operation: Promise<any>) =>
assertEOSError(operation, 'eosio_assert_message_exception', 'assert');

/**
* Assert Missing EOS Authority
* @desc Asserts operation is missing the required authority by throwing a `missing_auth_exception` error
* Asserts operation is missing the required authority by throwing a `missing_auth_exception` error
* @author Kevin Brown <github.com/thekevinbrown>
* @param operation Operation promise
*/
Expand Down

0 comments on commit 6e3f72b

Please sign in to comment.