forked from cerc-io/plugeth
core/chain_makers: add SetParentBeaconRoot(..) to chain makers (#28252)
This commit is contained in:
parent
b85c86022e
commit
20d5256e40
@ -88,6 +88,17 @@ func (b *BlockGen) SetPoS() {
|
|||||||
b.header.Difficulty = new(big.Int)
|
b.header.Difficulty = new(big.Int)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetParentBeaconRoot sets the parent beacon root field of the generated
|
||||||
|
// block.
|
||||||
|
func (b *BlockGen) SetParentBeaconRoot(root common.Hash) {
|
||||||
|
b.header.ParentBeaconRoot = &root
|
||||||
|
var (
|
||||||
|
blockContext = NewEVMBlockContext(b.header, nil, &b.header.Coinbase)
|
||||||
|
vmenv = vm.NewEVM(blockContext, vm.TxContext{}, b.statedb, b.config, vm.Config{})
|
||||||
|
)
|
||||||
|
ProcessBeaconBlockRoot(root, vmenv, b.statedb)
|
||||||
|
}
|
||||||
|
|
||||||
// addTx adds a transaction to the generated block. If no coinbase has
|
// addTx adds a transaction to the generated block. If no coinbase has
|
||||||
// been set, the block's coinbase is set to the zero address.
|
// been set, the block's coinbase is set to the zero address.
|
||||||
//
|
//
|
||||||
|
@ -32,7 +32,7 @@ import (
|
|||||||
"github.com/ethereum/go-ethereum/trie"
|
"github.com/ethereum/go-ethereum/trie"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGenerateWithdrawalChain(t *testing.T) {
|
func TestGeneratePOSChain(t *testing.T) {
|
||||||
var (
|
var (
|
||||||
keyHex = "9c647b8b7c4e7c3490668fb6c11473619db80c93704c70893d3813af4090c39c"
|
keyHex = "9c647b8b7c4e7c3490668fb6c11473619db80c93704c70893d3813af4090c39c"
|
||||||
key, _ = crypto.HexToECDSA(keyHex)
|
key, _ = crypto.HexToECDSA(keyHex)
|
||||||
@ -41,9 +41,13 @@ func TestGenerateWithdrawalChain(t *testing.T) {
|
|||||||
bb = common.Address{0xbb}
|
bb = common.Address{0xbb}
|
||||||
funds = big.NewInt(0).Mul(big.NewInt(1337), big.NewInt(params.Ether))
|
funds = big.NewInt(0).Mul(big.NewInt(1337), big.NewInt(params.Ether))
|
||||||
config = *params.AllEthashProtocolChanges
|
config = *params.AllEthashProtocolChanges
|
||||||
|
asm4788 = common.Hex2Bytes("3373fffffffffffffffffffffffffffffffffffffffe14604d57602036146024575f5ffd5b5f35801560495762001fff810690815414603c575f5ffd5b62001fff01545f5260205ff35b5f5ffd5b62001fff42064281555f359062001fff015500")
|
||||||
gspec = &Genesis{
|
gspec = &Genesis{
|
||||||
Config: &config,
|
Config: &config,
|
||||||
Alloc: GenesisAlloc{address: {Balance: funds}},
|
Alloc: GenesisAlloc{
|
||||||
|
address: {Balance: funds},
|
||||||
|
params.BeaconRootsStorageAddress: {Balance: common.Big0, Code: asm4788},
|
||||||
|
},
|
||||||
BaseFee: big.NewInt(params.InitialBaseFee),
|
BaseFee: big.NewInt(params.InitialBaseFee),
|
||||||
Difficulty: common.Big1,
|
Difficulty: common.Big1,
|
||||||
GasLimit: 5_000_000,
|
GasLimit: 5_000_000,
|
||||||
@ -56,6 +60,7 @@ func TestGenerateWithdrawalChain(t *testing.T) {
|
|||||||
config.TerminalTotalDifficultyPassed = true
|
config.TerminalTotalDifficultyPassed = true
|
||||||
config.TerminalTotalDifficulty = common.Big0
|
config.TerminalTotalDifficulty = common.Big0
|
||||||
config.ShanghaiTime = u64(0)
|
config.ShanghaiTime = u64(0)
|
||||||
|
config.CancunTime = u64(0)
|
||||||
|
|
||||||
// init 0xaa with some storage elements
|
// init 0xaa with some storage elements
|
||||||
storage := make(map[common.Hash]common.Hash)
|
storage := make(map[common.Hash]common.Hash)
|
||||||
@ -78,6 +83,7 @@ func TestGenerateWithdrawalChain(t *testing.T) {
|
|||||||
genesis := gspec.MustCommit(gendb, trie.NewDatabase(gendb, trie.HashDefaults))
|
genesis := gspec.MustCommit(gendb, trie.NewDatabase(gendb, trie.HashDefaults))
|
||||||
|
|
||||||
chain, _ := GenerateChain(gspec.Config, genesis, beacon.NewFaker(), gendb, 4, func(i int, gen *BlockGen) {
|
chain, _ := GenerateChain(gspec.Config, genesis, beacon.NewFaker(), gendb, 4, func(i int, gen *BlockGen) {
|
||||||
|
gen.SetParentBeaconRoot(common.Hash{byte(i + 1)})
|
||||||
tx, _ := types.SignTx(types.NewTransaction(gen.TxNonce(address), address, big.NewInt(1000), params.TxGas, new(big.Int).Add(gen.BaseFee(), common.Big1), nil), signer, key)
|
tx, _ := types.SignTx(types.NewTransaction(gen.TxNonce(address), address, big.NewInt(1000), params.TxGas, new(big.Int).Add(gen.BaseFee(), common.Big1), nil), signer, key)
|
||||||
gen.AddTx(tx)
|
gen.AddTx(tx)
|
||||||
if i == 1 {
|
if i == 1 {
|
||||||
@ -125,6 +131,8 @@ func TestGenerateWithdrawalChain(t *testing.T) {
|
|||||||
if block == nil {
|
if block == nil {
|
||||||
t.Fatalf("block %d not found", i)
|
t.Fatalf("block %d not found", i)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Verify withdrawals.
|
||||||
if len(block.Withdrawals()) == 0 {
|
if len(block.Withdrawals()) == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -134,6 +142,18 @@ func TestGenerateWithdrawalChain(t *testing.T) {
|
|||||||
}
|
}
|
||||||
withdrawalIndex += 1
|
withdrawalIndex += 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Verify parent beacon root.
|
||||||
|
want := common.Hash{byte(i)}
|
||||||
|
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.BeaconRootsStorageAddress, 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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user