github.com/hashgraph/hedera-sdk-go/v2@v2.48.0/file_create_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 TestIntegrationFileCreateTransactionCanExecute(t *testing.T) { 35 t.Parallel() 36 env := NewIntegrationTestEnv(t) 37 resp, err := NewFileCreateTransaction(). 38 SetKeys(env.Client.GetOperatorPublicKey()). 39 SetNodeAccountIDs(env.NodeAccountIDs). 40 SetContents([]byte("Hello, World")). 41 SetTransactionMemo("go sdk e2e tests"). 42 Execute(env.Client) 43 44 require.NoError(t, err) 45 46 receipt, err := resp.SetValidateStatus(true).GetReceipt(env.Client) 47 require.NoError(t, err) 48 49 fileID := *receipt.FileID 50 assert.NotNil(t, fileID) 51 52 resp, err = NewFileDeleteTransaction(). 53 SetFileID(fileID). 54 SetNodeAccountIDs([]AccountID{resp.NodeID}). 55 Execute(env.Client) 56 require.NoError(t, err) 57 58 _, err = resp.SetValidateStatus(true).GetReceipt(env.Client) 59 require.NoError(t, err) 60 61 err = CloseIntegrationTestEnv(env, nil) 62 require.NoError(t, err) 63 } 64 65 func TestIntegrationFileCreateTransactionNoKey(t *testing.T) { 66 t.Parallel() 67 env := NewIntegrationTestEnv(t) 68 69 resp, err := NewFileCreateTransaction(). 70 SetNodeAccountIDs(env.NodeAccountIDs). 71 Execute(env.Client) 72 require.NoError(t, err) 73 74 receipt, err := resp.SetValidateStatus(true).GetReceipt(env.Client) 75 require.NoError(t, err) 76 77 fileID := *receipt.FileID 78 assert.NotNil(t, fileID) 79 80 resp, err = NewFileDeleteTransaction(). 81 SetFileID(fileID). 82 SetNodeAccountIDs([]AccountID{resp.NodeID}). 83 Execute(env.Client) 84 require.NoError(t, err) 85 86 _, err = resp.SetValidateStatus(true).GetReceipt(env.Client) 87 assert.Error(t, err) 88 if err != nil { 89 assert.Equal(t, "exceptional receipt status: UNAUTHORIZED", err.Error()) 90 } 91 92 err = CloseIntegrationTestEnv(env, nil) 93 require.NoError(t, err) 94 }