MCPcopy Create free account
hub / github.com/CPChain/chain / TestSetupGenesis

Function TestSetupGenesis

core/genesis_test.go:42–130  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

40}
41
42func TestSetupGenesis(t *testing.T) {
43 runmode := configs.GetRunMode()
44 configs.SetRunMode(configs.Mainnet)
45 var (
46 customghash = common.HexToHash("0x7665f953c35e95322ebc826f0293500e3bf00689f1f9565be0b7cd097897988d")
47 customg = Genesis{
48 Config: &configs.ChainConfig{},
49 Alloc: GenesisAlloc{
50 {1}: {Balance: big.NewInt(1), Storage: map[common.Hash]common.Hash{{1}: {1}}},
51 },
52 }
53 oldcustomg = customg
54 )
55 oldcustomg.Config = &configs.ChainConfig{}
56 tests := []struct {
57 name string
58 fn func(database.Database) (*configs.ChainConfig, common.Hash, error)
59 wantConfig *configs.ChainConfig
60 wantHash common.Hash
61 wantErr error
62 }{
63 {
64 name: "genesis without ChainConfig",
65 fn: func(db database.Database) (*configs.ChainConfig, common.Hash, error) {
66 return SetupGenesisBlock(db, new(Genesis))
67 },
68 wantErr: errGenesisNoConfig,
69 wantConfig: configs.ChainConfigInfo(),
70 },
71 {
72 name: "no block in DB, genesis == nil",
73 fn: func(db database.Database) (*configs.ChainConfig, common.Hash, error) {
74 return SetupGenesisBlock(db, nil)
75 },
76 wantHash: MainnetGenesisHash,
77 wantConfig: configs.ChainConfigInfo(),
78 },
79 {
80 name: "mainnet block in DB, genesis == nil",
81 fn: func(db database.Database) (*configs.ChainConfig, common.Hash, error) {
82 DefaultGenesisBlock().MustCommit(db)
83 return SetupGenesisBlock(db, nil)
84 },
85 wantHash: MainnetGenesisHash,
86 wantConfig: configs.ChainConfigInfo(),
87 },
88 {
89 name: "custom block in DB, genesis == nil",
90 fn: func(db database.Database) (*configs.ChainConfig, common.Hash, error) {
91 customg.MustCommit(db)
92 return SetupGenesisBlock(db, nil)
93 },
94 wantHash: customghash,
95 wantConfig: customg.Config,
96 },
97 {
98 name: "compatible config in DB",
99 fn: func(db database.Database) (*configs.ChainConfig, common.Hash, error) {

Callers

nothing calls this directly

Calls 5

SetupGenesisBlockFunction · 0.85
DefaultGenesisBlockFunction · 0.85
ChainConfigInfoMethod · 0.80
MustCommitMethod · 0.80
HashMethod · 0.65

Tested by

no test coverage detected