@@ -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"
@@ -116,32 +117,47 @@ func TestUnitMirrorNodeAccountBalanceQueryResolvesPublicKeyAlias(t *testing.T) {
116117 assert .Equal (t , gotAccountID , url .QueryEscape (gotAccountID ), "alias must need no escaping" )
117118}
118119
119- func TestUnitMirrorNodeAccountBalanceQueryResolvesContractID (t * testing.T ) {
120+ func TestUnitMirrorNodeAccountBalanceQueryNonExistentAccountErrors (t * testing.T ) {
120121 var gotAccountID string
121- client := newMockMirrorClient (t , "contract.example.com:443" , balancesHandler (t , & gotAccountID ,
122- `{"balances":[{"account":"0.0.98765","balance":777}]}` ))
122+ client := newMockMirrorClient (t , "missing.example.com:443" , balancesHandler (t , & gotAccountID ,
123+ `{"timestamp":null,"balances":[],"links":{"next":null}}` ))
124+
125+ _ , err := NewMirrorNodeAccountBalanceQuery ().
126+ SetAccountID (AccountID {Account : 999999999 }).
127+ Execute (client )
128+
129+ var status ErrHederaPreCheckStatus
130+ require .ErrorAs (t , err , & status )
131+ assert .Equal (t , StatusInvalidAccountID , status .Status )
132+ assert .Contains (t , err .Error (), "INVALID_ACCOUNT_ID" )
133+ }
134+
135+ func TestUnitMirrorNodeAccountBalanceQueryZeroBalanceIsNotMissing (t * testing.T ) {
136+ var gotAccountID string
137+ client := newMockMirrorClient (t , "zerobalance.example.com:443" , balancesHandler (t , & gotAccountID ,
138+ `{"balances":[{"account":"0.0.42","balance":0}]}` ))
123139
124- contractID := ContractID {Shard : 0 , Realm : 0 , Contract : 98765 }
125140 balance , err := NewMirrorNodeAccountBalanceQuery ().
126- SetAccountID (AccountID {Shard : contractID . Shard , Realm : contractID . Realm , Account : contractID . Contract }).
141+ SetAccountID (AccountID {Account : 42 }).
127142 Execute (client )
128143
129144 require .NoError (t , err )
130- assert .Equal (t , HbarFromTinybar (777 ), balance .Hbars )
131- assert .Equal (t , "0.0.98765" , gotAccountID )
145+ assert .Zero (t , balance .Hbars .AsTinybar ())
132146}
133147
134- func TestUnitMirrorNodeAccountBalanceQueryNonExistentAccountIsZero (t * testing.T ) {
148+ func TestUnitMirrorNodeAccountBalanceQueryMissingBalancesArrayIsMalformed (t * testing.T ) {
135149 var gotAccountID string
136- client := newMockMirrorClient (t , "missing .example.com:443" , balancesHandler (t , & gotAccountID ,
137- `{"timestamp":null,"balances":[]," links":{"next":null}}` ))
150+ client := newMockMirrorClient (t , "nobalances .example.com:443" , balancesHandler (t , & gotAccountID ,
151+ `{"timestamp":null,"links":{"next":null}}` ))
138152
139- balance , err := NewMirrorNodeAccountBalanceQuery ().
140- SetAccountID (AccountID {Account : 999999999 }).
153+ _ , err := NewMirrorNodeAccountBalanceQuery ().
154+ SetAccountID (AccountID {Account : 7 }).
141155 Execute (client )
142156
143- require .NoError (t , err , "an empty balances array is a zero balance, not an error" )
144- assert .Equal (t , HbarFromTinybar (0 ), balance .Hbars )
157+ require .Error (t , err )
158+ assert .Contains (t , err .Error (), "no balances array" )
159+ var status ErrHederaPreCheckStatus
160+ assert .False (t , errors .As (err , & status ), "a malformed payload must not read as a missing account" )
145161}
146162
147163func TestUnitMirrorNodeAccountBalanceQueryNoAccountIDErrorsBeforeRequest (t * testing.T ) {
0 commit comments