Skip to content

Commit a9422ea

Browse files
committed
test: update docs and few nits
Signed-off-by: dosi <dosi.kolev@limechain.tech>
1 parent 3ba97ee commit a9422ea

4 files changed

Lines changed: 15 additions & 43 deletions

File tree

sdk/account_id.go

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -340,17 +340,9 @@ const (
340340
EvmAddress
341341
)
342342

343-
// _MirrorNodePathID renders the AccountID in a form /accounts/{idOrAliasOrEvmAddress} accepts: an
344-
// EVM-address alias as bare hex, a public-key alias as base32 (RFC 4648, no padding) of the
345-
// serialized key -- what the mirror node itself reports -- and anything else as shard.realm.num.
346-
//
347-
// The numeric form wins whenever it is available, because it is canonical and because an alias ID
348-
// keeps its alias field after PopulateAccount fills in the account number. 0.0.0 is not a real
349-
// account, so a zero Account means only the alias can identify this ID.
350-
//
351-
// Note that the alias forms carry no shard.realm prefix; the mirror node resolves an alias without
352-
// one. A contract is addressed through the same numeric form, so no separate contract variant is
353-
// needed.
343+
// _MirrorNodePathID renders the AccountID as the mirror node accepts it: shard.realm.num when a
344+
// number is set, otherwise an EVM-address alias as bare hex or a public key alias as unpadded
345+
// base32. Alias forms carry no shard.realm prefix.
354346
func (id AccountID) _MirrorNodePathID() string {
355347
if id.Account != 0 {
356348
return fmt.Sprintf("%d.%d.%d", id.Shard, id.Realm, id.Account)

sdk/mirror_node_account_balance_query.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ func (q *MirrorNodeAccountBalanceQuery) resolveEndpoint(client *Client) (string,
8484
return q.buildURL(mirrorUrl), nil
8585
}
8686

87-
// resolveAttempts picks the retry budget: query, then client, then the SDK default. Not a single
88-
// attempt: Client.GetMaxAttempts reports -1 when unset and 5xx responses must still be retried.
87+
// resolveAttempts picks the retry budget: query setting first,
88+
// client default second, the SDK default as the final fallback.
8989
func (q *MirrorNodeAccountBalanceQuery) resolveAttempts(client *Client) uint64 {
9090
if q.maxAttempts > 0 {
9191
return q.maxAttempts
@@ -118,8 +118,7 @@ func (q *MirrorNodeAccountBalanceQuery) validateNetworkOnIDs(client *Client) err
118118
return nil
119119
}
120120

121-
// fetchAccountBalances GETs the balances endpoint; the shared core retries 5xx/429 and transport
122-
// failures, and returns a 4xx as-is.
121+
// fetchAccountBalances GETs the balances endpoint through the shared retry core.
123122
func fetchAccountBalances(client *Client, endpoint string, attempts uint64) ([]byte, error) {
124123
resp, err := mirrorNodeGetWithRetry(client, endpoint, attempts, mirrorNodeDefaultTimeout)
125124
if err != nil {
@@ -151,6 +150,5 @@ type accountBalancesResponseJSON struct {
151150

152151
type accountBalanceJSON struct {
153152
Account string `json:"account"`
154-
// Tinybars; int64 holds the whole hbar supply exactly.
155-
Balance int64 `json:"balance"`
153+
Balance int64 `json:"balance"`
156154
}

sdk/mirror_node_account_balance_query_unit_test.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ func TestUnitMirrorNodeAccountBalanceQueryDefaults(t *testing.T) {
4848
assert.Zero(t, query.GetMaxAttempts())
4949
}
5050

51-
// AC 1: a valid account ID returns the hbar balance the mirror node reports.
5251
func TestUnitMirrorNodeAccountBalanceQueryReturnsHbarBalance(t *testing.T) {
5352
var gotAccountID string
5453
client := newMockMirrorClient(t, "balance.example.com:443", balancesHandler(t, &gotAccountID,
@@ -79,7 +78,6 @@ func TestUnitMirrorNodeAccountBalanceQueryLargeBalanceIsLossless(t *testing.T) {
7978
assert.Equal(t, tinybars, balance.Hbars.AsTinybar())
8079
}
8180

82-
// AC 2: an EVM address is sent as bare hex, which is what the mirror node resolves.
8381
func TestUnitMirrorNodeAccountBalanceQueryResolvesEvmAddress(t *testing.T) {
8482
var gotAccountID string
8583
client := newMockMirrorClient(t, "evm.example.com:443", balancesHandler(t, &gotAccountID,
@@ -97,7 +95,6 @@ func TestUnitMirrorNodeAccountBalanceQueryResolvesEvmAddress(t *testing.T) {
9795
assert.Equal(t, "742d35cc6634c0532925a3b844bc454e4438f44e", gotAccountID)
9896
}
9997

100-
// AC 3: a public key alias is sent base32-encoded, the form the mirror node reports and accepts.
10198
func TestUnitMirrorNodeAccountBalanceQueryResolvesPublicKeyAlias(t *testing.T) {
10299
var gotAccountID string
103100
client := newMockMirrorClient(t, "alias.example.com:443", balancesHandler(t, &gotAccountID,
@@ -119,7 +116,6 @@ func TestUnitMirrorNodeAccountBalanceQueryResolvesPublicKeyAlias(t *testing.T) {
119116
assert.Equal(t, gotAccountID, url.QueryEscape(gotAccountID), "alias must need no escaping")
120117
}
121118

122-
// AC 4: a contract is addressed through the same account.id parameter.
123119
func TestUnitMirrorNodeAccountBalanceQueryResolvesContractID(t *testing.T) {
124120
var gotAccountID string
125121
client := newMockMirrorClient(t, "contract.example.com:443", balancesHandler(t, &gotAccountID,
@@ -135,7 +131,6 @@ func TestUnitMirrorNodeAccountBalanceQueryResolvesContractID(t *testing.T) {
135131
assert.Equal(t, "0.0.98765", gotAccountID)
136132
}
137133

138-
// AC 5: an unknown account yields an empty list, which is a zero balance and not an error.
139134
func TestUnitMirrorNodeAccountBalanceQueryNonExistentAccountIsZero(t *testing.T) {
140135
var gotAccountID string
141136
client := newMockMirrorClient(t, "missing.example.com:443", balancesHandler(t, &gotAccountID,
@@ -149,7 +144,6 @@ func TestUnitMirrorNodeAccountBalanceQueryNonExistentAccountIsZero(t *testing.T)
149144
assert.Equal(t, HbarFromTinybar(0), balance.Hbars)
150145
}
151146

152-
// AC 6: an unset account ID fails before any network call.
153147
func TestUnitMirrorNodeAccountBalanceQueryNoAccountIDErrorsBeforeRequest(t *testing.T) {
154148
var called atomic.Bool
155149
client := newMockMirrorClient(t, "unused.example.com:443", func(w http.ResponseWriter, r *http.Request) {
@@ -173,7 +167,6 @@ func TestUnitMirrorNodeAccountBalanceQueryNilClientErrors(t *testing.T) {
173167
require.ErrorIs(t, err, errNoClientProvided)
174168
}
175169

176-
// AC 7: a transient 503 is retried and the following success is returned.
177170
func TestUnitMirrorNodeAccountBalanceQueryRetriesTransientError(t *testing.T) {
178171
var attempts atomic.Int32
179172
client := newMockMirrorClient(t, "retry.example.com:443", func(w http.ResponseWriter, r *http.Request) {
@@ -289,8 +282,7 @@ func TestUnitMirrorNodeAccountBalanceQueryBadChecksumErrorsBeforeRequest(t *test
289282
assert.False(t, called.Load(), "a checksum mismatch must not reach the network")
290283
}
291284

292-
// resolveAttempts: query setting, then client, then SDK default. The default must not be a single
293-
// attempt -- this query has to retry 5xx, and Client.GetMaxAttempts reports -1 when unset.
285+
// The fallback must not be a single attempt; 5xx responses still have to be retried.
294286
func TestUnitMirrorNodeAccountBalanceQueryResolveAttempts(t *testing.T) {
295287
t.Parallel()
296288

sdk/mirror_node_rest_helpers.go

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,8 @@ const (
2525
)
2626

2727
// mirrorNodeRestBaseURL returns the client's mirror node REST API base URL, erroring when no
28-
// mirror network is configured.
29-
//
30-
// The canonical value comes from _MirrorNode.getBaseRestUrl, which maps a localhost mirror network
31-
// to port 38081. Endpoints that a local node serves elsewhere override it afterwards: the fee
32-
// estimate and registered-node endpoints on 8084, the contract-call endpoint on 8545 (the JSON-RPC
33-
// relay). Callers that need no override use the returned URL as-is.
28+
// mirror network is configured. A caller whose endpoint is served on a different port against a
29+
// local node overrides it afterwards.
3430
func mirrorNodeRestBaseURL(client *Client) (string, error) {
3531
if client == nil {
3632
return "", errNoClientProvided
@@ -43,8 +39,8 @@ func mirrorNodeRestBaseURL(client *Client) (string, error) {
4339
return client.GetMirrorRestApiBaseUrl()
4440
}
4541

46-
// mirrorNodeValidateURL rejects a URL no HTTP request could ever satisfy, so the retry loop does
47-
// not spend its whole budget and backoff on a permanent failure.
42+
// mirrorNodeValidateURL rejects a URL no HTTP request could satisfy, so the retry loop does not
43+
// spend its budget on a permanent failure.
4844
func mirrorNodeValidateURL(rawURL string) error {
4945
parsed, err := url.Parse(rawURL)
5046
if err != nil {
@@ -61,12 +57,9 @@ func mirrorNodeValidateURL(rawURL string) error {
6157
}
6258

6359
// mirrorNodeRequestWithRetry runs send with exponential backoff, retrying transport failures and
64-
// 5xx/429; a 4xx is the intended result of the call and is not retried. send runs once per attempt
65-
// so it can rebuild the request body.
66-
//
67-
// The final attempt is returned raw so callers can format their own error: a 200 response, a
68-
// non-200 response with a nil error, or a nil response and the transport error. The caller must
69-
// close a non-nil Body (mirrorNodeReadBody does). A timeout of 0 disables the per-request timeout.
60+
// 5xx/429; a 4xx is the intended result and is not retried. The final attempt is returned raw so
61+
// callers can format their own error, and the caller must close a non-nil Body. A timeout of 0
62+
// disables the per-request timeout.
7063
func mirrorNodeRequestWithRetry(client *Client, maxAttempts uint64, timeout time.Duration, send func(*http.Client) (*http.Response, error)) (*http.Response, error) {
7164
if maxAttempts == 0 {
7265
return nil, errors.New("maxAttempts must be at least 1")
@@ -180,9 +173,6 @@ func mirrorNodeReadBody(resp *http.Response) ([]byte, error) {
180173
// mirrorNodeWalkPages walks a paginated endpoint from pageURL, passing each fetched body to
181174
// handlePage, which returns the raw links.next. Stops when next is absent, or at maxPages so a
182175
// misbehaving mirror node cannot loop forever.
183-
//
184-
// A links.next is a root-relative path, so it is resolved against pageURL itself rather than
185-
// against a separately supplied base -- one argument cannot then disagree with the other.
186176
func mirrorNodeWalkPages(
187177
pageURL string,
188178
maxPages int,

0 commit comments

Comments
 (0)