Skip to content

Commit 0ad1041

Browse files
author
MarcoFalke
committed
Merge #7807: Fixed miner test values, gave constants for less error-prone values.
f8536a6 Corrected values (instagibbs) 617deeb Gave miner test values constants for less error-prone values. (instagibbs)
2 parents 20f9ecd + f8536a6 commit 0ad1041

File tree

1 file changed

+29
-24
lines changed

1 file changed

+29
-24
lines changed

src/test/miner_tests.cpp

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -124,35 +124,40 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
124124
BOOST_CHECK(pblocktemplate = CreateNewBlock(chainparams, scriptPubKey));
125125
delete pblocktemplate;
126126

127+
const CAmount BLOCKSUBSIDY = 50*COIN;
128+
const CAmount LOWFEE = CENT;
129+
const CAmount HIGHFEE = COIN;
130+
const CAmount HIGHERFEE = 4*COIN;
131+
127132
// block sigops > limit: 1000 CHECKMULTISIG + 1
128133
tx.vin.resize(1);
129134
// NOTE: OP_NOP is used to force 20 SigOps for the CHECKMULTISIG
130135
tx.vin[0].scriptSig = CScript() << OP_0 << OP_0 << OP_0 << OP_NOP << OP_CHECKMULTISIG << OP_1;
131136
tx.vin[0].prevout.hash = txFirst[0]->GetHash();
132137
tx.vin[0].prevout.n = 0;
133138
tx.vout.resize(1);
134-
tx.vout[0].nValue = 5000000000LL;
139+
tx.vout[0].nValue = BLOCKSUBSIDY;
135140
for (unsigned int i = 0; i < 1001; ++i)
136141
{
137-
tx.vout[0].nValue -= 1000000;
142+
tx.vout[0].nValue -= LOWFEE;
138143
hash = tx.GetHash();
139144
bool spendsCoinbase = (i == 0) ? true : false; // only first tx spends coinbase
140145
// If we don't set the # of sig ops in the CTxMemPoolEntry, template creation fails
141-
mempool.addUnchecked(hash, entry.Fee(1000000).Time(GetTime()).SpendsCoinbase(spendsCoinbase).FromTx(tx));
146+
mempool.addUnchecked(hash, entry.Fee(LOWFEE).Time(GetTime()).SpendsCoinbase(spendsCoinbase).FromTx(tx));
142147
tx.vin[0].prevout.hash = hash;
143148
}
144149
BOOST_CHECK_THROW(CreateNewBlock(chainparams, scriptPubKey), std::runtime_error);
145150
mempool.clear();
146151

147152
tx.vin[0].prevout.hash = txFirst[0]->GetHash();
148-
tx.vout[0].nValue = 5000000000LL;
153+
tx.vout[0].nValue = BLOCKSUBSIDY;
149154
for (unsigned int i = 0; i < 1001; ++i)
150155
{
151-
tx.vout[0].nValue -= 1000000;
156+
tx.vout[0].nValue -= LOWFEE;
152157
hash = tx.GetHash();
153158
bool spendsCoinbase = (i == 0) ? true : false; // only first tx spends coinbase
154159
// If we do set the # of sig ops in the CTxMemPoolEntry, template creation passes
155-
mempool.addUnchecked(hash, entry.Fee(1000000).Time(GetTime()).SpendsCoinbase(spendsCoinbase).SigOps(20).FromTx(tx));
160+
mempool.addUnchecked(hash, entry.Fee(LOWFEE).Time(GetTime()).SpendsCoinbase(spendsCoinbase).SigOps(20).FromTx(tx));
156161
tx.vin[0].prevout.hash = hash;
157162
}
158163
BOOST_CHECK(pblocktemplate = CreateNewBlock(chainparams, scriptPubKey));
@@ -167,13 +172,13 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
167172
tx.vin[0].scriptSig << vchData << OP_DROP;
168173
tx.vin[0].scriptSig << OP_1;
169174
tx.vin[0].prevout.hash = txFirst[0]->GetHash();
170-
tx.vout[0].nValue = 5000000000LL;
175+
tx.vout[0].nValue = BLOCKSUBSIDY;
171176
for (unsigned int i = 0; i < 128; ++i)
172177
{
173-
tx.vout[0].nValue -= 10000000;
178+
tx.vout[0].nValue -= LOWFEE;
174179
hash = tx.GetHash();
175180
bool spendsCoinbase = (i == 0) ? true : false; // only first tx spends coinbase
176-
mempool.addUnchecked(hash, entry.Fee(1000000).Time(GetTime()).SpendsCoinbase(spendsCoinbase).FromTx(tx));
181+
mempool.addUnchecked(hash, entry.Fee(LOWFEE).Time(GetTime()).SpendsCoinbase(spendsCoinbase).FromTx(tx));
177182
tx.vin[0].prevout.hash = hash;
178183
}
179184
BOOST_CHECK(pblocktemplate = CreateNewBlock(chainparams, scriptPubKey));
@@ -182,24 +187,24 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
182187

