77 lines
3.1 KiB
C++
77 lines
3.1 KiB
C++
|
|
/*
|
||
|
|
* This file is part of the Flowee project
|
||
|
|
* Copyright (C) 2026 Tom Zander <tom@flowee.org>
|
||
|
|
*
|
||
|
|
* This program is free software: you can redistribute it and/or modify
|
||
|
|
* it under the terms of the GNU General Public License as published by
|
||
|
|
* the Free Software Foundation, either version 3 of the License, or
|
||
|
|
* (at your option) any later version.
|
||
|
|
*
|
||
|
|
* This program is distributed in the hope that it will be useful,
|
||
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
|
* GNU General Public License for more details.
|
||
|
|
*
|
||
|
|
* You should have received a copy of the GNU General Public License
|
||
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||
|
|
*/
|
||
|
|
#include "TestCashAddress.h"
|
||
|
|
#include "streaming/BufferPool.h"
|
||
|
|
#include <Logger.h>
|
||
|
|
|
||
|
|
#include <cashaddr.h>
|
||
|
|
|
||
|
|
#include <primitives/script.h>
|
||
|
|
|
||
|
|
void TestCashAddress::toScript()
|
||
|
|
{
|
||
|
|
auto content = CashAddress::decode("bitcoincash:qpl83jzctd048rvjf9kp5z8nd65y0c4zugf5m26j33", "bitcoincash");
|
||
|
|
QCOMPARE(content.hash.size(), 20);
|
||
|
|
auto script = CashAddress::createHashedOutputScript(content);
|
||
|
|
QCOMPARE(script.toHex(), "573c9f8d10e715d880b619ebe04acfd8e5d061b66bae79c08bc47291c359f745");
|
||
|
|
|
||
|
|
content = CashAddress::decode("bitcoincash:pvrtfxcklk4e74mqnnp0r6lg2u3lq4f8vk23ky2zf83gc9ufmksdv9zxavmtm", "bitcoincash");
|
||
|
|
QCOMPARE(content.hash.size(), 32);
|
||
|
|
script = CashAddress::createHashedOutputScript(content);
|
||
|
|
QCOMPARE(script.toHex(), "a5ab50587112779f0bc7b818d8cb0ff607e54c155a898ce17ae155422b26d02a");
|
||
|
|
}
|
||
|
|
|
||
|
|
void TestCashAddress::fromScript()
|
||
|
|
{
|
||
|
|
Streaming::BufferPool pool;
|
||
|
|
std::vector<uint8_t> address160 = {
|
||
|
|
0x20, 0x53, 0xf3, 0x01, 0x28, 0x9a, 0xb2, 0xdf, 0xf4, 0xbb,
|
||
|
|
0x20, 0x53, 0xf3, 0x01, 0x28, 0x9a, 0xb2, 0xdf, 0xf4, 0xbb
|
||
|
|
};
|
||
|
|
QCOMPARE(address160.size(), 20);
|
||
|
|
CScript s1 = CScript() << OP_DUP << OP_HASH160
|
||
|
|
<< address160 << OP_EQUALVERIFY << OP_CHECKSIG;
|
||
|
|
pool.write(&s1.front(), s1.size());
|
||
|
|
auto content = CashAddress::extractAddressFromScript(pool.commit());
|
||
|
|
QCOMPARE(content.hash.size(), 20);
|
||
|
|
QCOMPARE(content.type, CashAddress::PubkeyType);
|
||
|
|
compare(content.hash, address160);
|
||
|
|
|
||
|
|
CScript s2 = CScript() << OP_HASH160 << address160 << OP_EQUAL;
|
||
|
|
pool.write(&s2.front(), s2.size());
|
||
|
|
content = CashAddress::extractAddressFromScript(pool.commit());
|
||
|
|
QCOMPARE(content.hash.size(), 20);
|
||
|
|
QCOMPARE(content.type, CashAddress::ScriptType);
|
||
|
|
compare(content.hash, address160);
|
||
|
|
|
||
|
|
std::vector<uint8_t> address32 = {
|
||
|
|
0x20, 0x53, 0xf3, 0x01, 0x28, 0x9a, 0xb2, 0xdf, 0xf4, 0xbb,
|
||
|
|
0x20, 0x53, 0xf3, 0x01, 0x28, 0x9a, 0xb2, 0xdf, 0xf4, 0xbb,
|
||
|
|
0x20, 0x53, 0xf3, 0x01, 0x28, 0x9a, 0xb2, 0xdf, 0xf4, 0xbb,
|
||
|
|
0x20, 0x53
|
||
|
|
};
|
||
|
|
QCOMPARE(address32.size(), 32);
|
||
|
|
|
||
|
|
CScript s3 = CScript() << OP_HASH256 << address32 << OP_EQUAL;
|
||
|
|
pool.write(&s3.front(), s3.size());
|
||
|
|
content = CashAddress::extractAddressFromScript(pool.commit());
|
||
|
|
QCOMPARE(content.hash.size(), 32);
|
||
|
|
QCOMPARE(content.type, CashAddress::ScriptType);
|
||
|
|
compare(content.hash, address32);
|
||
|
|
}
|