Reformatting due to go fmt

This commit is contained in:
Elizabeth Engelman 2018-12-13 16:49:10 -06:00
parent 8578fc20a3
commit 4d4c229594
11 changed files with 69 additions and 70 deletions

View File

@ -20,27 +20,26 @@
package builder_test package builder_test
import ( import (
"github.com/onsi/ginkgo"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/consensus/ethash" "github.com/ethereum/go-ethereum/consensus/ethash"
"math/big" "github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto"
"github.com/onsi/gomega" "github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/params"
b "github.com/ethereum/go-ethereum/statediff/builder" b "github.com/ethereum/go-ethereum/statediff/builder"
"github.com/onsi/ginkgo"
"github.com/onsi/gomega"
"math/big"
) )
var ( var (
testdb = ethdb.NewMemDatabase() testdb = ethdb.NewMemDatabase()
testBankKey, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291") testBankKey, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
testBankAddress = crypto.PubkeyToAddress(testBankKey.PublicKey) //0x71562b71999873DB5b286dF957af199Ec94617F7 testBankAddress = crypto.PubkeyToAddress(testBankKey.PublicKey) //0x71562b71999873DB5b286dF957af199Ec94617F7
testBankFunds = big.NewInt(100000000) testBankFunds = big.NewInt(100000000)
genesis = core.GenesisBlockForTesting(testdb, testBankAddress, testBankFunds) genesis = core.GenesisBlockForTesting(testdb, testBankAddress, testBankFunds)
account1Key, _ = crypto.HexToECDSA("8a1f9a8f95be41cd7ccb6168179afb4504aefe388d1e14474d32c45c72ce7b7a") account1Key, _ = crypto.HexToECDSA("8a1f9a8f95be41cd7ccb6168179afb4504aefe388d1e14474d32c45c72ce7b7a")
account2Key, _ = crypto.HexToECDSA("49a7b37aa6f6645917e7b807e9d1c00d4fa71f18343b0d4122a4d2df64dd6fee") account2Key, _ = crypto.HexToECDSA("49a7b37aa6f6645917e7b807e9d1c00d4fa71f18343b0d4122a4d2df64dd6fee")
@ -50,9 +49,10 @@ var (
contractCode = common.Hex2Bytes("606060405260cc8060106000396000f360606040526000357c01000000000000000000000000000000000000000000000000000000009004806360cd2685146041578063c16431b914606b57603f565b005b6055600480803590602001909190505060a9565b6040518082815260200191505060405180910390f35b60886004808035906020019091908035906020019091905050608a565b005b80600060005083606481101560025790900160005b50819055505b5050565b6000600060005082606481101560025790900160005b5054905060c7565b91905056") contractCode = common.Hex2Bytes("606060405260cc8060106000396000f360606040526000357c01000000000000000000000000000000000000000000000000000000009004806360cd2685146041578063c16431b914606b57603f565b005b6055600480803590602001909190505060a9565b6040518082815260200191505060405180910390f35b60886004808035906020019091908035906020019091905050608a565b005b80600060005083606481101560025790900160005b50819055505b5050565b6000600060005082606481101560025790900160005b5054905060c7565b91905056")
contractAddr common.Address contractAddr common.Address
emptyAccountDiffEventualMap = make(map[common.Address]b.AccountDiffEventual) emptyAccountDiffEventualMap = make(map[common.Address]b.AccountDiffEventual)
emptyAccountDiffIncrementalMap = make(map[common.Address]b.AccountDiffIncremental) emptyAccountDiffIncrementalMap = make(map[common.Address]b.AccountDiffIncremental)
) )
/* /*
contract test { contract test {
@ -68,7 +68,6 @@ contract test {
} }
*/ */
// makeChain creates a chain of n blocks starting at and including parent. // makeChain creates a chain of n blocks starting at and including parent.
// the returned hash chain is ordered head->parent. In addition, every 3rd block // the returned hash chain is ordered head->parent. In addition, every 3rd block
// contains a transaction and every 5th an uncle to allow testing correct block // contains a transaction and every 5th an uncle to allow testing correct block
@ -86,7 +85,6 @@ func makeChain(n int, seed byte, parent *types.Block) ([]common.Hash, map[common
return hashes, blockm return hashes, blockm
} }
func testChainGen(i int, block *core.BlockGen) { func testChainGen(i int, block *core.BlockGen) {
signer := types.HomesteadSigner{} signer := types.HomesteadSigner{}
switch i { switch i {
@ -117,15 +115,16 @@ func testChainGen(i int, block *core.BlockGen) {
block.AddTx(tx) block.AddTx(tx)
} }
} }
var _ = ginkgo.FDescribe("", func() { var _ = ginkgo.FDescribe("", func() {
var ( var (
block0Hash, block1Hash, block2Hash, block3Hash common.Hash block0Hash, block1Hash, block2Hash, block3Hash common.Hash
block0, block1, block2, block3 *types.Block block0, block1, block2, block3 *types.Block
builder b.Builder builder b.Builder
miningReward = int64(3000000000000000000) miningReward = int64(3000000000000000000)
burnAddress = common.HexToAddress("0x0") burnAddress = common.HexToAddress("0x0")
diff *b.StateDiff diff *b.StateDiff
err error err error
) )
ginkgo.BeforeEach(func() { ginkgo.BeforeEach(func() {
@ -207,8 +206,8 @@ var _ = ginkgo.FDescribe("", func() {
//1000 transferred from testBankAddress to account1Addr //1000 transferred from testBankAddress to account1Addr
//1000 transferred from account1Addr to account2Addr //1000 transferred from account1Addr to account2Addr
var ( var (
balanceChange = int64(1000) balanceChange = int64(1000)
block1BankBalance = int64(99990000) block1BankBalance = int64(99990000)
block1Account1Balance = int64(10000) block1Account1Balance = int64(10000)
) )
@ -317,4 +316,4 @@ var _ = ginkgo.FDescribe("", func() {
gomega.Expect(diff.UpdatedAccounts[testBankAddress].Nonce).To(gomega.Equal(expectedBankNonceDiff)) gomega.Expect(diff.UpdatedAccounts[testBankAddress].Nonce).To(gomega.Equal(expectedBankNonceDiff))
}) })
}) })
}) })

View File

@ -115,4 +115,4 @@ func decodeNibbles(nibbles []byte, bytes []byte) {
// hasTerm returns whether a hex key has the terminator flag. // hasTerm returns whether a hex key has the terminator flag.
func hasTerm(s []byte) bool { func hasTerm(s []byte) bool {
return len(s) > 0 && s[len(s)-1] == 16 return len(s) > 0 && s[len(s)-1] == 16
} }

View File

@ -22,15 +22,15 @@ package statediff
import "fmt" import "fmt"
type Config struct { type Config struct {
On bool // Whether or not to extract state diffs On bool // Whether or not to extract state diffs
Mode StateDiffMode // Mode for storing diffs Mode StateDiffMode // Mode for storing diffs
Path string // Path for storing diffs Path string // Path for storing diffs
} }
type StateDiffMode int type StateDiffMode int
const ( const (
CSV StateDiffMode = iota CSV StateDiffMode = iota
IPLD IPLD
LDB LDB
SQL SQL
@ -85,4 +85,4 @@ func (mode *StateDiffMode) UnmarshalText(text []byte) error {
return fmt.Errorf(`unknown state diff storage mode %q, want "ipfs", "ldb" or "sql"`, text) return fmt.Errorf(`unknown state diff storage mode %q, want "ipfs", "ldb" or "sql"`, text)
} }
return nil return nil
} }

View File

@ -30,7 +30,7 @@ type Extractor interface {
} }
type extractor struct { type extractor struct {
Builder builder.Builder // Interface for building state diff objects from two blocks Builder builder.Builder // Interface for building state diff objects from two blocks
Publisher publisher.Publisher // Interface for publishing state diff objects to a datastore (e.g. IPFS) Publisher publisher.Publisher // Interface for publishing state diff objects to a datastore (e.g. IPFS)
} }
@ -48,4 +48,4 @@ func (e *extractor) ExtractStateDiff(parent, current types.Block) (string, error
} }
return e.Publisher.PublishStateDiff(stateDiff) return e.Publisher.PublishStateDiff(stateDiff)
} }

