Exemple #1
0
        public void Found()
        {
            var bitswap = new Bitswap {
                Swarm = new Swarm {
                    LocalPeer = self
                }
            };

            Assert.AreEqual(0, bitswap.PeerWants(self.Id).Count());

            var a      = new DagNode(Encoding.UTF8.GetBytes("BitswapTest found block a"));
            var b      = new DagNode(Encoding.UTF8.GetBytes("BitswapTest found block b"));
            var cancel = new CancellationTokenSource();
            var task   = bitswap.Want(a.Id, self.Id, cancel.Token);

            Assert.IsFalse(task.IsCompleted);
            CollectionAssert.Contains(bitswap.PeerWants(self.Id).ToArray(), a.Id);

            bitswap.Found(b);
            Assert.IsFalse(task.IsCompleted);
            CollectionAssert.Contains(bitswap.PeerWants(self.Id).ToArray(), a.Id);

            bitswap.Found(a);
            Assert.IsTrue(task.IsCompleted);
            CollectionAssert.DoesNotContain(bitswap.PeerWants(self.Id).ToArray(), a.Id);
            CollectionAssert.AreEqual(a.DataBytes, task.Result.DataBytes);
        }
Exemple #2
0
        public void Want_Unwant()
        {
            var bitswap = new Bitswap {
                Swarm = new Swarm {
                    LocalPeer = self
                }
            };
            var cid    = new DagNode(Encoding.UTF8.GetBytes("BitswapTest unknown block")).Id;
            var cancel = new CancellationTokenSource();
            var task   = bitswap.Want(cid, self.Id, cancel.Token);

            CollectionAssert.Contains(bitswap.PeerWants(self.Id).ToArray(), cid);

            bitswap.Unwant(cid);
            Assert.IsTrue(task.IsCanceled);
            CollectionAssert.DoesNotContain(bitswap.PeerWants(self.Id).ToArray(), cid);
        }