Skip to content

Commit

Permalink
Fix regression
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick-ogrady committed Oct 30, 2020
1 parent 7ebff5b commit 5f39662
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
13 changes: 8 additions & 5 deletions parser/balance_changes.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,17 @@ func (p *Parser) BalanceChanges(
continue
}

amount := op.Amount
// We create a copy of Amount.Value
// here to ensure we don't accidentally overwrite
// the value of op.Amount.
amountValue := op.Amount.Value
blockIdentifier := block.BlockIdentifier
if blockRemoved {
negatedValue, err := types.NegateValue(amount.Value)
negatedValue, err := types.NegateValue(amountValue)
if err != nil {
return nil, err
}
amount.Value = negatedValue
amountValue = negatedValue
blockIdentifier = block.ParentBlockIdentifier
}

Expand All @@ -111,13 +114,13 @@ func (p *Parser) BalanceChanges(
balanceChanges[key] = &BalanceChange{
Account: op.Account,
Currency: op.Amount.Currency,
Difference: amount.Value,
Difference: amountValue,
Block: blockIdentifier,
}
continue
}

newDifference, err := types.AddValues(val.Difference, amount.Value)
newDifference, err := types.AddValues(val.Difference, amountValue)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion storage/balance_storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1553,7 +1553,7 @@ func TestBlockSyncing(t *testing.T) {
amount, err = storage.GetBalance(ctx, addr1, curr, b2.BlockIdentifier.Index)
assert.NoError(t, err)
assert.Equal(t, &types.Amount{
Value: "0",
Value: "100",
Currency: curr,
}, amount)
amount, err = storage.GetBalance(ctx, addr2, curr, b2.BlockIdentifier.Index)
Expand Down

0 comments on commit 5f39662

Please sign in to comment.