github.com/hashgraph/hedera-sdk-go/v2@v2.48.0/account_info_flow_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 TestIntegrationVerifySignatureFlowCanExecute(t *testing.T) {
    35  	t.Parallel()
    36  	env := NewIntegrationTestEnv(t)
    37  
    38  	newKey, err := PrivateKeyGenerateEd25519()
    39  	require.NoError(t, err)
    40  
    41  	newBalance := NewHbar(10)
    42  
    43  	resp, err := NewAccountCreateTransaction().
    44  		SetKey(newKey.PublicKey()).
    45  		SetNodeAccountIDs(env.NodeAccountIDs).
    46  		SetInitialBalance(newBalance).
    47  		Execute(env.Client)
    48  	require.NoError(t, err)
    49  
    50  	receipt, err := resp.SetValidateStatus(true).GetReceipt(env.Client)
    51  	require.NoError(t, err)
    52  
    53  	accountID := *receipt.AccountID
    54  	require.NoError(t, err)
    55  
    56  	//verify, err := AccountInfoFlowVerifySignature(env.Client, accountID, newKey.PublicKey())
    57  	//require.NoError(t, err)
    58  	//
    59  	//assert.True(t, verify)
    60  
    61  	tx, err := NewAccountDeleteTransaction().
    62  		SetAccountID(accountID).
    63  		SetNodeAccountIDs([]AccountID{resp.NodeID}).
    64  		SetTransferAccountID(env.Client.GetOperatorAccountID()).
    65  		SetTransactionID(TransactionIDGenerate(accountID)).
    66  		FreezeWith(env.Client)
    67  	require.NoError(t, err)
    68  
    69  	resp, err = tx.
    70  		Sign(newKey).
    71  		Execute(env.Client)
    72  	require.NoError(t, err)
    73  
    74  	_, err = resp.SetValidateStatus(true).GetReceipt(env.Client)
    75  	require.NoError(t, err)
    76  
    77  	err = CloseIntegrationTestEnv(env, nil)
    78  	require.NoError(t, err)
    79  }
    80  
    81  func TestIntegrationVerifySignatureFlowKeyList(t *testing.T) {
    82  	t.Parallel()
    83  	env := NewIntegrationTestEnv(t)
    84  
    85  	keys := make([]PrivateKey, 3)
    86  	pubKeys := make([]PublicKey, 3)
    87  
    88  	for i := range keys {
    89  		newKey, err := PrivateKeyGenerateEd25519()
    90  		assert.NoError(t, err)
    91  
    92  		keys[i] = newKey
    93  		pubKeys[i] = newKey.PublicKey()
    94  	}
    95  
    96  	thresholdPublicKeys := KeyListWithThreshold(2).
    97  		AddAllPublicKeys(pubKeys)
    98  
    99  	newBalance := NewHbar(2)
   100  	assert.Equal(t, 2*HbarUnits.Hbar._NumberOfTinybar(), newBalance.tinybar)
   101  
   102  	resp, err := NewAccountCreateTransaction().
   103  		SetKey(thresholdPublicKeys).
   104  		SetNodeAccountIDs(env.NodeAccountIDs).
   105  		SetInitialBalance(newBalance).
   106  		Execute(env.Client)
   107  	require.NoError(t, err)
   108  
   109  	receipt, err := resp.SetValidateStatus(true).GetReceipt(env.Client)
   110  	require.NoError(t, err)
   111  
   112  	accountID := *receipt.AccountID
   113  	require.NoError(t, err)
   114  
   115  	//verify, err := AccountInfoFlowVerifySignature(env.Client, accountID, pubKeys[0])
   116  	//require.NoError(t, err)
   117  	//
   118  	//assert.True(t, verify)
   119  
   120  	tx, err := NewAccountDeleteTransaction().
   121  		SetAccountID(accountID).
   122  		SetNodeAccountIDs([]AccountID{resp.NodeID}).
   123  		SetTransferAccountID(env.Client.GetOperatorAccountID()).
   124  		SetTransactionID(TransactionIDGenerate(accountID)).
   125  		FreezeWith(env.Client)
   126  	require.NoError(t, err)
   127  
   128  	resp, err = tx.
   129  		Sign(keys[0]).
   130  		Sign(keys[1]).
   131  		Sign(keys[2]).
   132  		Execute(env.Client)
   133  	require.NoError(t, err)
   134  
   135  	_, err = resp.SetValidateStatus(true).GetReceipt(env.Client)
   136  	require.NoError(t, err)
   137  
   138  	err = CloseIntegrationTestEnv(env, nil)
   139  	require.NoError(t, err)
   140  }