Exemple #1
0
        public async Task SideChainServerClientsTest()
        {
            string dir = @"/tmp/ServerClientsTest";

            _mock.ClearDirectory(dir);
            try
            {
                GlobalConfig.InvertibleChainHeight = 0;
                var port        = 50052;
                var address     = "127.0.0.1";
                var sideChainId = _mock.MockSideChainServer(port, address, dir);
                var parimpl     = _mock.MockParentChainBlockInfoRpcServerImpl();
                parimpl.Init(Hash.Generate());
                var sideimpl = _mock.MockSideChainBlockInfoRpcServerImpl();
                sideimpl.Init(sideChainId);
                var serverManager = _mock.ServerManager(parimpl, sideimpl);
                serverManager.Init(dir);
                // create client, main chian is client-side
                var manager = _mock.MinerClientManager();
                int t       = 1000;
                GrpcRemoteConfig.Instance.ChildChains = new Dictionary <string, Uri>
                {
                    {
                        sideChainId.DumpHex(), new Uri {
                            Address = address,
                            Port    = port
                        }
                    }
                };
                GrpcLocalConfig.Instance.ClientToSideChain = true;
                manager.Init(dir, t);

                GrpcLocalConfig.Instance.WaitingIntervalInMillisecond = 10;
                Thread.Sleep(t / 2);
                var result = await manager.CollectSideChainBlockInfo();

                int count = result.Count;
                Assert.Equal(1, count);
                Assert.Equal(GlobalConfig.GenesisBlockHeight, result[0].Height);

                Thread.Sleep(t);
                result = await manager.CollectSideChainBlockInfo();

                count = result.Count;
                Assert.Equal(1, count);
                Assert.Equal(GlobalConfig.GenesisBlockHeight + 1, result[0].Height);

                Thread.Sleep(t);
                result = await manager.CollectSideChainBlockInfo();

                count = result.Count;
                Assert.Equal(1, count);
                Assert.Equal(GlobalConfig.GenesisBlockHeight + 2, result[0].Height);
                manager.CloseClientsToSideChain();

                Thread.Sleep(t);
                result = await manager.CollectSideChainBlockInfo();

                count = result.Count;
                Assert.Equal(0, count);
            }
            finally
            {
                Directory.Delete(Path.Combine(dir), true);
            }
        }