mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge remote-tracking branch 'ethereum/develop' into sol_swapConstants
Conflicts: test/solidityOptimizerTest.cpp
This commit is contained in:
commit
7d8ec26141
@ -32,7 +32,7 @@
|
||||
#include <libdevcore/CommonIO.h>
|
||||
#include <libdevcore/CommonData.h>
|
||||
#include <libevmcore/Instruction.h>
|
||||
#include <libevm/VM.h>
|
||||
#include <libevm/VMFactory.h>
|
||||
#include "vm.h"
|
||||
|
||||
using namespace std;
|
||||
@ -142,14 +142,14 @@ void doMyTests(json_spirit::mValue& v)
|
||||
}
|
||||
|
||||
bytes output;
|
||||
eth::VM vm(fev.gas);
|
||||
auto vm = eth::VMFactory::create(fev.gas);
|
||||
|
||||
u256 gas;
|
||||
bool vmExceptionOccured = false;
|
||||
try
|
||||
{
|
||||
output = vm.go(fev, fev.simpleTrace()).toBytes();
|
||||
gas = vm.gas();
|
||||
output = vm->go(fev, fev.simpleTrace()).toBytes();
|
||||
gas = vm->gas();
|
||||
}
|
||||
catch (eth::VMException const& _e)
|
||||
{
|
||||
|
@ -51,7 +51,7 @@ BOOST_AUTO_TEST_CASE(genesis_tests)
|
||||
|
||||
BOOST_CHECK_EQUAL(BlockChain::genesis().stateRoot, h256(o["genesis_state_root"].get_str()));
|
||||
BOOST_CHECK_EQUAL(toHex(BlockChain::createGenesisBlock()), toHex(fromHex(o["genesis_rlp_hex"].get_str())));
|
||||
BOOST_CHECK_EQUAL(sha3(BlockChain::createGenesisBlock()), h256(o["genesis_hash"].get_str()));
|
||||
BOOST_CHECK_EQUAL(BlockInfo::headerHash(BlockChain::createGenesisBlock()), h256(o["genesis_hash"].get_str()));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
@ -19,7 +19,7 @@
|
||||
* @date 2014
|
||||
*/
|
||||
|
||||
#if ETH_JSONRPC
|
||||
#if ETH_JSONRPC && 0
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
|
@ -363,6 +363,48 @@ BOOST_AUTO_TEST_CASE(small_signed_types)
|
||||
testSolidityAgainstCpp(0, small_signed_types_cpp);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(strings)
|
||||
{
|
||||
char const* sourceCode = "contract test {\n"
|
||||
" function fixed() returns(string32 ret) {\n"
|
||||
" return \"abc\\x00\\xff__\";\n"
|
||||
" }\n"
|
||||
" function pipeThrough(string2 small, bool one) returns(string16 large, bool oneRet) {\n"
|
||||
" oneRet = one;\n"
|
||||
" large = small;\n"
|
||||
" }\n"
|
||||
"}\n";
|
||||
compileAndRun(sourceCode);
|
||||
bytes expectation(32, 0);
|
||||
expectation[0] = byte('a');
|
||||
expectation[1] = byte('b');
|
||||
expectation[2] = byte('c');
|
||||
expectation[3] = byte(0);
|
||||
expectation[4] = byte(0xff);
|
||||
expectation[5] = byte('_');
|
||||
expectation[6] = byte('_');
|
||||
BOOST_CHECK(callContractFunction(0, bytes()) == expectation);
|
||||
expectation = bytes(17, 0);
|
||||
expectation[0] = 0;
|
||||
expectation[1] = 2;
|
||||
expectation[16] = 1;
|
||||
BOOST_CHECK(callContractFunction(1, bytes({0x00, 0x02, 0x01})) == expectation);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(empty_string_on_stack)
|
||||
{
|
||||
char const* sourceCode = "contract test {\n"
|
||||
" function run(string0 empty, uint8 inp) returns(uint16 a, string0 b, string4 c) {\n"
|
||||
" var x = \"abc\";\n"
|
||||
" var y = \"\";\n"
|
||||
" var z = inp;\n"
|
||||
" a = z; b = y; c = x;"
|
||||
" }\n"
|
||||
"}\n";
|
||||
compileAndRun(sourceCode);
|
||||
BOOST_CHECK(callContractFunction(0, bytes({0x02})) == bytes({0x00, 0x02, 'a', 'b', 'c', 0x00}));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(state_smoke_test)
|
||||
{
|
||||
char const* sourceCode = "contract test {\n"
|
||||
@ -941,6 +983,34 @@ BOOST_AUTO_TEST_CASE(inter_contract_calls_with_local_vars)
|
||||
BOOST_REQUIRE(callContractFunction(0, a, b) == toBigEndian(a * b + 9));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(strings_in_calls)
|
||||
{
|
||||
char const* sourceCode = R"(
|
||||
contract Helper {
|
||||
function invoke(string3 x, bool stop) returns (string4 ret) {
|
||||
return x;
|
||||
}
|
||||
}
|
||||
contract Main {
|
||||
Helper h;
|
||||
function callHelper(string2 x, bool stop) returns (string5 ret) {
|
||||
return h.invoke(x, stop);
|
||||
}
|
||||
function getHelper() returns (address addr) {
|
||||
return address(h);
|
||||
}
|
||||
function setHelper(address addr) {
|
||||
h = Helper(addr);
|
||||
}
|
||||
})";
|
||||
compileAndRun(sourceCode, 0, "Helper");
|
||||
u160 const helperAddress = m_contractAddress;
|
||||
compileAndRun(sourceCode, 0, "Main");
|
||||
BOOST_REQUIRE(callContractFunction(2, helperAddress) == bytes());
|
||||
BOOST_REQUIRE(callContractFunction(1, helperAddress) == toBigEndian(helperAddress));
|
||||
BOOST_CHECK(callContractFunction(0, bytes({0, 'a', 1})) == bytes({0, 'a', 0, 0, 0}));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
}
|
||||
|
@ -226,6 +226,14 @@ BOOST_AUTO_TEST_CASE(type_inference_explicit_conversion)
|
||||
BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(large_string_literal)
|
||||
{
|
||||
char const* text = "contract test {\n"
|
||||
" function f() { var x = \"123456789012345678901234567890123\"; }"
|
||||
"}\n";
|
||||
BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(balance)
|
||||
{
|
||||
char const* text = "contract test {\n"
|
||||
|
@ -48,7 +48,7 @@ public:
|
||||
m_optimize = true;
|
||||
bytes optimizedBytecode = compileAndRun(_sourceCode, _value, _contractName);
|
||||
int sizeDiff = nonOptimizedBytecode.size() - optimizedBytecode.size();
|
||||
BOOST_CHECK_MESSAGE(sizeDiff == _expectedSizeDecrease, "Bytecode did only shrink by "
|
||||
BOOST_CHECK_MESSAGE(sizeDiff == int(_expectedSizeDecrease), "Bytecode did only shrink by "
|
||||
+ boost::lexical_cast<string>(sizeDiff) + " bytes, expected: "
|
||||
+ boost::lexical_cast<string>(_expectedSizeDecrease));
|
||||
m_optimizedContract = m_contractAddress;
|
||||
|
7
trie.cpp
7
trie.cpp
@ -59,8 +59,8 @@ BOOST_AUTO_TEST_CASE(trie_tests)
|
||||
|
||||
cnote << "Testing Trie...";
|
||||
js::mValue v;
|
||||
string s = asString(contents(testPath + "/trietest.json"));
|
||||
BOOST_REQUIRE_MESSAGE(s.length() > 0, "Contents of 'trietest.json' is empty. Have you cloned the 'tests' repo branch develop?");
|
||||
string s = asString(contents(testPath + "/trieanyorder.json"));
|
||||
BOOST_REQUIRE_MESSAGE(s.length() > 0, "Contents of 'trieanyorder.json' is empty. Have you cloned the 'tests' repo branch develop?");
|
||||
js::read_string(s, v);
|
||||
for (auto& i: v.get_obj())
|
||||
{
|
||||
@ -88,12 +88,11 @@ BOOST_AUTO_TEST_CASE(trie_tests)
|
||||
BOOST_REQUIRE(t.check(true));
|
||||
}
|
||||
BOOST_REQUIRE(!o["root"].is_null());
|
||||
BOOST_CHECK_EQUAL(o["root"].get_str(), toHex(t.root().asArray()));
|
||||
BOOST_CHECK_EQUAL(o["root"].get_str(), "0x" + toHex(t.root().asArray()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
inline h256 stringMapHash256(StringMap const& _s)
|
||||
{
|
||||
return hash256(_s);
|
||||
|
15
vm.cpp
15
vm.cpp
@ -21,6 +21,8 @@
|
||||
*/
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <libethereum/Executive.h>
|
||||
#include <libevm/VMFactory.h>
|
||||
#include "vm.h"
|
||||
|
||||
using namespace std;
|
||||
@ -241,10 +243,11 @@ void FakeExtVM::importCallCreates(mArray& _callcreates)
|
||||
|
||||
eth::OnOpFunc FakeExtVM::simpleTrace()
|
||||
{
|
||||
return [](uint64_t steps, eth::Instruction inst, bigint newMemSize, bigint gasCost, void* voidVM, void const* voidExt)
|
||||
|
||||
return [](uint64_t steps, eth::Instruction inst, bigint newMemSize, bigint gasCost, dev::eth::VM* voidVM, dev::eth::ExtVMFace const* voidExt)
|
||||
{
|
||||
FakeExtVM const& ext = *(FakeExtVM const*)voidExt;
|
||||
eth::VM& vm = *(eth::VM*)voidVM;
|
||||
FakeExtVM const& ext = *static_cast<FakeExtVM const*>(voidExt);
|
||||
eth::VM& vm = *voidVM;
|
||||
|
||||
std::ostringstream o;
|
||||
o << std::endl << " STACK" << std::endl;
|
||||
@ -297,14 +300,14 @@ void doVMTests(json_spirit::mValue& v, bool _fillin)
|
||||
}
|
||||
|
||||
bytes output;
|
||||
VM vm(fev.gas);
|
||||
auto vm = eth::VMFactory::create(fev.gas);
|
||||
|
||||
u256 gas;
|
||||
bool vmExceptionOccured = false;
|
||||
try
|
||||
{
|
||||
output = vm.go(fev, fev.simpleTrace()).toBytes();
|
||||
gas = vm.gas();
|
||||
output = vm->go(fev, fev.simpleTrace()).toBytes();
|
||||
gas = vm->gas();
|
||||
}
|
||||
catch (VMException const& _e)
|
||||
{
|
||||
|
3
vm.h
3
vm.h
@ -80,9 +80,6 @@ public:
|
||||
bytes thisTxData;
|
||||
bytes thisTxCode;
|
||||
u256 gas;
|
||||
|
||||
private:
|
||||
eth::Manifest m_ms;
|
||||
};
|
||||
|
||||
|
||||
|
@ -32,7 +32,8 @@ BOOST_AUTO_TEST_SUITE(whisper)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(topic)
|
||||
{
|
||||
g_logVerbosity = 0;
|
||||
cnote << "Testing Whisper...";
|
||||
// g_logVerbosity = 0;
|
||||
|
||||
bool started = false;
|
||||
unsigned result = 0;
|
||||
@ -40,16 +41,16 @@ BOOST_AUTO_TEST_CASE(topic)
|
||||
{
|
||||
setThreadName("other");
|
||||
|
||||
Host ph("Test", NetworkPreferences(30303, "", false, true));
|
||||
Host ph("Test", NetworkPreferences(50303, "", false, true));
|
||||
auto wh = ph.registerCapability(new WhisperHost());
|
||||
ph.start();
|
||||
|
||||
started = true;
|
||||
|
||||
/// Only interested in odd packets
|
||||
auto w = wh->installWatch(BuildTopicMask()("odd"));
|
||||
auto w = wh->installWatch(BuildTopicMask("odd"));
|
||||
|
||||
for (int i = 0, last = 0; i < 100 && last < 81; ++i)
|
||||
for (int i = 0, last = 0; i < 200 && last < 81; ++i)
|
||||
{
|
||||
for (auto i: wh->checkWatch(w))
|
||||
{
|
||||
@ -65,10 +66,12 @@ BOOST_AUTO_TEST_CASE(topic)
|
||||
while (!started)
|
||||
this_thread::sleep_for(chrono::milliseconds(50));
|
||||
|
||||
Host ph("Test", NetworkPreferences(30300, "", false, true));
|
||||
Host ph("Test", NetworkPreferences(50300, "", false, true));
|
||||
auto wh = ph.registerCapability(new WhisperHost());
|
||||
this_thread::sleep_for(chrono::milliseconds(500));
|
||||
ph.start();
|
||||
ph.connect("127.0.0.1", 30303);
|
||||
this_thread::sleep_for(chrono::milliseconds(500));
|
||||
ph.connect("127.0.0.1", 50303);
|
||||
|
||||
KeyPair us = KeyPair::create();
|
||||
for (int i = 0; i < 10; ++i)
|
||||
@ -78,6 +81,8 @@ BOOST_AUTO_TEST_CASE(topic)
|
||||
}
|
||||
|
||||
listener.join();
|
||||
// g_logVerbosity = 0;
|
||||
|
||||
BOOST_REQUIRE_EQUAL(result, 1 + 9 + 25 + 49 + 81);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user