Remove mocks for transaction manager and transaction queue

It is very unlikely that there will be 2 or more implementations
of tx manager and queue, as they are tailored specifically to status project
requirements.
This commit is contained in:
Dmitry Shulyak 2018-01-22 11:31:24 +02:00 committed by Frank Mueller
parent 680d0513b7
commit ba0b20e53f
6 changed files with 8 additions and 277 deletions

View File

@ -7,6 +7,7 @@ import (
"github.com/status-im/status-go/geth/common" "github.com/status-im/status-go/geth/common"
"github.com/status-im/status-go/geth/log" "github.com/status-im/status-go/geth/log"
"github.com/status-im/status-go/geth/signal" "github.com/status-im/status-go/geth/signal"
"github.com/status-im/status-go/geth/transactions"
. "github.com/status-im/status-go/testing" //nolint: golint . "github.com/status-im/status-go/testing" //nolint: golint
"github.com/stretchr/testify/suite" "github.com/stretchr/testify/suite"
) )
@ -139,7 +140,7 @@ func (s *BackendTestSuite) LightEthereumService() *les.LightEthereum {
} }
// TxQueueManager returns a reference to the TxQueueManager. // TxQueueManager returns a reference to the TxQueueManager.
func (s *BackendTestSuite) TxQueueManager() common.TxQueueManager { func (s *BackendTestSuite) TxQueueManager() *transactions.Manager {
return s.Backend.TxQueueManager() return s.Backend.TxQueueManager()
} }

View File

@ -9,6 +9,7 @@ import (
"github.com/status-im/status-go/geth/common" "github.com/status-im/status-go/geth/common"
"github.com/status-im/status-go/geth/log" "github.com/status-im/status-go/geth/log"
"github.com/status-im/status-go/geth/params" "github.com/status-im/status-go/geth/params"
"github.com/status-im/status-go/geth/transactions"
) )
// StatusAPI provides API to access Status related functionality. // StatusAPI provides API to access Status related functionality.
@ -45,7 +46,7 @@ func (api *StatusAPI) JailManager() common.JailManager {
} }
// TxQueueManager returns reference to account manager // TxQueueManager returns reference to account manager
func (api *StatusAPI) TxQueueManager() common.TxQueueManager { func (api *StatusAPI) TxQueueManager() *transactions.Manager {
return api.b.TxQueueManager() return api.b.TxQueueManager()
} }

View File

@ -27,7 +27,7 @@ type StatusBackend struct {
nodeReady chan struct{} // channel to wait for when node is fully ready nodeReady chan struct{} // channel to wait for when node is fully ready
nodeManager common.NodeManager nodeManager common.NodeManager
accountManager common.AccountManager accountManager common.AccountManager
txQueueManager common.TxQueueManager txQueueManager *transactions.Manager
jailManager common.JailManager jailManager common.JailManager
newNotification common.NotificationConstructor newNotification common.NotificationConstructor
} }
@ -66,8 +66,8 @@ func (m *StatusBackend) JailManager() common.JailManager {
return m.jailManager return m.jailManager
} }
// TxQueueManager returns reference to jail // TxQueueManager returns reference to transactions manager
func (m *StatusBackend) TxQueueManager() common.TxQueueManager { func (m *StatusBackend) TxQueueManager() *transactions.Manager {
return m.txQueueManager return m.txQueueManager
} }

View File

