forked from hashgraph/hedera-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 1
/
file_update_transaction_test.go
84 lines (63 loc) · 2.99 KB
/
file_update_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
82
83
84
package hedera
import (
"github.com/stretchr/testify/assert"
"os"
"strings"
"testing"
"time"
)
func TestSerializeFileUpdateTransaction(t *testing.T) {
mockClient, err := newMockClient()
assert.NoError(t, err)
privateKey, err := Ed25519PrivateKeyFromString(mockPrivateKey)
assert.NoError(t, err)
tx, err := NewFileUpdateTransaction().
SetFileID(FileID{File: 5}).
SetContents([]byte("there was a hole here")).
SetExpirationTime(time.Unix(15415151511, 0)).
AddKey(privateKey.PublicKey()).
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\232\001I\n\002\030\005\022\006\010\227\227\302\2669\032$\n\"\022\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\"\025therewasaholehere"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:"\243.\202\276AZ\273i4\342\262a+:\231a\350;\326%\016\304\314\271b\205\261\316l\214bot\304+5\241\034N\r\361\340\031\360OZ\356\0149\2321\037\377\232\3515\324o\303\316\243\237\017">>transactionID:<transactionValidStart:<seconds:124124nanos:151515>accountID:<accountNum:3>>nodeAccountID:<accountNum:3>transactionFee:1000000transactionValidDuration:<seconds:120>fileUpdate:<fileID:<fileNum:5>expirationTime:<seconds:15415151511>keys:<keys:<ed25519:"\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">>contents:"therewasaholehere">`, strings.ReplaceAll(strings.ReplaceAll(tx.String(), " ", ""), "\n", ""))
}
func TestFileUpdateTransaction_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, World")).
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)
var new_contents = []byte("Good Night, World")
txID, err = NewFileUpdateTransaction().
SetFileID(*fileID).
SetContents(new_contents).
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, new_contents, contents)
txID, err = NewFileDeleteTransaction().
SetFileID(*fileID).
Execute(client)
assert.NoError(t, err)
_, err = txID.GetReceipt(client)
assert.NoError(t, err)
}