183188
// orphan in mempool, template creation fails
184189
hash = tx.GetHash();
185-
mempool.addUnchecked(hash, entry.Fee(1000000).Time(GetTime()).FromTx(tx));
190+
mempool.addUnchecked(hash, entry.Fee(LOWFEE).Time(GetTime()).FromTx(tx));
186191
BOOST_CHECK_THROW(CreateNewBlock(chainparams, scriptPubKey), std::runtime_error);
187192
mempool.clear();
188193

189194
// child with higher priority than parent
190195
tx.vin[0].scriptSig = CScript() << OP_1;
191196
tx.vin[0].prevout.hash = txFirst[1]->GetHash();
192-
tx.vout[0].nValue = 4900000000LL;
197+
tx.vout[0].nValue = BLOCKSUBSIDY-HIGHFEE;
193198
hash = tx.GetHash();
194-
mempool.addUnchecked(hash, entry.Fee(100000000LL).Time(GetTime()).SpendsCoinbase(true).FromTx(tx));
199+
mempool.addUnchecked(hash, entry.Fee(HIGHFEE).Time(GetTime()).SpendsCoinbase(true).FromTx(tx));
195200
tx.vin[0].prevout.hash = hash;
196201
tx.vin.resize(2);
197202
tx.vin[1].scriptSig = CScript() << OP_1;
198203
tx.vin[1].prevout.hash = txFirst[0]->GetHash();
199204
tx.vin[1].prevout.n = 0;
200-
tx.vout[0].nValue = 5900000000LL;
205+
tx.vout[0].nValue = tx.vout[0].nValue+BLOCKSUBSIDY-HIGHERFEE; //First txn output + fresh coinbase - new txn fee
201206
hash = tx.GetHash();
202-
mempool.addUnchecked(hash, entry.Fee(400000000LL).Time(GetTime()).SpendsCoinbase(true).FromTx(tx));
207+
mempool.addUnchecked(hash, entry.Fee(HIGHERFEE).Time(GetTime()).SpendsCoinbase(true).FromTx(tx));
203208
BOOST_CHECK(pblocktemplate = CreateNewBlock(chainparams, scriptPubKey));
204209
delete pblocktemplate;
205210
mempool.clear();
@@ -211,37 +216,37 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
211216
tx.vout[0].nValue = 0;
212217
hash = tx.GetHash();
213218
// give it a fee so it'll get mined
214-
mempool.addUnchecked(hash, entry.Fee(100000).Time(GetTime()).SpendsCoinbase(false).FromTx(tx));
219+
mempool.addUnchecked(hash, entry.Fee(LOWFEE).Time(GetTime()).SpendsCoinbase(false).FromTx(tx));
215220
BOOST_CHECK_THROW(CreateNewBlock(chainparams, scriptPubKey), std::runtime_error);
216221
mempool.clear();
217222

