2017-07-23 12:38:17 +02:00
|
|
|
/*
|
2017-11-09 19:34:51 +01:00
|
|
|
* This file is part of the Flowee project
|
2021-06-20 22:44:44 +02:00
|
|
|
* Copyright (C) 2017,2019 Tom Zander <tom@flowee.org>
|
2017-07-23 12:38:17 +02:00
|
|
|
*
|
|
|
|
|
* 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/>.
|
|
|
|
|
*/
|
2017-07-23 17:44:18 +02:00
|
|
|
#include "test/test_bitcoin.h"
|
|
|
|
|
|
2017-07-23 12:38:17 +02:00
|
|
|
#include <boost/test/auto_unit_test.hpp>
|
|
|
|
|
#include <Application.h>
|
|
|
|
|
#include <chain.h>
|
|
|
|
|
#include <chainparams.h>
|
2017-07-23 17:44:18 +02:00
|
|
|
#include <main.h>
|
2018-01-15 15:26:12 +00:00
|
|
|
#include <script/interpreter.h>
|
2017-07-23 17:44:18 +02:00
|
|
|
#include <consensus/validation.h>
|
2017-07-23 12:38:17 +02:00
|
|
|
|
2018-01-15 15:26:12 +00:00
|
|
|
BOOST_FIXTURE_TEST_SUITE(UAHF, TestingSetup)
|
2017-07-23 12:38:17 +02:00
|
|
|
|
2017-08-11 12:21:50 +02:00
|
|
|
BOOST_AUTO_TEST_CASE(Test_transactionAcceptance)
|
|
|
|
|
{
|
|
|
|
|
// Generate a 101-block chain:
|
2022-07-06 22:12:33 +02:00
|
|
|
PrivateKey coinbaseKey;
|
2021-11-02 10:18:24 +01:00
|
|
|
std::vector<Block> blocks = bv.appendChain(101, coinbaseKey, MockBlockValidation::StandardOutScript);
|
2022-05-11 13:46:15 +02:00
|
|
|
const CScript scriptPubKey = CScript() << ToByteVector(coinbaseKey.getPubKey()) << OP_CHECKSIG;
|
2021-11-02 10:18:24 +01:00
|
|
|
Block first = blocks[0];
|
2018-01-15 15:26:12 +00:00
|
|
|
first.findTransactions();
|
|
|
|
|
Tx coinbase1 = first.transactions().front();
|
|
|
|
|
const uint256 hash0 = coinbase1.createHash();
|
2021-11-02 10:18:24 +01:00
|
|
|
Block second = blocks[1];
|
2018-01-15 15:26:12 +00:00
|
|
|
second.findTransactions();
|
|
|
|
|
Tx coinbase2 = second.transactions().front();
|
|
|
|
|
const uint256 hash1 = coinbase2.createHash();
|
2017-08-11 12:21:50 +02:00
|
|
|
|
|
|
|
|
CMutableTransaction tx;
|
|
|
|
|
tx.vin.resize(1);
|
|
|
|
|
tx.vin[0].prevout.hash = hash1;
|
|
|
|
|
tx.vin[0].prevout.n = 0;
|
|
|
|
|
tx.vout.resize(1);
|
|
|
|
|
tx.vout[0].nValue = 50*COIN;
|
|
|
|
|
tx.vout[0].scriptPubKey = CScript() << OP_TRUE;
|
|
|
|
|
|
|
|
|
|
// build proper transaction, properly signed
|
|
|
|
|
uint256 newHash = SignatureHash(scriptPubKey, tx, 0, 50 * COIN,
|
|
|
|
|
SIGHASH_ALL | SIGHASH_FORKID, SCRIPT_ENABLE_SIGHASH_FORKID);
|
|
|
|
|
std::vector<unsigned char> vchSig;
|
2021-04-19 15:45:02 +02:00
|
|
|
bool ok = coinbaseKey.signECDSA(newHash, vchSig);
|
2017-08-11 12:21:50 +02:00
|
|
|
BOOST_CHECK(ok);
|
|
|
|
|
vchSig.push_back((unsigned char)SIGHASH_ALL | SIGHASH_FORKID);
|
|
|
|
|
tx.vin[0].scriptSig << vchSig;
|
|
|
|
|
{ // Check if this will be acceptable to the mempool
|
|
|
|
|
fRequireStandard = false;
|
2018-01-15 15:26:12 +00:00
|
|
|
auto future = bv.addTransaction(Tx::fromOldTransaction(tx));
|
|
|
|
|
std::string error = future.get();
|
|
|
|
|
if (!error.empty())
|
|
|
|
|
logDebug() << "::" << error;
|
|
|
|
|
BOOST_CHECK(error.empty());
|
2017-08-11 12:21:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// next transaction, without FORKID
|
|
|
|
|
tx.vin[0].prevout.hash = hash0;
|
|
|
|
|
newHash = SignatureHash(scriptPubKey, tx, 0, 50 * COIN, SIGHASH_ALL);
|
|
|
|
|
vchSig.clear();
|
2021-04-19 15:45:02 +02:00
|
|
|
ok = coinbaseKey.signECDSA(newHash, vchSig);
|
2017-08-11 12:21:50 +02:00
|
|
|
BOOST_CHECK(ok);
|
|
|
|
|
vchSig.push_back((unsigned char)SIGHASH_ALL);
|
|
|
|
|
tx.vin[0].scriptSig << vchSig;
|
|
|
|
|
{ // Check if this will be acceptable to the mempool
|
2018-01-15 15:26:12 +00:00
|
|
|
auto future = bv.addTransaction(Tx::fromOldTransaction(tx));
|
|
|
|
|
std::string error = future.get();
|
|
|
|
|
if (error.empty())
|
|
|
|
|
logDebug() << "::" << error;
|
|
|
|
|
BOOST_CHECK(!error.empty());
|
2017-08-11 12:21:50 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-23 12:38:17 +02:00
|
|
|
BOOST_AUTO_TEST_SUITE_END()
|