diff --git a/Makefile b/Makefile index c5883313..398391fc 100644 --- a/Makefile +++ b/Makefile @@ -73,7 +73,8 @@ mocks: rm -rf mocks; mockery --dir syncer --all --case underscore --outpkg syncer --output mocks/syncer; mockery --dir reconciler --all --case underscore --outpkg reconciler --output mocks/reconciler; - mockery --dir constructor --all --case underscore --outpkg constructor --output mocks/constructor; + mockery --dir constructor/executor --all --case underscore --outpkg executor --output mocks/constructor/executor; + mockery --dir constructor/coordinator --all --case underscore --outpkg coordinator --output mocks/constructor/coordinator; mockery --dir utils --all --case underscore --outpkg utils --output mocks/utils; ${ADDLICENCE_SCRIPT} .; diff --git a/constructor/coordinator/coordinator.go b/constructor/coordinator/coordinator.go index 66daffa5..7234d74a 100644 --- a/constructor/coordinator/coordinator.go +++ b/constructor/coordinator/coordinator.go @@ -345,7 +345,15 @@ func (c *Coordinator) Process( } // Invoke Broadcast storage (in same TX as update job) - if err := c.helper.Broadcast(ctx, dbTransaction, jobIdentifier, broadcast.Network, broadcast.Intent, transactionIdentifier, networkTransaction); err != nil { + if err := c.helper.Broadcast( + ctx, + dbTransaction, + jobIdentifier, + broadcast.Network, + broadcast.Intent, + transactionIdentifier, + networkTransaction, + ); err != nil { return fmt.Errorf("%w: unable to enque broadcast", err) } } diff --git a/constructor/coordinator/errors.go b/constructor/coordinator/errors.go index bd9c3648..edbc4609 100644 --- a/constructor/coordinator/errors.go +++ b/constructor/coordinator/errors.go @@ -1,3 +1,17 @@ +// Copyright 2020 Coinbase, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package coordinator import ( diff --git a/constructor/coordinator/types.go b/constructor/coordinator/types.go index 8f753d1f..fe32a3f3 100644 --- a/constructor/coordinator/types.go +++ b/constructor/coordinator/types.go @@ -23,7 +23,8 @@ const ( NoJobsWaitTime = 10 * time.Second ) -// Helper is used by the worker to process Jobs. +// Helper is used by the coordinator to process Jobs. +// It is a superset of functions required by the constructor/executor.Helper. type Helper interface { // StoreKey is called to persist an // address + KeyPair. diff --git a/constructor/executor/job_test.go b/constructor/executor/job_test.go index d9c7ed69..8761211d 100644 --- a/constructor/executor/job_test.go +++ b/constructor/executor/job_test.go @@ -21,7 +21,7 @@ import ( "regexp" "testing" - mocks "github.com/coinbase/rosetta-sdk-go/mocks/constructor" + mocks "github.com/coinbase/rosetta-sdk-go/mocks/constructor/executor" "github.com/coinbase/rosetta-sdk-go/types" "github.com/stretchr/testify/assert" diff --git a/constructor/executor/worker_test.go b/constructor/executor/worker_test.go index 166cb8b9..cb1b472e 100644 --- a/constructor/executor/worker_test.go +++ b/constructor/executor/worker_test.go @@ -19,7 +19,7 @@ import ( "errors" "testing" - mocks "github.com/coinbase/rosetta-sdk-go/mocks/constructor" + mocks "github.com/coinbase/rosetta-sdk-go/mocks/constructor/executor" "github.com/coinbase/rosetta-sdk-go/types" "github.com/stretchr/testify/assert" @@ -137,7 +137,7 @@ func TestFindBalanceWorker(t *testing.T) { tests := map[string]struct { input *FindBalanceInput - mockHelper *mocks.WorkerHelper + mockHelper *mocks.Helper output *FindBalanceOutput err error @@ -154,8 +154,8 @@ func TestFindBalanceWorker(t *testing.T) { Wait: true, NotAddress: []string{"addr4"}, }, - mockHelper: func() *mocks.WorkerHelper { - helper := &mocks.WorkerHelper{} + mockHelper: func() *mocks.Helper { + helper := &mocks.Helper{} helper.On( "AllAddresses", ctx, @@ -231,8 +231,8 @@ func TestFindBalanceWorker(t *testing.T) { Wait: true, NotAddress: []string{"addr4"}, }, - mockHelper: func() *mocks.WorkerHelper { - helper := &mocks.WorkerHelper{} + mockHelper: func() *mocks.Helper { + helper := &mocks.Helper{} helper.On( "AllAddresses", ctx, @@ -320,8 +320,8 @@ func TestFindBalanceWorker(t *testing.T) { }, }, }, - mockHelper: func() *mocks.WorkerHelper { - helper := &mocks.WorkerHelper{} + mockHelper: func() *mocks.Helper { + helper := &mocks.Helper{} helper.On( "AllAddresses", ctx, @@ -441,8 +441,8 @@ func TestFindBalanceWorker(t *testing.T) { }, Create: -1, }, - mockHelper: func() *mocks.WorkerHelper { - helper := &mocks.WorkerHelper{} + mockHelper: func() *mocks.Helper { + helper := &mocks.Helper{} helper.On( "AllAddresses", ctx, @@ -520,8 +520,8 @@ func TestFindBalanceWorker(t *testing.T) { }, Create: 10, }, - mockHelper: func() *mocks.WorkerHelper { - helper := &mocks.WorkerHelper{} + mockHelper: func() *mocks.Helper { + helper := &mocks.Helper{} helper.On( "AllAddresses", ctx, @@ -599,8 +599,8 @@ func TestFindBalanceWorker(t *testing.T) { }, Create: 2, }, - mockHelper: func() *mocks.WorkerHelper { - helper := &mocks.WorkerHelper{} + mockHelper: func() *mocks.Helper { + helper := &mocks.Helper{} helper.On( "AllAddresses", ctx, @@ -678,7 +678,7 @@ func TestFindBalanceWorker(t *testing.T) { }, Create: 2, }, - mockHelper: &mocks.WorkerHelper{}, + mockHelper: &mocks.Helper{}, err: ErrInvalidInput, }, "invalid currency": { @@ -699,7 +699,7 @@ func TestFindBalanceWorker(t *testing.T) { }, Create: 2, }, - mockHelper: &mocks.WorkerHelper{}, + mockHelper: &mocks.Helper{}, err: ErrInvalidInput, }, } diff --git a/mocks/constructor/helper.go b/mocks/constructor/coordinator/helper.go similarity index 99% rename from mocks/constructor/helper.go rename to mocks/constructor/coordinator/helper.go index 23f77d5b..dd58ab1f 100644 --- a/mocks/constructor/helper.go +++ b/mocks/constructor/coordinator/helper.go @@ -1,11 +1,12 @@ // Code generated by mockery v1.0.0. DO NOT EDIT. -package constructor +package coordinator import ( context "context" keys "github.com/coinbase/rosetta-sdk-go/keys" + mock "github.com/stretchr/testify/mock" storage "github.com/coinbase/rosetta-sdk-go/storage" diff --git a/mocks/constructor/job_storage.go b/mocks/constructor/coordinator/job_storage.go similarity index 76% rename from mocks/constructor/job_storage.go rename to mocks/constructor/coordinator/job_storage.go index 17a4c1c7..dfc207b4 100644 --- a/mocks/constructor/job_storage.go +++ b/mocks/constructor/coordinator/job_storage.go @@ -1,11 +1,11 @@ // Code generated by mockery v1.0.0. DO NOT EDIT. -package constructor +package coordinator import ( context "context" - constructor "github.com/coinbase/rosetta-sdk-go/constructor" + executor "github.com/coinbase/rosetta-sdk-go/constructor/executor" mock "github.com/stretchr/testify/mock" @@ -18,15 +18,15 @@ type JobStorage struct { } // Get provides a mock function with given fields: _a0, _a1, _a2 -func (_m *JobStorage) Get(_a0 context.Context, _a1 storage.DatabaseTransaction, _a2 string) (*constructor.Job, error) { +func (_m *JobStorage) Get(_a0 context.Context, _a1 storage.DatabaseTransaction, _a2 string) (*executor.Job, error) { ret := _m.Called(_a0, _a1, _a2) - var r0 *constructor.Job - if rf, ok := ret.Get(0).(func(context.Context, storage.DatabaseTransaction, string) *constructor.Job); ok { + var r0 *executor.Job + if rf, ok := ret.Get(0).(func(context.Context, storage.DatabaseTransaction, string) *executor.Job); ok { r0 = rf(_a0, _a1, _a2) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*constructor.Job) + r0 = ret.Get(0).(*executor.Job) } } @@ -62,15 +62,15 @@ func (_m *JobStorage) Processing(_a0 context.Context, _a1 string) (int, error) { } // Ready provides a mock function with given fields: _a0 -func (_m *JobStorage) Ready(_a0 context.Context) ([]*constructor.Job, error) { +func (_m *JobStorage) Ready(_a0 context.Context) ([]*executor.Job, error) { ret := _m.Called(_a0) - var r0 []*constructor.Job - if rf, ok := ret.Get(0).(func(context.Context) []*constructor.Job); ok { + var r0 []*executor.Job + if rf, ok := ret.Get(0).(func(context.Context) []*executor.Job); ok { r0 = rf(_a0) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).([]*constructor.Job) + r0 = ret.Get(0).([]*executor.Job) } } @@ -85,18 +85,18 @@ func (_m *JobStorage) Ready(_a0 context.Context) ([]*constructor.Job, error) { } // Update provides a mock function with given fields: _a0, _a1, _a2 -func (_m *JobStorage) Update(_a0 context.Context, _a1 storage.DatabaseTransaction, _a2 *constructor.Job) (string, error) { +func (_m *JobStorage) Update(_a0 context.Context, _a1 storage.DatabaseTransaction, _a2 *executor.Job) (string, error) { ret := _m.Called(_a0, _a1, _a2) var r0 string - if rf, ok := ret.Get(0).(func(context.Context, storage.DatabaseTransaction, *constructor.Job) string); ok { + if rf, ok := ret.Get(0).(func(context.Context, storage.DatabaseTransaction, *executor.Job) string); ok { r0 = rf(_a0, _a1, _a2) } else { r0 = ret.Get(0).(string) } var r1 error - if rf, ok := ret.Get(1).(func(context.Context, storage.DatabaseTransaction, *constructor.Job) error); ok { + if rf, ok := ret.Get(1).(func(context.Context, storage.DatabaseTransaction, *executor.Job) error); ok { r1 = rf(_a0, _a1, _a2) } else { r1 = ret.Error(1) diff --git a/mocks/constructor/executor/helper.go b/mocks/constructor/executor/helper.go new file mode 100644 index 00000000..2f8a0d24 --- /dev/null +++ b/mocks/constructor/executor/helper.go @@ -0,0 +1,154 @@ +// Code generated by mockery v1.0.0. DO NOT EDIT. + +package executor + +import ( + context "context" + + keys "github.com/coinbase/rosetta-sdk-go/keys" + + mock "github.com/stretchr/testify/mock" + + types "github.com/coinbase/rosetta-sdk-go/types" +) + +// Helper is an autogenerated mock type for the Helper type +type Helper struct { + mock.Mock +} + +// AllAddresses provides a mock function with given fields: ctx +func (_m *Helper) AllAddresses(ctx context.Context) ([]string, error) { + ret := _m.Called(ctx) + + var r0 []string + if rf, ok := ret.Get(0).(func(context.Context) []string); ok { + r0 = rf(ctx) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func(context.Context) error); ok { + r1 = rf(ctx) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// Balance provides a mock function with given fields: _a0, _a1 +func (_m *Helper) Balance(_a0 context.Context, _a1 *types.AccountIdentifier) ([]*types.Amount, error) { + ret := _m.Called(_a0, _a1) + + var r0 []*types.Amount + if rf, ok := ret.Get(0).(func(context.Context, *types.AccountIdentifier) []*types.Amount); ok { + r0 = rf(_a0, _a1) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*types.Amount) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func(context.Context, *types.AccountIdentifier) error); ok { + r1 = rf(_a0, _a1) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// Coins provides a mock function with given fields: _a0, _a1 +func (_m *Helper) Coins(_a0 context.Context, _a1 *types.AccountIdentifier) ([]*types.Coin, error) { + ret := _m.Called(_a0, _a1) + + var r0 []*types.Coin + if rf, ok := ret.Get(0).(func(context.Context, *types.AccountIdentifier) []*types.Coin); ok { + r0 = rf(_a0, _a1) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]*types.Coin) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func(context.Context, *types.AccountIdentifier) error); ok { + r1 = rf(_a0, _a1) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// Derive provides a mock function with given fields: _a0, _a1, _a2, _a3 +func (_m *Helper) Derive(_a0 context.Context, _a1 *types.NetworkIdentifier, _a2 *types.PublicKey, _a3 map[string]interface{}) (string, map[string]interface{}, error) { + ret := _m.Called(_a0, _a1, _a2, _a3) + + var r0 string + if rf, ok := ret.Get(0).(func(context.Context, *types.NetworkIdentifier, *types.PublicKey, map[string]interface{}) string); ok { + r0 = rf(_a0, _a1, _a2, _a3) + } else { + r0 = ret.Get(0).(string) + } + + var r1 map[string]interface{} + if rf, ok := ret.Get(1).(func(context.Context, *types.NetworkIdentifier, *types.PublicKey, map[string]interface{}) map[string]interface{}); ok { + r1 = rf(_a0, _a1, _a2, _a3) + } else { + if ret.Get(1) != nil { + r1 = ret.Get(1).(map[string]interface{}) + } + } + + var r2 error + if rf, ok := ret.Get(2).(func(context.Context, *types.NetworkIdentifier, *types.PublicKey, map[string]interface{}) error); ok { + r2 = rf(_a0, _a1, _a2, _a3) + } else { + r2 = ret.Error(2) + } + + return r0, r1, r2 +} + +// LockedAddresses provides a mock function with given fields: _a0 +func (_m *Helper) LockedAddresses(_a0 context.Context) ([]string, error) { + ret := _m.Called(_a0) + + var r0 []string + if rf, ok := ret.Get(0).(func(context.Context) []string); ok { + r0 = rf(_a0) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]string) + } + } + + var r1 error + if rf, ok := ret.Get(1).(func(context.Context) error); ok { + r1 = rf(_a0) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// StoreKey provides a mock function with given fields: _a0, _a1, _a2 +func (_m *Helper) StoreKey(_a0 context.Context, _a1 string, _a2 *keys.KeyPair) error { + ret := _m.Called(_a0, _a1, _a2) + + var r0 error + if rf, ok := ret.Get(0).(func(context.Context, string, *keys.KeyPair) error); ok { + r0 = rf(_a0, _a1, _a2) + } else { + r0 = ret.Error(0) + } + + return r0 +}