replace BalanceAt

add addressHasCode
remove m_state and sealengine
This commit is contained in:
Dimitry 2016-06-14 18:01:57 +03:00 committed by chriseth
parent ce2258b71e
commit 763faf7b0e
5 changed files with 27 additions and 24 deletions

View File

@ -234,9 +234,9 @@ BOOST_AUTO_TEST_CASE(disown)
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());
BOOST_CHECK_EQUAL(m_state.balance(Address(0x124)), 0);
BOOST_CHECK_EQUAL(balanceAt(Address(0x124)), 0);
BOOST_CHECK(callContractFunction("disown(string,address)", u256(0x40), u256(0x124), name.size(), name) == encodeArgs());
BOOST_CHECK_EQUAL(m_state.balance(Address(0x124)), m_fee);
BOOST_CHECK_EQUAL(balanceAt(Address(0x124)), m_fee);
BOOST_CHECK(callContractFunction("owner(string)", encodeDyn(name)) == encodeArgs(u256(0)));
BOOST_CHECK(callContractFunction("content(string)", encodeDyn(name)) == encodeArgs(u256(0)));

View File

@ -555,17 +555,17 @@ BOOST_AUTO_TEST_CASE(multisig_value_transfer)
BOOST_REQUIRE(callContractFunction("changeRequirement(uint256)", u256(3)) == encodeArgs());
// check that balance is and stays zero at destination address
h256 opHash("6244b4fa93f73e09db0ae52750095ca0364a76b72bc01723c97011fcb876cc9e");
BOOST_CHECK_EQUAL(m_state.balance(Address(0x05)), 0);
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));
BOOST_CHECK_EQUAL(m_state.balance(Address(0x05)), 0);
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));
BOOST_CHECK_EQUAL(m_state.balance(Address(0x05)), 0);
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));
// now it should go through
BOOST_CHECK_EQUAL(m_state.balance(Address(0x05)), 100);
BOOST_CHECK_EQUAL(balanceAt(Address(0x05)), 100);
}
BOOST_AUTO_TEST_CASE(revoke_addOwner)
@ -606,22 +606,22 @@ BOOST_AUTO_TEST_CASE(revoke_transaction)
// create a transaction
Address deployer = m_sender;
h256 opHash("6244b4fa93f73e09db0ae52750095ca0364a76b72bc01723c97011fcb876cc9e");
BOOST_CHECK_EQUAL(m_state.balance(Address(0x05)), 0);
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));
BOOST_CHECK_EQUAL(m_state.balance(Address(0x05)), 0);
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));
BOOST_CHECK_EQUAL(m_state.balance(Address(0x05)), 0);
BOOST_CHECK_EQUAL(balanceAt(Address(0x05)), 0);
m_sender = Address(0x12);
BOOST_REQUIRE(callContractFunction("revoke(bytes32)", opHash) == encodeArgs());
m_sender = deployer;
BOOST_REQUIRE(callContractFunction("execute(address,uint256,bytes)", h256(0x05), 100, 0x60, 0x00) == encodeArgs(opHash));
BOOST_CHECK_EQUAL(m_state.balance(Address(0x05)), 0);
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));
// now it should go through
BOOST_CHECK_EQUAL(m_state.balance(Address(0x05)), 100);
BOOST_CHECK_EQUAL(balanceAt(Address(0x05)), 100);
}
BOOST_AUTO_TEST_CASE(daylimit)
@ -637,27 +637,27 @@ BOOST_AUTO_TEST_CASE(daylimit)
BOOST_REQUIRE(callContractFunction("changeRequirement(uint256)", u256(3)) == encodeArgs());
// try to send tx over daylimit
BOOST_CHECK_EQUAL(m_state.balance(Address(0x05)), 0);
BOOST_CHECK_EQUAL(balanceAt(Address(0x05)), 0);
m_sender = Address(0x12);
BOOST_REQUIRE(
callContractFunction("execute(address,uint256,bytes)", h256(0x05), 150, 0x60, 0x00) !=
encodeArgs(u256(0))
);
BOOST_CHECK_EQUAL(m_state.balance(Address(0x05)), 0);
BOOST_CHECK_EQUAL(balanceAt(Address(0x05)), 0);
// try to send tx under daylimit by stranger
m_sender = Address(0x77);
BOOST_REQUIRE(
callContractFunction("execute(address,uint256,bytes)", h256(0x05), 90, 0x60, 0x00) ==
encodeArgs(u256(0))
);
BOOST_CHECK_EQUAL(m_state.balance(Address(0x05)), 0);
BOOST_CHECK_EQUAL(balanceAt(Address(0x05)), 0);
// now send below limit by owner
m_sender = Address(0x12);
BOOST_REQUIRE(
callContractFunction("execute(address,uint256,bytes)", h256(0x05), 90, 0x60, 0x00) ==
encodeArgs(u256(0))
);
BOOST_CHECK_EQUAL(m_state.balance(Address(0x05)), 90);
BOOST_CHECK_EQUAL(balanceAt(Address(0x05)), 90);
}
BOOST_AUTO_TEST_CASE(daylimit_constructor)

