diff --git a/broadcast/asymmetric_test.go b/broadcast/asymmetric_test.go index 776879127b040946b8147c184341cc4860de3296..6a08339d3f5b12ca50f25c3cb6a7e213b860d1bb 100644 --- a/broadcast/asymmetric_test.go +++ b/broadcast/asymmetric_test.go @@ -3,18 +3,22 @@ package broadcast import ( "bytes" "fmt" + "reflect" + "sync" + "testing" + "time" + + "gitlab.com/xx_network/crypto/csprng" + "gitlab.com/xx_network/crypto/signature/rsa" + "gitlab.com/elixxir/client/cmix" "gitlab.com/elixxir/client/cmix/identity/receptionID" + "gitlab.com/elixxir/client/cmix/message" "gitlab.com/elixxir/client/cmix/rounds" crypto "gitlab.com/elixxir/crypto/broadcast" cMixCrypto "gitlab.com/elixxir/crypto/cmix" "gitlab.com/elixxir/crypto/fastRNG" - "gitlab.com/xx_network/crypto/csprng" - "gitlab.com/xx_network/crypto/signature/rsa" - "reflect" - "sync" - "testing" - "time" + "gitlab.com/elixxir/primitives/format" ) // Tests that symmetricClient adheres to the Symmetric interface. @@ -23,6 +27,26 @@ var _ Channel = (*broadcastClient)(nil) // Tests that symmetricClient adheres to the Symmetric interface. var _ Client = (cmix.Client)(nil) +type mockProcessor struct { + messages []format.Message +} + +var _ message.Processor = (*mockProcessor)(nil) + +func newMockProcessor() *mockProcessor { + m := new(mockProcessor) + m.messages = make([]format.Message, 0) + return m +} +func (p *mockProcessor) Process(message format.Message, receptionID receptionID.EphemeralIdentity, + round rounds.Round) { + p.messages = append(p.messages, message) +} + +func (p mockProcessor) String() string { + return "hello" +} + func Test_asymmetricClient_Smoke(t *testing.T) { cMixHandler := newMockCmixHandler() rngGen := fastRNG.NewStreamGenerator(1000, 10, csprng.NewSystemRNG) @@ -46,6 +70,13 @@ func Test_asymmetricClient_Smoke(t *testing.T) { RsaPubKey: cpubkey, } + /// + // must mutate cMixHandler such that it's processorMap contains a + // message.Processor + processor := newMockProcessor() + cMixHandler.processorMap[*cid] = make(map[string][]message.Processor) + cMixHandler.processorMap[*cid]["AsymmBcast"] = []message.Processor{processor} + const n = 5 cbChans := make([]chan []byte, n) clients := make([]Channel, n) diff --git a/broadcast/utils_test.go b/broadcast/utils_test.go index 5d3857be44b5df21852588385440c1e6e25ee0e1..b777807af17cfcb7b3de6e3e13c463ff53e8d7e6 100644 --- a/broadcast/utils_test.go +++ b/broadcast/utils_test.go @@ -8,18 +8,20 @@ package broadcast import ( + "math/rand" + "sync" + "testing" + "time" + + "gitlab.com/xx_network/crypto/signature/rsa" + "gitlab.com/xx_network/primitives/id" + "gitlab.com/xx_network/primitives/id/ephemeral" + "gitlab.com/elixxir/client/cmix" "gitlab.com/elixxir/client/cmix/identity/receptionID" "gitlab.com/elixxir/client/cmix/message" "gitlab.com/elixxir/client/cmix/rounds" "gitlab.com/elixxir/primitives/format" - "gitlab.com/xx_network/crypto/signature/rsa" - "gitlab.com/xx_network/primitives/id" - "gitlab.com/xx_network/primitives/id/ephemeral" - "math/rand" - "sync" - "testing" - "time" ) // newRsaPubKey generates a new random RSA public key for testing. @@ -69,7 +71,10 @@ func (m *mockCmix) GetMaxMessageLength() int { func (m *mockCmix) SendWithAssembler(recipient *id.ID, assembler cmix.MessageAssembler, cmixParams cmix.CMIXParams) (id.Round, ephemeral.Id, error) { - fingerprint, service, payload, mac, _ := assembler(42) + fingerprint, service, payload, mac, err := assembler(42) + if err != nil { + panic(err) + } msg := format.NewMessage(m.numPrimeBytes) msg.SetContents(payload) @@ -78,6 +83,7 @@ func (m *mockCmix) SendWithAssembler(recipient *id.ID, assembler cmix.MessageAss m.handler.Lock() defer m.handler.Unlock() + for _, p := range m.handler.processorMap[*recipient][service.Tag] { p.Process(msg, receptionID.EphemeralIdentity{}, rounds.Round{}) }