diff --git a/src/ProjectOrigin.Chronicler.Test/BlockReaderJobTests.cs b/src/ProjectOrigin.Chronicler.Test/BlockReaderJobTests.cs index 09c131d..a29c06a 100644 --- a/src/ProjectOrigin.Chronicler.Test/BlockReaderJobTests.cs +++ b/src/ProjectOrigin.Chronicler.Test/BlockReaderJobTests.cs @@ -268,6 +268,27 @@ public async Task Verify_Claimed_NotFound_NotInserted() _repository.VerifyNoOtherCalls(); } + [Fact] + public async Task ProcessWithdrawnEvent_WithdrawsClaim() + { + // Arrange + var fixture = new Fixture(); + var certificateId = new FederatedCertificateId { RegistryName = RegistryName, StreamId = fixture.Create() }; + var block = new Registry.V1.Block + { + Height = 1, + }; + block.AddWithdrawn(certificateId); + _registryService.Setup(x => x.GetNextBlock(RegistryName, 0)).ReturnsAsync(block); + + // Act + await _job.ProcessRegistryBlocks(RegistryName, 0, default); + + // Assert + _repository.Verify(x => x.UpsertReadBlock(It.Is(x => x.BlockHeight == 1)), Times.Once); + _repository.Verify(x => x.WithdrawClaimRecord(certificateId), Times.Once); + _repository.VerifyNoOtherCalls(); + } [Fact] public async Task Verify_Claimed_Found_Inserted() @@ -454,5 +475,18 @@ public static void AddClaim(this Registry.V1.Block block, Guid allocationId, Fed }.ToByteString() }); } + + public static void AddWithdrawn(this Registry.V1.Block block, FederatedCertificateId id) + { + block.Transactions.Add(new Registry.V1.Transaction + { + Header = new Registry.V1.TransactionHeader + { + PayloadType = Electricity.V1.WithdrawnEvent.Descriptor.FullName, + FederatedStreamId = id.ToProto(), + }, + Payload = new Electricity.V1.WithdrawnEvent().ToByteString() + }); + } }