コード例 #1
0
 public void Web3ShaTest()
 {
     IWeb3RpcModule web3RpcModule = Substitute.For<IWeb3RpcModule>();
     web3RpcModule.web3_sha3(Arg.Any<byte[]>()).ReturnsForAnyArgs(x => ResultWrapper<Keccak>.Success(TestItem.KeccakA));
     JsonRpcSuccessResponse response = TestRequest(web3RpcModule, "web3_sha3", "0x68656c6c6f20776f726c64") as JsonRpcSuccessResponse;
     Assert.AreEqual(TestItem.KeccakA, response?.Result);
 }
コード例 #2
0
        public void GetNewFilterTest()
        {
            IEthModule ethModule = Substitute.For <IEthModule>();

            ethModule.eth_newFilter(Arg.Any <Filter>()).ReturnsForAnyArgs(x => ResultWrapper <UInt256?> .Success(1));

            var parameters = new
            {
                fromBlock = "0x1",
                toBlock   = "latest",
                address   = "0x1f88f1f195afa192cfee860698584c030f4c9db2",
                topics    = new List <object>
                {
                    "0x000000000000000000000000a94f5374fce5edbc8e2a8697c15331677e6ebf0b", null,
                    new[]
                    {
                        "0x000000000000000000000000a94f5374fce5edbc8e2a8697c15331677e6ebf0b",
                        "0x0000000000000000000000000aff3454fce5edbc8cca8697c15331677e6ebccc"
                    }
                }
            };

            JsonRpcSuccessResponse response = TestRequest(ethModule, "eth_newFilter", JsonConvert.SerializeObject(parameters)) as JsonRpcSuccessResponse;

            Assert.AreEqual(UInt256.One, response?.Result);
        }
コード例 #3
0
        public void Test_data_dir()
        {
            string serialized = RpcTest.TestSerializedRequest(_adminRpcModule, "admin_dataDir");
            JsonRpcSuccessResponse response = _serializer.Deserialize <JsonRpcSuccessResponse>(serialized);

            response.Result.Should().Be(_exampleDataDir);
        }
コード例 #4
0
 public void Eth_module_populates_size_when_returning_block_data()
 {
     IEthRpcModule ethRpcModule = Substitute.For<IEthRpcModule>();
     ISpecProvider specProvider = Substitute.For<ISpecProvider>();
     ethRpcModule.eth_getBlockByNumber(Arg.Any<BlockParameter>(), true).ReturnsForAnyArgs(x => ResultWrapper<BlockForRpc>.Success(new BlockForRpc(Build.A.Block.WithNumber(2).TestObject, true, specProvider)));
     JsonRpcSuccessResponse response = TestRequest(ethRpcModule, "eth_getBlockByNumber", "0x1b4", "true") as JsonRpcSuccessResponse;
     Assert.AreEqual(513L, (response?.Result as BlockForRpc)?.Size);
 }
コード例 #5
0
 public void NetVersionTest()
 {
     INetRpcModule netRpcModule = Substitute.For<INetRpcModule>();
     netRpcModule.net_version().ReturnsForAnyArgs(x => ResultWrapper<string>.Success("1"));
     JsonRpcSuccessResponse response = TestRequest(netRpcModule, "net_version") as JsonRpcSuccessResponse;
     Assert.AreEqual(response?.Result, "1");
     Assert.IsNotInstanceOf<JsonRpcErrorResponse>(response);
 }
コード例 #6
0
 public void GetWorkTest()
 {
     IEthRpcModule ethRpcModule = Substitute.For<IEthRpcModule>();
     ethRpcModule.eth_getWork().ReturnsForAnyArgs(x => ResultWrapper<IEnumerable<byte[]>>.Success(new[] {Bytes.FromHexString("aa"), Bytes.FromHexString("01")}));
     JsonRpcSuccessResponse response = TestRequest(ethRpcModule, "eth_getWork") as JsonRpcSuccessResponse;
     byte[][] dataList = response?.Result as byte[][];
     Assert.NotNull(dataList?.SingleOrDefault(d => d.ToHexString(true) == "0xaa"));
     Assert.NotNull(dataList?.SingleOrDefault(d => d.ToHexString(true) == "0x01"));
 }
