aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorchriseth <c@ethdev.com>2016-06-18 08:08:20 +0800
committerchriseth <c@ethdev.com>2016-06-29 05:18:55 +0800
commite5db096da9a2bfb3e6445b2d89cf730c7e22dc6d (patch)
tree3e950203ff1b0cb53f81447f1350feb3add0da27 /test
parent007132a78e5d97e0476e1153b14f0ae63f458b04 (diff)
downloaddexon-solidity-e5db096da9a2bfb3e6445b2d89cf730c7e22dc6d.tar.gz
dexon-solidity-e5db096da9a2bfb3e6445b2d89cf730c7e22dc6d.tar.zst
dexon-solidity-e5db096da9a2bfb3e6445b2d89cf730c7e22dc6d.zip
Fix some more tests.
Diffstat (limited to 'test')
-rw-r--r--test/IPCSocket.cpp83
-rw-r--r--test/IPCSocket.h38
-rw-r--r--test/contracts/AuctionRegistrar.cpp87
-rw-r--r--test/contracts/FixedFeeRegistrar.cpp37
-rw-r--r--test/contracts/Wallet.cpp103
-rw-r--r--test/libsolidity/SolidityEndToEndTest.cpp17
-rw-r--r--test/libsolidity/SolidityExecutionFramework.cpp29
-rw-r--r--test/libsolidity/SolidityExecutionFramework.h5
8 files changed, 220 insertions, 179 deletions
diff --git a/test/IPCSocket.cpp b/test/IPCSocket.cpp
index 8dd364bf..832875c0 100644
--- a/test/IPCSocket.cpp
+++ b/test/IPCSocket.cpp
@@ -134,17 +134,38 @@ string RPCSession::personal_newAccount(string const& _password)
return rpcCall("personal_newAccount", { quote(_password) }).asString();
}
-void RPCSession::test_setChainParams(string const& _author, string const& _account, string const& _balance)
+void RPCSession::test_setChainParams(vector<string> const& _accounts)
{
- if (_account.size() < 40)
- return;
- string config = c_genesisConfiguration;
- std::map<string, string> replaceMap;
- replaceMap["[AUTHOR]"] = _author;
- replaceMap["[ACCOUNT]"] = (_account[0] == '0' && _account[1] == 'x') ? _account.substr(2, 40) : _account;
- replaceMap["[BALANCE]"] = _balance;
- parseString(config, replaceMap);
- test_setChainParams(config);
+ static std::string const c_configString = R"(
+ {
+ "sealEngine": "NoProof",
+ "params": {
+ "accountStartNonce": "0x",
+ "maximumExtraDataSize": "0x1000000",
+ "blockReward": "0x",
+ "allowFutureBlocks": "1"
+ },
+ "genesis": {
+ "author": "0000000000000010000000000000000000000000",
+ "timestamp": "0x00",
+ "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
+ "extraData": "0x",
+ "gasLimit": "0x1000000000000"
+ },
+ "accounts": {
+ "0000000000000000000000000000000000000001": { "wei": "1", "precompiled": { "name": "ecrecover", "linear": { "base": 3000, "word": 0 } } },
+ "0000000000000000000000000000000000000002": { "wei": "1", "precompiled": { "name": "sha256", "linear": { "base": 60, "word": 12 } } },
+ "0000000000000000000000000000000000000003": { "wei": "1", "precompiled": { "name": "ripemd160", "linear": { "base": 600, "word": 120 } } },
+ "0000000000000000000000000000000000000004": { "wei": "1", "precompiled": { "name": "identity", "linear": { "base": 15, "word": 3 } } }
+ }
+ }
+ )";
+
+ Json::Value config;
+ BOOST_REQUIRE(Json::Reader().parse(c_configString, config));
+ for (auto const& account: _accounts)
+ config["accounts"][account]["wei"] = "0x100000000000000000000000000000000000000000";
+ test_setChainParams(Json::FastWriter().write(config));
}
void RPCSession::test_setChainParams(string const& _config)
@@ -173,6 +194,11 @@ void RPCSession::test_mineBlocks(int _number)
BOOST_FAIL("Error in test_mineBlocks: block mining timeout!");
}
+void RPCSession::test_modifyTimestamp(size_t _timestamp)
+{
+ rpcCall("test_modifyTimestamp", { to_string(_timestamp) });
+}
+
Json::Value RPCSession::rpcCall(string const& _methodName, vector<string> const& _args, bool _canFail)
{
string request = "{\"jsonrpc\":\"2.0\",\"method\":\"" + _methodName + "\",\"params\":[";
@@ -203,40 +229,25 @@ Json::Value RPCSession::rpcCall(string const& _methodName, vector<string> const&
return result["result"];
}
-RPCSession::RPCSession(const string& _path):
- m_ipcSocket(_path)
+string const& RPCSession::accountCreateIfNotExists(size_t _id)
{
- for (size_t i = 0; i < 1; ++i)
+ if (_id >= m_accounts.size())
{
- string account = personal_newAccount("");
- personal_unlockAccount(account, "", 100000);
- m_accounts.push_back(account);
+ m_accounts.push_back(personal_newAccount(""));
+ personal_unlockAccount(m_accounts.back(), "", 100000);
}
- test_setChainParams(
- "0x1000000000000000000000000000000000000000",
- m_accounts.front(),
- "1000000000000000000000000000000000000000000000"
- );
+ return m_accounts[_id];
}
-void RPCSession::parseString(string& _string, map<string, string> const& _varMap)
+RPCSession::RPCSession(const string& _path):
+ m_ipcSocket(_path)
{
- std::vector<string> types;
- for (std::map<std::string, std::string>::const_iterator it = _varMap.begin(); it != _varMap.end(); it++)
- types.push_back(it->first);
-
- for (unsigned i = 0; i < types.size(); i++)
- {
- std::size_t pos = _string.find(types.at(i));
- while (pos != std::string::npos)
- {
- _string.replace(pos, types.at(i).size(), _varMap.at(types.at(i)));
- pos = _string.find(types.at(i));
- }
- }
+ string account = personal_newAccount("");
+ personal_unlockAccount(account, "", 100000);
+ m_accounts.push_back(account);
+ test_setChainParams(m_accounts);
}
-
string RPCSession::TransactionData::toJson() const
{
Json::Value json;
diff --git a/test/IPCSocket.h b/test/IPCSocket.h
index 89e1d50a..040eb2c8 100644
--- a/test/IPCSocket.h
+++ b/test/IPCSocket.h
@@ -83,13 +83,15 @@ public:
std::string eth_getStorageRoot(std::string const& _address, std::string const& _blockNumber);
std::string personal_newAccount(std::string const& _password);
void personal_unlockAccount(std::string const& _address, std::string const& _password, int _duration);
- void test_setChainParams(std::string const& _author, std::string const& _account, std::string const& _balance);
+ void test_setChainParams(std::vector<std::string> const& _accounts);
void test_setChainParams(std::string const& _config);
void test_rewindToBlock(size_t _blockNr);
+ void test_modifyTimestamp(size_t _timestamp);
void test_mineBlocks(int _number);
Json::Value rpcCall(std::string const& _methodName, std::vector<std::string> const& _args = std::vector<std::string>(), bool _canFail = false);
std::string const& account(size_t _id) const { return m_accounts.at(_id); }
+ std::string const& accountCreateIfNotExists(size_t _id);
private:
RPCSession(std::string const& _path);
@@ -101,40 +103,6 @@ private:
IPCSocket m_ipcSocket;
size_t m_rpcSequence = 1;
- //Just working example of the node configuration file
- std::string const c_genesisConfiguration = R"(
- {
- "sealEngine": "NoProof",
- "options": {
- },
- "params": {
- "accountStartNonce": "0x",
- "maximumExtraDataSize": "0x1000000",
- "blockReward": "0x",
- "registrar": "",
- "allowFutureBlocks": "1"
- },
- "genesis": {
- "author": "[AUTHOR]",
- "timestamp": "0x00",
- "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
- "extraData": "0x",
- "gasLimit": "0x1000000000000"
- },
- "accounts": {
- "0000000000000000000000000000000000000001": { "wei": "1", "precompiled": { "name": "ecrecover", "linear": { "base": 3000, "word": 0 } } },
- "0000000000000000000000000000000000000002": { "wei": "1", "precompiled": { "name": "sha256", "linear": { "base": 60, "word": 12 } } },
- "0000000000000000000000000000000000000003": { "wei": "1", "precompiled": { "name": "ripemd160", "linear": { "base": 600, "word": 120 } } },
- "0000000000000000000000000000000000000004": { "wei": "1", "precompiled": { "name": "identity", "linear": { "base": 15, "word": 3 } } },
- "[ACCOUNT]": { "wei": "[BALANCE]" }
- },
- "network": {
- "nodes": [
- ]
- }
- }
- )";
-
std::vector<std::string> m_accounts;
};
diff --git a/test/contracts/AuctionRegistrar.cpp b/test/contracts/AuctionRegistrar.cpp
index e30f4572..0eee42a4 100644
--- a/test/contracts/AuctionRegistrar.cpp
+++ b/test/contracts/AuctionRegistrar.cpp
@@ -285,8 +285,8 @@ protected:
}
};
- u256 const m_biddingTime = u256(7 * 24 * 3600);
- u256 const m_renewalInterval = u256(365 * 24 * 3600);
+ size_t const m_biddingTime = size_t(7 * 24 * 3600);
+ size_t const m_renewalInterval = size_t(365 * 24 * 3600);
};
}
@@ -304,7 +304,6 @@ BOOST_AUTO_TEST_CASE(reserve)
// Test that reserving works for long strings
deployRegistrar();
vector<string> names{"abcabcabcabcabc", "defdefdefdefdef", "ghighighighighighighighighighighighighighighi"};
- m_sender = Address(0x123);
RegistrarInterface registrar(*this);
@@ -315,7 +314,7 @@ BOOST_AUTO_TEST_CASE(reserve)
for (auto const& name: names)
{
registrar.reserve(name);
- BOOST_CHECK_EQUAL(registrar.owner(name), u160(0x123));
+ BOOST_CHECK_EQUAL(registrar.owner(name), u160(m_sender));
}
}
@@ -324,14 +323,14 @@ BOOST_AUTO_TEST_CASE(double_reserve_long)
// Test that it is not possible to re-reserve from a different address.
deployRegistrar();
string name = "abcabcabcabcabcabcabcabcabcabca";
- m_sender = Address(0x123);
RegistrarInterface registrar(*this);
registrar.reserve(name);
- BOOST_CHECK_EQUAL(registrar.owner(name), u160(0x123));
+ BOOST_CHECK_EQUAL(registrar.owner(name), m_sender);
- m_sender = Address(0x124);
+ sendEther(account(1), u256(10) * eth::ether);
+ m_sender = account(1);
registrar.reserve(name);
- BOOST_CHECK_EQUAL(registrar.owner(name), u160(0x123));
+ BOOST_CHECK_EQUAL(registrar.owner(name), account(0));
}
BOOST_AUTO_TEST_CASE(properties)
@@ -341,14 +340,17 @@ BOOST_AUTO_TEST_CASE(properties)
RegistrarInterface registrar(*this);
string names[] = {"abcaeouoeuaoeuaoeu", "defncboagufra,fui", "ghagpyajfbcuajouhaeoi"};
size_t addr = 0x9872543;
+ size_t count = 1;
for (string const& name: names)
{
- addr++;
- size_t sender = addr + 10007;
- m_sender = Address(sender);
+ m_sender = account(0);
+ sendEther(account(count), u256(20) * eth::ether);
+ m_sender = account(count);
+ auto sender = m_sender;
+ addr += count;
// setting by sender works
registrar.reserve(name);
- BOOST_CHECK_EQUAL(registrar.owner(name), u160(sender));
+ BOOST_CHECK_EQUAL(registrar.owner(name), sender);
registrar.setAddress(name, addr, true);
BOOST_CHECK_EQUAL(registrar.addr(name), u160(addr));
registrar.setSubRegistrar(name, addr + 20);
@@ -357,14 +359,15 @@ BOOST_AUTO_TEST_CASE(properties)
BOOST_CHECK_EQUAL(registrar.content(name), h256(u256(addr + 90)));
// but not by someone else
- m_sender = Address(h256(addr + 10007 - 1));
- BOOST_CHECK_EQUAL(registrar.owner(name), u160(sender));
+ m_sender = account(count - 1);
+ BOOST_CHECK_EQUAL(registrar.owner(name), sender);
registrar.setAddress(name, addr + 1, true);
BOOST_CHECK_EQUAL(registrar.addr(name), u160(addr));
registrar.setSubRegistrar(name, addr + 20 + 1);
BOOST_CHECK_EQUAL(registrar.subRegistrar(name), u160(addr + 20));
registrar.setContent(name, h256(u256(addr + 90 + 1)));
BOOST_CHECK_EQUAL(registrar.content(name), h256(u256(addr + 90)));
+ count++;
}
}
@@ -372,7 +375,6 @@ BOOST_AUTO_TEST_CASE(transfer)
{
deployRegistrar();
string name = "abcaoeguaoucaeoduceo";
- m_sender = Address(0x123);
RegistrarInterface registrar(*this);
registrar.reserve(name);
registrar.setContent(name, h256(u256(123)));
@@ -385,7 +387,7 @@ BOOST_AUTO_TEST_CASE(disown)
{
deployRegistrar();
string name = "abcaoeguaoucaeoduceo";
- m_sender = Address(0x123);
+
RegistrarInterface registrar(*this);
registrar.reserve(name);
registrar.setContent(name, h256(u256(123)));
@@ -394,11 +396,12 @@ BOOST_AUTO_TEST_CASE(disown)
BOOST_CHECK_EQUAL(registrar.name(u160(124)), name);
// someone else tries disowning
- m_sender = Address(0x128);
+ sendEther(account(1), u256(10) * eth::ether);
+ m_sender = account(1);
registrar.disown(name);
- BOOST_CHECK_EQUAL(registrar.owner(name), 0x123);
+ BOOST_CHECK_EQUAL(registrar.owner(name), account(0));
- m_sender = Address(0x123);
+ m_sender = account(0);
registrar.disown(name);
BOOST_CHECK_EQUAL(registrar.owner(name), 0);
BOOST_CHECK_EQUAL(registrar.addr(name), 0);
@@ -411,7 +414,7 @@ BOOST_AUTO_TEST_CASE(auction_simple)
{
deployRegistrar();
string name = "x";
- m_sender = Address(0x123);
+
RegistrarInterface registrar(*this);
// initiate auction
registrar.setNextValue(8);
@@ -421,68 +424,70 @@ BOOST_AUTO_TEST_CASE(auction_simple)
m_envInfo.setTimestamp(m_envInfo.timestamp() + m_biddingTime + 10);
// trigger auction again
registrar.reserve(name);
- BOOST_CHECK_EQUAL(registrar.owner(name), 0x123);
+ BOOST_CHECK_EQUAL(registrar.owner(name), m_sender);
}
BOOST_AUTO_TEST_CASE(auction_bidding)
{
deployRegistrar();
string name = "x";
- m_sender = Address(0x123);
+
+ unsigned startTime = 0x776347e2;
+ m_rpc.test_modifyTimestamp(startTime);
+
RegistrarInterface registrar(*this);
// initiate auction
registrar.setNextValue(8);
registrar.reserve(name);
BOOST_CHECK_EQUAL(registrar.owner(name), 0);
// overbid self
- m_envInfo.setTimestamp(m_biddingTime - 10);
+ m_rpc.test_modifyTimestamp(startTime + m_biddingTime - 10);
registrar.setNextValue(12);
registrar.reserve(name);
// another bid by someone else
- m_sender = Address(0x124);
- m_envInfo.setTimestamp(2 * m_biddingTime - 50);
+ sendEther(account(1), 10 * eth::ether);
+ m_sender = account(1);
+ m_rpc.test_modifyTimestamp(startTime + 2 * m_biddingTime - 50);
registrar.setNextValue(13);
registrar.reserve(name);
BOOST_CHECK_EQUAL(registrar.owner(name), 0);
// end auction by first bidder (which is not highest) trying to overbid again (too late)
- m_sender = Address(0x123);
- m_envInfo.setTimestamp(4 * m_biddingTime);
+ m_sender = account(0);
+ m_rpc.test_modifyTimestamp(startTime + 4 * m_biddingTime);
registrar.setNextValue(20);
registrar.reserve(name);
- BOOST_CHECK_EQUAL(registrar.owner(name), 0x124);
+ BOOST_CHECK_EQUAL(registrar.owner(name), account(1));
}
BOOST_AUTO_TEST_CASE(auction_renewal)
{
deployRegistrar();
+
string name = "x";
RegistrarInterface registrar(*this);
+ size_t startTime = currentTimestamp();
// register name by auction
- m_sender = Address(0x123);
registrar.setNextValue(8);
registrar.reserve(name);
- m_envInfo.setTimestamp(4 * m_biddingTime);
+ m_rpc.test_modifyTimestamp(startTime + 4 * m_biddingTime);
registrar.reserve(name);
- BOOST_CHECK_EQUAL(registrar.owner(name), 0x123);
+ BOOST_CHECK_EQUAL(registrar.owner(name), m_sender);
// try to re-register before interval end
- m_sender = Address(0x222);
+ sendEther(account(1), 10 * eth::ether);
+ m_sender = account(1);
+ m_rpc.test_modifyTimestamp(currentTimestamp() + m_renewalInterval - 1);
registrar.setNextValue(80);
- m_envInfo.setTimestamp(m_envInfo.timestamp() + m_renewalInterval - 1);
registrar.reserve(name);
- m_envInfo.setTimestamp(m_envInfo.timestamp() + m_biddingTime);
- // if there is a bug in the renewal logic, this would transfer the ownership to 0x222,
+ m_rpc.test_modifyTimestamp(currentTimestamp() + m_biddingTime);
+ // if there is a bug in the renewal logic, this would transfer the ownership to account(1),
// but if there is no bug, this will initiate the auction, albeit with a zero bid
registrar.reserve(name);
- BOOST_CHECK_EQUAL(registrar.owner(name), 0x123);
+ BOOST_CHECK_EQUAL(registrar.owner(name), account(0));
- m_envInfo.setTimestamp(m_envInfo.timestamp() + 2);
registrar.setNextValue(80);
registrar.reserve(name);
- BOOST_CHECK_EQUAL(registrar.owner(name), 0x123);
- m_envInfo.setTimestamp(m_envInfo.timestamp() + m_biddingTime + 2);
- registrar.reserve(name);
- BOOST_CHECK_EQUAL(registrar.owner(name), 0x222);
+ BOOST_CHECK_EQUAL(registrar.owner(name), account(1));
}
BOOST_AUTO_TEST_SUITE_END()
diff --git a/test/contracts/FixedFeeRegistrar.cpp b/test/contracts/FixedFeeRegistrar.cpp
index df521e7e..8575d1fc 100644
--- a/test/contracts/FixedFeeRegistrar.cpp
+++ b/test/contracts/FixedFeeRegistrar.cpp
@@ -157,11 +157,10 @@ BOOST_AUTO_TEST_CASE(reserve)
// Test that reserving works and fee is taken into account.
deployRegistrar();
string name[] = {"abc", "def", "ghi"};
- m_sender = Address(0x123);
BOOST_REQUIRE(callContractFunctionWithValue("reserve(string)", m_fee, encodeDyn(name[0])) == encodeArgs());
- BOOST_CHECK(callContractFunction("owner(string)", encodeDyn(name[0])) == encodeArgs(h256(0x123)));
+ BOOST_CHECK(callContractFunction("owner(string)", encodeDyn(name[0])) == encodeArgs(h256(account(0), h256::AlignRight)));
BOOST_REQUIRE(callContractFunctionWithValue("reserve(string)", m_fee + 1, encodeDyn(name[1])) == encodeArgs());
- BOOST_CHECK(callContractFunction("owner(string)", encodeDyn(name[1])) == encodeArgs(h256(0x123)));
+ BOOST_CHECK(callContractFunction("owner(string)", encodeDyn(name[1])) == encodeArgs(h256(account(0), h256::AlignRight)));
BOOST_REQUIRE(callContractFunctionWithValue("reserve(string)", m_fee - 1, encodeDyn(name[2])) == encodeArgs());
BOOST_CHECK(callContractFunction("owner(string)", encodeDyn(name[2])) == encodeArgs(h256(0)));
}
@@ -171,13 +170,13 @@ BOOST_AUTO_TEST_CASE(double_reserve)
// Test that it is not possible to re-reserve from a different address.
deployRegistrar();
string name = "abc";
- m_sender = Address(0x123);
BOOST_REQUIRE(callContractFunctionWithValue("reserve(string)", m_fee, encodeDyn(name)) == encodeArgs());
- BOOST_CHECK(callContractFunction("owner(string)", encodeDyn(name)) == encodeArgs(h256(0x123)));
+ BOOST_CHECK(callContractFunction("owner(string)", encodeDyn(name)) == encodeArgs(h256(account(0), h256::AlignRight)));
- m_sender = Address(0x124);
+ sendEther(account(1), 10 * eth::ether);
+ m_sender = account(1);
BOOST_REQUIRE(callContractFunctionWithValue("reserve(string)", m_fee, encodeDyn(name)) == encodeArgs());
- BOOST_CHECK(callContractFunction("owner(string)", encodeDyn(name)) == encodeArgs(h256(0x123)));
+ BOOST_CHECK(callContractFunction("owner(string)", encodeDyn(name)) == encodeArgs(h256(account(0), h256::AlignRight)));
}
BOOST_AUTO_TEST_CASE(properties)
@@ -186,29 +185,35 @@ BOOST_AUTO_TEST_CASE(properties)
deployRegistrar();
string names[] = {"abc", "def", "ghi"};
size_t addr = 0x9872543;
+ size_t count = 1;
for (string const& name: names)
{
addr++;
- size_t sender = addr + 10007;
- m_sender = Address(sender);
+ m_sender = account(0);
+ sendEther(account(count), 10 * eth::ether);
+ m_sender = account(count);
+ Address owner = m_sender;
// setting by sender works
BOOST_REQUIRE(callContractFunctionWithValue("reserve(string)", m_fee, encodeDyn(name)) == encodeArgs());
- BOOST_CHECK(callContractFunction("owner(string)", encodeDyn(name)) == encodeArgs(u256(sender)));
+ BOOST_CHECK(callContractFunction("owner(string)", encodeDyn(name)) == encodeArgs(h256(owner, h256::AlignRight)));
BOOST_CHECK(callContractFunction("setAddr(string,address)", u256(0x40), u256(addr), u256(name.length()), name) == encodeArgs());
BOOST_CHECK(callContractFunction("addr(string)", encodeDyn(name)) == encodeArgs(addr));
BOOST_CHECK(callContractFunction("setSubRegistrar(string,address)", u256(0x40), addr + 20, u256(name.length()), name) == encodeArgs());
BOOST_CHECK(callContractFunction("subRegistrar(string)", encodeDyn(name)) == encodeArgs(addr + 20));
BOOST_CHECK(callContractFunction("setContent(string,bytes32)", u256(0x40), addr + 90, u256(name.length()), name) == encodeArgs());
BOOST_CHECK(callContractFunction("content(string)", encodeDyn(name)) == encodeArgs(addr + 90));
+ count++;
// but not by someone else
- m_sender = Address(h256(addr + 10007 - 1));
- BOOST_CHECK(callContractFunction("owner(string)", encodeDyn(name)) == encodeArgs(sender));
+ sendEther(account(count), 10 * eth::ether);
+ m_sender = account(count);
+ BOOST_CHECK(callContractFunction("owner(string)", encodeDyn(name)) == encodeArgs(h256(owner, h256::AlignRight)));
BOOST_CHECK(callContractFunction("setAddr(string,address)", u256(0x40), addr + 1, u256(name.length()), name) == encodeArgs());
BOOST_CHECK(callContractFunction("addr(string)", encodeDyn(name)) == encodeArgs(addr));
BOOST_CHECK(callContractFunction("setSubRegistrar(string,address)", u256(0x40), addr + 20 + 1, u256(name.length()), name) == encodeArgs());
BOOST_CHECK(callContractFunction("subRegistrar(string)", encodeDyn(name)) == encodeArgs(addr + 20));
BOOST_CHECK(callContractFunction("setContent(string,bytes32)", u256(0x40), addr + 90 + 1, u256(name.length()), name) == encodeArgs());
BOOST_CHECK(callContractFunction("content(string)", encodeDyn(name)) == encodeArgs(addr + 90));
+ count++;
}
}
@@ -216,21 +221,19 @@ BOOST_AUTO_TEST_CASE(transfer)
{
deployRegistrar();
string name = "abc";
- m_sender = Address(0x123);
BOOST_REQUIRE(callContractFunctionWithValue("reserve(string)", m_fee, encodeDyn(name)) == encodeArgs());
- BOOST_CHECK(callContractFunction("setContent(string,bytes32)", u256(0x40), u256(123), u256(name.length()), name) == encodeArgs());
+ BOOST_CHECK(callContractFunction("setContent(string,bytes32)", u256(0x40), h256(account(0), h256::AlignRight), u256(name.length()), name) == encodeArgs());
BOOST_CHECK(callContractFunction("transfer(string,address)", u256(0x40), u256(555), u256(name.length()), name) == encodeArgs());
BOOST_CHECK(callContractFunction("owner(string)", encodeDyn(name)) == encodeArgs(u256(555)));
- BOOST_CHECK(callContractFunction("content(string)", encodeDyn(name)) == encodeArgs(u256(123)));
+ BOOST_CHECK(callContractFunction("content(string)", encodeDyn(name)) == encodeArgs(h256(account(0), h256::AlignRight)));
}
BOOST_AUTO_TEST_CASE(disown)
{
deployRegistrar();
string name = "abc";
- m_sender = Address(0x123);
BOOST_REQUIRE(callContractFunctionWithValue("reserve(string)", m_fee, encodeDyn(name)) == encodeArgs());
- BOOST_CHECK(callContractFunction("setContent(string,bytes32)", u256(0x40), u256(123), u256(name.length()), name) == encodeArgs());
+ BOOST_CHECK(callContractFunction("setContent(string,bytes32)", u256(0x40), h256(account(0), h256::AlignRight), u256(name.length()), name) == encodeArgs());
BOOST_CHECK(callContractFunction("setAddr(string,address)", u256(0x40), u256(124), u256(name.length()), name) == encodeArgs());
BOOST_CHECK(callContractFunction("setSubRegistrar(string,address)", u256(0x40), u256(125), u256(name.length()), name) == encodeArgs());
diff --git a/test/contracts/Wallet.cpp b/test/contracts/Wallet.cpp
index 29fe5b8d..fbab2404 100644
--- a/test/contracts/Wallet.cpp
+++ b/test/contracts/Wallet.cpp
@@ -471,19 +471,22 @@ BOOST_AUTO_TEST_CASE(add_owners)
{
deployWallet(200);
Address originalOwner = m_sender;
- BOOST_REQUIRE(callContractFunction("addOwner(address)", h256(0x12)) == encodeArgs());
- BOOST_REQUIRE(callContractFunction("isOwner(address)", h256(0x12)) == encodeArgs(true));
+ BOOST_REQUIRE(callContractFunction("addOwner(address)", h256(account(1), h256::AlignRight)) == encodeArgs());
+ BOOST_REQUIRE(callContractFunction("isOwner(address)", h256(account(1), h256::AlignRight)) == encodeArgs(true));
// now let the new owner add someone
- m_sender = Address(0x12);
+ sendEther(account(1), 10 * eth::ether);
+ m_sender = account(1);
BOOST_REQUIRE(callContractFunction("addOwner(address)", h256(0x13)) == encodeArgs());
BOOST_REQUIRE(callContractFunction("isOwner(address)", h256(0x13)) == encodeArgs(true));
// and check that a non-owner cannot add a new owner
- m_sender = Address(0x50);
+ m_sender = account(0);
+ sendEther(account(2), 10 * eth::ether);
+ m_sender = account(2);
BOOST_REQUIRE(callContractFunction("addOwner(address)", h256(0x20)) == encodeArgs());
BOOST_REQUIRE(callContractFunction("isOwner(address)", h256(0x20)) == encodeArgs(false));
// finally check that all the owners are there
BOOST_REQUIRE(callContractFunction("isOwner(address)", h256(originalOwner, h256::AlignRight)) == encodeArgs(true));
- BOOST_REQUIRE(callContractFunction("isOwner(address)", h256(0x12)) == encodeArgs(true));
+ BOOST_REQUIRE(callContractFunction("isOwner(address)", h256(account(1), h256::AlignRight)) == encodeArgs(true));
BOOST_REQUIRE(callContractFunction("isOwner(address)", h256(0x13)) == encodeArgs(true));
}
@@ -548,22 +551,27 @@ BOOST_AUTO_TEST_CASE(initial_owners)
BOOST_AUTO_TEST_CASE(multisig_value_transfer)
{
deployWallet(200);
- BOOST_REQUIRE(callContractFunction("addOwner(address)", h256(0x12)) == encodeArgs());
- BOOST_REQUIRE(callContractFunction("addOwner(address)", h256(0x13)) == encodeArgs());
- BOOST_REQUIRE(callContractFunction("addOwner(address)", h256(0x14)) == encodeArgs());
+ BOOST_REQUIRE(callContractFunction("addOwner(address)", h256(account(1), h256::AlignRight)) == encodeArgs());
+ BOOST_REQUIRE(callContractFunction("addOwner(address)", h256(account(2), h256::AlignRight)) == encodeArgs());
+ BOOST_REQUIRE(callContractFunction("addOwner(address)", h256(account(3), h256::AlignRight)) == encodeArgs());
// 4 owners, set required to 3
BOOST_REQUIRE(callContractFunction("changeRequirement(uint256)", u256(3)) == encodeArgs());
// check that balance is and stays zero at destination address
- h256 opHash("6244b4fa93f73e09db0ae52750095ca0364a76b72bc01723c97011fcb876cc9e");
BOOST_CHECK_EQUAL(balanceAt(Address(0x05)), 0);
- m_sender = Address(0x12);
- BOOST_REQUIRE(callContractFunction("execute(address,uint256,bytes)", h256(0x05), 100, 0x60, 0x00) == encodeArgs(opHash));
+ m_sender = account(0);
+ sendEther(account(1), 10 * eth::ether);
+ m_sender = account(1);
+ auto ophash = callContractFunction("execute(address,uint256,bytes)", h256(0x05), 100, 0x60, 0x00);
BOOST_CHECK_EQUAL(balanceAt(Address(0x05)), 0);
- m_sender = Address(0x13);
- BOOST_REQUIRE(callContractFunction("execute(address,uint256,bytes)", h256(0x05), 100, 0x60, 0x00) == encodeArgs(opHash));
+ m_sender = account(0);
+ sendEther(account(2), 10 * eth::ether);
+ m_sender = account(2);
+ callContractFunction("confirm(bytes32)", ophash);
BOOST_CHECK_EQUAL(balanceAt(Address(0x05)), 0);
- m_sender = Address(0x14);
- BOOST_REQUIRE(callContractFunction("execute(address,uint256,bytes)", h256(0x05), 100, 0x60, 0x00) == encodeArgs(opHash));
+ m_sender = account(0);
+ sendEther(account(3), 10 * eth::ether);
+ m_sender = account(3);
+ callContractFunction("confirm(bytes32)", ophash);
// now it should go through
BOOST_CHECK_EQUAL(balanceAt(Address(0x05)), 100);
}
@@ -571,9 +579,9 @@ BOOST_AUTO_TEST_CASE(multisig_value_transfer)
BOOST_AUTO_TEST_CASE(revoke_addOwner)
{
deployWallet();
- BOOST_REQUIRE(callContractFunction("addOwner(address)", h256(0x12)) == encodeArgs());
- BOOST_REQUIRE(callContractFunction("addOwner(address)", h256(0x13)) == encodeArgs());
- BOOST_REQUIRE(callContractFunction("addOwner(address)", h256(0x14)) == encodeArgs());
+ BOOST_REQUIRE(callContractFunction("addOwner(address)", h256(account(1), h256::AlignRight)) == encodeArgs());
+ BOOST_REQUIRE(callContractFunction("addOwner(address)", h256(account(2), h256::AlignRight)) == encodeArgs());
+ BOOST_REQUIRE(callContractFunction("addOwner(address)", h256(account(3), h256::AlignRight)) == encodeArgs());
// 4 owners, set required to 3
BOOST_REQUIRE(callContractFunction("changeRequirement(uint256)", u256(3)) == encodeArgs());
// add a new owner
@@ -581,16 +589,22 @@ BOOST_AUTO_TEST_CASE(revoke_addOwner)
h256 opHash = sha3(FixedHash<4>(dev::sha3("addOwner(address)")).asBytes() + h256(0x33).asBytes());
BOOST_REQUIRE(callContractFunction("addOwner(address)", h256(0x33)) == encodeArgs());
BOOST_REQUIRE(callContractFunction("isOwner(address)", h256(0x33)) == encodeArgs(false));
- m_sender = Address(0x12);
+ m_sender = account(0);
+ sendEther(account(1), 10 * eth::ether);
+ m_sender = account(1);
BOOST_REQUIRE(callContractFunction("addOwner(address)", h256(0x33)) == encodeArgs());
BOOST_REQUIRE(callContractFunction("isOwner(address)", h256(0x33)) == encodeArgs(false));
// revoke one confirmation
m_sender = deployer;
BOOST_REQUIRE(callContractFunction("revoke(bytes32)", opHash) == encodeArgs());
- m_sender = Address(0x13);
+ m_sender = account(0);
+ sendEther(account(2), 10 * eth::ether);
+ m_sender = account(2);
BOOST_REQUIRE(callContractFunction("addOwner(address)", h256(0x33)) == encodeArgs());
BOOST_REQUIRE(callContractFunction("isOwner(address)", h256(0x33)) == encodeArgs(false));
- m_sender = Address(0x14);
+ m_sender = account(0);
+ sendEther(account(3), 10 * eth::ether);
+ m_sender = account(3);
BOOST_REQUIRE(callContractFunction("addOwner(address)", h256(0x33)) == encodeArgs());
BOOST_REQUIRE(callContractFunction("isOwner(address)", h256(0x33)) == encodeArgs(true));
}
@@ -598,28 +612,35 @@ BOOST_AUTO_TEST_CASE(revoke_addOwner)
BOOST_AUTO_TEST_CASE(revoke_transaction)
{
deployWallet(200);
- BOOST_REQUIRE(callContractFunction("addOwner(address)", h256(0x12)) == encodeArgs());
- BOOST_REQUIRE(callContractFunction("addOwner(address)", h256(0x13)) == encodeArgs());
- BOOST_REQUIRE(callContractFunction("addOwner(address)", h256(0x14)) == encodeArgs());
+ BOOST_REQUIRE(callContractFunction("addOwner(address)", h256(account(1), h256::AlignRight)) == encodeArgs());
+ BOOST_REQUIRE(callContractFunction("addOwner(address)", h256(account(2), h256::AlignRight)) == encodeArgs());
+ BOOST_REQUIRE(callContractFunction("addOwner(address)", h256(account(3), h256::AlignRight)) == encodeArgs());
// 4 owners, set required to 3
BOOST_REQUIRE(callContractFunction("changeRequirement(uint256)", u256(3)) == encodeArgs());
// create a transaction
Address deployer = m_sender;
- h256 opHash("6244b4fa93f73e09db0ae52750095ca0364a76b72bc01723c97011fcb876cc9e");
BOOST_CHECK_EQUAL(balanceAt(Address(0x05)), 0);
- m_sender = Address(0x12);
- BOOST_REQUIRE(callContractFunction("execute(address,uint256,bytes)", h256(0x05), 100, 0x60, 0x00) == encodeArgs(opHash));
+ m_sender = account(0);
+ sendEther(account(1), 10 * eth::ether);
+ m_sender = account(1);
+ auto opHash = callContractFunction("execute(address,uint256,bytes)", h256(0x05), 100, 0x60, 0x00);
BOOST_CHECK_EQUAL(balanceAt(Address(0x05)), 0);
- m_sender = Address(0x13);
- BOOST_REQUIRE(callContractFunction("execute(address,uint256,bytes)", h256(0x05), 100, 0x60, 0x00) == encodeArgs(opHash));
+ m_sender = account(0);
+ sendEther(account(2), 10 * eth::ether);
+ m_sender = account(2);
+ callContractFunction("confirm(bytes32)", opHash);
BOOST_CHECK_EQUAL(balanceAt(Address(0x05)), 0);
- m_sender = Address(0x12);
+ m_sender = account(0);
+ sendEther(account(1), 10 * eth::ether);
+ m_sender = account(1);
BOOST_REQUIRE(callContractFunction("revoke(bytes32)", opHash) == encodeArgs());
m_sender = deployer;
- BOOST_REQUIRE(callContractFunction("execute(address,uint256,bytes)", h256(0x05), 100, 0x60, 0x00) == encodeArgs(opHash));
+ callContractFunction("confirm(bytes32)", opHash);
BOOST_CHECK_EQUAL(balanceAt(Address(0x05)), 0);
- m_sender = Address(0x14);
- BOOST_REQUIRE(callContractFunction("execute(address,uint256,bytes)", h256(0x05), 100, 0x60, 0x00) == encodeArgs(opHash));
+ m_sender = account(0);
+ sendEther(account(3), 10 * eth::ether);
+ m_sender = account(3);
+ callContractFunction("confirm(bytes32)", opHash);
// now it should go through
BOOST_CHECK_EQUAL(balanceAt(Address(0x05)), 100);
}
@@ -630,29 +651,33 @@ BOOST_AUTO_TEST_CASE(daylimit)
BOOST_REQUIRE(callContractFunction("m_dailyLimit()") == encodeArgs(u256(0)));
BOOST_REQUIRE(callContractFunction("setDailyLimit(uint256)", h256(100)) == encodeArgs());
BOOST_REQUIRE(callContractFunction("m_dailyLimit()") == encodeArgs(u256(100)));
- BOOST_REQUIRE(callContractFunction("addOwner(address)", h256(0x12)) == encodeArgs());
- BOOST_REQUIRE(callContractFunction("addOwner(address)", h256(0x13)) == encodeArgs());
- BOOST_REQUIRE(callContractFunction("addOwner(address)", h256(0x14)) == encodeArgs());
+ BOOST_REQUIRE(callContractFunction("addOwner(address)", h256(account(1), h256::AlignRight)) == encodeArgs());
+ BOOST_REQUIRE(callContractFunction("addOwner(address)", h256(account(2), h256::AlignRight)) == encodeArgs());
+ BOOST_REQUIRE(callContractFunction("addOwner(address)", h256(account(3), h256::AlignRight)) == encodeArgs());
// 4 owners, set required to 3
BOOST_REQUIRE(callContractFunction("changeRequirement(uint256)", u256(3)) == encodeArgs());
// try to send tx over daylimit
BOOST_CHECK_EQUAL(balanceAt(Address(0x05)), 0);
- m_sender = Address(0x12);
+ sendEther(account(1), 10 * eth::ether);
+ m_sender = account(1);
BOOST_REQUIRE(
callContractFunction("execute(address,uint256,bytes)", h256(0x05), 150, 0x60, 0x00) !=
encodeArgs(u256(0))
);
BOOST_CHECK_EQUAL(balanceAt(Address(0x05)), 0);
// try to send tx under daylimit by stranger
- m_sender = Address(0x77);
+ m_sender = account(0);
+ sendEther(account(4), 10 * eth::ether);
+ m_sender = account(4);
BOOST_REQUIRE(
callContractFunction("execute(address,uint256,bytes)", h256(0x05), 90, 0x60, 0x00) ==
encodeArgs(u256(0))
);
BOOST_CHECK_EQUAL(balanceAt(Address(0x05)), 0);
// now send below limit by owner
- m_sender = Address(0x12);
+ m_sender = account(0);
+ sendEther(account(1), 10 * eth::ether);
BOOST_REQUIRE(
callContractFunction("execute(address,uint256,bytes)", h256(0x05), 90, 0x60, 0x00) ==
encodeArgs(u256(0))
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp
index 8689d61e..8dcc878e 100644
--- a/test/libsolidity/SolidityEndToEndTest.cpp
+++ b/test/libsolidity/SolidityEndToEndTest.cpp
@@ -1325,10 +1325,10 @@ BOOST_AUTO_TEST_CASE(blockchain)
" blockNumber = block.number;\n"
" }\n"
"}\n";
- m_envInfo.setAuthor(Address(0x123));
- m_envInfo.setNumber(7);
+ BOOST_CHECK(m_rpc.rpcCall("miner_setEtherbase", {"\"0x1212121212121212121212121212121212121212\""}).asBool() == true);
+ m_rpc.test_mineBlocks(5);
compileAndRun(sourceCode, 27);
- BOOST_CHECK(callContractFunctionWithValue("someInfo()", 28) == encodeArgs(28, 0x123, 7));
+ BOOST_CHECK(callContractFunctionWithValue("someInfo()", 28) == encodeArgs(28, u256("0x1212121212121212121212121212121212121212"), 7));
}
BOOST_AUTO_TEST_CASE(msg_sig)
@@ -1368,9 +1368,9 @@ BOOST_AUTO_TEST_CASE(now)
" val = now;\n"
" }\n"
"}\n";
- m_envInfo.setTimestamp(9);
+ m_rpc.test_modifyTimestamp(0x776347e2);
compileAndRun(sourceCode);
- BOOST_CHECK(callContractFunction("someInfo()") == encodeArgs(true, 9));
+ BOOST_CHECK(callContractFunction("someInfo()") == encodeArgs(true, 0x776347e3));
}
BOOST_AUTO_TEST_CASE(type_conversions_cleanup)
@@ -2462,8 +2462,7 @@ BOOST_AUTO_TEST_CASE(use_std_lib)
contract Icarus is mortal { }
)";
m_addStandardSources = true;
- u256 amount(130);
- u160 address(23);
+ u256 amount(130 * eth::ether);
compileAndRun(sourceCode, amount, "Icarus");
u256 balanceBefore = balanceAt(m_sender);
BOOST_CHECK(callContractFunction("kill()") == bytes());
@@ -2567,7 +2566,7 @@ BOOST_AUTO_TEST_CASE(event)
BOOST_CHECK_EQUAL(h256(m_logs[0].data), h256(u256(value)));
BOOST_REQUIRE_EQUAL(m_logs[0].topics.size(), 3);
BOOST_CHECK_EQUAL(m_logs[0].topics[0], dev::sha3(string("Deposit(address,bytes32,uint256)")));
- BOOST_CHECK_EQUAL(m_logs[0].topics[1], h256(m_sender));
+ BOOST_CHECK_EQUAL(m_logs[0].topics[1], h256(m_sender, h256::AlignRight));
BOOST_CHECK_EQUAL(m_logs[0].topics[2], h256(id));
}
}
@@ -2624,7 +2623,7 @@ BOOST_AUTO_TEST_CASE(event_anonymous_with_topics)
BOOST_CHECK_EQUAL(m_logs[0].address, m_contractAddress);
BOOST_CHECK(m_logs[0].data == encodeArgs("abc"));
BOOST_REQUIRE_EQUAL(m_logs[0].topics.size(), 4);
- BOOST_CHECK_EQUAL(m_logs[0].topics[0], h256(m_sender));
+ BOOST_CHECK_EQUAL(m_logs[0].topics[0], h256(m_sender, h256::AlignRight));
BOOST_CHECK_EQUAL(m_logs[0].topics[1], h256(id));
BOOST_CHECK_EQUAL(m_logs[0].topics[2], h256(value));
BOOST_CHECK_EQUAL(m_logs[0].topics[3], h256(2));
diff --git a/test/libsolidity/SolidityExecutionFramework.cpp b/test/libsolidity/SolidityExecutionFramework.cpp
index abb564db..efd3a8b8 100644
--- a/test/libsolidity/SolidityExecutionFramework.cpp
+++ b/test/libsolidity/SolidityExecutionFramework.cpp
@@ -45,7 +45,8 @@ string getIPCSocketPath()
}
}
if (ipcPath.empty())
- ipcPath = getenv("ETH_TEST_IPC");
+ if (auto path = getenv("ETH_TEST_IPC"))
+ ipcPath = path;
if (ipcPath.empty())
BOOST_FAIL("ERROR: ipcPath not set! (use --ipc <path>)");
return ipcPath;
@@ -86,7 +87,6 @@ void ExecutionFramework::sendMessage(bytes const& _data, bool _isCreation, u256
m_contractAddress = Address(receipt.contractAddress);
BOOST_REQUIRE(m_contractAddress);
string code = m_rpc.eth_getCode(receipt.contractAddress, "latest");
- BOOST_REQUIRE(code.size() > 2);
m_output = fromHex(code, WhenError::Throw);
}
@@ -103,6 +103,31 @@ void ExecutionFramework::sendMessage(bytes const& _data, bool _isCreation, u256
}
}
+void ExecutionFramework::sendEther(Address const& _to, u256 const& _value)
+{
+ RPCSession::TransactionData d;
+ d.data = "0x";
+ d.from = "0x" + toString(m_sender);
+ d.gas = toHex(m_gas, HexPrefix::Add);
+ d.gasPrice = toHex(m_gasPrice, HexPrefix::Add);
+ d.value = toHex(_value, HexPrefix::Add);
+ d.to = dev::toString(_to);
+
+ string txHash = m_rpc.eth_sendTransaction(d);
+ m_rpc.test_mineBlocks(1);
+}
+
+size_t ExecutionFramework::currentTimestamp()
+{
+ auto latestBlock = m_rpc.rpcCall("eth_getBlockByNumber", {"\"latest\"", "false"});
+ return size_t(u256(latestBlock.get("timestamp", "invalid").asString()));
+}
+
+Address ExecutionFramework::account(size_t _i)
+{
+ return Address(m_rpc.accountCreateIfNotExists(_i));
+}
+
bool ExecutionFramework::addressHasCode(Address const& _addr)
{
string code = m_rpc.eth_getCode(toString(_addr), "latest");
diff --git a/test/libsolidity/SolidityExecutionFramework.h b/test/libsolidity/SolidityExecutionFramework.h
index 42b22c82..f06aeff7 100644
--- a/test/libsolidity/SolidityExecutionFramework.h
+++ b/test/libsolidity/SolidityExecutionFramework.h
@@ -250,6 +250,11 @@ private:
protected:
void sendMessage(bytes const& _data, bool _isCreation, u256 const& _value = 0);
+ void sendEther(Address const& _to, u256 const& _value);
+ size_t currentTimestamp();
+
+ /// @returns the (potentially newly created) _ith address.
+ Address account(size_t _i);
u256 balanceAt(Address const& _addr);
bool storageEmpty(Address const& _addr);