mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2025-01-05 18:42:19 +00:00
e4e36c152e
* interface * generalize interface * linters * fix deadlock * fix linters * close goroutine * fix * debug * id+ttl * refactor downloader tests * tests * lru * handle genesis, extract fake consensuses * fix fake consensus * test uncles, verify * after a new master * fmt * fix close * debug * debug * fix chain length * remove test field * use single account * fix data race on closing channel * remove postponed blocks queue * miner test * VerifyHeaderRequests * fmt * fmt * fix data race * handle validating errors * simplify matchParents * remove copy-paste * move sort to constructor * clean up * debug for 10 parents * debug * debug * batch responses * batch requests * works for many ancestors * remove debug * always Close an engine * linters * ancestors deduplication * fix test * reduce interface * api * clique * green clique sync * stable * perpermance per second * full sync * linters * gitignore * deps * fix panic after master merge * init consensus * clique tests * fix tests * fix tests * clean up * reuse snap * store vefified snapshots * optimize snapshots * safe close * cleanup loop * after downloader * downloader and consensus tests * update tests * hack.go * clique flags * fix cliuqe config * review * gitignore * remove additional bucket * blk/sec instead of blk/microsecond * rename * deps * optimize * debug * test * tests without extracted validation process * same base performance as on master * benchmark * simplify ethash verification * ethash * ethash * linters * ethash * master stats * cleanup * gomod * linters * tests * better locks * Fix * Remove logging for verifyHeaders * Verification speed in the logs * Fix compile error Co-authored-by: Alexey Sharp <alexeysharp@Alexeys-iMac.local>
89 lines
2.6 KiB
Go
89 lines
2.6 KiB
Go
// Copyright 2017 The go-ethereum Authors
|
|
// This file is part of the go-ethereum library.
|
|
//
|
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU Lesser General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU Lesser General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
package ethash
|
|
|
|
import (
|
|
"math/big"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/ledgerwatch/turbo-geth/common/math"
|
|
"github.com/ledgerwatch/turbo-geth/core/types"
|
|
"github.com/ledgerwatch/turbo-geth/params"
|
|
|
|
json "github.com/json-iterator/go"
|
|
)
|
|
|
|
type diffTest struct {
|
|
ParentTimestamp uint64
|
|
ParentDifficulty *big.Int
|
|
CurrentTimestamp uint64
|
|
CurrentBlocknumber *big.Int
|
|
CurrentDifficulty *big.Int
|
|
}
|
|
|
|
func (d *diffTest) UnmarshalJSON(b []byte) (err error) {
|
|
var ext struct {
|
|
ParentTimestamp string
|
|
ParentDifficulty string
|
|
CurrentTimestamp string
|
|
CurrentBlocknumber string
|
|
CurrentDifficulty string
|
|
}
|
|
if err := json.Unmarshal(b, &ext); err != nil {
|
|
return err
|
|
}
|
|
|
|
d.ParentTimestamp = math.MustParseUint64(ext.ParentTimestamp)
|
|
d.ParentDifficulty = math.MustParseBig256(ext.ParentDifficulty)
|
|
d.CurrentTimestamp = math.MustParseUint64(ext.CurrentTimestamp)
|
|
d.CurrentBlocknumber = math.MustParseBig256(ext.CurrentBlocknumber)
|
|
d.CurrentDifficulty = math.MustParseBig256(ext.CurrentDifficulty)
|
|
|
|
return nil
|
|
}
|
|
|
|
func TestCalcDifficulty(t *testing.T) {
|
|
file, err := os.Open(filepath.Join("..", "..", "tests", "testdata", "BasicTests", "difficulty.json"))
|
|
if err != nil {
|
|
t.Skip(err)
|
|
}
|
|
defer file.Close()
|
|
|
|
tests := make(map[string]diffTest)
|
|
err = json.NewDecoder(file).Decode(&tests)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
config := ¶ms.ChainConfig{HomesteadBlock: big.NewInt(1150000)}
|
|
|
|
for name, test := range tests {
|
|
number := new(big.Int).Sub(test.CurrentBlocknumber, big.NewInt(1))
|
|
diff := CalcDifficulty(config, test.CurrentTimestamp,
|
|
test.ParentTimestamp,
|
|
test.ParentDifficulty,
|
|
number,
|
|
types.EmptyUncleHash,
|
|
)
|
|
if diff.Cmp(test.CurrentDifficulty) != 0 {
|
|
t.Error(name, "failed. Expected", test.CurrentDifficulty, "and calculated", diff)
|
|
}
|
|
}
|
|
}
|