mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
tests: update definitions
This commit is contained in:
parent
35971646b5
commit
5983fa65f2
4 changed files with 25 additions and 21 deletions
|
|
@ -82,7 +82,7 @@ type btHeader struct {
|
||||||
Difficulty *big.Int
|
Difficulty *big.Int
|
||||||
GasLimit uint64
|
GasLimit uint64
|
||||||
GasUsed uint64
|
GasUsed uint64
|
||||||
Timestamp *big.Int
|
Timestamp uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
type btHeaderMarshaling struct {
|
type btHeaderMarshaling struct {
|
||||||
|
|
@ -91,7 +91,7 @@ type btHeaderMarshaling struct {
|
||||||
Difficulty *math.HexOrDecimal256
|
Difficulty *math.HexOrDecimal256
|
||||||
GasLimit math.HexOrDecimal64
|
GasLimit math.HexOrDecimal64
|
||||||
GasUsed math.HexOrDecimal64
|
GasUsed math.HexOrDecimal64
|
||||||
Timestamp *math.HexOrDecimal256
|
Timestamp math.HexOrDecimal64
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *BlockTest) Run() error {
|
func (t *BlockTest) Run() error {
|
||||||
|
|
@ -146,7 +146,7 @@ func (t *BlockTest) genesis(config *params.ChainConfig) *core.Genesis {
|
||||||
return &core.Genesis{
|
return &core.Genesis{
|
||||||
Config: config,
|
Config: config,
|
||||||
Nonce: t.json.Genesis.Nonce.Uint64(),
|
Nonce: t.json.Genesis.Nonce.Uint64(),
|
||||||
Timestamp: t.json.Genesis.Timestamp.Uint64(),
|
Timestamp: t.json.Genesis.Timestamp,
|
||||||
ParentHash: t.json.Genesis.ParentHash,
|
ParentHash: t.json.Genesis.ParentHash,
|
||||||
ExtraData: t.json.Genesis.ExtraData,
|
ExtraData: t.json.Genesis.ExtraData,
|
||||||
GasLimit: t.json.Genesis.GasLimit,
|
GasLimit: t.json.Genesis.GasLimit,
|
||||||
|
|
@ -248,7 +248,7 @@ func validateHeader(h *btHeader, h2 *types.Header) error {
|
||||||
if h.GasUsed != h2.GasUsed {
|
if h.GasUsed != h2.GasUsed {
|
||||||
return fmt.Errorf("GasUsed: want: %d have: %d", h.GasUsed, h2.GasUsed)
|
return fmt.Errorf("GasUsed: want: %d have: %d", h.GasUsed, h2.GasUsed)
|
||||||
}
|
}
|
||||||
if h.Timestamp.Cmp(h2.Time) != 0 {
|
if h.Timestamp != h2.Time {
|
||||||
return fmt.Errorf("Timestamp: want: %v have: %v", h.Timestamp, h2.Time)
|
return fmt.Errorf("Timestamp: want: %v have: %v", h.Timestamp, h2.Time)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
|
||||||
|
|
@ -30,18 +30,18 @@ import (
|
||||||
//go:generate gencodec -type DifficultyTest -field-override difficultyTestMarshaling -out gen_difficultytest.go
|
//go:generate gencodec -type DifficultyTest -field-override difficultyTestMarshaling -out gen_difficultytest.go
|
||||||
|
|
||||||
type DifficultyTest struct {
|
type DifficultyTest struct {
|
||||||
ParentTimestamp *big.Int `json:"parentTimestamp"`
|
ParentTimestamp uint64 `json:"parentTimestamp"`
|
||||||
ParentDifficulty *big.Int `json:"parentDifficulty"`
|
ParentDifficulty *big.Int `json:"parentDifficulty"`
|
||||||
UncleHash common.Hash `json:"parentUncles"`
|
UncleHash common.Hash `json:"parentUncles"`
|
||||||
CurrentTimestamp *big.Int `json:"currentTimestamp"`
|
CurrentTimestamp uint64 `json:"currentTimestamp"`
|
||||||
CurrentBlockNumber uint64 `json:"currentBlockNumber"`
|
CurrentBlockNumber uint64 `json:"currentBlockNumber"`
|
||||||
CurrentDifficulty *big.Int `json:"currentDifficulty"`
|
CurrentDifficulty *big.Int `json:"currentDifficulty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type difficultyTestMarshaling struct {
|
type difficultyTestMarshaling struct {
|
||||||
ParentTimestamp *math.HexOrDecimal256
|
ParentTimestamp math.HexOrDecimal64
|
||||||
ParentDifficulty *math.HexOrDecimal256
|
ParentDifficulty *math.HexOrDecimal256
|
||||||
CurrentTimestamp *math.HexOrDecimal256
|
CurrentTimestamp math.HexOrDecimal64
|
||||||
CurrentDifficulty *math.HexOrDecimal256
|
CurrentDifficulty *math.HexOrDecimal256
|
||||||
UncleHash common.Hash
|
UncleHash common.Hash
|
||||||
CurrentBlockNumber math.HexOrDecimal64
|
CurrentBlockNumber math.HexOrDecimal64
|
||||||
|
|
@ -56,7 +56,7 @@ func (test *DifficultyTest) Run(config *params.ChainConfig) error {
|
||||||
UncleHash: test.UncleHash,
|
UncleHash: test.UncleHash,
|
||||||
}
|
}
|
||||||
|
|
||||||
actual := ethash.CalcDifficulty(config, test.CurrentTimestamp.Uint64(), parent)
|
actual := ethash.CalcDifficulty(config, test.CurrentTimestamp, parent)
|
||||||
exp := test.CurrentDifficulty
|
exp := test.CurrentDifficulty
|
||||||
|
|
||||||
if actual.Cmp(exp) != 0 {
|
if actual.Cmp(exp) != 0 {
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ import (
|
||||||
|
|
||||||
var _ = (*btHeaderMarshaling)(nil)
|
var _ = (*btHeaderMarshaling)(nil)
|
||||||
|
|
||||||
|
// MarshalJSON marshals as JSON.
|
||||||
func (b btHeader) MarshalJSON() ([]byte, error) {
|
func (b btHeader) MarshalJSON() ([]byte, error) {
|
||||||
type btHeader struct {
|
type btHeader struct {
|
||||||
Bloom types.Bloom
|
Bloom types.Bloom
|
||||||
|
|
@ -31,7 +32,7 @@ func (b btHeader) MarshalJSON() ([]byte, error) {
|
||||||
Difficulty *math.HexOrDecimal256
|
Difficulty *math.HexOrDecimal256
|
||||||
GasLimit math.HexOrDecimal64
|
GasLimit math.HexOrDecimal64
|
||||||
GasUsed math.HexOrDecimal64
|
GasUsed math.HexOrDecimal64
|
||||||
Timestamp *math.HexOrDecimal256
|
Timestamp math.HexOrDecimal64
|
||||||
}
|
}
|
||||||
var enc btHeader
|
var enc btHeader
|
||||||
enc.Bloom = b.Bloom
|
enc.Bloom = b.Bloom
|
||||||
|
|
@ -49,10 +50,11 @@ func (b btHeader) MarshalJSON() ([]byte, error) {
|
||||||
enc.Difficulty = (*math.HexOrDecimal256)(b.Difficulty)
|
enc.Difficulty = (*math.HexOrDecimal256)(b.Difficulty)
|
||||||
enc.GasLimit = math.HexOrDecimal64(b.GasLimit)
|
enc.GasLimit = math.HexOrDecimal64(b.GasLimit)
|
||||||
enc.GasUsed = math.HexOrDecimal64(b.GasUsed)
|
enc.GasUsed = math.HexOrDecimal64(b.GasUsed)
|
||||||
enc.Timestamp = (*math.HexOrDecimal256)(b.Timestamp)
|
enc.Timestamp = math.HexOrDecimal64(b.Timestamp)
|
||||||
return json.Marshal(&enc)
|
return json.Marshal(&enc)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UnmarshalJSON unmarshals from JSON.
|
||||||
func (b *btHeader) UnmarshalJSON(input []byte) error {
|
func (b *btHeader) UnmarshalJSON(input []byte) error {
|
||||||
type btHeader struct {
|
type btHeader struct {
|
||||||
Bloom *types.Bloom
|
Bloom *types.Bloom
|
||||||
|
|
@ -70,7 +72,7 @@ func (b *btHeader) UnmarshalJSON(input []byte) error {
|
||||||
Difficulty *math.HexOrDecimal256
|
Difficulty *math.HexOrDecimal256
|
||||||
GasLimit *math.HexOrDecimal64
|
GasLimit *math.HexOrDecimal64
|
||||||
GasUsed *math.HexOrDecimal64
|
GasUsed *math.HexOrDecimal64
|
||||||
Timestamp *math.HexOrDecimal256
|
Timestamp *math.HexOrDecimal64
|
||||||
}
|
}
|
||||||
var dec btHeader
|
var dec btHeader
|
||||||
if err := json.Unmarshal(input, &dec); err != nil {
|
if err := json.Unmarshal(input, &dec); err != nil {
|
||||||
|
|
@ -122,7 +124,7 @@ func (b *btHeader) UnmarshalJSON(input []byte) error {
|
||||||
b.GasUsed = uint64(*dec.GasUsed)
|
b.GasUsed = uint64(*dec.GasUsed)
|
||||||
}
|
}
|
||||||
if dec.Timestamp != nil {
|
if dec.Timestamp != nil {
|
||||||
b.Timestamp = (*big.Int)(dec.Timestamp)
|
b.Timestamp = uint64(*dec.Timestamp)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,31 +12,33 @@ import (
|
||||||
|
|
||||||
var _ = (*difficultyTestMarshaling)(nil)
|
var _ = (*difficultyTestMarshaling)(nil)
|
||||||
|
|
||||||
|
// MarshalJSON marshals as JSON.
|
||||||
func (d DifficultyTest) MarshalJSON() ([]byte, error) {
|
func (d DifficultyTest) MarshalJSON() ([]byte, error) {
|
||||||
type DifficultyTest struct {
|
type DifficultyTest struct {
|
||||||
ParentTimestamp *math.HexOrDecimal256 `json:"parentTimestamp"`
|
ParentTimestamp math.HexOrDecimal64 `json:"parentTimestamp"`
|
||||||
ParentDifficulty *math.HexOrDecimal256 `json:"parentDifficulty"`
|
ParentDifficulty *math.HexOrDecimal256 `json:"parentDifficulty"`
|
||||||
UncleHash common.Hash `json:"parentUncles"`
|
UncleHash common.Hash `json:"parentUncles"`
|
||||||
CurrentTimestamp *math.HexOrDecimal256 `json:"currentTimestamp"`
|
CurrentTimestamp math.HexOrDecimal64 `json:"currentTimestamp"`
|
||||||
CurrentBlockNumber math.HexOrDecimal64 `json:"currentBlockNumber"`
|
CurrentBlockNumber math.HexOrDecimal64 `json:"currentBlockNumber"`
|
||||||
CurrentDifficulty *math.HexOrDecimal256 `json:"currentDifficulty"`
|
CurrentDifficulty *math.HexOrDecimal256 `json:"currentDifficulty"`
|
||||||
}
|
}
|
||||||
var enc DifficultyTest
|
var enc DifficultyTest
|
||||||
enc.ParentTimestamp = (*math.HexOrDecimal256)(d.ParentTimestamp)
|
enc.ParentTimestamp = math.HexOrDecimal64(d.ParentTimestamp)
|
||||||
enc.ParentDifficulty = (*math.HexOrDecimal256)(d.ParentDifficulty)
|
enc.ParentDifficulty = (*math.HexOrDecimal256)(d.ParentDifficulty)
|
||||||
enc.UncleHash = d.UncleHash
|
enc.UncleHash = d.UncleHash
|
||||||
enc.CurrentTimestamp = (*math.HexOrDecimal256)(d.CurrentTimestamp)
|
enc.CurrentTimestamp = math.HexOrDecimal64(d.CurrentTimestamp)
|
||||||
enc.CurrentBlockNumber = math.HexOrDecimal64(d.CurrentBlockNumber)
|
enc.CurrentBlockNumber = math.HexOrDecimal64(d.CurrentBlockNumber)
|
||||||
enc.CurrentDifficulty = (*math.HexOrDecimal256)(d.CurrentDifficulty)
|
enc.CurrentDifficulty = (*math.HexOrDecimal256)(d.CurrentDifficulty)
|
||||||
return json.Marshal(&enc)
|
return json.Marshal(&enc)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UnmarshalJSON unmarshals from JSON.
|
||||||
func (d *DifficultyTest) UnmarshalJSON(input []byte) error {
|
func (d *DifficultyTest) UnmarshalJSON(input []byte) error {
|
||||||
type DifficultyTest struct {
|
type DifficultyTest struct {
|
||||||
ParentTimestamp *math.HexOrDecimal256 `json:"parentTimestamp"`
|
ParentTimestamp *math.HexOrDecimal64 `json:"parentTimestamp"`
|
||||||
ParentDifficulty *math.HexOrDecimal256 `json:"parentDifficulty"`
|
ParentDifficulty *math.HexOrDecimal256 `json:"parentDifficulty"`
|
||||||
UncleHash *common.Hash `json:"parentUncles"`
|
UncleHash *common.Hash `json:"parentUncles"`
|
||||||
CurrentTimestamp *math.HexOrDecimal256 `json:"currentTimestamp"`
|
CurrentTimestamp *math.HexOrDecimal64 `json:"currentTimestamp"`
|
||||||
CurrentBlockNumber *math.HexOrDecimal64 `json:"currentBlockNumber"`
|
CurrentBlockNumber *math.HexOrDecimal64 `json:"currentBlockNumber"`
|
||||||
CurrentDifficulty *math.HexOrDecimal256 `json:"currentDifficulty"`
|
CurrentDifficulty *math.HexOrDecimal256 `json:"currentDifficulty"`
|
||||||
}
|
}
|
||||||
|
|
@ -45,7 +47,7 @@ func (d *DifficultyTest) UnmarshalJSON(input []byte) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if dec.ParentTimestamp != nil {
|
if dec.ParentTimestamp != nil {
|
||||||
d.ParentTimestamp = (*big.Int)(dec.ParentTimestamp)
|
d.ParentTimestamp = uint64(*dec.ParentTimestamp)
|
||||||
}
|
}
|
||||||
if dec.ParentDifficulty != nil {
|
if dec.ParentDifficulty != nil {
|
||||||
d.ParentDifficulty = (*big.Int)(dec.ParentDifficulty)
|
d.ParentDifficulty = (*big.Int)(dec.ParentDifficulty)
|
||||||
|
|
@ -54,7 +56,7 @@ func (d *DifficultyTest) UnmarshalJSON(input []byte) error {
|
||||||
d.UncleHash = *dec.UncleHash
|
d.UncleHash = *dec.UncleHash
|
||||||
}
|
}
|
||||||
if dec.CurrentTimestamp != nil {
|
if dec.CurrentTimestamp != nil {
|
||||||
d.CurrentTimestamp = (*big.Int)(dec.CurrentTimestamp)
|
d.CurrentTimestamp = uint64(*dec.CurrentTimestamp)
|
||||||
}
|
}
|
||||||
if dec.CurrentBlockNumber != nil {
|
if dec.CurrentBlockNumber != nil {
|
||||||
d.CurrentBlockNumber = uint64(*dec.CurrentBlockNumber)
|
d.CurrentBlockNumber = uint64(*dec.CurrentBlockNumber)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue