github.com/hashgraph/hedera-sdk-go/v2@v2.48.0/one_signature_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  	"os"
    28  	"sync/atomic"
    29  	"testing"
    30  
    31  	"github.com/stretchr/testify/require"
    32  )
    33  
    34  var callCount int64
    35  
    36  func incrementCallCount() {
    37  	atomic.AddInt64(&callCount, 1)
    38  }
    39  
    40  func getCallCount() int64 {
    41  	return atomic.LoadInt64(&callCount)
    42  }
    43  
    44  func TestIntegrationOneSignature(t *testing.T) {
    45  	t.Parallel()
    46  	env := NewIntegrationTestEnv(t)
    47  
    48  	client := ClientForNetwork(env.Client.GetNetwork()).SetOperatorWith(env.OriginalOperatorID, env.OriginalOperatorKey, signingServiceTwo)
    49  	response, err := NewTransferTransaction().
    50  		AddHbarTransfer(env.OriginalOperatorID, NewHbar(-1)).
    51  		AddHbarTransfer(AccountID{Account: 3}, NewHbar(1)).
    52  		SetNodeAccountIDs(env.NodeAccountIDs).
    53  		Execute(client)
    54  	require.NoError(t, err)
    55  
    56  	_, err = response.GetReceipt(client)
    57  	require.NoError(t, err)
    58  
    59  	require.Equal(t, int64(1), getCallCount())
    60  	client.Close()
    61  	err = CloseIntegrationTestEnv(env, nil)
    62  	require.NoError(t, err)
    63  }
    64  
    65  func signingServiceTwo(txBytes []byte) []byte {
    66  	localOperatorPrivateKey, _ := PrivateKeyFromString(os.Getenv("OPERATOR_KEY"))
    67  	incrementCallCount()
    68  
    69  	signature := localOperatorPrivateKey.Sign(txBytes)
    70  	return signature
    71  }