Skip to content
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

Bugfix for ricardian contracts being generated #6

Merged
merged 2 commits into from
Aug 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions tests/toolchain/abigen-pass/ricardian_contract_test.abi
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"____comment": "This file was generated with eosio-abigen. DO NOT EDIT ",
"version": "eosio::abi/1.2",
"types": [],
"structs": [
{
"name": "test",
"base": "",
"fields": []
}
],
"actions": [
{
"name": "test",
"type": "test",
"ricardian_contract": "---\nspec-version: 0.0.2\ntitle: test\nsummary: This method does nothing on purpose.\nicon:\n---\n\nThis test checks ricardian contract was generated succesfully."
}
],
"tables": [],
"ricardian_clauses": [
{
"id": "Disclaimer",
"body": "This test checks ricardian contract was generated succesfully."
}
],
"variants": [],
"action_results": []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<h1 class="clause">Disclaimer</h1>

This test checks ricardian contract was generated succesfully.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<h1 class="contract">test</h1>
---
spec-version: 0.0.2
title: test
summary: This method does nothing on purpose.
icon:
---

This test checks ricardian contract was generated succesfully.
12 changes: 12 additions & 0 deletions tests/toolchain/abigen-pass/ricardian_contract_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <eosio/eosio.hpp>

using namespace eosio;

class [[eosio::contract]] ricardian_contract_test : public contract {
public:
using contract::contract;

[[eosio::action]]
void test() {
}
};
10 changes: 10 additions & 0 deletions tests/toolchain/abigen-pass/ricardian_contract_test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"tests" : [
{
"compile_flags" : ["-R={cwd}"],
"expected" : {
"abi-file" : "ricardian_contract_test.abi"
}
}
]
}
8 changes: 4 additions & 4 deletions tools/include/eosio/abigen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -768,8 +768,8 @@ namespace eosio { namespace cdt {

virtual bool VisitCXXMethodDecl(clang::CXXMethodDecl* decl) {
if (!has_added_clauses) {
ag.add_clauses(parse_clauses());
ag.add_contracts(parse_contracts());
ag.add_clauses(ag.parse_clauses());
ag.add_contracts(ag.parse_contracts());
has_added_clauses = true;
}

Expand All @@ -784,8 +784,8 @@ namespace eosio { namespace cdt {
}
virtual bool VisitCXXRecordDecl(clang::CXXRecordDecl* decl) {
if (!has_added_clauses) {
ag.add_clauses(parse_clauses());
ag.add_contracts(parse_contracts());
ag.add_clauses(ag.parse_clauses());
ag.add_contracts(ag.parse_contracts());
has_added_clauses = true;
}
if ((decl->isEosioAction() || decl->isEosioTable()) && ag.is_eosio_contract(decl, ag.get_contract_name())) {
Expand Down
3 changes: 2 additions & 1 deletion tools/toolchain-tester/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def _run(self, cdt_cpp: str, args: List[str]):
def run(self):
cf = self.test_json.get("compile_flags")
args = cf if cf else []
args = [arg.replace("{cwd}", self.test_suite.directory) for arg in args]

cdt_cpp = os.path.join(self.test_suite.cdt_path, "cdt-cpp")
self._run(cdt_cpp, args)
Expand Down Expand Up @@ -202,5 +203,5 @@ def _run(self, cdt_cpp, args):
command.extend(args)
res = subprocess.run(command, capture_output=True)
self.handle_test_result(res, expected_pass=False)

return res