github.com/hashgraph/hedera-sdk-go/v2@v2.48.0/crypto_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  	"github.com/stretchr/testify/assert"
    28  	"github.com/stretchr/testify/require"
    29  
    30  	"testing"
    31  )
    32  
    33  func TestSetKeyUsesAnyKey(t *testing.T) {
    34  	t.Parallel()
    35  	env := NewIntegrationTestEnv(t)
    36  
    37  	newKey, err := PrivateKeyGenerateEd25519()
    38  	require.NoError(t, err)
    39  
    40  	newBalance := NewHbar(2)
    41  
    42  	assert.Equal(t, 2*HbarUnits.Hbar._NumberOfTinybar(), newBalance.tinybar)
    43  
    44  	keys := make([]PrivateKey, 3)
    45  	pubKeys := make([]PublicKey, 3)
    46  
    47  	for i := range keys {
    48  		newKey, err := PrivateKeyGenerateEd25519()
    49  		if err != nil {
    50  			panic(err)
    51  		}
    52  
    53  		keys[i] = newKey
    54  		pubKeys[i] = newKey.PublicKey()
    55  	}
    56  
    57  	thresholdKey := KeyListWithThreshold(2).
    58  		AddAllPublicKeys(pubKeys)
    59  
    60  	_, err = NewAccountCreateTransaction().
    61  		SetNodeAccountIDs(env.NodeAccountIDs).
    62  		SetKey(newKey.PublicKey()).
    63  		SetKey(newKey).
    64  		SetKey(thresholdKey).
    65  		SetInitialBalance(newBalance).
    66  		Execute(env.Client)
    67  	require.NoError(t, err)
    68  }
    69  
    70  func DisabledTestECDSAPrivateKey(t *testing.T) {
    71  	t.Parallel()
    72  	env := NewIntegrationTestEnv(t)
    73  
    74  	newKey, err := PrivateKeyGenerateEcdsa()
    75  	require.NoError(t, err)
    76  
    77  	newBalance := NewHbar(2)
    78  
    79  	assert.Equal(t, 2*HbarUnits.Hbar._NumberOfTinybar(), newBalance.tinybar)
    80  
    81  	resp, err := NewAccountCreateTransaction().
    82  		SetKey(newKey).
    83  		SetNodeAccountIDs(env.NodeAccountIDs).
    84  		SetInitialBalance(newBalance).
    85  		SetMaxAutomaticTokenAssociations(100).
    86  		Execute(env.Client)
    87  	require.NoError(t, err)
    88  
    89  	receipt, err := resp.SetValidateStatus(true).GetReceipt(env.Client)
    90  	require.NoError(t, err)
    91  
    92  	accountID := *receipt.AccountID
    93  
    94  	tx, err := NewAccountDeleteTransaction().
    95  		SetNodeAccountIDs(env.NodeAccountIDs).
    96  		SetAccountID(accountID).
    97  		SetTransferAccountID(env.Client.GetOperatorAccountID()).
    98  		SetTransactionID(TransactionIDGenerate(accountID)).
    99  		FreezeWith(env.Client)
   100  	require.NoError(t, err)
   101  
   102  	resp, err = tx.
   103  		Sign(newKey).
   104  		Execute(env.Client)
   105  	require.NoError(t, err)
   106  
   107  	_, err = resp.SetValidateStatus(true).GetReceipt(env.Client)
   108  	require.NoError(t, err)
   109  
   110  	err = CloseIntegrationTestEnv(env, nil)
   111  	require.NoError(t, err)
   112  }