Added new transaction tests for checking miner fees

This commit is contained in:
Marko Simovic 2014-04-03 11:01:03 -04:00
parent cae6132e35
commit da2f0e1d4a
3 changed files with 79 additions and 18 deletions

View File

@ -37,4 +37,13 @@ void mine(Client& c, int numBlocks)
c.stopMining();
}
void connectClients(Client& c1, Client& c2)
{
short c1Port = 20000;
short c2Port = 21000;
c1.startNetwork(c1Port);
c2.startNetwork(c2Port);
c2.connect("127.0.0.1", c1Port);
}
}

View File

@ -25,5 +25,6 @@ namespace eth
{
void mine(Client& c, int numBlocks);
void connectClients(Client& c1, Client& c2);
}

View File

@ -29,38 +29,89 @@
using namespace std;
using namespace eth;
BOOST_AUTO_TEST_CASE(mine_and_send_to_peer)
BOOST_AUTO_TEST_CASE(mine_local_simple_tx)
{
KeyPair kp1 = KeyPair::create();
KeyPair kp2 = KeyPair::create();
string c1DataDir = (boost::filesystem::temp_directory_path() / boost::filesystem::unique_path()).string();
string c2DataDir = (boost::filesystem::temp_directory_path() / boost::filesystem::unique_path()).string();
Client c1("TestClient1", kp1.address(), c1DataDir);
Client c2("TestClient2", kp2.address(), c2DataDir);
short c1Port = 20000;
short c2Port = 21000;
//connect the two clients up
c1.startNetwork(c1Port);
c2.startNetwork(c2Port);
c2.connect("127.0.0.1", c1Port);
Client c1("TestClient1", kp1.address(), (boost::filesystem::temp_directory_path() / boost::filesystem::unique_path()).string());
//mine some blocks so that client 1 has a balance
mine(c1, 1);
auto c1bal = c1.state().balance(kp1.address());
BOOST_REQUIRE(c1bal > 0);
// BOOST_REQUIRE(c1bal > c1.state().fee());
//send c2 some eth from c1
// auto txAmount = c1bal - c1.state().fee();
// c1.transact(kp1.secret(), c2.address(), txAmount);
auto txAmount = c1bal / 2u;
auto gasPrice = 10 * szabo;
auto gas = eth::c_callGas;
c1.transact(kp1.secret(), txAmount, gasPrice, gas, kp2.address(), bytes());
//mine some more to include the transaction on chain
mine(c1, 1);
auto c2bal = c1.state().balance(kp2.address());
BOOST_REQUIRE(c2bal > 0);
BOOST_REQUIRE(c2bal == txAmount);
}
BOOST_AUTO_TEST_CASE(mine_and_send_to_peer)
{
KeyPair kp1 = KeyPair::create();
KeyPair kp2 = KeyPair::create();
Client c1("TestClient1", kp1.address(), (boost::filesystem::temp_directory_path() / boost::filesystem::unique_path()).string());
Client c2("TestClient2", kp2.address(), (boost::filesystem::temp_directory_path() / boost::filesystem::unique_path()).string());
connectClients(c1, c2);
//mine some blocks so that client 1 has a balance
mine(c1, 1);
auto c1bal = c1.state().balance(kp1.address());
BOOST_REQUIRE(c1bal > 0);
//send c2 some eth from c1
auto txAmount = c1bal / 2u;
auto gasPrice = 10 * szabo;
auto gas = eth::c_callGas;
c1.transact(kp1.secret(), txAmount, gasPrice, gas, kp2.address(), bytes());
//mine some more to include the transaction on chain
mine(c1, 1);
auto c2bal = c2.state().balance(kp2.address());
BOOST_REQUIRE(c2bal > 0);
// BOOST_REQUIRE(c2bal == txAmount);
BOOST_REQUIRE(c2bal == txAmount);
}
BOOST_AUTO_TEST_CASE(mine_and_send_to_peer_fee_check)
{
KeyPair kp1 = KeyPair::create();
KeyPair kp2 = KeyPair::create();
Client c1("TestClient1", kp1.address(), (boost::filesystem::temp_directory_path() / boost::filesystem::unique_path()).string());
Client c2("TestClient2", kp2.address(), (boost::filesystem::temp_directory_path() / boost::filesystem::unique_path()).string());
connectClients(c1, c2);
//mine some blocks so that client 1 has a balance
mine(c1, 1);
auto c1StartBalance = c1.state().balance(kp1.address());
auto c2StartBalance = c2.state().balance(kp2.address());
BOOST_REQUIRE(c1StartBalance > 0);
BOOST_REQUIRE(c2StartBalance == 0);
//send c2 some eth from c1
auto txAmount = c1StartBalance / 2u;
auto gasPrice = 10 * szabo;
auto gas = eth::c_callGas;
c1.transact(kp1.secret(), txAmount, gasPrice, gas, c2.address(), bytes());
//mine some more, this time with second client (so he can get fees from first client's tx)
mine(c2, 1);
auto c1EndBalance = c1.state().balance(kp1.address());
auto c2EndBalance = c2.state().balance(kp2.address());
BOOST_REQUIRE(c1EndBalance > 0);
BOOST_REQUIRE(c1EndBalance == c1StartBalance - txAmount - gasPrice * gas);
BOOST_REQUIRE(c2EndBalance > 0);
}