Closed hal0x2328 closed 5 years ago
I have not looked at what getapplicationlog
does, but notification events that triggered before the contract faulted
can be logged/displayed with neo-python via config sc-debug-notify
. Does that help?
sc-debug-notify - toggle printing smart contract Notify events on execution failure
notification events that triggered before the contract faulted
can be logged/displayed with neo-python viaconfig sc-debug-notify
. Does that help?
Yes, that could eliminate the need for the extra print statement.
One other issue I am having with my bespoke assert
implementation is that it appears to be impossible to have a void return type for a function. So unless I use something like
ret = sc_assert(something_is_true(), "Not true!")
I end up with an extra value on the evaluation stack at the end of execution, which is undesirable. But adding the unused variable assignment is also kind of inelegant.
I think I found the solution and it doesn't require any changes to neo-boa, just a little knowledge of Python internals:
OnError = RegisterAction('error', 'message')
def Main(operation, args):
assert args[0] == True, 'Got false argument!'
return True
def AssertionError(msg):
OnError(msg)
throw_if_null(0)
It would be neat if we could replace something like:
with:
I'm moving to just implement this in the following way in my smart contracts:
but it would be cool if it were just natively supported with the existing
assert
keyword in Python.(I noticed that the neo-cli implementation of
getapplicationlog
returns the notification events that triggered before the contract faulted, so thesc_assert
function I wrote takes advantage of that - I see this as being a huge help for people trying to debug contract failures after-the-fact. So if this suggestion were to be implemented as a built-in it would be nice to replicate that feature too.)