Open Aladeenb opened 1 year ago
Hey @Aladeenb, can you send a link to the code as well? Also, you may want to look at TestTransactionEvent from the GAM, which I think will make mocking the event easier for you.
I will check GAM @Vxatz, thank you
Thanks for the link.
So, firstly, there are some issues in the bot logic.
1) In this const createUpdateTransaction = Object.keys(txEvent.addresses).find(() => NETHERMIND_ADDRESS);
The NETHERMIND_ADDRESS
is a checksum address, while the txEvent.addresses
returns the addresses in lowercase.
2) The simpler way to perform this check is to check if txEvent.from
is equal to Nethermind Address.
3) The e.g. else if (!createBots && updateBots)
check in L51 is not correct because createBots
in this case is not undefined, but an empty array (the correct check would be !(createBots.length >0)
(You can re-open the PR and ask for a re-review)
Regarding your question, you're currently not mocking the txEvent object correctly. E.g. in the real logic you're using txEvent.addresses
, which is not mocked. But the main issues have to do with the logic, so you can focus on that first (then you can use the TestTransactionEvent
as I mentioned before)
Another issue is you're using mockTxEvent.filterFunction = jest.fn().mockReturnValue([mockCreateBot]), instead of mockTxEvent.filterFunction = jest.fn().mockReturnValueOnce([mockCreateBot]); (which would call the mock only for the create functions - not for update functions).
Lastly, both Forta and Nethermind address should be mocked while testing, so you can pass them as parameters to the provideHandleTransaction
(which will be a wrapper function for the handleTransaction
).
Description:
I am trying to test the case when a bot is created. The function is supposed to return a Finding object if a bot is created, but it is returning an empty array instead.
Here is the code for the test:
I am expecting the test to pass, but it is failing with the error message:
It seems that
handleTransaction()
function is not correctly handling the returned value frommockTxEvent.filterFunction
.I would appreciate any help in resolving this issue. Please let me know if you need any more information or context.
Steps to Reproduce:
Expected outcome:
Actual outcome: