github.com/hashgraph/hedera-sdk-go/v2@v2.48.0/topic_message_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/stretchr/testify/assert"
    31  	"github.com/stretchr/testify/require"
    32  	"google.golang.org/grpc/status"
    33  )
    34  
    35  func TestUnitTopicMessageQueryValidate(t *testing.T) {
    36  	t.Parallel()
    37  
    38  	client, err := _NewMockClient()
    39  	client.SetLedgerID(*NewLedgerIDTestnet())
    40  	require.NoError(t, err)
    41  	client.SetAutoValidateChecksums(true)
    42  	topicID, err := TopicIDFromString("0.0.123-esxsf")
    43  	require.NoError(t, err)
    44  
    45  	topicInfo := NewTopicMessageQuery().
    46  		SetTopicID(topicID)
    47  
    48  	err = topicInfo.validateNetworkOnIDs(client)
    49  	require.NoError(t, err)
    50  }
    51  
    52  func TestUnitTopicMessageQueryValidateWrong(t *testing.T) {
    53  	t.Parallel()
    54  
    55  	client, err := _NewMockClient()
    56  	client.SetLedgerID(*NewLedgerIDTestnet())
    57  	require.NoError(t, err)
    58  	client.SetAutoValidateChecksums(true)
    59  	topicID, err := TopicIDFromString("0.0.123-rmkykd")
    60  	require.NoError(t, err)
    61  
    62  	topicInfo := NewTopicMessageQuery().
    63  		SetTopicID(topicID)
    64  
    65  	err = topicInfo.validateNetworkOnIDs(client)
    66  	assert.Error(t, err)
    67  	if err != nil {
    68  		assert.Equal(t, "network mismatch or wrong checksum given, given checksum: rmkykd, correct checksum esxsf, network: testnet", err.Error())
    69  	}
    70  }
    71  
    72  func TestUnitTopicMessageQueryGet(t *testing.T) {
    73  	t.Parallel()
    74  
    75  	topicID := TopicID{Topic: 7}
    76  
    77  	balance := NewTopicMessageQuery().
    78  		SetTopicID(topicID).
    79  		SetStartTime(time.Now()).
    80  		SetMaxAttempts(23).
    81  		SetEndTime(time.Now()).
    82  		SetLimit(32).
    83  		SetCompletionHandler(func() {}).
    84  		SetErrorHandler(func(stat status.Status) {}).
    85  		SetRetryHandler(func(err error) bool { return false })
    86  
    87  	balance.GetTopicID()
    88  	balance.GetStartTime()
    89  	balance.GetMaxAttempts()
    90  	balance.GetEndTime()
    91  	balance.GetLimit()
    92  }
    93  
    94  func TestUnitTopicMessageQueryNothingSet(t *testing.T) {
    95  	t.Parallel()
    96  
    97  	balance := NewTopicMessageQuery()
    98  
    99  	balance.GetTopicID()
   100  	balance.GetStartTime()
   101  	balance.GetMaxAttempts()
   102  	balance.GetEndTime()
   103  	balance.GetLimit()
   104  }