public static async Task <TestNodeNetwork> CreateNetwork(IEnumerable <NodeConfig> configs) { var nodes = new List <TestNode>(); foreach (var c in configs) { var blockNotifier = BlockNotifier.Create(c.ChainMonitor); blockNotifier.RegisterManyChannelMonitor(c.ManyChannelMonitor); var channelManager = ChannelManager.Create(c.N, c.ConfigProvider, c.ChainMonitor, c.KeysManager, c.TestLogger, c.TestBroadcaster, c.TestFeeEstimator, 0, c.ManyChannelMonitor); blockNotifier.RegisterChannelManager(channelManager); var peerManager = PeerManager.Create(c.NodeSeed.ToBytes().AsSpan(), c.ConfigProvider, c.ChainMonitor, c.TestLogger, c.KeysManager.GetNodeSecret().ToBytes(), channelManager, blockNotifier); nodes.Add(new TestNode(peerManager, c, Channel.CreateBounded <byte>(5))); } var connections = new List <ConnectionLoop>(); foreach (var(a, b) in nodes.Combinations2()) { var(c1, c2) = await a.ConnectTo(b); connections.Add(c1); connections.Add(c2); } return(new TestNodeNetwork(nodes, connections)); }
public static PeerManager getTestPeerManager() { var logger = new TestLogger(); var broadcaster = new TestBroadcaster(); var feeEstiamtor = new TestFeeEstimator(); var n = NBitcoin.Network.TestNet; var chainWatchInterface = new ChainWatchInterfaceUtil(n); var seed = new byte[] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; var keysInterface = new KeysManager(seed, DateTime.UnixEpoch); var blockNotifier = BlockNotifier.Create(chainWatchInterface); var manyChannelMonitor = ManyChannelMonitor.Create(n, chainWatchInterface, broadcaster, logger, feeEstiamtor); var channelManager = ChannelManager.Create(n, TestUserConfig.Default, chainWatchInterface, keysInterface, logger, broadcaster, feeEstiamtor, 400000, manyChannelMonitor); blockNotifier.RegisterChannelManager(channelManager); blockNotifier.RegisterManyChannelMonitor(manyChannelMonitor); var peerManager = PeerManager.Create( seed, in TestUserConfig.Default, chainWatchInterface, logger, keysInterface.GetNodeSecret().ToBytes(), channelManager, blockNotifier, 10000 ); return(peerManager); }
public void RegistrationTests() { var keySeed = new byte[] { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 }; var keysInterface = new KeysManager(keySeed, DateTime.UnixEpoch); var logger = new TestLogger(); var broadcaster = new TestBroadcaster(); var feeEstiamtor = new TestFeeEstimator(); var n = NBitcoin.Network.TestNet; var chainWatchInterface = new ChainWatchInterfaceUtil(n); using var blockNotifier = BlockNotifier.Create(chainWatchInterface); using var manyChannelMonitor = ManyChannelMonitor.Create(n, chainWatchInterface, broadcaster, logger, feeEstiamtor); blockNotifier.RegisterManyChannelMonitor(manyChannelMonitor); using var channelManager = ChannelManager.Create(n, UserConfig.GetDefault(), chainWatchInterface, keysInterface, logger, broadcaster, feeEstiamtor, 0, manyChannelMonitor); blockNotifier.RegisterChannelManager(channelManager); // second block in testnet3 var block = (Block.Parse("0100000006128e87be8b1b4dea47a7247d5528d2702c96826c7a648497e773b800000000e241352e3bec0a95a6217e10c3abb54adfa05abb12c126695595580fb92e222032e7494dffff001d00d235340101000000010000000000000000000000000000000000000000000000000000000000000000ffffffff0e0432e7494d010e062f503253482fffffffff0100f2052a010000002321038a7f6ef1c8ca0c588aa53fa860128077c9e6c11e6830f4d7ee4e763a56b7718fac00000000", n)); blockNotifier.BlockConnected(block, 1); var b = manyChannelMonitor.Serialize(_pool); var(manyChannelMonitor2, keyToHeaderHash) = ManyChannelMonitor.Deserialize(new ManyChannelMonitorReadArgs(chainWatchInterface, broadcaster, logger, feeEstiamtor, n), b.AsMemory(), _pool); using (manyChannelMonitor2) { Assert.True(NBitcoin.Utils.ArrayEqual(b, manyChannelMonitor2.Serialize(_pool))); // without creating any channel, it will result to empty. Assert.Empty(keyToHeaderHash); } blockNotifier.UnregisterManyChannelMonitor(manyChannelMonitor); blockNotifier.UnregisterChannelManager(channelManager); }