github.com/hashgraph/hedera-sdk-go/v2@v2.48.0/system_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 ) 33 34 var testContractId = ContractID{Contract: 5} 35 var testExpirationTime = time.Now().Add(24 * time.Hour) 36 var testFileId = FileID{File: 3} 37 var testTrxValidDuration = 24 * time.Hour 38 39 func TestUnitSystemDeleteTransactionFromProtobuf(t *testing.T) { 40 t.Parallel() 41 42 trx, trxBody := _CreateProtoBufTrxBody() 43 sysDeleteTrx := _SystemDeleteTransactionFromProtobuf(trx, trxBody) 44 require.NotNil(t, sysDeleteTrx) 45 require.Equal(t, "memo", sysDeleteTrx.memo) 46 require.Equal(t, uint64(5), sysDeleteTrx.transactionFee) 47 require.Equal(t, uint64(10), sysDeleteTrx.defaultMaxTransactionFee) 48 } 49 50 func TestUnitSystemDeleteTrxGettersAndSetters(t *testing.T) { 51 t.Parallel() 52 deleteTrx := _SetupSystemDeleteTrx() 53 54 require.Equal(t, testContractId, deleteTrx.GetContractID()) 55 require.Equal(t, testExpirationTime.Unix(), deleteTrx.GetExpirationTime()) 56 require.Equal(t, testFileId, deleteTrx.GetFileID()) 57 require.Equal(t, testTrxValidDuration, deleteTrx.GetTransactionValidDuration()) 58 } 59 60 func TestUnitSystemDeleteTrxValidateNetworkOnIDs(t *testing.T) { 61 t.Parallel() 62 deleteTrx := _SetupSystemDeleteTrx() 63 client, err := _NewMockClient() 64 client.SetLedgerID(*NewLedgerIDTestnet()) 65 require.NoError(t, err) 66 67 error := deleteTrx.validateNetworkOnIDs(client) 68 require.NoError(t, error) 69 } 70 71 func TestUnitSystemDeleteTrxBuild(t *testing.T) { 72 t.Parallel() 73 deleteTrx := _SetupSystemDeleteTrx() 74 75 trxBody := deleteTrx.build() 76 77 require.NotNil(t, trxBody) 78 require.Equal(t, "memo", trxBody.Memo) 79 require.Equal(t, uint64(0), trxBody.TransactionFee) 80 require.Equal(t, int64(testTrxValidDuration.Seconds()), trxBody.TransactionValidDuration.Seconds) 81 } 82 83 func TestUnitSystemDeleteTrxExecute(t *testing.T) { 84 t.Parallel() 85 client, err := _NewMockClient() 86 client.SetLedgerID(*NewLedgerIDTestnet()) 87 require.NoError(t, err) 88 client.SetAutoValidateChecksums(true) 89 require.NoError(t, err) 90 deleteTrx := _SetupSystemDeleteTrx() 91 92 contractId, _ := ContractIDFromString("0.0.123-esxsf") 93 deleteTrx.SetContractID(contractId) 94 95 fileId, _ := FileIDFromString("0.0.123-esxsf") 96 deleteTrx.SetFileID(fileId) 97 98 _, err = deleteTrx.FreezeWith(client) 99 100 deleteTrx.Sign(*client.operator.privateKey) 101 response, _ := deleteTrx.Execute(client) 102 require.Equal(t, deleteTrx.transactionID, response.TransactionID) 103 104 } 105 106 func TestUnitSystemConstructNewScheduleDeleteTransactionProtobuf(t *testing.T) { 107 t.Parallel() 108 deleteTrx := _SetupSystemUndeleteTrx() 109 110 protoBody, err := deleteTrx.buildScheduled() 111 require.NoError(t, err) 112 require.NotNil(t, protoBody) 113 require.Equal(t, "memo", protoBody.Memo) 114 require.Equal(t, uint64(0), protoBody.TransactionFee) 115 } 116 117 func _CreateProtoBufTrxBody() (Transaction, *services.TransactionBody) { 118 transaction := Transaction{transactionFee: 5, memo: "memo", defaultMaxTransactionFee: 10} 119 transactionBody := &services.TransactionBody{ 120 Data: &services.TransactionBody_SystemDelete{SystemDelete: &services.SystemDeleteTransactionBody{ExpirationTime: &services.TimestampSeconds{Seconds: 100}}}} 121 122 return transaction, transactionBody 123 } 124 125 func _SetupSystemDeleteTrx() *SystemDeleteTransaction { 126 127 return NewSystemDeleteTransaction(). 128 SetContractID(testContractId). 129 SetExpirationTime(testExpirationTime). 130 SetFileID(testFileId). 131 SetTransactionValidDuration(testTrxValidDuration). 132 SetTransactionMemo("memo") 133 }