View File

@ -1653,7 +1653,7 @@ BOOST_AUTO_TEST_CASE(suicide)
compileAndRun(sourceCode, amount);
u160 address(23);
BOOST_CHECK(callContractFunction("a(address)", address) == bytes());
BOOST_CHECK(!m_state.addressHasCode(m_contractAddress));
BOOST_CHECK(!addressHasCode(m_contractAddress));
BOOST_CHECK_EQUAL(balanceAt(address), amount);
}
@ -1669,7 +1669,7 @@ BOOST_AUTO_TEST_CASE(selfdestruct)
compileAndRun(sourceCode, amount);
u160 address(23);
BOOST_CHECK(callContractFunction("a(address)", address) == bytes());
BOOST_CHECK(!m_state.addressHasCode(m_contractAddress));
BOOST_CHECK(!addressHasCode(m_contractAddress));
BOOST_CHECK_EQUAL(balanceAt(address), amount);
}
@ -2467,7 +2467,7 @@ BOOST_AUTO_TEST_CASE(use_std_lib)
compileAndRun(sourceCode, amount, "Icarus");
u256 balanceBefore = balanceAt(m_sender);
BOOST_CHECK(callContractFunction("kill()") == bytes());
BOOST_CHECK(!m_state.addressHasCode(m_contractAddress));
BOOST_CHECK(!addressHasCode(m_contractAddress));
BOOST_CHECK(balanceAt(m_sender) > balanceBefore);
}

View File

@ -30,12 +30,10 @@ using namespace dev::solidity::test;
ExecutionFramework::ExecutionFramework():
m_rpc(RPCSession::instance("/tmp/test/geth.ipc")),
m_sender(m_rpc.account(0)),
m_state(0)
m_rpc(RPCSession::instance("/home/wins/Ethereum/testnet/ethnode1/geth.ipc")),
m_sender(m_rpc.account(0))
{
eth::NoProof::init();
m_sealEngine.reset(eth::ChainParams().createSealEngine());
if (g_logVerbosity != -1)
g_logVerbosity = 0;
@ -84,6 +82,12 @@ void ExecutionFramework::sendMessage(bytes const& _data, bool _isCreation, u256
}
}
bool ExecutionFramework::addressHasCode(Address const& _addr)
{
string code = m_rpc.eth_getCode(toString(_addr), "latest");
return !code.empty() && code != "0x";
}
u256 ExecutionFramework::balanceAt(Address const& _addr)
{
return u256(m_rpc.eth_getBalance(toString(_addr), "latest"));

View File

@ -253,6 +253,7 @@ protected:
u256 balanceAt(Address const& _addr);
bool storageEmpty(Address const& _addr);
bool addressHasCode(Address const& _addr);
RPCSession& m_rpc;
@ -263,7 +264,6 @@ protected:
bytes data;
};
std::unique_ptr<eth::SealEngineFace> m_sealEngine;
size_t m_optimizeRuns = 200;
bool m_optimize = false;
bool m_addStandardSources = false;
@ -271,7 +271,6 @@ protected:
Address m_sender;
Address m_contractAddress;
eth::EnvInfo m_envInfo;
eth::State m_state;
u256 const m_gasPrice = 100 * eth::szabo;
u256 const m_gas = 100000000;
bytes m_output;