Skip to content

Commit 11b5847

Browse files
ceyonurJonathanOppenheimer
authored andcommitted
simplify test (#1268)
1 parent 7293eed commit 11b5847

File tree

1 file changed

+9
-51
lines changed

1 file changed

+9
-51
lines changed

plugin/evm/vm_test.go

Lines changed: 9 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818

1919
"github.com/ava-labs/avalanchego/database"
2020
"github.com/ava-labs/avalanchego/ids"
21-
"github.com/ava-labs/avalanchego/snow/engine/snowman/block"
2221
"github.com/ava-labs/avalanchego/snow/snowtest"
2322
"github.com/ava-labs/avalanchego/upgrade"
2423
"github.com/ava-labs/avalanchego/upgrade/upgradetest"
@@ -32,7 +31,6 @@ import (
3231
"github.com/ava-labs/libevm/core/types"
3332
"github.com/ava-labs/libevm/crypto"
3433
"github.com/ava-labs/libevm/log"
35-
"github.com/ava-labs/libevm/rlp"
3634
"github.com/ava-labs/libevm/trie"
3735
"github.com/holiman/uint256"
3836
"github.com/stretchr/testify/assert"
@@ -2279,13 +2277,7 @@ func TestBlockGasValidation(t *testing.T) {
22792277
) *types.Block {
22802278
require := require.New(t)
22812279

2282-
chainExtra := params.GetExtra(vm.chainConfig)
2283-
parent := vm.eth.APIBackend.CurrentBlock()
2284-
const timeDelta = acp176.TimeToFillCapacity
2285-
timestamp := parent.Time + timeDelta
2286-
gasLimit, err := customheader.GasLimit(chainExtra, parent, timestamp)
2287-
require.NoError(err)
2288-
baseFee, err := customheader.BaseFee(chainExtra, parent, timestamp)
2280+
blk, err := vm.BuildBlock(context.Background())
22892281
require.NoError(err)
22902282

22912283
callPayload, err := payload.NewAddressedCall(nil, nil)
@@ -2324,8 +2316,8 @@ func TestBlockGasValidation(t *testing.T) {
23242316
Nonce: 1,
23252317
To: &vmtest.TestEthAddrs[0],
23262318
Gas: acp176.MinMaxCapacity,
2327-
GasFeeCap: baseFee,
2328-
GasTipCap: baseFee,
2319+
GasFeeCap: big.NewInt(10),
2320+
GasTipCap: big.NewInt(10),
23292321
Value: common.Big0,
23302322
AccessList: accessList,
23312323
}),
@@ -2334,36 +2326,14 @@ func TestBlockGasValidation(t *testing.T) {
23342326
)
23352327
require.NoError(err)
23362328

2337-
header := &types.Header{
2338-
ParentHash: parent.Hash(),
2339-
Coinbase: constants.BlackholeAddr,
2340-
Difficulty: new(big.Int).Add(parent.Difficulty, common.Big1),
2341-
Number: new(big.Int).Add(parent.Number, common.Big1),
2342-
GasLimit: gasLimit,
2343-
GasUsed: 0,
2344-
Time: timestamp,
2345-
BaseFee: baseFee,
2346-
BlobGasUsed: new(uint64),
2347-
ExcessBlobGas: new(uint64),
2348-
ParentBeaconRoot: &common.Hash{},
2349-
}
2350-
2351-
configExtra := params.GetExtra(vm.chainConfig)
2352-
header.Extra, err = customheader.ExtraPrefix(configExtra, parent, header, nil)
2353-
require.NoError(err)
2354-
2355-
// Set TimeMilliseconds for Granite blocks
2356-
if configExtra.IsGranite(timestamp) {
2357-
headerExtra := customtypes.GetHeaderExtra(header)
2358-
timeMilliseconds := timestamp * 1000
2359-
headerExtra.TimeMilliseconds = &timeMilliseconds
2360-
}
2329+
ethBlock := blk.(*chain.BlockWrapper).Block.(*wrappedBlock).ethBlock
2330+
modifiedHeader := types.CopyHeader(ethBlock.Header())
23612331

23622332
// Set the gasUsed after calculating the extra prefix to support large
23632333
// claimed gas used values.
2364-
header.GasUsed = claimedGasUsed
2334+
modifiedHeader.GasUsed = claimedGasUsed
23652335
return customtypes.NewBlockWithExtData(
2366-
header,
2336+
modifiedHeader,
23672337
[]*types.Transaction{tx},
23682338
nil,
23692339
nil,
@@ -2401,23 +2371,11 @@ func TestBlockGasValidation(t *testing.T) {
24012371
}()
24022372

24032373
blk := newBlock(t, vm, test.gasUsed)
2404-
blkBytes, err := rlp.EncodeToBytes(blk)
2405-
require.NoError(err)
24062374

2407-
parsedBlk, err := vm.ParseBlock(ctx, blkBytes)
2375+
modifiedBlk, err := wrapBlock(blk, vm)
24082376
require.NoError(err)
24092377

2410-
parsedBlkWithContext, ok := parsedBlk.(block.WithVerifyContext)
2411-
require.True(ok)
2412-
2413-
shouldVerify, err := parsedBlkWithContext.ShouldVerifyWithContext(ctx)
2414-
require.NoError(err)
2415-
require.True(shouldVerify)
2416-
2417-
err = parsedBlkWithContext.VerifyWithContext(
2418-
ctx,
2419-
&block.Context{},
2420-
)
2378+
err = modifiedBlk.Verify(ctx)
24212379
require.ErrorIs(err, test.want)
24222380
})
24232381
}

0 commit comments

Comments
 (0)