diff --git a/tracelistener/processor/datamarshaler/impl_v44.go b/tracelistener/processor/datamarshaler/impl_v44.go index 9ab9545..c4b4559 100644 --- a/tracelistener/processor/datamarshaler/impl_v44.go +++ b/tracelistener/processor/datamarshaler/impl_v44.go @@ -79,14 +79,14 @@ func (d DataMarshaler) Bank(data tracelistener.TraceOperation) (models.BalanceRo // (picture someone who sends all their balance to another address). // To work around this issue, we don't return when coin is invalid when data.Operation is "delete", // and we set balance == 0 instead. - if !coins.IsValid() { + if err := coins.Validate(); err != nil { if data.Operation == tracelistener.DeleteOp.String() { // rawAddress still contains the length prefix, so we have to jump it by // reading 1 byte after len(addrBytes) denom := rawAddress[len(addrBytes)+1:] coins.Denom = string(denom) } else { - return models.BalanceRow{}, nil + return models.BalanceRow{}, fmt.Errorf("invalid balance coin: %w", err) } } diff --git a/tracelistener/processor/datamarshaler/impl_v44_test.go b/tracelistener/processor/datamarshaler/impl_v44_test.go index 3631c4b..c125b25 100644 --- a/tracelistener/processor/datamarshaler/impl_v44_test.go +++ b/tracelistener/processor/datamarshaler/impl_v44_test.go @@ -46,12 +46,12 @@ func TestDataMarshalerBank(t *testing.T) { expectedError: "cannot parse address from balance store key, invalid key", }, { - name: "ok: value is empty", + name: "fail: value is empty", tr: tracelistener.TraceOperation{ Operation: tracelistener.WriteOp.String(), Key: append(types.BalancesPrefix, []byte{3, 'a', 'd', 'd'}...), }, - expectedBalanceRow: models.BalanceRow{}, + expectedError: "invalid balance coin: invalid denom: ", }, { name: "ok: value is not a valid coin", @@ -60,6 +60,7 @@ func TestDataMarshalerBank(t *testing.T) { Key: append(types.BalancesPrefix, []byte{3, 'a', 'd', 'd'}...), Value: []byte("\n$\n\x05uiris\x12\x1b509625143506063788050678455"), }, + expectedError: "invalid balance coin: invalid denom: \n\x05uiris\x12\x1b509625143506063788050678455", }, { name: "ok: value is not a valid coin but operation is delete",