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
2 changes: 1 addition & 1 deletion internal/apiserver/route_post_new_contract_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ var postNewContractAPI = &oapispec.Route{
JSONHandler: func(r *oapispec.APIRequest) (output interface{}, err error) {
waitConfirm := strings.EqualFold(r.QP["confirm"], "true")
r.SuccessStatus = syncRetcode(waitConfirm)
return getOr(r.Ctx).Contracts().BroadcastContractAPI(r.Ctx, r.PP["ns"], r.Input.(*fftypes.ContractAPI), waitConfirm)
return getOr(r.Ctx).Contracts().BroadcastContractAPI(r.Ctx, r.APIBaseURL, r.PP["ns"], r.Input.(*fftypes.ContractAPI), waitConfirm)
},
}
4 changes: 2 additions & 2 deletions internal/apiserver/route_post_new_contract_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestPostNewContractAPI(t *testing.T) {
req.Header.Set("Content-Type", "application/json; charset=utf-8")
res := httptest.NewRecorder()

mcm.On("BroadcastContractAPI", mock.Anything, "ns1", mock.AnythingOfType("*fftypes.ContractAPI"), false).
mcm.On("BroadcastContractAPI", mock.Anything, mock.Anything, "ns1", mock.AnythingOfType("*fftypes.ContractAPI"), false).
Return(&fftypes.ContractAPI{}, nil)
r.ServeHTTP(res, req)

Expand All @@ -57,7 +57,7 @@ func TestPostNewContractAPISync(t *testing.T) {
req.Header.Set("Content-Type", "application/json; charset=utf-8")
res := httptest.NewRecorder()

mcm.On("BroadcastContractAPI", mock.Anything, "ns1", mock.AnythingOfType("*fftypes.ContractAPI"), true).
mcm.On("BroadcastContractAPI", mock.Anything, mock.Anything, "ns1", mock.AnythingOfType("*fftypes.ContractAPI"), true).
Return(&fftypes.ContractAPI{}, nil)
r.ServeHTTP(res, req)

Expand Down
2 changes: 1 addition & 1 deletion internal/apiserver/route_put_contract_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ var putContractAPI = &oapispec.Route{
api.ID, err = fftypes.ParseUUID(r.Ctx, r.PP["id"])
var res interface{}
if err == nil {
res, err = getOr(r.Ctx).Contracts().BroadcastContractAPI(r.Ctx, r.PP["ns"], api, waitConfirm)
res, err = getOr(r.Ctx).Contracts().BroadcastContractAPI(r.Ctx, r.APIBaseURL, r.PP["ns"], api, waitConfirm)
}
return res, err
},
Expand Down
4 changes: 2 additions & 2 deletions internal/apiserver/route_put_contract_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestPutContractAPI(t *testing.T) {
req.Header.Set("Content-Type", "application/json; charset=utf-8")
res := httptest.NewRecorder()

mcm.On("BroadcastContractAPI", mock.Anything, "ns1", mock.AnythingOfType("*fftypes.ContractAPI"), false).
mcm.On("BroadcastContractAPI", mock.Anything, mock.Anything, "ns1", mock.AnythingOfType("*fftypes.ContractAPI"), false).
Return(&fftypes.ContractAPI{}, nil)
r.ServeHTTP(res, req)

Expand All @@ -57,7 +57,7 @@ func TestPutContractAPISync(t *testing.T) {
req.Header.Set("Content-Type", "application/json; charset=utf-8")
res := httptest.NewRecorder()

mcm.On("BroadcastContractAPI", mock.Anything, "ns1", mock.AnythingOfType("*fftypes.ContractAPI"), true).
mcm.On("BroadcastContractAPI", mock.Anything, mock.Anything, "ns1", mock.AnythingOfType("*fftypes.ContractAPI"), true).
Return(&fftypes.ContractAPI{}, nil)
r.ServeHTTP(res, req)

Expand Down
5 changes: 3 additions & 2 deletions internal/contracts/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type Manager interface {
InvokeContractAPI(ctx context.Context, ns, apiName, methodPath string, req *fftypes.ContractCallRequest) (interface{}, error)
GetContractAPI(ctx context.Context, httpServerURL, ns, apiName string) (*fftypes.ContractAPI, error)
GetContractAPIs(ctx context.Context, httpServerURL, ns string, filter database.AndFilter) ([]*fftypes.ContractAPI, *database.FilterResult, error)
BroadcastContractAPI(ctx context.Context, ns string, api *fftypes.ContractAPI, waitConfirm bool) (output *fftypes.ContractAPI, err error)
BroadcastContractAPI(ctx context.Context, httpServerURL, ns string, api *fftypes.ContractAPI, waitConfirm bool) (output *fftypes.ContractAPI, err error)
SubscribeContract(ctx context.Context, ns, eventPath string, req *fftypes.ContractSubscribeRequest) (*fftypes.ContractSubscription, error)
SubscribeContractAPI(ctx context.Context, ns, apiName, eventPath string, req *fftypes.ContractSubscribeRequest) (*fftypes.ContractSubscription, error)

Expand Down Expand Up @@ -311,7 +311,7 @@ func (cm *contractManager) resolveFFIReference(ctx context.Context, ns string, r
}
}

func (cm *contractManager) BroadcastContractAPI(ctx context.Context, ns string, api *fftypes.ContractAPI, waitConfirm bool) (output *fftypes.ContractAPI, err error) {
func (cm *contractManager) BroadcastContractAPI(ctx context.Context, httpServerURL, ns string, api *fftypes.ContractAPI, waitConfirm bool) (output *fftypes.ContractAPI, err error) {
api.ID = fftypes.NewUUID()
api.Namespace = ns

Expand All @@ -337,6 +337,7 @@ func (cm *contractManager) BroadcastContractAPI(ctx context.Context, ns string,
return nil, err
}
api.Message = msg.Header.ID
cm.addContractURLs(httpServerURL, api)
return api, nil
}

Expand Down
25 changes: 14 additions & 11 deletions internal/contracts/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1501,8 +1501,11 @@ func TestBroadcastContractAPI(t *testing.T) {
mdb.On("GetContractAPIByName", mock.Anything, api.Namespace, api.Name).Return(nil, nil)
mdb.On("GetFFIByID", mock.Anything, api.Interface.ID).Return(&fftypes.FFI{}, nil)
mbm.On("BroadcastDefinitionAsNode", mock.Anything, "ns1", mock.AnythingOfType("*fftypes.ContractAPI"), fftypes.SystemTagDefineContractAPI, false).Return(msg, nil)
_, err := cm.BroadcastContractAPI(context.Background(), "ns1", api, false)
api, err := cm.BroadcastContractAPI(context.Background(), "http://localhost/api", "ns1", api, false)
assert.NoError(t, err)
assert.NotNil(t, api)
assert.NotEmpty(t, api.URLs.OpenAPI)
assert.NotEmpty(t, api.URLs.UI)
}

func TestBroadcastContractAPIExisting(t *testing.T) {
Expand Down Expand Up @@ -1539,7 +1542,7 @@ func TestBroadcastContractAPIExisting(t *testing.T) {
mdb.On("GetContractAPIByName", mock.Anything, api.Namespace, api.Name).Return(existing, nil)
mdb.On("GetFFIByID", mock.Anything, api.Interface.ID).Return(&fftypes.FFI{}, nil)
mbm.On("BroadcastDefinitionAsNode", mock.Anything, "ns1", mock.AnythingOfType("*fftypes.ContractAPI"), fftypes.SystemTagDefineContractAPI, false).Return(msg, nil)
_, err := cm.BroadcastContractAPI(context.Background(), "ns1", api, false)
_, err := cm.BroadcastContractAPI(context.Background(), "http://localhost/api", "ns1", api, false)
assert.NoError(t, err)
}

Expand Down Expand Up @@ -1577,7 +1580,7 @@ func TestBroadcastContractAPICannotChangeLocation(t *testing.T) {
mdb.On("GetContractAPIByName", mock.Anything, api.Namespace, api.Name).Return(existing, nil)
mdb.On("GetFFIByID", mock.Anything, api.Interface.ID).Return(&fftypes.FFI{}, nil)
mbm.On("BroadcastDefinition", mock.Anything, "ns1", mock.AnythingOfType("*fftypes.ContractAPI"), fftypes.SystemTagDefineContractAPI, false).Return(msg, nil)
_, err := cm.BroadcastContractAPI(context.Background(), "ns1", api, false)
_, err := cm.BroadcastContractAPI(context.Background(), "http://localhost/api", "ns1", api, false)
assert.Regexp(t, "FF10316", err)
}

Expand Down Expand Up @@ -1606,7 +1609,7 @@ func TestBroadcastContractAPIInterfaceName(t *testing.T) {
mdb.On("GetContractAPIByName", mock.Anything, api.Namespace, api.Name).Return(nil, nil)
mdb.On("GetFFI", mock.Anything, "ns1", "my-ffi", "1").Return(&fftypes.FFI{ID: interfaceID}, nil)
mbm.On("BroadcastDefinitionAsNode", mock.Anything, "ns1", mock.AnythingOfType("*fftypes.ContractAPI"), fftypes.SystemTagDefineContractAPI, false).Return(msg, nil)
_, err := cm.BroadcastContractAPI(context.Background(), "ns1", api, false)
_, err := cm.BroadcastContractAPI(context.Background(), "http://localhost/api", "ns1", api, false)
assert.NoError(t, err)
assert.Equal(t, *interfaceID, *api.Interface.ID)
}
Expand All @@ -1629,7 +1632,7 @@ func TestBroadcastContractAPIFail(t *testing.T) {
mdb.On("GetContractAPIByName", mock.Anything, api.Namespace, api.Name).Return(nil, nil)
mdb.On("GetFFIByID", mock.Anything, api.Interface.ID).Return(&fftypes.FFI{}, nil)
mbm.On("BroadcastDefinitionAsNode", mock.Anything, "ns1", mock.AnythingOfType("*fftypes.ContractAPI"), fftypes.SystemTagDefineContractAPI, false).Return(nil, fmt.Errorf("pop"))
_, err := cm.BroadcastContractAPI(context.Background(), "ns1", api, false)
_, err := cm.BroadcastContractAPI(context.Background(), "http://localhost/api", "ns1", api, false)
assert.Regexp(t, "pop", err)
}

Expand All @@ -1645,7 +1648,7 @@ func TestBroadcastContractAPINoInterface(t *testing.T) {
Name: "banana",
}
mdb.On("GetContractAPIByName", mock.Anything, api.Namespace, api.Name).Return(nil, nil)
_, err := cm.BroadcastContractAPI(context.Background(), "ns1", api, false)
_, err := cm.BroadcastContractAPI(context.Background(), "http://localhost/api", "ns1", api, false)
assert.Regexp(t, "FF10303", err)
}

Expand All @@ -1665,7 +1668,7 @@ func TestBroadcastContractAPIInterfaceIDFail(t *testing.T) {
}
mdb.On("GetContractAPIByName", mock.Anything, api.Namespace, api.Name).Return(nil, nil)
mdb.On("GetFFIByID", mock.Anything, api.Interface.ID).Return(nil, fmt.Errorf("pop"))
_, err := cm.BroadcastContractAPI(context.Background(), "ns1", api, false)
_, err := cm.BroadcastContractAPI(context.Background(), "http://localhost/api", "ns1", api, false)
assert.EqualError(t, err, "pop")
}

Expand All @@ -1685,7 +1688,7 @@ func TestBroadcastContractAPIInterfaceIDNotFound(t *testing.T) {
}
mdb.On("GetContractAPIByName", mock.Anything, api.Namespace, api.Name).Return(nil, nil)
mdb.On("GetFFIByID", mock.Anything, api.Interface.ID).Return(nil, nil)
_, err := cm.BroadcastContractAPI(context.Background(), "ns1", api, false)
_, err := cm.BroadcastContractAPI(context.Background(), "http://localhost/api", "ns1", api, false)
assert.Regexp(t, "FF10303.*"+api.Interface.ID.String(), err)
}

Expand All @@ -1706,7 +1709,7 @@ func TestBroadcastContractAPIInterfaceNameFail(t *testing.T) {
}
mdb.On("GetContractAPIByName", mock.Anything, api.Namespace, api.Name).Return(nil, nil)
mdb.On("GetFFI", mock.Anything, "ns1", "my-ffi", "1").Return(nil, fmt.Errorf("pop"))
_, err := cm.BroadcastContractAPI(context.Background(), "ns1", api, false)
_, err := cm.BroadcastContractAPI(context.Background(), "http://localhost/api", "ns1", api, false)
assert.EqualError(t, err, "pop")
}

Expand All @@ -1727,7 +1730,7 @@ func TestBroadcastContractAPIInterfaceNameNotFound(t *testing.T) {
}
mdb.On("GetContractAPIByName", mock.Anything, api.Namespace, api.Name).Return(nil, nil)
mdb.On("GetFFI", mock.Anything, "ns1", "my-ffi", "1").Return(nil, nil)
_, err := cm.BroadcastContractAPI(context.Background(), "ns1", api, false)
_, err := cm.BroadcastContractAPI(context.Background(), "http://localhost/api", "ns1", api, false)
assert.Regexp(t, "FF10303.*my-ffi", err)
}

Expand All @@ -1746,7 +1749,7 @@ func TestBroadcastContractAPIInterfaceNoVersion(t *testing.T) {
},
}
mdb.On("GetContractAPIByName", mock.Anything, api.Namespace, api.Name).Return(nil, nil)
_, err := cm.BroadcastContractAPI(context.Background(), "ns1", api, false)
_, err := cm.BroadcastContractAPI(context.Background(), "http://localhost/api", "ns1", api, false)
assert.Regexp(t, "FF10303.*my-ffi", err)
}

Expand Down
14 changes: 7 additions & 7 deletions mocks/contractmocks/manager.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.