Exemplo n.º 1
0
        public void RPCSendRPCException()
        {
            if (noClient)
            {
                return;
            }

            using (var builder = NodeBuilderXels.Create())
            {
                CoreNodeXels node = builder.CreateNode();
                builder.StartAll();
                RPCClient rpcClient = node.CreateRPCClient();
                try
                {
                    rpcClient.SendCommand("whatever");
                    Assert.False(true, "Should have thrown");
                }
                catch (RPCException ex)
                {
                    if (ex.RPCCode != RPCErrorCode.RPC_METHOD_NOT_FOUND)
                    {
                        Assert.False(true, "Should have thrown RPC_METHOD_NOT_FOUND");
                    }
                }
            }
        }
Exemplo n.º 2
0
        public void CanSendCommand()
        {
            if (noClient)
            {
                return;
            }

            using (var builder = NodeBuilderXels.Create())
            {
                RPCClient rpc = builder.CreateNode().CreateRPCClient();
                builder.StartAll();
                RPCResponse response = rpc.SendCommand(RPCOperations.getinfo);
                Assert.NotNull(response.Result);
            }
        }
Exemplo n.º 3
0
        public void CanGetTransactionBlockFromRPC()
        {
            if (noClient)
            {
                return;
            }

            using (var builder = NodeBuilderXels.Create())
            {
                RPCClient rpc = builder.CreateNode().CreateRPCClient();
                builder.StartAll();
                uint256  blockId = rpc.GetBestBlockHash();
                RPCBlock block   = rpc.GetRPCBlockAsync(blockId).Result;
                Assert.NotNull(block);
            }
        }
Exemplo n.º 4
0
        public void CanGetGenesisFromRPC()
        {
            if (noClient)
            {
                return;
            }

            using (var builder = NodeBuilderXels.Create())
            {
                RPCClient rpc = builder.CreateNode().CreateRPCClient();
                builder.StartAll();
                RPCResponse response      = rpc.SendCommand(RPCOperations.getblockhash, 0);
                var         actualGenesis = (string)response.Result;
                Assert.Equal(Network.XelsMain.GetGenesis().GetHash().ToString(), actualGenesis);
                //Assert.Equal(Network.XelsMain.GetGenesis().GetHash(), rpc.GetBestBlockHash());
            }
        }
Exemplo n.º 5
0
        public void InvalidCommandSendRPCException()
        {
            if (noClient)
            {
                return;
            }

            using (var builder = NodeBuilderXels.Create())
            {
                RPCClient rpc = builder.CreateNode().CreateRPCClient();
                builder.StartAll();
                AssertException <RPCException>(() => rpc.SendCommand("donotexist"), (ex) =>
                {
                    Assert.True(ex.RPCCode == RPCErrorCode.RPC_METHOD_NOT_FOUND);
                });
            }
        }
Exemplo n.º 6
0
        public void CanUseAsyncRPC()
        {
            if (noClient)
            {
                return;
            }

            using (var builder = NodeBuilderXels.Create())
            {
                CoreNodeXels node = builder.CreateNode();
                RPCClient    rpc  = node.CreateRPCClient();
                builder.StartAll();
                ////node.Generate(10);
                var blkCount = rpc.GetBlockCountAsync().Result;
                Assert.True(blkCount > 10);
            }
        }
Exemplo n.º 7
0
        public void CanGetBlockFromRPC()
        {
            if (noClient)
            {
                return;
            }

            using (var builder = NodeBuilderXels.Create())
            {
                RPCClient rpc = builder.CreateNode().CreateRPCClient();
                builder.StartAll();
                BlockHeader response = rpc.GetBlockHeader(0);
                AssertEx.CollectionEquals(Network.XelsMain.GetGenesis().Header.ToBytes(), response.ToBytes());

                response = rpc.GetBlockHeader(0);
                Assert.Equal(Network.XelsMain.GenesisHash, response.GetHash());
            }
        }
