Esempio n. 1
0
        public async Task Put_Informs_Bitswap()
        {
            _dfs = TestDfs.GetTestDfs(null, "sha2-256");
            await _dfs.StartAsync();

            try
            {
                var data = Guid.NewGuid().ToByteArray();
                var cid  = new Cid
                {
                    Hash = MultiHash.ComputeHash(data)
                };

                var cts = new CancellationTokenSource();
                cts.CancelAfter(20000);

                var wantTask = _dfs.BitSwapApi.GetAsync(cid, cts.Token);
                var cid1     = await _dfs.BlockApi.PutAsync(data, cancel : cts.Token);

                Assert.AreEqual(cid, cid1);
                Assert.AreEqual(cid, wantTask.Result.Id);
                Assert.AreEqual(data.Length, wantTask.Result.Size);
                Assert.AreEqual(data, wantTask.Result.DataBytes);
            }
            finally
            {
                await _dfs.StopAsync();
            }
        }
Esempio n. 2
0
 public async Task Can_Use_Private_Node()
 {
     using (var ipfs = TestDfs.GetTestDfs())
     {
         ipfs.Options.Discovery.BootstrapPeers = new MultiAddress[0];
         ipfs.Options.Swarm.PrivateNetworkKey  = new PreSharedKey().Generate();
         await _dfs1.StartAsync();
     }
 }
Esempio n. 3
0
        public async Task Read_From_OtherNode()
        {
            using (var a = TestDfs.GetTestDfs())
            {
                using (var b = TestDfs.GetTestDfs())
                {
                    using (var c = TestDfs.GetTestDfs())
                    {
                        var psk = new PreSharedKey().Generate();

                        // Start bootstrap node.
                        b.Options.Discovery.DisableMdns    = true;
                        b.Options.Swarm.MinConnections     = 0;
                        b.Options.Swarm.PrivateNetworkKey  = psk;
                        b.Options.Discovery.BootstrapPeers = new MultiAddress[0];
                        await b.StartAsync();

                        var bootstrapPeers = new[]
                        {
                            b.LocalPeer.Addresses.First()
                        };
                        TestContext.WriteLine($"B is {b.LocalPeer}");

                        // Node that has the content.
                        c.Options.Discovery.DisableMdns    = true;
                        c.Options.Swarm.MinConnections     = 0;
                        c.Options.Swarm.PrivateNetworkKey  = psk;
                        c.Options.Discovery.BootstrapPeers = bootstrapPeers;
                        await c.StartAsync();

                        await c.SwarmApi.ConnectAsync(bootstrapPeers[0]);

                        TestContext.WriteLine($"C is {c.LocalPeer}");

                        var fsn = await c.UnixFsApi.AddTextAsync("some content");

                        var cid = fsn.Id;

                        // Node that reads the content.
                        a.Options.Discovery.DisableMdns    = true;
                        a.Options.Swarm.MinConnections     = 0;
                        a.Options.Swarm.PrivateNetworkKey  = psk;
                        a.Options.Discovery.BootstrapPeers = bootstrapPeers;
                        await a.StartAsync();

                        TestContext.WriteLine($"A is {a.LocalPeer}");
                        var cts     = new CancellationTokenSource(TimeSpan.FromSeconds(30));
                        var content = await a.UnixFsApi.ReadAllTextAsync(cid, cts.Token);

                        Assert.AreEqual("some content", content);
                    }
                }
            }
        }
Esempio n. 4
0
        public void Init()
        {
            this.Setup(TestContext.CurrentContext);
            ContainerProvider.Container.Resolve <IHashProvider>();

            var passwordReader = Substitute.For <IPasswordManager>();

            passwordReader.RetrieveOrPromptAndAddPasswordToRegistry(Arg.Any <PasswordRegistryTypes>(), Arg.Any <string>())
            .Returns(TestPasswordReader.BuildSecureStringPassword("abcd"));

            Substitute.For <ILogger>();

            _dfs1 = TestDfs.GetTestDfs();
            _dfs2 = TestDfs.GetTestDfs();
        }
