Skip to content

Commit

Permalink
params: better handle nil and large timestamps
Browse files Browse the repository at this point in the history
  • Loading branch information
holiman committed Jan 20, 2023
1 parent fc9e216 commit fe24470
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
6 changes: 3 additions & 3 deletions params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -1020,8 +1020,8 @@ func (c *ChainConfig) Rules(num *big.Int, isMerge bool, timestamp *big.Int) Rule
IsBerlin: c.IsBerlin(num),
IsLondon: c.IsLondon(num),
IsMerge: isMerge,
IsShanghai: timestamp.IsUint64() && c.IsShanghai(timestamp.Uint64()),
isCancun: timestamp.IsUint64() && c.IsCancun(timestamp.Uint64()),
isPrague: timestamp.IsUint64() && c.IsPrague(timestamp.Uint64()),
IsShanghai: timestamp != nil && (!timestamp.IsUint64() || c.IsShanghai(timestamp.Uint64())),
isCancun: timestamp != nil && (!timestamp.IsUint64() || c.IsCancun(timestamp.Uint64())),
isPrague: timestamp != nil && (!timestamp.IsUint64() || c.IsPrague(timestamp.Uint64())),
}
}
22 changes: 22 additions & 0 deletions params/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,25 @@ func TestCheckCompatible(t *testing.T) {
}
}
}

func TestConfigRules(t *testing.T) {
c := &ChainConfig{
ShanghaiTime: big.NewInt(500),
}
var stamp *big.Int
if r := c.Rules(big.NewInt(0), true, stamp); r.IsShanghai {
t.Errorf("expected %v to not be shanghai", stamp)
}
stamp = big.NewInt(0)
if r := c.Rules(big.NewInt(0), true, stamp); r.IsShanghai {
t.Errorf("expected %v to not be shanghai", stamp)
}
stamp = big.NewInt(500)
if r := c.Rules(big.NewInt(0), true, stamp); !r.IsShanghai {
t.Errorf("expected %v to be shanghai", stamp)
}
stamp, _ = big.NewInt(0).SetString("0xffffffff0000000000000000000000000000000000000000", 0)
if r := c.Rules(big.NewInt(0), true, stamp); !r.IsShanghai {
t.Errorf("expected %v to be shanghai", stamp)
}
}

0 comments on commit fe24470

Please sign in to comment.