@@ -708,10 +708,12 @@ func TestLargeL1MessageSkipPayloadCheck(t *testing.T) {
708708func TestSkipMessageWithStrangeError (t * testing.T ) {
709709 assert := assert .New (t )
710710
711- // message #0 is skipped because of `Value`
712- // TODO: trigger skipping in some other way after this behaviour is changed
713711 msgs := []types.L1MessageTx {
714- {QueueIndex : 0 , Gas : 25100 , To : & common.Address {1 }, Data : []byte {0x01 }, Sender : common.Address {2 }, Value : big .NewInt (1 )},
712+ // message #0 is skipped because of `GasLimit`
713+ // (cannot happen in practice, this is checked in the contracts)
714+ {QueueIndex : 0 , Gas : 20000000 , To : & common.Address {1 }, Data : []byte {0x01 }, Sender : common.Address {2 }},
715+
716+ // messages #1 and #2 are correct
715717 {QueueIndex : 1 , Gas : 21016 , To : & common.Address {1 }, Data : []byte {0x01 }, Sender : common.Address {2 }},
716718 {QueueIndex : 2 , Gas : 21016 , To : & common.Address {1 }, Data : []byte {0x01 }, Sender : common.Address {3 }},
717719 }
@@ -742,15 +744,55 @@ func TestSkipMessageWithStrangeError(t *testing.T) {
742744 })
743745}
744746
747+ func TestL1MessageWithInsufficientBalanceNotSkipped (t * testing.T ) {
748+ assert := assert .New (t )
749+
750+ msgs := []types.L1MessageTx {
751+ // message #0 sends more funds than available in the sender account
752+ {QueueIndex : 0 , Gas : 25100 , To : & common.Address {1 }, Data : make ([]byte , 1025 ), Sender : common.Address {2 }, Value : big .NewInt (1 )},
753+
754+ // #message #1 is a correct msg
755+ {QueueIndex : 1 , Gas : 25100 , To : & common.Address {1 }, Data : make ([]byte , 1025 ), Sender : common.Address {2 }},
756+ }
757+
758+ l1MessageTest (t , msgs , false , func (blockNum int , block * types.Block , db ethdb.Database , w * worker , bc * core.BlockChain ) bool {
759+ switch blockNum {
760+ case 0 :
761+ return false
762+ case 1 :
763+ // include both #0 and #1
764+ assert .Equal (2 , len (block .Transactions ()))
765+ assert .True (block .Transactions ()[0 ].IsL1MessageTx ())
766+ assert .Equal (uint64 (0 ), block .Transactions ()[0 ].AsL1MessageTx ().QueueIndex )
767+ assert .True (block .Transactions ()[1 ].IsL1MessageTx ())
768+ assert .Equal (uint64 (1 ), block .Transactions ()[1 ].AsL1MessageTx ().QueueIndex )
769+
770+ // #0 fails, #1 succeeds
771+ receipts := bc .GetReceiptsByHash (block .Hash ())
772+ assert .Equal (2 , len (receipts ))
773+ assert .Equal (types .ReceiptStatusFailed , receipts [0 ].Status )
774+ assert .Equal (types .ReceiptStatusSuccessful , receipts [1 ].Status )
775+
776+ // db is updated correctly
777+ queueIndex := rawdb .ReadFirstQueueIndexNotInL2Block (db , block .Hash ())
778+ assert .NotNil (queueIndex )
779+ assert .Equal (uint64 (2 ), * queueIndex )
780+
781+ return true
782+ default :
783+ return true
784+ }
785+ })
786+ }
787+
745788func TestSkipAllL1MessagesInBlock (t * testing.T ) {
746789 assert := assert .New (t )
747790
748- // messages are skipped because of `Value`
749- // TODO: trigger skipping in some other way after this behaviour is changed
791+ // messages are skipped because of `GasLimit`
750792 msgs := []types.L1MessageTx {
751- {QueueIndex : 0 , Gas : 25100 , To : & common.Address {1 }, Data : []byte {0x01 }, Sender : common.Address {2 }, Value : big . NewInt ( 1 ) },
752- {QueueIndex : 1 , Gas : 21016 , To : & common.Address {1 }, Data : []byte {0x01 }, Sender : common.Address {2 }, Value : big . NewInt ( 1 ) },
753- {QueueIndex : 2 , Gas : 21016 , To : & common.Address {1 }, Data : []byte {0x01 }, Sender : common.Address {3 }, Value : big . NewInt ( 1 ) },
793+ {QueueIndex : 0 , Gas : 20000000 , To : & common.Address {1 }, Data : []byte {0x01 }, Sender : common.Address {2 }},
794+ {QueueIndex : 1 , Gas : 20000000 , To : & common.Address {1 }, Data : []byte {0x01 }, Sender : common.Address {2 }},
795+ {QueueIndex : 2 , Gas : 20000000 , To : & common.Address {1 }, Data : []byte {0x01 }, Sender : common.Address {3 }},
754796 }
755797
756798 l1MessageTest (t , msgs , true , func (blockNum int , block * types.Block , db ethdb.Database , w * worker , bc * core.BlockChain ) bool {
0 commit comments