@@ -732,7 +732,7 @@ func TestL1MsgCorrectOrder(t *testing.T) {
732732 }
733733}
734734
735- func l1MessageTest (t * testing.T , msgs []types.L1MessageTx , callback func (i int , block * types.Block , db ethdb.Database ) bool ) {
735+ func l1MessageTest (t * testing.T , msgs []types.L1MessageTx , callback func (i int , block * types.Block , db ethdb.Database , bc * core. BlockChain ) bool ) {
736736 var (
737737 engine consensus.Engine
738738 chainConfig * params.ChainConfig
@@ -784,8 +784,8 @@ func l1MessageTest(t *testing.T, msgs []types.L1MessageTx, callback func(i int,
784784 select {
785785 case ev := <- sub .Chan ():
786786 block := ev .Data .(core.NewMinedBlockEvent ).Block
787- // TODO
788- if callback (ii , block , db ) {
787+
788+ if done := callback (ii , block , db , chain ); done {
789789 return
790790 }
791791
@@ -805,7 +805,7 @@ func TestL1SingleMessageOverGasLimit(t *testing.T) {
805805 {QueueIndex : 2 , Gas : 21016 , To : & common.Address {1 }, Data : []byte {0x01 }, Sender : common.Address {3 }}, // different sender
806806 }
807807
808- l1MessageTest (t , msgs , func (_i int , block * types.Block , db ethdb.Database ) bool {
808+ l1MessageTest (t , msgs , func (_ int , block * types.Block , db ethdb.Database , _ * core. BlockChain ) bool {
809809 // skip #0, include #1 and #2
810810 assert .Equal (2 , len (block .Transactions ()))
811811
@@ -834,7 +834,7 @@ func TestL1CombinedMessagesOverGasLimit(t *testing.T) {
834834 {QueueIndex : 2 , Gas : 21016 , To : & common.Address {1 }, Data : []byte {0x01 }, Sender : common.Address {3 }}, // different sender
835835 }
836836
837- l1MessageTest (t , msgs , func (blockNum int , block * types.Block , db ethdb.Database ) bool {
837+ l1MessageTest (t , msgs , func (blockNum int , block * types.Block , db ethdb.Database , _ * core. BlockChain ) bool {
838838 switch blockNum {
839839 case 1 :
840840 // block #1 only includes 1 message
@@ -876,7 +876,7 @@ func TestLargeL1MessageSkipPayloadCheck(t *testing.T) {
876876 {QueueIndex : 2 , Gas : 21016 , To : & common.Address {1 }, Data : []byte {0x01 }, Sender : common.Address {3 }}, // different sender
877877 }
878878
879- l1MessageTest (t , msgs , func (blockNum int , block * types.Block , db ethdb.Database ) bool {
879+ l1MessageTest (t , msgs , func (blockNum int , block * types.Block , db ethdb.Database , _ * core. BlockChain ) bool {
880880 // include #0, #1 and #2
881881 assert .Equal (3 , len (block .Transactions ()))
882882
@@ -895,3 +895,31 @@ func TestLargeL1MessageSkipPayloadCheck(t *testing.T) {
895895 return true
896896 })
897897}
898+
899+ func TestL1MessageWithInsufficientBalanceNotSkipped (t * testing.T ) {
900+ assert := assert .New (t )
901+
902+ // message #0 sends more funds than available in the sender account
903+ msgs := []types.L1MessageTx {
904+ {QueueIndex : 0 , Gas : 25100 , To : & common.Address {1 }, Data : make ([]byte , 1025 ), Sender : common.Address {2 }, Value : big .NewInt (1 )},
905+ }
906+
907+ l1MessageTest (t , msgs , func (blockNum int , block * types.Block , db ethdb.Database , bc * core.BlockChain ) bool {
908+ // include #0
909+ assert .Equal (1 , len (block .Transactions ()))
910+ assert .True (block .Transactions ()[0 ].IsL1MessageTx ())
911+ assert .Equal (uint64 (0 ), block .Transactions ()[0 ].AsL1MessageTx ().QueueIndex )
912+
913+ // failing receipt is stored correctly
914+ receipts := bc .GetReceiptsByHash (block .Hash ())
915+ assert .Equal (1 , len (receipts ))
916+ assert .Equal (types .ReceiptStatusFailed , receipts [0 ].Status )
917+
918+ // db is updated correctly
919+ queueIndex := rawdb .ReadFirstQueueIndexNotInL2Block (db , block .Hash ())
920+ assert .NotNil (queueIndex )
921+ assert .Equal (uint64 (1 ), * queueIndex )
922+
923+ return true
924+ })
925+ }
0 commit comments