コード例 #7
0
 public void CanHandleOptionalArguments()
 {
     EthereumJsonSerializer serializer = new EthereumJsonSerializer();
     string serialized = serializer.Serialize(new TransactionForRpc());
     IEthRpcModule ethRpcModule = Substitute.For<IEthRpcModule>();
     ethRpcModule.eth_call(Arg.Any<TransactionForRpc>()).ReturnsForAnyArgs(x => ResultWrapper<string>.Success("0x1"));
     JsonRpcSuccessResponse response = TestRequest(ethRpcModule, "eth_call", serialized) as JsonRpcSuccessResponse;
     Assert.AreEqual("0x1", response?.Result);
 }
コード例 #8
0
        public void GetBlockByNumberTest()
        {
            IEthModule ethModule = Substitute.For <IEthModule>();

            ethModule.eth_getBlockByNumber(Arg.Any <BlockParameter>(), true).ReturnsForAnyArgs(x => ResultWrapper <BlockForRpc> .Success(new BlockForRpc(Build.A.Block.WithNumber(2).TestObject, true)));
            JsonRpcSuccessResponse response = TestRequest(ethModule, "eth_getBlockByNumber", "0x1b4", "true") as JsonRpcSuccessResponse;

            Assert.AreEqual(2L, (response?.Result as BlockForRpc)?.Number);
        }
コード例 #9
0
        public void Get_from_db_null_value()
        {
            byte[] key = new byte[] { 1, 2, 3 };
            debugBridge.GetDbValue(Arg.Any <string>(), Arg.Any <byte[]>()).Returns((byte[])null);

            IConfigProvider        configProvider = Substitute.For <IConfigProvider>();
            DebugRpcModule         rpcModule      = new DebugRpcModule(LimboLogs.Instance, debugBridge, jsonRpcConfig);
            JsonRpcSuccessResponse response       = RpcTest.TestRequest <IDebugRpcModule>(rpcModule, "debug_getFromDb", "STATE", key.ToHexString(true)) as JsonRpcSuccessResponse;

            Assert.NotNull(response);
        }
コード例 #10
0
        public void Get_block_rlp_by_hash()
        {
            BlockDecoder decoder = new BlockDecoder();
            Rlp          rlp     = decoder.Encode(Build.A.Block.WithNumber(1).TestObject);

            debugBridge.GetBlockRlp(Keccak.Zero).Returns(rlp.Bytes);

            DebugRpcModule         rpcModule = new DebugRpcModule(LimboLogs.Instance, debugBridge, jsonRpcConfig);
            JsonRpcSuccessResponse response  = RpcTest.TestRequest <IDebugRpcModule>(rpcModule, "debug_getBlockRlpByHash", $"{Keccak.Zero.Bytes.ToHexString()}") as JsonRpcSuccessResponse;

            Assert.AreEqual(rlp.Bytes, (byte[])response?.Result);
        }
コード例 #11
0
        public void Get_from_db()
        {
            byte[] key   = new byte[] { 1, 2, 3 };
            byte[] value = new byte[] { 4, 5, 6 };
            debugBridge.GetDbValue(Arg.Any <string>(), Arg.Any <byte[]>()).Returns(value);

            IConfigProvider        configProvider = Substitute.For <IConfigProvider>();
            DebugRpcModule         rpcModule      = new(LimboLogs.Instance, debugBridge, jsonRpcConfig);
            JsonRpcSuccessResponse response       = RpcTest.TestRequest <IDebugRpcModule>(rpcModule, "debug_getFromDb", "STATE", key.ToHexString(true)) as JsonRpcSuccessResponse;

            byte[] result = response.Result as byte[];
        }
