etherlime test
etherlime test
Syntax
Parameters:
path
- [Optional] By specifyingpath
you can set a path to aselected directory or you can set the path directly to the
javascript file which contains your tests. By default the
path
points to
./test
.timeout
- [Optional] This parameter defines the test timeout inmilliseconds. Defaults to 2000 ms.
skip-compilation
- [Optional] This parameter controls wether acompilation will be ran before the tests are started. Default:
false.
gas-report
- [Optional] Enables Gas reporting future that willshow Gas Usage after each test. Default: false.
runs
- [Optional] By specifyingruns
between 1 and 999 youenabled the optimizer and set how many times the optimizer will be
run. By default the optimizer is not enabled.
solcVersion
- [Optional] By specifyingsolcVersion
you canset the version of the solc which will be used for compiling the
smart contracts. By default it use the solc version from the
node_modules folder.
output
- [Optional] Defines the way that the logs are shown.Choices:
none
- silences the output of logs,normal
- seeverbose logs in the console and
structured
- structured output ina file meant for inter program communication.
port
- [Optional] The port that the etherlime ganache is runing.Used for wiring up the default accounts correctly. Defaults to 8545
Global Objects
We've augmented the test runner with the following things you can use:
In your unit tests you can use the global
accounts
object. Itcontains the secretKey (private key) and instance of ethers.Wallet
of the account.
The assert object has function:
assert.revert(promiseOfFailingTransaction)
for testing reverting transactionsassert.revertWith(promiseOfFailingTransaction, expectedRevertMessage)
for testing reverting transaction with specific revert messageassert.notRevert(promiseOfNotFailingTransaction)
for testing transaction is executed successfullyassert.isAddress(value)
for testing a value is a proper addressassert.isPrivateKey(value)
for testing a value is a proper private keyassert.isHash(value)
for testing a value is a proper hexassert.emit(function, eventName)
for testing an event is emitted after function executionassert.emitWithArgs(function, eventName, [args])
for testing an event is emitted with certain arguments after function executionassert.balanceChanged(function, account, value)
for testing the balance of an account has been changed after function executionassert.balancesChanged(function, [accounts], [values])
for testing the balances of multiple accounts has been changed after function execution
Available Utils
On your disposal there is a global available utils object. Here are the methods it exposes:
utils.timeTravel(provider, seconds)
method allowing etherlimeganache to move
seconds
ahead. You need to pass your providerfrom the EtherlimeGanacheDeployer
utils.setTimeTo(provider, timestamp)
method allowing etherlimeganache to move to the desired
timestamp
ahead. You need to passyour provider from the EtherlimeGanacheDeployer
utils.mineBlock(provider)
method telling the etherlime ganacheto mine the next block. You need to pass your provider from the
EtherlimeGanacheDeployer
utils.snapshot(provider)
snapshot the state of the blockchain at the current block. Returns the integer id of the snapshot created
utils.revertState(provider, snapshotID)
revert the state of the blockchain to a previous snapshot.If no snapshot id is passed it will revert to the latest snapshot. Returns
true
.
utils.hasEvent(receipt, contract, eventName)
allowing the userto check if the desired event was broadcasted in the transaction
receipt. You need to pass the Transaction receipt, the contract
that emits it and the name of the Event.
utils.parseLogs(receipt, contract, eventName)
allowing the userget parsed events from a transaction receipt. You need to pass the
Transaction receipt, the contract that emits it and the name of
the Event. Always returns an event.
Examples
General Example
execute function from another account
accounts
assert.revert
assert.revertWith
assert.notRevert
assert.isAddress
assert.isPrivateKey
Check if the desired event was broadcasted in the transaction receipt
Check if the desired event was broadcasted with specific arguments
Check if a balance was changed on ethers sent
Check if multiple balances changed on ethers sent
Time travel and snapshot
Last updated