Giter VIP home page Giter VIP logo

Comments (9)

kivanov82 avatar kivanov82 commented on May 19, 2024 5

The case is just a simple nested call to another contract which emits an event.
Like "tx" -> contract "A" -> call contract "B" which emits event "X".
Something like this: https://ethereum.stackexchange.com/questions/2942/how-do-you-get-events-from-a-function-in-another-contract

Using just
truffleAssert.eventEmitted(tx, 'X', (ev) ) will complain about missing event.

I actually made it work like this:
let nestedEventValues = (await truffleAssert.createTransactionResult(B, tx.tx)).logs[0].returnValues;
As you see I used an instance of 'child' contract and a hash of 'main' tx.

Would be great having it as a general assertion function.

from truffle-assertions.

rkalis avatar rkalis commented on May 19, 2024 5

@PaulRBerg this is definitely one of the more important issues open right now. I've discussed some ways to improve this flow in #1. One thing I'm wondering if the new Truffle decoder library (truffle-codec?) will be able to decode events that are included in TransactionReceipts. This would make the whole process a bit easier as this would allow me to go from a TransactionReceipt-type log (encoded events) to a TransactionResult-type log (decoded events and event args).

@gnidan given a transaction receipt and a contract definition / abi, will I be able to get a decoded log for that receipt using the new decoder library?

from truffle-assertions.

ejwessel avatar ejwessel commented on May 19, 2024 4

FWIW as an extension of @kivanov82 's answer

let newTx = await truffleAssert.createTransactionResult(B, tx.tx);
truffleAssert.eventEmitted(newTx, eventType[, filter][, message])

from truffle-assertions.

rkalis avatar rkalis commented on May 19, 2024 2

Good to hear that you found a workaround for now.

I will look at what the best way is to handle this in a more straightforward way in the future.

from truffle-assertions.

bivalent avatar bivalent commented on May 19, 2024 1

Hey all, curious if this was implemented yet, seeing the merged PR from @yondonfu has me curious. Currently trying to use this libary to test smartcontract/chainlink fufillments (https://github.com/smartcontractkit/chainlink/blob/develop/evm/v0.5/contracts/Oracle.sol#L119) but the events are all nested and so do not get currently captured. Amazing library and I'm very lucky that you all have been working on it!

from truffle-assertions.

rkalis avatar rkalis commented on May 19, 2024

Hi @kivanov82

Thank you for opening this bug report. Do you have some example code where this happens so that I can look at what is happening?

from truffle-assertions.

leonprou avatar leonprou commented on May 19, 2024

Nice! it's also easy to add an inner function to your test class. following your example:

contract ('A', () => {
  let B

  const eventEmitted = async (result, ...args) => {
    const resultsOfB = await truffleAssert.createTransactionResult(B, result.tx)
    truffleAssert.eventEmitted(resultsOfB, ...args)
  }
}

I had my own struggle with that problem but on the web3 side, described a possible solution here: https://ethereum.stackexchange.com/questions/70565/reading-events-of-the-inner-solidity-contract-with-web3/70566#70566.
But failed to make it work with truffle, might require more tinkering.

from truffle-assertions.

PaulRBerg avatar PaulRBerg commented on May 19, 2024

I also encountered this issue. @rkalis I guess you could use the logic from this SE answer to make this feature native to truffle-assertions?

Copy-pasting for reference:

const keccak256 = web3.utils.keccak256;
...
const tx = await instance.someFunction(();
let event = tx.receipt.logs.some(l => { return l.topics[0] == '0x' + keccak256("Stored()") });
assert.ok(event, "Stored event not emitted");

Something like:

truffleAssert.nestedEventEmitted(result, "EventName");

Update

It seems the snippet above doesn't work with the latest version of truffle (5.0.30).

from truffle-assertions.

rkalis avatar rkalis commented on May 19, 2024

Since Truffle is being sunset, I don't plan to add new features, so I'm closing this issue.

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.