Skip to content

Commit

Permalink
Merge pull request #4 from chongada/master
Browse files Browse the repository at this point in the history
Made changes to the testnet and test
  • Loading branch information
butkcore-dev authored Jun 16, 2021
2 parents fbfea9d + 0578a67 commit ac1827f
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 47 deletions.
12 changes: 6 additions & 6 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -612,18 +612,18 @@ class CTestNetParams : public CChainParams {
pchMessageStart[3] = 0xff;
nDefaultPort = 34340;
nPruneAfterHeight = 1000;
// FindMainNetGenesisBlock(1618300101, 0x20001fff, "test");
genesis = CreateGenesisBlock(1618300101, 3217, 0x20001fff, 4, 5000 * COIN);
// FindMainNetGenesisBlock(1618300101, 0x20001fff, "test");
genesis = CreateGenesisBlock(1618300101, 1957, 0x20001fff, 4, 5000 * COIN);
consensus.hashGenesisBlock = genesis.GetHash();
assert(consensus.hashGenesisBlock == uint256S("0x93055579e7cf39aa6434f445dcf415f9fe7319127b5309a61813b9e775f62192"));
assert(consensus.hashGenesisBlock == uint256S("0x001efd3021f4414e897125d9e85ec42c3e0dc360d2b6ce7853e7a2900448c63a"));
assert(genesis.hashMerkleRoot == uint256S("0xc083fb7c3b6936c15dc2685a522ffa685247e8c665c818888b51b0771584d7b4"));

vFixedSeeds.clear();
vFixedSeeds = std::vector<SeedSpec6>(pnSeed6_test, pnSeed6_test + ARRAYLEN(pnSeed6_test));

vSeeds.clear();
// nodes with support for servicebits filtering should be at the top
vSeeds.emplace_back("testnet-seed.but.xyz", true);
vSeeds.emplace_back("testnet.butcoin.xyz", true);

// Testnet But addresses start with 'y'
base58Prefixes[PUBKEY_ADDRESS] = std::vector<unsigned char>(1,140);
Expand Down Expand Up @@ -661,13 +661,13 @@ class CTestNetParams : public CChainParams {
nPoolMaxParticipants = 5;
nFulfilledRequestExpireTime = 5*60; // fulfilled requests expire in 5 minutes

vSporkAddresses = {"yjPtiKh2uwk3bDutTEA2q9mCtXyiZRWn55"};
vSporkAddresses = {"yVeVxPpzbebak4EZdASJdrnCSPZfAucLNv"};
nMinSporkKeys = 1;
fBIP9CheckSmartnodesUpgraded = true;

checkpointData = (CCheckpointData) {
{
{0, uint256S("0x93055579e7cf39aa6434f445dcf415f9fe7319127b5309a61813b9e775f62192")},
{0, uint256S("0x001efd3021f4414e897125d9e85ec42c3e0dc360d2b6ce7853e7a2900448c63a")},
}
};

Expand Down
34 changes: 17 additions & 17 deletions src/test/miner_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ void TestPackageSelection(const CChainParams& chainparams, CScript scriptPubKey,
uint256 hashHighFeeTx = tx.GetHash();
mempool.addUnchecked(hashHighFeeTx, entry.Fee(50000).Time(GetTime()).SpendsCoinbase(false).FromTx(tx));

std::unique_ptr<CBlockTemplate> pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey);
std::unique_ptr<CBlockTemplate> pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey, miningAlgo);
BOOST_CHECK(pblocktemplate->block.vtx[1]->GetHash() == hashParentTx);
BOOST_CHECK(pblocktemplate->block.vtx[2]->GetHash() == hashHighFeeTx);
BOOST_CHECK(pblocktemplate->block.vtx[3]->GetHash() == hashMediumFeeTx);
Expand All @@ -144,7 +144,7 @@ void TestPackageSelection(const CChainParams& chainparams, CScript scriptPubKey,
tx.vout[0].nValue = 5000000000LL - 1000 - 50000 - feeToUse;
uint256 hashLowFeeTx = tx.GetHash();
mempool.addUnchecked(hashLowFeeTx, entry.Fee(feeToUse).FromTx(tx));
pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey);
pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey, miningAlgo);
// Verify that the free tx and the low fee tx didn't get selected
for (size_t i=0; i<pblocktemplate->block.vtx.size(); ++i) {
BOOST_CHECK(pblocktemplate->block.vtx[i]->GetHash() != hashFreeTx);
Expand All @@ -158,7 +158,7 @@ void TestPackageSelection(const CChainParams& chainparams, CScript scriptPubKey,
tx.vout[0].nValue -= 2; // Now we should be just over the min relay fee
hashLowFeeTx = tx.GetHash();
mempool.addUnchecked(hashLowFeeTx, entry.Fee(feeToUse+2).FromTx(tx));
pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey);
pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey, miningAlgo);
BOOST_CHECK(pblocktemplate->block.vtx[4]->GetHash() == hashFreeTx);
BOOST_CHECK(pblocktemplate->block.vtx[5]->GetHash() == hashLowFeeTx);

