Пример #1
0
        public async Task RequestCrossChainData_Test()
        {
            var chainId       = ChainHelper.GetChainId(ChainHelper.ConvertBase58ToChainId("AELF") + 1);
            var remoteChainId = ChainOptions.ChainId;
            var height        = 2;
            var port          = 5000;
            await Server.StartAsync(port);

            var grpcClientInitializationContext = new GrpcClientInitializationContext
            {
                RemoteChainId = chainId,
                LocalChainId  = ChainHelper.ConvertBase58ToChainId("AELF"),
                DialTimeout   = 1000,
                UriStr        = string.Concat(Host, ":", port)
            };
            var client = new ClientForSideChain(grpcClientInitializationContext);

            _grpcCrossChainCommunicationTestHelper.GrpcCrossChainClients.TryAdd(remoteChainId, client);
            _grpcCrossChainCommunicationTestHelper.FakeSideChainBlockDataEntityCacheOnServerSide(height);
            await client.RequestCrossChainDataAsync(height, b => _blockCacheEntityProducer.TryAddBlockCacheEntity(b));

            var clientBlockDataEntityCache = GrpcCrossChainCommunicationTestHelper.ClientBlockDataEntityCache;
            var sideChainBlockData         = new SideChainBlockData {
                Height = height
            };

            Assert.Contains(sideChainBlockData, clientBlockDataEntityCache);
            Dispose();
        }
Пример #2
0
 protected GrpcCrossChainClient(GrpcClientInitializationContext grpcClientInitializationContext)
 {
     _localChainId    = grpcClientInitializationContext.LocalChainId;
     RemoteChainId    = grpcClientInitializationContext.RemoteChainId;
     DialTimeout      = grpcClientInitializationContext.DialTimeout;
     Channel          = CreateChannel(grpcClientInitializationContext.UriStr);
     _basicGrpcClient = new BasicCrossChainRpc.BasicCrossChainRpcClient(Channel);
     _listeningPort   = grpcClientInitializationContext.ListeningPort;
 }
Пример #3
0
        public async Task RequestChainInitializationData_ParentClient_Test()
        {
            var chainId = ChainHelper.GetChainId(ChainHelper.ConvertBase58ToChainId("AELF") + 1);
            await Server.StartAsync(5000);

            var grpcClientInitializationContext = new GrpcClientInitializationContext
            {
                LocalChainId  = chainId,
                RemoteChainId = ChainHelper.ConvertBase58ToChainId("AELF"),
                DialTimeout   = 1000,
                UriStr        = string.Concat(Host, ":", "5000")
            };
            var client = new ClientForParentChain(grpcClientInitializationContext);
            var res    = await client.RequestChainInitializationDataAsync(chainId);

            Assert.Equal(1, res.CreationHeightOnParentChain);
            Dispose();
        }
Пример #4
0
        private ICrossChainClient CreateClient(CrossChainClientCreationContext crossChainClientCreationContext)
        {
            var clientInitializationContext = new GrpcClientInitializationContext
            {
                DialTimeout   = _grpcCrossChainConfigOption.ConnectionTimeout,
                LocalChainId  = crossChainClientCreationContext.LocalChainId,
                ListeningPort = _grpcCrossChainConfigOption.ListeningPort,
                RemoteChainId = crossChainClientCreationContext.RemoteChainId
            };

            if (crossChainClientCreationContext.IsClientToParentChain)
            {
                clientInitializationContext.UriStr = GetUriStr(_grpcCrossChainConfigOption.ParentChainServerIp,
                                                               _grpcCrossChainConfigOption.ParentChainServerPort);
                return(new ClientForParentChain(clientInitializationContext));
            }

            clientInitializationContext.UriStr = GetUriStr(crossChainClientCreationContext.RemoteServerHost,
                                                           crossChainClientCreationContext.RemoteServerPort);
            return(new ClientForSideChain(clientInitializationContext));
        }
Пример #5
0
 public ClientForParentChain(GrpcClientInitializationContext grpcClientInitializationContext)
     : base(grpcClientInitializationContext)
 {
     GrpcClient = new ParentChainRpc.ParentChainRpcClient(Channel);
 }
Пример #6
0
 public ClientForSideChain(GrpcClientInitializationContext grpcClientInitializationContext)
     : base(grpcClientInitializationContext)
 {
     GrpcClient = new SideChainRpc.SideChainRpcClient(Channel);
 }