github.com/hashgraph/hedera-sdk-go/v2@v2.48.0/file_update_transaction_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 TestIntegrationFileUpdateTransactionCanExecute(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 var newContents = []byte("Good Night, World") 54 55 resp, err = NewFileUpdateTransaction(). 56 SetFileID(fileID). 57 SetNodeAccountIDs([]AccountID{resp.NodeID}). 58 SetContents(newContents). 59 Execute(env.Client) 60 61 require.NoError(t, err) 62 63 _, err = resp.SetValidateStatus(true).GetReceipt(env.Client) 64 require.NoError(t, err) 65 66 contents, err := NewFileContentsQuery(). 67 SetFileID(fileID). 68 SetNodeAccountIDs([]AccountID{resp.NodeID}). 69 Execute(env.Client) 70 require.NoError(t, err) 71 72 assert.Equal(t, newContents, contents) 73 74 resp, err = NewFileDeleteTransaction(). 75 SetFileID(fileID). 76 SetNodeAccountIDs([]AccountID{resp.NodeID}). 77 Execute(env.Client) 78 require.NoError(t, err) 79 80 _, err = resp.SetValidateStatus(true).GetReceipt(env.Client) 81 require.NoError(t, err) 82 83 err = CloseIntegrationTestEnv(env, nil) 84 require.NoError(t, err) 85 } 86 87 func TestIntegrationFileUpdateTransactionNoFileID(t *testing.T) { 88 t.Parallel() 89 env := NewIntegrationTestEnv(t) 90 91 resp, err := NewFileCreateTransaction(). 92 SetKeys(env.Client.GetOperatorPublicKey()). 93 SetNodeAccountIDs(env.NodeAccountIDs). 94 SetContents([]byte("Hello, World")). 95 SetTransactionMemo("go sdk e2e tests"). 96 Execute(env.Client) 97 98 require.NoError(t, err) 99 100 receipt, err := resp.SetValidateStatus(true).GetReceipt(env.Client) 101 require.NoError(t, err) 102 103 fileID := *receipt.FileID 104 assert.NotNil(t, fileID) 105 106 _, err = NewFileUpdateTransaction(). 107 SetNodeAccountIDs([]AccountID{resp.NodeID}). 108 Execute(env.Client) 109 if err != nil { 110 assert.Contains(t, err.Error(), "exceptional precheck status INVALID_FILE_ID") 111 } 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 err = CloseIntegrationTestEnv(env, nil) 122 require.NoError(t, err) 123 }