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