Fix publisher to include rows for accounts that don't have store updates
This commit is contained in:
parent
a3a6f97afb
commit
d0ea3a92eb
@ -46,16 +46,9 @@ func (p *publisher) publishStateDiffToCSV(sd builder.StateDiff) (string, error)
|
|||||||
|
|
||||||
var data [][]string
|
var data [][]string
|
||||||
data = append(data, Headers)
|
data = append(data, Headers)
|
||||||
for _, row := range accumulateAccountRows(sd, createdAccountAction) {
|
for _, row := range accumulateAccountRows(sd) {
|
||||||
data = append(data, row)
|
data = append(data, row)
|
||||||
}
|
}
|
||||||
for _, row := range accumulateAccountRows(sd, updatedAccountAction) {
|
|
||||||
data = append(data, row)
|
|
||||||
}
|
|
||||||
for _, row := range accumulateAccountRows(sd, deletedAccountAction) {
|
|
||||||
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 {
|
||||||
@ -66,10 +59,26 @@ func (p *publisher) publishStateDiffToCSV(sd builder.StateDiff) (string, error)
|
|||||||
return filePath, nil
|
return filePath, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func accumulateAccountRows(sd builder.StateDiff, accountAction string) [][]string {
|
func accumulateAccountRows(sd builder.StateDiff) [][]string {
|
||||||
var accountRows [][]string
|
var accountRows [][]string
|
||||||
|
for accountAddr, accountDiff := range sd.CreatedAccounts {
|
||||||
|
formattedAccountData := formatAccountData(accountAddr, accountDiff, sd, createdAccountAction)
|
||||||
|
|
||||||
|
for _, accountData := range formattedAccountData {
|
||||||
|
accountRows = append(accountRows, accountData)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for accountAddr, accountDiff := range sd.UpdatedAccounts {
|
for accountAddr, accountDiff := range sd.UpdatedAccounts {
|
||||||
formattedAccountData := formatAccountData(accountAddr, accountDiff, sd, accountAction)
|
formattedAccountData := formatAccountData(accountAddr, accountDiff, sd, updatedAccountAction)
|
||||||
|
|
||||||
|
for _, accountData := range formattedAccountData {
|
||||||
|
accountRows = append(accountRows, accountData)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for accountAddr, accountDiff := range sd.DeletedAccounts {
|
||||||
|
formattedAccountData := formatAccountData(accountAddr, accountDiff, sd, deletedAccountAction)
|
||||||
|
|
||||||
for _, accountData := range formattedAccountData {
|
for _, accountData := range formattedAccountData {
|
||||||
accountRows = append(accountRows, accountData)
|
accountRows = append(accountRows, accountData)
|
||||||
@ -89,7 +98,25 @@ func formatAccountData(accountAddr common.Address, accountDiff builder.AccountDi
|
|||||||
address := accountAddr.String()
|
address := accountAddr.String()
|
||||||
var result [][]string
|
var result [][]string
|
||||||
|
|
||||||
for storagePath, storage := range accountDiff.Storage {
|
if len(accountDiff.Storage) > 0 {
|
||||||
|
for storagePath, storage := range accountDiff.Storage {
|
||||||
|
formattedAccountData := []string{
|
||||||
|
blockNumberString,
|
||||||
|
blockHash,
|
||||||
|
accountAction,
|
||||||
|
codeHash,
|
||||||
|
nonce,
|
||||||
|
balance,
|
||||||
|
*newContractRoot,
|
||||||
|
storagePath,
|
||||||
|
address,
|
||||||
|
*storage.Key,
|
||||||
|
*storage.Value,
|
||||||
|
}
|
||||||
|
|
||||||
|
result = append(result, formattedAccountData)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
formattedAccountData := []string{
|
formattedAccountData := []string{
|
||||||
blockNumberString,
|
blockNumberString,
|
||||||
blockHash,
|
blockHash,
|
||||||
@ -98,15 +125,13 @@ func formatAccountData(accountAddr common.Address, accountDiff builder.AccountDi
|
|||||||
nonce,
|
nonce,
|
||||||
balance,
|
balance,
|
||||||
*newContractRoot,
|
*newContractRoot,
|
||||||
storagePath,
|
"",
|
||||||
address,
|
address,
|
||||||
*storage.Key,
|
"",
|
||||||
*storage.Value,
|
"",
|
||||||
}
|
}
|
||||||
|
|
||||||
result = append(result, formattedAccountData)
|
result = append(result, formattedAccountData)
|
||||||
}
|
}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,6 +39,20 @@ var expectedCreatedAccountRow = []string{
|
|||||||
testhelpers.StorageValue,
|
testhelpers.StorageValue,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var expectedCreatedAccountWithoutStorageUpdateRow = []string{
|
||||||
|
strconv.FormatInt(testhelpers.BlockNumber, 10),
|
||||||
|
testhelpers.BlockHash,
|
||||||
|
"created",
|
||||||
|
testhelpers.CodeHash,
|
||||||
|
strconv.FormatUint(testhelpers.NewNonceValue, 10),
|
||||||
|
strconv.FormatInt(testhelpers.NewBalanceValue, 10),
|
||||||
|
testhelpers.ContractRoot,
|
||||||
|
"",
|
||||||
|
testhelpers.AnotherContractAddress,
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
}
|
||||||
|
|
||||||
var expectedUpdatedAccountRow = []string{
|
var expectedUpdatedAccountRow = []string{
|
||||||
strconv.FormatInt(testhelpers.BlockNumber, 10),
|
strconv.FormatInt(testhelpers.BlockNumber, 10),
|
||||||
testhelpers.BlockHash,
|
testhelpers.BlockHash,
|
||||||
@ -176,10 +190,13 @@ func testAccountDiffs(t *testing.T) {
|
|||||||
if !equals(lines[1], expectedCreatedAccountRow) {
|
if !equals(lines[1], expectedCreatedAccountRow) {
|
||||||
t.Errorf(testhelpers.ErrorFormatString, t.Name(), err)
|
t.Errorf(testhelpers.ErrorFormatString, t.Name(), err)
|
||||||
}
|
}
|
||||||
if !equals(lines[2], expectedUpdatedAccountRow) {
|
if !equals(lines[2], expectedCreatedAccountWithoutStorageUpdateRow) {
|
||||||
t.Errorf(testhelpers.ErrorFormatString, t.Name(), err)
|
t.Errorf(testhelpers.ErrorFormatString, t.Name(), err)
|
||||||
}
|
}
|
||||||
if !equals(lines[3], expectedDeletedAccountRow) {
|
if !equals(lines[3], expectedUpdatedAccountRow) {
|
||||||
|
t.Errorf(testhelpers.ErrorFormatString, t.Name(), err)
|
||||||
|
}
|
||||||
|
if !equals(lines[4], expectedDeletedAccountRow) {
|
||||||
t.Errorf(testhelpers.ErrorFormatString, t.Name(), err)
|
t.Errorf(testhelpers.ErrorFormatString, t.Name(), err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -229,7 +246,7 @@ func testDefaultPublisher(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf(testhelpers.ErrorFormatString, t.Name(), err)
|
t.Errorf(testhelpers.ErrorFormatString, t.Name(), err)
|
||||||
}
|
}
|
||||||
if !equals(len(lines), 4) {
|
if !equals(len(lines), 5) {
|
||||||
t.Errorf(testhelpers.ErrorFormatString, t.Name(), err)
|
t.Errorf(testhelpers.ErrorFormatString, t.Name(), err)
|
||||||
}
|
}
|
||||||
if !equals(lines[0], p.Headers) {
|
if !equals(lines[0], p.Headers) {
|
||||||
@ -264,7 +281,7 @@ func testDefaultDirectory(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf(testhelpers.ErrorFormatString, t.Name(), err)
|
t.Errorf(testhelpers.ErrorFormatString, t.Name(), err)
|
||||||
}
|
}
|
||||||
if !equals(len(lines), 4) {
|
if !equals(len(lines), 5) {
|
||||||
t.Errorf(testhelpers.ErrorFormatString, t.Name(), err)
|
t.Errorf(testhelpers.ErrorFormatString, t.Name(), err)
|
||||||
}
|
}
|
||||||
if !equals(lines[0], p.Headers) {
|
if !equals(lines[0], p.Headers) {
|
||||||
|
@ -8,28 +8,40 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
BlockNumber = rand.Int63()
|
BlockNumber = rand.Int63()
|
||||||
BlockHash = "0xfa40fbe2d98d98b3363a778d52f2bcd29d6790b9b3f3cab2b167fd12d3550f73"
|
BlockHash = "0xfa40fbe2d98d98b3363a778d52f2bcd29d6790b9b3f3cab2b167fd12d3550f73"
|
||||||
CodeHash = "0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"
|
CodeHash = "0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"
|
||||||
NewNonceValue = rand.Uint64()
|
NewNonceValue = rand.Uint64()
|
||||||
NewBalanceValue = rand.Int63()
|
NewBalanceValue = rand.Int63()
|
||||||
ContractRoot = "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"
|
ContractRoot = "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"
|
||||||
StoragePath = "0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"
|
StoragePath = "0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"
|
||||||
StorageKey = "0000000000000000000000000000000000000000000000000000000000000001"
|
StorageKey = "0000000000000000000000000000000000000000000000000000000000000001"
|
||||||
StorageValue = "0x03"
|
StorageValue = "0x03"
|
||||||
storage = map[string]builder.DiffStorage{StoragePath: {
|
storage = map[string]builder.DiffStorage{StoragePath: {
|
||||||
Key: &StorageKey,
|
Key: &StorageKey,
|
||||||
Value: &StorageValue,
|
Value: &StorageValue,
|
||||||
}}
|
}}
|
||||||
address = common.HexToAddress("0xaE9BEa628c4Ce503DcFD7E305CaB4e29E7476592")
|
emptyStorage = map[string]builder.DiffStorage{}
|
||||||
ContractAddress = address.String()
|
address = common.HexToAddress("0xaE9BEa628c4Ce503DcFD7E305CaB4e29E7476592")
|
||||||
CreatedAccountDiffs = map[common.Address]builder.AccountDiff{address: {
|
anotherAddress = common.HexToAddress("0xaE9BEa628c4Ce503DcFD7E305CaB4e29E7476593")
|
||||||
Nonce: builder.DiffUint64{Value: &NewNonceValue},
|
ContractAddress = address.String()
|
||||||
Balance: builder.DiffBigInt{Value: big.NewInt(NewBalanceValue)},
|
AnotherContractAddress = anotherAddress.String()
|
||||||
ContractRoot: builder.DiffString{Value: &ContractRoot},
|
CreatedAccountDiffs = map[common.Address]builder.AccountDiff{
|
||||||
CodeHash: CodeHash,
|
address: {
|
||||||
Storage: storage,
|
Nonce: builder.DiffUint64{Value: &NewNonceValue},
|
||||||
}}
|
Balance: builder.DiffBigInt{Value: big.NewInt(NewBalanceValue)},
|
||||||
|
ContractRoot: builder.DiffString{Value: &ContractRoot},
|
||||||
|
CodeHash: CodeHash,
|
||||||
|
Storage: storage,
|
||||||
|
},
|
||||||
|
anotherAddress: {
|
||||||
|
Nonce: builder.DiffUint64{Value: &NewNonceValue},
|
||||||
|
Balance: builder.DiffBigInt{Value: big.NewInt(NewBalanceValue)},
|
||||||
|
CodeHash: CodeHash,
|
||||||
|
ContractRoot: builder.DiffString{Value: &ContractRoot},
|
||||||
|
Storage: emptyStorage,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
UpdatedAccountDiffs = map[common.Address]builder.AccountDiff{address: {
|
UpdatedAccountDiffs = map[common.Address]builder.AccountDiff{address: {
|
||||||
Nonce: builder.DiffUint64{Value: &NewNonceValue},
|
Nonce: builder.DiffUint64{Value: &NewNonceValue},
|
||||||
|
Loading…
Reference in New Issue
Block a user