From dceddbfbaac409d0d78049b42f051c350bd4b2eb Mon Sep 17 00:00:00 2001 From: Elizabeth Engelman Date: Thu, 10 Jan 2019 15:08:06 -0600 Subject: [PATCH] Add contract address and storage value to csv --- statediff/publisher/csv.go | 30 ++++++++++++++++++--------- statediff/publisher/publisher_test.go | 6 ++++++ statediff/testhelpers/test_data.go | 5 +++-- 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/statediff/publisher/csv.go b/statediff/publisher/csv.go index 6ee62f7e8..341eec17f 100644 --- a/statediff/publisher/csv.go +++ b/statediff/publisher/csv.go @@ -8,12 +8,14 @@ import ( "strconv" "strings" "time" + "github.com/ethereum/go-ethereum/common" ) var ( Headers = []string{ "blockNumber", "blockHash", "accountAction", "codeHash", "nonceValue", "balanceValue", "contractRoot", "storageDiffPaths", + "accountAddress", "storageValue", } timeStampFormat = "20060102150405.00000" @@ -67,8 +69,8 @@ func (p *publisher) publishStateDiffToCSV(sd builder.StateDiff) (string, error) func accumulateUpdatedAccountRows(sd builder.StateDiff) [][]string { var updatedAccountRows [][]string - for _, accountDiff := range sd.UpdatedAccounts { - formattedAccountData := formatAccountDiffIncremental(accountDiff, sd, updatedAccountAction) + for accountAddr, accountDiff := range sd.UpdatedAccounts { + formattedAccountData := formatAccountDiffIncremental(accountAddr, accountDiff, sd, updatedAccountAction) updatedAccountRows = append(updatedAccountRows, formattedAccountData) } @@ -78,8 +80,8 @@ func accumulateUpdatedAccountRows(sd builder.StateDiff) [][]string { func accumulateDeletedAccountRows(sd builder.StateDiff) [][]string { var deletedAccountRows [][]string - for _, accountDiff := range sd.DeletedAccounts { - formattedAccountData := formatAccountDiffEventual(accountDiff, sd, deletedAccountAction) + for accountAddr, accountDiff := range sd.DeletedAccounts { + formattedAccountData := formatAccountDiffEventual(accountAddr, accountDiff, sd, deletedAccountAction) deletedAccountRows = append(deletedAccountRows, formattedAccountData) } @@ -89,8 +91,8 @@ func accumulateDeletedAccountRows(sd builder.StateDiff) [][]string { func accumulateCreatedAccountRows(sd builder.StateDiff) [][]string { var createdAccountRows [][]string - for _, accountDiff := range sd.CreatedAccounts { - formattedAccountData := formatAccountDiffEventual(accountDiff, sd, createdAccountAction) + for accountAddr, accountDiff := range sd.CreatedAccounts { + formattedAccountData := formatAccountDiffEventual(accountAddr, accountDiff, sd, createdAccountAction) createdAccountRows = append(createdAccountRows, formattedAccountData) } @@ -98,10 +100,12 @@ func accumulateCreatedAccountRows(sd builder.StateDiff) [][]string { return createdAccountRows } -func formatAccountDiffEventual(accountDiff builder.AccountDiff, sd builder.StateDiff, accountAction string) []string { +func formatAccountDiffEventual(accountAddr common.Address, accountDiff builder.AccountDiff, sd builder.StateDiff, accountAction string) []string { newContractRoot := accountDiff.ContractRoot.Value var storageDiffPaths []string - for k := range accountDiff.Storage { + var storageValue builder.DiffString + for k, v := range accountDiff.Storage { + storageValue = v storageDiffPaths = append(storageDiffPaths, k) } formattedAccountData := []string{ @@ -113,15 +117,19 @@ func formatAccountDiffEventual(accountDiff builder.AccountDiff, sd builder.State accountDiff.Balance.Value.String(), *newContractRoot, strings.Join(storageDiffPaths, ","), + accountAddr.String(), + *storageValue.Value, } return formattedAccountData } -func formatAccountDiffIncremental(accountDiff builder.AccountDiff, sd builder.StateDiff, accountAction string) []string { +func formatAccountDiffIncremental(accountAddr common.Address, accountDiff builder.AccountDiff, sd builder.StateDiff, accountAction string) []string { newContractRoot := accountDiff.ContractRoot.Value var storageDiffPaths []string - for k := range accountDiff.Storage { + var storageValue builder.DiffString + for k, v := range accountDiff.Storage { storageDiffPaths = append(storageDiffPaths, k) + storageValue = v } formattedAccountData := []string{ strconv.FormatInt(sd.BlockNumber, 10), @@ -132,6 +140,8 @@ func formatAccountDiffIncremental(accountDiff builder.AccountDiff, sd builder.St accountDiff.Balance.Value.String(), *newContractRoot, strings.Join(storageDiffPaths, ","), + accountAddr.String(), + *storageValue.Value, } return formattedAccountData } diff --git a/statediff/publisher/publisher_test.go b/statediff/publisher/publisher_test.go index 714accf06..215505db3 100644 --- a/statediff/publisher/publisher_test.go +++ b/statediff/publisher/publisher_test.go @@ -34,6 +34,8 @@ var expectedCreatedAccountRow = []string{ strconv.FormatInt(testhelpers.NewBalanceValue, 10), testhelpers.ContractRoot, testhelpers.StoragePath, + testhelpers.ContractAddress, + testhelpers.StorageValue, } var expectedUpdatedAccountRow = []string{ @@ -45,6 +47,8 @@ var expectedUpdatedAccountRow = []string{ strconv.FormatInt(testhelpers.NewBalanceValue, 10), testhelpers.ContractRoot, testhelpers.StoragePath, + testhelpers.ContractAddress, + testhelpers.StorageValue, } var expectedDeletedAccountRow = []string{ @@ -56,6 +60,8 @@ var expectedDeletedAccountRow = []string{ strconv.FormatInt(testhelpers.NewBalanceValue, 10), testhelpers.ContractRoot, testhelpers.StoragePath, + testhelpers.ContractAddress, + testhelpers.StorageValue, } func TestPublisher(t *testing.T) { diff --git a/statediff/testhelpers/test_data.go b/statediff/testhelpers/test_data.go index 27d6f7c29..cdbbb54c3 100644 --- a/statediff/testhelpers/test_data.go +++ b/statediff/testhelpers/test_data.go @@ -15,9 +15,10 @@ var ( NewBalanceValue = rand.Int63() ContractRoot = "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421" StoragePath = "0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470" - newStorage = "0x03" - storage = map[string]builder.DiffString{StoragePath: {Value: &newStorage}} + StorageValue = "0x03" + storage = map[string]builder.DiffString{StoragePath: {Value: &StorageValue}} address = common.HexToAddress("0xaE9BEa628c4Ce503DcFD7E305CaB4e29E7476592") + ContractAddress = address.String() CreatedAccountDiffs = map[common.Address]builder.AccountDiff{address: { Nonce: builder.DiffUint64{Value: &NewNonceValue}, Balance: builder.DiffBigInt{Value: big.NewInt(NewBalanceValue)},