Example #1
0
        public async Task <Validator> GetValidator(ECPoint publicKey)
        {
            var raw = await _rocksDbContext.Get(publicKey.BuildStateValidatorKey());

            return(raw == null
                ? null
                : _binarySerializer.Deserialize <Validator>(raw));
        }
        public async Task DeleteValidator_DeletesCorrectKey()
        {
            var pubkey = new byte[33];

            pubkey[0] = 0x02;
            var input = new ECPoint(pubkey);
            var redisDbContextMock = AutoMockContainer.GetMock <IRedisDbJsonContext>();
            var testee             = AutoMockContainer.Create <RedisDbJsonRepository>();

            await testee.DeleteValidator(input);

            redisDbContextMock.Verify(
                m => m.Delete(It.Is <RedisKey>(b => b == input.BuildStateValidatorKey())));
        }
Example #3
0
        public async Task DeleteValidator_DeletesCorrectKey()
        {
            var pubkey = new byte[33];

            pubkey[0] = 0x02;
            var input = new ECPoint(pubkey);
            var rocksDbContextMock = AutoMockContainer.GetMock <IRocksDbContext>();
            var testee             = AutoMockContainer.Create <RocksDbRepository>();

            await testee.DeleteValidator(input);

            rocksDbContextMock.Verify(
                m => m.Delete(It.Is <byte[]>(b => b.SequenceEqual(input.BuildStateValidatorKey()))));
        }
        public async Task GetValidator_NoValue_ReturnsNull()
        {
            var pubkey = new byte[33];

            pubkey[0] = 0x02;
            var input = new ECPoint(pubkey);
            var redisDbContextMock = AutoMockContainer.GetMock <IRedisDbJsonContext>();

            redisDbContextMock
            .Setup(m => m.Get(It.Is <RedisKey>(b => b == input.BuildStateValidatorKey())))
            .ReturnsAsync(RedisValue.Null);
            var testee = AutoMockContainer.Create <RedisDbJsonRepository>();

            var result = await testee.GetValidator(input);

            result.Should().BeNull();
        }
Example #5
0
        public async Task GetValidator_NoValue_ReturnsNull()
        {
            var pubkey = new byte[33];

            pubkey[0] = 0x02;
            var input = new ECPoint(pubkey);
            var rocksDbContextMock = AutoMockContainer.GetMock <IRocksDbContext>();

            rocksDbContextMock
            .Setup(m => m.Get(It.Is <byte[]>(b => b.SequenceEqual(input.BuildStateValidatorKey()))))
            .ReturnsAsync((byte[])null);
            var testee = AutoMockContainer.Create <RocksDbRepository>();

            var result = await testee.GetValidator(input);

            result.Should().BeNull();
        }
Example #6
0
        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));
        }
Example #7
0
        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);
        }
Example #8
0
 public async Task DeleteValidator(ECPoint point)
 {
     await _redisDbContext.Delete(point.BuildStateValidatorKey());
 }
        public async Task <Validator> GetValidator(ECPoint publicKey)
        {
            var raw = await _redisDbJsonContext.Get(publicKey.BuildStateValidatorKey());

            return(raw.IsNull ? null : _jsonConverter.DeserializeObject <Validator>(raw));
        }