public void Case_sensitivity_test() { IEthRpcModule ethRpcModule = Substitute.For<IEthRpcModule>(); ethRpcModule.eth_chainId().ReturnsForAnyArgs(ResultWrapper<ulong>.Success(1ul)); TestRequest(ethRpcModule, "eth_chainID").Should().BeOfType<JsonRpcErrorResponse>(); TestRequest(ethRpcModule, "eth_chainId").Should().BeOfType<JsonRpcSuccessResponse>(); }
public void GetNewFilterTest() { IEthRpcModule ethRpcModule = Substitute.For <IEthRpcModule>(); ethRpcModule.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(ethRpcModule, "eth_newFilter", JsonConvert.SerializeObject(parameters)) as JsonRpcSuccessResponse; Assert.AreEqual(UInt256.One, response?.Result); }
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); }
public async Task Ensure_returning_shared_does_not_change_concurrency() { IEthRpcModule shared = await _modulePool.GetModule(true); _modulePool.ReturnModule(shared); await _modulePool.GetModule(false); Assert.ThrowsAsync <ModuleRentalTimeoutException>(() => _modulePool.GetModule(false)); }
public async Task Can_rent_and_return_in_a_loop(bool canBeShared) { for (int i = 0; i < 1000; i++) { IEthRpcModule ethRpcModule = await _modulePool.GetModule(canBeShared); _modulePool.ReturnModule(ethRpcModule); } }
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); }
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")); }
public void GetBlockByNumberTest() { IEthRpcModule ethRpcModule = Substitute.For <IEthRpcModule>(); ethRpcModule.eth_getBlockByNumber(Arg.Any <BlockParameter>(), true).ReturnsForAnyArgs(x => ResultWrapper <BlockForRpc> .Success(new BlockForRpc(Build.A.Block.WithNumber(2).TestObject, true))); JsonRpcSuccessResponse response = TestRequest(ethRpcModule, "eth_getBlockByNumber", "0x1b4", "true") as JsonRpcSuccessResponse; Assert.AreEqual(2L, (response?.Result as BlockForRpc)?.Number); }
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); }
public async Task Ensure_that_shared_is_never_returned_as_exclusive() { IEthRpcModule sharedRpcModule = await _modulePool.GetModule(true); _modulePool.ReturnModule(sharedRpcModule); const int iterations = 1000; Func <Task> rentReturnShared = async() => { for (int i = 0; i < iterations; i++) { TestContext.Out.WriteLine($"Rent shared {i}"); IEthRpcModule ethRpcModule = await _modulePool.GetModule(true); Assert.AreSame(sharedRpcModule, ethRpcModule); _modulePool.ReturnModule(ethRpcModule); TestContext.Out.WriteLine($"Return shared {i}"); } }; Func <Task> rentReturnExclusive = async() => { for (int i = 0; i < iterations; i++) { TestContext.Out.WriteLine($"Rent exclusive {i}"); IEthRpcModule ethRpcModule = await _modulePool.GetModule(false); Assert.AreNotSame(sharedRpcModule, ethRpcModule); _modulePool.ReturnModule(ethRpcModule); TestContext.Out.WriteLine($"Return exclusive {i}"); } }; Task a = Task.Run(rentReturnExclusive); Task b = Task.Run(rentReturnExclusive); Task c = Task.Run(rentReturnShared); Task d = Task.Run(rentReturnShared); await Task.WhenAll(a, b, c, d); }
public async Task Can_rent_and_return(bool canBeShared) { IEthRpcModule ethRpcModule = await _modulePool.GetModule(canBeShared); _modulePool.ReturnModule(ethRpcModule); }