@@ -120,7 +120,22 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
120
120
tx.vout [0 ].nValue -= 1000000 ;
121
121
hash = tx.GetHash ();
122
122
bool spendsCoinbase = (i == 0 ) ? true : false ; // only first tx spends coinbase
123
- mempool.addUnchecked (hash, entry.Time (GetTime ()).SpendsCoinbase (spendsCoinbase).FromTx (tx));
123
+ // If we don't set the # of sig ops in the CTxMemPoolEntry, template creation fails
124
+ mempool.addUnchecked (hash, entry.Fee (1000000 ).Time (GetTime ()).SpendsCoinbase (spendsCoinbase).FromTx (tx));
125
+ tx.vin [0 ].prevout .hash = hash;
126
+ }
127
+ BOOST_CHECK_THROW (CreateNewBlock (chainparams, scriptPubKey), std::runtime_error);
128
+ mempool.clear ();
129
+
130
+ tx.vin [0 ].prevout .hash = txFirst[0 ]->GetHash ();
131
+ tx.vout [0 ].nValue = 5000000000LL ;
132
+ for (unsigned int i = 0 ; i < 1001 ; ++i)
133
+ {
134
+ tx.vout [0 ].nValue -= 1000000 ;
135
+ hash = tx.GetHash ();
136
+ bool spendsCoinbase = (i == 0 ) ? true : false ; // only first tx spends coinbase
137
+ // If we do set the # of sig ops in the CTxMemPoolEntry, template creation passes
138
+ mempool.addUnchecked (hash, entry.Fee (1000000 ).Time (GetTime ()).SpendsCoinbase (spendsCoinbase).SigOps (20 ).FromTx (tx));
124
139
tx.vin [0 ].prevout .hash = hash;
125
140
}
126
141
BOOST_CHECK (pblocktemplate = CreateNewBlock (chainparams, scriptPubKey));
@@ -141,79 +156,76 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
141
156
tx.vout [0 ].nValue -= 10000000 ;
142
157
hash = tx.GetHash ();
143
158
bool spendsCoinbase = (i == 0 ) ? true : false ; // only first tx spends coinbase
144
- mempool.addUnchecked (hash, entry.Time (GetTime ()).SpendsCoinbase (spendsCoinbase).FromTx (tx));
159
+ mempool.addUnchecked (hash, entry.Fee ( 1000000 ). Time (GetTime ()).SpendsCoinbase (spendsCoinbase).FromTx (tx));
145
160
tx.vin [0 ].prevout .hash = hash;
146
161
}
147
162
BOOST_CHECK (pblocktemplate = CreateNewBlock (chainparams, scriptPubKey));
148
163
delete pblocktemplate;
149
164
mempool.clear ();
150
165
151
- // orphan in mempool
166
+ // orphan in mempool, template creation fails
152
167
hash = tx.GetHash ();
153
- mempool.addUnchecked (hash, entry.Time (GetTime ()).FromTx (tx));
154
- BOOST_CHECK (pblocktemplate = CreateNewBlock (chainparams, scriptPubKey));
155
- delete pblocktemplate;
168
+ mempool.addUnchecked (hash, entry.Fee (1000000 ).Time (GetTime ()).FromTx (tx));
169
+ BOOST_CHECK_THROW (CreateNewBlock (chainparams, scriptPubKey), std::runtime_error);
156
170
mempool.clear ();
157
171
158
172
// child with higher priority than parent
159
173
tx.vin [0 ].scriptSig = CScript () << OP_1;
160
174
tx.vin [0 ].prevout .hash = txFirst[1 ]->GetHash ();
161
175
tx.vout [0 ].nValue = 4900000000LL ;
162
176
hash = tx.GetHash ();
163
- mempool.addUnchecked (hash, entry.Time (GetTime ()).SpendsCoinbase (true ).FromTx (tx));
177
+ mempool.addUnchecked (hash, entry.Fee ( 100000000LL ). Time (GetTime ()).SpendsCoinbase (true ).FromTx (tx));
164
178
tx.vin [0 ].prevout .hash = hash;
165
179
tx.vin .resize (2 );
166
180
tx.vin [1 ].scriptSig = CScript () << OP_1;
167
181
tx.vin [1 ].prevout .hash = txFirst[0 ]->GetHash ();
168
182
tx.vin [1 ].prevout .n = 0 ;
169
183
tx.vout [0 ].nValue = 5900000000LL ;
170
184
hash = tx.GetHash ();
171
- mempool.addUnchecked (hash, entry.Time (GetTime ()).SpendsCoinbase (true ).FromTx (tx));
185
+ mempool.addUnchecked (hash, entry.Fee ( 400000000LL ). Time (GetTime ()).SpendsCoinbase (true ).FromTx (tx));
172
186
BOOST_CHECK (pblocktemplate = CreateNewBlock (chainparams, scriptPubKey));
173
187
delete pblocktemplate;
174
188
mempool.clear ();
175
189
176
- // coinbase in mempool
190
+ // coinbase in mempool, template creation fails
177
191
tx.vin .resize (1 );
178
192
tx.vin [0 ].prevout .SetNull ();
179
193
tx.vin [0 ].scriptSig = CScript () << OP_0 << OP_1;
180
194
tx.vout [0 ].nValue = 0 ;
181
195
hash = tx.GetHash ();
182
- mempool. addUnchecked (hash, entry. Time ( GetTime ()). SpendsCoinbase ( false ). FromTx (tx));
183
- BOOST_CHECK (pblocktemplate = CreateNewBlock (chainparams, scriptPubKey ));
184
- delete pblocktemplate ;
196
+ // give it a fee so it'll get mined
197
+ mempool. addUnchecked (hash, entry. Fee ( 100000 ). Time ( GetTime ()). SpendsCoinbase ( false ). FromTx (tx ));
198
+ BOOST_CHECK_THROW ( CreateNewBlock (chainparams, scriptPubKey), std::runtime_error) ;
185
199
mempool.clear ();
186
200
187
- // invalid (pre-p2sh) txn in mempool
201
+ // invalid (pre-p2sh) txn in mempool, template creation fails
188
202
tx.vin [0 ].prevout .hash = txFirst[0 ]->GetHash ();
189
203
tx.vin [0 ].prevout .n = 0 ;
190
204
tx.vin [0 ].scriptSig = CScript () << OP_1;
191
205
tx.vout [0 ].nValue = 4900000000LL ;
192
206
script = CScript () << OP_0;
193
207
tx.vout [0 ].scriptPubKey = GetScriptForDestination (CScriptID (script));
194
208
hash = tx.GetHash ();
195
- mempool.addUnchecked (hash, entry.Time (GetTime ()).SpendsCoinbase (true ).FromTx (tx));
209
+ mempool.addUnchecked (hash, entry.Fee ( 10000000L ). Time (GetTime ()).SpendsCoinbase (true ).FromTx (tx));
196
210
tx.vin [0 ].prevout .hash = hash;
197
211
tx.vin [0 ].scriptSig = CScript () << std::vector<unsigned char >(script.begin (), script.end ());
198
212
tx.vout [0 ].nValue -= 1000000 ;
199
213
hash = tx.GetHash ();
200
- mempool.addUnchecked (hash, entry.Time (GetTime ()).SpendsCoinbase (false ).FromTx (tx));
201
- BOOST_CHECK (pblocktemplate = CreateNewBlock (chainparams, scriptPubKey));
202
- delete pblocktemplate;
214
+ mempool.addUnchecked (hash, entry.Fee (1000000 ).Time (GetTime ()).SpendsCoinbase (false ).FromTx (tx));
215
+ BOOST_CHECK_THROW (CreateNewBlock (chainparams, scriptPubKey), std::runtime_error);
203
216
mempool.clear ();
204
217
205
- // double spend txn pair in mempool
218
+ // double spend txn pair in mempool, template creation fails
206
219
tx.vin [0 ].prevout .hash = txFirst[0 ]->GetHash ();
207
220
tx.vin [0 ].scriptSig = CScript () << OP_1;
208
221
tx.vout [0 ].nValue = 4900000000LL ;
209
222
tx.vout [0 ].scriptPubKey = CScript () << OP_1;
210
223
hash = tx.GetHash ();
211
- mempool.addUnchecked (hash, entry.Time (GetTime ()).SpendsCoinbase (true ).FromTx (tx));
224
+ mempool.addUnchecked (hash, entry.Fee ( 100000000L ). Time (GetTime ()).SpendsCoinbase (true ).FromTx (tx));
212
225
tx.vout [0 ].scriptPubKey = CScript () << OP_2;
213
226
hash = tx.GetHash ();
214
- mempool.addUnchecked (hash, entry.Time (GetTime ()).SpendsCoinbase (true ).FromTx (tx));
215
- BOOST_CHECK (pblocktemplate = CreateNewBlock (chainparams, scriptPubKey));
216
- delete pblocktemplate;
227
+ mempool.addUnchecked (hash, entry.Fee (100000000L ).Time (GetTime ()).SpendsCoinbase (true ).FromTx (tx));
228
+ BOOST_CHECK_THROW (CreateNewBlock (chainparams, scriptPubKey), std::runtime_error);
217
229
mempool.clear ();
218
230
219
231
// subsidy changing
@@ -237,7 +249,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
237
249
tx.vout [0 ].scriptPubKey = CScript () << OP_1;
238
250
tx.nLockTime = chainActive.Tip ()->nHeight +1 ;
239
251
hash = tx.GetHash ();
240
- mempool.addUnchecked (hash, entry.Time (GetTime ()).SpendsCoinbase (true ).FromTx (tx));
252
+ mempool.addUnchecked (hash, entry.Fee ( 100000000L ). Time (GetTime ()).SpendsCoinbase (true ).FromTx (tx));
241
253
BOOST_CHECK (!CheckFinalTx (tx, LOCKTIME_MEDIAN_TIME_PAST));
242
254
243
255
// time locked
@@ -251,7 +263,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
251
263
tx2.vout [0 ].scriptPubKey = CScript () << OP_1;
252
264
tx2.nLockTime = chainActive.Tip ()->GetMedianTimePast ()+1 ;
253
265
hash = tx2.GetHash ();
254
- mempool.addUnchecked (hash, entry.Time (GetTime ()).SpendsCoinbase (true ).FromTx (tx2));
266
+ mempool.addUnchecked (hash, entry.Fee ( 100000000L ). Time (GetTime ()).SpendsCoinbase (true ).FromTx (tx2));
255
267
BOOST_CHECK (!CheckFinalTx (tx2, LOCKTIME_MEDIAN_TIME_PAST));
256
268
257
269
BOOST_CHECK (pblocktemplate = CreateNewBlock (chainparams, scriptPubKey));
0 commit comments