github.com/hashgraph/hedera-sdk-go/v2@v2.48.0/account_allowance_delete_transaction_unit_test.go (about) 1 //go:build all || unit 2 // +build all unit 3 4 package hedera 5 6 import ( 7 "github.com/hashgraph/hedera-protobufs-go/services" 8 "github.com/stretchr/testify/require" 9 protobuf "google.golang.org/protobuf/proto" 10 "testing" 11 "time" 12 ) 13 14 func TestUnitAccountAllowanceDeleteTransactionCoverage(t *testing.T) { 15 t.Parallel() 16 17 checksum := "dmqui" 18 token := TokenID{Token: 3, checksum: &checksum} 19 account := AccountID{Account: 3, checksum: &checksum} 20 nodeAccountID := []AccountID{{Account: 10}} 21 transactionID := TransactionIDGenerate(AccountID{Account: 324}) 22 23 newKey, err := PrivateKeyGenerateEd25519() 24 require.NoError(t, err) 25 26 client, err := _NewMockClient() 27 client.SetLedgerID(*NewLedgerIDTestnet()) 28 require.NoError(t, err) 29 client.SetAutoValidateChecksums(true) 30 31 transaction, err := NewAccountAllowanceDeleteTransaction(). 32 SetTransactionID(transactionID). 33 SetNodeAccountIDs(nodeAccountID). 34 DeleteAllTokenNftAllowances(token.Nft(4), &account). 35 DeleteAllTokenNftAllowances(token.Nft(5), &account). 36 SetMaxTransactionFee(NewHbar(3)). 37 SetMaxRetry(3). 38 DeleteAllHbarAllowances(&account). 39 DeleteAllTokenAllowances(token, &account). 40 SetMaxBackoff(time.Second * 30). 41 SetMinBackoff(time.Second * 10). 42 SetTransactionMemo("no"). 43 SetTransactionValidDuration(time.Second * 30). 44 SetRegenerateTransactionID(false). 45 Freeze() 46 require.NoError(t, err) 47 transaction.validateNetworkOnIDs(client) 48 49 _, err = transaction.Schedule() 50 require.NoError(t, err) 51 transaction.GetTransactionID() 52 transaction.GetNodeAccountIDs() 53 transaction.GetMaxRetry() 54 transaction.GetMaxTransactionFee() 55 transaction.GetMaxBackoff() 56 transaction.GetMinBackoff() 57 transaction.GetRegenerateTransactionID() 58 byt, err := transaction.ToBytes() 59 require.NoError(t, err) 60 txFromBytesI, err := TransactionFromBytes(byt) 61 txFromBytes, ok := txFromBytesI.(AccountAllowanceDeleteTransaction) 62 require.True(t, ok) 63 sig, err := newKey.SignTransaction(&transaction.Transaction) 64 require.NoError(t, err) 65 66 _, err = transaction.GetTransactionHash() 67 require.NoError(t, err) 68 transaction.GetAllTokenNftDeleteAllowances() 69 transaction.GetMaxTransactionFee() 70 transaction.GetTransactionMemo() 71 transaction.GetRegenerateTransactionID() 72 _, err = transaction.GetSignatures() 73 require.NoError(t, err) 74 transaction.GetAllHbarDeleteAllowances() 75 transaction.GetAllTokenDeleteAllowances() 76 transaction.getName() 77 txFromBytes.AddSignature(newKey.PublicKey(), sig) 78 } 79 80 func TestUnitAccountAllowanceDeleteTransactionMock(t *testing.T) { 81 t.Parallel() 82 83 checksum := "dmqui" 84 token := TokenID{Token: 3, checksum: &checksum} 85 nodeAccountID := []AccountID{{Account: 3}} 86 transactionID := TransactionIDGenerate(AccountID{Account: 3}) 87 88 call := func(request *services.Transaction) *services.TransactionResponse { 89 require.NotEmpty(t, request.SignedTransactionBytes) 90 signedTransaction := services.SignedTransaction{} 91 _ = protobuf.Unmarshal(request.SignedTransactionBytes, &signedTransaction) 92 93 require.NotEmpty(t, signedTransaction.BodyBytes) 94 transactionBody := services.TransactionBody{} 95 _ = protobuf.Unmarshal(signedTransaction.BodyBytes, &transactionBody) 96 97 require.NotNil(t, transactionBody.TransactionID) 98 transactionId := transactionBody.TransactionID.String() 99 require.NotEqual(t, "", transactionId) 100 101 sigMap := signedTransaction.GetSigMap() 102 require.NotNil(t, sigMap) 103 104 return &services.TransactionResponse{ 105 NodeTransactionPrecheckCode: services.ResponseCodeEnum_OK, 106 } 107 } 108 responses := [][]interface{}{{ 109 call, 110 }} 111 112 client, server := NewMockClientAndServer(responses) 113 defer server.Close() 114 115 _, err := NewAccountAllowanceDeleteTransaction(). 116 SetTransactionID(transactionID). 117 SetNodeAccountIDs(nodeAccountID). 118 DeleteAllTokenNftAllowances(token.Nft(4), &AccountID{Account: 3}). 119 Execute(client) 120 require.NoError(t, err) 121 } 122 123 func TestUnitAccountAllowanceDeleteTransactionSetNothing(t *testing.T) { 124 t.Parallel() 125 126 token := TokenID{Token: 3} 127 nodeAccountID := []AccountID{{Account: 10}, {Account: 11}, {Account: 12}} 128 transactionID := TransactionIDGenerate(AccountID{Account: 324}) 129 130 transaction, err := NewAccountAllowanceDeleteTransaction(). 131 SetTransactionID(transactionID). 132 SetNodeAccountIDs(nodeAccountID). 133 DeleteAllTokenNftAllowances(token.Nft(4), &AccountID{Account: 3}). 134 Freeze() 135 require.NoError(t, err) 136 137 transaction.GetTransactionID() 138 transaction.GetNodeAccountIDs() 139 140 _, err = transaction.GetTransactionHash() 141 require.NoError(t, err) 142 transaction.GetAllTokenNftDeleteAllowances() 143 transaction.GetMaxTransactionFee() 144 transaction.GetTransactionMemo() 145 transaction.GetRegenerateTransactionID() 146 _, err = transaction.GetSignatures() 147 require.NoError(t, err) 148 }