@@ -5,6 +5,7 @@ package hiero
55// SPDX-License-Identifier: Apache-2.0
66
77import (
8+ "errors"
89 "fmt"
910 "net/http"
1011 "net/url"
@@ -131,17 +132,49 @@ func TestUnitMirrorNodeAccountBalanceQueryResolvesContractID(t *testing.T) {
131132 assert .Equal (t , "0.0.98765" , gotAccountID )
132133}
133134
134- func TestUnitMirrorNodeAccountBalanceQueryNonExistentAccountIsZero (t * testing.T ) {
135+ // An empty list must not read as a zero balance: the caller could not tell a missing account from
136+ // one holding nothing. It maps onto the status AccountBalanceQuery reported for the same case.
137+ func TestUnitMirrorNodeAccountBalanceQueryNonExistentAccountErrors (t * testing.T ) {
135138 var gotAccountID string
136139 client := newMockMirrorClient (t , "missing.example.com:443" , balancesHandler (t , & gotAccountID ,
137140 `{"timestamp":null,"balances":[],"links":{"next":null}}` ))
138141
139- balance , err := NewMirrorNodeAccountBalanceQuery ().
142+ _ , err := NewMirrorNodeAccountBalanceQuery ().
140143 SetAccountID (AccountID {Account : 999999999 }).
141144 Execute (client )
142145
143- require .NoError (t , err , "an empty balances array is a zero balance, not an error" )
144- assert .Equal (t , HbarFromTinybar (0 ), balance .Hbars )
146+ var status ErrHederaPreCheckStatus
147+ require .ErrorAs (t , err , & status )
148+ assert .Equal (t , StatusInvalidAccountID , status .Status )
149+ assert .Contains (t , err .Error (), "INVALID_ACCOUNT_ID" )
150+ }
151+
152+ func TestUnitMirrorNodeAccountBalanceQueryZeroBalanceIsNotMissing (t * testing.T ) {
153+ var gotAccountID string
154+ client := newMockMirrorClient (t , "zerobalance.example.com:443" , balancesHandler (t , & gotAccountID ,
155+ `{"balances":[{"account":"0.0.42","balance":0}]}` ))
156+
157+ balance , err := NewMirrorNodeAccountBalanceQuery ().
158+ SetAccountID (AccountID {Account : 42 }).
159+ Execute (client )
160+
161+ require .NoError (t , err )
162+ assert .Zero (t , balance .Hbars .AsTinybar ())
163+ }
164+
165+ func TestUnitMirrorNodeAccountBalanceQueryMissingBalancesArrayIsMalformed (t * testing.T ) {
166+ var gotAccountID string
167+ client := newMockMirrorClient (t , "nobalances.example.com:443" , balancesHandler (t , & gotAccountID ,
168+ `{"timestamp":null,"links":{"next":null}}` ))
169+
170+ _ , err := NewMirrorNodeAccountBalanceQuery ().
171+ SetAccountID (AccountID {Account : 7 }).
172+ Execute (client )
173+
174+ require .Error (t , err )
175+ assert .Contains (t , err .Error (), "no balances array" )
176+ var status ErrHederaPreCheckStatus
177+ assert .False (t , errors .As (err , & status ), "a malformed payload must not read as a missing account" )
145178}
146179
147180func TestUnitMirrorNodeAccountBalanceQueryNoAccountIDErrorsBeforeRequest (t * testing.T ) {
0 commit comments