Skip to content

Commit

Permalink
Update to contracts branch, CDT 1.6, and EOS 1.7
Browse files Browse the repository at this point in the history
  • Loading branch information
tbfleming committed Mar 25, 2019
1 parent f5c5b39 commit dd4a81f
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 153 deletions.
7 changes: 2 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
cmake_minimum_required(VERSION 3.5)
project(eosio.assert VERSION 0.0.0)

set(EOSIO_CDT_VERSION_MIN "1.4")
set(EOSIO_CDT_VERSION_SOFT_MAX "1.4")
set(EOSIO_CDT_VERSION_MIN "1.6")
set(EOSIO_CDT_VERSION_SOFT_MAX "1.6")
#set(EOSIO_CDT_VERSION_HARD_MAX "")

include(CheckVersion.txt)

find_package(eosio.cdt)

### Check the version of eosio.cdt
Expand All @@ -31,7 +29,6 @@ else()
set(TEST_BUILD_TYPE ${CMAKE_BUILD_TYPE})
endif()

include_directories(AFTER ${BOOST_ROOT}/include)
add_subdirectory(eosio.assert)

if (APPLE)
Expand Down
90 changes: 0 additions & 90 deletions CheckVersion.txt

This file was deleted.

6 changes: 5 additions & 1 deletion UnitTestsExternalProject.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ include(ExternalProject)
find_package(Git REQUIRED)
include(GNUInstallDirs)

string(REPLACE ";" "|" TEST_FRAMEWORK_PATH "${CMAKE_FRAMEWORK_PATH}")
string(REPLACE ";" "|" TEST_MODULE_PATH "${CMAKE_MODULE_PATH}")

ExternalProject_Add(
contracts_unit_tests
CMAKE_ARGS -DCMAKE_BUILD_TYPE=${TEST_BUILD_TYPE} -DEOSIO_ROOT=${EOSIO_ROOT} -DEOSIO_DEPENDENCY=${EOSIO_DEPENDENCY}
LIST_SEPARATOR | # Use the alternate list separator
CMAKE_ARGS -DCMAKE_BUILD_TYPE=${TEST_BUILD_TYPE} -DCMAKE_FRAMEWORK_PATH=${TEST_FRAMEWORK_PATH} -DCMAKE_MODULE_PATH=${TEST_MODULE_PATH} -DEOSIO_ROOT=${EOSIO_ROOT} -DLLVM_DIR=${LLVM_DIR}
SOURCE_DIR ${CMAKE_SOURCE_DIR}/tests
BINARY_DIR ${CMAKE_BINARY_DIR}/tests
BUILD_ALWAYS 1
Expand Down
21 changes: 0 additions & 21 deletions eosio.assert/build.sh

This file was deleted.

6 changes: 3 additions & 3 deletions eosio.assert/include/eosio.assert/eosio.assert.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#pragma once

#include <eosiolib/crypto.hpp>
#include <eosiolib/multi_index.hpp>
#include <eosiolib/singleton.hpp>
#include <eosio/crypto.hpp>
#include <eosio/multi_index.hpp>
#include <eosio/singleton.hpp>

namespace assert_contract {

Expand Down
34 changes: 10 additions & 24 deletions eosio.assert/src/eosio.assert.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include <eosio.assert/eosio.assert.hpp>

#include <eosiolib/contract.hpp>
#include <eosiolib/dispatcher.hpp>
#include <eosiolib/ignore.hpp>
#include <eosio/contract.hpp>
#include <eosio/dispatcher.hpp>
#include <eosio/ignore.hpp>

namespace assert_contract {

Expand Down Expand Up @@ -47,14 +47,14 @@ struct[[eosio::contract("eosio.assert")]] asserter : eosio::contract {

require_auth(stored.account);
auto it = manifest_id_idx.find(stored.id_key());
eosio_assert(it == manifest_id_idx.end(), "manifest already present");
check(it == manifest_id_idx.end(), "manifest already present");
manifest_table.emplace(stored.account, [&](auto& x) { x = stored; });
chain_table.set(chain, _self);
};

[[eosio::action("del.manifest")]] void del_manifest(checksum256 id) {
auto it = manifest_id_idx.find(id);
eosio_assert(it != manifest_id_idx.end(), "manifest not found");
check(it != manifest_id_idx.end(), "manifest not found");
require_auth(it->account);
manifest_id_idx.erase(it);
};
Expand All @@ -81,50 +81,36 @@ struct[[eosio::contract("eosio.assert")]] asserter : eosio::contract {
const checksum256& chain_params_hash, const checksum256& manifest_id, const vector<contract_action>& actions,
const vector<checksum256>& abi_hashes) {
if (!(chain_params_hash == chain.hash))
eosio_assert(
check(
false,
("chain hash is " + hash_to_str(chain.hash) + " but user expected " + hash_to_str(chain_params_hash))
.c_str());
auto it = manifest_id_idx.find(manifest_id);
eosio_assert(it != manifest_id_idx.end(), "manifest not found");
check(it != manifest_id_idx.end(), "manifest not found");
std::vector<name> contracts;
for (auto& action : actions) {
auto contract_it = std::lower_bound(contracts.begin(), contracts.end(), action.contract);
if (contract_it == contracts.end() || *contract_it != action.contract)
contracts.insert(contract_it, action.contract);
if (!in(action, it->whitelist))
eosio_assert(
check(
false,
(action.action.to_string() + "@" + action.contract.to_string() + " is not in whitelist").c_str());
}
abi_hash_table table{"eosio"_n, "eosio"_n.value};
eosio_assert(abi_hashes.size() == contracts.size(), "incorrect number of abi hashes");
check(abi_hashes.size() == contracts.size(), "incorrect number of abi hashes");
for (size_t i = 0; i < abi_hashes.size(); ++i) {
auto it = table.find(contracts[i].value);
checksum256 hash{};
if (it != table.end())
hash = it->hash;
if (!(abi_hashes[i] == hash))
eosio_assert(
check(
false, (contracts[i].to_string() + " abi hash is " + hash_to_str(hash) + " but user expected " +
hash_to_str(abi_hashes[i]))
.c_str());
}
}
};

#define CALL(n, m) \
case eosio::name(#n).value: eosio::execute_action(receiver, code, &asserter::m); break;

extern "C" void apply(eosio::name receiver, eosio::name code, eosio::name action) {
if (code != receiver)
return;
switch (action.value) {
CALL(setchain, setchain)
CALL(add.manifest, add_manifest)
CALL(del.manifest, del_manifest)
CALL(require, require)
}
}

} // namespace assert_contract
26 changes: 20 additions & 6 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
cmake_minimum_required( VERSION 3.5 )

set(EOSIO_VERSION_MIN "1.7")
set(EOSIO_VERSION_SOFT_MAX "1.7")
#set(EOSIO_VERSION_HARD_MAX "")

find_package(eosio)

### check the version of EOSIO
string(FIND "${EOSIO_VERSION}" "${EOSIO_DEPENDENCY}" output)
if (NOT "${output}" EQUAL 0)
message(FATAL_ERROR "Incorrect EOSIO version, please use version ${EOSIO_DEPENDENCY}.x")
endif()
### Check the version of eosio
set(VERSION_MATCH_ERROR_MSG "")
EOSIO_CHECK_VERSION(VERSION_OUTPUT "${EOSIO_VERSION}"
"${EOSIO_VERSION_MIN}"
"${EOSIO_VERSION_SOFT_MAX}"
"${EOSIO_VERSION_HARD_MAX}"
VERSION_MATCH_ERROR_MSG)
if(VERSION_OUTPUT STREQUAL "MATCH")
message(STATUS "Using eosio version ${EOSIO_VERSION}")
elseif(VERSION_OUTPUT STREQUAL "WARN")
message(WARNING "Using eosio version ${EOSIO_VERSION} even though it exceeds the maximum supported version of ${EOSIO_VERSION_SOFT_MAX}; continuing with configuration, however build may fail.\nIt is recommended to use eosio version ${EOSIO_VERSION_SOFT_MAX}.x")
else() # INVALID OR MISMATCH
message(FATAL_ERROR "Found eosio version ${EOSIO_VERSION} but it does not satisfy version requirements: ${VERSION_MATCH_ERROR_MSG}\nPlease use eosio version ${EOSIO_VERSION_SOFT_MAX}.x")
endif(VERSION_OUTPUT STREQUAL "MATCH")


enable_testing()

Expand All @@ -18,4 +32,4 @@ file(GLOB UNIT_TESTS "*.cpp" "*.hpp")

add_eosio_test( unit_test ${UNIT_TESTS} )

target_compile_options(unit_test PUBLIC -ftemplate-backtrace-limit=0 -DDATA_DIR="${CMAKE_CURRENT_SOURCE_DIR}/data/")
target_compile_options(unit_test PUBLIC -DASSERT_DATA_DIR="${CMAKE_CURRENT_SOURCE_DIR}/data/")
6 changes: 3 additions & 3 deletions tests/eosio_assert_tests.cpp → tests/eosio.assert_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class assert_tester : public TESTER {
}

assert_tester(const std::string& test_name)
: TESTER(), test_name{test_name}, outfile{DATA_DIR + test_name + ".actual"}, abi{contracts::eosio_assert_abi()},
: TESTER(), test_name{test_name}, outfile{ASSERT_DATA_DIR + test_name + ".actual"}, abi{contracts::eosio_assert_abi()},
abi_ser(json::from_string(std::string{abi.data(), abi.data() + abi.size()}).as<abi_def>(),
abi_serializer_max_time) {

Expand Down Expand Up @@ -142,10 +142,10 @@ class assert_tester : public TESTER {
outfile.close();
if (write_mode)
BOOST_REQUIRE_EQUAL(
0, system(("cp " DATA_DIR + test_name + ".actual " DATA_DIR + test_name + ".expected").c_str()));
0, system(("cp " ASSERT_DATA_DIR + test_name + ".actual " ASSERT_DATA_DIR + test_name + ".expected").c_str()));
else
BOOST_REQUIRE_EQUAL(
0, system(("colordiff " DATA_DIR + test_name + ".expected " DATA_DIR + test_name + ".actual").c_str()));
0, system(("colordiff " ASSERT_DATA_DIR + test_name + ".expected " ASSERT_DATA_DIR + test_name + ".actual").c_str()));
}

std::string test_name;
Expand Down
File renamed without changes.

0 comments on commit dd4a81f

Please sign in to comment.