Skip to content

Commit

Permalink
Merge pull request #309 from bloxbean/fix/307
Browse files Browse the repository at this point in the history
chore: #307 Get PP with target epoch as previous epoch
  • Loading branch information
satran004 authored Jul 13, 2024
2 parents 5a1a2a6 + 2c6fc70 commit feca573
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,13 @@ public void handleEpochChangeEvent(PreEpochTransitionEvent epochChangeEvent) {
EpochParam previousEpochParam = epochParamStorage.getProtocolParams(newEpoch - 1).orElse(null);

//Get protocol param proposals target for this era (Signature check for validity -- //TODO)
List<ProtocolParamsProposal> ppProposals = protocolParamsProposalStorage.getProtocolParamsProposalsByTargetEpoch(newEpoch);

//Also check any proposal target to previous epoch, but also submitted in previous epoch. Those should be considered now.
//Filter to check if submitted in previous epochl
List<ProtocolParamsProposal> ppProposalsSubmittedPrevEpoch = protocolParamsProposalStorage.getProtocolParamsProposalsByTargetEpoch(newEpoch - 1)
.stream().filter(protocolParamsProposal -> protocolParamsProposal.getEpoch() == newEpoch - 1).toList();
List<ProtocolParamsProposal> ppProposals = protocolParamsProposalStorage.getProtocolParamsProposalsByTargetEpoch(newEpoch - 1);

if (previousEpochParam != null)
protocolParams.merge(previousEpochParam.getParams());

genesisProtocolParams.ifPresent(protocolParams::merge);

ppProposalsSubmittedPrevEpoch.forEach(ppProposal -> protocolParams.merge(ppProposal.getParams()));
ppProposals.forEach(ppProposal -> protocolParams.merge(ppProposal.getParams()));

//Additional Era change specific rules
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.mockito.junit.jupiter.MockitoExtension;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.when;

@ExtendWith(MockitoExtension.class)
class EpochParamProcessorTest {
Expand Down Expand Up @@ -50,7 +51,7 @@ void givenEpochChangeEvent_whenPreviousEpochIsNullAndEpochEqualsMaxEpoch_shouldR
.build())
.build();

Mockito.when(epochParamStorage.getMaxEpoch()).thenReturn(28);
when(epochParamStorage.getMaxEpoch()).thenReturn(28);

epochParamProcessor.handleEpochChangeEvent(epochChangeEvent);
Mockito.verify(epochParamStorage, Mockito.never()).save(Mockito.any());
Expand All @@ -71,7 +72,7 @@ void givenEpochChangeEvent_whenMaxEpochIsNotNullAndMaxEpochPlusOneIsNotEqualToEp
.build())
.build();

Mockito.when(epochParamStorage.getMaxEpoch()).thenReturn(30);
when(epochParamStorage.getMaxEpoch()).thenReturn(30);

epochParamProcessor.handleEpochChangeEvent(epochChangeEvent);
Mockito.verify(epochParamStorage, Mockito.never()).save(Mockito.any());
Expand All @@ -98,7 +99,6 @@ void givenEpochChangeEvent_shouldSaveEpochParam() {
Mockito.verify(epochParamStorage, Mockito.times(1)).save(argCaptor.capture());

Mockito.verify(epochParamStorage).getProtocolParams(27);
Mockito.verify(protocolParamsProposalStorage).getProtocolParamsProposalsByTargetEpoch(28);
Mockito.verify(protocolParamsProposalStorage).getProtocolParamsProposalsByTargetEpoch(27);

EpochParam epochParam = argCaptor.getValue();
Expand All @@ -108,4 +108,6 @@ void givenEpochChangeEvent_shouldSaveEpochParam() {
assertThat(epochParam.getBlockNumber()).isEqualTo(177070);
assertThat(epochParam.getBlockTime()).isEqualTo(1666342887);
}

//TODO -- Add more test cases without mock
}

0 comments on commit feca573

Please sign in to comment.