forked from hiero-ledger/hiero-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 1
/
file_append_transaction_test.go
81 lines (59 loc) · 2.6 KB
/
file_append_transaction_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package hedera
import (
"github.com/stretchr/testify/assert"
"os"
"strings"
"testing"
)
func TestSerializeFileAppendTransaction(t *testing.T) {
mockClient, err := newMockClient()
assert.NoError(t, err)
privateKey, err := Ed25519PrivateKeyFromString(mockPrivateKey)
assert.NoError(t, err)
tx, err := NewFileAppendTransaction().
SetFileID(FileID{File: 5}).
SetContents([]byte("This is some random data")).
SetMaxTransactionFee(HbarFromTinybar(1e6)).
SetTransactionID(testTransactionID).
Build(mockClient)
assert.NoError(t, err)
tx.Sign(privateKey)
assert.Equal(t, `bodyBytes:"\n\016\n\010\010\334\311\007\020\333\237\t\022\002\030\003\022\002\030\003\030\300\204=\"\002\010x\202\001\036\022\002\030\005\"\030Thisissomerandomdata"sigMap:<sigPair:<pubKeyPrefix:"\344\361\300\353L}\315\303\347\353\021p\263\010\212=\022\242\227\364\243\353\342\362\205\003\375g5F\355\216"ed25519:"\211Q\013\365\342\\\257B\255\370\347t\234`+"`"+`)\271\017\\\273\266\367\347\214\256]D\2004\220kC$:\252\245\227\257\351\365\344\236\244\032\336@\263a\353\001\276\257\300)x\254\021\032\217\223DF\316\016\004">>transactionID:<transactionValidStart:<seconds:124124nanos:151515>accountID:<accountNum:3>>nodeAccountID:<accountNum:3>transactionFee:1000000transactionValidDuration:<seconds:120>fileAppend:<fileID:<fileNum:5>contents:"Thisissomerandomdata">`, strings.ReplaceAll(strings.ReplaceAll(tx.String(), " ", ""), "\n", ""))
}
func TestFileAppendTransaction_Execute(t *testing.T) {
operatorAccountID, err := AccountIDFromString(os.Getenv("OPERATOR_ID"))
assert.NoError(t, err)
operatorPrivateKey, err := Ed25519PrivateKeyFromString(os.Getenv("OPERATOR_KEY"))
assert.NoError(t, err)
client := ClientForTestnet().
SetOperator(operatorAccountID, operatorPrivateKey).
SetMaxTransactionFee(NewHbar(2))
txID, err := NewFileCreateTransaction().
AddKey(operatorPrivateKey.PublicKey()).
SetContents([]byte("Hello")).
SetTransactionMemo("go sdk e2e tests").
Execute(client)
assert.NoError(t, err)
receipt, err := txID.GetReceipt(client)
assert.NoError(t, err)
fileID := receipt.fileID
assert.NotNil(t, fileID)
txID, err = NewFileAppendTransaction().
SetFileID(*fileID).
SetContents([]byte(" world!")).
Execute(client)
assert.NoError(t, err)
_, err = txID.GetReceipt(client)
assert.NoError(t, err)
contents, err := NewFileContentsQuery().
SetFileID(*fileID).
Execute(client)
assert.NoError(t, err)
assert.Equal(t, []byte("Hello world!"), contents)
txID, err = NewFileDeleteTransaction().
SetFileID(*fileID).
Execute(client)
assert.NoError(t, err)
_, err = txID.GetReceipt(client)
assert.NoError(t, err)
}