Comments (9)
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.
@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.
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.
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.
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.
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.
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.
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.
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)
- 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.