< Summary - Combined Code Coverage

Information
Class: NLightning.Infrastructure.Repositories.Database.Channel.ChannelKeySetDbRepository
Assembly: NLightning.Infrastructure.Repositories
File(s): /home/runner/work/nlightning/nlightning/src/NLightning.Infrastructure.Repositories/Database/Channel/ChannelKeySetDbRepository.cs
Tag: 36_15743069263
Line coverage
0%
Covered lines: 0
Uncovered lines: 47
Coverable lines: 47
Total lines: 72
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 4
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%210%
Add(...)100%210%
Add(...)100%210%
Update(...)100%210%
Update(...)100%210%
DeleteAsync(...)100%210%
DeleteAsync(...)100%210%
GetByIdAsync()0%620%
GetByIdAsync()0%620%
MapDomainToEntity(...)0%620%
MapDomainToEntity(...)0%620%
MapEntityToDomain(...)100%210%
MapEntityToDomain(...)100%210%

File(s)

/home/runner/work/nlightning/nlightning/src/NLightning.Infrastructure.Repositories/Database/Channel/ChannelKeySetDbRepository.cs

#LineLine coverage
 1using NLightning.Domain.Channels.Interfaces;
 2using NLightning.Domain.Channels.Models;
 3using NLightning.Domain.Channels.ValueObjects;
 4using NLightning.Infrastructure.Persistence.Contexts;
 5using NLightning.Infrastructure.Persistence.Entities.Channel;
 6
 7namespace NLightning.Infrastructure.Repositories.Database.Channel;
 8
 9public class ChannelKeySetDbRepository : BaseDbRepository<ChannelKeySetEntity>, IChannelKeySetDbRepository
 10{
 011    public ChannelKeySetDbRepository(NLightningDbContext context) : base(context)
 012    {
 013    }
 14
 15    public void Add(ChannelId channelId, bool isLocal, ChannelKeySetModel keySet)
 016    {
 017        var keySetEntity = MapDomainToEntity(channelId, isLocal, keySet);
 018        Insert(keySetEntity);
 019    }
 20
 21    public void Update(ChannelId channelId, bool isLocal, ChannelKeySetModel keySet)
 022    {
 023        var keySetEntity = MapDomainToEntity(channelId, isLocal, keySet);
 024        base.Update(keySetEntity);
 025    }
 26
 27    public Task DeleteAsync(ChannelId channelId, bool isLocal)
 028    {
 029        return DeleteByIdAsync((channelId, isLocal));
 030    }
 31
 32    public async Task<ChannelKeySetModel?> GetByIdAsync(ChannelId channelId, bool isLocal)
 033    {
 034        var keySetEntity = await base.GetByIdAsync((channelId, isLocal));
 35
 036        if (keySetEntity is null)
 037            return null;
 38
 039        return MapEntityToDomain(keySetEntity);
 040    }
 41
 42    internal static ChannelKeySetEntity MapDomainToEntity(ChannelId channelId, bool isLocal, ChannelKeySetModel keySet)
 043    {
 044        return new ChannelKeySetEntity
 045        {
 046            // Base information
 047            ChannelId = channelId,
 048            IsLocal = isLocal,
 049            KeyIndex = isLocal ? keySet.KeyIndex : 0,
 050
 051            // PubKeys and Basepoints
 052            FundingPubKey = keySet.FundingCompactPubKey,
 053            RevocationBasepoint = keySet.RevocationCompactBasepoint,
 054            PaymentBasepoint = keySet.PaymentCompactBasepoint,
 055            DelayedPaymentBasepoint = keySet.DelayedPaymentCompactBasepoint,
 056            HtlcBasepoint = keySet.HtlcCompactBasepoint,
 057
 058            // Current commitment state
 059            CurrentPerCommitmentPoint = keySet.CurrentPerCommitmentCompactPoint,
 060            CurrentPerCommitmentIndex = keySet.CurrentPerCommitmentIndex,
 061            LastRevealedPerCommitmentSecret = keySet.LastRevealedPerCommitmentSecret
 062        };
 063    }
 64
 65    internal static ChannelKeySetModel MapEntityToDomain(ChannelKeySetEntity entity)
 066    {
 067        return new ChannelKeySetModel(entity.KeyIndex, entity.FundingPubKey, entity.RevocationBasepoint,
 068                                      entity.PaymentBasepoint, entity.DelayedPaymentBasepoint, entity.HtlcBasepoint,
 069                                      entity.CurrentPerCommitmentPoint, entity.CurrentPerCommitmentIndex,
 070                                      entity.LastRevealedPerCommitmentSecret);
 071    }
 72}