Expand All @@ -179,7 +179,7 @@ void TestPackageSelection(const CChainParams& chainparams, CScript scriptPubKey,
tx.vout[0].nValue = 5000000000LL - 100000000 - feeToUse;
uint256 hashLowFeeTx2 = tx.GetHash();
mempool.addUnchecked(hashLowFeeTx2, entry.Fee(feeToUse).SpendsCoinbase(false).FromTx(tx));
pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey);
pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey, miningAlgo);

// Verify that this tx isn't selected.
for (size_t i=0; i<pblocktemplate->block.vtx.size(); ++i) {
Expand All @@ -192,7 +192,7 @@ void TestPackageSelection(const CChainParams& chainparams, CScript scriptPubKey,
tx.vin[0].prevout.n = 1;
tx.vout[0].nValue = 100000000 - 10000; // 10k satoshi fee
mempool.addUnchecked(tx.GetHash(), entry.Fee(10000).FromTx(tx));
pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey);
pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey, miningAlgo);
BOOST_CHECK(pblocktemplate->block.vtx[8]->GetHash() == hashLowFeeTx2);
}

Expand All @@ -213,7 +213,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
fCheckpointsEnabled = false;

// Simple block creation, nothing special yet:
BOOST_CHECK(pemptyblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey));
BOOST_CHECK(pemptyblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey, miningAlgo));

// We can't make transactions until we have inputs
// Therefore, load 100 blocks :)
Expand Down Expand Up @@ -261,7 +261,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
LOCK(cs_main);

// Just to make sure we can still make simple blocks
BOOST_CHECK(pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey));
BOOST_CHECK(pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey, miningAlgo));

const CAmount BLOCKSUBSIDY = 500*COIN;
const CAmount LOWFEE = CENT;
Expand All @@ -285,7 +285,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
mempool.addUnchecked(hash, entry.Fee(LOWFEE).Time(GetTime()).SpendsCoinbase(spendsCoinbase).FromTx(tx));
tx.vin[0].prevout.hash = hash;
}
BOOST_CHECK_THROW(AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey), std::runtime_error);
BOOST_CHECK_THROW(AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey, miningAlgo), std::runtime_error);
mempool.clear();

tx.vin[0].prevout.hash = txFirst[0]->GetHash();
Expand All @@ -299,7 +299,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
mempool.addUnchecked(hash, entry.Fee(LOWFEE).Time(GetTime()).SpendsCoinbase(spendsCoinbase).SigOps(20).FromTx(tx));
tx.vin[0].prevout.hash = hash;
}
BOOST_CHECK(pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey));
BOOST_CHECK(pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey, miningAlgo));
mempool.clear();

// block size > limit
Expand All @@ -319,13 +319,13 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
mempool.addUnchecked(hash, entry.Fee(LOWFEE).Time(GetTime()).SpendsCoinbase(spendsCoinbase).FromTx(tx));
tx.vin[0].prevout.hash = hash;
}
BOOST_CHECK(pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey));
BOOST_CHECK(pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey, miningAlgo));
mempool.clear();

