@@ -124,35 +124,40 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
124
124
BOOST_CHECK (pblocktemplate = CreateNewBlock (chainparams, scriptPubKey));
125
125
delete pblocktemplate;
126
126
127
+ const CAmount BLOCKSUBSIDY = 50 *COIN;
128
+ const CAmount LOWFEE = CENT;
129
+ const CAmount HIGHFEE = COIN;
130
+ const CAmount HIGHERFEE = 4 *COIN;
131
+
127
132
// block sigops > limit: 1000 CHECKMULTISIG + 1
128
133
tx.vin .resize (1 );
129
134
// NOTE: OP_NOP is used to force 20 SigOps for the CHECKMULTISIG
130
135
tx.vin [0 ].scriptSig = CScript () << OP_0 << OP_0 << OP_0 << OP_NOP << OP_CHECKMULTISIG << OP_1;
131
136
tx.vin [0 ].prevout .hash = txFirst[0 ]->GetHash ();
132
137
tx.vin [0 ].prevout .n = 0 ;
133
138
tx.vout .resize (1 );
134
- tx.vout [0 ].nValue = 5000000000LL ;
139
+ tx.vout [0 ].nValue = BLOCKSUBSIDY ;
135
140
for (unsigned int i = 0 ; i < 1001 ; ++i)
136
141
{
137
- tx.vout [0 ].nValue -= 1000000 ;
142
+ tx.vout [0 ].nValue -= LOWFEE ;
138
143
hash = tx.GetHash ();
139
144
bool spendsCoinbase = (i == 0 ) ? true : false ; // only first tx spends coinbase
140
145
// 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));
142
147
tx.vin [0 ].prevout .hash = hash;
143
148
}
144
149
BOOST_CHECK_THROW (CreateNewBlock (chainparams, scriptPubKey), std::runtime_error);
145
150
mempool.clear ();
146
151
147
152
tx.vin [0 ].prevout .hash = txFirst[0 ]->GetHash ();
148
- tx.vout [0 ].nValue = 5000000000LL ;
153
+ tx.vout [0 ].nValue = BLOCKSUBSIDY ;
149
154
for (unsigned int i = 0 ; i < 1001 ; ++i)
150
155
{
151
- tx.vout [0 ].nValue -= 1000000 ;
156
+ tx.vout [0 ].nValue -= LOWFEE ;
152
157
hash = tx.GetHash ();
153
158
bool spendsCoinbase = (i == 0 ) ? true : false ; // only first tx spends coinbase
154
159
// 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));
156
161
tx.vin [0 ].prevout .hash = hash;
157
162
}
158
163
BOOST_CHECK (pblocktemplate = CreateNewBlock (chainparams, scriptPubKey));
@@ -167,13 +172,13 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
167
172
tx.vin [0 ].scriptSig << vchData << OP_DROP;
168
173
tx.vin [0 ].scriptSig << OP_1;
169
174
tx.vin [0 ].prevout .hash = txFirst[0 ]->GetHash ();
170
- tx.vout [0 ].nValue = 5000000000LL ;
175
+ tx.vout [0 ].nValue = BLOCKSUBSIDY ;
171
176
for (unsigned int i = 0 ; i < 128 ; ++i)
172
177
{
173
- tx.vout [0 ].nValue -= 10000000 ;
178
+ tx.vout [0 ].nValue -= LOWFEE ;
174
179
hash = tx.GetHash ();
175
180
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));
177
182
tx.vin [0 ].prevout .hash = hash;
178
183
}
179
184
BOOST_CHECK (pblocktemplate = CreateNewBlock (chainparams, scriptPubKey));
@@ -182,24 +187,24 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
182
187
183
188
// orphan in mempool, template creation fails
184
189
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));
186
191
BOOST_CHECK_THROW (CreateNewBlock (chainparams, scriptPubKey), std::runtime_error);
187
192
mempool.clear ();
188
193
189
194
// child with higher priority than parent
190
195
tx.vin [0 ].scriptSig = CScript () << OP_1;
191
196
tx.vin [0 ].prevout .hash = txFirst[1 ]->GetHash ();
192
- tx.vout [0 ].nValue = 4900000000LL ;
197
+ tx.vout [0 ].nValue = BLOCKSUBSIDY-HIGHFEE ;
193
198
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));
195
200
tx.vin [0 ].prevout .hash = hash;
196
201
tx.vin .resize (2 );
197
202
tx.vin [1 ].scriptSig = CScript () << OP_1;
198
203
tx.vin [1 ].prevout .hash = txFirst[0 ]->GetHash ();
199
204
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
201
206
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));
203
208
BOOST_CHECK (pblocktemplate = CreateNewBlock (chainparams, scriptPubKey));
204
209
delete pblocktemplate;
205
210
mempool.clear ();
@@ -211,37 +216,37 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
211
216
tx.vout [0 ].nValue = 0 ;
212
217
hash = tx.GetHash ();
213
218
// 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));
215
220
BOOST_CHECK_THROW (CreateNewBlock (chainparams, scriptPubKey), std::runtime_error);
216
221
mempool.clear ();
217
222
218
223
// invalid (pre-p2sh) txn in mempool, template creation fails
219
224
tx.vin [0 ].prevout .hash = txFirst[0 ]->GetHash ();
220
225
tx.vin [0 ].prevout .n = 0 ;
221
226
tx.vin [0 ].scriptSig = CScript () << OP_1;
222
- tx.vout [0 ].nValue = 4900000000LL ;
227
+ tx.vout [0 ].nValue = BLOCKSUBSIDY-LOWFEE ;
223
228
script = CScript () << OP_0;
224
229
tx.vout [0 ].scriptPubKey = GetScriptForDestination (CScriptID (script));
225
230
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));
227
232
tx.vin [0 ].prevout .hash = hash;
228
233
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 ;
230
235
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));
232
237
BOOST_CHECK_THROW (CreateNewBlock (chainparams, scriptPubKey), std::runtime_error);
233
238
mempool.clear ();
234
239
235
240
// double spend txn pair in mempool, template creation fails
236
241
tx.vin [0 ].prevout .hash = txFirst[0 ]->GetHash ();
237
242
tx.vin [0 ].scriptSig = CScript () << OP_1;
238
- tx.vout [0 ].nValue = 4900000000LL ;
243
+ tx.vout [0 ].nValue = BLOCKSUBSIDY-HIGHFEE ;
239
244
tx.vout [0 ].scriptPubKey = CScript () << OP_1;
240
245
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));
242
247
tx.vout [0 ].scriptPubKey = CScript () << OP_2;
243
248
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));
245
250
BOOST_CHECK_THROW (CreateNewBlock (chainparams, scriptPubKey), std::runtime_error);
246
251
mempool.clear ();
247
252
@@ -298,11 +303,11 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
298
303
tx.vin [0 ].nSequence = chainActive.Tip ()->nHeight + 1 ; // txFirst[0] is the 2nd block
299
304
prevheights[0 ] = baseheight + 1 ;
300
305
tx.vout .resize (1 );
301
- tx.vout [0 ].nValue = 4900000000LL ;
306
+ tx.vout [0 ].nValue = BLOCKSUBSIDY-HIGHFEE ;
302
307
tx.vout [0 ].scriptPubKey = CScript () << OP_1;
303
308
tx.nLockTime = 0 ;
304
309
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));
306
311
BOOST_CHECK (CheckFinalTx (tx, flags)); // Locktime passes
307
312
BOOST_CHECK (!TestSequenceLocks (tx, flags)); // Sequence locks fail
308
313
BOOST_CHECK (SequenceLocks (tx, flags, &prevheights, CreateBlockIndex (chainActive.Tip ()->nHeight + 2 ))); // Sequence locks pass on 2nd block
0 commit comments