Skip to content

Commit e778545

Browse files
committed
add expect_linter and fix issues it found
1 parent f8c1e24 commit e778545

File tree

9 files changed

+106
-7
lines changed

9 files changed

+106
-7
lines changed

test/e2e-go/cli/goal/expect/basicExpectTest.exp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,19 @@ if { [catch {
1616
spawn echo "hello"
1717
expect {
1818
timeout { abort "\n Failed to see expected input hello" }
19+
eof { abort "Ended without hello" }
1920
"^hello*" {close}
2021
}
2122

2223
spawn echo "goodbye"
2324
expect {
2425
timeout { abort "Failed to see expected input goodbye" }
26+
eof { abort "Ended without goodbye" }
2527
"^goodbye*" {close}
2628
}
2729

2830
exit 0
2931

3032
} EXCEPTION ] } {
3133
abort "ERROR in basic expect test: $EXCEPTION"
32-
}
34+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/usr/bin/env python
2+
import sys
3+
import argparse
4+
5+
def check_expect_blocks(filename, verbose=False):
6+
with open(filename, 'r') as f:
7+
lines = f.readlines()
8+
9+
in_expect_block = False
10+
brace_count = 0
11+
block_start_line = None
12+
current_block = []
13+
expect_blocks = []
14+
15+
# Process each line, considering possible strings or comments
16+
for line_num, line in enumerate(lines, start=1):
17+
stripped_line = line.strip()
18+
19+
if not in_expect_block:
20+
if "expect " in stripped_line and '{' in stripped_line:
21+
in_expect_block = True
22+
block_start_line = line_num
23+
brace_count = stripped_line.count('{') - stripped_line.count('}')
24+
current_block = [stripped_line]
25+
elif stripped_line.startswith("#") or stripped_line.startswith("//"):
26+
continue # Ignore comment lines outside of expect blocks
27+
else:
28+
current_block.append(stripped_line)
29+
brace_count += stripped_line.count('{') - stripped_line.count('}')
30+
31+
if brace_count == 0:
32+
in_expect_block = False
33+
expect_blocks.append((block_start_line, "\n".join(current_block)))
34+
current_block = []
35+
36+
for block_start_line, block in expect_blocks:
37+
if '#nolint:eof' in block:
38+
if verbose:
39+
print(f"{filename}:{block_start_line}: SKIP: 'nolint:eof' comment found, skipping")
40+
continue
41+
42+
if 'eof' not in block:
43+
# Check for only timeout condition
44+
actions = block.count('}')
45+
if block.count('timeout') == actions:
46+
if verbose:
47+
print(f"{filename}:{block_start_line}: OK: only timeout action present")
48+
continue
49+
50+
print(f"{filename}:{block_start_line}: Warning: missing 'eof' in expect block")
51+
elif verbose:
52+
print(f"{filename}:{block_start_line}: OK: expect block contains 'eof'")
53+
54+
def main():
55+
parser = argparse.ArgumentParser(description="Check for 'eof' in expect blocks of scripts.")
56+
parser.add_argument('files', metavar='FILE', type=str, nargs='+', help='Files to check')
57+
parser.add_argument('-v', '--verbose', action='store_true', help='Enable verbose output')
58+
args = parser.parse_args()
59+
60+
for fname in args.files:
61+
check_expect_blocks(fname, args.verbose)
62+
63+
if __name__ == "__main__":
64+
main()

