From 935f4a40c4cc27afb4ac0d27864882c214f540f1 Mon Sep 17 00:00:00 2001 From: Dmytro Sydorchenko Date: Mon, 30 Aug 2021 20:44:02 -0400 Subject: [PATCH] bugfix for ricardian contracts being generated --- .../abigen-pass/ricardian_contract_test.abi | 29 +++++++++++++++++++ .../ricardian_contract_test.clauses.md | 3 ++ .../ricardian_contract_test.contracts.md | 9 ++++++ .../abigen-pass/ricardian_contract_test.cpp | 12 ++++++++ .../abigen-pass/ricardian_contract_test.json | 10 +++++++ tools/include/eosio/abigen.hpp | 8 ++--- tools/toolchain-tester/tests.py | 1 + 7 files changed, 68 insertions(+), 4 deletions(-) create mode 100644 tests/toolchain/abigen-pass/ricardian_contract_test.abi create mode 100644 tests/toolchain/abigen-pass/ricardian_contract_test.clauses.md create mode 100644 tests/toolchain/abigen-pass/ricardian_contract_test.contracts.md create mode 100644 tests/toolchain/abigen-pass/ricardian_contract_test.cpp create mode 100644 tests/toolchain/abigen-pass/ricardian_contract_test.json diff --git a/tests/toolchain/abigen-pass/ricardian_contract_test.abi b/tests/toolchain/abigen-pass/ricardian_contract_test.abi new file mode 100644 index 000000000..89e6e22ef --- /dev/null +++ b/tests/toolchain/abigen-pass/ricardian_contract_test.abi @@ -0,0 +1,29 @@ +{ + "____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": [], + "kv_tables": {}, + "ricardian_clauses": [ + { + "id": "Disclaimer", + "body": "This test checks ricardian contract was generated succesfully." + } + ], + "variants": [], + "action_results": [] +} \ No newline at end of file diff --git a/tests/toolchain/abigen-pass/ricardian_contract_test.clauses.md b/tests/toolchain/abigen-pass/ricardian_contract_test.clauses.md new file mode 100644 index 000000000..53993020d --- /dev/null +++ b/tests/toolchain/abigen-pass/ricardian_contract_test.clauses.md @@ -0,0 +1,3 @@ +

Disclaimer

+ +This test checks ricardian contract was generated succesfully. \ No newline at end of file diff --git a/tests/toolchain/abigen-pass/ricardian_contract_test.contracts.md b/tests/toolchain/abigen-pass/ricardian_contract_test.contracts.md new file mode 100644 index 000000000..16f96295f --- /dev/null +++ b/tests/toolchain/abigen-pass/ricardian_contract_test.contracts.md @@ -0,0 +1,9 @@ +

test

+--- +spec-version: 0.0.2 +title: test +summary: This method does nothing on purpose. +icon: +--- + +This test checks ricardian contract was generated succesfully. \ No newline at end of file diff --git a/tests/toolchain/abigen-pass/ricardian_contract_test.cpp b/tests/toolchain/abigen-pass/ricardian_contract_test.cpp new file mode 100644 index 000000000..e4393a354 --- /dev/null +++ b/tests/toolchain/abigen-pass/ricardian_contract_test.cpp @@ -0,0 +1,12 @@ +#include + +using namespace eosio; + +class [[eosio::contract]] ricardian_contract_test : public contract { + public: + using contract::contract; + + [[eosio::action]] + void test() { + } +}; \ No newline at end of file diff --git a/tests/toolchain/abigen-pass/ricardian_contract_test.json b/tests/toolchain/abigen-pass/ricardian_contract_test.json new file mode 100644 index 000000000..8e46bd465 --- /dev/null +++ b/tests/toolchain/abigen-pass/ricardian_contract_test.json @@ -0,0 +1,10 @@ +{ + "tests" : [ + { + "compile_flags" : ["-R={cwd}"], + "expected" : { + "abi-file" : "ricardian_contract_test.abi" + } + } + ] +} diff --git a/tools/include/eosio/abigen.hpp b/tools/include/eosio/abigen.hpp index d671c8af9..6ab3a16a7 100644 --- a/tools/include/eosio/abigen.hpp +++ b/tools/include/eosio/abigen.hpp @@ -737,8 +737,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; } @@ -753,8 +753,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())) { diff --git a/tools/toolchain-tester/tests.py b/tools/toolchain-tester/tests.py index 486674258..d92f04606 100644 --- a/tools/toolchain-tester/tests.py +++ b/tools/toolchain-tester/tests.py @@ -44,6 +44,7 @@ def _run(self, eosio_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] eosio_cpp = os.path.join(self.test_suite.cdt_path, "eosio-cpp") self._run(eosio_cpp, args)