@@ -1569,6 +1569,47 @@ func TestABCI_PrepareProposal_BadEncoding(t *testing.T) {
15691569 require .Equal (t , 1 , len (resPrepareProposal .Txs ))
15701570}
15711571
1572+ func TestABCI_PrepareProposal_OverGasUnderBytes (t * testing.T ) {
1573+ pool := mempool .NewSenderNonceMempool ()
1574+ suite := NewBaseAppSuite (t , baseapp .SetMempool (pool ))
1575+ baseapptestutil .RegisterCounterServer (suite .baseApp .MsgServiceRouter (), NoopCounterServerImpl {})
1576+
1577+ // set max block gas limit to 99, this will allow 9 txs of 10 gas each.
1578+ _ , err := suite .baseApp .InitChain (& abci.RequestInitChain {
1579+ ConsensusParams : & cmtproto.ConsensusParams {
1580+ Block : & cmtproto.BlockParams {MaxGas : 99 },
1581+ },
1582+ })
1583+
1584+ require .NoError (t , err )
1585+ // insert 100 txs, each with a gas limit of 10
1586+ _ , _ , addr := testdata .KeyTestPubAddr ()
1587+ for i := int64 (0 ); i < 100 ; i ++ {
1588+ msg := & baseapptestutil.MsgCounter {Counter : i , FailOnHandler : false , Signer : addr .String ()}
1589+ msgs := []sdk.Msg {msg }
1590+
1591+ builder := suite .txConfig .NewTxBuilder ()
1592+ err = builder .SetMsgs (msgs ... )
1593+ require .NoError (t , err )
1594+ builder .SetMemo ("counter=" + strconv .FormatInt (i , 10 ) + "&failOnAnte=false" )
1595+ builder .SetGasLimit (10 )
1596+ setTxSignature (t , builder , uint64 (i ))
1597+
1598+ err := pool .Insert (sdk.Context {}, builder .GetTx ())
1599+ require .NoError (t , err )
1600+ }
1601+
1602+ // ensure we only select transactions that fit within the block gas limit
1603+ res , err := suite .baseApp .PrepareProposal (& abci.RequestPrepareProposal {
1604+ MaxTxBytes : 1_000_000 , // large enough to ignore restriction
1605+ Height : 1 ,
1606+ })
1607+ require .NoError (t , err )
1608+
1609+ // Should include 9 transactions
1610+ require .Len (t , res .Txs , 9 , "invalid number of transactions returned" )
1611+ }
1612+
15721613func TestABCI_PrepareProposal_MaxGas (t * testing.T ) {
15731614 pool := mempool .NewSenderNonceMempool ()
15741615 suite := NewBaseAppSuite (t , baseapp .SetMempool (pool ))
0 commit comments