コード例 #12
0
        public void Eth_call_is_working_with_explicit_null_as_the_last_argument(string nullValue)
        {
            EthereumJsonSerializer serializer   = new();
            IEthRpcModule          ethRpcModule = Substitute.For <IEthRpcModule>();

            ethRpcModule.eth_call(Arg.Any <TransactionForRpc>(), Arg.Any <BlockParameter?>()).ReturnsForAnyArgs(x => ResultWrapper <string> .Success("0x"));

            string serialized = serializer.Serialize(new TransactionForRpc());

            JsonRpcSuccessResponse response = TestRequest(ethRpcModule, "eth_call", serialized, nullValue) as JsonRpcSuccessResponse;

            Assert.AreEqual("0x", response?.Result);
        }
コード例 #13
0
        public void Get_block_rlp_by_hash()
        {
            BlockDecoder decoder     = new BlockDecoder();
            IDebugBridge debugBridge = Substitute.For <IDebugBridge>();
            Rlp          rlp         = decoder.Encode(Build.A.Block.WithNumber(1).TestObject);

            debugBridge.GetBlockRlp(Keccak.Zero).Returns(rlp.Bytes);

            DebugModule            module   = new DebugModule(NullLogManager.Instance, debugBridge);
            JsonRpcSuccessResponse response = RpcTest.TestRequest <IDebugModule>(module, "debug_getBlockRlpByHash", $"{Keccak.Zero.Bytes.ToHexString()}") as JsonRpcSuccessResponse;

            Assert.AreEqual(rlp.Bytes, (byte[])response?.Result);
        }
コード例 #14
0
        public void Get_block_rlp()
        {
            BlockDecoder decoder     = new BlockDecoder();
            IDebugBridge debugBridge = Substitute.For <IDebugBridge>();
            Rlp          rlp         = decoder.Encode(Build.A.Block.WithNumber(1).TestObject);

            debugBridge.GetBlockRlp(1).Returns(rlp.Bytes);

            DebugRpcModule         rpcModule = new DebugRpcModule(LimboLogs.Instance, debugBridge, jsonRpcConfig);
            JsonRpcSuccessResponse response  = RpcTest.TestRequest <IDebugRpcModule>(rpcModule, "debug_getBlockRlp", "1") as JsonRpcSuccessResponse;

            Assert.AreEqual(rlp.Bytes, (byte[])response?.Result);
        }
コード例 #15
0
        public void Get_transaction_receipt(bool includeHeader)
        {
            Keccak txHash = TestItem.KeccakA;
            JsonRpcSuccessResponse response = new JsonRpcSuccessResponse
            {
                Id     = "id1",
                Result = "result",
            };

            _jsonRpcClient.Post <object>("proof_getTransactionReceipt", txHash, includeHeader)
            .Returns(_serializer.Serialize(response));

            JsValue value = _engine.Execute($"proof.getTransactionReceipt(\"{txHash}\", {(includeHeader ? "true" : "false")})");

            Colorful.Console.WriteLine(_serializer.Serialize(value.ToObject(), true));
            Assert.AreNotEqual(JsValue.Null, value);
        }
コード例 #16
0
        public void Get_chain_level(string parameter)
        {
            debugBridge.GetLevelInfo(1).Returns(
                new ChainLevelInfo(
                    true,
                    new[]
            {
                new BlockInfo(TestItem.KeccakA, 1000),
                new BlockInfo(TestItem.KeccakB, 1001),
            }));

            DebugRpcModule         rpcModule  = new DebugRpcModule(LimboLogs.Instance, debugBridge, jsonRpcConfig);
            JsonRpcSuccessResponse response   = RpcTest.TestRequest <IDebugRpcModule>(rpcModule, "debug_getChainLevel", parameter) as JsonRpcSuccessResponse;
            ChainLevelForRpc       chainLevel = response?.Result as ChainLevelForRpc;

            Assert.NotNull(chainLevel);
            Assert.AreEqual(true, chainLevel.HasBlockOnMainChain);
            Assert.AreEqual(2, chainLevel.BlockInfos.Length);
        }
