private JsonRpcResult GetSyncingSubscriptionResult(bool newHead, SyncingSubscription syncingSubscription, BlockEventArgs blockEventArgs) { JsonRpcResult jsonRpcResult = new JsonRpcResult(); ManualResetEvent manualResetEvent = new ManualResetEvent(false); syncingSubscription.JsonRpcDuplexClient.SendJsonRpcResult(Arg.Do <JsonRpcResult>(j => { jsonRpcResult = j; manualResetEvent.Set(); })); if (newHead) { _blockTree.NewHeadBlock += Raise.EventWith(new object(), blockEventArgs); } else { _blockTree.NewBestSuggestedBlock += Raise.EventWith(new object(), blockEventArgs); } manualResetEvent.WaitOne(TimeSpan.FromMilliseconds(100)); return(jsonRpcResult); }
public void SyncingSubscription_on_NewHeadBlock_event_when_sync_no_change() { SyncingSubscription syncingSubscription = GetSyncingSubscription(10042, 10024); Block blockChanged = Build.A.Block.WithNumber(10030).TestObject; BlockEventArgs blockEventArgs = new BlockEventArgs(blockChanged); _blockTree.Head.Returns(blockChanged); JsonRpcResult jsonRpcResult = GetSyncingSubscriptionResult(true, syncingSubscription, blockEventArgs); jsonRpcResult.Response.Should().BeNull(); }
public void SyncingSubscription_on_NewBestSuggestedBlock_event_when_sync_no_change() { SyncingSubscription syncingSubscription = GetSyncingSubscription(10042, 10024); BlockHeader blockHeader = Build.A.BlockHeader.WithNumber(10045).TestObject; Block block = new Block(blockHeader, BlockBody.Empty); BlockEventArgs blockEventArgs = new BlockEventArgs(block); _blockTree.FindBestSuggestedHeader().Returns(blockHeader); JsonRpcResult jsonRpcResult = GetSyncingSubscriptionResult(false, syncingSubscription, blockEventArgs); jsonRpcResult.Response.Should().BeNull(); }
private SyncingSubscription GetSyncingSubscription(int bestSuggested, int head) { BlockHeader blockHeader = Build.A.BlockHeader.WithNumber(bestSuggested).TestObject; _blockTree.FindBestSuggestedHeader().Returns(blockHeader); Block block = Build.A.Block.WithNumber(head).TestObject; _blockTree.Head.Returns(block); SyncingSubscription syncingSubscription = new SyncingSubscription(_jsonRpcDuplexClient, _blockTree, _logManager); return(syncingSubscription); }
public void SyncingSubscription_on_NewHeadBlock_event_when_sync_changed_to_true() { SyncingSubscription syncingSubscription = GetSyncingSubscription(10042, 10040); Block blockChanged = Build.A.Block.WithNumber(10024).TestObject; BlockEventArgs blockEventArgs = new BlockEventArgs(blockChanged); _blockTree.Head.Returns(blockChanged); JsonRpcResult jsonRpcResult = GetSyncingSubscriptionResult(true, syncingSubscription, blockEventArgs); jsonRpcResult.Response.Should().NotBeNull(); string serialized = _jsonSerializer.Serialize(jsonRpcResult.Response); var expectedResult = string.Concat("{\"jsonrpc\":\"2.0\",\"method\":\"eth_subscription\",\"params\":{\"subscription\":\"", syncingSubscription.Id, "\",\"result\":{\"isSyncing\":true,\"startingBlock\":\"0x0\",\"currentBlock\":\"0x2728\",\"highestBlock\":\"0x273a\"}}}"); expectedResult.Should().Be(serialized); }
public void SyncingSubscription_on_NewBestSuggestedBlock_event_when_sync_changed_to_false() { SyncingSubscription syncingSubscription = GetSyncingSubscription(10042, 10024); BlockHeader blockHeader = Build.A.BlockHeader.WithNumber(10030).TestObject; Block block = new Block(blockHeader, BlockBody.Empty); BlockEventArgs blockEventArgs = new BlockEventArgs(block); _blockTree.FindBestSuggestedHeader().Returns(blockHeader); JsonRpcResult jsonRpcResult = GetSyncingSubscriptionResult(false, syncingSubscription, blockEventArgs); jsonRpcResult.Response.Should().NotBeNull(); string serialized = _jsonSerializer.Serialize(jsonRpcResult.Response); var expectedResult = string.Concat("{\"jsonrpc\":\"2.0\",\"method\":\"eth_subscription\",\"params\":{\"subscription\":\"", syncingSubscription.Id, "\",\"result\":false}}"); expectedResult.Should().Be(serialized); }