Skip to content

Commit 67a0637

Browse files
authored
Merge pull request #414 from shutter-network/dev/third_party_messaging
Third party messaging test
2 parents 875cb44 + f5fb27e commit 67a0637

File tree

4 files changed

+147
-1
lines changed

4 files changed

+147
-1
lines changed

play/README.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ export ROLLING_SHUTTER_BOOTSTRAP_SIGNING_KEY=479968ffa5ee4c84514a477a8f15f3db041
1616
export ROLLING_SHUTTER_CHAIN_GENESIS_KEYPER=0x440Dc6F164e9241F04d282215ceF2780cd0B755e
1717
```
1818

19+
## prepare psql (via docker)
20+
21+
```
22+
docker run --rm -it -e POSTGRES_USER=$(whoami) -e POSTGRES_PASSWORD=password -e POSTGRES_DB=testdb -v /tmp:/tmp --net=host -v /tmp/projectdir:/home/circleci/project -v /tmp/datadir:/var/lib/postgresql/data cimg/postgres:13.9
23+
```
24+
1925
## keyper only test setup
2026

2127
1. bb init; bb chain
@@ -49,3 +55,64 @@ Run `bb test-system`.
4955

5056
Run `bb nitro` to start an arbitrum nitro test setup. This requires docker and
5157
docker-compose to be installed.
58+
59+
## Running third party clients in a test
60+
61+
There is an example test task `keyper-dkg-external`, that shows how a third
62+
party client can be addressed.
63+
64+
Instead of three `keyper` instances, it starts only two and one external
65+
executable. That external executable can be defined with `BB_EXTERNAL_COMMAND`.
66+
For convenience, there is also the optional `BB_EXTERNAL_WD`, to manipulate the
67+
working directory of the external call.
68+
69+
As an example, here is how one of the three original test keypers can be called
70+
manually:
71+
72+
```
73+
BB_EXTERNAL_WD="$(pwd)" BB_EXTERNAL_COMMAND="../rolling-shutter/bin/rolling-shutter keyper --config work/keyper-dkg-external/keyper-2.toml" clojure -M:test keyper-dkg-external
74+
```
75+
76+
### Parameters in the environment
77+
78+
You can find the test system parameters in the environment of the
79+
`BB_EXTERNAL_COMMAND`, e.g.:
80+
81+
```
82+
# run "/bin/sh -c env" as external command to dump the environment:
83+
BB_EXTERNAL_COMMAND="/bin/sh -c env" clojure -M:test keyper-dkg-external
84+
...
85+
# find the values in the test log:
86+
cat work/keyper-dkg-external/logs/keyper-external-*|grep KPR
87+
KPR_P2P_PORT=23102
88+
KPR_DKG_PHASE_LENGTH=8
89+
KPR_ENVIRONMENT=local
90+
KPR_ETHEREUM_URL=http://127.0.0.1:8545/
91+
KPR_DKG_START_BLOCK_DELTA=5
92+
KPR_HTTP_LISTEN_ADDRESS=:24003
93+
KPR_CONTRACTS_URL=http://127.0.0.1:8545/
94+
KPR_LISTEN_ADDRESSES=/ip4/127.0.0.1/tcp/23102
95+
```
96+
97+
Here you see, that the keyper implementation under tests, should use port
98+
`23102` for its `p2p` connection, the ethereum node is running at
99+
`http://127.0.0.1:8545/` etc. Not all of these may be relevant to your
100+
implementation.
101+
102+
### Self contained testrunner
103+
104+
It is possible to compile the testrunner into a self contained `.jar` file, by
105+
running
106+
107+
```
108+
clojure -T:build
109+
```
110+
111+
If you have such a `sht-standalone.jar` you can run the above test (without the
112+
need to install clojure), by calling
113+
114+
```
115+
BB_EXTERNAL_COMMAND="../rolling-shutter/bin/rolling-shutter keyper --config work/keyper-dkg-external/keyper-2.toml" java -jar sht-standalone.jar -M:test keyper-dkg-external
116+
```
117+
118+
(The `circleci` integration tests make use of this.)

play/src/sht/build.clj

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,16 @@
9898
[{:keys [num-keypers]}]
9999
(mapv run-keyper (range num-keypers)))
100100

