github.com/hashgraph/hedera-sdk-go/v2@v2.48.0/address_book_query_e2e_test.go (about)

     1  //go:build all || testnets
     2  // +build all testnets
     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  	"os"
    28  	"testing"
    29  
    30  	"github.com/stretchr/testify/require"
    31  )
    32  
    33  func TestIntegrationAddressBookQueryUpdateAll(t *testing.T) {
    34  	client, err := ClientFromConfig([]byte(`{"network":"previewnet"}`))
    35  	require.NoError(t, err)
    36  	client.SetMirrorNetwork(previewnetMirror)
    37  
    38  	previewnet, err := NewAddressBookQuery().
    39  		SetFileID(FileIDForAddressBook()).
    40  		SetMaxAttempts(5).
    41  		Execute(client)
    42  	require.NoError(t, err)
    43  	require.Greater(t, len(previewnet.NodeAddresses), 0)
    44  
    45  	client, err = ClientFromConfig([]byte(`{"network":"testnet"}`))
    46  	require.NoError(t, err)
    47  	client.SetMirrorNetwork(testnetMirror)
    48  
    49  	testnet, err := NewAddressBookQuery().
    50  		SetFileID(FileIDForAddressBook()).
    51  		SetMaxAttempts(5).
    52  		Execute(client)
    53  
    54  	require.NoError(t, err)
    55  	require.Greater(t, len(testnet.NodeAddresses), 0)
    56  
    57  	client, err = ClientFromConfig([]byte(`{"network":"mainnet"}`))
    58  	require.NoError(t, err)
    59  	client.SetMirrorNetwork(mainnetMirror)
    60  
    61  	mainnet, err := NewAddressBookQuery().
    62  		SetFileID(FileIDForAddressBook()).
    63  		SetMaxAttempts(5).
    64  		Execute(client)
    65  	require.NoError(t, err)
    66  	require.Greater(t, len(mainnet.NodeAddresses), 0)
    67  
    68  	filePreviewnet, err := os.OpenFile("addressbook/previewnet.pb", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
    69  	require.NoError(t, err)
    70  
    71  	fileTestnet, err := os.OpenFile("addressbook/testnet.pb", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
    72  	require.NoError(t, err)
    73  
    74  	fileMainnet, err := os.OpenFile("addressbook/mainnet.pb", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
    75  	require.NoError(t, err)
    76  
    77  	_, err = filePreviewnet.Write(previewnet.ToBytes())
    78  	require.NoError(t, err)
    79  
    80  	_, err = fileTestnet.Write(testnet.ToBytes())
    81  	require.NoError(t, err)
    82  
    83  	_, err = fileMainnet.Write(mainnet.ToBytes())
    84  	require.NoError(t, err)
    85  
    86  	err = filePreviewnet.Close()
    87  	require.NoError(t, err)
    88  
    89  	err = fileTestnet.Close()
    90  	require.NoError(t, err)
    91  
    92  	err = fileMainnet.Close()
    93  	require.NoError(t, err)
    94  }