github.com/hashgraph/hedera-sdk-go/v2@v2.48.0/system_undelete_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 29 "github.com/hashgraph/hedera-protobufs-go/services" 30 "github.com/stretchr/testify/require" 31 ) 32 33 func TestUnitSystemUndeleteTransactionFromProtobuf(t *testing.T) { 34 t.Parallel() 35 36 trx, trxBody := _CreateProtoBufUndeleteTrxBody() 37 sysUndeleteTrx := _SystemUndeleteTransactionFromProtobuf(trx, trxBody) 38 require.NotNil(t, sysUndeleteTrx) 39 require.Equal(t, "memo", sysUndeleteTrx.memo) 40 require.Equal(t, uint64(5), sysUndeleteTrx.transactionFee) 41 require.Equal(t, uint64(10), sysUndeleteTrx.defaultMaxTransactionFee) 42 } 43 44 func TestUnitSystemUndeleteTrxGettersAndSetters(t *testing.T) { 45 t.Parallel() 46 undeleteTrx := _SetupSystemUndeleteTrx() 47 48 require.Equal(t, testContractId, undeleteTrx.GetContractID()) 49 require.Equal(t, undeleteTrx.GetNodeAccountIDs(), []AccountID{AccountID{Account: 3}}) 50 require.Equal(t, testFileId, undeleteTrx.GetFileID()) 51 require.Equal(t, testTrxValidDuration, undeleteTrx.GetTransactionValidDuration()) 52 require.Equal(t, testTrxValidDuration, *undeleteTrx.GetGrpcDeadline()) 53 } 54 55 func TestUnitSystemUndeleteTrxValidateNetworkOnIDs(t *testing.T) { 56 t.Parallel() 57 undeleteTrx := _SetupSystemUndeleteTrx() 58 client, err := _NewMockClient() 59 client.SetLedgerID(*NewLedgerIDTestnet()) 60 require.NoError(t, err) 61 62 error := undeleteTrx.validateNetworkOnIDs(client) 63 require.NoError(t, error) 64 } 65 66 func TestUnitSystemUndeleteTrxBuild(t *testing.T) { 67 t.Parallel() 68 deleteTrx := _SetupSystemUndeleteTrx() 69 70 trxBody := deleteTrx.build() 71 require.NotNil(t, trxBody) 72 require.Equal(t, "memo", trxBody.Memo) 73 require.Equal(t, uint64(0), trxBody.TransactionFee) 74 require.Equal(t, int64(testTrxValidDuration.Seconds()), trxBody.TransactionValidDuration.Seconds) 75 } 76 77 func TestUnitSystemUndeleteTrxExecute(t *testing.T) { 78 t.Parallel() 79 client, err := _NewMockClient() 80 client.SetLedgerID(*NewLedgerIDTestnet()) 81 require.NoError(t, err) 82 client.SetAutoValidateChecksums(true) 83 require.NoError(t, err) 84 undeleteTrx := _SetupSystemUndeleteTrx() 85 86 contractId, _ := ContractIDFromString("0.0.123-esxsf") 87 undeleteTrx.SetContractID(contractId) 88 89 fileId, _ := FileIDFromString("0.0.123-esxsf") 90 undeleteTrx.SetFileID(fileId) 91 92 _, err = undeleteTrx.FreezeWith(client) 93 undeleteTrx.Sign(*client.operator.privateKey) 94 response, _ := undeleteTrx.Execute(client) 95 96 require.Equal(t, undeleteTrx.transactionID, response.TransactionID) 97 } 98 99 func TestUnitSystemConstructNewScheduleUndeleteTransactionProtobuf(t *testing.T) { 100 t.Parallel() 101 undeleteTrx := _SetupSystemUndeleteTrx() 102 103 protoBody, err := undeleteTrx.buildScheduled() 104 require.NoError(t, err) 105 require.NotNil(t, protoBody) 106 require.Equal(t, "memo", protoBody.Memo) 107 require.Equal(t, uint64(0), protoBody.TransactionFee) 108 } 109 110 func _CreateProtoBufUndeleteTrxBody() (Transaction, *services.TransactionBody) { 111 transaction := Transaction{transactionFee: 5, memo: "memo", defaultMaxTransactionFee: 10} 112 transactionBody := &services.TransactionBody{ 113 Data: &services.TransactionBody_SystemUndelete{SystemUndelete: &services.SystemUndeleteTransactionBody{}}} 114 115 return transaction, transactionBody 116 } 117 118 func _SetupSystemUndeleteTrx() *SystemUndeleteTransaction { 119 testAccountID := AccountID{Account: 3} 120 121 return NewSystemUndeleteTransaction(). 122 SetContractID(testContractId). 123 SetFileID(testFileId). 124 SetTransactionValidDuration(testTrxValidDuration). 125 SetTransactionMemo("memo"). 126 SetGrpcDeadline(&testTrxValidDuration). 127 SetNodeAccountIDs([]AccountID{testAccountID}) 128 }