Exemplo n.º 8
0
 public CoreNodeXels(string folder, NodeBuilderXels builder)
 {
     this._Builder = builder;
     this._Folder  = folder;
     //_State = CoreNodeState.Stopped;
     //CleanFolder();
     //Directory.CreateDirectory(folder);
     //dataDir = Path.Combine(folder, "data");
     //Directory.CreateDirectory(dataDir);
     //var pass = Encoders.Hex.EncodeData(RandomUtils.GetBytes(20));
     //creds = new NetworkCredential(pass, pass);
     //_Config = Path.Combine(dataDir, "bitcoin.conf");
     //ConfigParameters.Import(builder.ConfigParameters);
     ports = new int[2];
     FindPorts(ports);
     //ports[1] = Network.XelsMain.RPCPort;
     //ports[0] = Network.XelsMain.DefaultPort;
 }
Exemplo n.º 9
0
        public void CanGetRawMemPool()
        {
            if (noClient)
            {
                return;
            }

            using (var builder = NodeBuilderXels.Create())
            {
                CoreNodeXels node = builder.CreateNode();
                RPCClient    rpc  = node.CreateRPCClient();
                builder.StartAll();
                ////node.Generate(101);
                //var txid = rpc.SendToAddress(new Key().PubKey.GetAddress(rpc.Network), Money.Coins(1.0m), "hello", "world");
                uint256[] ids = rpc.GetRawMempool();
                Assert.NotNull(ids);
                //Assert.Equal(txid, ids[0]);
            }
        }
Exemplo n.º 10
0
        public void RawTransactionIsConformsToRPC()
        {
            if (noClient)
            {
                return;
            }

            using (var builder = NodeBuilderXels.Create())
            {
                CoreNodeXels node = builder.CreateNode();
                builder.StartAll();

                RPCClient rpc = node.CreateRPCClient();
                var       tx  = Transaction.Parse("01000000ac55a957010000000000000000000000000000000000000000000000000000000000000000ffffffff0401320103ffffffff010084d717000000001976a9143ac0dad2ad42e35fcd745d7511d47c24ad6580b588ac00000000");

                Transaction tx2 = rpc.GetRawTransaction(uint256.Parse("a6783a0933942d37dcb5fb923ddd343522036de23fbc658f2ad2a9f1428ca19d"));
                Assert.Equal(tx.GetHash(), tx2.GetHash());
            }
        }
Exemplo n.º 11
0
        public void CanAddNodes()
        {
            if (noClient)
            {
                return;
            }

            using (var builder = NodeBuilderXels.Create())
            {
                CoreNodeXels nodeA = builder.CreateNode();
                CoreNodeXels nodeB = builder.CreateNode();
                builder.StartAll();

                RPCClient rpc = nodeA.CreateRPCClient();
                rpc.RemoveNode(nodeA.Endpoint);
                rpc.AddNode(nodeB.Endpoint);
                Thread.Sleep(500);

                AddedNodeInfo[] info = rpc.GetAddedNodeInfo(true);
                Assert.NotNull(info);
                Assert.NotEmpty(info);

                //For some reason this one does not pass anymore in 0.13.1.
                //Assert.Equal(nodeB.Endpoint, info.First().Addresses.First().Address);
                AddedNodeInfo oneInfo = rpc.GetAddedNodeInfo(true, nodeB.Endpoint);
                Assert.NotNull(oneInfo);
                Assert.True(oneInfo.AddedNode.ToString() == nodeB.Endpoint.ToString());

                oneInfo = rpc.GetAddedNodeInfo(true, nodeA.Endpoint);
                Assert.Null(oneInfo);

                //rpc.RemoveNode(nodeB.Endpoint);
                //Thread.Sleep(500);
                //info = rpc.GetAddedNodeInfo(true);
                //Assert.Equal(0, info.Count());
            }
        }