github.com/hashgraph/hedera-sdk-go/v2@v2.48.0/live_hash_delete_transaction_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/hashgraph/hedera-protobufs-go/services" 31 "github.com/stretchr/testify/require" 32 protobuf "google.golang.org/protobuf/proto" 33 ) 34 35 func TestUnitLiveHashDeleteTransactionCoverage(t *testing.T) { 36 t.Parallel() 37 38 checksum := "dmqui" 39 grpc := time.Second * 30 40 account := AccountID{Account: 3, checksum: &checksum} 41 nodeAccountID := []AccountID{{Account: 10}} 42 transactionID := TransactionIDGenerate(AccountID{Account: 324}) 43 44 newKey, err := PrivateKeyGenerateEd25519() 45 require.NoError(t, err) 46 47 client, err := _NewMockClient() 48 client.SetLedgerID(*NewLedgerIDTestnet()) 49 require.NoError(t, err) 50 client.SetAutoValidateChecksums(true) 51 52 transaction, err := NewLiveHashDeleteTransaction(). 53 SetTransactionID(transactionID). 54 SetNodeAccountIDs(nodeAccountID). 55 SetHash([]byte{1}). 56 SetAccountID(account). 57 SetGrpcDeadline(&grpc). 58 SetMaxTransactionFee(NewHbar(3)). 59 SetMaxRetry(3). 60 SetMaxBackoff(time.Second * 30). 61 SetMinBackoff(time.Second * 10). 62 SetTransactionMemo("no"). 63 SetTransactionValidDuration(time.Second * 30). 64 SetRegenerateTransactionID(false). 65 Freeze() 66 require.NoError(t, err) 67 68 transaction.validateNetworkOnIDs(client) 69 70 transaction.GetTransactionID() 71 transaction.GetNodeAccountIDs() 72 transaction.GetMaxRetry() 73 transaction.GetMaxTransactionFee() 74 transaction.GetMaxBackoff() 75 transaction.GetMinBackoff() 76 transaction.GetRegenerateTransactionID() 77 byt, err := transaction.ToBytes() 78 require.NoError(t, err) 79 txFromBytes, err := TransactionFromBytes(byt) 80 require.NoError(t, err) 81 sig, err := newKey.SignTransaction(&transaction.Transaction) 82 require.NoError(t, err) 83 84 _, err = transaction.GetTransactionHash() 85 require.NoError(t, err) 86 transaction.GetMaxTransactionFee() 87 transaction.GetTransactionMemo() 88 transaction.GetRegenerateTransactionID() 89 transaction.GetAccountID() 90 transaction.GetHash() 91 _, err = transaction.GetSignatures() 92 require.NoError(t, err) 93 transaction.getName() 94 switch b := txFromBytes.(type) { 95 case LiveHashDeleteTransaction: 96 b.AddSignature(newKey.PublicKey(), sig) 97 } 98 } 99 100 func TestUnitLiveHashDeleteTransactionMock(t *testing.T) { 101 t.Parallel() 102 103 newKey, err := PrivateKeyFromStringEd25519("302e020100300506032b657004220420a869f4c6191b9c8c99933e7f6b6611711737e4b1a1a5a4cb5370e719a1f6df98") 104 require.NoError(t, err) 105 106 call := func(request *services.Transaction) *services.TransactionResponse { 107 require.NotEmpty(t, request.SignedTransactionBytes) 108 signedTransaction := services.SignedTransaction{} 109 _ = protobuf.Unmarshal(request.SignedTransactionBytes, &signedTransaction) 110 111 require.NotEmpty(t, signedTransaction.BodyBytes) 112 transactionBody := services.TransactionBody{} 113 _ = protobuf.Unmarshal(signedTransaction.BodyBytes, &transactionBody) 114 115 require.NotNil(t, transactionBody.TransactionID) 116 transactionId := transactionBody.TransactionID.String() 117 require.NotEqual(t, "", transactionId) 118 119 sigMap := signedTransaction.GetSigMap() 120 require.NotNil(t, sigMap) 121 122 return &services.TransactionResponse{ 123 NodeTransactionPrecheckCode: services.ResponseCodeEnum_OK, 124 } 125 } 126 responses := [][]interface{}{{ 127 call, 128 }} 129 130 client, server := NewMockClientAndServer(responses) 131 defer server.Close() 132 133 freez, err := NewLiveHashDeleteTransaction(). 134 SetNodeAccountIDs([]AccountID{{Account: 3}}). 135 SetAccountID(AccountID{Account: 3}). 136 SetHash([]byte{123}). 137 FreezeWith(client) 138 require.NoError(t, err) 139 140 _, err = freez.Sign(newKey).Execute(client) 141 require.NoError(t, err) 142 }