@ -176,53 +176,6 @@ type SendTxArgs struct {
Nonce *hexutil.Uint64 `json:"nonce"` Nonce *hexutil.Uint64 `json:"nonce"`
} }
// TxQueue is a queue of transactions.
type TxQueue interface {
// Remove removes a transaction from the queue.
Remove(id QueuedTxID)
// Reset resets the state of the queue.
Reset()
// Count returns a number of transactions in the queue.
Count() int
// Has returns true if a transaction is in the queue.
Has(id QueuedTxID) bool
}
// TxQueueManager defines expected methods for managing transaction queue
type TxQueueManager interface {
// Start starts accepting new transaction in the queue.
Start()
// Stop stops accepting new transactions in the queue.
Stop()
// TransactionQueue returns a transaction queue.
TransactionQueue() TxQueue
// QueueTransaction adds a new transaction to the queue.
QueueTransaction(tx *QueuedTx) error
// WaitForTransactions blocks until transaction is completed, discarded or timed out.
WaitForTransaction(tx *QueuedTx) error
SendTransactionRPCHandler(ctx context.Context, args ...interface{}) (interface{}, error)
// CompleteTransaction instructs backend to complete sending of a given transaction
CompleteTransaction(id QueuedTxID, password string) (common.Hash, error)
// CompleteTransactions instructs backend to complete sending of multiple transactions
CompleteTransactions(ids []QueuedTxID, password string) map[QueuedTxID]RawCompleteTransactionResult
// DiscardTransaction discards a given transaction from transaction queue
DiscardTransaction(id QueuedTxID) error
// DiscardTransactions discards given multiple transactions from transaction queue
DiscardTransactions(ids []QueuedTxID) map[QueuedTxID]RawDiscardTransactionResult
}
// JailCell represents single jail cell, which is basically a JavaScript VM. // JailCell represents single jail cell, which is basically a JavaScript VM.
// It's designed to be a transparent wrapper around otto.VM's methods. // It's designed to be a transparent wrapper around otto.VM's methods.
type JailCell interface { type JailCell interface {

View File

@ -5,7 +5,6 @@
package common package common
import ( import (
context "context"
accounts "github.com/ethereum/go-ethereum/accounts" accounts "github.com/ethereum/go-ethereum/accounts"
keystore "github.com/ethereum/go-ethereum/accounts/keystore" keystore "github.com/ethereum/go-ethereum/accounts/keystore"
common "github.com/ethereum/go-ethereum/common" common "github.com/ethereum/go-ethereum/common"
@ -399,229 +398,6 @@ func (mr *MockAccountManagerMockRecorder) AddressToDecryptedAccount(address, pas
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddressToDecryptedAccount", reflect.TypeOf((*MockAccountManager)(nil).AddressToDecryptedAccount), address, password) return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AddressToDecryptedAccount", reflect.TypeOf((*MockAccountManager)(nil).AddressToDecryptedAccount), address, password)
} }
// MockTxQueue is a mock of TxQueue interface
type MockTxQueue struct {
ctrl *gomock.Controller
recorder *MockTxQueueMockRecorder
}
// MockTxQueueMockRecorder is the mock recorder for MockTxQueue
type MockTxQueueMockRecorder struct {
mock *MockTxQueue
}
// NewMockTxQueue creates a new mock instance
func NewMockTxQueue(ctrl *gomock.Controller) *MockTxQueue {
mock := &MockTxQueue{ctrl: ctrl}
mock.recorder = &MockTxQueueMockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use
func (m *MockTxQueue) EXPECT() *MockTxQueueMockRecorder {
return m.recorder
}
// Remove mocks base method
func (m *MockTxQueue) Remove(id QueuedTxID) {
m.ctrl.Call(m, "Remove", id)
}
// Remove indicates an expected call of Remove
func (mr *MockTxQueueMockRecorder) Remove(id interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Remove", reflect.TypeOf((*MockTxQueue)(nil).Remove), id)
}
// Reset mocks base method
func (m *MockTxQueue) Reset() {
m.ctrl.Call(m, "Reset")
}
// Reset indicates an expected call of Reset
func (mr *MockTxQueueMockRecorder) Reset() *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Reset", reflect.TypeOf((*MockTxQueue)(nil).Reset))
}
// Count mocks base method
func (m *MockTxQueue) Count() int {
ret := m.ctrl.Call(m, "Count")
ret0, _ := ret[0].(int)
return ret0
}
// Count indicates an expected call of Count
func (mr *MockTxQueueMockRecorder) Count() *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Count", reflect.TypeOf((*MockTxQueue)(nil).Count))
}
// Has mocks base method
func (m *MockTxQueue) Has(id QueuedTxID) bool {
ret := m.ctrl.Call(m, "Has", id)
ret0, _ := ret[0].(bool)
return ret0
}
// Has indicates an expected call of Has
func (mr *MockTxQueueMockRecorder) Has(id interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Has", reflect.TypeOf((*MockTxQueue)(nil).Has), id)
}
// MockTxQueueManager is a mock of TxQueueManager interface
type MockTxQueueManager struct {
ctrl *gomock.Controller
recorder *MockTxQueueManagerMockRecorder
}
// MockTxQueueManagerMockRecorder is the mock recorder for MockTxQueueManager
type MockTxQueueManagerMockRecorder struct {
mock *MockTxQueueManager
}
// NewMockTxQueueManager creates a new mock instance
func NewMockTxQueueManager(ctrl *gomock.Controller) *MockTxQueueManager {
mock := &MockTxQueueManager{ctrl: ctrl}
mock.recorder = &MockTxQueueManagerMockRecorder{mock}
return mock
}
// EXPECT returns an object that allows the caller to indicate expected use
func (m *MockTxQueueManager) EXPECT() *MockTxQueueManagerMockRecorder {
return m.recorder
}
// Start mocks base method
func (m *MockTxQueueManager) Start() {
m.ctrl.Call(m, "Start")
}
// Start indicates an expected call of Start
func (mr *MockTxQueueManagerMockRecorder) Start() *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Start", reflect.TypeOf((*MockTxQueueManager)(nil).Start))
}
// Stop mocks base method
func (m *MockTxQueueManager) Stop() {
m.ctrl.Call(m, "Stop")
}
// Stop indicates an expected call of Stop
func (mr *MockTxQueueManagerMockRecorder) Stop() *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Stop", reflect.TypeOf((*MockTxQueueManager)(nil).Stop))
}
// TransactionQueue mocks base method
func (m *MockTxQueueManager) TransactionQueue() TxQueue {
ret := m.ctrl.Call(m, "TransactionQueue")
ret0, _ := ret[0].(TxQueue)
return ret0
}
// TransactionQueue indicates an expected call of TransactionQueue
func (mr *MockTxQueueManagerMockRecorder) TransactionQueue() *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "TransactionQueue", reflect.TypeOf((*MockTxQueueManager)(nil).TransactionQueue))
}
// QueueTransaction mocks base method
func (m *MockTxQueueManager) QueueTransaction(tx *QueuedTx) error {
ret := m.ctrl.Call(m, "QueueTransaction", tx)
ret0, _ := ret[0].(error)
return ret0
}
// QueueTransaction indicates an expected call of QueueTransaction
func (mr *MockTxQueueManagerMockRecorder) QueueTransaction(tx interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "QueueTransaction", reflect.TypeOf((*MockTxQueueManager)(nil).QueueTransaction), tx)
}
// WaitForTransaction mocks base method
func (m *MockTxQueueManager) WaitForTransaction(tx *QueuedTx) error {
ret := m.ctrl.Call(m, "WaitForTransaction", tx)
ret0, _ := ret[0].(error)
return ret0
}
// WaitForTransaction indicates an expected call of WaitForTransaction
func (mr *MockTxQueueManagerMockRecorder) WaitForTransaction(tx interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "WaitForTransaction", reflect.TypeOf((*MockTxQueueManager)(nil).WaitForTransaction), tx)
}
// SendTransactionRPCHandler mocks base method
func (m *MockTxQueueManager) SendTransactionRPCHandler(ctx context.Context, args ...interface{}) (interface{}, error) {
varargs := []interface{}{ctx}
for _, a := range args {
varargs = append(varargs, a)
}
ret := m.ctrl.Call(m, "SendTransactionRPCHandler", varargs...)
ret0, _ := ret[0].(interface{})
ret1, _ := ret[1].(error)
return ret0, ret1
}
// SendTransactionRPCHandler indicates an expected call of SendTransactionRPCHandler
func (mr *MockTxQueueManagerMockRecorder) SendTransactionRPCHandler(ctx interface{}, args ...interface{}) *gomock.Call {
varargs := append([]interface{}{ctx}, args...)
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SendTransactionRPCHandler", reflect.TypeOf((*MockTxQueueManager)(nil).SendTransactionRPCHandler), varargs...)
}
// CompleteTransaction mocks base method
func (m *MockTxQueueManager) CompleteTransaction(id QueuedTxID, password string) (common.Hash, error) {
ret := m.ctrl.Call(m, "CompleteTransaction", id, password)
ret0, _ := ret[0].(common.Hash)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// CompleteTransaction indicates an expected call of CompleteTransaction
func (mr *MockTxQueueManagerMockRecorder) CompleteTransaction(id, password interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CompleteTransaction", reflect.TypeOf((*MockTxQueueManager)(nil).CompleteTransaction), id, password)
}
// CompleteTransactions mocks base method
func (m *MockTxQueueManager) CompleteTransactions(ids []QueuedTxID, password string) map[QueuedTxID]RawCompleteTransactionResult {
ret := m.ctrl.Call(m, "CompleteTransactions", ids, password)
ret0, _ := ret[0].(map[QueuedTxID]RawCompleteTransactionResult)
return ret0
}
// CompleteTransactions indicates an expected call of CompleteTransactions
func (mr *MockTxQueueManagerMockRecorder) CompleteTransactions(ids, password interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CompleteTransactions", reflect.TypeOf((*MockTxQueueManager)(nil).CompleteTransactions), ids, password)
}
// DiscardTransaction mocks base method
func (m *MockTxQueueManager) DiscardTransaction(id QueuedTxID) error {
ret := m.ctrl.Call(m, "DiscardTransaction", id)
ret0, _ := ret[0].(error)
return ret0
}
// DiscardTransaction indicates an expected call of DiscardTransaction
func (mr *MockTxQueueManagerMockRecorder) DiscardTransaction(id interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DiscardTransaction", reflect.TypeOf((*MockTxQueueManager)(nil).DiscardTransaction), id)
}
// DiscardTransactions mocks base method
func (m *MockTxQueueManager) DiscardTransactions(ids []QueuedTxID) map[QueuedTxID]RawDiscardTransactionResult {
ret := m.ctrl.Call(m, "DiscardTransactions", ids)
ret0, _ := ret[0].(map[QueuedTxID]RawDiscardTransactionResult)
return ret0
}
// DiscardTransactions indicates an expected call of DiscardTransactions
func (mr *MockTxQueueManagerMockRecorder) DiscardTransactions(ids interface{}) *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DiscardTransactions", reflect.TypeOf((*MockTxQueueManager)(nil).DiscardTransactions), ids)
}
// DisableNotificactions mocks base method
func (m *MockTxQueueManager) DisableNotificactions() {
m.ctrl.Call(m, "DisableNotificactions")
}
// DisableNotificactions indicates an expected call of DisableNotificactions
func (mr *MockTxQueueManagerMockRecorder) DisableNotificactions() *gomock.Call {
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DisableNotificactions", reflect.TypeOf((*MockTxQueueManager)(nil).DisableNotificactions))
}
// MockJailCell is a mock of JailCell interface // MockJailCell is a mock of JailCell interface
type MockJailCell struct { type MockJailCell struct {
ctrl *gomock.Controller ctrl *gomock.Controller

View File

@ -64,7 +64,7 @@ func (m *Manager) Stop() {
} }
// TransactionQueue returns a reference to the queue. // TransactionQueue returns a reference to the queue.
func (m *Manager) TransactionQueue() common.TxQueue { func (m *Manager) TransactionQueue() *queue.TxQueue {
return m.txQueue return m.txQueue
} }