npmjs_truffle-helper
v2.0.0
Published
Development helpers for Truffle and Ganache — test assertions, event capture, Ganache configuration, and block utilities
Maintainers
Readme
truffle-helper
Development helper utilities for Truffle and Ganache. Provides test assertions, event capture, Ganache configuration, and block waiting utilities.
Installation
npm install truffle-helperQuick Start
const { assertTxSuccess, assertTxReverts, getEvent, createGanacheConfig, waitForBlocks } = require('truffle-helper');
// Test helpers
const result = { receipt: { status: true }, tx: '0x1234...' };
assertTxSuccess(result); // passes
try {
throw new Error('revert: insufficient balance');
} catch (e) {
assertTxReverts(e); // passes
}
// Capture events
const receipt = {
logs: [{ event: 'Transfer', args: { from: '0x...', to: '0x...' } }]
};
const transferEvent = getEvent(receipt, 'Transfer');
console.log(transferEvent);
// Create Ganache config
const config = createGanacheConfig({ port: 8545 });
console.log(config);API Reference
assertTxSuccess(result)
Asserts that a transaction was successful (status true, non-empty hash).
assertTxReverts(error)
Asserts that an error indicates a transaction revert.
getEvent(receipt, eventName)
Extracts a specific event from a transaction receipt.
createGanacheConfig(opts)
Creates a Ganache provider configuration with sensible defaults.
waitForBlocks(blocks)
Async wait for a specified number of blocks (1s per block).
License
MIT
