mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-18 18:02:24 +00:00
eth/tracers: various small nits
This commit is contained in:
parent
f9a1c7bf54
commit
8296be8909
3 changed files with 61 additions and 79 deletions
|
|
@ -26,7 +26,6 @@ import (
|
|||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
"unicode"
|
||||
|
||||
"github.com/ethereum/go-ethereum/tests"
|
||||
)
|
||||
|
|
@ -62,7 +61,6 @@ func TestSupplyTracerBlockchain(t *testing.T) {
|
|||
if !strings.HasSuffix(file.Name(), ".json") {
|
||||
continue
|
||||
}
|
||||
file := file // capture range variable
|
||||
var testcases map[string]*blockTest
|
||||
var blob []byte
|
||||
// Tracer test found, read if from disk
|
||||
|
|
@ -72,8 +70,14 @@ func TestSupplyTracerBlockchain(t *testing.T) {
|
|||
if err := json.Unmarshal(blob, &testcases); err != nil {
|
||||
t.Fatalf("failed to parse testcase %s: %v", file.Name(), err)
|
||||
}
|
||||
for testname, test := range testcases {
|
||||
t.Run(fmt.Sprintf("%s/%s", camel(strings.TrimSuffix(file.Name(), ".json")), testname), func(t *testing.T) {
|
||||
for testname, blockTest := range testcases {
|
||||
t.Run(fmt.Sprintf("%s/%s", file.Name(), testname),
|
||||
func(t *testing.T) { runBlockTest(t, blockTest) })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func runBlockTest(t *testing.T, test *blockTest) {
|
||||
t.Parallel()
|
||||
|
||||
traceOutputPath := filepath.ToSlash(t.TempDir())
|
||||
|
|
@ -98,9 +102,8 @@ func TestSupplyTracerBlockchain(t *testing.T) {
|
|||
scanner = bufio.NewScanner(file)
|
||||
)
|
||||
for scanner.Scan() {
|
||||
blockBytes := scanner.Bytes()
|
||||
var info supplyInfo
|
||||
if err := json.Unmarshal(blockBytes, &info); err != nil {
|
||||
if err := json.Unmarshal(scanner.Bytes(), &info); err != nil {
|
||||
t.Fatalf("failed to unmarshal result: %v", err)
|
||||
}
|
||||
output = append(output, info)
|
||||
|
|
@ -112,18 +115,6 @@ func TestSupplyTracerBlockchain(t *testing.T) {
|
|||
for i, expected := range test.Expected {
|
||||
compareAsJSON(t, expected, output[i])
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// camel converts a snake cased input string into a camel cased output.
|
||||
func camel(str string) string {
|
||||
pieces := strings.Split(str, "_")
|
||||
for i := 1; i < len(pieces); i++ {
|
||||
pieces[i] = string(unicode.ToUpper(rune(pieces[i][0]))) + pieces[i][1:]
|
||||
}
|
||||
return strings.Join(pieces, "")
|
||||
}
|
||||
|
||||
func compareAsJSON(t *testing.T, expected interface{}, actual interface{}) {
|
||||
|
|
@ -136,6 +127,6 @@ func compareAsJSON(t *testing.T, expected interface{}, actual interface{}) {
|
|||
t.Fatalf("failed to marshal actual value to JSON: %v", err)
|
||||
}
|
||||
if !bytes.Equal(want, have) {
|
||||
t.Fatalf("incorrect supply info:\nexpected:\n%s\ngot:\n%s", string(want), string(have))
|
||||
t.Fatalf("incorrect supply info:\nhave: %s\nwant: %s", string(have), string(want))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,43 +44,43 @@ const (
|
|||
func (f Fork) String() string {
|
||||
switch f {
|
||||
case Prague:
|
||||
return "prague"
|
||||
return "Prague"
|
||||
case Cancun:
|
||||
return "cancun"
|
||||
return "Cancun"
|
||||
case Shanghai:
|
||||
return "shanghai"
|
||||
return "Shanghai"
|
||||
case Paris:
|
||||
return "paris"
|
||||
return "Paris"
|
||||
case GrayGlacier:
|
||||
return "grayGlacier"
|
||||
return "GrayGlacier"
|
||||
case ArrowGlacier:
|
||||
return "arrowGlacier"
|
||||
return "ArrowGlacier"
|
||||
case London:
|
||||
return "london"
|
||||
return "London"
|
||||
case Berlin:
|
||||
return "berlin"
|
||||
return "Berlin"
|
||||
case MuirGlacier:
|
||||
return "muirGlacier"
|
||||
return "MuirGlacier"
|
||||
case Istanbul:
|
||||
return "istanbul"
|
||||
return "Istanbul"
|
||||
case Petersburg:
|
||||
return "petersburg"
|
||||
return "Petersburg"
|
||||
case Constantinople:
|
||||
return "constantinople"
|
||||
return "Constantinople"
|
||||
case Byzantium:
|
||||
return "byzantium"
|
||||
return "Byzantium"
|
||||
case SpuriousDragon:
|
||||
return "spuriousDragon"
|
||||
return "SpuriousDragon"
|
||||
case TangerineWhistle:
|
||||
return "tangerineWhistle"
|
||||
return "TangerineWhistle"
|
||||
case DAO:
|
||||
return "dao"
|
||||
return "Dao"
|
||||
case Homestead:
|
||||
return "homestead"
|
||||
return "Homestead"
|
||||
case FrontierThawing:
|
||||
return "frontierThawing"
|
||||
return "FrontierThawing"
|
||||
case Frontier:
|
||||
return "frontier"
|
||||
return "Frontier"
|
||||
default:
|
||||
panic("unknown fork")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,6 @@ import (
|
|||
"math/big"
|
||||
"os"
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||
|
|
@ -89,7 +88,7 @@ func FromChain(db ethdb.Database, chain *core.BlockChain, post *types.GenesisAll
|
|||
post = &types.GenesisAlloc{}
|
||||
}
|
||||
bt.json = btJSON{
|
||||
Network: capitalize(chain.Config().LatestFork(head.Number, head.Time).String()),
|
||||
Network: chain.Config().LatestFork(head.Number, head.Time).String(),
|
||||
Blocks: blocks,
|
||||
Genesis: FromHeader(chain.Genesis().Header()),
|
||||
Pre: alloc,
|
||||
|
|
@ -466,11 +465,3 @@ func (bb *btBlock) decode() (*types.Block, error) {
|
|||
err = rlp.DecodeBytes(data, &b)
|
||||
return &b, err
|
||||
}
|
||||
|
||||
func capitalize(s string) string {
|
||||
// Check if the string is empty
|
||||
if len(s) == 0 {
|
||||
return s
|
||||
}
|
||||
return strings.ToUpper(string(s[0])) + s[1:]
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue