openzeppelin-test-helpers
openzeppelin-test-helpers copied to clipboard
txCost/Fee Helper?
Hey.
A pattern I've often had to do was to either estimate the tx cost (gas * gasPrice) in wei beforehand OR after a transaction take gasUsed * gasPrice to calculate how much wei was spent in the transaction. This is used in transactions, for example, where someone withdraws ETH, to see if the balance AFTER withdrawal is correct [withdrawn ETH - tx fee to withdraw ETH].
Is this something that would be meaningful? Are there others who want a similar helper? If so, I might take a stab at it, but first want to gauge interest.
Something like:
estimatedTxCost(<contract method>, <tx data>)
or
txCost(<txReceipt>, <gasPrice>)
Unsure if this would be meaningful (or something like it). So want to hear from others.
This may be very useful, yes! A trick we sometimes do when calculating how a transaction affected balance, without taking into account gas, is to set gasPrice: 0
for that tx (which works fine on ganache). I can see however other scenarios where such a helper could be used.
I agree this would be very useful. I'm not sure what a nice API for it would look like. I wonder if we can do something similar to balance.tracker
?
A trick we sometimes do when calculating how a transaction affected balance, without taking into account gas, is to set gasPrice: 0 for that tx (which works fine on ganache).
Ah yes! Really simple trick to avoid this problem. :)