Comments (7)
I set up a CI pipeline. On every push, a Travis build will run, which runs all tests using Mocha. Test coverage is generated using İstanbul (nyc), and sent to Coveralls.
from truffle-assertions.
I added eslint to the repository with the AirBnB javascript styleguide enabled. I added the linting to the Travis job as well.
from truffle-assertions.
I would like to remove the dependency on web3 (used in createTransactionResult()
). Instead I could perhaps support passing in transaction receipts, along with a contract instance/abi, so the logs in the transaction receipt could be decoded and asserted.
Instead of:
const tx = truffleAssert.createTransactionResult(contractInstance, txHash);
truffleAssert.eventEmitted(tx, 'Event');
It would be:
const txReceipt = web3.eth.getTransactionReceipt(transactionHash);
truffleAssert.eventEmittedInReceipt(contractInstance, txReceipt, 'Event');
This makes it easier to support multiple versions of web3, and it makes unit testing easier, as there is never a running blockchain needed to test the implementation. This might make it easier as well to create a general solution for #6, although I still need to find a way get the decoded logs using multiple contracts/abis to get nested events.
from truffle-assertions.
In the light of #6 and #9, it could be possible to change the API of the library to be more fluent, allowing additional assertions to be added more easily.
Such an API could look like the following examples:
const tx = await contractInstance.function({from: account});
truffleAssert.inTxResult(tx).events('Event', (ev) => {
return ev.parameter1 = 'One';
}).areEmitted();
truffleAssert.inTxResult(tx).events('Event').areNotEmitted();
truffleAssert.inTxResult(tx).events('Event', filterFn).count.isGreaterThan(2);
truffleAssert.inTxResult(tx).events().count.isLessThan(2);
const txReceipt = web3.eth.getTransactionReceipt(transactionHash);
truffleAssert.inTxReceipt(txReceipt, contractInstance).events('Event', (ev) => {
return ev.parameter2 == 'Two'
}).isEmitted();
truffleAssert.inTxReceipt(txReceipt, contractInstance)
.events('Event').isNotEmitted();
truffleAssert.inTxReceipt(txReceipt, contractInstance)
.events('Event').count.equals(1);
Another option could be to return the events or event count and using that in regular assertions.
assert.isAbove(truffleAssert.inTxResult(tx).getEvents('Event', filterFn).length, 2);
A pro of using such a fluent API would be that it is easier to take different inputs (like a transaction result or a transaction receipt) without needing multiple functions for the different combinations of inputs and actions.
A con of using this API would be that it would lead to longer lines, and code that is potentially less easy to read.
from truffle-assertions.
I like the fluent API design since it allows for greater flexibility.
It looks readable except for when using regular assertions like in:
assert.isAbove(truffleAssert.inTxResult(tx).getEvents('Event', filterFn).length, 2);
However while i'd prefer using count.isGreaterThan
I think having the ability to use either would be really helpful:
truffleAssert.inTxResult(tx).events('Event').count.isGreaterThan(2);
// OR
assert.isAbove(truffleAssert.inTxResult(tx).events('Event').length, 2);
And additionally the API events()
appeals to me more than getEvents()
from truffle-assertions.
Thanks @zanawar, I agree with the things you said. I think I will get started on implementing some first test version of the basic truffle-assertions functionality (eventEmitted, eventNotEmitted) to see what it's like.
from truffle-assertions.
I added tests for all methods (except createTransactionResult()
) to the v1.0 branch. I should still add some tests using fixtures generated with truffle v5 to be sure.
With these tests in place, it should be safe to start refactoring the existing code.
I also switched to Codecov from Coveralls as Coveralls was being completely unreliable for the past week, while Codecov immediately worked great.
from truffle-assertions.
Related Issues (20)
- Indentation of getPrettyEmittedEventsString doesn't always make sense HOT 4
- Different behavior when running testing against Rinkeby HOT 4
- Make web3 an optional dependency HOT 5
- truffleAssert.reverts not working but error msg is displayed instead HOT 3
- eventEmitted to receive an event object. HOT 6
- Checking event spawned by fallback function HOT 7
- Cannot read property 'filter' of undefined HOT 5
- can not install with truffle-hdwallet-provider installed HOT 5
- truffle-assertions + truffle-hdwallet-provider + Test.sol > Error: the tx doesn't have the correct nonce HOT 1
- Revert reason checking is not strict HOT 4
- Does not work well with solidity-coverage HOT 3
- Revert reason string not working with Ropsten HOT 1
- Support numeric event parameter HOT 3
- Capturing multiple events HOT 3
- Assigning emitted event parameter to variable HOT 1
- Make "reverts" automatically unpack promises? HOT 1
- How can I test the burning of a token with truffle assertions? HOT 1
- Reverts Test For Calling Same Function Twice Incorrectly Fails HOT 10
- Add JSDocs or convert to TypeScript HOT 1
- Is there a way to subscribe to events using this library? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from truffle-assertions.