Updates per go fmt
This commit is contained in:
parent
0a6dbb8a27
commit
2a8a914705
@ -21,12 +21,12 @@ package builder
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"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/core/state"
|
||||||
"github.com/ethereum/go-ethereum/ethdb"
|
"github.com/ethereum/go-ethereum/ethdb"
|
||||||
"github.com/ethereum/go-ethereum/log"
|
"github.com/ethereum/go-ethereum/log"
|
||||||
"github.com/ethereum/go-ethereum/rlp"
|
"github.com/ethereum/go-ethereum/rlp"
|
||||||
"github.com/ethereum/go-ethereum/trie"
|
"github.com/ethereum/go-ethereum/trie"
|
||||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Builder interface {
|
type Builder interface {
|
||||||
|
@ -1,18 +1,18 @@
|
|||||||
package builder_test
|
package builder_test
|
||||||
|
|
||||||
import (
|
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"
|
"bytes"
|
||||||
"reflect"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/params"
|
|
||||||
"github.com/ethereum/go-ethereum/consensus/ethash"
|
"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 (
|
var (
|
||||||
|
@ -72,6 +72,12 @@ type AccountDiffIncremental struct {
|
|||||||
Storage map[string]DiffString `json:"storage" gencodec:"required"`
|
Storage map[string]DiffString `json:"storage" gencodec:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type DiffString struct{ Value *string `json:"value" gencodec:"optional"` }
|
type DiffString struct {
|
||||||
type DiffUint64 struct{ Value *uint64 `json:"value" gencodec:"optional"` }
|
Value *string `json:"value" gencodec:"optional"`
|
||||||
type DiffBigInt struct{ Value *big.Int `json:"value" gencodec:"optional"` }
|
}
|
||||||
|
type DiffUint64 struct {
|
||||||
|
Value *uint64 `json:"value" gencodec:"optional"`
|
||||||
|
}
|
||||||
|
type DiffBigInt struct {
|
||||||
|
Value *big.Int `json:"value" gencodec:"optional"`
|
||||||
|
}
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
package extractor_test
|
package extractor_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"bytes"
|
||||||
"math/big"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"math/rand"
|
|
||||||
b "github.com/ethereum/go-ethereum/statediff/builder"
|
b "github.com/ethereum/go-ethereum/statediff/builder"
|
||||||
e "github.com/ethereum/go-ethereum/statediff/extractor"
|
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"
|
"github.com/ethereum/go-ethereum/statediff/testhelpers/mocks"
|
||||||
|
"math/big"
|
||||||
|
"math/rand"
|
||||||
|
"reflect"
|
||||||
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
var publisher mocks.Publisher
|
var publisher mocks.Publisher
|
||||||
@ -56,10 +56,18 @@ func testBuildStateDiffStruct(t *testing.T) {
|
|||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !equals(builder.OldStateRoot, parentBlock.Root()) { t.Error()}
|
if !equals(builder.OldStateRoot, parentBlock.Root()) {
|
||||||
if !equals(builder.NewStateRoot, currentBlock.Root()) { t.Error()}
|
t.Error()
|
||||||
if !equals(builder.BlockNumber,currentBlockNumber.Int64()) { t.Error()}
|
}
|
||||||
if !equals(builder.BlockHash, currentBlock.Hash()) { 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) {
|
func testBuildStateDiffErrorHandling(t *testing.T) {
|
||||||
@ -70,7 +78,9 @@ func testBuildStateDiffErrorHandling(t *testing.T) {
|
|||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !equals(err, mocks.Error) { t.Error() }
|
if !equals(err, mocks.Error) {
|
||||||
|
t.Error()
|
||||||
|
}
|
||||||
builder.SetBuilderError(nil)
|
builder.SetBuilderError(nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,7 +92,9 @@ func testPublishingStateDiff(t *testing.T) {
|
|||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !equals(publisher.StateDiff, &expectedStateDiff) { t.Error() }
|
if !equals(publisher.StateDiff, &expectedStateDiff) {
|
||||||
|
t.Error()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func testPublisherErrorHandling(t *testing.T) {
|
func testPublisherErrorHandling(t *testing.T) {
|
||||||
@ -92,7 +104,9 @@ func testPublisherErrorHandling(t *testing.T) {
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
t.Error("Expected an error, but it didn't occur.")
|
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)
|
publisher.SetPublisherError(nil)
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,6 @@ func (p *publisher) publishStateDiffToCSV(sd builder.StateDiff) error {
|
|||||||
for _, row := range accumulateUpdatedAccountRows(sd) {
|
for _, row := range accumulateUpdatedAccountRows(sd) {
|
||||||
data = append(data, row)
|
data = append(data, row)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, row := range accumulateDeletedAccountRows(sd) {
|
for _, row := range accumulateDeletedAccountRows(sd) {
|
||||||
data = append(data, row)
|
data = append(data, row)
|
||||||
}
|
}
|
||||||
|
@ -1,19 +1,19 @@
|
|||||||
package publisher_test
|
package publisher_test
|
||||||
|
|
||||||
import (
|
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"
|
"bytes"
|
||||||
"reflect"
|
"encoding/csv"
|
||||||
|
"github.com/ethereum/go-ethereum/statediff"
|
||||||
"github.com/ethereum/go-ethereum/statediff/builder"
|
"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"
|
"github.com/pkg/errors"
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"reflect"
|
||||||
|
"strconv"
|
||||||
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -119,9 +119,13 @@ func testColumnHeaders(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
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) {
|
func testAccountDiffs(t *testing.T) {
|
||||||
@ -140,10 +144,18 @@ func testAccountDiffs(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
if len(lines) <= 3 { t.Error() }
|
if len(lines) <= 3 {
|
||||||
if !equals(lines[1], expectedCreatedAccountRow) { t.Error() }
|
t.Error()
|
||||||
if !equals(lines[2], expectedUpdatedAccountRow) { t.Error()}
|
}
|
||||||
if !equals(lines[3], expectedDeletedAccountRow) { 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) {
|
func testWhenNoDiff(t *testing.T) {
|
||||||
@ -163,52 +175,84 @@ func testWhenNoDiff(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
if !equals(len(lines), 1) { t.Error() }
|
if !equals(len(lines), 1) {
|
||||||
|
t.Error()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func testDefaultPublisher(t *testing.T) {
|
func testDefaultPublisher(t *testing.T) {
|
||||||
//it defaults to publishing state diffs to a CSV file when no mode is configured
|
//it defaults to publishing state diffs to a CSV file when no mode is configured
|
||||||
config := statediff.Config{Path: dir}
|
config := statediff.Config{Path: dir}
|
||||||
publisher, err = p.NewPublisher(config)
|
publisher, err = p.NewPublisher(config)
|
||||||
if err != nil { t.Error(err) }
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
|
||||||
_, err = publisher.PublishStateDiff(&testhelpers.TestStateDiff)
|
_, err = publisher.PublishStateDiff(&testhelpers.TestStateDiff)
|
||||||
if err != nil { t.Error(err) }
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
|
||||||
file, err := getTestDiffFile(dir)
|
file, err := getTestDiffFile(dir)
|
||||||
if err != nil { t.Error(err) }
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
|
||||||
lines, err := csv.NewReader(file).ReadAll()
|
lines, err := csv.NewReader(file).ReadAll()
|
||||||
if err != nil { t.Error(err) }
|
if err != nil {
|
||||||
if !equals(len(lines), 4) { t.Error()}
|
t.Error(err)
|
||||||
if !equals(lines[0],p.Headers) { t.Error()}
|
}
|
||||||
|
if !equals(len(lines), 4) {
|
||||||
|
t.Error()
|
||||||
|
}
|
||||||
|
if !equals(lines[0], p.Headers) {
|
||||||
|
t.Error()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func testDefaultDirectory(t *testing.T) {
|
func testDefaultDirectory(t *testing.T) {
|
||||||
//it defaults to publishing CSV files in the current directory when no path is configured
|
//it defaults to publishing CSV files in the current directory when no path is configured
|
||||||
config := statediff.Config{}
|
config := statediff.Config{}
|
||||||
publisher, err = p.NewPublisher(config)
|
publisher, err = p.NewPublisher(config)
|
||||||
if err != nil { t.Error(err) }
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
|
||||||
err := os.Chdir(dir)
|
err := os.Chdir(dir)
|
||||||
if err != nil { t.Error(err) }
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
|
||||||
_, err = publisher.PublishStateDiff(&testhelpers.TestStateDiff)
|
_, err = publisher.PublishStateDiff(&testhelpers.TestStateDiff)
|
||||||
if err != nil { t.Error(err) }
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
|
||||||
file, err := getTestDiffFile(dir)
|
file, err := getTestDiffFile(dir)
|
||||||
if err != nil { t.Error(err) }
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
|
||||||
lines, err := csv.NewReader(file).ReadAll()
|
lines, err := csv.NewReader(file).ReadAll()
|
||||||
if err != nil { t.Error(err) }
|
if err != nil {
|
||||||
if !equals(len(lines), 4) { t.Error() }
|
t.Error(err)
|
||||||
if !equals(lines[0], p.Headers) { t.Error() }
|
}
|
||||||
|
if !equals(len(lines), 4) {
|
||||||
|
t.Error()
|
||||||
|
}
|
||||||
|
if !equals(lines[0], p.Headers) {
|
||||||
|
t.Error()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getTestDiffFile(dir string) (*os.File, error) {
|
func getTestDiffFile(dir string) (*os.File, error) {
|
||||||
files, err := ioutil.ReadDir(dir)
|
files, err := ioutil.ReadDir(dir)
|
||||||
if err != nil { return nil, err }
|
if err != nil {
|
||||||
if len(files) == 0 { return nil, errors.New("There are 0 files.") }
|
return nil, err
|
||||||
|
}
|
||||||
|
if len(files) == 0 {
|
||||||
|
return nil, errors.New("There are 0 files.")
|
||||||
|
}
|
||||||
|
|
||||||
fileName := files[0].Name()
|
fileName := files[0].Name()
|
||||||
filePath := filepath.Join(dir, fileName)
|
filePath := filepath.Join(dir, fileName)
|
||||||
|
@ -10,9 +10,9 @@ import (
|
|||||||
e "github.com/ethereum/go-ethereum/statediff/extractor"
|
e "github.com/ethereum/go-ethereum/statediff/extractor"
|
||||||
p "github.com/ethereum/go-ethereum/statediff/publisher"
|
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/common"
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
|
"github.com/ethereum/go-ethereum/event"
|
||||||
)
|
)
|
||||||
|
|
||||||
type BlockChain interface {
|
type BlockChain interface {
|
||||||
|
@ -1,16 +1,17 @@
|
|||||||
package service_test
|
package service_test
|
||||||
|
|
||||||
import (
|
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/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/big"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"github.com/ethereum/go-ethereum/statediff/testhelpers/mocks"
|
"reflect"
|
||||||
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestServiceLoop(t *testing.T) {
|
func TestServiceLoop(t *testing.T) {
|
||||||
testServiceLoop(t)
|
testServiceLoop(t)
|
||||||
}
|
}
|
||||||
|
@ -2,8 +2,8 @@ package mocks
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"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"
|
||||||
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
"github.com/ethereum/go-ethereum/event"
|
"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 {
|
func (BlockChain) SubscribeChainEvent(ch chan<- core.ChainEvent) event.Subscription {
|
||||||
panic("implement me")
|
panic("implement me")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package mocks
|
package mocks
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/ethereum/go-ethereum/statediff/builder"
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
|
"github.com/ethereum/go-ethereum/statediff/builder"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Builder struct {
|
type Builder struct {
|
||||||
@ -30,4 +30,3 @@ func (builder *Builder) SetStateDiffToBuild(stateDiff *builder.StateDiff) {
|
|||||||
func (builder *Builder) SetBuilderError(err error) {
|
func (builder *Builder) SetBuilderError(err error) {
|
||||||
builder.builderError = err
|
builder.builderError = err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,4 +18,3 @@ func (me *Extractor) ExtractStateDiff(parent, current types.Block) (string, erro
|
|||||||
func (me *Extractor) SetExtractError(err error) {
|
func (me *Extractor) SetExtractError(err error) {
|
||||||
me.extractError = err
|
me.extractError = err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user