Changeset View
Changeset View
Standalone View
Standalone View
src/test/dstencode_tests.cpp
- This file was added.
// Copyright (c) 2017 The Bitcoin developers | |||||
// Distributed under the MIT software license, see the accompanying | |||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | |||||
#include "chainparams.h" | |||||
#include "config.h" | |||||
#include "dstencode.h" | |||||
#include "test/test_bitcoin.h" | |||||
#include <boost/test/unit_test.hpp> | |||||
namespace { | |||||
class DummyCfg : public Config { | |||||
public: | |||||
DummyCfg() : useCashAddr(false) {} | |||||
virtual bool SetMaxBlockSize(uint64_t maxBlockSize) { return false; } | |||||
virtual uint64_t GetMaxBlockSize() const { return 0; } | |||||
virtual bool SetBlockPriorityPercentage(int64_t blockPriorityPercentage) { | |||||
return false; | |||||
} | |||||
virtual uint8_t GetBlockPriorityPercentage() const { return 0; } | |||||
virtual const CChainParams &GetChainParams() const { | |||||
return Params(CBaseChainParams::MAIN); | |||||
} | |||||
virtual void SetCashAddrEncoding(bool b) { useCashAddr = b; } | |||||
virtual bool UseCashAddrEncoding() const { return useCashAddr; } | |||||
private: | |||||
bool useCashAddr; | |||||
}; | |||||
} // anon ns | |||||
BOOST_FIXTURE_TEST_SUITE(dstencode_tests, BasicTestingSetup) | |||||
BOOST_AUTO_TEST_CASE(test_addresses) { | |||||
std::vector<uint8_t> hash = {118, 160, 64, 83, 189, 160, 168, | |||||
139, 218, 81, 119, 184, 106, 21, | |||||
195, 178, 159, 85, 152, 115}; | |||||
const CTxDestination dstKey = CKeyID(uint160(hash)); | |||||
const CTxDestination dstScript = CScriptID(uint160(hash)); | |||||
std::string cashaddr_pubkey = | |||||
"bitcoincash:qpm2qsznhks23z7629mms6s4cwef74vcwvy22gdx6a"; | |||||
std::string cashaddr_script = | |||||
"bitcoincash:ppm2qsznhks23z7629mms6s4cwef74vcwvn0h829pq"; | |||||
std::string base58_pubkey = "1BpEi6DfDAUFd7GtittLSdBeYJvcoaVggu"; | |||||
std::string base58_script = "3CWFddi6m4ndiGyKqzYvsFYagqDLPVMTzC"; | |||||
const CChainParams ¶ms = Params(CBaseChainParams::MAIN); | |||||
DummyCfg cfg; | |||||
// Check encoding | |||||
cfg.SetCashAddrEncoding(true); | |||||
BOOST_CHECK_EQUAL(cashaddr_pubkey, EncodeDestination(dstKey, params, cfg)); | |||||
BOOST_CHECK_EQUAL(cashaddr_script, | |||||
EncodeDestination(dstScript, params, cfg)); | |||||
cfg.SetCashAddrEncoding(false); | |||||
BOOST_CHECK_EQUAL(base58_pubkey, EncodeDestination(dstKey, params, cfg)); | |||||
BOOST_CHECK_EQUAL(base58_script, EncodeDestination(dstScript, params, cfg)); | |||||
// Check decoding | |||||
BOOST_CHECK(dstKey == DecodeDestination(cashaddr_pubkey, params)); | |||||
BOOST_CHECK(dstScript == DecodeDestination(cashaddr_script, params)); | |||||
BOOST_CHECK(dstKey == DecodeDestination(base58_pubkey, params)); | |||||
BOOST_CHECK(dstScript == DecodeDestination(base58_script, params)); | |||||
// Validation | |||||
BOOST_CHECK(IsValidDestinationString(cashaddr_pubkey, params)); | |||||
BOOST_CHECK(IsValidDestinationString(cashaddr_script, params)); | |||||
BOOST_CHECK(IsValidDestinationString(base58_pubkey, params)); | |||||
BOOST_CHECK(IsValidDestinationString(base58_script, params)); | |||||
BOOST_CHECK(!IsValidDestinationString("notvalid", params)); | |||||
} | |||||
BOOST_AUTO_TEST_SUITE_END() |