Fabcoin Core  0.16.2
P2P Digital Currency
AccountHolder.cpp
Go to the documentation of this file.
1 /*
2  This file is part of cpp-ethereum.
3 
4  cpp-ethereum is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  cpp-ethereum is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
16  */
22 #include <boost/test/unit_test.hpp>
25 
26 using namespace std;
27 using namespace dev;
28 using namespace eth;
29 
30 namespace dev
31 {
32 namespace test
33 {
34 
35 BOOST_FIXTURE_TEST_SUITE(AccountHolderTest, TestOutputHelper)
36 
37 BOOST_AUTO_TEST_CASE(ProxyAccountUseCase)
38 {
39  FixedAccountHolder h = FixedAccountHolder(function<Interface*()>(), vector<KeyPair>());
40 
41  BOOST_CHECK(h.allAccounts().empty());
42  BOOST_CHECK(h.realAccounts().empty());
43  Address addr("abababababababababababababababababababab");
44  Address addr2("abababababababababababababababababababab");
45  int id = h.addProxyAccount(addr);
46  BOOST_CHECK(h.queuedTransactions(id).empty());
47  // register it again
48  int secondID = h.addProxyAccount(addr);
49  BOOST_CHECK(h.queuedTransactions(secondID).empty());
50 
53  t1.from = addr;
54  t1.data = fromHex("12345678");
55  t2.from = addr;
56  t2.data = fromHex("abcdef");
57  BOOST_CHECK(h.queuedTransactions(id).empty());
58  h.queueTransaction(t1);
59  BOOST_CHECK_EQUAL(1, h.queuedTransactions(id).size());
60  h.queueTransaction(t2);
61  BOOST_REQUIRE_EQUAL(2, h.queuedTransactions(id).size());
62 
63  // second proxy should not see transactions
64  BOOST_CHECK(h.queuedTransactions(secondID).empty());
65 
66  BOOST_CHECK(h.queuedTransactions(id)[0].data == t1.data);
67  BOOST_CHECK(h.queuedTransactions(id)[1].data == t2.data);
68 
69  h.clearQueue(id);
70  BOOST_CHECK(h.queuedTransactions(id).empty());
71  // removing fails because it never existed
72  BOOST_CHECK(!h.removeProxyAccount(secondID));
74 }
75 
77 
78 }
79 }
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
Definition: Arith256.cpp:15
#define h(i)
Definition: sha.cpp:736
void queueTransaction(eth::TransactionSkeleton const &_transaction)
std::hash for asio::adress
Definition: Common.h:323
int addProxyAccount(Address const &_account)
bytes fromHex(std::string const &_s, WhenError _throw=WhenError::DontThrow)
Definition: CommonData.cpp:99
BOOST_AUTO_TEST_CASE(ProxyAccountUseCase)
Fixed-size raw-byte array container type, with an API optimised for storing hashes.
Definition: FixedHash.h:47
#define t1
std::vector< eth::TransactionSkeleton > const & queuedTransactions(int _id) const
Main API hub for interfacing with Ethereum.
Definition: Interface.h:67
dev::AddressHash realAccounts() const override
#define t2
#define BOOST_FIXTURE_TEST_SUITE(a, b)
Definition: object.cpp:14
#define BOOST_CHECK_EQUAL(v1, v2)
Definition: object.cpp:18
#define BOOST_AUTO_TEST_SUITE_END()
Definition: object.cpp:16
bool removeProxyAccount(unsigned _id)
Addresses allAccounts() const
Helper functions to work with json::spirit and test files.
#define BOOST_CHECK(expr)
Definition: object.cpp:17