// orphan in mempool, template creation fails
hash = tx.GetHash();
mempool.addUnchecked(hash, entry.Fee(LOWFEE).Time(GetTime()).FromTx(tx));
BOOST_CHECK_THROW(AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey), std::runtime_error);
BOOST_CHECK_THROW(AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey, miningAlgo), std::runtime_error);
mempool.clear();

// child with higher feerate than parent
Expand All @@ -342,7 +342,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
tx.vout[0].nValue = tx.vout[0].nValue+BLOCKSUBSIDY-HIGHERFEE; //First txn output + fresh coinbase - new txn fee
hash = tx.GetHash();
mempool.addUnchecked(hash, entry.Fee(HIGHERFEE).Time(GetTime()).SpendsCoinbase(true).FromTx(tx));
BOOST_CHECK(pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey));
BOOST_CHECK(pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey, miningAlgo));
mempool.clear();

// coinbase in mempool, template creation fails
Expand All @@ -353,7 +353,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
hash = tx.GetHash();
// give it a fee so it'll get mined
mempool.addUnchecked(hash, entry.Fee(LOWFEE).Time(GetTime()).SpendsCoinbase(false).FromTx(tx));
BOOST_CHECK_THROW(AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey), std::runtime_error);
BOOST_CHECK_THROW(AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey, miningAlgo), std::runtime_error);
mempool.clear();

// invalid (pre-p2sh) txn in mempool, template creation fails
Expand All @@ -370,7 +370,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
tx.vout[0].nValue -= LOWFEE;
hash = tx.GetHash();
mempool.addUnchecked(hash, entry.Fee(LOWFEE).Time(GetTime()).SpendsCoinbase(false).FromTx(tx));
BOOST_CHECK_THROW(AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey), std::runtime_error);
BOOST_CHECK_THROW(AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey, miningAlgo), std::runtime_error);
mempool.clear();

// double spend txn pair in mempool, template creation fails
Expand All @@ -383,7 +383,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
tx.vout[0].scriptPubKey = CScript() << OP_2;
hash = tx.GetHash();
mempool.addUnchecked(hash, entry.Fee(HIGHFEE).Time(GetTime()).SpendsCoinbase(true).FromTx(tx));
BOOST_CHECK_THROW(AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey), std::runtime_error);
BOOST_CHECK_THROW(AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey, miningAlgo), std::runtime_error);
mempool.clear();

// subsidy changing
Expand Down Expand Up @@ -497,7 +497,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
tx.vin[0].nSequence = CTxIn::SEQUENCE_LOCKTIME_TYPE_FLAG | 1;
BOOST_CHECK(!TestSequenceLocks(tx, flags)); // Sequence locks fail

BOOST_CHECK(pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey));
BOOST_CHECK(pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey, miningAlgo));

// None of the of the absolute height/time locked tx should have made
// it into the template because we still check IsFinalTx in CreateNewBlock,
Expand All @@ -517,7 +517,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)

SetMockTime(chainActive.Tip()->GetMedianTimePast() + 1);

BOOST_CHECK(pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey));
BOOST_CHECK(pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey, miningAlgo));
BOOST_CHECK_EQUAL(pblocktemplate->block.vtx.size(), 5);

