@@ -120,7 +120,22 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
120120 tx.vout [0 ].nValue -= 1000000 ;
121121 hash = tx.GetHash ();
122122 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));
124139 tx.vin [0 ].prevout .hash = hash;
125140 }
126141 BOOST_CHECK (pblocktemplate = CreateNewBlock (chainparams, scriptPubKey));
@@ -141,79 +156,76 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
141156 tx.vout [0 ].nValue -= 10000000 ;
142157 hash = tx.GetHash ();
143158 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));
145160 tx.vin [0 ].prevout .hash = hash;
146161 }
147162 BOOST_CHECK (pblocktemplate = CreateNewBlock (chainparams, scriptPubKey));
148163 delete pblocktemplate;
149164 mempool.clear ();
150165
151- // orphan in mempool
166+ // orphan in mempool, template creation fails
152167 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);
156170 mempool.clear ();
157171
158172 // child with higher priority than parent
159173 tx.vin [0 ].scriptSig = CScript () << OP_1;
160174 tx.vin [0 ].prevout .hash = txFirst[1 ]->GetHash ();
161175 tx.vout [0 ].nValue = 4900000000LL ;
162176 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));
164178 tx.vin [0 ].prevout .hash = hash;
165179 tx.vin .resize (2 );
166180 tx.vin [1 ].scriptSig = CScript () << OP_1;
167181 tx.vin [1 ].prevout .hash = txFirst[0 ]->GetHash ();
168182 tx.vin [1 ].prevout .n = 0 ;
169183 tx.vout [0 ].nValue = 5900000000LL ;
170184 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));
172186 BOOST_CHECK (pblocktemplate = CreateNewBlock (chainparams, scriptPubKey));
173187 delete pblocktemplate;
174188 mempool.clear ();
175189
176- // coinbase in mempool
190+ // coinbase in mempool, template creation fails
177191 tx.vin .resize (1 );
178192 tx.vin [0 ].prevout .SetNull ();
179193 tx.vin [0 ].scriptSig = CScript () << OP_0 << OP_1;
180194 tx.vout [0 ].nValue = 0 ;
181195 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) ;
185199 mempool.clear ();
186200
187- // invalid (pre-p2sh) txn in mempool
201+ // invalid (pre-p2sh) txn in mempool, template creation fails
188202 tx.vin [0 ].prevout .hash = txFirst[0 ]->GetHash ();
189203 tx.vin [0 ].prevout .n = 0 ;
190204 tx.vin [0 ].scriptSig = CScript () << OP_1;
191205 tx.vout [0 ].nValue = 4900000000LL ;
192206 script = CScript () << OP_0;
193207 tx.vout [0 ].scriptPubKey = GetScriptForDestination (CScriptID (script));
194208 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));
196210 tx.vin [0 ].prevout .hash = hash;
197211 tx.vin [0 ].scriptSig = CScript () << std::vector<unsigned char >(script.begin (), script.end ());
198212 tx.vout [0 ].nValue -= 1000000 ;
199213 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);
203216 mempool.clear ();
204217
205- // double spend txn pair in mempool
218+ // double spend txn pair in mempool, template creation fails
206219 tx.vin [0 ].prevout .hash = txFirst[0 ]->GetHash ();
207220 tx.vin [0 ].scriptSig = CScript () << OP_1;
208221 tx.vout [0 ].nValue = 4900000000LL ;
209222 tx.vout [0 ].scriptPubKey = CScript () << OP_1;
210223 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));
212225 tx.vout [0 ].scriptPubKey = CScript () << OP_2;
213226 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);
217229 mempool.clear ();
218230
219231 // subsidy changing
@@ -237,7 +249,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
237249 tx.vout [0 ].scriptPubKey = CScript () << OP_1;
238250 tx.nLockTime = chainActive.Tip ()->nHeight +1 ;
239251 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));
241253 BOOST_CHECK (!CheckFinalTx (tx, LOCKTIME_MEDIAN_TIME_PAST));
242254
243255 // time locked
@@ -251,7 +263,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
251263 tx2.vout [0 ].scriptPubKey = CScript () << OP_1;
252264 tx2.nLockTime = chainActive.Tip ()->GetMedianTimePast ()+1 ;
253265 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));
255267 BOOST_CHECK (!CheckFinalTx (tx2, LOCKTIME_MEDIAN_TIME_PAST));
256268
257269 BOOST_CHECK (pblocktemplate = CreateNewBlock (chainparams, scriptPubKey));
0 commit comments