Skip to content

Commit

Permalink
Added blockreaderjob test
Browse files Browse the repository at this point in the history
  • Loading branch information
tnickelsen committed Sep 27, 2024
1 parent fdb7ca3 commit 4711bda
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/ProjectOrigin.Chronicler.Test/BlockReaderJobTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Guid>() };
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<LastReadBlock>(x => x.BlockHeight == 1)), Times.Once);
_repository.Verify(x => x.WithdrawClaimRecord(certificateId), Times.Once);
_repository.VerifyNoOtherCalls();
}

[Fact]
public async Task Verify_Claimed_Found_Inserted()
Expand Down Expand Up @@ -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()
});
}
}

0 comments on commit 4711bda

Please sign in to comment.