コード例 #17
0
        public void Get_chain_level(string parameter)
        {
            IDebugBridge debugBridge = Substitute.For <IDebugBridge>();

            debugBridge.GetLevelInfo(1).Returns(
                new ChainLevelInfo(
                    true,
                    new[]
            {
                new BlockInfo(TestItem.KeccakA, 1000),
                new BlockInfo(TestItem.KeccakB, 1001),
            }));

            DebugModule            module     = new DebugModule(NullLogManager.Instance, debugBridge);
            JsonRpcSuccessResponse response   = RpcTest.TestRequest <IDebugModule>(module, "debug_getChainLevel", parameter) as JsonRpcSuccessResponse;
            ChainLevelForRpc       chainLevel = response?.Result as ChainLevelForRpc;

            Assert.NotNull(chainLevel);
            Assert.AreEqual(true, chainLevel.HasBlockOnMainChain);
            Assert.AreEqual(2, chainLevel.BlockInfos.Length);
        }
コード例 #18
0
        public void Call()
        {
            Keccak            blockHash = TestItem.KeccakA;
            TransactionForRpc tx        = new TransactionForRpc
            {
                From = TestItem.AddressA,
                To   = TestItem.AddressB
            };

            JsonRpcSuccessResponse response = new JsonRpcSuccessResponse
            {
                Id     = "id1",
                Result = "result",
            };

            _jsonRpcClient.Post <object>("proof_call", Arg.Any <ExpandoObject>(), blockHash.ToString())
            .Returns(_serializer.Serialize(response));

            JsValue value = _engine.Execute($"proof.call({_serializer.Serialize(tx)}, \"{blockHash}\")");

            Colorful.Console.WriteLine(_serializer.Serialize(value.ToObject(), true));
            Assert.AreNotEqual(JsValue.Null, value);
        }
コード例 #19
0
        public void Test_node_info()
        {
            string serialized = RpcTest.TestSerializedRequest(_adminRpcModule, "admin_nodeInfo");
            JsonRpcSuccessResponse response = _serializer.Deserialize <JsonRpcSuccessResponse>(serialized);
            JsonSerializerSettings settings = new JsonSerializerSettings();

            settings.Converters = EthereumJsonSerializer.CommonConverters.ToList();

            NodeInfo nodeInfo = ((JObject)response.Result).ToObject <NodeInfo>(JsonSerializer.Create(settings));

            nodeInfo.Enode.Should().Be(_enodeString);
            nodeInfo.Id.Should().Be("ae3623ef35c06ab49e9ae4b9f5a2b0f1983c28f85de1ccc98e2174333fdbdf1f");
            nodeInfo.Ip.Should().Be("127.0.0.1");
            nodeInfo.Name.Should().Be(ClientVersion.Description);
            nodeInfo.ListenAddress.Should().Be("127.0.0.1:30303");
            nodeInfo.Ports.Discovery.Should().Be(_networkConfig.DiscoveryPort);
            nodeInfo.Ports.Listener.Should().Be(_networkConfig.P2PPort);

            nodeInfo.Protocols.Should().HaveCount(1);
            nodeInfo.Protocols["eth"].Difficulty.Should().Be(_blockTree.Head.TotalDifficulty ?? 0);
            nodeInfo.Protocols["eth"].HeadHash.Should().Be(_blockTree.HeadHash);
            nodeInfo.Protocols["eth"].GenesisHash.Should().Be(_blockTree.GenesisHash);
            nodeInfo.Protocols["eth"].ChainId.Should().Be(_blockTree.ChainId);
        }