@@ -22,6 +22,7 @@ import (
2222 "math/big"
2323 "testing"
2424
25+ "github.com/0xsoniclabs/sonic/gossip/blockproc/bundle"
2526 "github.com/0xsoniclabs/sonic/inter/state"
2627 "github.com/0xsoniclabs/sonic/opera"
2728 "github.com/ethereum/go-ethereum/common"
@@ -1288,6 +1289,44 @@ func TestValidateTx_RejectsTx_WhenStateValidationFails(t *testing.T) {
12881289 }
12891290}
12901291
1292+ func TestValidateTx_RejectsTx_WhenBundleTransactionValidationFails (t * testing.T ) {
1293+ require := require .New (t )
1294+ ctrl := gomock .NewController (t )
1295+ signer := NewMockSigner (ctrl )
1296+ signer .EXPECT ().Sender (gomock .Any ()).AnyTimes ()
1297+ signer .EXPECT ().Equal (gomock .Any ()).AnyTimes ()
1298+
1299+ chain := NewMockStateReader (ctrl )
1300+ chain .EXPECT ().CurrentBaseFee ().Return (big .NewInt (5 )).AnyTimes ()
1301+ chain .EXPECT ().CurrentMaxGasLimit ().Return (uint64 (100_000 )).AnyTimes ()
1302+
1303+ state := state .NewMockStateDB (ctrl )
1304+ state .EXPECT ().GetNonce (gomock .Any ()).Return (uint64 (0 )).AnyTimes ()
1305+ state .EXPECT ().GetBalance (gomock .Any ()).Return (uint256 .NewInt (0 )).AnyTimes ()
1306+ state .EXPECT ().GetCode (gomock .Any ()).Return (nil ).AnyTimes ()
1307+
1308+ invalidBundle := types .NewTx (& types.LegacyTx {
1309+ To : & bundle .BundleProcessor ,
1310+ Gas : 100_000 ,
1311+ })
1312+
1313+ require .True (bundle .IsEnvelope (invalidBundle ))
1314+ require .ErrorIs (validateTx (
1315+ invalidBundle ,
1316+ poolOptions {
1317+ isLocal : true ,
1318+ },
1319+ NetworkRules {
1320+ brio : true ,
1321+ transactionBundles : true ,
1322+ },
1323+ chain ,
1324+ state ,
1325+ nil ,
1326+ signer ,
1327+ ), ErrBundleTransactionInvalid )
1328+ }
1329+
12911330func TestValidateTx_AcceptsZeroGasPriceTransactions_WhenSubsidiesAreEnabled (t * testing.T ) {
12921331 tests := []types.TxData {
12931332 & types.LegacyTx {
@@ -1440,6 +1479,80 @@ func Test_validateSponsoredTransactions_RejectsSponsoredTransactions(t *testing.
14401479 }
14411480}
14421481
1482+ func Test_validateBundleTransactions_AcceptNonBundleTransactions (t * testing.T ) {
1483+ tests := map [string ]* types.Transaction {
1484+ "legacy tx" : types .NewTx (& types.LegacyTx {}),
1485+ "access list tx" : types .NewTx (& types.AccessListTx {}),
1486+ "dynamic fee tx" : types .NewTx (& types.DynamicFeeTx {}),
1487+ "blob tx" : types .NewTx (& types.BlobTx {}),
1488+ }
1489+
1490+ for name , tx := range tests {
1491+ t .Run (name , func (t * testing.T ) {
1492+ require := require .New (t )
1493+ require .False (bundle .IsEnvelope (tx ))
1494+ require .NoError (validateBundleTransactions (tx , NetworkRules {}, nil , nil , nil ))
1495+ })
1496+ }
1497+ }
1498+
1499+ func Test_validateBundleTransactions_RespectNetworkRules (t * testing.T ) {
1500+ signer := types .LatestSignerForChainID (big .NewInt (1 ))
1501+ bundle := bundle .NewBuilder (signer ).Build ()
1502+
1503+ tests := map [string ]struct {
1504+ rules NetworkRules
1505+ expectedError error
1506+ }{
1507+ "bundle transactions disabled pre brio" : {
1508+ rules : NetworkRules {},
1509+ expectedError : nil ,
1510+ },
1511+ "bundle transactions enabled pre brio" : {
1512+ rules : NetworkRules {transactionBundles : true },
1513+ expectedError : nil ,
1514+ },
1515+ "bundle transactions disabled post brio" : {
1516+ rules : NetworkRules {brio : true },
1517+ expectedError : ErrBundleTransactionsDisabled ,
1518+ },
1519+ "bundle transactions enabled post brio" : {
1520+ rules : NetworkRules {brio : true , transactionBundles : true },
1521+ expectedError : nil ,
1522+ },
1523+ }
1524+
1525+ for name , test := range tests {
1526+ t .Run (name , func (t * testing.T ) {
1527+ require := require .New (t )
1528+ err := validateBundleTransactions (bundle , test .rules , nil , nil , nil )
1529+ if test .expectedError != nil {
1530+ require .ErrorIs (err , test .expectedError )
1531+ } else {
1532+ require .NoError (err )
1533+ }
1534+ })
1535+ }
1536+ }
1537+
1538+ func Test_validateBundleTransactions_ReturnsErrorWithMalformedEnvelope (t * testing.T ) {
1539+ malformedBundle := types .NewTx (& types.LegacyTx {
1540+ To : & bundle .BundleProcessor ,
1541+ Gas : 100_000 ,
1542+ })
1543+
1544+ require := require .New (t )
1545+ require .True (bundle .IsEnvelope (malformedBundle ))
1546+
1547+ bundlesEnabled := NetworkRules {
1548+ brio : true ,
1549+ transactionBundles : true ,
1550+ }
1551+
1552+ err := validateBundleTransactions (malformedBundle , bundlesEnabled , nil , nil , nil )
1553+ require .ErrorIs (err , ErrBundleTransactionInvalid )
1554+ }
1555+
14431556func TestValidateTx_AllowsSponsoredZeroGasPriceTransactions_WhenSubsidiesAreFunded (t * testing.T ) {
14441557
14451558 tests := map [string ]struct {
0 commit comments