mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-18 10:50:44 +00:00
Merge 9e445ae7f3 into dddbaa4bf3
This commit is contained in:
commit
0abb6b0f82
2 changed files with 47 additions and 1 deletions
|
|
@ -2745,6 +2745,47 @@ func TestSimulateV1WithdrawalsByFork(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSimulateV1DifficultyOverridePostMerge(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
gspec := &core.Genesis{Config: params.MergedTestChainConfig, Alloc: types.GenesisAlloc{}}
|
||||||
|
backend := newTestBackend(t, 1, gspec, beacon.New(ethash.NewFaker()), func(i int, b *core.BlockGen) { b.SetPoS() })
|
||||||
|
|
||||||
|
ctx := context.Background()
|
||||||
|
stateDB, baseHeader, err := backend.StateAndHeaderByNumberOrHash(ctx, rpc.BlockNumberOrHashWithNumber(rpc.LatestBlockNumber))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to get state and header: %v", err)
|
||||||
|
}
|
||||||
|
sim := &simulator{
|
||||||
|
b: backend,
|
||||||
|
state: stateDB,
|
||||||
|
base: baseHeader,
|
||||||
|
chainConfig: backend.ChainConfig(),
|
||||||
|
budget: newGasBudget(0),
|
||||||
|
}
|
||||||
|
|
||||||
|
diff := (*hexutil.Big)(big.NewInt(0xCAFE0000))
|
||||||
|
results, err := sim.execute(ctx, []simBlock{{
|
||||||
|
BlockOverrides: &override.BlockOverrides{Difficulty: diff},
|
||||||
|
}})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("simulation execution failed: %v", err)
|
||||||
|
}
|
||||||
|
require.Len(t, results, 1)
|
||||||
|
|
||||||
|
enc, err := json.Marshal(results[0])
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to marshal result: %v", err)
|
||||||
|
}
|
||||||
|
var raw map[string]json.RawMessage
|
||||||
|
if err := json.Unmarshal(enc, &raw); err != nil {
|
||||||
|
t.Fatalf("failed to unmarshal result: %v", err)
|
||||||
|
}
|
||||||
|
if got := string(raw["difficulty"]); got != `"0x0"` {
|
||||||
|
t.Fatalf("difficulty override was not a no-op post-merge: got %s, want \"0x0\"\n%s", got, enc)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestSignTransaction(t *testing.T) {
|
func TestSignTransaction(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
// Initialize test accounts
|
// Initialize test accounts
|
||||||
|
|
|
||||||
|
|
@ -562,8 +562,9 @@ func (sim *simulator) makeHeaders(blocks []simBlock) ([]*types.Header, error) {
|
||||||
}
|
}
|
||||||
// Set difficulty to zero if the given block is post-merge. Without this, all post-merge hardforks would remain inactive.
|
// Set difficulty to zero if the given block is post-merge. Without this, all post-merge hardforks would remain inactive.
|
||||||
// For example, calling eth_simulateV1(..., blockParameter: 0x0) on hoodi network will cause all blocks to have a difficulty of 1 and be treated as pre-merge.
|
// For example, calling eth_simulateV1(..., blockParameter: 0x0) on hoodi network will cause all blocks to have a difficulty of 1 and be treated as pre-merge.
|
||||||
|
isPostMerge := sim.chainConfig.IsPostMerge(number.Uint64(), timestamp)
|
||||||
difficulty := header.Difficulty
|
difficulty := header.Difficulty
|
||||||
if sim.chainConfig.IsPostMerge(number.Uint64(), timestamp) {
|
if isPostMerge {
|
||||||
difficulty = big.NewInt(0)
|
difficulty = big.NewInt(0)
|
||||||
}
|
}
|
||||||
header = overrides.MakeHeader(&types.Header{
|
header = overrides.MakeHeader(&types.Header{
|
||||||
|
|
@ -576,6 +577,10 @@ func (sim *simulator) makeHeaders(blocks []simBlock) ([]*types.Header, error) {
|
||||||
WithdrawalsHash: withdrawalsHash,
|
WithdrawalsHash: withdrawalsHash,
|
||||||
ParentBeaconRoot: parentBeaconRoot,
|
ParentBeaconRoot: parentBeaconRoot,
|
||||||
})
|
})
|
||||||
|
// A difficulty override is documented as a no-op for post-merge blocks.
|
||||||
|
if isPostMerge {
|
||||||
|
header.Difficulty = big.NewInt(0)
|
||||||
|
}
|
||||||
res[bi] = header
|
res[bi] = header
|
||||||
}
|
}
|
||||||
return res, nil
|
return res, nil
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue