@@ -4,7 +4,11 @@ package dkg
44
55import (
66 "encoding/hex"
7+ "encoding/json"
8+ "io"
79 "math/rand"
10+ "net/http"
11+ "net/http/httptest"
812 "os"
913 "path/filepath"
1014 "testing"
@@ -216,12 +220,34 @@ func TestWriteArtifactsProtocolStep(t *testing.T) {
216220
217221 shares := valKeysToSharesNode0 (t , valKeys , lock .Validators )
218222
223+ var receivedLock cluster.Lock
224+
225+ mockServer := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
226+ require .Equal (t , "/lock" , r .URL .Path )
227+ require .Equal (t , http .MethodPost , r .Method )
228+ require .Equal (t , "application/json" , r .Header .Get ("Content-Type" ))
229+
230+ body , err := io .ReadAll (r .Body )
231+ require .NoError (t , err )
232+
233+ err = json .Unmarshal (body , & receivedLock )
234+ require .NoError (t , err )
235+
236+ w .WriteHeader (http .StatusOK )
237+ }))
238+ defer mockServer .Close ()
239+
219240 pctx := & ProtocolContext {
220241 Lock : & lock ,
221242 PrivateKeyPath : p2p .KeyPath (dataDir ),
222243 ENRPrivateKey : nodeKeys [0 ],
223244 Shares : shares ,
224245 ThisNodeIdx : cluster.NodeIdx {PeerIdx : 0 , ShareIdx : 1 },
246+ Config : Config {
247+ PublishAddr : mockServer .URL ,
248+ PublishTimeout : 30 * time .Second ,
249+ Publish : true ,
250+ },
225251 }
226252 err = step .Run (t .Context (), pctx )
227253
@@ -231,6 +257,9 @@ func TestWriteArtifactsProtocolStep(t *testing.T) {
231257 require .FileExists (t , p2p .KeyPath (step .outputDir ))
232258 require .FileExists (t , p2p .KeyPath (step .outputDir )+ ".lock" )
233259
260+ require .NotZero (t , receivedLock .LockHash , "Expected lock to be published to mock server" )
261+ require .Equal (t , lock .LockHash , receivedLock .LockHash )
262+
234263 enrPrivKey , err := os .ReadFile (p2p .KeyPath (step .outputDir ))
235264 require .NoError (t , err )
236265 enrPrivKeyBytes , err := hex .DecodeString (string (enrPrivKey ))
0 commit comments