@@ -25,7 +25,6 @@ import (
2525 "github.com/ava-labs/avalanchego/snow"
2626 "github.com/ava-labs/avalanchego/snow/consensus/snowman"
2727 "github.com/ava-labs/avalanchego/snow/engine/enginetest"
28- "github.com/ava-labs/avalanchego/snow/engine/snowman/block"
2928 "github.com/ava-labs/avalanchego/snow/snowtest"
3029 "github.com/ava-labs/avalanchego/upgrade"
3130 "github.com/ava-labs/avalanchego/upgrade/upgradetest"
@@ -39,7 +38,6 @@ import (
3938 "github.com/ava-labs/libevm/core/rawdb"
4039 "github.com/ava-labs/libevm/core/types"
4140 "github.com/ava-labs/libevm/log"
42- "github.com/ava-labs/libevm/rlp"
4341 "github.com/ava-labs/libevm/trie"
4442 "github.com/stretchr/testify/assert"
4543 "github.com/stretchr/testify/require"
@@ -3852,15 +3850,7 @@ func TestBlockGasValidation(t *testing.T) {
38523850 ) * types.Block {
38533851 require := require .New (t )
38543852
3855- chainExtra := params .GetExtra (vm .chainConfig )
3856- parent := vm .eth .APIBackend .CurrentBlock ()
3857- const timeDelta = 5 // mocked block delay
3858- timestamp := parent .Time + timeDelta
3859- feeConfig , _ , err := vm .blockChain .GetFeeConfigAt (parent )
3860- require .NoError (err )
3861- gasLimit , err := customheader .GasLimit (chainExtra , feeConfig , parent , timestamp )
3862- require .NoError (err )
3863- baseFee , err := customheader .BaseFee (chainExtra , feeConfig , parent , timestamp )
3853+ blk , err := vm .BuildBlock (context .Background ())
38643854 require .NoError (err )
38653855
38663856 callPayload , err := payload .NewAddressedCall (nil , nil )
@@ -3899,8 +3889,8 @@ func TestBlockGasValidation(t *testing.T) {
38993889 Nonce : 1 ,
39003890 To : & testEthAddrs [0 ],
39013891 Gas : 8_000_000 , // block gas limit
3902- GasFeeCap : baseFee ,
3903- GasTipCap : baseFee ,
3892+ GasFeeCap : big . NewInt ( 10 ) ,
3893+ GasTipCap : big . NewInt ( 10 ) ,
39043894 Value : common .Big0 ,
39053895 AccessList : accessList ,
39063896 }),
@@ -3909,36 +3899,14 @@ func TestBlockGasValidation(t *testing.T) {
39093899 )
39103900 require .NoError (err )
39113901
3912- header := & types.Header {
3913- ParentHash : parent .Hash (),
3914- Coinbase : constants .BlackholeAddr ,
3915- Difficulty : new (big.Int ).Add (parent .Difficulty , common .Big1 ),
3916- Number : new (big.Int ).Add (parent .Number , common .Big1 ),
3917- GasLimit : gasLimit ,
3918- GasUsed : 0 ,
3919- Time : timestamp ,
3920- BaseFee : baseFee ,
3921- BlobGasUsed : new (uint64 ),
3922- ExcessBlobGas : new (uint64 ),
3923- ParentBeaconRoot : & common.Hash {},
3924- }
3925-
3926- configExtra := params .GetExtra (vm .chainConfig )
3927- header .Extra , err = customheader .ExtraPrefix (configExtra , parent , header )
3928- require .NoError (err )
3929-
3930- // Set TimeMilliseconds if Granite is active
3931- if configExtra .IsGranite (timestamp ) {
3932- headerExtra := customtypes .GetHeaderExtra (header )
3933- timeMilliseconds := timestamp * 1000 // convert to milliseconds
3934- headerExtra .TimeMilliseconds = & timeMilliseconds
3935- }
3902+ ethBlock := blk .(* chain.BlockWrapper ).Block .(* wrappedBlock ).ethBlock
3903+ modifiedHeader := types .CopyHeader (ethBlock .Header ())
39363904
39373905 // Set the gasUsed after calculating the extra prefix to support large
39383906 // claimed gas used values.
3939- header .GasUsed = claimedGasUsed
3907+ modifiedHeader .GasUsed = claimedGasUsed
39403908 return types .NewBlock (
3941- header ,
3909+ modifiedHeader ,
39423910 []* types.Transaction {tx },
39433911 nil ,
39443912 nil ,
@@ -3984,24 +3952,22 @@ func TestBlockGasValidation(t *testing.T) {
39843952 require .NoError (vm .Shutdown (ctx ))
39853953 }()
39863954
3987- blk := newBlock (t , vm , test .gasUsed )
3988- blkBytes , err := rlp .EncodeToBytes (blk )
3989- require .NoError (err )
3990-
3991- parsedBlk , err := vm .ParseBlock (ctx , blkBytes )
3955+ // Add a transaction to the pool so BuildBlock doesn't create an empty block
3956+ // (subnet-evm doesn't allow empty blocks)
3957+ tx := types .NewTransaction (uint64 (0 ), testEthAddrs [1 ], big .NewInt (1 ), 21000 , big .NewInt (testMinGasPrice ), nil )
3958+ signedTx , err := types .SignTx (tx , types .NewEIP155Signer (vm .chainConfig .ChainID ), testKeys [0 ].ToECDSA ())
39923959 require .NoError (err )
3960+ errs := vm .txPool .AddRemotesSync ([]* types.Transaction {signedTx })
3961+ for i , err := range errs {
3962+ require .NoError (err , "Failed to add tx at index %d" , i )
3963+ }
39933964
3994- parsedBlkWithContext , ok := parsedBlk .(block.WithVerifyContext )
3995- require .True (ok )
3965+ blk := newBlock (t , vm , test .gasUsed )
39963966
3997- shouldVerify , err := parsedBlkWithContext . ShouldVerifyWithContext ( ctx )
3967+ modifiedBlk , err := wrapBlock ( blk , vm )
39983968 require .NoError (err )
3999- require .True (shouldVerify )
40003969
4001- err = parsedBlkWithContext .VerifyWithContext (
4002- ctx ,
4003- & block.Context {},
4004- )
3970+ err = modifiedBlk .Verify (ctx )
40053971 require .ErrorIs (err , test .want )
40063972 })
40073973 }
0 commit comments