Fabcoin Core  0.16.2
P2P Digital Currency
commonjs.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>
23 #include <libdevcore/Log.h>
24 #include <libethcore/CommonJS.h>
26 
27 using namespace std;
28 using namespace dev;
29 using namespace dev::eth;
30 using namespace dev::test;
31 
33 
35 {
36  KeyPair kp = KeyPair::create();
37  string s = toJS(kp.pub());
38  Public pub = dev::jsToPublic(s);
39  BOOST_CHECK_EQUAL(kp.pub(), pub);
40 }
41 
43 {
44  KeyPair kp = KeyPair::create();
45  string s = toJS(kp.address());
48 }
49 
51 {
52  KeyPair kp = KeyPair::create();
53  string s = toJS(kp.secret().makeInsecure());
54  Secret secret = dev::jsToSecret(s);
55  BOOST_CHECK_EQUAL(kp.secret().makeInsecure(), secret.makeInsecure());
56 }
57 
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
Definition: Arith256.cpp:15
BOOST_AUTO_TEST_CASE(jsToPublic)
Definition: commonjs.cpp:34
Simple class that represents a "key pair".
Definition: Common.h:150
std::hash for asio::adress
Definition: Common.h:323
Secret const & secret() const
Definition: Common.h:167
Public const & pub() const
Retrieve the public key.
Definition: Common.h:170
FixedHash< T > const & makeInsecure() const
Definition: FixedHash.h:253
std::string toJS(FixedHash< S > const &_h)
Definition: CommonJS.h:34
Address jsToAddress(std::string const &_s)
Leniently convert string to Address (h160). Accepts integers, "0x" prefixing, non-exact length...
Definition: CommonJS.h:43
Public jsToPublic(std::string const &_s)
Leniently convert string to Public (h512). Accepts integers, "0x" prefixing, non-exact length...
Definition: CommonJS.h:37
Address const & address() const
Retrieve the associated address of the public key.
Definition: Common.h:173
#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
struct evm_uint160be address(struct evm_env *env)
Definition: capi.c:13
Helper functions to work with json::spirit and test files.
Secret jsToSecret(std::string const &_s)
Leniently convert string to Secret (h256). Accepts integers, "0x" prefixing, non-exact length...
Definition: CommonJS.h:40