|
17 | 17 | package com.swirlds.platform.test.event.tipset;
|
18 | 18 |
|
19 | 19 | import static com.swirlds.common.test.fixtures.RandomUtils.getRandomPrintSeed;
|
20 |
| -import static com.swirlds.common.test.fixtures.RandomUtils.randomHash; |
21 | 20 | import static com.swirlds.common.test.fixtures.RandomUtils.randomSignature;
|
22 | 21 | import static com.swirlds.common.utility.CompareTo.isGreaterThanOrEqualTo;
|
23 | 22 | import static com.swirlds.platform.consensus.ConsensusConstants.ROUND_FIRST;
|
|
53 | 52 | import com.swirlds.platform.system.SoftwareVersion;
|
54 | 53 | import com.swirlds.platform.system.address.Address;
|
55 | 54 | import com.swirlds.platform.system.address.AddressBook;
|
56 |
| -import com.swirlds.platform.system.events.BaseEventHashedData; |
57 |
| -import com.swirlds.platform.system.events.BaseEventUnhashedData; |
58 | 55 | import com.swirlds.platform.system.events.ConsensusData;
|
59 | 56 | import com.swirlds.platform.system.events.EventConstants;
|
60 | 57 | import com.swirlds.platform.system.events.EventDescriptor;
|
61 | 58 | import com.swirlds.platform.system.transaction.ConsensusTransactionImpl;
|
62 | 59 | import com.swirlds.platform.system.transaction.SwirldTransaction;
|
63 | 60 | import com.swirlds.platform.test.fixtures.addressbook.RandomAddressBookGenerator;
|
| 61 | +import com.swirlds.platform.test.fixtures.event.TestingEventBuilder; |
64 | 62 | import edu.umd.cs.findbugs.annotations.NonNull;
|
65 | 63 | import edu.umd.cs.findbugs.annotations.Nullable;
|
66 | 64 | import java.time.Duration;
|
@@ -798,37 +796,29 @@ void sizeOneNetworkTest(final boolean advancingClock, final boolean useBirthRoun
|
798 | 796 | }
|
799 | 797 |
|
800 | 798 | @NonNull
|
801 |
| - private GossipEvent createMockEvent( |
| 799 | + private GossipEvent createTestEvent( |
802 | 800 | @NonNull final Random random,
|
803 | 801 | @NonNull final NodeId creator,
|
804 | 802 | long selfParentGeneration,
|
805 | 803 | @Nullable final NodeId otherParentId,
|
806 | 804 | final long otherParentGeneration) {
|
807 |
| - final GossipEvent event = mock(GossipEvent.class); |
808 | 805 |
|
809 |
| - final BaseEventHashedData hashedData = mock(BaseEventHashedData.class); |
810 |
| - when(hashedData.getCreatorId()).thenReturn(creator); |
811 |
| - when(hashedData.getCreatorId()).thenReturn(creator); |
812 |
| - final long generation = Math.max(selfParentGeneration, otherParentGeneration) + 1; |
813 |
| - when(hashedData.getGeneration()).thenReturn(generation); |
814 |
| - when(event.getGeneration()).thenReturn(generation); |
| 806 | + final GossipEvent selfParent = |
| 807 | + new TestingEventBuilder(random).setCreatorId(creator).build(); |
815 | 808 |
|
816 |
| - final Hash hash = randomHash(random); |
817 |
| - when(hashedData.getHash()).thenReturn(hash); |
| 809 | + final TestingEventBuilder eventBuilder = new TestingEventBuilder(random) |
| 810 | + .setCreatorId(creator) |
| 811 | + .setSelfParent(selfParent) |
| 812 | + .overrideSelfParentGeneration(selfParentGeneration); |
818 | 813 |
|
819 |
| - final EventDescriptor descriptor = |
820 |
| - new EventDescriptor(hash, creator, generation, -EventConstants.BIRTH_ROUND_UNDEFINED); |
| 814 | + if (otherParentId != null) { |
| 815 | + final GossipEvent otherParent = |
| 816 | + new TestingEventBuilder(random).setCreatorId(otherParentId).build(); |
821 | 817 |
|
822 |
| - when(hashedData.createEventDescriptor()).thenReturn(descriptor); |
823 |
| - when(event.getDescriptor()).thenReturn(descriptor); |
824 |
| - |
825 |
| - when(event.getHashedData()).thenReturn(hashedData); |
826 |
| - |
827 |
| - final BaseEventUnhashedData unhashedData = mock(BaseEventUnhashedData.class); |
828 |
| - when(unhashedData.getOtherId()).thenReturn(otherParentId); |
829 |
| - when(event.getUnhashedData()).thenReturn(unhashedData); |
| 818 | + eventBuilder.setOtherParent(otherParent).overrideOtherParentGeneration(otherParentGeneration); |
| 819 | + } |
830 | 820 |
|
831 |
| - return event; |
| 821 | + return eventBuilder.build(); |
832 | 822 | }
|
833 | 823 |
|
834 | 824 | /**
|
@@ -863,11 +853,11 @@ void frozenEventCreationBug() {
|
863 | 853 | final GossipEvent eventA1 = eventCreator.maybeCreateEvent();
|
864 | 854 | assertNotNull(eventA1);
|
865 | 855 |
|
866 |
| - final GossipEvent eventB1 = createMockEvent( |
| 856 | + final GossipEvent eventB1 = createTestEvent( |
867 | 857 | random, nodeB, EventConstants.GENERATION_UNDEFINED, null, EventConstants.GENERATION_UNDEFINED);
|
868 |
| - final GossipEvent eventC1 = createMockEvent( |
| 858 | + final GossipEvent eventC1 = createTestEvent( |
869 | 859 | random, nodeC, EventConstants.GENERATION_UNDEFINED, null, EventConstants.GENERATION_UNDEFINED);
|
870 |
| - final GossipEvent eventD1 = createMockEvent( |
| 860 | + final GossipEvent eventD1 = createTestEvent( |
871 | 861 | random, nodeD, EventConstants.GENERATION_UNDEFINED, null, EventConstants.GENERATION_UNDEFINED);
|
872 | 862 |
|
873 | 863 | eventCreator.registerEvent(eventB1);
|
@@ -896,7 +886,7 @@ void frozenEventCreationBug() {
|
896 | 886 | // but has not been updated in the current snapshot.
|
897 | 887 |
|
898 | 888 | final NodeId otherParentId = eventA2.getUnhashedData().getOtherId();
|
899 |
| - final GossipEvent legalOtherParent = createMockEvent(random, otherParentId, 0, nodeA, 0); |
| 889 | + final GossipEvent legalOtherParent = createTestEvent(random, otherParentId, 0, nodeA, 0); |
900 | 890 |
|
901 | 891 | eventCreator.registerEvent(legalOtherParent);
|
902 | 892 |
|
@@ -936,13 +926,13 @@ void notRegisteringEventsFromNodesNotInAddressBook() {
|
936 | 926 | final GossipEvent eventA1 = eventCreator.maybeCreateEvent();
|
937 | 927 | assertNotNull(eventA1);
|
938 | 928 |
|
939 |
| - final GossipEvent eventB1 = createMockEvent( |
| 929 | + final GossipEvent eventB1 = createTestEvent( |
940 | 930 | random, nodeB, EventConstants.GENERATION_UNDEFINED, null, EventConstants.GENERATION_UNDEFINED);
|
941 |
| - final GossipEvent eventC1 = createMockEvent( |
| 931 | + final GossipEvent eventC1 = createTestEvent( |
942 | 932 | random, nodeC, EventConstants.GENERATION_UNDEFINED, null, EventConstants.GENERATION_UNDEFINED);
|
943 |
| - final GossipEvent eventD1 = createMockEvent( |
| 933 | + final GossipEvent eventD1 = createTestEvent( |
944 | 934 | random, nodeD, EventConstants.GENERATION_UNDEFINED, null, EventConstants.GENERATION_UNDEFINED);
|
945 |
| - final GossipEvent eventE1 = createMockEvent( |
| 935 | + final GossipEvent eventE1 = createTestEvent( |
946 | 936 | random, nodeE, EventConstants.GENERATION_UNDEFINED, null, EventConstants.GENERATION_UNDEFINED);
|
947 | 937 |
|
948 | 938 | eventCreator.registerEvent(eventB1);
|
|
0 commit comments