github.com/hashgraph/hedera-sdk-go/v2@v2.48.0/file_info_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 "testing" 28 29 "github.com/stretchr/testify/assert" 30 31 "github.com/stretchr/testify/require" 32 ) 33 34 func TestIntegrationFileInfoQueryCanExecute(t *testing.T) { 35 t.Parallel() 36 env := NewIntegrationTestEnv(t) 37 38 resp, err := NewFileCreateTransaction(). 39 SetKeys(env.Client.GetOperatorPublicKey()). 40 SetNodeAccountIDs(env.NodeAccountIDs). 41 SetContents([]byte("Hello, World")). 42 SetTransactionMemo("go sdk e2e tests"). 43 Execute(env.Client) 44 45 require.NoError(t, err) 46 47 receipt, err := resp.SetValidateStatus(true).GetReceipt(env.Client) 48 require.NoError(t, err) 49 50 fileID := receipt.FileID 51 assert.NotNil(t, fileID) 52 53 info, err := NewFileInfoQuery(). 54 SetFileID(*fileID). 55 SetNodeAccountIDs([]AccountID{resp.NodeID}). 56 SetMaxQueryPayment(NewHbar(1)). 57 SetQueryPayment(HbarFromTinybar(25)). 58 Execute(env.Client) 59 require.NoError(t, err) 60 61 assert.Equal(t, *fileID, info.FileID) 62 assert.Equal(t, info.Size, int64(12)) 63 assert.False(t, info.IsDeleted) 64 assert.NotNil(t, info.Keys) 65 66 resp, err = NewFileDeleteTransaction(). 67 SetFileID(*fileID). 68 SetNodeAccountIDs([]AccountID{resp.NodeID}). 69 Execute(env.Client) 70 require.NoError(t, err) 71 72 _, err = resp.SetValidateStatus(true).GetReceipt(env.Client) 73 require.NoError(t, err) 74 75 err = CloseIntegrationTestEnv(env, nil) 76 require.NoError(t, err) 77 } 78 79 func TestIntegrationFileInfoQueryGetCost(t *testing.T) { 80 t.Parallel() 81 env := NewIntegrationTestEnv(t) 82 83 resp, err := NewFileCreateTransaction(). 84 SetKeys(env.Client.GetOperatorPublicKey()). 85 SetNodeAccountIDs(env.NodeAccountIDs). 86 SetContents([]byte("Hello, World")). 87 SetTransactionMemo("go sdk e2e tests"). 88 Execute(env.Client) 89 90 require.NoError(t, err) 91 92 receipt, err := resp.SetValidateStatus(true).GetReceipt(env.Client) 93 require.NoError(t, err) 94 95 fileID := receipt.FileID 96 assert.NotNil(t, fileID) 97 98 fileInfo := NewFileInfoQuery(). 99 SetFileID(*fileID). 100 SetMaxQueryPayment(NewHbar(1)). 101 SetNodeAccountIDs([]AccountID{resp.NodeID}) 102 103 cost, err := fileInfo.GetCost(env.Client) 104 require.NoError(t, err) 105 106 info, err := fileInfo.SetQueryPayment(cost).Execute(env.Client) 107 require.NoError(t, err) 108 109 assert.Equal(t, *fileID, info.FileID) 110 assert.Equal(t, info.Size, int64(12)) 111 assert.False(t, info.IsDeleted) 112 113 resp, err = NewFileDeleteTransaction(). 114 SetFileID(*fileID). 115 SetNodeAccountIDs([]AccountID{resp.NodeID}). 116 Execute(env.Client) 117 require.NoError(t, err) 118 119 _, err = resp.SetValidateStatus(true).GetReceipt(env.Client) 120 require.NoError(t, err) 121 122 err = CloseIntegrationTestEnv(env, nil) 123 require.NoError(t, err) 124 } 125 126 func TestIntegrationFileInfoQuerySetBigMaxPayment(t *testing.T) { 127 t.Parallel() 128 env := NewIntegrationTestEnv(t) 129 130 resp, err := NewFileCreateTransaction(). 131 SetKeys(env.Client.GetOperatorPublicKey()). 132 SetNodeAccountIDs(env.NodeAccountIDs). 133 SetContents([]byte("Hello, World")). 134 SetTransactionMemo("go sdk e2e tests"). 135 Execute(env.Client) 136 137 require.NoError(t, err) 138 139 receipt, err := resp.SetValidateStatus(true).GetReceipt(env.Client) 140 require.NoError(t, err) 141 142 fileID := receipt.FileID 143 assert.NotNil(t, fileID) 144 145 fileInfo := NewFileInfoQuery(). 146 SetFileID(*fileID). 147 SetMaxQueryPayment(NewHbar(10000)). 148 SetNodeAccountIDs([]AccountID{resp.NodeID}) 149 150 _, err = fileInfo.GetCost(env.Client) 151 require.NoError(t, err) 152 153 info, err := fileInfo.Execute(env.Client) 154 require.NoError(t, err) 155 156 assert.Equal(t, *fileID, info.FileID) 157 assert.Equal(t, info.Size, int64(12)) 158 assert.False(t, info.IsDeleted) 159 160 resp, err = NewFileDeleteTransaction(). 161 SetFileID(*fileID). 162 SetNodeAccountIDs([]AccountID{resp.NodeID}). 163 Execute(env.Client) 164 require.NoError(t, err) 165 166 _, err = resp.SetValidateStatus(true).GetReceipt(env.Client) 167 require.NoError(t, err) 168 169 err = CloseIntegrationTestEnv(env, nil) 170 require.NoError(t, err) 171 } 172 173 func TestIntegrationFileInfoQuerySetSmallMaxPayment(t *testing.T) { 174 t.Parallel() 175 env := NewIntegrationTestEnv(t) 176 177 resp, err := NewFileCreateTransaction(). 178 SetKeys(env.Client.GetOperatorPublicKey()). 179 SetNodeAccountIDs(env.NodeAccountIDs). 180 SetContents([]byte("Hello, World")). 181 SetTransactionMemo("go sdk e2e tests"). 182 Execute(env.Client) 183 184 require.NoError(t, err) 185 186 receipt, err := resp.SetValidateStatus(true).GetReceipt(env.Client) 187 require.NoError(t, err) 188 189 fileID := receipt.FileID 190 assert.NotNil(t, fileID) 191 192 fileInfo := NewFileInfoQuery(). 193 SetFileID(*fileID). 194 SetMaxQueryPayment(HbarFromTinybar(1)). 195 SetNodeAccountIDs([]AccountID{resp.NodeID}) 196 197 cost, err := fileInfo.GetCost(env.Client) 198 require.NoError(t, err) 199 200 _, err = fileInfo.Execute(env.Client) 201 assert.Error(t, err) 202 if err != nil { 203 assert.Equal(t, "cost of FileInfoQuery ("+cost.String()+") without explicit payment is greater than the max query payment of 1 tℏ", err.Error()) 204 } 205 206 resp, err = NewFileDeleteTransaction(). 207 SetFileID(*fileID). 208 SetNodeAccountIDs([]AccountID{resp.NodeID}). 209 Execute(env.Client) 210 require.NoError(t, err) 211 212 _, err = resp.SetValidateStatus(true).GetReceipt(env.Client) 213 require.NoError(t, err) 214 215 err = CloseIntegrationTestEnv(env, nil) 216 require.NoError(t, err) 217 } 218 219 func TestIntegrationFileInfoQueryInsufficientFee(t *testing.T) { 220 t.Parallel() 221 env := NewIntegrationTestEnv(t) 222 223 resp, err := NewFileCreateTransaction(). 224 SetKeys(env.Client.GetOperatorPublicKey()). 225 SetNodeAccountIDs(env.NodeAccountIDs). 226 SetContents([]byte("Hello, World")). 227 SetTransactionMemo("go sdk e2e tests"). 228 Execute(env.Client) 229 230 require.NoError(t, err) 231 232 receipt, err := resp.SetValidateStatus(true).GetReceipt(env.Client) 233 require.NoError(t, err) 234 235 fileID := receipt.FileID 236 assert.NotNil(t, fileID) 237 238 fileInfo := NewFileInfoQuery(). 239 SetFileID(*fileID). 240 SetMaxQueryPayment(NewHbar(1)). 241 SetNodeAccountIDs([]AccountID{resp.NodeID}) 242 243 _, err = fileInfo.GetCost(env.Client) 244 require.NoError(t, err) 245 246 _, err = fileInfo.SetQueryPayment(HbarFromTinybar(1)).Execute(env.Client) 247 if err != nil { 248 assert.Equal(t, "exceptional precheck status INSUFFICIENT_TX_FEE", err.Error()) 249 } 250 251 resp, err = NewFileDeleteTransaction(). 252 SetFileID(*fileID). 253 SetNodeAccountIDs([]AccountID{resp.NodeID}). 254 Execute(env.Client) 255 require.NoError(t, err) 256 257 _, err = resp.SetValidateStatus(true).GetReceipt(env.Client) 258 require.NoError(t, err) 259 260 err = CloseIntegrationTestEnv(env, nil) 261 require.NoError(t, err) 262 } 263 264 func TestIntegrationFileInfoQueryNoFileID(t *testing.T) { 265 t.Parallel() 266 env := NewIntegrationTestEnv(t) 267 268 _, err := NewFileInfoQuery(). 269 SetQueryPayment(NewHbar(1)). 270 SetNodeAccountIDs(env.NodeAccountIDs). 271 Execute(env.Client) 272 assert.Error(t, err) 273 if err != nil { 274 assert.Equal(t, "exceptional precheck status INVALID_FILE_ID", err.Error()) 275 } 276 277 err = CloseIntegrationTestEnv(env, nil) 278 require.NoError(t, err) 279 }