-
Notifications
You must be signed in to change notification settings - Fork 0
/
swarm-tests.scm
366 lines (331 loc) · 13.8 KB
/
swarm-tests.scm
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
;;; Copyright © 2021 Attila Lendvai <attila@lendvai.name>
;;;
;;; This file is part of guix-crypto, a channel for Guix.
;;;
;;; guix-crypto is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; guix-crypto is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with guix-crypto. If not, see <http://www.gnu.org/licenses/>.
;; Run with something like this:
;; $(guix system --no-graphic vm ~/workspace/guix/guix-crypto/tests/swarm-tests.scm) -m 2048
;; $(./pre-inst-env guix system --no-graphic vm --share=$HOME/workspace/guix/var-lib-of-guest-vm=/var/lib ~/workspace/guix/guix-crypto/tests/swarm-tests.scm) -m 2048
(define-module (swarm-tests)
#:use-module (shepherd-package) ; from a checkout of the shepherd git repo
#:use-module (guix-crypto utils)
#:use-module (guix-crypto service-utils)
#:use-module (guix-crypto packages ethereum)
#:use-module (guix-crypto packages swarm)
#:use-module (guix-crypto services swarm)
#:use-module (guix-crypto services lighthouse)
#:use-module (guix-crypto services nethermind)
#:use-module (gnu tests)
#:use-module (gnu system)
#:use-module (gnu system shadow)
#:use-module (gnu system nss)
#:use-module (gnu system vm)
#:use-module (gnu services)
#:use-module (gnu services base)
#:use-module (gnu services dbus)
#:use-module (gnu services avahi)
#:use-module (gnu services mcron)
#:use-module (gnu services shepherd)
#:use-module (gnu services networking)
#:use-module (gnu services sysctl)
#:use-module (gnu packages admin)
#:use-module (gnu packages base)
#:use-module (gnu packages bash)
#:use-module (gnu packages certs)
#:use-module (gnu packages guile-xyz)
#:use-module (gnu packages imagemagick)
#:use-module (gnu packages networking)
#:use-module (gnu packages ocr)
#:use-module (gnu packages package-management)
#:use-module (gnu packages linux)
#:use-module (gnu packages tmux)
#:use-module (guix gexp)
#:use-module (guix git)
#:use-module (guix git-download)
#:use-module (guix store)
#:use-module (guix modules)
#:use-module (guix monads)
#:use-module (guix packages)
#:use-module (srfi srfi-1)
#:use-module (ice-9 match)
#:export (run-basic-test
*test-swarm-starting*))
(define *use-custom-shepherd* #true)
;;(define *parent-shepherd-package* shepherd-0.10) ; from guix
(define *parent-shepherd-package* (@ (shepherd-package) shepherd)) ; from shepherd
(define *custom-shepherd-dir* "/home/alendvai/workspace/guix/shepherd")
(define *custom-shepherd-only-from-commits* #true)
;; (define-public custom-guile-fibers
;; (package
;; (inherit guile-fibers-next)
;; (version "dev")
;; (arguments
;; `(;;#:tests? #false
;; ,@(package-arguments guile-fibers-next)))
;; (source (let ((dir "/home/alendvai/workspace/guix/fibers"))
;; (if #true
;; (git-checkout
;; (url (string-append "file://" dir))
;; (branch "bit-count")
;; ;;(commit "a281ebfd4466a6925e264c303201b8dc44d33cb4")
;; )
;; (local-file dir
;; #:recursive? #t
;; #:select? (git-predicate dir)))))))
(define custom-shepherd
(package
(inherit *parent-shepherd-package*)
(version "dev")
;; (inputs
;; (modify-inputs (package-inputs *parent-shepherd-package*)
;; (replace "guile-fibers" custom-guile-fibers)))
(source
(if *custom-shepherd-only-from-commits*
(git-checkout
(url (string-append "file://" *custom-shepherd-dir*))
(branch "attila")
;;(commit "a281ebfd4466a6925e264c303201b8dc44d33cb4")
)
(local-file *custom-shepherd-dir*
#:recursive? #t
#:select? (git-predicate *custom-shepherd-dir*))))
(arguments
`(#:tests? #false
,@(package-arguments *parent-shepherd-package*)))))
(define *mainnet-group*
(user-group
(name "mainnet")
(system? #t)))
(define *gnosis-user*
(user-account
(name "gnosis")
(group (user-group-name *mainnet-group*))
;;(supplementary-groups '("nethermind" "lighthouse"))
(system? #t)
(comment (string-append "User for the Gnosis chain daemons"))
(home-directory "/nohome")
(shell (file-append shadow "/sbin/nologin"))))
(define *swarm-os*
(operating-system
(inherit %simple-os)
(users (cons*
*gnosis-user*
%base-user-accounts))
(groups (cons*
*mainnet-group*
%base-groups))
(services
(cons*
(service dhcp-client-service-type)
(service
nethermind-service-type
(nethermind-service-configuration
(service-name 'gnosis-e)
(user-account *gnosis-user*)
(nethermind-configuration
(nethermind-configuration
(config "gnosis")
;;(Sync.FastSync #true)
(JsonRpc.JwtSecretFile "/var/lib/nethermind/jwt-secret")
(extra-arguments '())))))
(service
lighthouse-service-type
(lighthouse-service-configuration
(service-name 'gnosis-c)
(user-account *gnosis-user*)
(requirement '(gnosis-e))
(lighthouse-configuration
(lighthouse-configuration
(network "gnosis")
(logfile-compress #true)
(extra-arguments '((http #true)
(execution-endpoint "http://localhost:8551")
(execution-jwt "/var/lib/nethermind/jwt-secret")
(checkpoint-sync-url "https://checkpoint.gnosischain.com")))))))
(service
swarm-service-type
(swarm-service-configuration
(swarm swarm/mainnet)
(bee-configurations
(indexed-bee-configurations
2
(bee-config-values
(resolver-options "https://mainnet.infura.io/v3/7216e0c44a0c47d99ca6de1c82b5d7b9")
(blockchain-rpc-endpoint "http://serlap.lan:8545")
(swap-initial-deposit 0)
(debug-api-enable #true))))))
(simple-service
'server-config
sysctl-service-type
'(("fs.file-max" . "2000000")))
(modify-services %base-services
(sysctl-service-type config =>
(sysctl-configuration
(settings (append '(("fs.file-max" . "500000")
("fs.inotify.max_user_watches" . "524288"))
%default-sysctl-settings)))))))
;; Use own Shepherd package.
(essential-services
(modify-services (operating-system-default-essential-services
this-operating-system)
(shepherd-root-service-type
config =>
(shepherd-configuration
(inherit config)
(shepherd (if *use-custom-shepherd*
custom-shepherd
shepherd))))))))
(define *swarm-marionette-os*
(marionette-operating-system
(operating-system
(inherit *swarm-os*)
(kernel-arguments '())
(packages (append
(list
;; netcat-openbsd
socat
;; for HTTPS access
nss-certs
le-certs)
%base-packages)))
#:requirements '(nscd)
#:imported-modules '((gnu services herd)
(guix combinators))))
(define* (run-basic-test os command #:optional (derivation-name "swarm-service")
#:key
initialization
root-password
desktop?)
(define test-expression
(with-imported-modules '((gnu build marionette)
(guix build syscalls))
#~(begin
(use-modules (gnu build marionette)
(guix build syscalls)
(srfi srfi-1)
(srfi srfi-26)
(srfi srfi-64)
(ice-9 match))
(define marionette
(make-marionette #$command))
(mkdir #$output)
(chdir #$output)
(test-begin "swarm-service")
#$(and initialization
(initialization #~marionette))
;; Shepherd reads the config file *before* binding its control
;; socket, so /var/run/shepherd/socket might not exist yet when the
;; 'marionette' service is started.
(test-assert "shepherd socket ready"
(marionette-eval
`(begin
(use-modules (gnu services herd))
(let loop ((i 10))
(cond ((file-exists? (%shepherd-socket-file))
#t)
((> i 0)
(sleep 1)
(loop (- i 1)))
(else
#f))))
marionette))
(test-assert "accounts"
(let ((users (marionette-eval '(begin
(use-modules (ice-9 match))
(let loop ((result '()))
(match (getpwent)
(#f (reverse result))
(x (loop (cons x result))))))
marionette)))
(lset= equal?
(map (lambda (user)
(list (passwd:name user)
(passwd:dir user)))
users)
(list
#$@(map (lambda (account)
`(list ,(user-account-name account)
,(user-account-home-directory account)))
(operating-system-user-accounts os))))))
(test-assert "shepherd services"
(let ((services (marionette-eval
'(begin
(use-modules (gnu services herd))
(map (compose car live-service-provision)
(current-services)))
marionette)))
(lset= eq?
(pk 'services services)
'(root #$@(operating-system-shepherd-service-names os)))))
(test-equal "login on tty1"
"root\n"
(begin
;; XXX: On desktop, GDM3 will switch to TTY7. If this happens
;; after we switched to TTY1, we won't be able to login. Make
;; sure to wait long enough before switching to TTY1.
(when #$desktop?
(sleep 30))
(marionette-control "sendkey ctrl-alt-f1" marionette)
;; Wait for the 'term-tty1' service to be running (using
;; 'start-service' is the simplest and most reliable way to do
;; that.)
(marionette-eval
'(begin
(use-modules (gnu services herd))
(start-service 'term-tty1))
marionette)
;; Now we can type.
(let ((password #$root-password))
(if password
(begin
(marionette-type "root\n" marionette)
(wait-for-screen-text marionette
(lambda (text)
(string-contains text "Password"))
#:ocrad
#$(file-append ocrad "/bin/ocrad"))
(marionette-type (string-append password "\n\n")
marionette))
(marionette-type "root\n\n" marionette)))
(marionette-type "id -un > logged-in\n" marionette)
;; It can take a while before the shell commands are executed.
(marionette-eval '(use-modules (rnrs io ports)) marionette)
(wait-for-file "/root/logged-in" marionette
#:read 'get-string-all)))
(test-assert "host name resolution"
(match (marionette-eval
'(begin
;; Wait for nscd or our requests go through it.
(use-modules (gnu services herd))
(start-service 'nscd)
(list (getaddrinfo "localhost")
(getaddrinfo #$(operating-system-host-name os))))
marionette)
((((? vector?) ..1) ((? vector?) ..1))
#t)
(x
(pk 'failure x #f))))
(test-end)
(exit (= (test-runner-fail-count (test-runner-current)) 0)))))
(gexp->derivation derivation-name test-expression))
(define *test-swarm-starting*
(system-test
(name "swarm-service-start")
(description
"Instrument *SWARM-MARIONETTE-OS* to run it in a VM, and test the SWARM-SERVICE-TYPE.")
(value
(run-basic-test (virtualized-operating-system *swarm-marionette-os* '())
#~(list #$(virtual-machine *swarm-marionette-os*))))))
;; Return the OS object, so that it can be passed to `guix system vm swarm.scm`.
*swarm-marionette-os*