public static NodeConfig CreateDefault() { var n = Network.RegTest; var chainMonitor = new ChainWatchInterfaceUtil(n); var b = new TestBroadcaster(); var l = new TestLogger(Colors[index]); index++; if (index == 8) { index = 0; } var est = new TestFeeEstimator(); return(new NodeConfig() { ChainMonitor = chainMonitor, TestBroadcaster = b, TestFeeEstimator = est, ManyChannelMonitor = ManyChannelMonitor.Create(n, chainMonitor, b, l, est), TestLogger = l, NodeSeed = RandomUtils.GetUInt256(), KeysManager = new KeysManager(RandomUtils.GetBytes(32), DateTime.Now), ConfigProvider = new TestUserConfigProvider(), N = n, }); }
private ChannelManager GetTestChannelManager() { var logger = new TestLogger(); var broadcaster = new TestBroadcaster(); var feeEstiamtor = new TestFeeEstimator(); var n = NBitcoin.Network.TestNet; var chainWatchInterface = new ChainWatchInterfaceUtil(n); 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 manyChannelMonitor = ManyChannelMonitor.Create(n, chainWatchInterface, broadcaster, logger, feeEstiamtor); var channelManager = ChannelManager.Create(n, in TestUserConfig.Default, chainWatchInterface, keysInterface, logger, broadcaster, feeEstiamtor, 400000, manyChannelMonitor); return(channelManager); }
private (ChannelManager, ChannelManagerReadArgs, ManyChannelMonitor, ManyChannelMonitorReadArgs) GetTestChannelManager() { var logger = new TestLogger(); var broadcaster = new TestBroadcaster(); var feeEstiamtor = new TestFeeEstimator(); var n = Network.TestNet; var chainWatchInterface = new ChainWatchInterfaceUtil(n); 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 manyChannelMonitor = ManyChannelMonitor.Create(n, chainWatchInterface, broadcaster, logger, feeEstiamtor); var userConfig = new UserConfigObject(); var channelManager = ChannelManager.Create(n, userConfig, chainWatchInterface, keysInterface, logger, broadcaster, feeEstiamtor, 400000, manyChannelMonitor); var readArgs = new ChannelManagerReadArgs(keysInterface, broadcaster, feeEstiamtor, logger, chainWatchInterface, n, manyChannelMonitor); var monitorReadArgs = new ManyChannelMonitorReadArgs(chainWatchInterface, broadcaster, logger, feeEstiamtor, n); return(channelManager, readArgs, manyChannelMonitor, monitorReadArgs); }
public void ChannelManagerSerializationTests() { using var channelManager = GetTestChannelManager(); var b = channelManager.Serialize(_pool); 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); var manyChannelMonitor = ManyChannelMonitor.Create(n, chainWatchInterface, broadcaster, logger, feeEstiamtor); var args = new ChannelManagerReadArgs(keysInterface, broadcaster, feeEstiamtor, logger, chainWatchInterface, n, manyChannelMonitor); var items = ChannelManager.Deserialize(b, args, new TestUserConfigProvider(), _pool); var(_, channelManager2) = items; Assert.True(channelManager2.Serialize(_pool).SequenceEqual(b)); }
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); }