public async Task AddContract_WritesCorrectKeyValue() { var inputHash = UInt160.Parse(RandomInt().ToString("X40")); var input = new Contract { Code = new Code { ScriptHash = inputHash } }; var expectedBytes = new byte[1]; _serializerMock.Setup(m => m.Serialize(input, null)).Returns(expectedBytes); var rocksDbContextMock = AutoMockContainer.GetMock <IRocksDbContext>(); var testee = AutoMockContainer.Create <RocksDbRepository>(); await testee.AddContract(input); rocksDbContextMock.Verify(m => m.Save(It.Is <byte[]>(b => b.SequenceEqual(inputHash.BuildStateContractKey())), expectedBytes)); }
public void Register_AllObjectsAreCorrectlyRegister() { // Arrange var containerBuilderMock = AutoMockContainer.GetMock <IContainerBuilder>(); var module = AutoMockContainer.Create <ConfigurationModule>(); // Act module.Register(containerBuilderMock.Object); // Assert containerBuilderMock.Verify( x => x.Register <IConfiguration>( It.Is <IConfigurationRoot>(c => c.Providers.Count() == 1 && ((JsonConfigurationProvider)c.Providers.Single()).Source.Path == "appsettings.json" && !((JsonConfigurationProvider)c.Providers.Single()).Source.Optional && ((JsonConfigurationProvider)c.Providers.Single()).Source.ReloadOnChange)), Times.Once); }
public void Verify_AttributeUsageECDH02() { var testee = AutoMockContainer.Create <TransactionOperationManager>(); var transaction = new EnrollmentTransaction { Attributes = new [] { new TransactionAttribute { Usage = TransactionAttributeUsage.ECDH02 } } }; var result = testee.Verify(transaction); result.Should().BeFalse(); }
public async Task AddValidator_WritesCorrectKeyValue() { var pubkey = new byte[33]; pubkey[0] = 0x02; var point = new ECPoint(pubkey); var input = new Validator { PublicKey = point }; var expectedBytes = new byte[1]; _serializerMock.Setup(m => m.Serialize(input, null)).Returns(expectedBytes); var rocksDbContextMock = AutoMockContainer.GetMock <IRocksDbContext>(); var testee = AutoMockContainer.Create <RocksDbRepository>(); await testee.AddValidator(input); rocksDbContextMock.Verify(m => m.Save(It.Is <byte[]>(b => b.SequenceEqual(point.BuildStateValidatorKey())), expectedBytes)); }
public async Task Can_serialize_and_deserialize_messages_with_payload() { // Arrange var versionPayload = new VersionPayload { Version = (uint)this.RandomInt(0, int.MaxValue), Services = (ulong)this.RandomInt(0, int.MaxValue), Timestamp = DateTime.UtcNow.ToTimestamp(), Port = (ushort)this.RandomInt(0, short.MaxValue), Nonce = (uint)this.RandomInt(0, int.MaxValue), UserAgent = $"/NEO:{this.RandomInt(1, 10)}.{this.RandomInt(1, 100)}.{this.RandomInt(1, 1000)}/", CurrentBlockIndex = (uint)this.RandomInt(0, int.MaxValue), Relay = false }; var tcpProtocol = AutoMockContainer.Create <ProtocolV1>(); var expectedVersionMessage = new VersionMessage(versionPayload); VersionMessage actualVersionMessage; // Act using (var memory = new MemoryStream()) { await tcpProtocol.SendMessageAsync(memory, expectedVersionMessage, CancellationToken.None); memory.Seek(0, SeekOrigin.Begin); actualVersionMessage = (VersionMessage)await tcpProtocol.ReceiveMessageAsync(memory, CancellationToken.None); } // Assert actualVersionMessage .Should() .NotBeNull(); actualVersionMessage.Command .Should() .Be(expectedVersionMessage.Command); actualVersionMessage.Payload .Should() .NotBeNull() .And .BeEquivalentTo(versionPayload); }
public async Task Can_serialize_and_deserialize_messages() { // Arrange var tcpProtocol = AutoMockContainer.Create <ProtocolV1>(); var expectedVerAckMessage = new VerAckMessage(); VerAckMessage actualVerAckMessage; // Act using (var memory = new MemoryStream()) { await tcpProtocol.SendMessageAsync(memory, expectedVerAckMessage, CancellationToken.None); memory.Seek(0, SeekOrigin.Begin); actualVerAckMessage = (VerAckMessage)await tcpProtocol.ReceiveMessageAsync(memory, CancellationToken.None); } // Asset actualVerAckMessage.Should().NotBeNull(); actualVerAckMessage.Command.Should().Be(expectedVerAckMessage.Command); }
public async Task GetValidator_ValueFound_ReturnsValidator() { var pubkey = new byte[33]; pubkey[0] = 0x02; var input = new ECPoint(pubkey); var expectedBytes = new byte[1]; var expectedResult = new Validator(); var rocksDbContextMock = AutoMockContainer.GetMock <IRocksDbContext>(); rocksDbContextMock .Setup(m => m.Get(It.Is <byte[]>(b => b.SequenceEqual(input.BuildStateValidatorKey())))) .ReturnsAsync(expectedBytes); _serializerMock.Setup(m => m.Deserialize <Validator>(expectedBytes, null)).Returns(expectedResult); var testee = AutoMockContainer.Create <RocksDbRepository>(); var result = await testee.GetValidator(input); result.Should().Be(expectedResult); }
public void Can_disconnect_to_peers_on_stop() { // Arrange AutoMockContainer.Register(GetNetworkConfig("tcp://localhost:8081")); var peerMock = AutoMockContainer.GetMock <IPeer>(); FakeHandshake(peerMock); var peerFactoryMock = AutoMockContainer.GetMock <IPeerFactory>(); peerFactoryMock.Setup(x => x.ConnectTo(It.IsAny <EndPoint>())).Returns(Task.FromResult(peerMock.Object)); var server = AutoMockContainer.Create <Server>(); // Act server.Start(); WaitUntilPeersAreConnected(server); server.Stop(); // Asset peerMock.Verify(x => x.Disconnect(), Times.Once); }
public void Register_AllObjectsAreCorrectlyRegister() { // Arrange var containerBuilderMock = AutoMockContainer.GetMock <IContainerBuilder>(); var module = AutoMockContainer.Create <BlockchainModule>(); // Act module.Register(containerBuilderMock.Object); // Assert containerBuilderMock.Verify(x => x.RegisterSingleton <IBlockchain, Blockchain>(), Times.Once); containerBuilderMock.Verify(x => x.RegisterSingleton <IBlockProcessor, BlockProcessor>(), Times.Once); containerBuilderMock.Verify(x => x.RegisterSingleton <IBlockPool, BlockPool>(), Times.Once); containerBuilderMock.Verify(x => x.RegisterSingleton <ITransactionPersister <Transaction>, TransactionPersister>(), Times.Once); containerBuilderMock.Verify(x => x.RegisterSingleton <ITransactionPersister <InvocationTransaction>, InvocationTransactionPersister>(), Times.Once); containerBuilderMock.Verify(x => x.RegisterSingleton <IWitnessOperationsManager, WitnessOperationsManager>(), Times.Once); containerBuilderMock.Verify(x => x.RegisterSingleton <ITransactionOperationsManager, TransactionOperationManager>(), Times.Once); containerBuilderMock.Verify(x => x.RegisterSingleton <IBlockHeaderOperationsManager, BlockHeaderOperationsManager>(), Times.Once); containerBuilderMock.Verify(x => x.RegisterSingleton <IBlockOperationsManager, BlockOperationManager>(), Times.Once); }
public async Task GetStorage_ValueFound_ReturnsStorageValue() { var input = new StorageKey { ScriptHash = UInt160.Parse(RandomInt().ToString("X40")), Key = new byte[1] }; var expectedBytes = new byte[1]; var expectedResult = new StorageValue(); var rocksDbContextMock = AutoMockContainer.GetMock <IRocksDbContext>(); rocksDbContextMock .Setup(m => m.Get(It.Is <byte[]>(b => b.SequenceEqual(input.BuildStateStorageKey())))) .ReturnsAsync(expectedBytes); _serializerMock.Setup(m => m.Deserialize <StorageValue>(expectedBytes, null)).Returns(expectedResult); var testee = AutoMockContainer.Create <RocksDbRepository>(); var result = await testee.GetStorage(input); result.Should().Be(expectedResult); }
public async Task GetBlockHashFromHeight_NoHashFound_ReturnUInt256Zero() { // Arrange const uint heightParameter = 0; var redisDbContextMock = AutoMockContainer.GetMock <IRedisDbJsonContext>(); redisDbContextMock .Setup(x => x.Get(heightParameter.BuildIxHeightToHashKey())) .ReturnsAsync(RedisValue.Null); var testee = AutoMockContainer.Create <RedisDbJsonRepository>(); // Act var result = await testee.GetBlockHashFromHeight(heightParameter); // Assert result .Should() .Be(UInt256.Zero); }
public async Task Can_serialize_and_deserialize_messages_with_payload() { // Arrange var tcpProtocol = AutoMockContainer.Create <TcpProtocolV2>(); var expectedVersionMessage = new VersionMessage(); var r = new Random(Environment.TickCount); expectedVersionMessage.Payload.Version = (uint)r.Next(0, int.MaxValue); expectedVersionMessage.Payload.Services = (ulong)r.Next(0, int.MaxValue); expectedVersionMessage.Payload.Timestamp = DateTime.UtcNow.ToTimestamp(); expectedVersionMessage.Payload.Port = (ushort)r.Next(0, short.MaxValue); expectedVersionMessage.Payload.Nonce = (uint)r.Next(0, int.MaxValue); expectedVersionMessage.Payload.UserAgent = $"/NEO:{r.Next(1, 10)}.{r.Next(1, 100)}.{r.Next(1, 1000)}/"; expectedVersionMessage.Payload.StartHeight = (uint)r.Next(0, int.MaxValue); expectedVersionMessage.Payload.Relay = false; VersionMessage actualVersionMessage; // Act using (var memory = new MemoryStream()) { await tcpProtocol.SendMessageAsync(memory, expectedVersionMessage, CancellationToken.None); memory.Seek(0, SeekOrigin.Begin); actualVersionMessage = (VersionMessage)await tcpProtocol.ReceiveMessageAsync(memory, CancellationToken.None); } // Asset actualVersionMessage.Should().NotBeNull(); actualVersionMessage.Flags.Should().Be(expectedVersionMessage.Flags); actualVersionMessage.Command.Should().Be(expectedVersionMessage.Command); actualVersionMessage.Payload.Should().NotBeNull(); actualVersionMessage.Payload.Version.Should().Be(expectedVersionMessage.Payload.Version); actualVersionMessage.Payload.Services.Should().Be(expectedVersionMessage.Payload.Services); actualVersionMessage.Payload.Timestamp.Should().Be(expectedVersionMessage.Payload.Timestamp); actualVersionMessage.Payload.Port.Should().Be(expectedVersionMessage.Payload.Port); actualVersionMessage.Payload.Nonce.Should().Be(expectedVersionMessage.Payload.Nonce); actualVersionMessage.Payload.UserAgent.Should().Be(expectedVersionMessage.Payload.UserAgent); actualVersionMessage.Payload.StartHeight.Should().Be(expectedVersionMessage.Payload.StartHeight); actualVersionMessage.Payload.Relay.Should().Be(expectedVersionMessage.Payload.Relay); }
public async Task Persist_IssueAssets_IncreaseAvailable() { var assetId = new UInt256(RandomByteArray(32)); var oldAvailability = RandomInt(10000); var changeInAvailability1 = RandomInt(10000); var changeInAvailability2 = RandomInt(10000); var input = new IssueTransaction { Outputs = new[] { new TransactionOutput { AssetId = assetId, ScriptHash = new UInt160(RandomByteArray(20)), Value = new Fixed8(changeInAvailability1) }, new TransactionOutput { AssetId = assetId, ScriptHash = new UInt160(RandomByteArray(20)), Value = new Fixed8(changeInAvailability2) } } }; var asset = new Asset { Available = new Fixed8(oldAvailability) }; var repositoryMock = AutoMockContainer.GetMock <IRepository>(); repositoryMock.Setup(m => m.GetAsset(It.Is <UInt256>(u => u.Equals(assetId)))).ReturnsAsync(asset); var testee = AutoMockContainer.Create <IssueTransactionPersister>(); await testee.Persist(input); repositoryMock.Verify(m => m.AddAsset(It.Is <Asset>(a => a == asset && a.Available.Equals(new Fixed8(oldAvailability + changeInAvailability1 + changeInAvailability2))))); }
public void TestDeserializeStreamTransactionUploadFile_WhenDeserializeStreamCsvCorrectFormat_ThenCanDeserializeToTransactionUploadModel() { // Arrange var csvContent = "\"Invoice0000001\",\"1,000.00\", \"USD\", \"20/02/2019 12:33:16\", \"Approved\""; var csvExtension = ".csv"; var fileUploadManager = AutoMockContainer.Create <FileUploadManager>(); using (Stream stream = new MemoryStream(Encoding.UTF8.GetBytes(csvContent))) { // Act var result = fileUploadManager.DeserializeStreamTransactionUploadFile <TransactionUploadModel>(stream, csvExtension); // Assert Assert.AreEqual(1, result.Count); Assert.AreEqual(UploadSourceEnum.Csv, result.First().Source); Assert.AreEqual("1,000.00", result.First().Amount); Assert.AreEqual("USD", result.First().CurrencyCode); Assert.AreEqual("Approved", result.First().Status); Assert.AreEqual("20/02/2019 12:33:16", result.First().TransactionDate); Assert.AreEqual("Invoice0000001", result.First().TransactionId); } }
public async Task Process_SetValidatorRegisteredToTrue() { var pubKey = new byte[33]; pubKey[0] = 0x02; var input = new EnrollmentTransaction { PublicKey = new ECPoint(pubKey) }; var validator = new Validator { Registered = false }; var repositoryMock = AutoMockContainer.GetMock <IRepository>(); repositoryMock.Setup(m => m.GetValidator(input.PublicKey)).ReturnsAsync(validator); var testee = AutoMockContainer.Create <EnrollmentTransactionProcessor>(); await testee.Process(input); repositoryMock.Verify(m => m.AddValidator(It.Is <Validator>(v => v == validator && v.Registered))); }
public void IsDoubleSpend_ConfirmedInput() { var testee = AutoMockContainer.Create <TransactionRepository>(); var tx = new Transaction { Inputs = new[] { new CoinReference() } }; tx.Inputs[0].PrevHash = new UInt256(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 }); // mocking: IRepository instance, when called GetCoinStates with our test hash, // returns a single confirmed coinstate var repositoryMock = AutoMockContainer.GetMock <IRepository>(); repositoryMock .Setup(x => x.GetCoinStates(tx.Inputs[0].PrevHash)) .ReturnsAsync(new[] { CoinState.Confirmed }); var result = testee.IsDoubleSpend(tx); result.Should().BeFalse(); }
public void TestSaveWalletSuccess() { var expectedFileName = "name.json"; var expectedNep6WalletSerialized = "NEP6WalletSerialized"; var expetectedWalletVersion = "1.0"; var expectedWalletName = "name"; var fileWrapper = AutoMockContainer.GetMock <IFileWrapper>(); var jsonConverter = AutoMockContainer.GetMock <IJsonConverter>(); fileWrapper.Setup(x => x.Exists(expectedFileName)).Returns(false); jsonConverter .Setup(x => x.SerializeObject(It.Is <NEP6Wallet>(wallet => wallet.Name == expectedWalletName && wallet.Version == expetectedWalletVersion))) .Returns(expectedNep6WalletSerialized); var mockWalletManager = AutoMockContainer.Create <Nep6WalletManager>(); mockWalletManager.CreateWallet(expectedFileName); Assert.IsNotNull(mockWalletManager.Wallet); fileWrapper.Verify(x => x.WriteToFile(expectedNep6WalletSerialized, expectedFileName)); }
public void TestInsertUploadTransaction_WhenSetIncorrectStatusCodeCriteria_ThenThrowValidationErrorsException() { // Arrange var expectedCurrentcy = "THB"; var expectedStatusCode = "0"; var expectedFromDate = default(string); var expectedToDate = default(string); AutoMockContainer.Mock <ITransactionRepository>() .Setup(x => x.GetTransactionBySearchCriteria(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <DateTime?>(), It.IsAny <DateTime?>())) .ReturnsAsync(It.IsAny <List <TransactionEntity> >()); var transactionManager = AutoMockContainer.Create <TransactionManager>(); // Assert Assert.ThrowsAsync <ValidationErrorsException>( async() => { // Act await transactionManager.GetTransactions(expectedCurrentcy, expectedStatusCode, expectedFromDate, expectedToDate); }, $"Should Throw ValidationErrorsException"); }
public void Stop_SuccessfulPeerConnection_StoppingServerLeadsToDisconnectingPeer() { // Arrange var waitPeerIsConnectedResetEvent = new AutoResetEvent(false); this.AutoMockContainer.Register(GetNetworkConfig("tcp://localhost:8081")); var blockchainMock = this.AutoMockContainer.GetMock <IBlockchain>(); blockchainMock .SetupGet(x => x.CurrentBlock) .Returns(new Block()); var peerMock = AutoMockContainer.GetMock <IPeer>(); peerMock .SetupFakeHandshake() .Setup(x => x.Send(It.IsAny <VersionMessage>())) .Callback(() => waitPeerIsConnectedResetEvent.Set()); var peerFactoryMock = AutoMockContainer.GetMock <IPeerFactory>(); peerFactoryMock .Setup(x => x.ConnectTo(It.IsAny <EndPoint>())) .Returns(Task.FromResult(peerMock.Object)); // Act var server = AutoMockContainer.Create <Server>(); server.Start(); waitPeerIsConnectedResetEvent.WaitOne(); server.Stop(); // Asset peerMock.Verify(x => x.Disconnect(), Times.Once); }
public async Task GetBlockHashFromHeight_HashFound_ReturnValidUInt256() { // Arrange const uint heightParameter = 0; var expectedUint256 = UInt256.Parse("0x4520462a8c80056291f871da523bff0eb17e29d44ab4317e69ff7a42083cb39d"); var redisDbContextMock = AutoMockContainer.GetMock <IRedisDbJsonContext>(); redisDbContextMock .Setup(x => x.GetFromHashIndex(It.Is <RedisIndex>(a => a == RedisIndex.BlockHeight), It.IsAny <double>())) .ReturnsAsync(expectedUint256); var testee = AutoMockContainer.Create <RedisDbJsonRepository>(); // Act var result = await testee.GetBlockHashFromHeight(heightParameter); // Assert result .Should() .BeEquivalentTo(expectedUint256); }
public async Task Persist_MarksCorrectCoinStateAsClaimed() { var txHash = UInt256.Parse(RandomInt().ToString("X64")); var expectedClaimIndex = (ushort)RandomInt(3); var input = new ClaimTransaction { Claims = new[] { new CoinReference { PrevHash = txHash, PrevIndex = expectedClaimIndex } } }; var coinStates = new[] { CoinState.Confirmed | CoinState.Spent, CoinState.Confirmed | CoinState.Spent, CoinState.Confirmed | CoinState.Spent }; var repositoryMock = AutoMockContainer.GetMock <IRepository>(); repositoryMock.Setup(m => m.GetCoinStates(txHash)).ReturnsAsync(coinStates); var testee = AutoMockContainer.Create <ClaimTransactionPersister>(); await testee.Persist(input); repositoryMock.Verify(m => m.AddCoinStates(It.Is <UInt256>(u => u.Equals(txHash)), coinStates)); for (var i = 0; i < coinStates.Length; i++) { coinStates[i].Should().HaveFlag(CoinState.Confirmed); coinStates[i].Should().HaveFlag(CoinState.Spent); if (i == expectedClaimIndex) { coinStates[i].Should().HaveFlag(CoinState.Claimed); } } }
public void IsAllowed_Blacklist() { // Arrange var aclFactory = AutoMockContainer.Create <NetworkACLFactory>(); var acl = aclFactory.CreateNew(); NetworkACLConfig cfg = new NetworkACLConfig(); string tmpRules = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".json"); File.WriteAllText(tmpRules, @"[{'value':'192\\.168\\.8\\..*','regex':true},{'value':'192.168.7.1','regex':false}]"); cfg.Path = tmpRules; cfg.Type = NetworkACLConfig.ACLType.Blacklist; // Act acl?.Load(cfg); File.Delete(tmpRules); // Asset for (var i = 0; i < 256; ++i) { acl.IsAllowed("192.168.8." + i).Should().BeFalse(); acl.IsAllowed("192.168." + i + ".1").Should().Be(i != 8 && i != 7); acl.IsAllowed("192.168.7." + i).Should().Be(i != 1); } }
public async Task Persist_ValidatorStateDescriptor_UpdateValidatorToTrue() { var pubKey = new byte[33]; pubKey[0] = 0x02; var input = new StateTransaction { Descriptors = new[] { new StateDescriptor { Type = StateType.Validator, Key = pubKey, Field = "Registered", Value = new byte[] { 0x01 } } } }; var expectedVotes = RandomInt(); var expectedValidator = new Validator { PublicKey = new ECPoint(pubKey), Registered = false, Votes = new Fixed8(expectedVotes) }; var repositoryMock = AutoMockContainer.GetMock <IRepository>(); repositoryMock.Setup(m => m.GetValidator(It.Is <ECPoint>(p => p.CompareTo(new ECPoint(pubKey)) == 0))) .ReturnsAsync(expectedValidator); var testee = AutoMockContainer.Create <StateTransactionPersister>(); await testee.Persist(input); repositoryMock.Verify(m => m.AddValidator(It.Is <Validator>(v => v == expectedValidator && v.Votes.Equals(new Fixed8(expectedVotes)) && v.Registered))); }
public void Start_PeerConnectionThrowException_WarningMessageIsLoggedServerKeepListeningForPeers() { // Arrange var connectionException = new Exception("The network error"); var expectedLoggedWarningMessage = $"Something went wrong with {_peerEndPoint}. Exception: {connectionException}"; var peerFactoryMock = AutoMockContainer.GetMock <IPeerFactory>(); peerFactoryMock .Setup(x => x.ConnectTo(_peerEndPoint)) .Returns(Task.FromException <IPeer>(connectionException)); var loggerMock = AutoMockContainer.GetMock <ILogger <Server> >(); var peerListenerMock = AutoMockContainer.GetMock <IPeerListener>(); var server = AutoMockContainer.Create <Server>(); // Act server.Start(); // Assert peerFactoryMock.Verify(x => x.ConnectTo(_peerEndPoint), Times.Once); loggerMock.Verify(x => x.LogWarning(It.Is <string>(msg => msg.Contains(expectedLoggedWarningMessage))), Times.Once); peerListenerMock.Verify(x => x.Start(), Times.Once); }
public void Verify_WithPrevBlockHeaderIndexNotThePrevious() { var testee = AutoMockContainer.Create <BlockOperationManager>(); var block = new Block { PreviousBlockHash = UInt256.Parse("7ee8170d86de43d6c105699273f9b82d077180e5e0f8e4d942f43d7804cc54d3"), Index = 3 }; var prevBlockHeader = new BlockHeader { Index = 1 }; this.AutoMockContainer .GetMock <IBlockRepository>() .Setup(b => b.GetBlockHeader(block.PreviousBlockHash)) .ReturnsAsync(() => prevBlockHeader); var result = testee.Verify(block); result.Should().BeFalse(); }
public void Verify_WithDoubleSpending() { var testee = AutoMockContainer.Create <TransactionOperationManager>(); var transaction = new Transaction { Attributes = new [] { new TransactionAttribute { Usage = TransactionAttributeUsage.ContractHash } }, Inputs = new[] { new CoinReference { PrevHash = UInt256.Zero, PrevIndex = 1 }, new CoinReference { PrevHash = UInt256.Zero, PrevIndex = 2 } } }; this.AutoMockContainer.GetMock <ITransactionRepository>() .Setup(b => b.IsDoubleSpend(transaction)) .Returns(true); var result = testee.Verify(transaction); result.Should().BeFalse(); }
public void IsAllowed_Whitelist() { // Arrange var aclLoader = AutoMockContainer.Create <NetworkAclLoader>(); var cfg = new NetworkAclConfig(); var tmpRules = Path.Combine(Path.GetTempPath(), $"{Guid.NewGuid()}.json"); File.WriteAllText(tmpRules, @"[{'value':'192\\.168\\.6\\..*','regex':true},{'value':'192.168.5.1','regex':false}]"); cfg.Path = tmpRules; cfg.Type = NetworkAclType.Whitelist; // Act var acl = aclLoader.Load(cfg); File.Delete(tmpRules); // Assert for (var i = 0; i < 256; ++i) { acl.IsAllowed("192.168.6." + i).Should().BeTrue(); acl.IsAllowed("192.168." + i + ".1").Should().Be(i == 6 || i == 5); acl.IsAllowed("192.168.5." + i).Should().Be(i == 1); } }
public void Init() { _bccrypto = AutoMockContainer.Create <BouncyCastleCrypto>(); _nativecrypto = AutoMockContainer.Create <NativeCrypto>(); _data = new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F }; }
public async Task Persist_BurnAssets_DecreaseAvailable() { var assetId = new UInt256(RandomByteArray(32)); var oldAvailability = RandomInt(20000, 100000); var changeInAvailability1 = RandomInt(10000); var changeInAvailability2 = RandomInt(10000); var prevTx1 = new Transaction { Hash = new UInt256(RandomByteArray(32)), Outputs = new[] { new TransactionOutput { AssetId = assetId, ScriptHash = new UInt160(RandomByteArray(20)), Value = new Fixed8(changeInAvailability1) }, new TransactionOutput { AssetId = assetId, ScriptHash = new UInt160(RandomByteArray(20)), Value = new Fixed8(RandomInt()) } } }; var prevTx2 = new Transaction { Hash = new UInt256(RandomByteArray(32)), Outputs = new[] { new TransactionOutput { AssetId = assetId, ScriptHash = new UInt160(RandomByteArray(20)), Value = new Fixed8(RandomInt()) }, new TransactionOutput { AssetId = assetId, ScriptHash = new UInt160(RandomByteArray(20)), Value = new Fixed8(changeInAvailability2) } } }; var input = new IssueTransaction { Inputs = new[] { new CoinReference { PrevHash = prevTx1.Hash, PrevIndex = 0 }, new CoinReference { PrevHash = prevTx2.Hash, PrevIndex = 1 } } }; var asset = new Asset { Available = new Fixed8(oldAvailability) }; var repositoryMock = AutoMockContainer.GetMock <IRepository>(); repositoryMock.Setup(m => m.GetTransaction(It.Is <UInt256>(u => u.Equals(prevTx1.Hash)))) .ReturnsAsync(prevTx1); repositoryMock.Setup(m => m.GetTransaction(It.Is <UInt256>(u => u.Equals(prevTx2.Hash)))) .ReturnsAsync(prevTx2); repositoryMock.Setup(m => m.GetAsset(It.Is <UInt256>(u => u.Equals(assetId)))).ReturnsAsync(asset); var testee = AutoMockContainer.Create <IssueTransactionPersister>(); await testee.Persist(input); repositoryMock.Verify(m => m.AddAsset(It.Is <Asset>(a => a == asset && a.Available.Equals(new Fixed8(oldAvailability - changeInAvailability1 - changeInAvailability2))))); }
public void Ctor_CreateValidRedisDbRepository() { var testee = AutoMockContainer.Create <RedisDbJsonRepository>(); testee.Should().BeOfType <RedisDbJsonRepository>(); }