Changeset View
Changeset View
Standalone View
Standalone View
src/test/dstencode_tests.cpp
// Copyright (c) 2017 The Bitcoin developers | // Copyright (c) 2017 The Bitcoin developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include "chainparams.h" | #include "chainparams.h" | ||||
#include "config.h" | #include "config.h" | ||||
#include "dstencode.h" | #include "dstencode.h" | ||||
#include "test/test_bitcoin.h" | #include "test/test_bitcoin.h" | ||||
#include <boost/test/unit_test.hpp> | #include <boost/test/unit_test.hpp> | ||||
namespace { | namespace { | ||||
class DummyCfg : public Config { | class DstCfgDummy : public DummyConfig { | ||||
public: | public: | ||||
DummyCfg() : useCashAddr(false) {} | DstCfgDummy() : useCashAddr(false) {} | ||||
virtual bool SetMaxBlockSize(uint64_t maxBlockSize) { return false; } | void SetCashAddrEncoding(bool b) override { useCashAddr = b; } | ||||
virtual uint64_t GetMaxBlockSize() const { return 0; } | bool UseCashAddrEncoding() const override { return useCashAddr; } | ||||
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: | private: | ||||
bool useCashAddr; | bool useCashAddr; | ||||
}; | }; | ||||
} // anon ns | } // anon ns | ||||
BOOST_FIXTURE_TEST_SUITE(dstencode_tests, BasicTestingSetup) | BOOST_FIXTURE_TEST_SUITE(dstencode_tests, BasicTestingSetup) | ||||
Show All 9 Lines | BOOST_AUTO_TEST_CASE(test_addresses) { | ||||
std::string cashaddr_pubkey = | std::string cashaddr_pubkey = | ||||
"bitcoincash:qpm2qsznhks23z7629mms6s4cwef74vcwvy22gdx6a"; | "bitcoincash:qpm2qsznhks23z7629mms6s4cwef74vcwvy22gdx6a"; | ||||
std::string cashaddr_script = | std::string cashaddr_script = | ||||
"bitcoincash:ppm2qsznhks23z7629mms6s4cwef74vcwvn0h829pq"; | "bitcoincash:ppm2qsznhks23z7629mms6s4cwef74vcwvn0h829pq"; | ||||
std::string base58_pubkey = "1BpEi6DfDAUFd7GtittLSdBeYJvcoaVggu"; | std::string base58_pubkey = "1BpEi6DfDAUFd7GtittLSdBeYJvcoaVggu"; | ||||
std::string base58_script = "3CWFddi6m4ndiGyKqzYvsFYagqDLPVMTzC"; | std::string base58_script = "3CWFddi6m4ndiGyKqzYvsFYagqDLPVMTzC"; | ||||
const CChainParams ¶ms = Params(CBaseChainParams::MAIN); | const CChainParams ¶ms = Params(CBaseChainParams::MAIN); | ||||
DummyCfg cfg; | DstCfgDummy cfg; | ||||
// Check encoding | // Check encoding | ||||
cfg.SetCashAddrEncoding(true); | cfg.SetCashAddrEncoding(true); | ||||
BOOST_CHECK_EQUAL(cashaddr_pubkey, EncodeDestination(dstKey, params, cfg)); | BOOST_CHECK_EQUAL(cashaddr_pubkey, EncodeDestination(dstKey, params, cfg)); | ||||
BOOST_CHECK_EQUAL(cashaddr_script, | BOOST_CHECK_EQUAL(cashaddr_script, | ||||
EncodeDestination(dstScript, params, cfg)); | EncodeDestination(dstScript, params, cfg)); | ||||
cfg.SetCashAddrEncoding(false); | cfg.SetCashAddrEncoding(false); | ||||
BOOST_CHECK_EQUAL(base58_pubkey, EncodeDestination(dstKey, params, cfg)); | BOOST_CHECK_EQUAL(base58_pubkey, EncodeDestination(dstKey, params, cfg)); | ||||
Show All 17 Lines |