aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/contracts/LLL_ENS.cpp2
-rw-r--r--test/contracts/LLL_ERC20.cpp2
-rw-r--r--test/fuzzer.cpp1
-rw-r--r--test/libevmasm/Optimiser.cpp4
-rw-r--r--test/liblll/Compiler.cpp17
-rw-r--r--test/liblll/EndToEndTest.cpp276
-rw-r--r--test/liblll/ExecutionFramework.h2
-rw-r--r--test/libsolidity/GasMeter.cpp10
8 files changed, 190 insertions, 124 deletions
diff --git a/test/contracts/LLL_ENS.cpp b/test/contracts/LLL_ENS.cpp
index c5fe8a82..028d58c8 100644
--- a/test/contracts/LLL_ENS.cpp
+++ b/test/contracts/LLL_ENS.cpp
@@ -345,7 +345,7 @@ protected:
if (!s_compiledEns)
{
vector<string> errors;
- s_compiledEns.reset(new bytes(compileLLL(ensCode, dev::test::Options::get().optimize, &errors)));
+ s_compiledEns.reset(new bytes(compileLLL(ensCode, dev::test::Options::get().evmVersion(), dev::test::Options::get().optimize, &errors)));
BOOST_REQUIRE(errors.empty());
}
sendMessage(*s_compiledEns, true);
diff --git a/test/contracts/LLL_ERC20.cpp b/test/contracts/LLL_ERC20.cpp
index 25665d64..60b43e4f 100644
--- a/test/contracts/LLL_ERC20.cpp
+++ b/test/contracts/LLL_ERC20.cpp
@@ -396,7 +396,7 @@ protected:
if (!s_compiledErc20)
{
vector<string> errors;
- s_compiledErc20.reset(new bytes(compileLLL(erc20Code, dev::test::Options::get().optimize, &errors)));
+ s_compiledErc20.reset(new bytes(compileLLL(erc20Code, dev::test::Options::get().evmVersion(), dev::test::Options::get().optimize, &errors)));
BOOST_REQUIRE(errors.empty());
}
sendMessage(*s_compiledErc20, true);
diff --git a/test/fuzzer.cpp b/test/fuzzer.cpp
index 45738baa..71f38b67 100644
--- a/test/fuzzer.cpp
+++ b/test/fuzzer.cpp
@@ -76,6 +76,7 @@ void testConstantOptimizer()
ConstantOptimisationMethod::optimiseConstants(
isCreation,
runs,
+ EVMVersion{},
assembly,
const_cast<AssemblyItems&>(assembly.items())
);
diff --git a/test/libevmasm/Optimiser.cpp b/test/libevmasm/Optimiser.cpp
index 0ab95b08..e6abcb53 100644
--- a/test/libevmasm/Optimiser.cpp
+++ b/test/libevmasm/Optimiser.cpp
@@ -20,6 +20,8 @@
* Tests for the Solidity optimizer.
*/
+#include <test/TestHelper.h>
+
#include <libevmasm/CommonSubexpressionEliminator.h>
#include <libevmasm/PeepholeOptimiser.h>
#include <libevmasm/JumpdestRemover.h>
@@ -916,7 +918,7 @@ BOOST_AUTO_TEST_CASE(jumpdest_removal_subassemblies)
main.append(t1.toSubAssemblyTag(subId));
main.append(u256(8));
- main.optimise(true);
+ main.optimise(true, dev::test::Options::get().evmVersion());
AssemblyItems expectationMain{
AssemblyItem(PushSubSize, 0),
diff --git a/test/liblll/Compiler.cpp b/test/liblll/Compiler.cpp
index ace97e15..6c6eae3f 100644
--- a/test/liblll/Compiler.cpp
+++ b/test/liblll/Compiler.cpp
@@ -20,11 +20,16 @@
* Unit tests for the LLL compiler.
*/
+#include <test/TestHelper.h>
+
+#include <libdevcore/FixedHash.h>
+
+#include <liblll/Compiler.h>
+
+#include <boost/test/unit_test.hpp>
+
#include <string>
#include <memory>
-#include <boost/test/unit_test.hpp>
-#include <liblll/Compiler.h>
-#include <libdevcore/FixedHash.h>
using namespace std;
@@ -41,7 +46,7 @@ namespace
bool successCompile(string const& _sourceCode)
{
vector<string> errors;
- bytes bytecode = eth::compileLLL(_sourceCode, false, &errors);
+ bytes bytecode = eth::compileLLL(_sourceCode, dev::test::Options::get().evmVersion(), false, &errors);
if (!errors.empty())
return false;
if (bytecode.empty())
@@ -353,7 +358,7 @@ BOOST_AUTO_TEST_CASE(valid_opcodes_functional)
for (size_t i = 0; i < opcodes_bytecode.size(); i++) {
vector<string> errors;
- bytes code = eth::compileLLL(opcodes_lll[i], false, &errors);
+ bytes code = eth::compileLLL(opcodes_lll[i], dev::test::Options::get().evmVersion(), false, &errors);
BOOST_REQUIRE_MESSAGE(errors.empty(), opcodes_lll[i]);
@@ -641,7 +646,7 @@ BOOST_AUTO_TEST_CASE(valid_opcodes_asm)
for (size_t i = 0; i < opcodes_bytecode.size(); i++) {
vector<string> errors;
- bytes code = eth::compileLLL(opcodes_lll[i], false, &errors);
+ bytes code = eth::compileLLL(opcodes_lll[i], dev::test::Options::get().evmVersion(), false, &errors);
BOOST_REQUIRE_MESSAGE(errors.empty(), opcodes_lll[i]);
diff --git a/test/liblll/EndToEndTest.cpp b/test/liblll/EndToEndTest.cpp
index 1a5bb490..e5e70cf8 100644
--- a/test/liblll/EndToEndTest.cpp
+++ b/test/liblll/EndToEndTest.cpp
@@ -20,10 +20,13 @@
* End to end tests for LLL.
*/
+#include <test/liblll/ExecutionFramework.h>
+#include <test/TestHelper.h>
+
+#include <boost/test/unit_test.hpp>
+
#include <string>
#include <memory>
-#include <boost/test/unit_test.hpp>
-#include <test/liblll/ExecutionFramework.h>
using namespace std;
@@ -583,24 +586,34 @@ BOOST_AUTO_TEST_CASE(allgas)
BOOST_AUTO_TEST_CASE(send_two_args)
{
- char const* sourceCode = R"(
- (returnlll
- (send 0xdead 42))
- )";
- compileAndRun(sourceCode);
- callFallbackWithValue(42);
- BOOST_CHECK(balanceAt(Address(0xdead)) == 42);
+ // "send" does not retain enough gas to be able to pay for account creation.
+ // Disabling for non-tangerineWhistle VMs.
+ if (dev::test::Options::get().evmVersion().canOverchargeGasForCall())
+ {
+ char const* sourceCode = R"(
+ (returnlll
+ (send 0xdead 42))
+ )";
+ compileAndRun(sourceCode);
+ callFallbackWithValue(42);
+ BOOST_CHECK(balanceAt(Address(0xdead)) == 42);
+ }
}
BOOST_AUTO_TEST_CASE(send_three_args)
{
- char const* sourceCode = R"(
- (returnlll
- (send allgas 0xdead 42))
- )";
- compileAndRun(sourceCode);
- callFallbackWithValue(42);
- BOOST_CHECK(balanceAt(Address(0xdead)) == 42);
+ // "send" does not retain enough gas to be able to pay for account creation.
+ // Disabling for non-tangerineWhistle VMs.
+ if (dev::test::Options::get().evmVersion().canOverchargeGasForCall())
+ {
+ char const* sourceCode = R"(
+ (returnlll
+ (send allgas 0xdead 42))
+ )";
+ compileAndRun(sourceCode);
+ callFallbackWithValue(42);
+ BOOST_CHECK(balanceAt(Address(0xdead)) == 42);
+ }
}
// Regression test for edge case that previously failed
@@ -708,56 +721,76 @@ BOOST_AUTO_TEST_CASE(msg_four_args)
BOOST_AUTO_TEST_CASE(msg_three_args)
{
- char const* sourceCode = R"(
- (returnlll
- (seq
- (when (= 0 (calldatasize))
- (return (msg (address) 42 0xff)))
- (return (callvalue))))
- )";
- compileAndRun(sourceCode);
- BOOST_CHECK(callFallbackWithValue(42) == encodeArgs(u256(42)));
+ // "msg" does not retain enough gas.
+ // Disabling for non-tangerineWhistle VMs.
+ if (dev::test::Options::get().evmVersion().canOverchargeGasForCall())
+ {
+ char const* sourceCode = R"(
+ (returnlll
+ (seq
+ (when (= 0 (calldatasize))
+ (return (msg (address) 42 0xff)))
+ (return (callvalue))))
+ )";
+ compileAndRun(sourceCode);
+ BOOST_CHECK(callFallbackWithValue(42) == encodeArgs(u256(42)));
+ }
}
BOOST_AUTO_TEST_CASE(msg_two_args)
{
- char const* sourceCode = R"(
- (returnlll
- (seq
- (when (= 0 (calldatasize))
- (return (msg (address) 0xff)))
- (return 42)))
- )";
- compileAndRun(sourceCode);
- BOOST_CHECK(callFallback() == encodeArgs(u256(42)));
+ // "msg" does not retain enough gas.
+ // Disabling for non-tangerineWhistle VMs.
+ if (dev::test::Options::get().evmVersion().canOverchargeGasForCall())
+ {
+ char const* sourceCode = R"(
+ (returnlll
+ (seq
+ (when (= 0 (calldatasize))
+ (return (msg (address) 0xff)))
+ (return 42)))
+ )";
+ compileAndRun(sourceCode);
+ BOOST_CHECK(callFallback() == encodeArgs(u256(42)));
+ }
}
BOOST_AUTO_TEST_CASE(create_one_arg)
{
- char const* sourceCode = R"(
- (returnlll
- (seq
- (call allgas
- (create (returnlll (return 42)))
- 0 0 0 0x00 0x20)
- (return 0x00 0x20)))
- )";
- compileAndRun(sourceCode);
- BOOST_CHECK(callFallback() == encodeArgs(u256(42)));
+ // "call" does not retain enough gas.
+ // Disabling for non-tangerineWhistle VMs.
+ if (dev::test::Options::get().evmVersion().canOverchargeGasForCall())
+ {
+ char const* sourceCode = R"(
+ (returnlll
+ (seq
+ (call allgas
+ (create (returnlll (return 42)))
+ 0 0 0 0x00 0x20)
+ (return 0x00 0x20)))
+ )";
+ compileAndRun(sourceCode);
+ BOOST_CHECK(callFallback() == encodeArgs(u256(42)));
+ }
}
BOOST_AUTO_TEST_CASE(create_two_args)
{
- char const* sourceCode = R"(
- (returnlll
- (seq
- (call allgas
- (create 42 (returnlll (return (balance (address)))))
- 0 0 0 0x00 0x20)
- (return 0x00 0x20)))
- )";
- compileAndRun(sourceCode);
- BOOST_CHECK(callFallbackWithValue(42) == encodeArgs(u256(42)));
+ // "call" does not retain enough gas.
+ // Disabling for non-tangerineWhistle VMs.
+ if (dev::test::Options::get().evmVersion().canOverchargeGasForCall())
+ {
+ char const* sourceCode = R"(
+ (returnlll
+ (seq
+ (call allgas
+ (create 42 (returnlll (return (balance (address)))))
+ 0 0 0 0x00 0x20)
+ (return 0x00 0x20)))
+ )";
+ compileAndRun(sourceCode);
+ BOOST_CHECK(callFallbackWithValue(42) == encodeArgs(u256(42)));
+ }
}
BOOST_AUTO_TEST_CASE(sha3_two_args)
@@ -822,77 +855,102 @@ BOOST_AUTO_TEST_CASE(makeperm) // Covers makeperm (implicit), permcount and perm
BOOST_AUTO_TEST_CASE(ecrecover)
{
- char const* sourceCode = R"(
- (returnlll
- (return
- (ecrecover
- ; Hash of 'hello world'
- 0x47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad
- ; v = 1 + 27
- 0x1c
- ; r
- 0xdebaaa0cddb321b2dcaaf846d39605de7b97e77ba6106587855b9106cb104215
- ; s
- 0x61a22d94fa8b8a687ff9c911c844d1c016d1a685a9166858f9c7c1bc85128aca)))
- )";
- compileAndRun(sourceCode);
- BOOST_CHECK(callFallback() == encodeArgs(fromHex("0x8743523d96a1b2cbe0c6909653a56da18ed484af")));
+ // "ecrecover" does not retain enough gas.
+ // Disabling for non-tangerineWhistle VMs.
+ if (dev::test::Options::get().evmVersion().canOverchargeGasForCall())
+ {
+ char const* sourceCode = R"(
+ (returnlll
+ (return
+ (ecrecover
+ ; Hash of 'hello world'
+ 0x47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad
+ ; v = 1 + 27
+ 0x1c
+ ; r
+ 0xdebaaa0cddb321b2dcaaf846d39605de7b97e77ba6106587855b9106cb104215
+ ; s
+ 0x61a22d94fa8b8a687ff9c911c844d1c016d1a685a9166858f9c7c1bc85128aca)))
+ )";
+ compileAndRun(sourceCode);
+ BOOST_CHECK(callFallback() == encodeArgs(fromHex("0x8743523d96a1b2cbe0c6909653a56da18ed484af")));
+ }
}
BOOST_AUTO_TEST_CASE(sha256_two_args)
{
- char const* sourceCode = R"(
- (returnlll
- (seq
- (lit 0x20 "abcdefghijklmnopqrstuvwxyzABCDEF")
- (lit 0x40 "GHIJKLMNOPQRSTUVWXYZ0123456789?!")
- (sha256 0x20 0x40)
- (return 0x00 0x20)))
- )";
- compileAndRun(sourceCode);
- BOOST_CHECK(callFallback() == encodeArgs(
- fromHex("0xcf25a9fe3d86ae228c226c81d2d8c64c687cd6dc4586d10d8e7e4e5b6706d429")));
+ // "sha256" does not retain enough gas.
+ // Disabling for non-tangerineWhistle VMs.
+ if (dev::test::Options::get().evmVersion().canOverchargeGasForCall())
+ {
+ char const* sourceCode = R"(
+ (returnlll
+ (seq
+ (lit 0x20 "abcdefghijklmnopqrstuvwxyzABCDEF")
+ (lit 0x40 "GHIJKLMNOPQRSTUVWXYZ0123456789?!")
+ (sha256 0x20 0x40)
+ (return 0x00 0x20)))
+ )";
+ compileAndRun(sourceCode);
+ BOOST_CHECK(callFallback() == encodeArgs(
+ fromHex("0xcf25a9fe3d86ae228c226c81d2d8c64c687cd6dc4586d10d8e7e4e5b6706d429")));
+ }
}
BOOST_AUTO_TEST_CASE(ripemd160_two_args)
{
- char const* sourceCode = R"(
- (returnlll
- (seq
- (lit 0x20 "abcdefghijklmnopqrstuvwxyzABCDEF")
- (lit 0x40 "GHIJKLMNOPQRSTUVWXYZ0123456789?!")
- (ripemd160 0x20 0x40)
- (return 0x00 0x20)))
- )";
- compileAndRun(sourceCode);
- BOOST_CHECK(callFallback() == encodeArgs(
- fromHex("0x36c6b90a49e17d4c1e1b0e634ec74124d9b207da")));
+ // "ripemd160" does not retain enough gas.
+ // Disabling for non-tangerineWhistle VMs.
+ if (dev::test::Options::get().evmVersion().canOverchargeGasForCall())
+ {
+ char const* sourceCode = R"(
+ (returnlll
+ (seq
+ (lit 0x20 "abcdefghijklmnopqrstuvwxyzABCDEF")
+ (lit 0x40 "GHIJKLMNOPQRSTUVWXYZ0123456789?!")
+ (ripemd160 0x20 0x40)
+ (return 0x00 0x20)))
+ )";
+ compileAndRun(sourceCode);
+ BOOST_CHECK(callFallback() == encodeArgs(
+ fromHex("0x36c6b90a49e17d4c1e1b0e634ec74124d9b207da")));
+ }
}
BOOST_AUTO_TEST_CASE(sha256_one_arg)
{
- char const* sourceCode = R"(
- (returnlll
- (seq
- (sha256 0x6162636465666768696a6b6c6d6e6f707172737475767778797a414243444546)
- (return 0x00 0x20)))
- )";
- compileAndRun(sourceCode);
- BOOST_CHECK(callFallback() == encodeArgs(
- fromHex("0xcfd2f1fad75a1978da0a444883db7251414b139f31f5a04704c291fdb0e175e6")));
+ // "sha256" does not retain enough gas.
+ // Disabling for non-tangerineWhistle VMs.
+ if (dev::test::Options::get().evmVersion().canOverchargeGasForCall())
+ {
+ char const* sourceCode = R"(
+ (returnlll
+ (seq
+ (sha256 0x6162636465666768696a6b6c6d6e6f707172737475767778797a414243444546)
+ (return 0x00 0x20)))
+ )";
+ compileAndRun(sourceCode);
+ BOOST_CHECK(callFallback() == encodeArgs(
+ fromHex("0xcfd2f1fad75a1978da0a444883db7251414b139f31f5a04704c291fdb0e175e6")));
+ }
}
BOOST_AUTO_TEST_CASE(ripemd160_one_arg)
{
- char const* sourceCode = R"(
- (returnlll
- (seq
- (ripemd160 0x6162636465666768696a6b6c6d6e6f707172737475767778797a414243444546)
- (return 0x00 0x20)))
- )";
- compileAndRun(sourceCode);
- BOOST_CHECK(callFallback() == encodeArgs(
- fromHex("0xac5ab22e07b0fb80c69b6207902f725e2507e546")));
+ // "ripemd160" does not retain enough gas.
+ // Disabling for non-tangerineWhistle VMs.
+ if (dev::test::Options::get().evmVersion().canOverchargeGasForCall())
+ {
+ char const* sourceCode = R"(
+ (returnlll
+ (seq
+ (ripemd160 0x6162636465666768696a6b6c6d6e6f707172737475767778797a414243444546)
+ (return 0x00 0x20)))
+ )";
+ compileAndRun(sourceCode);
+ BOOST_CHECK(callFallback() == encodeArgs(
+ fromHex("0xac5ab22e07b0fb80c69b6207902f725e2507e546")));
+ }
}
BOOST_AUTO_TEST_CASE(wei_szabo_finney_ether)
diff --git a/test/liblll/ExecutionFramework.h b/test/liblll/ExecutionFramework.h
index 58e1f0ad..ae5cd988 100644
--- a/test/liblll/ExecutionFramework.h
+++ b/test/liblll/ExecutionFramework.h
@@ -56,7 +56,7 @@ public:
BOOST_REQUIRE(_libraryAddresses.empty());
std::vector<std::string> errors;
- bytes bytecode = eth::compileLLL(_sourceCode, m_optimize, &errors);
+ bytes bytecode = eth::compileLLL(_sourceCode, dev::test::Options::get().evmVersion(), m_optimize, &errors);
if (!errors.empty())
{
for (auto const& error: errors)
diff --git a/test/libsolidity/GasMeter.cpp b/test/libsolidity/GasMeter.cpp
index 105a0398..fd2017f9 100644
--- a/test/libsolidity/GasMeter.cpp
+++ b/test/libsolidity/GasMeter.cpp
@@ -56,7 +56,7 @@ public:
ASTNode const& sourceUnit = m_compiler.ast("");
BOOST_REQUIRE(items != nullptr);
m_gasCosts = GasEstimator::breakToStatementLevel(
- GasEstimator::structuralEstimation(*items, vector<ASTNode const*>({&sourceUnit})),
+ GasEstimator(dev::test::Options::get().evmVersion()).structuralEstimation(*items, vector<ASTNode const*>({&sourceUnit})),
{&sourceUnit}
);
}
@@ -65,7 +65,7 @@ public:
{
compileAndRun(_sourceCode);
auto state = make_shared<KnownState>();
- PathGasMeter meter(*m_compiler.assemblyItems(m_compiler.lastContractName()));
+ PathGasMeter meter(*m_compiler.assemblyItems(m_compiler.lastContractName()), dev::test::Options::get().evmVersion());
GasMeter::GasConsumption gas = meter.estimateMax(0, state);
u256 bytecodeSize(m_compiler.runtimeObject(m_compiler.lastContractName()).bytecode.size());
// costs for deployment
@@ -74,7 +74,7 @@ public:
gas += gasForTransaction(m_compiler.object(m_compiler.lastContractName()).bytecode, true);
BOOST_REQUIRE(!gas.isInfinite);
- BOOST_CHECK(gas.value == m_gasUsed);
+ BOOST_CHECK_EQUAL(gas.value, m_gasUsed);
}
/// Compares the gas computed by PathGasMeter for the given signature (but unknown arguments)
@@ -91,12 +91,12 @@ public:
gas = max(gas, gasForTransaction(hash.asBytes() + arguments, false));
}
- gas += GasEstimator::functionalEstimation(
+ gas += GasEstimator(dev::test::Options::get().evmVersion()).functionalEstimation(
*m_compiler.runtimeAssemblyItems(m_compiler.lastContractName()),
_sig
);
BOOST_REQUIRE(!gas.isInfinite);
- BOOST_CHECK(gas.value == m_gasUsed);
+ BOOST_CHECK_EQUAL(gas.value, m_gasUsed);
}
static GasMeter::GasConsumption gasForTransaction(bytes const& _data, bool _isCreation)