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

     1  //go:build all || e2e
     2  // +build all e2e
     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  
    29  	"github.com/stretchr/testify/assert"
    30  
    31  	"github.com/stretchr/testify/require"
    32  )
    33  
    34  func TestIntegrationAccountStakersQueryCanExecute(t *testing.T) {
    35  	t.Parallel()
    36  	env := NewIntegrationTestEnv(t)
    37  
    38  	_, err := NewAccountStakersQuery().
    39  		SetAccountID(env.Client.GetOperatorAccountID()).
    40  		SetMaxQueryPayment(NewHbar(1)).
    41  		SetNodeAccountIDs(env.NodeAccountIDs).
    42  		SetQueryPayment(HbarFromTinybar(25)).
    43  		Execute(env.Client)
    44  	assert.Error(t, err)
    45  
    46  	err = CloseIntegrationTestEnv(env, nil)
    47  	require.NoError(t, err)
    48  }
    49  
    50  func TestIntegrationAccountStakersQueryGetCost(t *testing.T) {
    51  	t.Parallel()
    52  	env := NewIntegrationTestEnv(t)
    53  
    54  	accountStakers := NewAccountStakersQuery().
    55  		SetMaxQueryPayment(NewHbar(1)).
    56  		SetNodeAccountIDs(env.NodeAccountIDs).
    57  		SetAccountID(env.Client.GetOperatorAccountID())
    58  
    59  	cost, err := accountStakers.GetCost(env.Client)
    60  	assert.Error(t, err)
    61  
    62  	_, err = accountStakers.SetQueryPayment(cost).Execute(env.Client)
    63  	assert.Error(t, err)
    64  
    65  	err = CloseIntegrationTestEnv(env, nil)
    66  	require.NoError(t, err)
    67  }
    68  
    69  func TestIntegrationAccountStakersQuerySetBigMaxPayment(t *testing.T) {
    70  	t.Parallel()
    71  	env := NewIntegrationTestEnv(t)
    72  
    73  	accountStakers := NewAccountStakersQuery().
    74  		SetMaxQueryPayment(NewHbar(100000)).
    75  		SetNodeAccountIDs(env.NodeAccountIDs).
    76  		SetAccountID(env.Client.GetOperatorAccountID())
    77  
    78  	cost, err := accountStakers.GetCost(env.Client)
    79  	assert.Error(t, err)
    80  
    81  	_, err = accountStakers.SetQueryPayment(cost).Execute(env.Client)
    82  	assert.Error(t, err)
    83  
    84  	err = CloseIntegrationTestEnv(env, nil)
    85  	require.NoError(t, err)
    86  }
    87  
    88  func TestIntegrationAccountStakersQuerySetSmallMaxPayment(t *testing.T) {
    89  	t.Parallel()
    90  	env := NewIntegrationTestEnv(t)
    91  
    92  	accountStakers := NewAccountStakersQuery().
    93  		SetMaxQueryPayment(HbarFromTinybar(25)).
    94  		SetNodeAccountIDs(env.NodeAccountIDs).
    95  		SetAccountID(env.Client.GetOperatorAccountID())
    96  
    97  	cost, err := accountStakers.GetCost(env.Client)
    98  	assert.Error(t, err)
    99  
   100  	_, err = accountStakers.SetQueryPayment(cost).Execute(env.Client)
   101  	assert.Error(t, err)
   102  
   103  	err = CloseIntegrationTestEnv(env, nil)
   104  	require.NoError(t, err)
   105  }
   106  
   107  func TestIntegrationAccountStakersQueryInsufficientFee(t *testing.T) {
   108  	t.Parallel()
   109  	env := NewIntegrationTestEnv(t)
   110  
   111  	accountStakers := NewAccountStakersQuery().
   112  		SetMaxQueryPayment(NewHbar(1)).
   113  		SetNodeAccountIDs(env.NodeAccountIDs).
   114  		SetAccountID(env.Client.GetOperatorAccountID())
   115  
   116  	_, err := accountStakers.GetCost(env.Client)
   117  	assert.Error(t, err)
   118  
   119  	_, err = accountStakers.SetQueryPayment(HbarFromTinybar(1)).Execute(env.Client)
   120  	assert.Error(t, err)
   121  	if err != nil {
   122  		assert.Equal(t, "exceptional precheck status NOT_SUPPORTED", err.Error())
   123  	}
   124  
   125  	err = CloseIntegrationTestEnv(env, nil)
   126  	require.NoError(t, err)
   127  }
   128  
   129  func TestIntegrationAccountStakersQueryNoAccountID(t *testing.T) {
   130  	t.Parallel()
   131  	env := NewIntegrationTestEnv(t)
   132  
   133  	_, err := NewAccountStakersQuery().
   134  		SetNodeAccountIDs(env.NodeAccountIDs).
   135  		Execute(env.Client)
   136  	assert.Error(t, err)
   137  	if err != nil {
   138  		assert.Equal(t, "exceptional precheck status NOT_SUPPORTED", err.Error())
   139  	}
   140  
   141  	err = CloseIntegrationTestEnv(env, nil)
   142  	require.NoError(t, err)
   143  }