Skip to content

Commit 2ba0c77

Browse files
authored
Add tests for special rules for slow blocks on devnet/testnet (#2176)
* Add tests for special rules for slow blocks on devnet/testnet * add 20m and 3h
1 parent b9a83d2 commit 2ba0c77

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/test/pow_tests.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,26 @@ BOOST_AUTO_TEST_CASE(get_next_work)
120120
CBlockHeader blockHeader;
121121
blockHeader.nTime = 1408732505; // Block #123457
122122
BOOST_CHECK_EQUAL(GetNextWorkRequired(&blockIndexLast, &blockHeader, params), 0x1b1441de); // Block #123457 has 0x1b1441de
123+
124+
// test special rules for slow blocks on devnet/testnet
125+
SoftSetBoolArg("-devnet", true);
126+
SelectParams(CBaseChainParams::DEVNET);
127+
const Consensus::Params& paramsdev = Params().GetConsensus();
128+
129+
// make sure normal rules apply
130+
blockHeader.nTime = 1408732505; // Block #123457
131+
BOOST_CHECK_EQUAL(GetNextWorkRequired(&blockIndexLast, &blockHeader, paramsdev), 0x1b1441de); // Block #123457 has 0x1b1441de
132+
133+
// 10x higher target
134+
blockHeader.nTime = 1408733090; // Block #123457 (10m+1sec)
135+
BOOST_CHECK_EQUAL(GetNextWorkRequired(&blockIndexLast, &blockHeader, paramsdev), 0x1c00c8f8); // Block #123457 has 0x1c00c8f8
136+
blockHeader.nTime = 1408733689; // Block #123457 (20m)
137+
BOOST_CHECK_EQUAL(GetNextWorkRequired(&blockIndexLast, &blockHeader, paramsdev), 0x1c00c8f8); // Block #123457 has 0x1c00c8f8
138+
// lowest diff possible
139+
blockHeader.nTime = 1408739690; // Block #123457 (2h+1sec)
140+
BOOST_CHECK_EQUAL(GetNextWorkRequired(&blockIndexLast, &blockHeader, paramsdev), 0x207fffff); // Block #123457 has 0x207fffff
141+
blockHeader.nTime = 1408743289; // Block #123457 (3h)
142+
BOOST_CHECK_EQUAL(GetNextWorkRequired(&blockIndexLast, &blockHeader, paramsdev), 0x207fffff); // Block #123457 has 0x207fffff
123143
}
124144

125145
/* Test the constraint on the upper bound for next work */

0 commit comments

Comments
 (0)