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
390 changes: 195 additions & 195 deletions docs/swagger/swagger.yaml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ import (
"github.com/hyperledger/firefly/pkg/fftypes"
)

var getContractEventByID = &oapispec.Route{
Name: "getContractEventByID",
Path: "namespaces/{ns}/contracts/events/{id}",
var getBlockchainEventByID = &oapispec.Route{
Name: "getBlockchainEventByID",
Path: "namespaces/{ns}/blockchainevents/{id}",
Method: http.MethodGet,
PathParams: []*oapispec.PathParam{
{Name: "ns", ExampleFromConf: config.NamespacesDefault, Description: i18n.MsgTBD},
Expand All @@ -45,6 +45,6 @@ var getContractEventByID = &oapispec.Route{
if err != nil {
return nil, err
}
return getOr(r.Ctx).Contracts().GetContractEventByID(r.Ctx, u)
return getOr(r.Ctx).GetBlockchainEventByID(r.Ctx, u)
},
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,28 @@ import (
"net/http/httptest"
"testing"

"github.com/hyperledger/firefly/mocks/contractmocks"
"github.com/hyperledger/firefly/pkg/fftypes"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
)

func TestGetContractEventByID(t *testing.T) {
func TestGetBlockchainEventByID(t *testing.T) {
o, r := newTestAPIServer()
mcm := &contractmocks.Manager{}
o.On("Contracts").Return(mcm)
id := fftypes.NewUUID()
req := httptest.NewRequest("GET", "/api/v1/namespaces/mynamespace/contracts/events/"+id.String(), nil)
req := httptest.NewRequest("GET", "/api/v1/namespaces/mynamespace/blockchainevents/"+id.String(), nil)
req.Header.Set("Content-Type", "application/json; charset=utf-8")
res := httptest.NewRecorder()

mcm.On("GetContractEventByID", mock.Anything, id).
o.On("GetBlockchainEventByID", mock.Anything, id).
Return(&fftypes.BlockchainEvent{}, nil)
r.ServeHTTP(res, req)

assert.Equal(t, 200, res.Result().StatusCode)
}

func TestGetContractEventBadID(t *testing.T) {
func TestGetBlockchainEventBadID(t *testing.T) {
_, r := newTestAPIServer()
req := httptest.NewRequest("GET", "/api/v1/namespaces/mynamespace/contracts/events/bad", nil)
req := httptest.NewRequest("GET", "/api/v1/namespaces/mynamespace/blockchainevents/bad", nil)
req.Header.Set("Content-Type", "application/json; charset=utf-8")
res := httptest.NewRecorder()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ import (
"github.com/hyperledger/firefly/pkg/fftypes"
)

var getContractEvents = &oapispec.Route{
Name: "getContractEvents",
Path: "namespaces/{ns}/contracts/events",
var getBlockchainEvents = &oapispec.Route{
Name: "getBlockchainEvents",
Path: "namespaces/{ns}/blockchainevents",
Method: http.MethodGet,
PathParams: []*oapispec.PathParam{
{Name: "ns", ExampleFromConf: config.NamespacesDefault, Description: i18n.MsgTBD},
Expand All @@ -41,6 +41,6 @@ var getContractEvents = &oapispec.Route{
JSONOutputValue: func() interface{} { return []*fftypes.BlockchainEvent{} },
JSONOutputCodes: []int{http.StatusOK},
JSONHandler: func(r *oapispec.APIRequest) (output interface{}, err error) {
return filterResult(getOr(r.Ctx).Contracts().GetContractEvents(r.Ctx, r.PP["ns"], r.Filter))
return filterResult(getOr(r.Ctx).GetBlockchainEvents(r.Ctx, r.PP["ns"], r.Filter))
},
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,18 @@ import (
"net/http/httptest"
"testing"

"github.com/hyperledger/firefly/mocks/contractmocks"
"github.com/hyperledger/firefly/pkg/fftypes"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
)

func TestGetContractEvents(t *testing.T) {
func TestGetBlockchainEvents(t *testing.T) {
o, r := newTestAPIServer()
mcm := &contractmocks.Manager{}
o.On("Contracts").Return(mcm)
req := httptest.NewRequest("GET", "/api/v1/namespaces/mynamespace/contracts/events", nil)
req := httptest.NewRequest("GET", "/api/v1/namespaces/mynamespace/blockchainevents", nil)
req.Header.Set("Content-Type", "application/json; charset=utf-8")
res := httptest.NewRecorder()

mcm.On("GetContractEvents", mock.Anything, "mynamespace", mock.Anything).
o.On("GetBlockchainEvents", mock.Anything, "mynamespace", mock.Anything).
Return([]*fftypes.BlockchainEvent{}, nil, nil)
r.ServeHTTP(res, req)

Expand Down
4 changes: 2 additions & 2 deletions internal/apiserver/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,6 @@ var routes = []*oapispec.Route{
getContractSubscriptionByNameOrID,
getContractSubscriptions,
deleteContractSubscription,
getContractEvents,
getContractEventByID,
getBlockchainEvents,
getBlockchainEventByID,
}
10 changes: 0 additions & 10 deletions internal/contracts/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ type Manager interface {
GetContractSubscriptionByNameOrID(ctx context.Context, ns, nameOrID string) (*fftypes.ContractSubscription, error)
GetContractSubscriptions(ctx context.Context, ns string, filter database.AndFilter) ([]*fftypes.ContractSubscription, *database.FilterResult, error)
DeleteContractSubscriptionByNameOrID(ctx context.Context, ns, nameOrID string) error
GetContractEventByID(ctx context.Context, id *fftypes.UUID) (*fftypes.BlockchainEvent, error)
GetContractEvents(ctx context.Context, ns string, filter database.AndFilter) ([]*fftypes.BlockchainEvent, *database.FilterResult, error)
}

type contractManager struct {
Expand Down Expand Up @@ -546,14 +544,6 @@ func (cm *contractManager) SubscribeContractAPI(ctx context.Context, ns, apiName
return cm.SubscribeContract(ctx, ns, eventPath, req)
}

func (cm *contractManager) GetContractEventByID(ctx context.Context, id *fftypes.UUID) (*fftypes.BlockchainEvent, error) {
return cm.database.GetBlockchainEventByID(ctx, id)
}

func (cm *contractManager) GetContractEvents(ctx context.Context, ns string, filter database.AndFilter) ([]*fftypes.BlockchainEvent, *database.FilterResult, error) {
return cm.database.GetBlockchainEvents(ctx, cm.scopeNS(ns, filter))
}

func (cm *contractManager) checkParamSchema(ctx context.Context, input interface{}, param *fftypes.FFIParam) error {
// TODO: Cache the compiled schema?
c := jsonschema.NewCompiler()
Expand Down
22 changes: 0 additions & 22 deletions internal/contracts/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1274,28 +1274,6 @@ func TestDeleteContractSubscriptionNotFound(t *testing.T) {
assert.Regexp(t, "FF10109", err)
}

func TestGetContractEventByID(t *testing.T) {
cm := newTestContractManager()
mdi := cm.database.(*databasemocks.Plugin)

id := fftypes.NewUUID()
mdi.On("GetBlockchainEventByID", context.Background(), id).Return(&fftypes.BlockchainEvent{}, nil)

_, err := cm.GetContractEventByID(context.Background(), id)
assert.NoError(t, err)
}

func TestGetContractEvents(t *testing.T) {
cm := newTestContractManager()
mdi := cm.database.(*databasemocks.Plugin)

mdi.On("GetBlockchainEvents", context.Background(), mock.Anything).Return(nil, nil, nil)

f := database.ContractSubscriptionQueryFactory.NewFilter(context.Background())
_, _, err := cm.GetContractEvents(context.Background(), "ns", f.And())
assert.NoError(t, err)
}

func TestInvokeContractAPI(t *testing.T) {
cm := newTestContractManager()
mdb := cm.database.(*databasemocks.Plugin)
Expand Down
10 changes: 9 additions & 1 deletion internal/orchestrator/data_query.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2021 Kaleido, Inc.
// Copyright © 2022 Kaleido, Inc.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down Expand Up @@ -286,3 +286,11 @@ func (or *orchestrator) GetEvents(ctx context.Context, ns string, filter databas
filter = or.scopeNS(ns, filter)
return or.database.GetEvents(ctx, filter)
}

func (or *orchestrator) GetBlockchainEventByID(ctx context.Context, id *fftypes.UUID) (*fftypes.BlockchainEvent, error) {
return or.database.GetBlockchainEventByID(ctx, id)
}

func (or *orchestrator) GetBlockchainEvents(ctx context.Context, ns string, filter database.AndFilter) ([]*fftypes.BlockchainEvent, *database.FilterResult, error) {
return or.database.GetBlockchainEvents(ctx, or.scopeNS(ns, filter))
}
22 changes: 21 additions & 1 deletion internal/orchestrator/data_query_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2021 Kaleido, Inc.
// Copyright © 2022 Kaleido, Inc.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down Expand Up @@ -571,3 +571,23 @@ func TestGetEvents(t *testing.T) {
_, _, err := or.GetEvents(context.Background(), "ns1", f)
assert.NoError(t, err)
}

func TestGetBlockchainEventByID(t *testing.T) {
or := newTestOrchestrator()

id := fftypes.NewUUID()
or.mdi.On("GetBlockchainEventByID", context.Background(), id).Return(&fftypes.BlockchainEvent{}, nil)

_, err := or.GetBlockchainEventByID(context.Background(), id)
assert.NoError(t, err)
}

func TestGetBlockchainEvents(t *testing.T) {
or := newTestOrchestrator()

or.mdi.On("GetBlockchainEvents", context.Background(), mock.Anything).Return(nil, nil, nil)

f := database.ContractSubscriptionQueryFactory.NewFilter(context.Background())
_, _, err := or.GetBlockchainEvents(context.Background(), "ns", f.And())
assert.NoError(t, err)
}
2 changes: 2 additions & 0 deletions internal/orchestrator/orchestrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ type Orchestrator interface {
GetOperations(ctx context.Context, ns string, filter database.AndFilter) ([]*fftypes.Operation, *database.FilterResult, error)
GetEventByID(ctx context.Context, ns, id string) (*fftypes.Event, error)
GetEvents(ctx context.Context, ns string, filter database.AndFilter) ([]*fftypes.Event, *database.FilterResult, error)
GetBlockchainEventByID(ctx context.Context, id *fftypes.UUID) (*fftypes.BlockchainEvent, error)
GetBlockchainEvents(ctx context.Context, ns string, filter database.AndFilter) ([]*fftypes.BlockchainEvent, *database.FilterResult, error)

// Charts
GetChartHistogram(ctx context.Context, ns string, startTime int64, endTime int64, buckets int64, tableName database.CollectionName) ([]*fftypes.ChartHistogram, error)
Expand Down
55 changes: 0 additions & 55 deletions mocks/contractmocks/manager.go

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

55 changes: 55 additions & 0 deletions mocks/orchestratormocks/orchestrator.go

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

23 changes: 1 addition & 22 deletions test/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,32 +304,11 @@ func waitForMessageConfirmed(t *testing.T, c chan *fftypes.EventDelivery, msgTyp
}
}

func waitForChangeEvent(t *testing.T, client *resty.Client, c chan *fftypes.ChangeEvent, match map[string]interface{}) map[string]interface{} {
for {
changeEvent := <-c
if changeEvent.Collection == "events" || changeEvent.Collection == "contractevents" {
event, err := GetChangeEvent(t, client, changeEvent)
if err != nil {
t.Logf("WARN: unable to get changeEvent: %v", err.Error())
continue
}
eventJSON, ok := event.(map[string]interface{})
if !ok {
t.Logf("WARN: unable to parse changeEvent: %v", event)
continue
}
if checkObject(t, match, eventJSON) {
return eventJSON
}
}
}
}

func waitForContractEvent(t *testing.T, client *resty.Client, c chan *fftypes.EventDelivery, match map[string]interface{}) map[string]interface{} {
for {
eventDelivery := <-c
if eventDelivery.Type == fftypes.EventTypeBlockchainEvent {
event, err := GetContractEvent(t, client, eventDelivery.Event.Reference.String())
event, err := GetBlockchainEvent(t, client, eventDelivery.Event.Reference.String())
if err != nil {
t.Logf("WARN: unable to get event: %v", err.Error())
continue
Expand Down
Loading