mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge remote-tracking branch 'upstream/develop' into addTests
This commit is contained in:
commit
a1b2fa345a
@ -4172,6 +4172,43 @@ BOOST_AUTO_TEST_CASE(evm_exceptions_in_constructor_out_of_baund)
|
||||
BOOST_CHECK(compileAndRunWthoutCheck(sourceCode, 0, "A").empty());
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(positive_integers_to_signed)
|
||||
{
|
||||
char const* sourceCode = R"(
|
||||
contract test {
|
||||
int8 public x = 2;
|
||||
int8 public y = 127;
|
||||
int16 public q = 250;
|
||||
}
|
||||
)";
|
||||
compileAndRun(sourceCode, 0, "test");
|
||||
BOOST_CHECK(callContractFunction("x()") == encodeArgs(2));
|
||||
BOOST_CHECK(callContractFunction("y()") == encodeArgs(127));
|
||||
BOOST_CHECK(callContractFunction("q()") == encodeArgs(250));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(failing_send)
|
||||
{
|
||||
char const* sourceCode = R"(
|
||||
contract Helper {
|
||||
uint[] data;
|
||||
function () {
|
||||
data[9]; // trigger exception
|
||||
}
|
||||
}
|
||||
contract Main {
|
||||
function callHelper(address _a) returns (bool r, uint bal) {
|
||||
r = !_a.send(5);
|
||||
bal = this.balance;
|
||||
}
|
||||
}
|
||||
)";
|
||||
compileAndRun(sourceCode, 0, "Helper");
|
||||
u160 const c_helperAddress = m_contractAddress;
|
||||
compileAndRun(sourceCode, 20, "Main");
|
||||
BOOST_REQUIRE(callContractFunction("callHelper(address)", c_helperAddress) == encodeArgs(true, 20));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
}
|
||||
|
@ -1816,6 +1816,100 @@ BOOST_AUTO_TEST_CASE(string_length)
|
||||
BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(negative_integers_to_signed_out_of_bound)
|
||||
{
|
||||
char const* sourceCode = R"(
|
||||
contract test {
|
||||
int8 public i = -129;
|
||||
}
|
||||
)";
|
||||
BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(negative_integers_to_signed_min)
|
||||
{
|
||||
char const* sourceCode = R"(
|
||||
contract test {
|
||||
int8 public i = -128;
|
||||
}
|
||||
)";
|
||||
BOOST_CHECK_NO_THROW(parseTextAndResolveNames(sourceCode));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(positive_integers_to_signed_out_of_bound)
|
||||
{
|
||||
char const* sourceCode = R"(
|
||||
contract test {
|
||||
int8 public j = 128;
|
||||
}
|
||||
)";
|
||||
BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(positive_integers_to_signed_out_of_bound_max)
|
||||
{
|
||||
char const* sourceCode = R"(
|
||||
contract test {
|
||||
int8 public j = 127;
|
||||
}
|
||||
)";
|
||||
BOOST_CHECK_NO_THROW(parseTextAndResolveNames(sourceCode));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(negative_integers_to_unsigned)
|
||||
{
|
||||
char const* sourceCode = R"(
|
||||
contract test {
|
||||
uint8 public x = -1;
|
||||
}
|
||||
)";
|
||||
BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(positive_integers_to_unsigned_out_of_bound)
|
||||
{
|
||||
char const* sourceCode = R"(
|
||||
contract test {
|
||||
uint8 public x = 700;
|
||||
}
|
||||
)";
|
||||
BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(overwrite_memory_location_external)
|
||||
{
|
||||
char const* sourceCode = R"(
|
||||
contract C {
|
||||
function f(uint[] memory a) external {}
|
||||
}
|
||||
)";
|
||||
BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(overwrite_storage_location_external)
|
||||
{
|
||||
char const* sourceCode = R"(
|
||||
contract C {
|
||||
function f(uint[] storage a) external {}
|
||||
}
|
||||
)";
|
||||
BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(storage_location_local_variables)
|
||||
{
|
||||
char const* sourceCode = R"(
|
||||
contract C {
|
||||
function f() {
|
||||
uint[] storage x;
|
||||
uint[] memory y;
|
||||
uint[] memory z;
|
||||
}
|
||||
}
|
||||
)";
|
||||
BOOST_CHECK_NO_THROW(parseTextAndResolveNames(sourceCode));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
}
|
||||
|
@ -1036,6 +1036,51 @@ BOOST_AUTO_TEST_CASE(block_deduplicator_loops)
|
||||
BOOST_CHECK_EQUAL(pushTags.size(), 1);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(computing_constants)
|
||||
{
|
||||
char const* sourceCode = R"(
|
||||
contract c {
|
||||
uint a;
|
||||
uint b;
|
||||
uint c;
|
||||
function set() returns (uint a, uint b, uint c) {
|
||||
a = 0x77abc0000000000000000000000000000000000000000000000000000000001;
|
||||
b = 0x817416927846239487123469187231298734162934871263941234127518276;
|
||||
g();
|
||||
}
|
||||
function g() {
|
||||
b = 0x817416927846239487123469187231298734162934871263941234127518276;
|
||||
c = 0x817416927846239487123469187231298734162934871263941234127518276;
|
||||
}
|
||||
function get() returns (uint ra, uint rb, uint rc) {
|
||||
ra = a;
|
||||
rb = b;
|
||||
rc = c ;
|
||||
}
|
||||
}
|
||||
)";
|
||||
compileBothVersions(sourceCode);
|
||||
compareVersions("set()");
|
||||
compareVersions("get()");
|
||||
|
||||
m_optimize = true;
|
||||
m_optimizeRuns = 1;
|
||||
bytes optimizedBytecode = compileAndRun(sourceCode, 0, "c");
|
||||
bytes complicatedConstant = toBigEndian(u256("0x817416927846239487123469187231298734162934871263941234127518276"));
|
||||
unsigned occurrences = 0;
|
||||
for (auto iter = optimizedBytecode.cbegin(); iter < optimizedBytecode.cend(); ++occurrences)
|
||||
iter = search(iter, optimizedBytecode.cend(), complicatedConstant.cbegin(), complicatedConstant.cend()) + 1;
|
||||
BOOST_CHECK_EQUAL(2, occurrences);
|
||||
|
||||
bytes constantWithZeros = toBigEndian(u256("0x77abc0000000000000000000000000000000000000000000000000000000001"));
|
||||
BOOST_CHECK(search(
|
||||
optimizedBytecode.cbegin(),
|
||||
optimizedBytecode.cend(),
|
||||
constantWithZeros.cbegin(),
|
||||
constantWithZeros.cend()
|
||||
) == optimizedBytecode.cend());
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
}
|
||||
|
@ -873,6 +873,47 @@ BOOST_AUTO_TEST_CASE(var_array)
|
||||
BOOST_CHECK_THROW(parseText(text), ParserError);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(location_specifiers_for_params)
|
||||
{
|
||||
char const* text = R"(
|
||||
contract Foo {
|
||||
function f(uint[] storage constant x, uint[] memory y) { }
|
||||
}
|
||||
)";
|
||||
BOOST_CHECK_NO_THROW(parseText(text));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(location_specifiers_for_locals)
|
||||
{
|
||||
char const* text = R"(
|
||||
contract Foo {
|
||||
function f() {
|
||||
uint[] storage x;
|
||||
uint[] memory y;
|
||||
}
|
||||
}
|
||||
)";
|
||||
BOOST_CHECK_NO_THROW(parseText(text));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(location_specifiers_for_state)
|
||||
{
|
||||
char const* text = R"(
|
||||
contract Foo {
|
||||
uint[] memory x;
|
||||
})";
|
||||
BOOST_CHECK_THROW(parseText(text), ParserError);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(location_specifiers_with_var)
|
||||
{
|
||||
char const* text = R"(
|
||||
contract Foo {
|
||||
function f() { var memory x; }
|
||||
})";
|
||||
BOOST_CHECK_THROW(parseText(text), ParserError);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
}
|
||||
|
@ -77,13 +77,13 @@ BOOST_AUTO_TEST_CASE(storage_layout_mapping)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(storage_layout_arrays)
|
||||
{
|
||||
BOOST_CHECK(ArrayType(ArrayType::Location::Storage, make_shared<FixedBytesType>(1), 32).getStorageSize() == 1);
|
||||
BOOST_CHECK(ArrayType(ArrayType::Location::Storage, make_shared<FixedBytesType>(1), 33).getStorageSize() == 2);
|
||||
BOOST_CHECK(ArrayType(ArrayType::Location::Storage, make_shared<FixedBytesType>(2), 31).getStorageSize() == 2);
|
||||
BOOST_CHECK(ArrayType(ArrayType::Location::Storage, make_shared<FixedBytesType>(7), 8).getStorageSize() == 2);
|
||||
BOOST_CHECK(ArrayType(ArrayType::Location::Storage, make_shared<FixedBytesType>(7), 9).getStorageSize() == 3);
|
||||
BOOST_CHECK(ArrayType(ArrayType::Location::Storage, make_shared<FixedBytesType>(31), 9).getStorageSize() == 9);
|
||||
BOOST_CHECK(ArrayType(ArrayType::Location::Storage, make_shared<FixedBytesType>(32), 9).getStorageSize() == 9);
|
||||
BOOST_CHECK(ArrayType(ReferenceType::Location::Storage, make_shared<FixedBytesType>(1), 32).getStorageSize() == 1);
|
||||
BOOST_CHECK(ArrayType(ReferenceType::Location::Storage, make_shared<FixedBytesType>(1), 33).getStorageSize() == 2);
|
||||
BOOST_CHECK(ArrayType(ReferenceType::Location::Storage, make_shared<FixedBytesType>(2), 31).getStorageSize() == 2);
|
||||
BOOST_CHECK(ArrayType(ReferenceType::Location::Storage, make_shared<FixedBytesType>(7), 8).getStorageSize() == 2);
|
||||
BOOST_CHECK(ArrayType(ReferenceType::Location::Storage, make_shared<FixedBytesType>(7), 9).getStorageSize() == 3);
|
||||
BOOST_CHECK(ArrayType(ReferenceType::Location::Storage, make_shared<FixedBytesType>(31), 9).getStorageSize() == 9);
|
||||
BOOST_CHECK(ArrayType(ReferenceType::Location::Storage, make_shared<FixedBytesType>(32), 9).getStorageSize() == 9);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
@ -46,7 +46,7 @@ public:
|
||||
{
|
||||
m_compiler.reset(false, m_addStandardSources);
|
||||
m_compiler.addSource("", _sourceCode);
|
||||
ETH_TEST_REQUIRE_NO_THROW(m_compiler.compile(m_optimize), "Compiling contract failed");
|
||||
ETH_TEST_REQUIRE_NO_THROW(m_compiler.compile(m_optimize, m_optimizeRuns), "Compiling contract failed");
|
||||
bytes code = m_compiler.getBytecode(_contractName);
|
||||
sendMessage(code, true, _value);
|
||||
return m_output;
|
||||
@ -180,6 +180,7 @@ protected:
|
||||
m_logs = executive.logs();
|
||||
}
|
||||
|
||||
size_t m_optimizeRuns = 200;
|
||||
bool m_optimize = false;
|
||||
bool m_addStandardSources = false;
|
||||
dev::solidity::CompilerStack m_compiler;
|
||||
|
Loading…
Reference in New Issue
Block a user