Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion internal/dataexchange/ffdx/ffdx.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,21 @@ func (h *FFDX) Capabilities() *dataexchange.Capabilities {
return h.capabilities
}

func (h *FFDX) dxEndpointArray(nodes []fftypes.DXInfo) []fftypes.JSONObject {
// The remote DataExchange connector HTTP API expects a flat array
// where "id" is in embedded in each entry - because that's how it
// originally passed the data to us.
// In the DXInfo contract on the Go plugin in FireFly we raise the "id" up
// to be a first class "peer" field, so it can be indexed outside of the opaque
// endpoint payload.
// This function just converts back to a flat array.
dxEndpointArray := make([]fftypes.JSONObject, len(nodes))
for i, node := range nodes {
dxEndpointArray[i] = node.Endpoint
}
return dxEndpointArray
}

func (h *FFDX) beforeConnect(ctx context.Context) error {
h.initMutex.Lock()
defer h.initMutex.Unlock()
Expand All @@ -156,7 +171,7 @@ func (h *FFDX) beforeConnect(ctx context.Context) error {
h.initialized = false
var status dxStatus
res, err := h.client.R().SetContext(ctx).
SetBody(h.nodes).
SetBody(h.dxEndpointArray(h.nodes)).
SetResult(&status).
Post("/api/v1/init")
if err != nil || !res.IsSuccess() {
Expand Down
11 changes: 7 additions & 4 deletions internal/dataexchange/ffdx/ffdx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ func TestWebsocketWithReinit(t *testing.T) {
utConfPrefix.Set(restclient.HTTPCustomClient, mockedClient)
utConfPrefix.Set(DataExchangeInitEnabled, true)

first := true
count := 0
httpmock.RegisterResponder("POST", fmt.Sprintf("%s/api/v1/init", httpURL),
func(req *http.Request) (*http.Response, error) {
var reqNodes []fftypes.DXInfo
Expand All @@ -538,12 +538,15 @@ func TestWebsocketWithReinit(t *testing.T) {

assert.False(t, h.initialized)

if first {
first = false
count++
if count == 1 {
return httpmock.NewJsonResponse(200, fftypes.JSONObject{
"status": "notready",
})
}
if count == 2 {
return nil, fmt.Errorf("pop")
}
return httpmock.NewJsonResponse(200, fftypes.JSONObject{
"status": "ready",
})
Expand All @@ -556,7 +559,7 @@ func TestWebsocketWithReinit(t *testing.T) {
err = h.Start()
assert.NoError(t, err)

assert.Equal(t, 2, httpmock.GetTotalCallCount())
assert.Equal(t, 3, httpmock.GetTotalCallCount())
assert.True(t, h.initialized)
}

Expand Down