From 4d4c229594b465fc248a6794bb59d15651b44503 Mon Sep 17 00:00:00 2001 From: Elizabeth Engelman Date: Thu, 13 Dec 2018 16:49:10 -0600 Subject: [PATCH] Reformatting due to go fmt --- statediff/builder/builder_test.go | 41 +++++++++++++-------------- statediff/builder/helpers.go | 2 +- statediff/config.go | 10 +++---- statediff/extractor/extractor.go | 4 +-- statediff/extractor/extractor_test.go | 11 +++---- statediff/publisher/csv.go | 13 ++++----- statediff/publisher/publisher.go | 2 +- statediff/publisher/publisher_test.go | 22 +++++++------- statediff/service/service.go | 12 ++++---- statediff/testhelpers/mocks.go | 12 ++++---- statediff/testhelpers/test_data.go | 10 +++---- 11 files changed, 69 insertions(+), 70 deletions(-) diff --git a/statediff/builder/builder_test.go b/statediff/builder/builder_test.go index 5fc4fca13..84477700a 100644 --- a/statediff/builder/builder_test.go +++ b/statediff/builder/builder_test.go @@ -20,27 +20,26 @@ package builder_test 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/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/onsi/gomega" + "github.com/ethereum/go-ethereum/ethdb" + "github.com/ethereum/go-ethereum/params" b "github.com/ethereum/go-ethereum/statediff/builder" + "github.com/onsi/ginkgo" + "github.com/onsi/gomega" + "math/big" ) - var ( testdb = ethdb.NewMemDatabase() testBankKey, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291") testBankAddress = crypto.PubkeyToAddress(testBankKey.PublicKey) //0x71562b71999873DB5b286dF957af199Ec94617F7 testBankFunds = big.NewInt(100000000) - genesis = core.GenesisBlockForTesting(testdb, testBankAddress, testBankFunds) + genesis = core.GenesisBlockForTesting(testdb, testBankAddress, testBankFunds) account1Key, _ = crypto.HexToECDSA("8a1f9a8f95be41cd7ccb6168179afb4504aefe388d1e14474d32c45c72ce7b7a") account2Key, _ = crypto.HexToECDSA("49a7b37aa6f6645917e7b807e9d1c00d4fa71f18343b0d4122a4d2df64dd6fee") @@ -50,9 +49,10 @@ var ( contractCode = common.Hex2Bytes("606060405260cc8060106000396000f360606040526000357c01000000000000000000000000000000000000000000000000000000009004806360cd2685146041578063c16431b914606b57603f565b005b6055600480803590602001909190505060a9565b6040518082815260200191505060405180910390f35b60886004808035906020019091908035906020019091905050608a565b005b80600060005083606481101560025790900160005b50819055505b5050565b6000600060005082606481101560025790900160005b5054905060c7565b91905056") contractAddr common.Address - emptyAccountDiffEventualMap = make(map[common.Address]b.AccountDiffEventual) + emptyAccountDiffEventualMap = make(map[common.Address]b.AccountDiffEventual) emptyAccountDiffIncrementalMap = make(map[common.Address]b.AccountDiffIncremental) ) + /* contract test { @@ -68,7 +68,6 @@ contract test { } */ - // 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 // 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 } - func testChainGen(i int, block *core.BlockGen) { signer := types.HomesteadSigner{} switch i { @@ -117,15 +115,16 @@ func testChainGen(i int, block *core.BlockGen) { block.AddTx(tx) } } + var _ = ginkgo.FDescribe("", func() { var ( block0Hash, block1Hash, block2Hash, block3Hash common.Hash - block0, block1, block2, block3 *types.Block - builder b.Builder - miningReward = int64(3000000000000000000) - burnAddress = common.HexToAddress("0x0") - diff *b.StateDiff - err error + block0, block1, block2, block3 *types.Block + builder b.Builder + miningReward = int64(3000000000000000000) + burnAddress = common.HexToAddress("0x0") + diff *b.StateDiff + err error ) ginkgo.BeforeEach(func() { @@ -207,8 +206,8 @@ var _ = ginkgo.FDescribe("", func() { //1000 transferred from testBankAddress to account1Addr //1000 transferred from account1Addr to account2Addr var ( - balanceChange = int64(1000) - block1BankBalance = int64(99990000) + balanceChange = int64(1000) + block1BankBalance = int64(99990000) block1Account1Balance = int64(10000) ) @@ -317,4 +316,4 @@ var _ = ginkgo.FDescribe("", func() { gomega.Expect(diff.UpdatedAccounts[testBankAddress].Nonce).To(gomega.Equal(expectedBankNonceDiff)) }) }) -}) \ No newline at end of file +}) diff --git a/statediff/builder/helpers.go b/statediff/builder/helpers.go index 31aae926b..e82fe7aa4 100644 --- a/statediff/builder/helpers.go +++ b/statediff/builder/helpers.go @@ -115,4 +115,4 @@ func decodeNibbles(nibbles []byte, bytes []byte) { // hasTerm returns whether a hex key has the terminator flag. func hasTerm(s []byte) bool { return len(s) > 0 && s[len(s)-1] == 16 -} \ No newline at end of file +} diff --git a/statediff/config.go b/statediff/config.go index fbc258be2..0fef737ba 100644 --- a/statediff/config.go +++ b/statediff/config.go @@ -22,15 +22,15 @@ package statediff import "fmt" type Config struct { - On bool // Whether or not to extract state diffs - Mode StateDiffMode // Mode for storing diffs - Path string // Path for storing diffs + On bool // Whether or not to extract state diffs + Mode StateDiffMode // Mode for storing diffs + Path string // Path for storing diffs } type StateDiffMode int const ( - CSV StateDiffMode = iota + CSV StateDiffMode = iota IPLD LDB 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 nil -} \ No newline at end of file +} diff --git a/statediff/extractor/extractor.go b/statediff/extractor/extractor.go index 8910e47a1..cac56a1c2 100644 --- a/statediff/extractor/extractor.go +++ b/statediff/extractor/extractor.go @@ -30,7 +30,7 @@ type Extractor interface { } 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) } @@ -48,4 +48,4 @@ func (e *extractor) ExtractStateDiff(parent, current types.Block) (string, error } return e.Publisher.PublishStateDiff(stateDiff) -} \ No newline at end of file +} diff --git a/statediff/extractor/extractor_test.go b/statediff/extractor/extractor_test.go index 3cd8b3230..9f0841903 100644 --- a/statediff/extractor/extractor_test.go +++ b/statediff/extractor/extractor_test.go @@ -20,15 +20,16 @@ package extractor_test 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/gomega" - "github.com/ethereum/go-ethereum/core/types" - "math/rand" - "github.com/ethereum/go-ethereum/statediff/testhelpers" "math/big" - e "github.com/ethereum/go-ethereum/statediff/extractor" - b "github.com/ethereum/go-ethereum/statediff/builder" + "math/rand" ) + var _ = ginkgo.Describe("Extractor", func() { var publisher testhelpers.MockPublisher var builder testhelpers.MockBuilder diff --git a/statediff/publisher/csv.go b/statediff/publisher/csv.go index fe8b337a2..3ae0a2b62 100644 --- a/statediff/publisher/csv.go +++ b/statediff/publisher/csv.go @@ -1,13 +1,13 @@ package publisher import ( - "github.com/ethereum/go-ethereum/statediff/builder" - "time" - "os" "encoding/csv" + "github.com/ethereum/go-ethereum/statediff/builder" + "os" + "path/filepath" "strconv" "strings" - "path/filepath" + "time" ) var ( @@ -20,7 +20,7 @@ var ( "storageDiffPaths", } - timeStampFormat = "20060102150405.00000" + timeStampFormat = "20060102150405.00000" deletedAccountAction = "deleted" createdAccountAction = "created" updatedAccountAction = "updated" @@ -59,7 +59,7 @@ func (p *publisher) publishStateDiffToCSV(sd builder.StateDiff) error { data = append(data, row) } - for _, value := range data{ + for _, value := range data { err := writer.Write(value) if err != nil { return err @@ -149,4 +149,3 @@ func formatAccountDiffIncremental(accountDiff builder.AccountDiffIncremental, sd } return formattedAccountData } - diff --git a/statediff/publisher/publisher.go b/statediff/publisher/publisher.go index 0e2776f1d..be2ed9eb3 100644 --- a/statediff/publisher/publisher.go +++ b/statediff/publisher/publisher.go @@ -20,8 +20,8 @@ package publisher import ( - "github.com/ethereum/go-ethereum/statediff/builder" "github.com/ethereum/go-ethereum/statediff" + "github.com/ethereum/go-ethereum/statediff/builder" ) type Publisher interface { diff --git a/statediff/publisher/publisher_test.go b/statediff/publisher/publisher_test.go index 7e33518a9..40f584b2c 100644 --- a/statediff/publisher/publisher_test.go +++ b/statediff/publisher/publisher_test.go @@ -1,26 +1,26 @@ package publisher_test import ( - "github.com/onsi/ginkgo" - "github.com/onsi/gomega" - "os" "encoding/csv" - "path/filepath" - "strconv" + "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/onsi/ginkgo" + "github.com/onsi/gomega" "io/ioutil" - "github.com/ethereum/go-ethereum/statediff/builder" - "github.com/ethereum/go-ethereum/statediff" + "os" + "path/filepath" + "strconv" ) var _ = ginkgo.Describe("Publisher", func() { var ( - tempDir = os.TempDir() + tempDir = os.TempDir() testFilePrefix = "test-statediff" - publisher p.Publisher - dir string - err error + publisher p.Publisher + dir string + err error ) var expectedCreatedAccountRow = []string{ diff --git a/statediff/service/service.go b/statediff/service/service.go index d2a46c121..c308c83b9 100644 --- a/statediff/service/service.go +++ b/statediff/service/service.go @@ -3,14 +3,14 @@ package service import ( "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/ethdb" + "github.com/ethereum/go-ethereum/event" "github.com/ethereum/go-ethereum/p2p" "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" + b "github.com/ethereum/go-ethereum/statediff/builder" + e "github.com/ethereum/go-ethereum/statediff/extractor" p "github.com/ethereum/go-ethereum/statediff/publisher" + "log" ) type StateDiffService struct { @@ -43,7 +43,7 @@ func (StateDiffService) APIs() []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() 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.Println("doing something with an event", ev) - previousBlock := ev.Block + previousBlock := ev.Block //TODO: figure out the best way to get the previous block currentBlock := ev.Block sds.extractor.ExtractStateDiff(*previousBlock, *currentBlock) diff --git a/statediff/testhelpers/mocks.go b/statediff/testhelpers/mocks.go index 8dec1d949..686550361 100644 --- a/statediff/testhelpers/mocks.go +++ b/statediff/testhelpers/mocks.go @@ -1,8 +1,8 @@ package testhelpers import ( - "github.com/ethereum/go-ethereum/common" "errors" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/statediff/builder" ) @@ -11,9 +11,9 @@ var MockError = errors.New("mock error") type MockBuilder struct { OldStateRoot common.Hash NewStateRoot common.Hash - BlockNumber int64 - BlockHash common.Hash - stateDiff *builder.StateDiff + BlockNumber int64 + BlockHash common.Hash + stateDiff *builder.StateDiff builderError error } @@ -34,8 +34,8 @@ func (builder *MockBuilder) SetBuilderError(err error) { builder.builderError = err } -type MockPublisher struct{ - StateDiff *builder.StateDiff +type MockPublisher struct { + StateDiff *builder.StateDiff publisherError error } diff --git a/statediff/testhelpers/test_data.go b/statediff/testhelpers/test_data.go index 7d44d4121..04440a8a4 100644 --- a/statediff/testhelpers/test_data.go +++ b/statediff/testhelpers/test_data.go @@ -1,9 +1,9 @@ package testhelpers import ( + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/statediff/builder" "math/big" - "github.com/ethereum/go-ethereum/common" "math/rand" ) @@ -23,7 +23,7 @@ var ( NewValue: &newStorage, OldValue: &oldStorage, }} - address = common.HexToAddress("0xaE9BEa628c4Ce503DcFD7E305CaB4e29E7476592") + address = common.HexToAddress("0xaE9BEa628c4Ce503DcFD7E305CaB4e29E7476592") CreatedAccountDiffs = map[common.Address]builder.AccountDiffEventual{address: { Nonce: builder.DiffUint64{ NewValue: &NewNonceValue, @@ -43,15 +43,15 @@ var ( }} UpdatedAccountDiffs = map[common.Address]builder.AccountDiffIncremental{address: { - Nonce: builder.DiffUint64{ + Nonce: builder.DiffUint64{ NewValue: &NewNonceValue, OldValue: &OldNonceValue, }, - Balance: builder.DiffBigInt{ + Balance: builder.DiffBigInt{ NewValue: big.NewInt(NewBalanceValue), OldValue: big.NewInt(OldBalanceValue), }, - CodeHash: CodeHash, + CodeHash: CodeHash, ContractRoot: builder.DiffString{ NewValue: &ContractRoot, OldValue: &ContractRoot,