@@ -25,23 +25,28 @@ import (
25
25
"github.com/stretchr/testify/require"
26
26
)
27
27
28
- func TestActionTypes (t * testing.T ) {
28
+ func TestInnerTypesV5 (t * testing.T ) {
29
+ v5 , _ := makeSampleEnvWithVersion (5 )
30
+ // not alllowed in v5
31
+ testApp (t , "itxn_begin; byte \" keyreg\" ; itxn_field Type; itxn_submit; int 1;" , v5 , "keyreg is not a valid Type for itxn_field" )
32
+ testApp (t , "itxn_begin; int keyreg; itxn_field TypeEnum; itxn_submit; int 1;" , v5 , "keyreg is not a valid Type for itxn_field" )
33
+ }
34
+
35
+ func TestCurrentInnerTypes (t * testing.T ) {
29
36
ep , ledger := makeSampleEnv ()
30
37
testApp (t , "itxn_submit; int 1;" , ep , "itxn_submit without itxn_begin" )
31
38
testApp (t , "int pay; itxn_field TypeEnum; itxn_submit; int 1;" , ep , "itxn_field without itxn_begin" )
32
- testApp (t , "itxn_begin; itxn_submit; int 1;" , ep , "Invalid inner transaction type" )
39
+ testApp (t , "itxn_begin; itxn_submit; int 1;" , ep , "unknown tx type" )
33
40
// bad type
34
41
testApp (t , "itxn_begin; byte \" pya\" ; itxn_field Type; itxn_submit; int 1;" , ep , "pya is not a valid Type" )
35
42
// mixed up the int form for the byte form
36
43
testApp (t , obfuscate ("itxn_begin; int pay; itxn_field Type; itxn_submit; int 1;" ), ep , "Type arg not a byte array" )
37
44
// or vice versa
38
45
testApp (t , obfuscate ("itxn_begin; byte \" pay\" ; itxn_field TypeEnum; itxn_submit; int 1;" ), ep , "not a uint64" )
39
46
40
- // good types, not alllowed yet
41
- testApp (t , "itxn_begin; byte \" keyreg\" ; itxn_field Type; itxn_submit; int 1;" , ep , "keyreg is not a valid Type for itxn_field" )
47
+ // good types, not allowed yet
42
48
testApp (t , "itxn_begin; byte \" appl\" ; itxn_field Type; itxn_submit; int 1;" , ep , "appl is not a valid Type for itxn_field" )
43
49
// same, as enums
44
- testApp (t , "itxn_begin; int keyreg; itxn_field TypeEnum; itxn_submit; int 1;" , ep , "keyreg is not a valid Type for itxn_field" )
45
50
testApp (t , "itxn_begin; int appl; itxn_field TypeEnum; itxn_submit; int 1;" , ep , "appl is not a valid Type for itxn_field" )
46
51
testApp (t , "itxn_begin; int 42; itxn_field TypeEnum; itxn_submit; int 1;" , ep , "42 is not a valid TypeEnum" )
47
52
testApp (t , "itxn_begin; int 0; itxn_field TypeEnum; itxn_submit; int 1;" , ep , "0 is not a valid TypeEnum" )
@@ -58,6 +63,10 @@ func TestActionTypes(t *testing.T) {
58
63
testApp (t , "itxn_begin; int acfg; itxn_field TypeEnum; itxn_submit; int 1;" , ep , "insufficient balance" )
59
64
testApp (t , "itxn_begin; int afrz; itxn_field TypeEnum; itxn_submit; int 1;" , ep , "insufficient balance" )
60
65
66
+ // alllowed since v6
67
+ testApp (t , "itxn_begin; byte \" keyreg\" ; itxn_field Type; itxn_submit; int 1;" , ep , "insufficient balance" )
68
+ testApp (t , "itxn_begin; int keyreg; itxn_field TypeEnum; itxn_submit; int 1;" , ep , "insufficient balance" )
69
+
61
70
// Establish 888 as the app id, and fund it.
62
71
ledger .NewApp (ep .Txn .Txn .Receiver , 888 , basics.AppParams {})
63
72
ledger .NewAccount (basics .AppIndex (888 ).Address (), 200000 )
@@ -220,6 +229,30 @@ func TestRekeyPay(t *testing.T) {
220
229
// See explanation in logicLedger's Perform()
221
230
}
222
231
232
+ func TestRekeyBack (t * testing.T ) {
233
+ payAndUnkey := `
234
+ itxn_begin
235
+ itxn_field Amount
236
+ itxn_field Receiver
237
+ itxn_field Sender
238
+ int pay
239
+ itxn_field TypeEnum
240
+ txn Sender
241
+ itxn_field RekeyTo
242
+ itxn_submit
243
+ `
244
+
245
+ ep , ledger := makeSampleEnv ()
246
+ ledger .NewApp (ep .Txn .Txn .Receiver , 888 , basics.AppParams {})
247
+ testApp (t , "txn Sender; balance; int 0; ==;" , ep )
248
+ testApp (t , "txn Sender; txn Accounts 1; int 100" + payAndUnkey , ep , "unauthorized" )
249
+ ledger .NewAccount (ep .Txn .Txn .Sender , 120 + 3 * ep .Proto .MinTxnFee )
250
+ ledger .Rekey (ep .Txn .Txn .Sender , basics .AppIndex (888 ).Address ())
251
+ testApp (t , "txn Sender; txn Accounts 1; int 100" + payAndUnkey + "; int 1" , ep )
252
+ // now rekeyed back to original
253
+ testApp (t , "txn Sender; txn Accounts 1; int 100" + payAndUnkey , ep , "unauthorized" )
254
+ }
255
+
223
256
func TestDefaultSender (t * testing.T ) {
224
257
pay := `
225
258
itxn_begin
@@ -320,7 +353,7 @@ func TestExtraFields(t *testing.T) {
320
353
"non-zero fields for type axfer" )
321
354
}
322
355
323
- func TestBadField (t * testing.T ) {
356
+ func TestBadFieldV5 (t * testing.T ) {
324
357
pay := `
325
358
itxn_begin
326
359
int 7; itxn_field AssetAmount;
@@ -334,12 +367,34 @@ func TestBadField(t *testing.T) {
334
367
itxn_submit
335
368
`
336
369
337
- ep , ledger := makeSampleEnv ( )
370
+ ep , ledger := makeSampleEnvWithVersion ( 5 )
338
371
ledger .NewApp (ep .Txn .Txn .Receiver , 888 , basics.AppParams {})
339
372
testApp (t , "global CurrentApplicationAddress; txn Accounts 1; int 100" + pay , ep ,
340
373
"invalid itxn_field RekeyTo" )
341
374
}
342
375
376
+ func TestBadField (t * testing.T ) {
377
+ pay := `
378
+ itxn_begin
379
+ int 7; itxn_field AssetAmount;
380
+ itxn_field Amount
381
+ itxn_field Receiver
382
+ itxn_field Sender
383
+ int pay
384
+ itxn_field TypeEnum
385
+ txn Receiver
386
+ itxn_field RekeyTo // ALLOWED, since v6
387
+ int 10
388
+ itxn_field FirstValid // NOT ALLOWED
389
+ itxn_submit
390
+ `
391
+
392
+ ep , ledger := makeSampleEnv ()
393
+ ledger .NewApp (ep .Txn .Txn .Receiver , 888 , basics.AppParams {})
394
+ testApp (t , "global CurrentApplicationAddress; txn Accounts 1; int 100" + pay , ep ,
395
+ "invalid itxn_field FirstValid" )
396
+ }
397
+
343
398
func TestNumInner (t * testing.T ) {
344
399
pay := `
345
400
itxn_begin
@@ -434,3 +489,32 @@ func TestAssetFreeze(t *testing.T) {
434
489
require .NoError (t , err )
435
490
require .Equal (t , false , holding .Frozen )
436
491
}
492
+
493
+ func TestFieldSetting (t * testing.T ) {
494
+ ep , ledger := makeSampleEnv ()
495
+ ledger .NewApp (ep .Txn .Txn .Receiver , 888 , basics.AppParams {})
496
+ ledger .NewAccount (ledger .ApplicationID ().Address (), 10 * defaultEvalProto ().MinTxnFee )
497
+ testApp (t , "itxn_begin; int 500; bzero; itxn_field Note; int 1" , ep )
498
+ testApp (t , "itxn_begin; int 501; bzero; itxn_field Note; int 1" , ep ,
499
+ "Note may not exceed" )
500
+
501
+ testApp (t , "itxn_begin; int 32; bzero; itxn_field VotePK; int 1" , ep )
502
+ testApp (t , "itxn_begin; int 31; bzero; itxn_field VotePK; int 1" , ep ,
503
+ "VotePK must be 32" )
504
+
505
+ testApp (t , "itxn_begin; int 32; bzero; itxn_field SelectionPK; int 1" , ep )
506
+ testApp (t , "itxn_begin; int 33; bzero; itxn_field SelectionPK; int 1" , ep ,
507
+ "SelectionPK must be 32" )
508
+
509
+ testApp (t , "itxn_begin; int 32; bzero; itxn_field RekeyTo; int 1" , ep )
510
+ testApp (t , "itxn_begin; int 31; bzero; itxn_field RekeyTo; int 1" , ep ,
511
+ "not an address" )
512
+
513
+ testApp (t , "itxn_begin; int 6; bzero; itxn_field ConfigAssetUnitName; int 1" , ep )
514
+ testApp (t , "itxn_begin; int 7; bzero; itxn_field ConfigAssetUnitName; int 1" , ep ,
515
+ "value is too long" )
516
+
517
+ testApp (t , "itxn_begin; int 12; bzero; itxn_field ConfigAssetName; int 1" , ep )
518
+ testApp (t , "itxn_begin; int 13; bzero; itxn_field ConfigAssetName; int 1" , ep ,
519
+ "value is too long" )
520
+ }
0 commit comments