mirror of
https://github.com/bisq-network/bisq.git
synced 2024-11-19 09:52:23 +01:00
Make addPersistableNetworkPayloadFromInitialRequest private
Now that the only user is internal, the API can be made private and the tests can be removed. This involved adding a few test cases to processGetDataResponse to ensure the invalid hash size condition was still covered.
This commit is contained in:
parent
4fe19aeec2
commit
0649323505
@ -542,15 +542,13 @@ public class P2PDataStorage implements MessageListener, ConnectionListener, Pers
|
||||
// Overwriting an entry would be also no issue. We also skip notifying listeners as we get called before the domain
|
||||
// is ready so no listeners are set anyway. We might get called twice from a redundant call later, so listeners
|
||||
// might be added then but as we have the data already added calling them would be irrelevant as well.
|
||||
public boolean addPersistableNetworkPayloadFromInitialRequest(PersistableNetworkPayload payload) {
|
||||
private void addPersistableNetworkPayloadFromInitialRequest(PersistableNetworkPayload payload) {
|
||||
byte[] hash = payload.getHash();
|
||||
if (payload.verifyHashSize()) {
|
||||
ByteArray hashAsByteArray = new ByteArray(hash);
|
||||
appendOnlyDataStoreService.put(hashAsByteArray, payload);
|
||||
return true;
|
||||
} else {
|
||||
log.warn("We got a hash exceeding our permitted size");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -49,11 +49,10 @@ import static bisq.network.p2p.storage.TestState.*;
|
||||
* Each subclass (Payload type) can optionally add additional tests that verify functionality only relevant
|
||||
* to that payload.
|
||||
*
|
||||
* Each test case is run through 4 entry points to verify the correct behavior:
|
||||
* Each test case is run through 3 entry points to verify the correct behavior:
|
||||
*
|
||||
* 1. RequestData path [addPersistableNetworkPayloadFromInitialRequest]
|
||||
* 2 & 3 Client API [addPersistableNetworkPayload(reBroadcast=(true && false))]
|
||||
* 4. onMessage() [onMessage(AddPersistableNetworkPayloadMessage)]
|
||||
* 1 & 2 Client API [addPersistableNetworkPayload(reBroadcast=(true && false))]
|
||||
* 3. onMessage() [onMessage(AddPersistableNetworkPayloadMessage)]
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public class P2PDataStoragePersistableNetworkPayloadTest {
|
||||
@ -81,11 +80,6 @@ public class P2PDataStoragePersistableNetworkPayloadTest {
|
||||
enum TestCase {
|
||||
PUBLIC_API,
|
||||
ON_MESSAGE,
|
||||
INIT,
|
||||
}
|
||||
|
||||
boolean expectBroadcastOnStateChange() {
|
||||
return this.testCase != TestCase.INIT;
|
||||
}
|
||||
|
||||
boolean expectedIsDataOwner() {
|
||||
@ -95,9 +89,7 @@ public class P2PDataStoragePersistableNetworkPayloadTest {
|
||||
void doAddAndVerify(PersistableNetworkPayload persistableNetworkPayload, boolean expectedReturnValue, boolean expectedStateChange) {
|
||||
SavedTestState beforeState = this.testState.saveTestState(persistableNetworkPayload);
|
||||
|
||||
if (this.testCase == TestCase.INIT) {
|
||||
Assert.assertEquals(expectedReturnValue, this.testState.mockedStorage.addPersistableNetworkPayloadFromInitialRequest(persistableNetworkPayload));
|
||||
} else if (this.testCase == TestCase.PUBLIC_API) {
|
||||
if (this.testCase == TestCase.PUBLIC_API) {
|
||||
Assert.assertEquals(expectedReturnValue,
|
||||
this.testState.mockedStorage.addPersistableNetworkPayload(persistableNetworkPayload, TestState.getTestNodeAddress(), true, this.allowBroadcast, this.reBroadcast, this.checkDate));
|
||||
} else { // onMessage
|
||||
@ -107,9 +99,7 @@ public class P2PDataStoragePersistableNetworkPayloadTest {
|
||||
testState.mockedStorage.onMessage(new AddPersistableNetworkPayloadMessage(persistableNetworkPayload), mockedConnection);
|
||||
}
|
||||
|
||||
boolean expectedBroadcast = expectedStateChange && this.expectBroadcastOnStateChange();
|
||||
|
||||
this.testState.verifyPersistableAdd(beforeState, persistableNetworkPayload, expectedStateChange, expectedBroadcast, expectedBroadcast, this.expectedIsDataOwner());
|
||||
this.testState.verifyPersistableAdd(beforeState, persistableNetworkPayload, expectedStateChange, expectedStateChange, expectedStateChange, this.expectedIsDataOwner());
|
||||
}
|
||||
|
||||
@Before
|
||||
@ -123,9 +113,6 @@ public class P2PDataStoragePersistableNetworkPayloadTest {
|
||||
public static Collection<Object[]> data() {
|
||||
List<Object[]> data = new ArrayList<>();
|
||||
|
||||
// Init doesn't use other parameters
|
||||
data.add(new Object[] { TestCase.INIT, false, false, false });
|
||||
|
||||
// onMessage doesn't use other parameters
|
||||
data.add(new Object[] { TestCase.ON_MESSAGE, false, false, false });
|
||||
|
||||
@ -149,9 +136,8 @@ public class P2PDataStoragePersistableNetworkPayloadTest {
|
||||
public void addPersistableNetworkPayloadDuplicate() {
|
||||
doAddAndVerify(this.persistableNetworkPayload, true, true);
|
||||
|
||||
// Second call only succeeds if reBroadcast was set or we are adding through the init
|
||||
// path which just overwrites
|
||||
boolean expectedReturnValue = this.reBroadcast || this.testCase == TestCase.INIT;
|
||||
// Second call only succeeds if reBroadcast was set
|
||||
boolean expectedReturnValue = this.reBroadcast;
|
||||
doAddAndVerify(this.persistableNetworkPayload, expectedReturnValue, false);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user