218223
// invalid (pre-p2sh) txn in mempool, template creation fails
219224
tx.vin[0].prevout.hash = txFirst[0]->GetHash();
220225
tx.vin[0].prevout.n = 0;
221226
tx.vin[0].scriptSig = CScript() << OP_1;
222-
tx.vout[0].nValue = 4900000000LL;
227+
tx.vout[0].nValue = BLOCKSUBSIDY-LOWFEE;
223228
script = CScript() << OP_0;
224229
tx.vout[0].scriptPubKey = GetScriptForDestination(CScriptID(script));
225230
hash = tx.GetHash();
226-
mempool.addUnchecked(hash, entry.Fee(10000000L).Time(GetTime()).SpendsCoinbase(true).FromTx(tx));
231+
mempool.addUnchecked(hash, entry.Fee(LOWFEE).Time(GetTime()).SpendsCoinbase(true).FromTx(tx));
227232
tx.vin[0].prevout.hash = hash;
228233
tx.vin[0].scriptSig = CScript() << std::vector<unsigned char>(script.begin(), script.end());
229-
tx.vout[0].nValue -= 1000000;
234+
tx.vout[0].nValue -= LOWFEE;
230235
hash = tx.GetHash();
231-
mempool.addUnchecked(hash, entry.Fee(1000000).Time(GetTime()).SpendsCoinbase(false).FromTx(tx));
236+
mempool.addUnchecked(hash, entry.Fee(LOWFEE).Time(GetTime()).SpendsCoinbase(false).FromTx(tx));
232237
BOOST_CHECK_THROW(CreateNewBlock(chainparams, scriptPubKey), std::runtime_error);
233238
mempool.clear();
234239

235240
// double spend txn pair in mempool, template creation fails
236241
tx.vin[0].prevout.hash = txFirst[0]->GetHash();
237242
tx.vin[0].scriptSig = CScript() << OP_1;
238-
tx.vout[0].nValue = 4900000000LL;
243+
tx.vout[0].nValue = BLOCKSUBSIDY-HIGHFEE;
239244
tx.vout[0].scriptPubKey = CScript() << OP_1;
240245
hash = tx.GetHash();
241-
mempool.addUnchecked(hash, entry.Fee(100000000L).Time(GetTime()).SpendsCoinbase(true).FromTx(tx));
246+
mempool.addUnchecked(hash, entry.Fee(HIGHFEE).Time(GetTime()).SpendsCoinbase(true).FromTx(tx));
242247
tx.vout[0].scriptPubKey = CScript() << OP_2;
243248
hash = tx.GetHash();
244-
mempool.addUnchecked(hash, entry.Fee(100000000L).Time(GetTime()).SpendsCoinbase(true).FromTx(tx));
249+
mempool.addUnchecked(hash, entry.Fee(HIGHFEE).Time(GetTime()).SpendsCoinbase(true).FromTx(tx));
245250
BOOST_CHECK_THROW(CreateNewBlock(chainparams, scriptPubKey), std::runtime_error);
246251
mempool.clear();
247252

@@ -298,11 +303,11 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
298303
tx.vin[0].nSequence = chainActive.Tip()->nHeight + 1; // txFirst[0] is the 2nd block
299304
prevheights[0] = baseheight + 1;
300305
tx.vout.resize(1);
301-
tx.vout[0].nValue = 4900000000LL;
306+
tx.vout[0].nValue = BLOCKSUBSIDY-HIGHFEE;
302307
tx.vout[0].scriptPubKey = CScript() << OP_1;
303308
tx.nLockTime = 0;
304309
hash = tx.GetHash();
305-
mempool.addUnchecked(hash, entry.Fee(100000000L).Time(GetTime()).SpendsCoinbase(true).FromTx(tx));
310+
mempool.addUnchecked(hash, entry.Fee(HIGHFEE).Time(GetTime()).SpendsCoinbase(true).FromTx(tx));
306311
BOOST_CHECK(CheckFinalTx(tx, flags)); // Locktime passes
307312
BOOST_CHECK(!TestSequenceLocks(tx, flags)); // Sequence locks fail
308313
BOOST_CHECK(SequenceLocks(tx, flags, &prevheights, CreateBlockIndex(chainActive.Tip()->nHeight + 2))); // Sequence locks pass on 2nd block

0 commit comments

Comments
 (0)