/* * This file is part of the Flowee project * Copyright (C) 2021 Tom Zander * * 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 . */ #include "MetaBlock_tests.h" #include #include #include TestMetaBlock::TestMetaBlock() { } void TestMetaBlock::testCreation() { QFile input(":/blockdata"); auto pool = std::make_shared(); bool ok = input.open(QIODevice::ReadOnly); QVERIFY(ok); auto size = input.read(pool->begin(), pool->capacity()); Block block(pool->commit(size)); QVERIFY(block.createHash() == uint256S("0x00000000000000000560372e0caadc38c56cde6c4aaae03287a6898e643e5b8a")); std::vector > > 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); feesVector.resize(1); feesVector[0].reset(new std::deque()); feesVector[0]->push_back(8475); // first one should go to the first real transaction (not coinbase); BlockMetaData md = BlockMetaData::parseBlock(13451, block, feesVector, pool); QCOMPARE(md.blockHeight(), 13451); QCOMPARE(md.txCount(), 94); coinbase = md.first(); QCOMPARE(coinbase->offsetInBlock, 81); QCOMPARE(coinbase->fees, 0); auto nextTx = coinbase->next(); QCOMPARE(nextTx->offsetInBlock, 248); QCOMPARE(nextTx->fees, 8475); QCOMPARE(nextTx->next()->fees, 0); BlockMetaData md2(md.data()); QCOMPARE(md2.blockHeight(), 13451); QCOMPARE(md2.txCount(), 94); coinbase = md2.first(); QCOMPARE(coinbase->offsetInBlock, 81); QCOMPARE(coinbase->fees, 0); nextTx = coinbase->next(); QCOMPARE(nextTx->offsetInBlock, 248); QCOMPARE(nextTx->fees, 8475); QCOMPARE(nextTx->next()->fees, 0); 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 (...) { } }