Replies: 2 comments 2 replies
-
I was checking the behavior with an invalid test. It was showing that the state from the current contract is not being reverted on all 3 functions. Check updated test below |
Beta Was this translation helpful? Give feedback.
2 replies
-
We can check the behavior with this test: This is state.var {
v = state.value()
}
function constructor()
v:set(0)
end
local function error_handler(err_msg)
return "error_handler: " .. err_msg
end
function test_pcall()
v:set(111)
contract.event("before pcall")
local success, ret = pcall(do_work, "pcall")
contract.event("after pcall", success, ret)
return v:get()
end
function test_contract_pcall()
v:set(111)
contract.event("before contract.pcall")
local success, ret = contract.pcall(do_work, "contract.pcall")
contract.event("after contract.pcall", success, ret)
return v:get()
end
function test_xpcall()
v:set(111)
contract.event("before xpcall")
local success, ret = xpcall(do_work, error_handler, "xpcall")
contract.event("after xpcall", success, ret)
return v:get()
end
function do_work(caller)
contract.event("inside do_work: before")
v:set(123)
assert(1 == 0, "failed")
contract.event("inside do_work: after")
end
abi.register(test_pcall, test_contract_pcall, test_xpcall) And this is
To run:
Currently the state from the current contract is only being reverted on
This is the behavior that was on the docs, but it can be changed on V4 to make all 3 of them to rollback the contract state |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
This is written in the documentation about
contract.pcall
:The example used there is also not good
I am not sure if there is indeed any difference between
contract.pcall
andpcall
currentlyAnd if it should have any difference
What do you think should be the behavior of the 2 functions above?
(also do not forget that there is a
xpcall
function as well)Beta Was this translation helpful? Give feedback.
All reactions