2021-03-05 19:10:51 +01:00
|
|
|
/*
|
|
|
|
|
* This file is part of the Flowee project
|
|
|
|
|
* Copyright (C) 2021 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 "MetaBlock_tests.h"
|
|
|
|
|
|
|
|
|
|
#include <BlockMetaData.h>
|
2021-03-08 13:47:33 +01:00
|
|
|
#include <streaming/BufferPool.h>
|
2021-11-02 10:23:33 +01:00
|
|
|
#include <primitives/Block.h>
|
2021-03-05 19:10:51 +01:00
|
|
|
|
|
|
|
|
TestMetaBlock::TestMetaBlock()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TestMetaBlock::testCreation()
|
|
|
|
|
{
|
|
|
|
|
QFile input(":/blockdata");
|
2023-12-21 15:13:56 +01:00
|
|
|
auto pool = std::make_shared<Streaming::BufferPool>();
|
2021-03-05 19:10:51 +01:00
|
|
|
bool ok = input.open(QIODevice::ReadOnly);
|
|
|
|
|
QVERIFY(ok);
|
2023-12-21 15:13:56 +01:00
|
|
|
auto size = input.read(pool->begin(), pool->capacity());
|
|
|
|
|
Block block(pool->commit(size));
|
2021-03-05 19:10:51 +01:00
|
|
|
QVERIFY(block.createHash()
|
|
|
|
|
== uint256S("0x00000000000000000560372e0caadc38c56cde6c4aaae03287a6898e643e5b8a"));
|
|
|
|
|
|
2021-03-10 19:44:50 +01:00
|
|
|
std::vector<std::unique_ptr<std::deque<std::int32_t> > > feesVector;
|
|
|
|
|
BlockMetaData noFeesMD = BlockMetaData::parseBlock(13451, block, feesVector, pool);
|
|
|
|
|
auto coinbase = noFeesMD.first();
|
|
|
|
|
// no fees vector sets the coinbase to a non-zero value.
|
|
|
|
|
QCOMPARE(coinbase->fees, 0xFFFFFF);
|
|
|
|
|
QCOMPARE(coinbase->next()->fees, 0);
|
2021-03-08 13:47:33 +01:00
|
|
|
|
2021-03-10 19:44:50 +01:00
|
|
|
feesVector.resize(1);
|
|
|
|
|
feesVector[0].reset(new std::deque<std::int32_t>());
|
|
|
|
|
feesVector[0]->push_back(8475); // first one should go to the first real transaction (not coinbase);
|
|
|
|
|
BlockMetaData md = BlockMetaData::parseBlock(13451, block, feesVector, pool);
|
2021-03-05 19:10:51 +01:00
|
|
|
QCOMPARE(md.blockHeight(), 13451);
|
|
|
|
|
QCOMPARE(md.txCount(), 94);
|
2021-03-10 19:44:50 +01:00
|
|
|
coinbase = md.first();
|
2021-03-05 19:10:51 +01:00
|
|
|
QCOMPARE(coinbase->offsetInBlock, 81);
|
2021-03-08 13:47:33 +01:00
|
|
|
QCOMPARE(coinbase->fees, 0);
|
2021-03-05 19:10:51 +01:00
|
|
|
auto nextTx = coinbase->next();
|
|
|
|
|
QCOMPARE(nextTx->offsetInBlock, 248);
|
2021-03-08 13:47:33 +01:00
|
|
|
QCOMPARE(nextTx->fees, 8475);
|
|
|
|
|
QCOMPARE(nextTx->next()->fees, 0);
|
2021-03-05 19:10:51 +01:00
|
|
|
|
|
|
|
|
BlockMetaData md2(md.data());
|
|
|
|
|
QCOMPARE(md2.blockHeight(), 13451);
|
|
|
|
|
QCOMPARE(md2.txCount(), 94);
|
|
|
|
|
coinbase = md2.first();
|
|
|
|
|
QCOMPARE(coinbase->offsetInBlock, 81);
|
2021-03-08 13:47:33 +01:00
|
|
|
QCOMPARE(coinbase->fees, 0);
|
2021-03-05 19:10:51 +01:00
|
|
|
nextTx = coinbase->next();
|
|
|
|
|
QCOMPARE(nextTx->offsetInBlock, 248);
|
2021-03-08 13:47:33 +01:00
|
|
|
QCOMPARE(nextTx->fees, 8475);
|
|
|
|
|
QCOMPARE(nextTx->next()->fees, 0);
|
2021-03-05 19:10:51 +01:00
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
md2.tx(0);
|
|
|
|
|
md2.tx(50);
|
|
|
|
|
md2.tx(93);
|
|
|
|
|
} catch (...) {
|
|
|
|
|
QFAIL("Should not throw");
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
md2.tx(94);
|
|
|
|
|
QFAIL("Out of bounds, should have thrown");
|
|
|
|
|
} catch (...) { }
|
|
|
|
|
}
|