Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion core/chain_makers.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ func (b *BlockGen) SetNonce(nonce types.BlockNonce) {
b.header.Nonce = nonce
}

// SetSlotNumber sets the slot number field of the generated block.
func (b *BlockGen) SetSlotNumber(slot uint64) {
b.header.SlotNumber = &slot
}

// SetDifficulty sets the difficulty field of the generated block. This method is
// useful for Clique tests where the difficulty does not depend on time. For the
// ethash tests, please use OffsetTime, which implicitly recalculates the diff.
Expand All @@ -102,7 +107,11 @@ func (b *BlockGen) Difficulty() *big.Int {
func (b *BlockGen) SetParentBeaconRoot(root common.Hash) {
b.header.ParentBeaconRoot = &root
blockContext := NewEVMBlockContext(b.header, b.cm, &b.header.Coinbase)
ProcessBeaconBlockRoot(root, vm.NewEVM(blockContext, b.statedb, b.cm.config, vm.Config{}))
reads, writes := ProcessBeaconBlockRoot(root, vm.NewEVM(blockContext, b.statedb, b.cm.config, vm.Config{}))
if b.accessList != nil {
b.accessList.AddBlockInitMutations(writes)
b.accessList.AddAccesses(reads)
}
}

// addTx adds a transaction to the generated block. If no coinbase has
Expand Down
27 changes: 12 additions & 15 deletions core/chain_makers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ func TestGenerateBALChain(t *testing.T) {
// TODO: I think we can remove SetBeaconRoot entirely
// and provide a different mechanism to set it?

// gen.SetParentBeaconRoot(common.Hash{byte(i + 1)})
gen.SetParentBeaconRoot(common.Hash{byte(i + 1)})

if gspec.Config.IsAmsterdam(gen.header.Number, gen.header.Time) {
// TODO: parameterize the slot num
Expand Down Expand Up @@ -333,20 +333,17 @@ func TestGenerateBALChain(t *testing.T) {
withdrawalIndex += 1
}

// TODO: can we reinstate the following?
/*
// Verify parent beacon root.
want := common.Hash{byte(blocknum)}
if got := block.BeaconRoot(); *got != want {
t.Fatalf("block %d, wrong parent beacon root: got %s, want %s", i, got, want)
}
state, _ := blockchain.State()
idx := block.Time()%8191 + 8191
got := state.GetState(params.BeaconRootsAddress, common.BigToHash(new(big.Int).SetUint64(idx)))
if got != want {
t.Fatalf("block %d, wrong parent beacon root in state: got %s, want %s", i, got, want)
}
*/
// Verify parent beacon root.
want := common.Hash{byte(blocknum)}
if got := block.BeaconRoot(); *got != want {
t.Fatalf("block %d, wrong parent beacon root: got %s, want %s", i, got, want)
}
state, _ := blockchain.State()
idx := block.Time()%8191 + 8191
got := state.GetState(params.BeaconRootsAddress, common.BigToHash(new(big.Int).SetUint64(idx)))
if got != want {
t.Fatalf("block %d, wrong parent beacon root in state: got %s, want %s", i, got, want)
}
}
}

Expand Down