提交 c64b137c 编写于 作者: A arhag

Merge branch 'slim' into slim-resource-limits-fix2

......@@ -5,7 +5,6 @@
#include <eosio/chain/account_object.hpp>
#include <eosio/chain/abi_serializer.hpp>
#include <fc/io/json.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/test/unit_test.hpp>
#include <iosfwd>
......@@ -181,15 +180,15 @@ namespace eosio { namespace testing {
static action_result error(const string& msg) { return msg; }
auto get_resolver() {
return [this](const account_name &name) -> optional<abi_serializer> {
return [this]( const account_name& name ) -> optional<abi_serializer> {
try {
const auto &accnt = control->db().get<account_object, by_name>(name);
const auto& accnt = control->db().get<account_object, by_name>( name );
abi_def abi;
if (abi_serializer::to_abi(accnt.abi, abi)) {
return abi_serializer(abi);
if( abi_serializer::to_abi( accnt.abi, abi )) {
return abi_serializer( abi );
}
return optional<abi_serializer>();
} FC_RETHROW_EXCEPTIONS(error, "Failed to find or parse ABI for ${name}", ("name", name))
} FC_RETHROW_EXCEPTIONS( error, "Failed to find or parse ABI for ${name}", ("name", name))
};
}
......@@ -328,14 +327,10 @@ namespace eosio { namespace testing {
* Utility predicate to check whether an FC_ASSERT message ends with a given string
*/
struct assert_message_ends_with {
assert_message_ends_with(string expected)
:expected(expected)
{}
assert_message_ends_with( string expected )
: expected( expected ) {}
bool operator()( const fc::exception& ex ) {
auto message = ex.get_log().at(0).get_message();
return boost::algorithm::ends_with(message, expected);
}
bool operator()( const fc::exception& ex );
string expected;
};
......@@ -344,17 +339,76 @@ namespace eosio { namespace testing {
* Utility predicate to check whether an FC_ASSERT message contains a given string
*/
struct assert_message_contains {
assert_message_contains(string expected)
:expected(expected)
{}
assert_message_contains( string expected )
: expected( expected ) {}
bool operator()( const fc::exception& ex ) {
auto message = ex.get_log().at(0).get_message();
return boost::algorithm::contains(message, expected);
}
bool operator()( const fc::exception& ex );
string expected;
};
/**
* Utility predicate to check whether an fc::exception message starts with a given string
*/
struct fc_exception_message_starts_with {
fc_exception_message_starts_with( const string& msg )
: expected( msg ) {}
bool operator()( const fc::exception& ex );
string expected;
};
/**
* Utility predicate to check whether an fc::assert_exception message is equivalent to a given string
*/
struct fc_assert_exception_message_is {
fc_assert_exception_message_is( const string& msg )
: expected( msg ) {}
bool operator()( const fc::assert_exception& ex );
string expected;
};
/**
* Utility predicate to check whether an fc::assert_exception message starts with a given string
*/
struct fc_assert_exception_message_starts_with {
fc_assert_exception_message_starts_with( const string& msg )
: expected( msg ) {}
bool operator()( const fc::assert_exception& ex );
string expected;
};
/**
* Utility predicate to check whether an eosio_assert message is equivalent to a given string
*/
struct eosio_assert_message_is {
eosio_assert_message_is( const string& msg )
: expected( "assertion failed: " ) {
expected.append( msg );
}
bool operator()( const fc::assert_exception& ex );
string expected;
};
/**
* Utility predicate to check whether an eosio_assert message starts with a given string
*/
struct eosio_assert_message_starts_with {
eosio_assert_message_starts_with( const string& msg )
: expected( "assertion failed: " ) {
expected.append( msg );
}
bool operator()( const fc::assert_exception& ex );
string expected;
};
} } /// eosio::testing
#include <boost/test/unit_test.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <eosio/testing/tester.hpp>
#include <eosio/chain/wast_to_wasm.hpp>
#include <eosio/chain/eosio_contract.hpp>
......@@ -677,6 +678,81 @@ namespace eosio { namespace testing {
return tid;
}
bool assert_message_ends_with::operator()( const fc::exception& ex ) {
auto message = ex.get_log().at( 0 ).get_message();
return boost::algorithm::ends_with( message, expected );
}
bool assert_message_contains::operator()( const fc::exception& ex ) {
auto message = ex.get_log().at( 0 ).get_message();
return boost::algorithm::contains( message, expected );
}
bool fc_exception_message_starts_with::operator()( const fc::exception& ex ) {
auto message = ex.get_log().at( 0 ).get_message();
bool match = boost::algorithm::starts_with( message, expected );
if( !match ) {
BOOST_TEST_MESSAGE( "LOG: expected: " << expected << ", actual: " << message );
}
return match;
}
bool fc_assert_exception_message_is::operator()( const fc::assert_exception& ex ) {
auto message = ex.get_log().at( 0 ).get_message();
bool match = false;
auto pos = message.find( ": " );
if( pos != std::string::npos ) {
message = message.substr( pos + 2 );
match = (message == expected);
}
if( !match ) {
BOOST_TEST_MESSAGE( "LOG: expected: " << expected << ", actual: " << message );
}
return match;
}
bool fc_assert_exception_message_starts_with::operator()( const fc::assert_exception& ex ) {
auto message = ex.get_log().at( 0 ).get_message();
bool match = false;
auto pos = message.find( ": " );
if( pos != std::string::npos ) {
message = message.substr( pos + 2 );
match = boost::algorithm::starts_with( message, expected );
}
if( !match ) {
BOOST_TEST_MESSAGE( "LOG: expected: " << expected << ", actual: " << message );
}
return match;
}
bool eosio_assert_message_is::operator()( const fc::assert_exception& ex ) {
auto message = ex.get_log().at( 0 ).get_message();
bool match = false;
auto pos = message.find( ": " );
if( pos != std::string::npos ) {
message = message.substr( pos + 2 );
match = (message == expected);
}
if( !match ) {
BOOST_TEST_MESSAGE( "LOG: expected: " << expected << ", actual: " << message );
}
return match;
}
bool eosio_assert_message_starts_with::operator()( const fc::assert_exception& ex ) {
auto message = ex.get_log().at( 0 ).get_message();
bool match = false;
auto pos = message.find( ": " );
if( pos != std::string::npos ) {
message = message.substr( pos + 2 );
match = boost::algorithm::starts_with( message, expected );
}
if( !match ) {
BOOST_TEST_MESSAGE( "LOG: expected: " << expected << ", actual: " << message );
}
return match;
}
} } /// eosio::test
std::ostream& operator<<( std::ostream& osm, const fc::variant& v ) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册