test/e2e-go/cli/goal/expect/goalCmdFlagsTest.exp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ log_user 1
55
proc TestGoalCommandLineFlags { CMD EXPECTED_RE } {
66
set PASSED 0
77
eval spawn $CMD
8-
expect {
8+
expect { #nolint:eof checking PASSED catches no match
99
timeout { puts "goal asset create timed out"; exit 1 }
1010
-re $EXPECTED_RE {set PASSED 1; close }
1111
}

test/e2e-go/cli/goal/expect/goalDryrunRestTest.exp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ proc TestGoalDryrun { DRREQ_FILE TEST_PRIMARY_NODE_DIR } {
77
set COST 0
88
set PROGRAM_TYPE ""
99
spawn goal clerk dryrun-remote -d $TEST_PRIMARY_NODE_DIR -D $DRREQ_FILE -v
10-
expect {
10+
expect { #nolint:eof checking PASSED catches no match
1111
timeout { ::AlgorandGoal::Abort "goal clerk dryrun-remote timeout" }
1212
"budget consumed:" {set COST 1; exp_continue}
1313
-re {(ApprovalProgram)} {set PROGRAM_TYPE $expect_out(1,string); exp_continue}

test/e2e-go/cli/goal/expect/goalExpectCommon.exp

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,12 +234,14 @@ proc ::AlgorandGoal::RestartNode { TEST_ALGO_DIR {SYSTEMD_MANAGED ""} } {
234234
expect {
235235
timeout { close; ::AlgorandGoal::Abort "Did not receive appropriate message during node restart" }
236236
"^The node was successfully stopped.*Algorand node successfully started!*" {puts "Node restarted successfully"; close}
237+
eof { close; ::AlgorandGoal::Abort "Did not receive appropriate message before node restart eof" }
237238
}
238239
} else {
239240
spawn goal node restart -d $TEST_ALGO_DIR
240241
expect {
241242
timeout { close; ::AlgorandGoal::Abort "Did not receive appropriate message during node restart" }
242243
"^This node is using systemd and should be managed with systemctl*" { puts "Goal showed correct error message for systemd" ; close}
244+
eof { close; ::AlgorandGoal::Abort "Did not receive appropriate message before node restart eof" }
243245
}
244246
}
245247
} EXCEPTION] } {
@@ -333,22 +335,27 @@ proc ::AlgorandGoal::CreateWallet { WALLET_NAME WALLET_PASSWORD TEST_PRIMARY_NOD
333335

334336
expect {
335337
timeout {::AlgorandGoal::Abort "Timed out CreateWallet password" }
338+
eof {::AlgorandGoal::Abort "EOF CreateWallet password" }
336339
"Please choose a password for wallet*" { send "$WALLET_PASSWORD\r" }
337340
}
338341
expect {
339342
timeout {::AlgorandGoal::Abort "Timed out CreateWallet confirmation" }
343+
eof {::AlgorandGoal::Abort "EOF CreateWallet confirmation" }
340344
"Please confirm*" { send "$WALLET_PASSWORD\r"}
341345
}
342346
expect {
343347
timeout {::AlgorandGoal::Abort "Timed out CreateWallet see it now" }
348+
eof {::AlgorandGoal::Abort "EOF CreateWallet see it now" }
344349
"Would you like to see it now? (Y/n):" { send "y\r" }
345350
}
346351
expect {
347352
timeout {::AlgorandGoal::Abort "Timed out CreateWallet keep info safe" }
353+
eof {::AlgorandGoal::Abort "EOF CreateWallet keep info safe" }
348354
"Keep this information safe -- never share it with anyone!" {}
349355
}
350356
expect {
351357
timeout {::AlgorandGoal::Abort "Timed out CreateWallet pass phrase" }
358+
eof {::AlgorandGoal::Abort "EOF CreateWallet pass phrase" }
352359
-re {([a-z ]+)} {set WALLET_PASS_PHRASE $expect_out(1,string); close;}
353360
}
354361
} EXCEPTION ] } {
@@ -364,6 +371,7 @@ proc ::AlgorandGoal::VerifyWallet { WALLET_NAME TEST_PRIMARY_NODE_DIR } {
364371
spawn goal wallet list -d $TEST_PRIMARY_NODE_DIR
365372
expect {
366373
timeout { ::AlgorandGoal::Abort "Timed out seeing expected input for spawn goal wallet list" }
374+
eof { ::AlgorandGoal::Abort "EOF seeing expected input for spawn goal wallet list" }
367375
"*$WALLET_NAME*" {close}
368376
}
369377
} EXCEPTION ] } {
@@ -376,12 +384,14 @@ proc ::AlgorandGoal::RecoverWallet { NEW_WALLET_NAME WALLET_PASSPHRASE NEW_WALLE
376384
if { [catch {
377385
spawn goal wallet new -r $NEW_WALLET_NAME -d $TEST_PRIMARY_NODE_DIR
378386
expect {
379-
timeout { puts "TIMEOUT" }
387+
timeout { ::AlgorandGoal::Abort "TIMEOUT" }
388+
eof { ::AlgorandGoal::Abort "EOF" }
380389
{Please type your recovery mnemonic below, and hit return when you are done:*} { send "$WALLET_PASSPHRASE\r" }
381390
}
382391
for { set index 1} {$index <= 5} {incr index} {
383392
expect {
384-
timeout { puts "TIMEOUT" }
393+
timeout { ::AlgorandGoal::Abort "TIMEOUT" }
394+
eof { ::AlgorandGoal::Abort "EOF" }
385395
{Please choose a password for wallet* } { send "$NEW_WALLET_PASSWORD\r"}
386396
{Please confirm the password:*} { send "$NEW_WALLET_PASSWORD\r"}
387397
{Creating wallet...*} {puts $expect_out(buffer) }
@@ -403,6 +413,7 @@ proc ::AlgorandGoal::CreateAccountForWallet { WALLET_NAME WALLET_PASSWORD TEST_P
403413
while 1 {
404414
expect {
405415
timeout { break; ::AlgorandGoal::Abort "Timed out seeing new account created for wallet $WALLET_NAME" }
416+
eof { break; ::AlgorandGoal::Abort "EOF seeing new account created for wallet $WALLET_NAME" }
406417
"Please enter the password for wallet*" { send "$WALLET_PASSWORD\r" }
407418
-re {Created new account with address ([a-zA-Z0-9]+)} {set ACCOUNT_ADDRESS $expect_out(1,string) ;close; break }
408419
}
@@ -422,6 +433,7 @@ proc ::AlgorandGoal::VerifyAccount { WALLET_NAME WALLET_PASSWORD ACCOUNT_ADDRESS
422433
while 1 {
423434
expect {
424435
timeout {break; ::AlgorandGoal::Abort "Timed out seeing expected account: $ACCOUNT_ADDRESS"}
436+
eof {break; ::AlgorandGoal::Abort "EOF seeing expected account: $ACCOUNT_ADDRESS"}
425437
"Please enter the password for wallet*" { send "$WALLET_PASSWORD\r" }
426438
-re {\t([A-Z0-9]+)\t([A-Z0-9]+)} {set RETURN_ACCOUNT_ADDRESS $expect_out(1,string); break }
427439
}
@@ -487,6 +499,7 @@ proc ::AlgorandGoal::GetAccountRewards { WALLET_NAME ACCOUNT_ADDRESS TEST_PRIMAR
487499
spawn goal account rewards -w $WALLET_NAME -a $ACCOUNT_ADDRESS -d $TEST_PRIMARY_NODE_DIR
488500
expect {
489501
timeout { ::AlgorandGoal::Abort "Timed out retrieving account rewards for wallet $WALLET_NAME and account $ACCOUNT_ADDRESS" }
502+
eof { ::AlgorandGoal::Abort "EOF retrieving account rewards for wallet $WALLET_NAME and account $ACCOUNT_ADDRESS" }
490503
-re {\d+} {set ACCOUNT_EARNINGS $expect_out(0,string)}
491504
}
492505
puts "Wallet: $WALLET_NAME, Account: $ACCOUNT_ADDRESS, Rewards: $ACCOUNT_EARNINGS"
@@ -667,6 +680,7 @@ proc ::AlgorandGoal::LimitOrder {TEAL_DRIVER SWAP_N SWAP_D MIN_TRD OWNER FEE TIM
667680
spawn python $TEAL_DRIVER "limit-order" --swapn $SWAP_N --swapd $SWAP_D --mintrd $MIN_TRD --own $OWNER --fee $FEE --timeout $TIME_OUT --asset $ASSET_ID
668681
expect {
669682
timeout { ::AlgorandGoal::Abort "Timed out limit order" }
683+
eof { ::AlgorandGoal::Abort "EOF limit order" }
670684
-re {^.+$} { puts $limitf $expect_out(buffer); close $limitf; close }
671685
}
672686
} EXCEPTION ] } {
@@ -741,6 +755,7 @@ proc ::AlgorandGoal::RawSend { TXN_FILE TEST_PRIMARY_NODE_DIR } {
741755
spawn goal clerk rawsend -f $TXN_FILE -d $TEST_PRIMARY_NODE_DIR
742756
expect {
743757
timeout { close; ::AlgorandGoal::Abort "Timed out rawsend $TXN_FILE" }
758+
eof { close; ::AlgorandGoal::Abort "EOF rawsend $TXN_FILE" }
744759
-re {Transaction ([A-Z0-9]{52}) committed} {set TRANSACTION_ID $expect_out(1,string); close }
745760
-re {Rejected transactions written to (.+rej)} {::AlgorandGoal::Abort "RawSend rejected."}
746761
}
@@ -809,6 +824,7 @@ proc ::AlgorandGoal::CheckNetworkAddressForCors { NET_ADDRESS } {
809824
spawn curl -X OPTIONS -H "Origin: http://algorand.com" --head $NET_ADDRESS
810825
expect {
811826
timeout { close; ::AlgorandGoal::Abort "Timeout failure in CheckNetworkAddressForCors" }
827+
eof { close; ::AlgorandGoal::Abort "EOF in CheckNetworkAddressForCors" }
812828
"Access-Control-Allow-Origin" { puts "success" ; close }
813829
eof {
814830
return -code error "EOF without Access-Control-Allow-Origin in output"
@@ -826,6 +842,7 @@ proc ::AlgorandGoal::GetLedgerSupply { TEST_PRIMARY_NODE_DIR } {
826842
spawn goal ledger supply -d $TEST_PRIMARY_NODE_DIR
827843
expect {
828844
timeout { ::AlgorandGoal::Abort "Get Ledger Supply timed out" }
845+
eof { ::AlgorandGoal::Abort "Get Ledger Supply EOF" }
829846
-re {Round: (\d+)} {set ROUND $expect_out(1,string); exp_continue }
830847
-re {Total Money: (\d+)} {set TOTAL_MONEY $expect_out(1,string); exp_continue }
831848
-re {Online Money: (\d+)} {set ONLINE_MONEY $expect_out(1,string) }
@@ -844,6 +861,7 @@ proc ::AlgorandGoal::CreateOneOfTwoMultisigForWallet { ADDRESS_1 ADDRESS_2 WALLE
844861
spawn goal account multisig new $ADDRESS_1 $ADDRESS_2 -T 1 -d $TEST_PRIMARY_NODE_DIR -w $WALLET_NAME
845862
expect {
846863
timeout { ::AlgorandGoal::Abort "Timed out creating a multisig account from $ADDRESS_1 and $ADDRESS_2" }
864+
eof { ::AlgorandGoal::Abort "EOF creating a multisig account from $ADDRESS_1 and $ADDRESS_2" }
847865
"Please enter the password for wallet*" { send "$WALLET_PASSWORD\r" }
848866
-re {Created new account with address ([a-zA-Z0-9]+)} {
849867
set MULTISIG_ADDRESS $expect_out(1,string);
@@ -862,6 +880,7 @@ proc ::AlgorandGoal::VerifyMultisigInfoForOneOfTwoMultisig { MULTISIG_ADDRESS AD
862880
spawn goal account multisig info --address $MULTISIG_ADDRESS -d $TEST_PRIMARY_NODE_DIR -w $WALLET_NAME
863881
expect {
864882
timeout { ::AlgorandGoal::Abort "Timed out querying info about multisig account $MULTISIG_ADDRESS" }
883+
eof { ::AlgorandGoal::Abort "EOF querying info about multisig account $MULTISIG_ADDRESS" }
865884
-re {Version: (\d+)\s+Threshold: (\d+)\s+Public keys:\s+([a-zA-Z0-9]+)\s+([a-zA-Z0-9]+)\s+} {
866885
set VERSION $expect_out(1,string);
867886
set THRESHOLD $expect_out(2,string);
@@ -882,7 +901,11 @@ proc ::AlgorandGoal::VerifyMultisigInfoForOneOfTwoMultisig { MULTISIG_ADDRESS AD
882901
proc ::AlgorandGoal::DeleteMultisigAccount { MULTISIG_ADDRESS TEST_PRIMARY_NODE_DIR } {
883902
if { [ catch {
884903
spawn goal account multisig delete --address $MULTISIG_ADDRESS -d $TEST_PRIMARY_NODE_DIR
885-
expect {*}
904+
expect eof
905+
set status [wait]
906+
if {$status != 0} {
907+
::AlgorandGoal::Abort "DeleteMultisigAccount failed with exit code $status"
908+
}
886909
} EXCEPTION ] } {
887910
::AlgorandGoal::Abort "ERROR in DeleteMultisigAccount: $EXCEPTION"
888911
}
@@ -1049,6 +1072,7 @@ proc ::AlgorandGoal::Report { TEST_PRIMARY_NODE_DIR } {
10491072
spawn goal report -d $TEST_PRIMARY_NODE_DIR
10501073
expect {
10511074
timeout { ::AlgorandGoal::Abort "goal report timed out" }
1075+
eof { ::AlgorandGoal::Abort "goal report EOF" }
10521076
"source code available at https://github.com/algorand/go-algorand" {puts "goal -v ok"}
10531077
-re {Genesis ID from genesis.json: *} {puts "genesis ID from genesis.json ok"}
10541078
-re {Last committed block: (\d+)} {puts "status check ok"}

test/e2e-go/cli/goal/expect/goalTxValidityTest.exp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ proc TestLastValidInTx { CMD TX_FILE EXPECTED_LAST_VALID } {
3232
spawn goal clerk inspect $TX_FILE
3333
expect {
3434
timeout { ::AlgorandGoal::Abort "'goal clerk inspect' timed out" }
35+
eof { ::AlgorandGoal::Abort "'goal clerk inspect' eof" }
3536
-re {"lv": (\d+)} {set PASSED 1; set LAST_VALID $expect_out(1,string); close }
3637
}
3738

test/e2e-go/cli/goal/expect/limitOrderTest.exp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ if { [catch {
123123

124124
puts "Generated Teal Source:"
125125
spawn cat $TEAL_SOURCE
126-
expect {
126+
expect { #nolint:eof not asserting expected output
127127
-re {^.+$} { close }
128128
}
129129

test/e2e-go/cli/goal/expect/tealConsensusTest.exp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ if { [catch {
5050
spawn goal clerk compile "$TEST_ROOT_DIR/small-sig.teal"
5151
expect {
5252
-re {[A-Z2-9]{58}} { set SMALL_SIG $expect_out(0,string) }
53+
eof { ::AlgorandGoal::Abort $expect_out(buffer) }
5354
"\n" { ::AlgorandGoal::Abort $expect_out(buffer) }
5455
}
5556

@@ -58,13 +59,15 @@ if { [catch {
5859
expect {
5960
-re {[A-Z2-9]{58}} { ::AlgorandGoal::Abort "hash" }
6061
-re {.*logicsig program size too large} { puts "bigsigcheck: pass" }
62+
eof { ::AlgorandGoal::Abort $expect_out(buffer) }
6163
"\n" { ::AlgorandGoal::Abort $expect_out(buffer) }
6264
}
6365

6466
teal "$TEST_ROOT_DIR/barely-fits-app.teal" 2 4090 1 "int 0\nbalance\npop\n"
6567
spawn goal clerk compile "$TEST_ROOT_DIR/barely-fits-app.teal"
6668
expect {
6769
-re {[A-Z2-9]{58}} { puts "hash $expect_out(0,string)" }
70+
eof { ::AlgorandGoal::Abort $expect_out(buffer) }
6871
"\n" { ::AlgorandGoal::Abort $expect_out(buffer) }
6972
}
7073

@@ -74,6 +77,7 @@ if { [catch {
7477
expect {
7578
-re {[A-Z2-9]{58}} { ::AlgorandGoal::Abort "hash" }
7679
-re {.*app program size too large} { puts "bigappcheck: pass" }
80+
eof { ::AlgorandGoal::Abort $expect_out(buffer) }
7781
"\n" { ::AlgorandGoal::Abort $expect_out(buffer) }
7882
}
7983

@@ -84,6 +88,7 @@ if { [catch {
8488
" - pass -" { puts "small-sig dryrun pass" }
8589
"REJECT" { ::AlgorandGoal::Abort $expect_out(buffer) }
8690
"static cost budget" { ::AlgorandGoal::Abort $expect_out(buffer) }
91+
eof { ::AlgorandGoal::Abort $expect_out(buffer) }
8792
}
8893

8994
teal "$TEST_ROOT_DIR/slow-sig.teal" 2 1 20001
@@ -94,6 +99,7 @@ if { [catch {
9499
"dynamic cost budget" { puts "slow-sig dryrun pass" }
95100
" - pass -" { ::AlgorandGoal::Abort $expect_out(buffer) }
96101
"REJECT" { ::AlgorandGoal::Abort $expect_out(buffer) }
102+
eof { ::AlgorandGoal::Abort $expect_out(buffer) }
97103
}
98104

99105
# Shutdown the network

test/e2e-go/cli/goal/expect/testInfraTest.exp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ proc checkProcessReturnedCodeTest {} {
5858
44 {
5959
close
6060
}
61+
eof { puts "expected output not 44"; exit 1 }
6162
}
6263
lassign [::AlgorandGoal::CheckProcessReturnedCode 0] response OS_CODE ERR_CODE KILLED KILL_SIGNAL EXP
6364
if {$response != 0} {
@@ -72,6 +73,7 @@ proc checkProcessReturnedCodeTest {} {
7273
44 {
7374
puts "not closing"
7475
}
76+
eof { puts "expected output not 44"; exit 1 }
7577
}
7678
lassign [::AlgorandGoal::CheckProcessReturnedCode 0] response OS_CODE ERR_CODE KILLED KILL_SIGNAL EXP
7779
if {$KILLED != "CHILDKILLED" || $KILL_SIGNAL != "SIGSEGV" || $EXP != "segmentation violation"} {

0 commit comments

Comments
 (0)