This repository has been archived by the owner on Jan 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
cli.bats
executable file
·200 lines (163 loc) · 5.84 KB
/
cli.bats
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#!/usr/bin/env bats
: ${EMERALD_VAULT:=$HOME/.cargo/bin/emerald-vault}
# Setup and teardown are called surrounding EACH @test.
setup() {
export EMERALD_BASE_PATH=`mktemp -d`
}
teardown() {
rm -rf $EMERALD_BASE_PATH
unset EMERALD_BASE_PATH
}
@test "[meta] succeeds: set env var and tmp dir EMERALD_BASE_PATH" {
run echo "$EMERALD_BASE_PATH"
[ "$status" -eq 0 ]
[ -d $EMERALD_BASE_PATH ]
[ "$output" != "" ]
}
@test "succeeds: --version" {
run $EMERALD_VAULT --version
[ "$status" -eq 0 ]
[[ "$output" == *"v"* ]]
}
@test "succeeds: --help" {
run $EMERALD_VAULT --help
[ "$status" -eq 0 ]
[[ "$output" == *"emerald"* ]]
[[ "$output" == *"Command-line"* ]]
[[ "$output" == *"USAGE"* ]]
[[ "$output" == *"FLAGS"* ]]
[[ "$output" == *"OPTIONS"* ]]
[[ "$output" == *"SUBCOMMANDS"* ]]
}
@test "succeeds: --chain=morden account new [empty options]" {
run $EMERALD_VAULT --chain=morden account new <<< $'foo\n'
[ "$status" -eq 0 ]
[[ "$output" == *"Created new account"* ]]
}
@test "succeeds: --chain=etc new --security=high --name='Test account' --description='Some description'" {
run $EMERALD_VAULT --chain=etc \
account new \
--security-level=high \
--name="Test account" \
--description="Some description" \
<<< $'foo\n'
[ "$status" -eq 0 ]
[[ "$output" == *"Created new account"* ]]
}
@test "succeeds: create on mainnet read on etc" {
run $EMERALD_VAULT --chain=mainnet \
account new \
--name="Test account c693ad" \
--description="Some description" \
<<< $'foo\n'
echo $output
[ "$status" -eq 0 ]
[[ "$output" == *"Created new account"* ]]
run $EMERALD_VAULT --chain=etc account list
local output_clean=$(echo "$output" | tr -d "\n" | sed -e "s/0x[0-9a-f]*/0xADDR/" | sed -e 's/[[:blank:]][[:blank:]]*/ /g')
[[ "$output_clean" == *"ADDRESS NAME 0xADDR test account c693ad"* ]]
run $EMERALD_VAULT --chain=mainnet account list
local output_clean=$(echo "$output" | tr -d "\n" | sed -e "s/0x[0-9a-f]*/0xADDR/" | sed -e 's/[[:blank:]][[:blank:]]*/ /g')
[[ "$output_clean" == *"ADDRESS NAME 0xADDR test account c693ad"* ]]
}
@test "succeeds: create on etc read on mainnet" {
run $EMERALD_VAULT --chain=etc \
account new \
--name="Test account a14272" \
--description="Some description" \
<<< $'foo\n'
[ "$status" -eq 0 ]
[[ "$output" == *"Created new account"* ]]
run $EMERALD_VAULT --chain=mainnet account list
local output_clean=$(echo "$output" | tr -d "\n" | sed -e "s/0x[0-9a-f]*/0xADDR/" | sed -e 's/[[:blank:]][[:blank:]]*/ /g')
[[ "$output_clean" == *"ADDRESS NAME 0xADDR test account a14272"* ]]
run $EMERALD_VAULT --chain=etc account list
local output_clean=$(echo "$output" | tr -d "\n" | sed -e "s/0x[0-9a-f]*/0xADDR/" | sed -e 's/[[:blank:]][[:blank:]]*/ /g')
[[ "$output_clean" == *"ADDRESS NAME 0xADDR test account a14272"* ]]
}
@test "succeeds: account list" {
run $EMERALD_VAULT --chain=morden \
account new \
<<< $'foo\n'
[ "$status" -eq 0 ]
[[ "$output" == *"Created new account"* ]]
# FIXME I'm ugly.
local address=$(echo "$output" | perl -lane 'print $F[-1]' | tr -d '\n')
local removeme='!passphrase:'
local replacewith=''
address="${address//$removeme/$replacewith}"
[[ "$address" != "" ]]
[[ "$address" == *"0x"* ]]
run $EMERALD_VAULT --chain=morden account list
echo "$output" # prints in case fails
echo "$address"
[ "$status" -eq 0 ]
[[ "$output" == *"$address"* ]]
}
@test "succeeds: account update" {
run $EMERALD_VAULT --chain=morden account new \
<<< $'foo\n'
[ "$status" -eq 0 ]
[[ "$output" == *"Created new account"* ]]
# FIXME I'm ugly.
local address=$(echo "$output" | perl -lane 'print $F[-1]' | tr -d '\n')
local removeme='!passphrase:'
local replacewith=''
address="${address//$removeme/$replacewith}"
[[ "$address" != "" ]]
[[ "$address" == *"0x"* ]]
run $EMERALD_VAULT --chain=morden account update \
"$address" \
--name="new name" \
--description="new description"
[ "$status" -eq 0 ]
run $EMERALD_VAULT --chain=morden account list
[ "$status" -eq 0 ]
[[ "$output" == *"new name"* ]]
}
@test "succeeds: account strip" {
run $EMERALD_VAULT --chain=morden account new \
<<< $'foo\n'
[ "$status" -eq 0 ]
[[ "$output" == *"Created new account"* ]]
# FIXME I'm ugly.
local address=$(echo "$output" | perl -lane 'print $F[-1]' | tr -d '\n')
local removeme='!passphrase:'
local replacewith=''
address="${address//$removeme/$replacewith}"
[[ "$address" != "" ]]
[[ "$address" == *"0x"* ]]
run $EMERALD_VAULT --chain=morden account strip \
"$address" \
<<< $'foo\n'
[ "$status" -eq 0 ]
[[ "$output" == *"Private key: 0x"* ]]
}
@test "succeeds: account hide && unhide" {
run $EMERALD_VAULT --chain=morden account new \
<<< $'foo\n'
[ "$status" -eq 0 ]
[[ "$output" == *"Created new account"* ]]
# FIXME I'm ugly.
local address=$(echo "$output" | perl -lane 'print $F[-1]' | tr -d '\n')
local removeme='!passphrase:'
local replacewith=''
address="${address//$removeme/$replacewith}"
[[ "$address" != "" ]]
[[ "$address" == *"0x"* ]]
# Hide account.
run $EMERALD_VAULT --chain=morden account hide \
"$address"
[ "$status" -eq 0 ]
# Ensure is hidden; doesn't show up in list.
run $EMERALD_VAULT --chain=morden account list \
[ "$status" -eq 0 ]
[[ "$output" != *"$address"* ]]
# Unhide account.
run $EMERALD_VAULT --chain=morden account unhide \
"$address"
# Ensure is not hidden; shows up in list.
run $EMERALD_VAULT --chain=morden account list
[ "$status" -eq 0 ]
[[ "$output" == *"$address"* ]]
}