Example #1
0
        public RpcServerChannelFactoryTests()
        {
            _testScheduler      = new TestScheduler();
            _correlationManager = Substitute.For <IRpcMessageCorrelationManager>();
            _keySigner          = Substitute.For <FakeKeySigner>();
            _keySigner.CryptoContext.SignatureLength.Returns(64);

            var authenticationStrategy = Substitute.For <IAuthenticationStrategy>();

            authenticationStrategy.Authenticate(Arg.Any <PeerId>()).Returns(true);

            var peerSettings = Substitute.For <IPeerSettings>();

            peerSettings.NetworkType.Returns(NetworkType.Devnet);

            var peerIdValidator = Substitute.For <IPeerIdValidator>();

            peerIdValidator.ValidatePeerIdFormat(Arg.Any <PeerId>()).Returns(true);
            _factory = new TestRpcServerChannelFactory(
                _correlationManager,
                _keySigner,
                authenticationStrategy,
                peerIdValidator,
                peerSettings,
                _testScheduler);
        }
Example #2
0
        public void Init()
        {
            _testScheduler      = new TestScheduler();
            _correlationManager = Substitute.For <IPeerMessageCorrelationManager>();
            _gossipManager      = Substitute.For <IBroadcastManager>();
            _keySigner          = Substitute.For <FakeKeySigner>();

            var peerSettings = Substitute.For <IPeerSettings>();

            peerSettings.NetworkType.Returns(NetworkType.Devnet);
            var peerValidator = Substitute.For <IPeerIdValidator>();

            peerValidator.ValidatePeerIdFormat(Arg.Any <PeerId>()).Returns(true);

            _factory = new TestPeerServerChannelFactory(
                _correlationManager,
                _gossipManager,
                _keySigner,
                peerValidator,
                peerSettings,
                _testScheduler);
            _senderId      = PeerIdHelper.GetPeerId("sender");
            _correlationId = CorrelationId.GenerateCorrelationId();
            _signature     = ByteUtil.GenerateRandomByteArray(new FfiWrapper().SignatureLength);
            _keySigner.Verify(Arg.Any <ISignature>(), Arg.Any <byte[]>(), default)
            .ReturnsForAnyArgs(true);
        }
        public BroadcastManagerTests()
        {
            _senderPeerId = PeerIdHelper.GetPeerId("sender");
            _keySigner    = Substitute.For <FakeKeySigner>();
            var fakeSignature = Substitute.For <ISignature>();

            _keySigner.Sign(Arg.Any <byte[]>(), default).ReturnsForAnyArgs(fakeSignature);
            _keySigner.CryptoContext.SignatureLength.Returns(64);
            _peers        = new PeerRepository(new InMemoryRepository <Peer, string>());
            _cache        = new MemoryCache(new MemoryCacheOptions());
            _peerSettings = _senderPeerId.ToSubstitutedPeerSettings();
        }
        public ProtocolMessageSignHandlerTests()
        {
            _fakeContext = Substitute.For <IChannelHandlerContext>();
            _keySigner   = Substitute.For <FakeKeySigner>();
            _signature   = Substitute.For <ISignature>();

            _signature.SignatureBytes.Returns(ByteUtil.GenerateRandomByteArray(new FfiWrapper().SignatureLength));
            _signature.PublicKeyBytes.Returns(ByteUtil.GenerateRandomByteArray(new FfiWrapper().PublicKeyLength));

            _dto = new MessageDto(new PingRequest().ToProtocolMessage(PeerIdHelper.GetPeerId("sender")),
                                  PeerIdHelper.GetPeerId("recipient")
                                  );
        }
