예제 #1
0
        public void Copiar_blockchain_de_otro_nodo_en_ejecucion_con_2_bloques()
        {
            using (var loggerFactory = CreateLoggerFactory())
            {
                var channel = new PeerChannelInProc();
                var node1   = new Node(new NodeOptions("Nodo 1", "1111", 1, 2000, "http://localhost:8001"), new BlockBuilder(), loggerFactory, channel);
                var node2   = new Node(new NodeOptions("Nodo 2", "1234", 1, 2000, "http://localhost:8002"), new BlockBuilder(), loggerFactory, channel);
                channel.Add(node1);
                channel.Add(node2);

                Assert.AreEqual(1, node1.ChainLength);

                var community = new Community {
                    Id = Guid.NewGuid(), Name = "My Company", Address = new byte[] { 1, 2, 3 }
                };
                var keys = CryptoService.Instance.GeneratePair();
                signer.Sign(community, keys);

                node1.Add(community);
                node1.MinePendingTransactions();

                Assert.AreEqual(2, node1.ChainLength);

                Assert.AreEqual(1, node2.ChainLength);
                node2.Connect(node1.Host.PublicUrl);
                node2.Syncronize();

                Assert.AreEqual(2, node2.ChainLength);
            }
        }
예제 #2
0
        public void Copiar_blockchain_de_otros_nodos_en_ejecucion_x3_con_5_bloques()
        {
            using (var loggerFactory = CreateLoggerFactory())
            {
                var owner         = CryptoService.Instance.GeneratePair();
                var communityKeys = CryptoService.Instance.GeneratePair();

                var channel = new PeerChannelInProc();
                var node1   = new Node(new NodeOptions("Nodo 1", "1111", 1, 2000, "http://localhost:8001"), new BlockBuilder(), loggerFactory, channel);
                var node2   = new Node(new NodeOptions("Nodo 2", "2222", 1, 2000, "http://localhost:8002"), new BlockBuilder(), loggerFactory, channel);
                var node3   = new Node(new NodeOptions("Mi Nodo", "3333", 1, 2000, "http://localhost:8003"), new BlockBuilder(), loggerFactory, channel);
                channel.Add(node1);
                channel.Add(node2);
                channel.Add(node3);

                node1.Start();

                node2.Start();
                node2.Connect($"http://{host1}:{port1}");
                node2.Syncronize();

                Assert.AreEqual(1, node1.ChainLength);
                Assert.AreEqual(1, node2.ChainLength);

                var community = new Community {
                    Id = Guid.NewGuid(), Name = "My Company", Address = new byte[] { 1, 2, 3 }
                };
                community.SetAddress(communityKeys.PublicKey);

                signer.Sign(community, owner);

                node1.Add(community);
                node1.MinePendingTransactions();

                Assert.AreEqual(2, node1.ChainLength);

                var question = new Question {
                    CommunityId = community.Id, Name = "My Question"
                };
                signer.Sign(question, communityKeys);
                node1.Add(question);
                node1.MinePendingTransactions();

                Assert.AreEqual(3, node1.ChainLength);
                Assert.AreEqual(1, node3.ChainLength);

                node3.Start();
                node3.Connect($"http://{host1}:{port1}");
                Assert.AreEqual(1, node3.Peers.Count);
                node3.Connect($"http://{host2}:{port2}");
                Assert.AreEqual(2, node3.Peers.Count);

                node3.Syncronize();
                Assert.AreEqual(3, node3.ChainLength);
            }
        }
예제 #3
0
        public void Mensaje_entre_red_de_3_nodos()
        {
            using (var loggerFactory = CreateLoggerFactory())
            {
                var channel = new PeerChannelInProc();
                var node1   = new Node(new NodeOptions("Nodo 1", "1111", 1, 2000, "http://localhost:8001"), new BlockBuilder(), loggerFactory, channel);
                var node2   = new Node(new NodeOptions("Nodo 2", "2222", 1, 2000, "http://localhost:8002"), new BlockBuilder(), loggerFactory, channel);
                var node3   = new Node(new NodeOptions("Nodo 3", "3333", 1, 2000, "http://localhost:8003"), new BlockBuilder(), loggerFactory, channel);
                channel.Add(node1);
                channel.Add(node2);
                channel.Add(node3);

                node1.Connect(node2.Host.PublicUrl);
                Assert.AreEqual(1, node1.Peers.Count);
                Assert.AreEqual(1, node2.Peers.Count);
                Assert.AreEqual(0, node3.Peers.Count);

                node2.Connect(node3.Host.PublicUrl);
                Assert.AreEqual(1, node1.Peers.Count);
                Assert.AreEqual(2, node2.Peers.Count);
                Assert.AreEqual(1, node3.Peers.Count);

                node3.Discovery();
                Assert.AreEqual(2, node1.Peers.Count);
                Assert.AreEqual(2, node2.Peers.Count);
                Assert.AreEqual(2, node3.Peers.Count);

                node2.Syncronize();
                node3.Syncronize();

                node1.Add(new Community {
                    Address = new byte[] { 1, 2, 3 }
                });
                Assert.AreEqual(1, node2.Pendings.Count());
                Assert.AreEqual(1, node3.Pendings.Count());
            }
        }