Esempio n. 5
0
        public void Init()
        {
            var fileSystem1 = Substitute.For <IFileSystem>();

            fileSystem1.GetCatalystDataDir().Returns(new DirectoryInfo(Path.Combine(Environment.CurrentDirectory,
                                                                                    $"dfs1-_{DateTime.Now:yyMMddHHmmssffff}")));

            var fileSystem2 = Substitute.For <IFileSystem>();

            fileSystem2.GetCatalystDataDir().Returns(new DirectoryInfo(Path.Combine(Environment.CurrentDirectory,
                                                                                    $"dfs2-_{DateTime.Now:yyMMddHHmmssffff}")));

            _dfsService      = TestDfs.GetTestDfs(fileSystem1);
            _dfsServiceOther = TestDfs.GetTestDfs(fileSystem2);
        }
Esempio n. 6
0
        public void Init()
        {
            this.Setup(TestContext.CurrentContext);

            ContainerProvider.ConfigureContainerBuilder(true, true, true);

            var context = new FfiWrapper();

            _endOfTestCancellationSource = new CancellationTokenSource();

            var poaNodeDetails = Enumerable.Range(0, 3).Select(i =>
            {
                var fileSystem = Substitute.For <IFileSystem>();
                var path       = Path.Combine(FileSystem.GetCatalystDataDir().FullName, $"producer{i}");
                fileSystem.GetCatalystDataDir().Returns(new DirectoryInfo(path));

                var privateKey     = context.GeneratePrivateKey();
                var publicKey      = privateKey.GetPublicKey();
                var nodeSettings   = PeerSettingsHelper.TestPeerSettings(publicKey.Bytes, 2000 + i);
                var peerIdentifier = nodeSettings.PeerId;
                var name           = $"producer{i.ToString()}";
                var dfs            = TestDfs.GetTestDfs(fileSystem);
                return(new { index = i, name, privateKey, nodeSettings, peerIdentifier, dfs, fileSystem });
            }
                                                               ).ToList();

            var peerIdentifiers = poaNodeDetails.Select(n => n.peerIdentifier).ToList();

            _nodes = new List <PoaTestNode>();
            foreach (var nodeDetails in poaNodeDetails)
            {
                nodeDetails.dfs.Options.Discovery.BootstrapPeers = poaNodeDetails.Select(x => x.dfs.LocalPeer.Addresses.First());
                var node = new PoaTestNode(nodeDetails.name,
                                           nodeDetails.privateKey,
                                           nodeDetails.nodeSettings,
                                           nodeDetails.dfs,
                                           peerIdentifiers.Except(new[] { nodeDetails.peerIdentifier }),
                                           nodeDetails.fileSystem);

                _nodes.Add(node);
            }
        }
Esempio n. 7
0
 public ObjectApiTest()
 {
     ipfs = TestDfs.GetTestDfs(null, "sha2-256");
 }
Esempio n. 8
0
 public BlockApiTest()
 {
     _dfs = TestDfs.GetTestDfs(null, "sha2-256");
 }
Esempio n. 9
0
 public async Task Can_Dispose()
 {
     using var node = TestDfs.GetTestDfs();
     await node.StartAsync();
 }
 public BlockRepositoryApiTest()
 {
     ipfs = TestDfs.GetTestDfs();
 }
Esempio n. 11
0
 public NameApiTest()
 {
     ipfs = TestDfs.GetTestDfs(null, "sha2-256");
 }
Esempio n. 12
0
 public PinApiTest()
 {
     _dfs = TestDfs.GetTestDfs();
 }
Esempio n. 13
0
        public DhtApiTest()
        {
            ipfs = TestDfs.GetTestDfs();

            _locaId = ipfs.LocalPeer.Id;
        }
Esempio n. 14
0
 public PubSubApiTest()
 {
     ipfs = TestDfs.GetTestDfs();
 }
Esempio n. 15
0
 public DagApiTest()
 {
     _dfs = TestDfs.GetTestDfs(null, "sha2-256");
 }
Esempio n. 16
0
 public void Init()
 {
     ipfs = TestDfs.GetTestDfs(null, "sha2-256");
 }
Esempio n. 17
0
 public StatsApiTest()
 {
     _dfs = TestDfs.GetTestDfs();
 }
Esempio n. 18
0
 public MigrationManagerTest()
 {
     _dfs = TestDfs.GetTestDfs();
 }
Esempio n. 19
0
 public BootstapApiTest()
 {
     ipfs = TestDfs.GetTestDfs();
 }