Example #5
0
        public void Init()
        {
            _fakeContext    = Substitute.For <IChannelHandlerContext>();
            _keySigner      = Substitute.For <FakeKeySigner>();
            _signingContext = DevNetPeerSigningContext.Instance;

            var signatureBytes = ByteUtil.GenerateRandomByteArray(new FfiWrapper().SignatureLength);
            var publicKeyBytes = ByteUtil.GenerateRandomByteArray(new FfiWrapper().PublicKeyLength);
            var peerId         = PeerIdHelper.GetPeerId(publicKeyBytes);

            _protocolMessageSigned = new PingRequest()
                                     .ToSignedProtocolMessage(peerId, signatureBytes, _signingContext)
                                     .ToSignedProtocolMessage(peerId, signatureBytes, _signingContext);
        }
        public void Init()
        {
            _testScheduler      = new TestScheduler();
            _correlationManager = Substitute.For <IRpcMessageCorrelationManager>();
            _keySigner          = Substitute.For <FakeKeySigner>();

            var peerIdValidator = Substitute.For <IPeerIdValidator>();

            peerIdValidator.ValidatePeerIdFormat(Arg.Any <PeerId>()).Returns(true);

            var peerSettings = Substitute.For <IPeerSettings>();

            peerSettings.NetworkType.Returns(NetworkType.Devnet);

            _factory = new TestRpcClientChannelFactory(_keySigner, _correlationManager, peerIdValidator,
                                                       peerSettings, _testScheduler);
        }
        public void Init()
        {
            _keySigner = Substitute.For <FakeKeySigner>();
            _keySigner.Verify(Arg.Any <ISignature>(), Arg.Any <byte[]>(), default).ReturnsForAnyArgs(true);
            _fakeBroadcastManager = Substitute.For <IBroadcastManager>();
            _broadcastHandler     = new BroadcastHandler(_fakeBroadcastManager);

            var fakeSignature = Substitute.For <ISignature>();

            fakeSignature.SignatureBytes.Returns(ByteUtil.GenerateRandomByteArray(new FfiWrapper().SignatureLength));

            _signingContext = DevNetPeerSigningContext.Instance;

            var peerId       = PeerIdHelper.GetPeerId("Test");
            var innerMessage = new TransactionBroadcast();

            _broadcastMessageSigned = innerMessage
                                      .ToSignedProtocolMessage(peerId, fakeSignature, _signingContext)
                                      .ToSignedProtocolMessage(peerId, fakeSignature, _signingContext);
        }
Example #8
0
        public PeerClientChannelFactoryTests()
        {
            _testScheduler            = new TestScheduler();
            _serverCorrelationManager = Substitute.For <IPeerMessageCorrelationManager>();
            _serverKeySigner          = Substitute.For <FakeKeySigner>();
            _serverKeySigner.CryptoContext.SignatureLength.Returns(64);
            var broadcastManager = Substitute.For <IBroadcastManager>();

            _peerIdValidator = Substitute.For <IPeerIdValidator>();

            var peerSettings = Substitute.For <IPeerSettings>();

            peerSettings.NetworkType.Returns(NetworkType.Devnet);

            var serverFactory = new UnitTests.P2P.IO.Transport.Channels.PeerServerChannelFactoryTests.TestPeerServerChannelFactory(
                _serverCorrelationManager,
                broadcastManager,
                _serverKeySigner,
                _peerIdValidator,
                peerSettings,
                _testScheduler);

            _signature = Substitute.For <ISignature>();

            _clientCorrelationManager = Substitute.For <IPeerMessageCorrelationManager>();
            _clientKeySigner          = Substitute.For <FakeKeySigner>();
            _clientKeySigner.CryptoContext.SignatureLength.Returns(64);

            _clientFactory = new UnitTests.P2P.IO.Transport.Channels.PeerClientChannelFactoryTests.TestPeerClientChannelFactory(
                _clientKeySigner,
                _clientCorrelationManager,
                _peerIdValidator,
                peerSettings,
                _testScheduler);

            _serverChannel =
                new EmbeddedChannel("server".ToChannelId(), true, serverFactory.InheritedHandlers.ToArray());

            _clientChannel =
                new EmbeddedChannel("client".ToChannelId(), true, _clientFactory.InheritedHandlers.ToArray());
        }
        public RpcClientChannelFactoryTests()
        {
            _testScheduler            = new TestScheduler();
            _serverCorrelationManager = Substitute.For <IRpcMessageCorrelationManager>();
            _serverKeySigner          = Substitute.For <FakeKeySigner>();
            _serverKeySigner.CryptoContext.SignatureLength.Returns(64);

            _authenticationStrategy = Substitute.For <IAuthenticationStrategy>();

            _peerIdValidator = Substitute.For <IPeerIdValidator>();
            var peerSettings = Substitute.For <IPeerSettings>();

            peerSettings.NetworkType.Returns(NetworkType.Devnet);

            _serverFactory = new UnitTests.Rpc.IO.Transport.Channels.RpcServerChannelFactoryTests.TestRpcServerChannelFactory(
                _serverCorrelationManager,
                _serverKeySigner,
                _authenticationStrategy,
                _peerIdValidator,
                peerSettings,
                _testScheduler);

            _clientCorrelationManager = Substitute.For <IRpcMessageCorrelationManager>();
            _clientKeySigner          = Substitute.For <FakeKeySigner>();
            _clientKeySigner.CryptoContext.SignatureLength.Returns(64);
            var clientFactory =
                new UnitTests.Rpc.IO.Transport.Channels.RpcClientChannelFactoryTests.TestRpcClientChannelFactory(
                    _clientKeySigner,
                    _clientCorrelationManager,
                    _peerIdValidator,
                    peerSettings,
                    _testScheduler);

            _serverChannel =
                new EmbeddedChannel("server".ToChannelId(), true, _serverFactory.InheritedHandlers.ToArray());

            _clientChannel =
                new EmbeddedChannel("client".ToChannelId(), true, clientFactory.InheritedHandlers.ToArray());
        }