Skip to content

Commit 3ca8eb9

Browse files
🧹 Add expect-based tests for interactive scripts (LayerZero-Labs#389)
1 parent bdbe8ab commit 3ca8eb9

File tree

7 files changed

+292
-1
lines changed

7 files changed

+292
-1
lines changed

‎.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
.turbo
22
dist
33
node_modules
4+
*.exp
45
*.md
56
*.sol
67
*.toml

‎.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
*.exp
12
*.log
23
.eslintignore
34
.prettierignore
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/expect -f
2+
#
3+
# This Expect script was generated by autoexpect on Mon Feb 12 16:57:18 2024
4+
# Expect and autoexpect were both written by Don Libes, NIST.
5+
#
6+
# Note that autoexpect does not guarantee a working script. It
7+
# necessarily has to guess about certain things. Two reasons a script
8+
# might fail are:
9+
#
10+
# 1) timing - A surprising number of programs (rn, ksh, zsh, telnet,
11+
# etc.) and devices discard or ignore keystrokes that arrive "too
12+
# quickly" after prompts. If you find your new script hanging up at
13+
# one spot, try adding a short sleep just before the previous send.
14+
# Setting "force_conservative" to 1 (see below) makes Expect do this
15+
# automatically - pausing briefly before sending each character. This
16+
# pacifies every program I know of. The -c flag makes the script do
17+
# this in the first place. The -C flag allows you to define a
18+
# character to toggle this mode off and on.
19+
20+
set force_conservative 0
21+
if {$force_conservative} {
22+
set send_slow {1 .1}
23+
proc send {ignore arg} {
24+
sleep .1
25+
exp_send -s -- $arg
26+
}
27+
}
28+
29+
30+
set timeout 60
31+
spawn npx hardhat lz:deploy
32+
match_max 100000
33+
34+
expect "Which networks would you like to deploy?"
35+
send -- "\r"
36+
37+
expect "Which deploy script tags would you like to use?"
38+
send -- "MeNoExist"
39+
send -- "\r"
40+
41+
expect "Will deploy 3 networks: britney, tango, vengaboys"
42+
expect "Will use deploy scripts tagged with MeNoExist"
43+
expect "Do you want to continue?"
44+
send -- "\r"
45+
46+
expect "Deploying..."
47+
expect "Your contracts are now deployed"
48+
49+
expect eof
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/expect -f
2+
#
3+
# This Expect script was generated by autoexpect on Mon Feb 12 16:57:18 2024
4+
# Expect and autoexpect were both written by Don Libes, NIST.
5+
#
6+
# Note that autoexpect does not guarantee a working script. It
7+
# necessarily has to guess about certain things. Two reasons a script
8+
# might fail are:
9+
#
10+
# 1) timing - A surprising number of programs (rn, ksh, zsh, telnet,
11+
# etc.) and devices discard or ignore keystrokes that arrive "too
12+
# quickly" after prompts. If you find your new script hanging up at
13+
# one spot, try adding a short sleep just before the previous send.
14+
# Setting "force_conservative" to 1 (see below) makes Expect do this
15+
# automatically - pausing briefly before sending each character. This
16+
# pacifies every program I know of. The -c flag makes the script do
17+
# this in the first place. The -C flag allows you to define a
18+
# character to toggle this mode off and on.
19+
20+
set force_conservative 0
21+
if {$force_conservative} {
22+
set send_slow {1 .1}
23+
proc send {ignore arg} {
24+
sleep .1
25+
exp_send -s -- $arg
26+
}
27+
}
28+
29+
30+
set timeout 60
31+
spawn npx hardhat lz:deploy
32+
match_max 100000
33+
34+
expect "Which networks would you like to deploy?"
35+
send -- "\r"
36+
37+
expect "Which deploy script tags would you like to use?"
38+
send -- "\r"
39+
40+
expect "Will deploy 3 networks: britney, tango, vengaboys"
41+
expect "Will use all deployment scripts"
42+
expect "Do you want to continue?"
43+
send -- "\r"
44+
45+
expect "Deploying..."
46+
expect "Your contracts are now deployed"
47+
48+
expect eof
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/usr/bin/expect -f
2+
#
3+
# This Expect script was generated by autoexpect on Mon Feb 12 16:57:18 2024
4+
# Expect and autoexpect were both written by Don Libes, NIST.
5+
#
6+
# Note that autoexpect does not guarantee a working script. It
7+
# necessarily has to guess about certain things. Two reasons a script
8+
# might fail are:
9+
#
10+
# 1) timing - A surprising number of programs (rn, ksh, zsh, telnet,
11+
# etc.) and devices discard or ignore keystrokes that arrive "too
12+
# quickly" after prompts. If you find your new script hanging up at
13+
# one spot, try adding a short sleep just before the previous send.
14+
# Setting "force_conservative" to 1 (see below) makes Expect do this
15+
# automatically - pausing briefly before sending each character. This
16+
# pacifies every program I know of. The -c flag makes the script do
17+
# this in the first place. The -C flag allows you to define a
18+
# character to toggle this mode off and on.
19+
20+
set force_conservative 0
21+
if {$force_conservative} {
22+
set send_slow {1 .1}
23+
proc send {ignore arg} {
24+
sleep .1
25+
exp_send -s -- $arg
26+
}
27+
}
28+
29+
30+
set timeout 60
31+
spawn npx hardhat lz:deploy
32+
match_max 100000
33+
34+
expect "Which networks would you like to deploy?"
35+
36+
# First we deselect britney
37+
send -- " "
38+
# We move down by pressing down array
39+
send -- "\[B"
40+
# Then we deselect tango
41+
send -- " "
42+
# Finally we confirm
43+
send -- "\r"
44+
45+
expect "Which deploy script tags would you like to use?"
46+
send -- "Thrower"
47+
send -- "\r"
48+
49+
expect "Will deploy 1 network: vengaboys"
50+
expect "Will use deploy scripts tagged with Thrower"
51+
expect "Do you want to continue?"
52+
send -- "\r"
53+
54+
expect "Deploying..."
55+
expect "Your contracts are now deployed"
56+
57+
expect eof
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/usr/bin/expect -f
2+
#
3+
# This Expect script was generated by autoexpect on Mon Feb 12 16:57:18 2024
4+
# Expect and autoexpect were both written by Don Libes, NIST.
5+
#
6+
# Note that autoexpect does not guarantee a working script. It
7+
# necessarily has to guess about certain things. Two reasons a script
8+
# might fail are:
9+
#
10+
# 1) timing - A surprising number of programs (rn, ksh, zsh, telnet,
11+
# etc.) and devices discard or ignore keystrokes that arrive "too
12+
# quickly" after prompts. If you find your new script hanging up at
13+
# one spot, try adding a short sleep just before the previous send.
14+
# Setting "force_conservative" to 1 (see below) makes Expect do this
15+
# automatically - pausing briefly before sending each character. This
16+
# pacifies every program I know of. The -c flag makes the script do
17+
# this in the first place. The -C flag allows you to define a
18+
# character to toggle this mode off and on.
19+
20+
set force_conservative 0
21+
if {$force_conservative} {
22+
set send_slow {1 .1}
23+
proc send {ignore arg} {
24+
sleep .1
25+
exp_send -s -- $arg
26+
}
27+
}
28+
29+
30+
set timeout 60
31+
spawn npx hardhat lz:deploy
32+
match_max 100000
33+
34+
expect "Which networks would you like to deploy?"
35+
36+
# First we deselect britney
37+
send -- " "
38+
# We move down by pressing down array
39+
send -- "\[B"
40+
# Then we deselect tango
41+
send -- " "
42+
# Finally we confirm
43+
send -- "\r"
44+
45+
expect "Which deploy script tags would you like to use?"
46+
send -- "\r"
47+
48+
expect "Will deploy 1 network: vengaboys"
49+
expect "Will use all deployment scripts"
50+
expect "Do you want to continue?"
51+
send -- "\r"
52+
53+
expect "Deploying..."
54+
expect "Your contracts are now deployed"
55+
56+
expect eof

‎tests/devtools-evm-hardhat-test/test/task/deploy.test.ts

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,15 @@ import hre from 'hardhat'
44
import { TASK_COMPILE } from 'hardhat/builtin-tasks/task-names'
55
import { DeploymentsManager } from 'hardhat-deploy/dist/src/DeploymentsManager'
66
import { TASK_LZ_DEPLOY } from '@layerzerolabs/devtools-evm-hardhat'
7-
import { promptForText, promptToContinue, promptToSelectMultiple } from '@layerzerolabs/io-devtools'
7+
import {
8+
isDirectory,
9+
isFile,
10+
promptForText,
11+
promptToContinue,
12+
promptToSelectMultiple,
13+
} from '@layerzerolabs/io-devtools'
14+
import { spawnSync } from 'child_process'
15+
import { join } from 'path'
816

917
jest.mock('@layerzerolabs/io-devtools', () => {
1018
const original = jest.requireActual('@layerzerolabs/io-devtools')
@@ -24,6 +32,77 @@ const runSpy = jest.spyOn(hre, 'run')
2432
const runDeploySpy = jest.spyOn(DeploymentsManager.prototype, 'runDeploy')
2533

2634
describe(`task ${TASK_LZ_DEPLOY}`, () => {
35+
describe('expectations', () => {
36+
const EXPECTATIONS_DIRECTORY = join('test', 'task', 'deploy.test.expectations')
37+
const expectationPath = (name: string) => join(EXPECTATIONS_DIRECTORY, `${name}.exp`)
38+
const runExpect = (name: string) =>
39+
spawnSync(expectationPath(name), {
40+
encoding: 'utf8',
41+
stdio: 'inherit',
42+
})
43+
44+
const deploymentsPath = (networkName: string) => join('deployments', networkName)
45+
46+
const deploymentPath = (networkName: string) => (name: string) =>
47+
join(deploymentsPath(networkName), `${name}.json`)
48+
49+
it('should deploy all tags on all networks', async () => {
50+
const result = runExpect('deploy-all')
51+
52+
expect(result.status).toBe(0)
53+
54+
const britneyDeploymentPath = deploymentPath('britney')
55+
const tangoDeploymentPath = deploymentPath('tango')
56+
const vengaboysDeploymentPath = deploymentPath('vengaboys')
57+
58+
expect(isFile(britneyDeploymentPath('TestProxy'))).toBeTruthy()
59+
expect(isFile(tangoDeploymentPath('TestProxy'))).toBeTruthy()
60+
expect(isFile(vengaboysDeploymentPath('TestProxy'))).toBeTruthy()
61+
62+
expect(isFile(britneyDeploymentPath('Thrower'))).toBeTruthy()
63+
expect(isFile(tangoDeploymentPath('Thrower'))).toBeTruthy()
64+
expect(isFile(vengaboysDeploymentPath('Thrower'))).toBeTruthy()
65+
})
66+
67+
it('should deploy all tags on vengaboys', async () => {
68+
const result = runExpect('deploy-vengaboys')
69+
70+
expect(result.status).toBe(0)
71+
72+
const vengaboysDeploymentPath = deploymentPath('vengaboys')
73+
74+
expect(isDirectory(deploymentsPath('britney'))).toBeFalsy()
75+
expect(isDirectory(deploymentsPath('tango'))).toBeFalsy()
76+
77+
expect(isFile(vengaboysDeploymentPath('TestProxy'))).toBeTruthy()
78+
expect(isFile(vengaboysDeploymentPath('Thrower'))).toBeTruthy()
79+
})
80+
81+
it('should deploy single tag on vengaboys', async () => {
82+
const result = runExpect('deploy-vengaboys-thrower')
83+
84+
expect(result.status).toBe(0)
85+
86+
const vengaboysDeploymentPath = deploymentPath('vengaboys')
87+
88+
expect(isDirectory(deploymentsPath('britney'))).toBeFalsy()
89+
expect(isDirectory(deploymentsPath('tango'))).toBeFalsy()
90+
91+
expect(isFile(vengaboysDeploymentPath('Thrower'))).toBeTruthy()
92+
expect(isFile(vengaboysDeploymentPath('TestProxy'))).toBeFalsy()
93+
})
94+
95+
it('should not deploy anything if tag does not exist', async () => {
96+
const result = runExpect('deploy-all-missing-tag')
97+
98+
expect(result.status).toBe(0)
99+
100+
expect(isDirectory(deploymentsPath('britney'))).toBeFalsy()
101+
expect(isDirectory(deploymentsPath('tango'))).toBeFalsy()
102+
expect(isDirectory(deploymentsPath('vengaboys'))).toBeFalsy()
103+
})
104+
})
105+
27106
const expectDeployment = expect.objectContaining({
28107
abi: expect.any(Array),
29108
args: expect.any(Array),

0 commit comments

Comments
 (0)