-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add validation of smart contract calls #802
Add validation of smart contract calls #802
Conversation
17ac581
to
58e6a69
Compare
278b185
to
2ee2886
Compare
test/archethic_web/controllers/api/transaction_controller_test.exs
Outdated
Show resolved
Hide resolved
299c122
to
61b2ced
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's a few comments (some very biased) based only on reading the code. I'm going to need your help for a real word test.
Archethic.simulate_contract_execution!(prev_tx, tx) | ||
|
||
{:error, reason} -> | ||
{false, reason} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It look like this {false, _}
is not handled in the Stream.map
? Did you mean a %{valid: false, ...}
struct?
32ed025
to
cfa4fc6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works great!
Tested with the transaction builder & curl.
I tested 3 scenarios:
valid contract:
[{"address":"00002223BBD4EC3D64AE597696C7D7ADE1CEE65C639D885450AD2D7B75592AC76AFA","valid":true}]
invalid contract:
[{"address":"00002223BBD4EC3D64AE597696C7D7ADE1CEE65C639D885450AD2D7B75592AC76AFA","reason":"invalid_inherit_conditions","valid":false}]
exception throwing contract:
[{"reason":"A contract exited while simulating","valid":false}]
I found an issue with the transaction condition, but this is not the goal of this PR, I'll create an issue for that.
ps: maybe add the address to the exit message for consistency?
We are not going to merge that one yet, we will integrate it as soon as interpreter v1 is merged. We want to check the conditions in the Interpreter.exectute functions directly. Then we can use Interpreter.execute directly in the validate_contract function and in the worker as well. |
6886076
to
48bcf6c
Compare
lib/archethic/contracts.ex
Outdated
incoming_tx, | ||
date | ||
) do | ||
case valid_from_trigger?(trigger_type, incoming_tx, date) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a if
would do the job instead of a case ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you could even use a with
I'm going to do one last thing on this PR:
|
2bde966
to
d47a43c
Compare
4cac2d8
to
bbe896d
Compare
c27deb7
to
d4b9797
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code is nicer ;)
Description
Provide an endpoint to pre-validate smart contract execution
Fixes #57
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
Checklist: