Updates per go fmt

This commit is contained in:
Elizabeth Engelman 2018-12-21 11:51:42 -06:00
parent 0a6dbb8a27
commit 2a8a914705
12 changed files with 236 additions and 175 deletions

View File

@ -21,12 +21,12 @@ package builder
import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/trie"
"github.com/ethereum/go-ethereum/common/hexutil"
)
type Builder interface {

View File

@ -1,18 +1,18 @@
package builder_test
import (
"testing"
"math/big"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/common"
b "github.com/ethereum/go-ethereum/statediff/builder"
"github.com/ethereum/go-ethereum/core/types"
"bytes"
"reflect"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/consensus/ethash"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/params"
b "github.com/ethereum/go-ethereum/statediff/builder"
"math/big"
"reflect"
"testing"
)
var (

View File

@ -72,6 +72,12 @@ type AccountDiffIncremental struct {
Storage map[string]DiffString `json:"storage" gencodec:"required"`
}
type DiffString struct{ Value *string `json:"value" gencodec:"optional"` }
type DiffUint64 struct{ Value *uint64 `json:"value" gencodec:"optional"` }
type DiffBigInt struct{ Value *big.Int `json:"value" gencodec:"optional"` }
type DiffString struct {
Value *string `json:"value" gencodec:"optional"`
}
type DiffUint64 struct {
Value *uint64 `json:"value" gencodec:"optional"`
}
type DiffBigInt struct {
Value *big.Int `json:"value" gencodec:"optional"`
}

View File

@ -1,15 +1,15 @@
package extractor_test
import (
"testing"
"math/big"
"math/rand"
"bytes"
"github.com/ethereum/go-ethereum/core/types"
b "github.com/ethereum/go-ethereum/statediff/builder"
e "github.com/ethereum/go-ethereum/statediff/extractor"
"github.com/ethereum/go-ethereum/core/types"
"bytes"
"reflect"
"github.com/ethereum/go-ethereum/statediff/testhelpers/mocks"
"math/big"
"math/rand"
"reflect"
"testing"
)
var publisher mocks.Publisher
@ -56,10 +56,18 @@ func testBuildStateDiffStruct(t *testing.T) {
t.Error(err)
}
if !equals(builder.OldStateRoot, parentBlock.Root()) { t.Error()}
if !equals(builder.NewStateRoot, currentBlock.Root()) { t.Error()}
if !equals(builder.BlockNumber,currentBlockNumber.Int64()) { t.Error()}
if !equals(builder.BlockHash, currentBlock.Hash()) { t.Error()}
if !equals(builder.OldStateRoot, parentBlock.Root()) {
t.Error()
}
if !equals(builder.NewStateRoot, currentBlock.Root()) {
t.Error()
}
if !equals(builder.BlockNumber, currentBlockNumber.Int64()) {
t.Error()
}
if !equals(builder.BlockHash, currentBlock.Hash()) {
t.Error()
}
}
func testBuildStateDiffErrorHandling(t *testing.T) {
@ -70,7 +78,9 @@ func testBuildStateDiffErrorHandling(t *testing.T) {
t.Error(err)
}
if !equals(err, mocks.Error) { t.Error() }
if !equals(err, mocks.Error) {
t.Error()
}
builder.SetBuilderError(nil)
}
@ -82,7 +92,9 @@ func testPublishingStateDiff(t *testing.T) {
t.Error(err)
}
if !equals(publisher.StateDiff, &expectedStateDiff) { t.Error() }
if !equals(publisher.StateDiff, &expectedStateDiff) {
t.Error()
}
}
func testPublisherErrorHandling(t *testing.T) {
@ -92,7 +104,9 @@ func testPublisherErrorHandling(t *testing.T) {
if err == nil {
t.Error("Expected an error, but it didn't occur.")
}
if !equals(err, mocks.Error) { t.Error() }
if !equals(err, mocks.Error) {
t.Error()
}
publisher.SetPublisherError(nil)
}

View File

@ -51,7 +51,6 @@ func (p *publisher) publishStateDiffToCSV(sd builder.StateDiff) error {
for _, row := range accumulateUpdatedAccountRows(sd) {
data = append(data, row)
}
for _, row := range accumulateDeletedAccountRows(sd) {
data = append(data, row)
}

View File

@ -1,19 +1,19 @@
package publisher_test
import (
"testing"
"os"
"strconv"
"github.com/ethereum/go-ethereum/statediff/testhelpers"
p "github.com/ethereum/go-ethereum/statediff/publisher"
"io/ioutil"
"github.com/ethereum/go-ethereum/statediff"
"encoding/csv"
"path/filepath"
"bytes"
"reflect"
"encoding/csv"
"github.com/ethereum/go-ethereum/statediff"
"github.com/ethereum/go-ethereum/statediff/builder"
p "github.com/ethereum/go-ethereum/statediff/publisher"
"github.com/ethereum/go-ethereum/statediff/testhelpers"
"github.com/pkg/errors"
"io/ioutil"
"os"
"path/filepath"
"reflect"
"strconv"
"testing"
)
var (
@ -119,9 +119,13 @@ func testColumnHeaders(t *testing.T) {
if err != nil {
t.Error(err)
}
if len(lines) <= 1 { t.Error() }
if len(lines) <= 1 {
t.Error()
}
if !equals(lines[0], p.Headers) { t.Error() }
if !equals(lines[0], p.Headers) {
t.Error()
}
}
func testAccountDiffs(t *testing.T) {
@ -140,10 +144,18 @@ func testAccountDiffs(t *testing.T) {
if err != nil {
t.Error(err)
}
if len(lines) <= 3 { t.Error() }
if !equals(lines[1], expectedCreatedAccountRow) { t.Error() }
if !equals(lines[2], expectedUpdatedAccountRow) { t.Error()}
if !equals(lines[3], expectedDeletedAccountRow) { t.Error()}
if len(lines) <= 3 {
t.Error()
}
if !equals(lines[1], expectedCreatedAccountRow) {
t.Error()
}
if !equals(lines[2], expectedUpdatedAccountRow) {
t.Error()
}
if !equals(lines[3], expectedDeletedAccountRow) {
t.Error()
}
}
func testWhenNoDiff(t *testing.T) {
@ -163,52 +175,84 @@ func testWhenNoDiff(t *testing.T) {
if err != nil {
t.Error(err)
}
if !equals(len(lines), 1) { t.Error() }
if !equals(len(lines), 1) {
t.Error()
}
}
func testDefaultPublisher(t *testing.T) {
//it defaults to publishing state diffs to a CSV file when no mode is configured
config := statediff.Config{Path: dir}
publisher, err = p.NewPublisher(config)
if err != nil { t.Error(err) }
if err != nil {
t.Error(err)
}
_, err = publisher.PublishStateDiff(&testhelpers.TestStateDiff)
if err != nil { t.Error(err) }
if err != nil {
t.Error(err)
}
file, err := getTestDiffFile(dir)
if err != nil { t.Error(err) }
if err != nil {
t.Error(err)
}
lines, err := csv.NewReader(file).ReadAll()
if err != nil { t.Error(err) }
if !equals(len(lines), 4) { t.Error()}
if !equals(lines[0],p.Headers) { t.Error()}
if err != nil {
t.Error(err)
}
if !equals(len(lines), 4) {
t.Error()
}
if !equals(lines[0], p.Headers) {
t.Error()
}
}
func testDefaultDirectory(t *testing.T) {
//it defaults to publishing CSV files in the current directory when no path is configured
config := statediff.Config{}
publisher, err = p.NewPublisher(config)
if err != nil { t.Error(err) }
if err != nil {
t.Error(err)
}
err := os.Chdir(dir)
if err != nil { t.Error(err) }
if err != nil {
t.Error(err)
}
_, err = publisher.PublishStateDiff(&testhelpers.TestStateDiff)
if err != nil { t.Error(err) }
if err != nil {
t.Error(err)
}
file, err := getTestDiffFile(dir)
if err != nil { t.Error(err) }
if err != nil {
t.Error(err)
}
lines, err := csv.NewReader(file).ReadAll()
if err != nil { t.Error(err) }
if !equals(len(lines), 4) { t.Error() }
if !equals(lines[0], p.Headers) { t.Error() }
if err != nil {
t.Error(err)
}
if !equals(len(lines), 4) {
t.Error()
}
if !equals(lines[0], p.Headers) {
t.Error()
}
}
func getTestDiffFile(dir string) (*os.File, error) {
files, err := ioutil.ReadDir(dir)
if err != nil { return nil, err }
if len(files) == 0 { return nil, errors.New("There are 0 files.") }
if err != nil {
return nil, err
}
if len(files) == 0 {
return nil, errors.New("There are 0 files.")
}
fileName := files[0].Name()
filePath := filepath.Join(dir, fileName)

View File

@ -10,9 +10,9 @@ import (
e "github.com/ethereum/go-ethereum/statediff/extractor"
p "github.com/ethereum/go-ethereum/statediff/publisher"
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/event"
)
type BlockChain interface {

View File

@ -1,16 +1,17 @@
package service_test
import (
"testing"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core"
service2 "github.com/ethereum/go-ethereum/statediff/service"
"reflect"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/types"
service2 "github.com/ethereum/go-ethereum/statediff/service"
"github.com/ethereum/go-ethereum/statediff/testhelpers/mocks"
"math/big"
"math/rand"
"github.com/ethereum/go-ethereum/statediff/testhelpers/mocks"
"reflect"
"testing"
)
func TestServiceLoop(t *testing.T) {
testServiceLoop(t)
}

View File

@ -2,8 +2,8 @@ package mocks
import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/event"
)
@ -32,4 +32,3 @@ func (mc *BlockChain) GetBlockByHash(hash common.Hash) *types.Block {
func (BlockChain) SubscribeChainEvent(ch chan<- core.ChainEvent) event.Subscription {
panic("implement me")
}

View File

@ -1,8 +1,8 @@
package mocks
import (
"github.com/ethereum/go-ethereum/statediff/builder"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/statediff/builder"
)
type Builder struct {
@ -30,4 +30,3 @@ func (builder *Builder) SetStateDiffToBuild(stateDiff *builder.StateDiff) {
func (builder *Builder) SetBuilderError(err error) {
builder.builderError = err
}

View File

@ -18,4 +18,3 @@ func (me *Extractor) ExtractStateDiff(parent, current types.Block) (string, erro
func (me *Extractor) SetExtractError(err error) {
me.extractError = err
}