@@ -8,20 +8,24 @@ import (
8
8
)
9
9
10
10
func RunTransactionOptions () {
11
- runAppId ()
12
- runNonce ()
11
+ RunTransactionOptionsAppId ()
12
+ RunTransactionOptionsNonce ()
13
+ RunTransactionOptionsMortality ()
14
+ RunTransactionOptionsTip ()
13
15
14
16
fmt .Println ("RunTransactionOptions finished correctly." )
15
17
}
16
18
17
- func runAppId () {
19
+ func RunTransactionOptionsAppId () {
18
20
sdk , err := SDK .NewSDK (SDK .LocalEndpoint )
19
21
PanicOnError (err )
20
22
21
- // Setting AppId and Executing Transaction
23
+ // Setting AppId
22
24
appId := uint32 (5 )
23
- tx := sdk .Tx .DataAvailability .SubmitData ([]byte ("Hello World" ))
24
25
options := SDK .NewTransactionOptions ().WithAppId (appId )
26
+
27
+ // Executing Transaction
28
+ tx := sdk .Tx .DataAvailability .SubmitData ([]byte ("Hello World" ))
25
29
res , err := tx .ExecuteAndWatchInclusion (SDK .Account .Alice (), options )
26
30
PanicOnError (err )
27
31
@@ -34,9 +38,11 @@ func runAppId() {
34
38
genTx := block .TransactionByHash (res .TxHash ).UnsafeUnwrap ()
35
39
foundAppId := genTx .Signed ().UnsafeUnwrap ().AppId
36
40
AssertEq (appId , foundAppId , "App Ids are not the same" )
41
+
42
+ fmt .Println ("RunTransactionOptionsAppId finished correctly." )
37
43
}
38
44
39
- func runNonce () {
45
+ func RunTransactionOptionsNonce () {
40
46
sdk , err := SDK .NewSDK (SDK .LocalEndpoint )
41
47
PanicOnError (err )
42
48
@@ -64,4 +70,56 @@ func runNonce() {
64
70
newNonce , err := SDK .Account .Nonce (sdk .Client , metadata .NewAccountIdFromKeyPair (acc ))
65
71
PanicOnError (err )
66
72
AssertEq (newNonce , currentNonce + 1 , "New nonce and old nonce + 1 are not the same." )
73
+
74
+ fmt .Println ("RunTransactionOptionsNonce finished correctly." )
75
+ }
76
+
77
+ func RunTransactionOptionsMortality () {
78
+ sdk , err := SDK .NewSDK (SDK .LocalEndpoint )
79
+ PanicOnError (err )
80
+
81
+ // Setting Mortality
82
+ mortality := uint32 (16 )
83
+ options := SDK .NewTransactionOptions ().WithMortality (mortality ).WithAppId (1 )
84
+
85
+ // Executing Transaction
86
+ tx := sdk .Tx .DataAvailability .SubmitData ([]byte ("Hello World" ))
87
+ res , err := tx .ExecuteAndWatchInclusion (SDK .Account .Alice (), options )
88
+ PanicOnError (err )
89
+ AssertTrue (res .IsSuccessful ().Unwrap (), "Transaction is supposed to succeed" )
90
+
91
+ block , err := SDK .NewBlock (sdk .Client , res .BlockHash )
92
+ PanicOnError (err )
93
+
94
+ // Checking if the Mortality is the same as the one expected
95
+ genTx := block .TransactionByHash (res .TxHash ).UnsafeUnwrap ()
96
+ actualMortality := uint32 (genTx .Signed ().UnsafeUnwrap ().Era .Period )
97
+ AssertEq (actualMortality , mortality , "Moartalities are not the same." )
98
+
99
+ fmt .Println ("RunTransactionOptionsMortality finished correctly." )
100
+ }
101
+
102
+ func RunTransactionOptionsTip () {
103
+ sdk , err := SDK .NewSDK (SDK .LocalEndpoint )
104
+ PanicOnError (err )
105
+
106
+ // Setting Tip
107
+ tip := SDK .OneAvail ()
108
+ options := SDK .NewTransactionOptions ().WithTip (tip ).WithAppId (1 )
109
+
110
+ // Executing Transaction
111
+ tx := sdk .Tx .DataAvailability .SubmitData ([]byte ("Hello World" ))
112
+ res , err := tx .ExecuteAndWatchInclusion (SDK .Account .Alice (), options )
113
+ PanicOnError (err )
114
+ AssertTrue (res .IsSuccessful ().Unwrap (), "Transaction is supposed to succeed" )
115
+
116
+ block , err := SDK .NewBlock (sdk .Client , res .BlockHash )
117
+ PanicOnError (err )
118
+
119
+ // Checking if the Tip is the same as the one expected
120
+ genTx := block .TransactionByHash (res .TxHash ).UnsafeUnwrap ()
121
+ actualTip := genTx .Signed ().UnsafeUnwrap ().Tip
122
+ AssertEq (metadata.Balance {Value : actualTip }, tip , "Tips are not the same." )
123
+
124
+ fmt .Println ("RunTransactionOptionsTip finished correctly." )
67
125
}
0 commit comments