github.com/hashgraph/hedera-sdk-go/v2@v2.48.0/live_hash_query_e2e_test.go (about) 1 //go:build all || e2e 2 // +build all e2e 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 "encoding/hex" 28 "fmt" 29 "testing" 30 "time" 31 32 "github.com/stretchr/testify/assert" 33 34 "github.com/stretchr/testify/require" 35 ) 36 37 func TestIntegrationLiveHashQueryCanExecute(t *testing.T) { 38 t.Parallel() 39 env := NewIntegrationTestEnv(t) 40 41 _hash, _ := hex.DecodeString("100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002") 42 43 newKey, err := PrivateKeyGenerateEd25519() 44 require.NoError(t, err) 45 46 resp, err := NewAccountCreateTransaction(). 47 SetKey(newKey.PublicKey()). 48 SetNodeAccountIDs(env.NodeAccountIDs). 49 SetInitialBalance(NewHbar(1)). 50 Execute(env.Client) 51 require.NoError(t, err) 52 53 receipt, err := resp.SetValidateStatus(true).GetReceipt(env.Client) 54 require.NoError(t, err) 55 56 accountID := *receipt.AccountID 57 58 resp2, err := NewLiveHashAddTransaction(). 59 SetAccountID(accountID). 60 SetDuration(24 * 30 * time.Hour). 61 SetNodeAccountIDs([]AccountID{resp.NodeID}). 62 SetHash(_hash). 63 SetKeys(newKey.PublicKey()). 64 Execute(env.Client) 65 assert.Error(t, err) 66 if err != nil { 67 assert.Equal(t, fmt.Sprintf("exceptional precheck status NOT_SUPPORTED received for transaction %s", resp2.TransactionID), err.Error()) 68 } 69 70 _, err = NewLiveHashQuery(). 71 SetAccountID(accountID). 72 SetNodeAccountIDs([]AccountID{resp.NodeID}). 73 SetMaxQueryPayment(NewHbar(1)). 74 SetHash(_hash). 75 Execute(env.Client) 76 assert.Error(t, err) 77 if err != nil { 78 assert.Equal(t, "exceptional precheck status NOT_SUPPORTED", err.Error()) 79 } 80 81 resp2, err = NewLiveHashDeleteTransaction(). 82 SetAccountID(accountID). 83 SetNodeAccountIDs([]AccountID{resp.NodeID}). 84 SetHash(_hash). 85 Execute(env.Client) 86 assert.Error(t, err) 87 if err != nil { 88 assert.Equal(t, fmt.Sprintf("exceptional precheck status NOT_SUPPORTED received for transaction %s", resp2.TransactionID), err.Error()) 89 } 90 91 tx, err := NewAccountDeleteTransaction(). 92 SetAccountID(accountID). 93 SetNodeAccountIDs([]AccountID{resp.NodeID}). 94 SetTransferAccountID(env.Client.GetOperatorAccountID()). 95 FreezeWith(env.Client) 96 require.NoError(t, err) 97 98 resp, err = tx.Sign(newKey). 99 Execute(env.Client) 100 require.NoError(t, err) 101 102 _, err = resp.SetValidateStatus(true).GetReceipt(env.Client) 103 require.NoError(t, err) 104 105 err = CloseIntegrationTestEnv(env, nil) 106 require.NoError(t, err) 107 } 108 109 func TestIntegrationLiveHashQueryGetCost(t *testing.T) { 110 t.Parallel() 111 env := NewIntegrationTestEnv(t) 112 113 _hash, _ := hex.DecodeString("100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002") 114 115 newKey, err := PrivateKeyGenerateEd25519() 116 require.NoError(t, err) 117 118 resp, err := NewAccountCreateTransaction(). 119 SetKey(newKey.PublicKey()). 120 SetNodeAccountIDs(env.NodeAccountIDs). 121 SetInitialBalance(NewHbar(1)). 122 Execute(env.Client) 123 require.NoError(t, err) 124 125 receipt, err := resp.SetValidateStatus(true).GetReceipt(env.Client) 126 require.NoError(t, err) 127 128 accountID := *receipt.AccountID 129 130 resp2, err := NewLiveHashAddTransaction(). 131 SetAccountID(accountID). 132 SetDuration(24 * 30 * time.Hour). 133 SetNodeAccountIDs([]AccountID{resp.NodeID}). 134 SetHash(_hash). 135 SetKeys(newKey.PublicKey()). 136 Execute(env.Client) 137 assert.Error(t, err) 138 if err != nil { 139 assert.Equal(t, fmt.Sprintf("exceptional precheck status NOT_SUPPORTED received for transaction %s", resp2.TransactionID), err.Error()) 140 } 141 142 liveHashQ := NewLiveHashQuery(). 143 SetAccountID(accountID). 144 SetMaxQueryPayment(NewHbar(1)). 145 SetNodeAccountIDs([]AccountID{resp.NodeID}). 146 SetHash(_hash) 147 148 cost, err := liveHashQ.GetCost(env.Client) 149 assert.Error(t, err) 150 151 _, err = liveHashQ.SetQueryPayment(cost).Execute(env.Client) 152 assert.Error(t, err) 153 if err != nil { 154 assert.Equal(t, "exceptional precheck status NOT_SUPPORTED", err.Error()) 155 } 156 157 resp2, err = NewLiveHashDeleteTransaction(). 158 SetAccountID(accountID). 159 SetNodeAccountIDs([]AccountID{resp.NodeID}). 160 SetHash(_hash). 161 Execute(env.Client) 162 assert.Error(t, err) 163 if err != nil { 164 assert.Equal(t, fmt.Sprintf("exceptional precheck status NOT_SUPPORTED received for transaction %s", resp2.TransactionID), err.Error()) 165 } 166 167 tx, err := NewAccountDeleteTransaction(). 168 SetAccountID(accountID). 169 SetNodeAccountIDs([]AccountID{resp.NodeID}). 170 SetTransferAccountID(env.Client.GetOperatorAccountID()). 171 FreezeWith(env.Client) 172 require.NoError(t, err) 173 174 resp, err = tx.Sign(newKey). 175 Execute(env.Client) 176 require.NoError(t, err) 177 178 _, err = resp.SetValidateStatus(true).GetReceipt(env.Client) 179 require.NoError(t, err) 180 181 err = CloseIntegrationTestEnv(env, nil) 182 require.NoError(t, err) 183 }