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

            using (var builder = NodeBuilderPurple.Create())
            {
                CoreNodePurple 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");
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public void RawTransactionIsConformsToRPC()
        {
            using (var builder = NodeBuilderPurple.Create())
            {
                RPCClient rpc = builder.CreateNode().CreateRPCClient();
                builder.StartAll();
                var tx = Transaction.Parse("01000000ac55a957010000000000000000000000000000000000000000000000000000000000000000ffffffff0401320103ffffffff010084d717000000001976a9143ac0dad2ad42e35fcd745d7511d47c24ad6580b588ac00000000");

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

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

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

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

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

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

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

                response = rpc.GetBlockHeader(0);
                Assert.Equal(Network.PurpleMain.GenesisHash, response.GetHash());
            }
        }
Ejemplo n.º 9
0
        public void CanGetRawMemPool()
        {
            if (noClient)
            {
                return;
            }

            using (var builder = NodeBuilderPurple.Create())
            {
                CoreNodePurple 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]);
            }
        }
Ejemplo n.º 10
0
        public void CanAddNodes()
        {
            if (noClient)
            {
                return;
            }

            using (var builder = NodeBuilderPurple.Create())
            {
                CoreNodePurple nodeA = builder.CreateNode();
                CoreNodePurple 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());
            }
        }