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,6 +98,7 @@ func formatAccountData(accountAddr common.Address, accountDiff builder.AccountDi
|
|||||||
address := accountAddr.String()
|
address := accountAddr.String()
|
||||||
var result [][]string
|
var result [][]string
|
||||||
|
|
||||||
|
if len(accountDiff.Storage) > 0 {
|
||||||
for storagePath, storage := range accountDiff.Storage {
|
for storagePath, storage := range accountDiff.Storage {
|
||||||
formattedAccountData := []string{
|
formattedAccountData := []string{
|
||||||
blockNumberString,
|
blockNumberString,
|
||||||
@ -106,7 +116,22 @@ func formatAccountData(accountAddr common.Address, accountDiff builder.AccountDi
|
|||||||
|
|
||||||
result = append(result, formattedAccountData)
|
result = append(result, formattedAccountData)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
formattedAccountData := []string{
|
||||||
|
blockNumberString,
|
||||||
|
blockHash,
|
||||||
|
accountAction,
|
||||||
|
codeHash,
|
||||||
|
nonce,
|
||||||
|
balance,
|
||||||
|
*newContractRoot,
|
||||||
|
"",
|
||||||
|
address,
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
}
|
||||||
|
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) {
|
||||||
|
@ -21,15 +21,27 @@ var (
|
|||||||
Key: &StorageKey,
|
Key: &StorageKey,
|
||||||
Value: &StorageValue,
|
Value: &StorageValue,
|
||||||
}}
|
}}
|
||||||
|
emptyStorage = map[string]builder.DiffStorage{}
|
||||||
address = common.HexToAddress("0xaE9BEa628c4Ce503DcFD7E305CaB4e29E7476592")
|
address = common.HexToAddress("0xaE9BEa628c4Ce503DcFD7E305CaB4e29E7476592")
|
||||||
|
anotherAddress = common.HexToAddress("0xaE9BEa628c4Ce503DcFD7E305CaB4e29E7476593")
|
||||||
ContractAddress = address.String()
|
ContractAddress = address.String()
|
||||||
CreatedAccountDiffs = map[common.Address]builder.AccountDiff{address: {
|
AnotherContractAddress = anotherAddress.String()
|
||||||
|
CreatedAccountDiffs = map[common.Address]builder.AccountDiff{
|
||||||
|
address: {
|
||||||
Nonce: builder.DiffUint64{Value: &NewNonceValue},
|
Nonce: builder.DiffUint64{Value: &NewNonceValue},
|
||||||
Balance: builder.DiffBigInt{Value: big.NewInt(NewBalanceValue)},
|
Balance: builder.DiffBigInt{Value: big.NewInt(NewBalanceValue)},
|
||||||
ContractRoot: builder.DiffString{Value: &ContractRoot},
|
ContractRoot: builder.DiffString{Value: &ContractRoot},
|
||||||
CodeHash: CodeHash,
|
CodeHash: CodeHash,
|
||||||
Storage: storage,
|
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