Skip to content

Commit

Permalink
core: move genesis alloc types to core/types (ethereum#29003)
Browse files Browse the repository at this point in the history
  • Loading branch information
gzliudan committed Jan 10, 2025
1 parent aa2f6bf commit 4be3ee5
Show file tree
Hide file tree
Showing 36 changed files with 282 additions and 246 deletions.
4 changes: 2 additions & 2 deletions accounts/abi/bind/backends/simulated.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func SimulateWalletAddressAndSignFn() (common.Address, func(account accounts.Acc
}

// NewXDCSimulatedBackend creates a new backend for testing purpose.
func NewXDCSimulatedBackend(alloc core.GenesisAlloc, gasLimit uint64, chainConfig *params.ChainConfig) *SimulatedBackend {
func NewXDCSimulatedBackend(alloc types.GenesisAlloc, gasLimit uint64, chainConfig *params.ChainConfig) *SimulatedBackend {
database := rawdb.NewMemoryDatabase()
genesis := core.Genesis{
GasLimit: gasLimit, // need this big, support initial smart contract
Expand Down Expand Up @@ -147,7 +147,7 @@ func NewXDCSimulatedBackend(alloc core.GenesisAlloc, gasLimit uint64, chainConfi
// SimulOldNewSimulatedBackendatedBackend creates a new binding backend based on the given database
// and uses a simulated blockchain for testing purposes.
// A simulated backend always uses chainID 1337.
func NewSimulatedBackend(alloc core.GenesisAlloc, gasLimit uint64) *SimulatedBackend {
func NewSimulatedBackend(alloc types.GenesisAlloc, gasLimit uint64) *SimulatedBackend {
database := rawdb.NewMemoryDatabase()
genesis := core.Genesis{Config: params.AllEthashProtocolChanges, GasLimit: gasLimit, Alloc: alloc}
genesis.MustCommit(database)
Expand Down
21 changes: 10 additions & 11 deletions accounts/abi/bind/backends/simulated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (
"github.com/XinFinOrg/XDPoSChain/accounts/abi"
"github.com/XinFinOrg/XDPoSChain/accounts/abi/bind"
"github.com/XinFinOrg/XDPoSChain/common"
"github.com/XinFinOrg/XDPoSChain/core"
"github.com/XinFinOrg/XDPoSChain/core/types"
"github.com/XinFinOrg/XDPoSChain/crypto"
"github.com/XinFinOrg/XDPoSChain/params"
Expand All @@ -42,8 +41,8 @@ func TestSimulatedBackend(t *testing.T) {
var gasLimit uint64 = 8000029
key, _ := crypto.GenerateKey() // nolint: gosec
auth, _ := bind.NewKeyedTransactorWithChainID(key, big.NewInt(1337))
genAlloc := make(core.GenesisAlloc)
genAlloc[auth.From] = core.GenesisAccount{Balance: big.NewInt(9223372036854775807)}
genAlloc := make(types.GenesisAlloc)
genAlloc[auth.From] = types.Account{Balance: big.NewInt(9223372036854775807)}

config := *params.TestXDPoSMockChainConfig
config.Eip1559Block = big.NewInt(0)
Expand Down Expand Up @@ -119,7 +118,7 @@ func simTestBackend(testAddr common.Address) *SimulatedBackend {
config := *params.TestXDPoSMockChainConfig
config.Eip1559Block = big.NewInt(0)
return NewXDCSimulatedBackend(
core.GenesisAlloc{
types.GenesisAlloc{
testAddr: {Balance: big.NewInt(100000000000000000)},
},
10000000,
Expand All @@ -144,7 +143,7 @@ func TestNewSimulatedBackend(t *testing.T) {
func TestAdjustTime(t *testing.T) {
t.Parallel()
sim := NewXDCSimulatedBackend(
core.GenesisAlloc{},
types.GenesisAlloc{},
10000000,
params.TestXDPoSMockChainConfig,
)
Expand Down Expand Up @@ -226,7 +225,7 @@ func TestBalanceAt(t *testing.T) {
func TestBlockByHash(t *testing.T) {
t.Parallel()
sim := NewXDCSimulatedBackend(
core.GenesisAlloc{},
types.GenesisAlloc{},
10000000,
params.TestXDPoSMockChainConfig,
)
Expand All @@ -250,7 +249,7 @@ func TestBlockByHash(t *testing.T) {
func TestBlockByNumber(t *testing.T) {
t.Parallel()
sim := NewXDCSimulatedBackend(
core.GenesisAlloc{},
types.GenesisAlloc{},
10000000,
params.TestXDPoSMockChainConfig,
)
Expand Down Expand Up @@ -446,7 +445,7 @@ func TestEstimateGas(t *testing.T) {
opts, _ := bind.NewKeyedTransactorWithChainID(key, big.NewInt(1337))

sim := NewXDCSimulatedBackend(
core.GenesisAlloc{addr: {Balance: big.NewInt(params.Ether)}},
types.GenesisAlloc{addr: {Balance: big.NewInt(params.Ether)}},
10000000,
params.TestXDPoSMockChainConfig,
)
Expand Down Expand Up @@ -557,10 +556,10 @@ func TestEstimateGasWithPrice(t *testing.T) {
addr := crypto.PubkeyToAddress(key.PublicKey)

sim := NewXDCSimulatedBackend(
core.GenesisAlloc{addr: {Balance: big.NewInt(params.Ether*2 + 2e17)}},
types.GenesisAlloc{addr: {Balance: big.NewInt(params.Ether*2 + 2e17)}},
10000000,
params.TestXDPoSMockChainConfig,
)
)
defer sim.Close()

recipient := common.HexToAddress("deadbeef")
Expand Down Expand Up @@ -908,7 +907,7 @@ func TestTransactionReceipt(t *testing.T) {
func TestSuggestGasPrice(t *testing.T) {
t.Parallel()
sim := NewXDCSimulatedBackend(
core.GenesisAlloc{},
types.GenesisAlloc{},
10000000,
params.TestXDPoSMockChainConfig,
)
Expand Down
Loading

0 comments on commit 4be3ee5

Please sign in to comment.