Skip to content
This repository has been archived by the owner on Oct 4, 2019. It is now read-only.

Commit

Permalink
Fix merge redundancies and test both external chain configs.
Browse files Browse the repository at this point in the history
Both branches had made a TestChainConfig_GetChainID.
  • Loading branch information
whilei committed May 12, 2017
1 parent 50aeb26 commit 68f193d
Showing 1 changed file with 24 additions and 31 deletions.
55 changes: 24 additions & 31 deletions core/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,24 +292,39 @@ func TestChainConfig_GetFeature4_WorkForHighNumbers(t *testing.T) {
}

func TestChainConfig_GetChainID(t *testing.T) {
// Test default hardcoded configs.
if DefaultConfig.GetChainID().Cmp(DefaultChainConfigChainID) != 0 {
t.Error("got: %v, want: %v", DefaultConfig.GetChainID(), DefaultTestnetChainConfigChainID)
}
if TestConfig.GetChainID().Cmp(DefaultTestnetChainConfigChainID) != 0 {
t.Error("got: %v, want: %v", TestConfig.GetChainID(), DefaultTestnetChainConfigChainID)
}

// Test parsing default external config.
p, e := filepath.Abs("../cmd/geth/config/mainnet.json")
if e != nil {
t.Errorf("filepath err: %v", e)
// If no chainID (config is empty) returns 0.
c := &ChainConfig{}
cid := c.GetChainID()
// check is zero
if cid.Cmp(new(big.Int)) != 0 {
t.Errorf("got: %v, want: %v", cid, new(big.Int))
}
extConfig, err := ReadExternalChainConfig(p)
if err != nil {
t.Errorf("could not find file: %v", err)

// Test parsing default external mainnet config.
cases := map[string]*big.Int{
"../cmd/geth/config/mainnet.json": DefaultChainConfigChainID,
"../cmd/geth/config/testnet.json": DefaultTestnetChainConfigChainID,
}
if extConfig.ChainConfig.GetChainID().Cmp(big.NewInt(61)) != 0 {
t.Error("found 0 chainid for eip155")
for extConfigPath, wantInt := range cases {
p, e := filepath.Abs(extConfigPath)
if e != nil {
t.Errorf("filepath err: %v", e)
}
extConfig, err := ReadExternalChainConfig(p)
if err != nil {
t.Errorf("could not find file: %v", err)
}
if extConfig.ChainConfig.GetChainID().Cmp(wantInt) != 0 {
t.Error("got: %v, want: %v", extConfig.ChainConfig.GetChainID(), wantInt)
}
}
}

Expand Down Expand Up @@ -491,28 +506,6 @@ func TestChainConfig_GetSigner(t *testing.T) {

}

func TestChainConfig_GetChainID(t *testing.T) {
d := DefaultConfig
cid := d.GetChainID()
// check is not zero
if cid.Cmp(new(big.Int)) == 0 {
t.Errorf("got: %v, want: %v", cid, DefaultChainConfigChainID)
}
// check is expected default 61
if cid.Cmp(DefaultChainConfigChainID) != 0 {
t.Errorf("got: %v, want: %v", cid, DefaultChainConfigChainID)
}

// no chain id feature configured, should return zero-value (0)
d = &ChainConfig{}
cid = d.GetChainID()
// check is zero
if cid.Cmp(new(big.Int)) != 0 {
t.Errorf("got: %v, want: %v", cid, new(big.Int))
}

}

func makeOKSufficientChainConfig(dump *GenesisDump, config *ChainConfig) *SufficientChainConfig {
// Setup.
whole := &SufficientChainConfig{}
Expand Down

0 comments on commit 68f193d

Please sign in to comment.