101+
(defn run-external-command
102+
[n]
103+
(let [external (play/external-command n)]
104+
{:run :process/run
105+
:process/id (keyword "keyper-external")
106+
:process/cmd (str (System/getenv "BB_EXTERNAL_COMMAND"))
107+
:process/opts (:process/opts external)
108+
:process/port (:process/p2p-port external)
109+
:process/port-timeout 3000}))
110+
101111
(defn run-p2pnode
102112
[n]
103113
(let [p2pnode (play/p2pnode-subcommand n)]

play/src/sht/dkg_test.clj

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,13 +507,60 @@
507507
{:check :keyper/ordered-eons-match
508508
:keyper/num keyper
509509
:keyper/ordered-eons [1201 1202]}])]})
510+
511+
(defn test-keypers-dkg-with-external
512+
[{:keys [num-keypers] :as conf}]
513+
{:test/id :keyper-dkg-external
514+
:test/conf conf
515+
:test/description "distributed key generation with external keyper should work"
516+
:test/steps [{:run :init/init
517+
:init/conf conf}
518+
(for [keyper (range num-keypers 1)]
519+
{:check :keyper/meta-inf
520+
:keyper-num keyper})
521+
522+
(build/run-chain)
523+
(build/run-node conf)
524+
(build/run-p2pnodes conf)
525+
(mapv build/run-keyper (range (- num-keypers 1)))
526+
(build/run-external-command num-keypers)
527+
528+
{:run :process/run
529+
:process/id :boot
530+
:process/cmd '[bb boot]
531+
:process/wait true}
532+
533+
{:check :loop/until
534+
:loop/description "eon should exist for all keypers"
535+
:loop/timeout-ms (* 60 1000)
536+
:loop/checks (for [keyper (range (- num-keypers 1))]
537+
{:check :keyper/eon-exists
538+
:keyper/num keyper
539+
:keyper/eon 1})}
540+
541+
{:check :loop/until
542+
:loop/description "all keypers should succeed with the dkg process"
543+
:loop/timeout-ms (* 60 1000)
544+
:loop/checks (for [keyper (range (- num-keypers 1))]
545+
{:check :keyper/dkg-success
546+
:keyper/eon 1
547+
:keyper/num keyper})}
548+
549+
(for [keyper (range (- num-keypers 1))]
550+
[{:check :keyper/non-zero-activation-block
551+
:keyper/num keyper}
552+
{:check :keyper/ordered-eons-match
553+
:keyper/num keyper
554+
:keyper/ordered-eons [1]}])]})
555+
510556
(defn generate-tests
511557
[]
512558
(concat
513559
[(test-change-keyper-set)]
514560
(for [conf [{:num-keypers 3, :num-bootstrappers 2, :threshold 2}]
515561
f [test-keypers-dkg-generation
516-
test-dkg-keypers-join-late]]
562+
test-dkg-keypers-join-late
563+
test-keypers-dkg-with-external]]
517564
(f conf))))
518565

519566
(def tests (delay (generate-tests)))

play/src/sht/play.clj

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,28 @@
219219
"EthereumURL" (format "http://127.0.0.1:%d/" ethereum-rpc-port)
220220
"ContractsURL" (format "http://127.0.0.1:%d/" contracts-rpc-port)}}))
221221

222+
;; -- external-command
223+
(defn external-command
224+
[n]
225+
(let [p2p-port (dec (+ keyper-base-port n))
226+
work-dir (or (System/getenv "BB_EXTERNAL_WD")
227+
(System/getenv "PWD"))
228+
]
229+
#:process{:cmd 'external-cmd
230+
:p2p-port p2p-port
231+
:opts {:dir work-dir
232+
:extra-env {
233+
"KPR_P2P_PORT" p2p-port
234+
"KPR_DKG_PHASE_LENGTH" 8
235+
"KPR_DKG_START_BLOCK_DELTA" 5
236+
"KPR_LISTEN_ADDRESSES" (format "/ip4/127.0.0.1/tcp/%d" p2p-port)
237+
"KPR_ENVIRONMENT" "local"
238+
"KPR_HTTP_LISTEN_ADDRESS" (format ":%d" (+ 24000 n))
239+
"KPR_ETHEREUM_URL" (format "http://127.0.0.1:%d/" ethereum-rpc-port)
240+
"KPR_CONTRACTS_URL" (format "http://127.0.0.1:%d/" contracts-rpc-port)}}
241+
}
242+
))
243+
222244
;; -- mocknode-subcommand
223245
(defn mocknode-subcommand
224246
[]

0 commit comments

Comments
 (0)