From 8b56cb7bfa233b340f3f7f84f439a3ac3e70f92d Mon Sep 17 00:00:00 2001 From: Samuel Hawksby-Robinson Date: Thu, 27 Jan 2022 09:52:13 +0000 Subject: [PATCH] Smoke test on API and signals --- services/local_pairing/api.go | 29 ++++++++++++++++++++++++++++ services/local_pairing/events.go | 25 ++++++++++++++++++++++++ services/local_pairing/service.go | 32 +++++++++++++++++++++++++++++++ signal/events_pairing.go | 10 ++++++++++ 4 files changed, 96 insertions(+) create mode 100644 services/local_pairing/api.go create mode 100644 services/local_pairing/events.go create mode 100644 services/local_pairing/service.go create mode 100644 signal/events_pairing.go diff --git a/services/local_pairing/api.go b/services/local_pairing/api.go new file mode 100644 index 000000000..12b4b351d --- /dev/null +++ b/services/local_pairing/api.go @@ -0,0 +1,29 @@ +package local_pairing + +import ( + "time" + + "github.com/status-im/status-go/signal" +) + +func NewAPI() *API { + return &API{} +} + +type API struct {} + +func (a *API) StartSendingServer(password string) (string, error){ + + go func() { + time.Sleep(time.Second) + signal.SendLocalPairingEvent(Event{Type: EventConnectionSuccess}) + + time.Sleep(time.Second) + signal.SendLocalPairingEvent(Event{Type: EventTransferSuccess}) + + time.Sleep(time.Second) + signal.SendLocalPairingEvent(Event{Type: EventSuccess}) + }() + + return password, nil +} \ No newline at end of file diff --git a/services/local_pairing/events.go b/services/local_pairing/events.go new file mode 100644 index 000000000..a66c84ffa --- /dev/null +++ b/services/local_pairing/events.go @@ -0,0 +1,25 @@ +package local_pairing + +// EventType type for event types. +type EventType string + +const ( + EventConnectionError EventType = "connection-error" + + EventConnectionSuccess EventType = "connection-success" + + EventTransferError EventType = "transfer-error" + + EventTransferSuccess EventType = "transfer-success" + + EventDecryptionError EventType = "decryption-error" + + EventInstallationError EventType = "installation-error" + + EventSuccess EventType = "success" +) + +// Event is a type for transfer events. +type Event struct { + Type EventType `json:"type"` +} diff --git a/services/local_pairing/service.go b/services/local_pairing/service.go new file mode 100644 index 000000000..6ee93db4f --- /dev/null +++ b/services/local_pairing/service.go @@ -0,0 +1,32 @@ +package local_pairing + +import ( + "github.com/ethereum/go-ethereum/p2p" + "github.com/ethereum/go-ethereum/rpc" +) + +type Service struct {} + +func (s *Service) Start() error { + return nil +} + +func (s *Service) Stop() error { + return nil +} + +func (s *Service) APIs() []rpc.API { + return []rpc.API{ + { + Namespace: "localPairing", + Version: "0.1.0", + Service: NewAPI(), + Public: true, + }, + } +} + +func (s *Service) Protocols() []p2p.Protocol { + return nil +} + diff --git a/signal/events_pairing.go b/signal/events_pairing.go new file mode 100644 index 000000000..4a87e17b9 --- /dev/null +++ b/signal/events_pairing.go @@ -0,0 +1,10 @@ +package signal + +const ( + localPairingEvent = "localPairing" +) + +// SendLocalPairingEvent sends event from services/pairing/events. +func SendLocalPairingEvent(event interface{}) { + send(localPairingEvent, event) +}