View File

@ -20,15 +20,16 @@
package extractor_test package extractor_test
import ( import (
"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/statediff/testhelpers"
"github.com/onsi/ginkgo" "github.com/onsi/ginkgo"
"github.com/onsi/gomega" "github.com/onsi/gomega"
"github.com/ethereum/go-ethereum/core/types"
"math/rand"
"github.com/ethereum/go-ethereum/statediff/testhelpers"
"math/big" "math/big"
e "github.com/ethereum/go-ethereum/statediff/extractor" "math/rand"
b "github.com/ethereum/go-ethereum/statediff/builder"
) )
var _ = ginkgo.Describe("Extractor", func() { var _ = ginkgo.Describe("Extractor", func() {
var publisher testhelpers.MockPublisher var publisher testhelpers.MockPublisher
var builder testhelpers.MockBuilder var builder testhelpers.MockBuilder

View File

@ -1,13 +1,13 @@
package publisher package publisher
import ( import (
"github.com/ethereum/go-ethereum/statediff/builder"
"time"
"os"
"encoding/csv" "encoding/csv"
"github.com/ethereum/go-ethereum/statediff/builder"
"os"
"path/filepath"
"strconv" "strconv"
"strings" "strings"
"path/filepath" "time"
) )
var ( var (
@ -20,7 +20,7 @@ var (
"storageDiffPaths", "storageDiffPaths",
} }
timeStampFormat = "20060102150405.00000" timeStampFormat = "20060102150405.00000"
deletedAccountAction = "deleted" deletedAccountAction = "deleted"
createdAccountAction = "created" createdAccountAction = "created"
updatedAccountAction = "updated" updatedAccountAction = "updated"
@ -59,7 +59,7 @@ func (p *publisher) publishStateDiffToCSV(sd builder.StateDiff) error {
data = append(data, row) data = append(data, row)
} }
for _, value := range data{ for _, value := range data {
err := writer.Write(value) err := writer.Write(value)
if err != nil { if err != nil {
return err return err
@ -149,4 +149,3 @@ func formatAccountDiffIncremental(accountDiff builder.AccountDiffIncremental, sd
} }
return formattedAccountData return formattedAccountData
} }

View File

@ -20,8 +20,8 @@
package publisher package publisher
import ( import (
"github.com/ethereum/go-ethereum/statediff/builder"
"github.com/ethereum/go-ethereum/statediff" "github.com/ethereum/go-ethereum/statediff"
"github.com/ethereum/go-ethereum/statediff/builder"
) )
type Publisher interface { type Publisher interface {

View File

@ -1,26 +1,26 @@
package publisher_test package publisher_test
import ( import (
"github.com/onsi/ginkgo"
"github.com/onsi/gomega"
"os"
"encoding/csv" "encoding/csv"
"path/filepath" "github.com/ethereum/go-ethereum/statediff"
"strconv" "github.com/ethereum/go-ethereum/statediff/builder"
p "github.com/ethereum/go-ethereum/statediff/publisher" p "github.com/ethereum/go-ethereum/statediff/publisher"
"github.com/ethereum/go-ethereum/statediff/testhelpers" "github.com/ethereum/go-ethereum/statediff/testhelpers"
"github.com/onsi/ginkgo"
"github.com/onsi/gomega"
"io/ioutil" "io/ioutil"
"github.com/ethereum/go-ethereum/statediff/builder" "os"
"github.com/ethereum/go-ethereum/statediff" "path/filepath"
"strconv"
) )
var _ = ginkgo.Describe("Publisher", func() { var _ = ginkgo.Describe("Publisher", func() {
var ( var (
tempDir = os.TempDir() tempDir = os.TempDir()
testFilePrefix = "test-statediff" testFilePrefix = "test-statediff"
publisher p.Publisher publisher p.Publisher
dir string dir string
err error err error
) )
var expectedCreatedAccountRow = []string{ var expectedCreatedAccountRow = []string{

View File

@ -3,14 +3,14 @@ package service
import ( import (
"github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/p2p" "github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/rpc" "github.com/ethereum/go-ethereum/rpc"
"github.com/ethereum/go-ethereum/event"
"log"
e "github.com/ethereum/go-ethereum/statediff/extractor"
b "github.com/ethereum/go-ethereum/statediff/builder"
"github.com/ethereum/go-ethereum/statediff" "github.com/ethereum/go-ethereum/statediff"
b "github.com/ethereum/go-ethereum/statediff/builder"
e "github.com/ethereum/go-ethereum/statediff/extractor"
p "github.com/ethereum/go-ethereum/statediff/publisher" p "github.com/ethereum/go-ethereum/statediff/publisher"
"log"
) )
type StateDiffService struct { type StateDiffService struct {
@ -43,7 +43,7 @@ func (StateDiffService) APIs() []rpc.API {
return []rpc.API{} return []rpc.API{}
} }
func (sds *StateDiffService) loop (sub event.Subscription, events chan core.ChainHeadEvent) { func (sds *StateDiffService) loop(sub event.Subscription, events chan core.ChainHeadEvent) {
defer sub.Unsubscribe() defer sub.Unsubscribe()
for { for {
@ -53,7 +53,7 @@ func (sds *StateDiffService) loop (sub event.Subscription, events chan core.Chai
log.Fatalf("Error getting chain head event from subscription.") log.Fatalf("Error getting chain head event from subscription.")
} }
log.Println("doing something with an event", ev) log.Println("doing something with an event", ev)
previousBlock := ev.Block previousBlock := ev.Block
//TODO: figure out the best way to get the previous block //TODO: figure out the best way to get the previous block
currentBlock := ev.Block currentBlock := ev.Block
sds.extractor.ExtractStateDiff(*previousBlock, *currentBlock) sds.extractor.ExtractStateDiff(*previousBlock, *currentBlock)

View File

@ -1,8 +1,8 @@
package testhelpers package testhelpers
import ( import (
"github.com/ethereum/go-ethereum/common"
"errors" "errors"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/statediff/builder" "github.com/ethereum/go-ethereum/statediff/builder"
) )
@ -11,9 +11,9 @@ var MockError = errors.New("mock error")
type MockBuilder struct { type MockBuilder struct {
OldStateRoot common.Hash OldStateRoot common.Hash
NewStateRoot common.Hash NewStateRoot common.Hash
BlockNumber int64 BlockNumber int64
BlockHash common.Hash BlockHash common.Hash
stateDiff *builder.StateDiff stateDiff *builder.StateDiff
builderError error builderError error
} }
@ -34,8 +34,8 @@ func (builder *MockBuilder) SetBuilderError(err error) {
builder.builderError = err builder.builderError = err
} }
type MockPublisher struct{ type MockPublisher struct {
StateDiff *builder.StateDiff StateDiff *builder.StateDiff
publisherError error publisherError error
} }

View File

@ -1,9 +1,9 @@
package testhelpers package testhelpers
import ( import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/statediff/builder" "github.com/ethereum/go-ethereum/statediff/builder"
"math/big" "math/big"
"github.com/ethereum/go-ethereum/common"
"math/rand" "math/rand"
) )
@ -23,7 +23,7 @@ var (
NewValue: &newStorage, NewValue: &newStorage,
OldValue: &oldStorage, OldValue: &oldStorage,
}} }}
address = common.HexToAddress("0xaE9BEa628c4Ce503DcFD7E305CaB4e29E7476592") address = common.HexToAddress("0xaE9BEa628c4Ce503DcFD7E305CaB4e29E7476592")
CreatedAccountDiffs = map[common.Address]builder.AccountDiffEventual{address: { CreatedAccountDiffs = map[common.Address]builder.AccountDiffEventual{address: {
Nonce: builder.DiffUint64{ Nonce: builder.DiffUint64{
NewValue: &NewNonceValue, NewValue: &NewNonceValue,
@ -43,15 +43,15 @@ var (
}} }}
UpdatedAccountDiffs = map[common.Address]builder.AccountDiffIncremental{address: { UpdatedAccountDiffs = map[common.Address]builder.AccountDiffIncremental{address: {
Nonce: builder.DiffUint64{ Nonce: builder.DiffUint64{
NewValue: &NewNonceValue, NewValue: &NewNonceValue,
OldValue: &OldNonceValue, OldValue: &OldNonceValue,
}, },
Balance: builder.DiffBigInt{ Balance: builder.DiffBigInt{
NewValue: big.NewInt(NewBalanceValue), NewValue: big.NewInt(NewBalanceValue),
OldValue: big.NewInt(OldBalanceValue), OldValue: big.NewInt(OldBalanceValue),
}, },
CodeHash: CodeHash, CodeHash: CodeHash,
ContractRoot: builder.DiffString{ ContractRoot: builder.DiffString{
NewValue: &ContractRoot, NewValue: &ContractRoot,
OldValue: &ContractRoot, OldValue: &ContractRoot,