Git Product home page Git Product logo

Comments (7)

rkalis avatar rkalis commented on May 19, 2024

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.

rkalis avatar rkalis commented on May 19, 2024

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.

rkalis avatar rkalis commented on May 19, 2024

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.

rkalis avatar rkalis commented on May 19, 2024

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.

zanawar avatar zanawar commented on May 19, 2024

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.

rkalis avatar rkalis commented on May 19, 2024

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.

rkalis avatar rkalis commented on May 19, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.