@@ -23,15 +23,41 @@ func TestWithRunActionsCtx(t *testing.T) {
23
23
require := require .New (t )
24
24
addr , err := address .FromString ("io1mflp9m6hcgm2qcghchsdqj3z3eccrnekx9p0ms" )
25
25
require .NoError (err )
26
- actionCtx := RunActionsCtx {1 , time .Now (), 1 , config .Default .Genesis , addr , addr , hash .ZeroHash256 , nil , 0 , 0 , false , nil }
26
+ actionCtx := RunActionsCtx {
27
+ BlockHeight : 1111 ,
28
+ BlockTimeStamp : time .Now (),
29
+ GasLimit : 1 ,
30
+ Genesis : config .Default .Genesis ,
31
+ Producer : addr ,
32
+ Caller : addr ,
33
+ ActionHash : hash .ZeroHash256 ,
34
+ GasPrice : nil ,
35
+ IntrinsicGas : 0 ,
36
+ Nonce : 0 ,
37
+ History : false ,
38
+ Registry : nil ,
39
+ }
27
40
require .NotNil (WithRunActionsCtx (context .Background (), actionCtx ))
28
41
}
29
42
30
43
func TestGetRunActionsCtx (t * testing.T ) {
31
44
require := require .New (t )
32
45
addr , err := address .FromString ("io1mflp9m6hcgm2qcghchsdqj3z3eccrnekx9p0ms" )
33
46
require .NoError (err )
34
- actionCtx := RunActionsCtx {1111 , time .Now (), 1 , config .Default .Genesis , addr , addr , hash .ZeroHash256 , nil , 0 , 0 , false , nil }
47
+ actionCtx := RunActionsCtx {
48
+ BlockHeight : 1111 ,
49
+ BlockTimeStamp : time .Now (),
50
+ GasLimit : 1 ,
51
+ Genesis : config .Default .Genesis ,
52
+ Producer : addr ,
53
+ Caller : addr ,
54
+ ActionHash : hash .ZeroHash256 ,
55
+ GasPrice : nil ,
56
+ IntrinsicGas : 0 ,
57
+ Nonce : 0 ,
58
+ History : false ,
59
+ Registry : nil ,
60
+ }
35
61
ctx := WithRunActionsCtx (context .Background (), actionCtx )
36
62
require .NotNil (ctx )
37
63
ret , ok := GetRunActionsCtx (ctx )
@@ -43,7 +69,20 @@ func TestMustGetRunActionsCtx(t *testing.T) {
43
69
require := require .New (t )
44
70
addr , err := address .FromString ("io1mflp9m6hcgm2qcghchsdqj3z3eccrnekx9p0ms" )
45
71
require .NoError (err )
46
- actionCtx := RunActionsCtx {1111 , time .Now (), 1 , config .Default .Genesis , addr , addr , hash .ZeroHash256 , nil , 0 , 0 , false , nil }
72
+ actionCtx := RunActionsCtx {
73
+ BlockHeight : 1111 ,
74
+ BlockTimeStamp : time .Now (),
75
+ GasLimit : 1 ,
76
+ Genesis : config .Default .Genesis ,
77
+ Producer : addr ,
78
+ Caller : addr ,
79
+ ActionHash : hash .ZeroHash256 ,
80
+ GasPrice : nil ,
81
+ IntrinsicGas : 0 ,
82
+ Nonce : 0 ,
83
+ History : false ,
84
+ Registry : nil ,
85
+ }
47
86
ctx := WithRunActionsCtx (context .Background (), actionCtx )
48
87
require .NotNil (ctx )
49
88
// Case I: Normal
@@ -57,14 +96,24 @@ func TestWithValidateActionsCtx(t *testing.T) {
57
96
require := require .New (t )
58
97
addr , err := address .FromString ("io1mflp9m6hcgm2qcghchsdqj3z3eccrnekx9p0ms" )
59
98
require .NoError (err )
60
- validateCtx := ValidateActionsCtx {1 , "io1mflp9m6hcgm2qcghchsdqj3z3eccrnekx9p0ms" , addr , config .Default .Genesis }
99
+ validateCtx := ValidateActionsCtx {
100
+ BlockHeight : 1 ,
101
+ ProducerAddr : "io1mflp9m6hcgm2qcghchsdqj3z3eccrnekx9p0ms" ,
102
+ Caller : addr ,
103
+ Genesis : config .Default .Genesis ,
104
+ }
61
105
require .NotNil (WithValidateActionsCtx (context .Background (), validateCtx ))
62
106
}
63
107
func TestGetValidateActionsCtx (t * testing.T ) {
64
108
require := require .New (t )
65
109
addr , err := address .FromString ("io1mflp9m6hcgm2qcghchsdqj3z3eccrnekx9p0ms" )
66
110
require .NoError (err )
67
- validateCtx := ValidateActionsCtx {1111 , "io1mflp9m6hcgm2qcghchsdqj3z3eccrnekx9p0ms" , addr , config .Default .Genesis }
111
+ validateCtx := ValidateActionsCtx {
112
+ BlockHeight : 1111 ,
113
+ ProducerAddr : "io1mflp9m6hcgm2qcghchsdqj3z3eccrnekx9p0ms" ,
114
+ Caller : addr ,
115
+ Genesis : config .Default .Genesis ,
116
+ }
68
117
ctx := WithValidateActionsCtx (context .Background (), validateCtx )
69
118
require .NotNil (ctx )
70
119
ret , ok := GetValidateActionsCtx (ctx )
@@ -75,12 +124,158 @@ func TestMustGetValidateActionsCtx(t *testing.T) {
75
124
require := require .New (t )
76
125
addr , err := address .FromString ("io1mflp9m6hcgm2qcghchsdqj3z3eccrnekx9p0ms" )
77
126
require .NoError (err )
78
- validateCtx := ValidateActionsCtx {1111 , "io1mflp9m6hcgm2qcghchsdqj3z3eccrnekx9p0ms" , addr , config .Default .Genesis }
127
+ validateCtx := ValidateActionsCtx {
128
+ BlockHeight : 1111 ,
129
+ ProducerAddr : "io1mflp9m6hcgm2qcghchsdqj3z3eccrnekx9p0ms" ,
130
+ Caller : addr ,
131
+ Genesis : config .Default .Genesis ,
132
+ }
79
133
ctx := WithValidateActionsCtx (context .Background (), validateCtx )
80
134
require .NotNil (ctx )
81
135
// Case I: Normal
82
136
ret := MustGetValidateActionsCtx (ctx )
83
137
require .Equal (uint64 (1111 ), ret .BlockHeight )
84
138
// Case II: Panic
85
- require .Panics (func () { MustGetValidateActionsCtx (context .Background ()) }, "Miss run actions context" )
139
+ require .Panics (func () { MustGetValidateActionsCtx (context .Background ()) }, "Miss validate action context" )
140
+ }
141
+
142
+ func TestWithBlockchainCtx (t * testing.T ) {
143
+ require := require .New (t )
144
+ bcCtx := BlockchainCtx {
145
+ Genesis : config .Default .Genesis ,
146
+ History : false ,
147
+ Registry : nil ,
148
+ }
149
+ require .NotNil (WithBlockchainCtx (context .Background (), bcCtx ))
150
+ }
151
+
152
+ func TestGetBlockchainCtx (t * testing.T ) {
153
+ require := require .New (t )
154
+ bcCtx := BlockchainCtx {
155
+ Genesis : config .Default .Genesis ,
156
+ History : false ,
157
+ Registry : nil ,
158
+ }
159
+ ctx := WithBlockchainCtx (context .Background (), bcCtx )
160
+ require .NotNil (ctx )
161
+ ret , ok := GetBlockchainCtx (ctx )
162
+ require .True (ok )
163
+ require .Equal (false , ret .History )
164
+ }
165
+
166
+ func TestMustGetBlockchainCtx (t * testing.T ) {
167
+ require := require .New (t )
168
+ bcCtx := BlockchainCtx {
169
+ Genesis : config .Default .Genesis ,
170
+ History : false ,
171
+ Registry : nil ,
172
+ }
173
+ ctx := WithBlockchainCtx (context .Background (), bcCtx )
174
+ require .NotNil (ctx )
175
+ // Case I: Normal
176
+ ret := MustGetBlockchainCtx (ctx )
177
+ require .Equal (false , ret .History )
178
+ // Case II: Panic
179
+ require .Panics (func () { MustGetBlockchainCtx (context .Background ()) }, "Miss blockchain context" )
180
+ }
181
+
182
+ func TestWithBlockCtx (t * testing.T ) {
183
+ require := require .New (t )
184
+ addr , err := address .FromString ("io1mflp9m6hcgm2qcghchsdqj3z3eccrnekx9p0ms" )
185
+ require .NoError (err )
186
+ blkCtx := BlockCtx {
187
+ BlockHeight : 1111 ,
188
+ BlockTimeStamp : time .Now (),
189
+ GasLimit : 1 ,
190
+ Producer : addr ,
191
+ }
192
+ require .NotNil (WithBlockCtx (context .Background (), blkCtx ))
193
+ }
194
+
195
+ func TestGetBlockCtx (t * testing.T ) {
196
+ require := require .New (t )
197
+ addr , err := address .FromString ("io1mflp9m6hcgm2qcghchsdqj3z3eccrnekx9p0ms" )
198
+ require .NoError (err )
199
+ blkCtx := BlockCtx {
200
+ BlockHeight : 1111 ,
201
+ BlockTimeStamp : time .Now (),
202
+ GasLimit : 1 ,
203
+ Producer : addr ,
204
+ }
205
+ ctx := WithBlockCtx (context .Background (), blkCtx )
206
+ require .NotNil (ctx )
207
+ ret , ok := GetBlockCtx (ctx )
208
+ require .True (ok )
209
+ require .Equal (uint64 (1111 ), ret .BlockHeight )
210
+ }
211
+
212
+ func TestMustGetBlockCtx (t * testing.T ) {
213
+ require := require .New (t )
214
+ addr , err := address .FromString ("io1mflp9m6hcgm2qcghchsdqj3z3eccrnekx9p0ms" )
215
+ require .NoError (err )
216
+ blkCtx := BlockCtx {
217
+ BlockHeight : 1111 ,
218
+ BlockTimeStamp : time .Now (),
219
+ GasLimit : 1 ,
220
+ Producer : addr ,
221
+ }
222
+ ctx := WithBlockCtx (context .Background (), blkCtx )
223
+ require .NotNil (ctx )
224
+ // Case I: Normal
225
+ ret := MustGetBlockCtx (ctx )
226
+ require .Equal (uint64 (1111 ), ret .BlockHeight )
227
+ // Case II: Panic
228
+ require .Panics (func () { MustGetBlockCtx (context .Background ()) }, "Miss block context" )
229
+ }
230
+
231
+ func TestWithActionCtx (t * testing.T ) {
232
+ require := require .New (t )
233
+ addr , err := address .FromString ("io1mflp9m6hcgm2qcghchsdqj3z3eccrnekx9p0ms" )
234
+ require .NoError (err )
235
+ actionCtx := ActionCtx {
236
+ Caller : addr ,
237
+ ActionHash : hash .ZeroHash256 ,
238
+ GasPrice : nil ,
239
+ IntrinsicGas : 0 ,
240
+ Nonce : 0 ,
241
+ }
242
+ require .NotNil (WithActionCtx (context .Background (), actionCtx ))
243
+ }
244
+
245
+ func TestGetActionCtx (t * testing.T ) {
246
+ require := require .New (t )
247
+ addr , err := address .FromString ("io1mflp9m6hcgm2qcghchsdqj3z3eccrnekx9p0ms" )
248
+ require .NoError (err )
249
+ actionCtx := ActionCtx {
250
+ Caller : addr ,
251
+ ActionHash : hash .ZeroHash256 ,
252
+ GasPrice : nil ,
253
+ IntrinsicGas : 0 ,
254
+ Nonce : 0 ,
255
+ }
256
+ ctx := WithActionCtx (context .Background (), actionCtx )
257
+ require .NotNil (ctx )
258
+ ret , ok := GetActionCtx (ctx )
259
+ require .True (ok )
260
+ require .Equal (hash .ZeroHash256 , ret .ActionHash )
261
+ }
262
+
263
+ func TestMustGetActionCtx (t * testing.T ) {
264
+ require := require .New (t )
265
+ addr , err := address .FromString ("io1mflp9m6hcgm2qcghchsdqj3z3eccrnekx9p0ms" )
266
+ require .NoError (err )
267
+ actionCtx := ActionCtx {
268
+ Caller : addr ,
269
+ ActionHash : hash .ZeroHash256 ,
270
+ GasPrice : nil ,
271
+ IntrinsicGas : 0 ,
272
+ Nonce : 0 ,
273
+ }
274
+ ctx := WithActionCtx (context .Background (), actionCtx )
275
+ require .NotNil (ctx )
276
+ // Case I: Normal
277
+ ret := MustGetActionCtx (ctx )
278
+ require .Equal (hash .ZeroHash256 , ret .ActionHash )
279
+ // Case II: Panic
280
+ require .Panics (func () { MustGetActionCtx (context .Background ()) }, "Miss action context" )
86
281
}
0 commit comments