CValidationState state;
Expand Down
22 changes: 12 additions & 10 deletions src/test/pow_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ BOOST_FIXTURE_TEST_SUITE(pow_tests, BasicTestingSetup)
/* Test calculation of next difficulty target with DGW */
BOOST_AUTO_TEST_CASE(get_next_work)
{
const auto chainParams = CreateChainParams(CBaseChainParams::MAIN);

// build the chain of 24 blocks
SelectParams(CBaseChainParams::MAIN);
const Consensus::Params& params = Params().GetConsensus();
// build the chain of 24 blocks
CBlockIndex blockIndexLast;
blockIndexLast.nHeight = 123456;
blockIndexLast.nTime = 1408732489;
Expand Down Expand Up @@ -118,26 +118,28 @@ BOOST_AUTO_TEST_CASE(get_next_work)

CBlockHeader blockHeader;
blockHeader.nTime = 1408732505; // Block #123457
BOOST_CHECK_EQUAL(GetNextWorkRequired(&blockIndexLast, &blockHeader, chainParams->GetConsensus()), 0x1b1441de); // Block #123457 has 0x1b1441de
BOOST_CHECK_EQUAL(GetNextWorkRequired(&blockIndexLast, &blockHeader, params, miningAlgo), 0x1b1441de); // Block #123457 has 0x1b1441de

// test special rules for slow blocks on devnet/testnet
// test special rules for slow blocks on devnet/testnet
gArgs.SoftSetBoolArg("-devnet", true);
const auto chainParamsDev = CreateChainParams(CBaseChainParams::DEVNET);
SelectParams(CBaseChainParams::DEVNET);
const Consensus::Params& paramsdev = Params().GetConsensus();

// make sure normal rules apply
blockHeader.nTime = 1408732505; // Block #123457
BOOST_CHECK_EQUAL(GetNextWorkRequired(&blockIndexLast, &blockHeader, chainParamsDev->GetConsensus()), 0x1b1441de); // Block #123457 has 0x1b1441de
BOOST_CHECK_EQUAL(GetNextWorkRequired(&blockIndexLast, &blockHeader, paramsdev, miningAlgo), 0x1b1441de); // Block #123457 has 0x1b1441de

// 10x higher target
blockHeader.nTime = 1408733090; // Block #123457 (10m+1sec)
BOOST_CHECK_EQUAL(GetNextWorkRequired(&blockIndexLast, &blockHeader, chainParamsDev->GetConsensus()), 0x1c00c8f8); // Block #123457 has 0x1c00c8f8
BOOST_CHECK_EQUAL(GetNextWorkRequired(&blockIndexLast, &blockHeader, paramsdev, miningAlgo), 0x1c00c8f8); // Block #123457 has 0x1c00c8f8
blockHeader.nTime = 1408733689; // Block #123457 (20m)
BOOST_CHECK_EQUAL(GetNextWorkRequired(&blockIndexLast, &blockHeader, chainParamsDev->GetConsensus()), 0x1c00c8f8); // Block #123457 has 0x1c00c8f8
BOOST_CHECK_EQUAL(GetNextWorkRequired(&blockIndexLast, &blockHeader, paramsdev, miningAlgo), 0x1c00c8f8); // Block #123457 has 0x1c00c8f8
// lowest diff possible
blockHeader.nTime = 1408739690; // Block #123457 (2h+1sec)
BOOST_CHECK_EQUAL(GetNextWorkRequired(&blockIndexLast, &blockHeader, chainParamsDev->GetConsensus()), 0x207fffff); // Block #123457 has 0x207fffff
BOOST_CHECK_EQUAL(GetNextWorkRequired(&blockIndexLast, &blockHeader, paramsdev, miningAlgo), 0x207fffff); // Block #123457 has 0x207fffff
blockHeader.nTime = 1408743289; // Block #123457 (3h)
BOOST_CHECK_EQUAL(GetNextWorkRequired(&blockIndexLast, &blockHeader, chainParamsDev->GetConsensus()), 0x207fffff); // Block #123457 has 0x207fffff
BOOST_CHECK_EQUAL(GetNextWorkRequired(&blockIndexLast, &blockHeader, paramsdev, miningAlgo), 0x207fffff); // Block #123457 has 0x207fffff
}

/* Test the constraint on the upper bound for next work */
Expand Down
2 changes: 1 addition & 1 deletion src/test/test_but.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ CBlock TestChainSetup::CreateAndProcessBlock(const std::vector<CMutableTransacti
CBlock TestChainSetup::CreateBlock(const std::vector<CMutableTransaction>& txns, const CScript& scriptPubKey)
{
const CChainParams& chainparams = Params();
std::unique_ptr<CBlockTemplate> pblocktemplate = BlockAssembler(chainparams).CreateNewBlock(scriptPubKey);
std::unique_ptr<CBlockTemplate> pblocktemplate = BlockAssembler(chainparams).CreateNewBlock(scriptPubKey, miningAlgo);
CBlock& block = pblocktemplate->block;

std::vector<CTransactionRef> llmqCommitments;
Expand Down
Loading

0 comments on commit ac1827f

Please sign in to comment.