github.com/hashgraph/hedera-sdk-go/v2@v2.48.0/nework_version_info_query_unit_test.go (about) 1 //go:build all || unit 2 // +build all unit 3 4 package hedera 5 6 /*- 7 * 8 * Hedera Go SDK 9 * 10 * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC 11 * 12 * Licensed under the Apache License, Version 2.0 (the "License"); 13 * you may not use this file except in compliance with the License. 14 * You may obtain a copy of the License at 15 * 16 * http://www.apache.org/licenses/LICENSE-2.0 17 * 18 * Unless required by applicable law or agreed to in writing, software 19 * distributed under the License is distributed on an "AS IS" BASIS, 20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 * See the License for the specific language governing permissions and 22 * limitations under the License. 23 * 24 */ 25 26 import ( 27 "testing" 28 "time" 29 30 "github.com/hashgraph/hedera-protobufs-go/services" 31 "github.com/stretchr/testify/require" 32 ) 33 34 func TestUnitNetworkVersionInfoQuerySetNothing(t *testing.T) { 35 t.Parallel() 36 37 query := NewNetworkVersionQuery() 38 39 require.Equal(t, []AccountID{}, query.GetNodeAccountIDs()) 40 require.Equal(t, 250*time.Millisecond, query.GetMinBackoff()) 41 require.Equal(t, 8*time.Second, query.GetMaxBackoff()) 42 require.Equal(t, 10, query.GetMaxRetryCount()) 43 require.Equal(t, TransactionID{}, query.GetPaymentTransactionID()) 44 require.Equal(t, Hbar{}, query.GetQueryPayment()) 45 require.Equal(t, Hbar{}, query.GetMaxQueryPayment()) 46 } 47 48 func TestNetworkVersionInfoQuery_Get(t *testing.T) { 49 t.Parallel() 50 51 deadline := time.Duration(time.Minute) 52 transactionID := TransactionIDGenerate(AccountID{Account: 324}) 53 query := NewNetworkVersionQuery(). 54 SetQueryPayment(NewHbar(2)). 55 SetMaxQueryPayment(NewHbar(10)). 56 SetNodeAccountIDs([]AccountID{{Account: 3}, {Account: 4}}). 57 SetMaxRetry(5). 58 SetMaxBackoff(10 * time.Second). 59 SetMinBackoff(1 * time.Second). 60 SetPaymentTransactionID(transactionID). 61 SetGrpcDeadline(&deadline) 62 63 require.Equal(t, NewHbar(2), query.GetQueryPayment()) 64 require.Equal(t, NewHbar(10), query.GetMaxQueryPayment()) 65 require.Equal(t, []AccountID{{Account: 3}, {Account: 4}}, query.GetNodeAccountIDs()) 66 require.Equal(t, 5, query.GetMaxRetryCount()) 67 require.Equal(t, 10*time.Second, query.GetMaxBackoff()) 68 require.Equal(t, 1*time.Second, query.GetMinBackoff()) 69 require.Equal(t, transactionID, query.GetPaymentTransactionID()) 70 require.Equal(t, &deadline, query.GetGrpcDeadline()) 71 } 72 73 func TestUnitNetworkVersionInfoQueryMock(t *testing.T) { 74 t.Parallel() 75 76 responses := [][]interface{}{{ 77 &services.Response{ 78 Response: &services.Response_NetworkGetVersionInfo{ 79 NetworkGetVersionInfo: &services.NetworkGetVersionInfoResponse{ 80 Header: &services.ResponseHeader{NodeTransactionPrecheckCode: services.ResponseCodeEnum_OK, ResponseType: services.ResponseType_COST_ANSWER, Cost: 2}, 81 }, 82 }, 83 }, 84 }} 85 86 client, server := NewMockClientAndServer(responses) 87 defer server.Close() 88 89 query := NewNetworkVersionQuery(). 90 SetNodeAccountIDs([]AccountID{{Account: 3}}). 91 SetMaxQueryPayment(NewHbar(1)) 92 93 cost, err := query.GetCost(client) 94 require.NoError(t, err) 95 require.Equal(t, HbarFromTinybar(2), cost) 96 }