Skip to content

Commit

Permalink
Fixes for missing auth error and extends the max transaction duration…
Browse files Browse the repository at this point in the history
… to enable passing tests
  • Loading branch information
dallasjohnson committed Dec 14, 2019
1 parent 531c733 commit bf3cb6f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 49 deletions.
4 changes: 2 additions & 2 deletions src/scripts/init_blockchain.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env bash
set -o errexit
# set -o errexit

echo "=== lamington: setup blockchain accounts and smart contract ==="

Expand All @@ -15,7 +15,7 @@ rm -rf /mnt/dev/data
# run it in a background job such that docker run could continue
nodeos -e -p eosio -d /mnt/dev/data \
--config-dir /mnt/dev/config \
--max-transaction-time=1000 \
--max-transaction-time=5000 \
--http-validate-host=false \
--plugin eosio::producer_plugin \
--plugin eosio::producer_api_plugin \
Expand Down
56 changes: 9 additions & 47 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import * as deepEqualInAnyOrder from 'deep-equal-in-any-order';
import { EOSManager } from './eosManager';
import { verbose_logging } from './cli/lamington-test';
import { TableRowsResult } from './contracts';
import { verbose_logging } from './cli/lamington-test';

// Extend Chai's expect methods
chai.use(deepEqualInAnyOrder);
Expand Down Expand Up @@ -201,8 +200,12 @@ export const assertEOSError = async (
* @param operation Operation promise
* @param message Output message expected to be included
*/
export const assertEOSErrorIncludesMessage = async (operation: Promise<any>, message: string) => {
const eosErrorName = 'eosio_assert_message_exception';
export const assertEOSErrorIncludesMessage = async (
operation: Promise<any>,
message: string,
errorName?: string
) => {
const eosErrorName = errorName || 'eosio_assert_message_exception';
// Execute operation and handle exceptions
if (
!(await assertExpectedEOSError(operation, eosErrorName, error => {
Expand All @@ -226,59 +229,18 @@ export const assertEOSErrorIncludesMessage = async (operation: Promise<any>, mes
}
};

/**
* Asserts EOS throws an error and validates the error output name matches the
* expected 'eosio_assert_message_exception' and the error message includes `description`
* @author Dallas Johnson <github.com/dallasjohnson>
* @param operation Operation promise
* @param description Output message description
*/

export const assertEOSErrorIncludesMessage = async (operation: Promise<any>, message: string) => {
const eosErrorName = 'eosio_assert_message_exception';
// Execute operation and handle exceptions
try {
await operation;
} catch (error) {
let errorMessage = error.json.error.details[0].message;
if (verbose_logging) {
console.log('full error message: ' + JSON.stringify(error, null, 4));
}
if (error.json && error.json.error && error.json.error.name && errorMessage) {
// Compare error and fail if the error doesn't match the expected
assert(
error.json.error.name === eosErrorName,
`Expected ${eosErrorName}, got ${error.json.error.name} instead.`
);
assert(
errorMessage.includes(message),
`Expected to include ${message}, got ${errorMessage} instead.`
);
return;
} else {
// Fail if error not thrown by EOS
assert.fail(
`Expected EOS error ${eosErrorName}, but got ${JSON.stringify(error, null, 4)} instead.`
);
}
}
// Fail if no exception thrown
assert.fail(`Expected ${eosErrorName} but operation completed successfully.`);
};

/**
* 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>) =>
export const assertEOSException = async (operation: Promise<any>) =>
assertEOSError(operation, 'eosio_assert_message_exception', 'assert');

/**
* Asserts operation is missing the required authority by throwing a `missing_auth_exception` error
* @author Kevin Brown <github.com/thekevinbrown>
* @param operation Operation promise
*/
export const assertMissingAuthority = (operation: Promise<any>) =>
assertEOSError(operation, 'missing_auth_exception', 'missing authority');
export const assertMissingAuthority = async (operation: Promise<any>) =>
assertEOSErrorIncludesMessage(operation, '', 'missing_auth_exception');

0 comments on commit bf3cb6f

Please sign in to comment.