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
|
// 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
|
// 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.
|
// 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();
|
byte[] hash = payload.getHash();
|
||||||
if (payload.verifyHashSize()) {
|
if (payload.verifyHashSize()) {
|
||||||
ByteArray hashAsByteArray = new ByteArray(hash);
|
ByteArray hashAsByteArray = new ByteArray(hash);
|
||||||
appendOnlyDataStoreService.put(hashAsByteArray, payload);
|
appendOnlyDataStoreService.put(hashAsByteArray, payload);
|
||||||
return true;
|
|
||||||
} else {
|
} else {
|
||||||
log.warn("We got a hash exceeding our permitted size");
|
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
|
* Each subclass (Payload type) can optionally add additional tests that verify functionality only relevant
|
||||||
* to that payload.
|
* 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]
|
* 1 & 2 Client API [addPersistableNetworkPayload(reBroadcast=(true && false))]
|
||||||
* 2 & 3 Client API [addPersistableNetworkPayload(reBroadcast=(true && false))]
|
* 3. onMessage() [onMessage(AddPersistableNetworkPayloadMessage)]
|
||||||
* 4. onMessage() [onMessage(AddPersistableNetworkPayloadMessage)]
|
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public class P2PDataStoragePersistableNetworkPayloadTest {
|
public class P2PDataStoragePersistableNetworkPayloadTest {
|
||||||
@ -81,11 +80,6 @@ public class P2PDataStoragePersistableNetworkPayloadTest {
|
|||||||
enum TestCase {
|
enum TestCase {
|
||||||
PUBLIC_API,
|
PUBLIC_API,
|
||||||
ON_MESSAGE,
|
ON_MESSAGE,
|
||||||
INIT,
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean expectBroadcastOnStateChange() {
|
|
||||||
return this.testCase != TestCase.INIT;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean expectedIsDataOwner() {
|
boolean expectedIsDataOwner() {
|
||||||
@ -95,9 +89,7 @@ public class P2PDataStoragePersistableNetworkPayloadTest {
|
|||||||
void doAddAndVerify(PersistableNetworkPayload persistableNetworkPayload, boolean expectedReturnValue, boolean expectedStateChange) {
|
void doAddAndVerify(PersistableNetworkPayload persistableNetworkPayload, boolean expectedReturnValue, boolean expectedStateChange) {
|
||||||
SavedTestState beforeState = this.testState.saveTestState(persistableNetworkPayload);
|
SavedTestState beforeState = this.testState.saveTestState(persistableNetworkPayload);
|
||||||
|
|
||||||
if (this.testCase == TestCase.INIT) {
|
if (this.testCase == TestCase.PUBLIC_API) {
|
||||||
Assert.assertEquals(expectedReturnValue, this.testState.mockedStorage.addPersistableNetworkPayloadFromInitialRequest(persistableNetworkPayload));
|
|
||||||
} else if (this.testCase == TestCase.PUBLIC_API) {
|
|
||||||
Assert.assertEquals(expectedReturnValue,
|
Assert.assertEquals(expectedReturnValue,
|
||||||
this.testState.mockedStorage.addPersistableNetworkPayload(persistableNetworkPayload, TestState.getTestNodeAddress(), true, this.allowBroadcast, this.reBroadcast, this.checkDate));
|
this.testState.mockedStorage.addPersistableNetworkPayload(persistableNetworkPayload, TestState.getTestNodeAddress(), true, this.allowBroadcast, this.reBroadcast, this.checkDate));
|
||||||
} else { // onMessage
|
} else { // onMessage
|
||||||
@ -107,9 +99,7 @@ public class P2PDataStoragePersistableNetworkPayloadTest {
|
|||||||
testState.mockedStorage.onMessage(new AddPersistableNetworkPayloadMessage(persistableNetworkPayload), mockedConnection);
|
testState.mockedStorage.onMessage(new AddPersistableNetworkPayloadMessage(persistableNetworkPayload), mockedConnection);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean expectedBroadcast = expectedStateChange && this.expectBroadcastOnStateChange();
|
this.testState.verifyPersistableAdd(beforeState, persistableNetworkPayload, expectedStateChange, expectedStateChange, expectedStateChange, this.expectedIsDataOwner());
|
||||||
|
|
||||||
this.testState.verifyPersistableAdd(beforeState, persistableNetworkPayload, expectedStateChange, expectedBroadcast, expectedBroadcast, this.expectedIsDataOwner());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
@ -123,9 +113,6 @@ public class P2PDataStoragePersistableNetworkPayloadTest {
|
|||||||
public static Collection<Object[]> data() {
|
public static Collection<Object[]> data() {
|
||||||
List<Object[]> data = new ArrayList<>();
|
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
|
// onMessage doesn't use other parameters
|
||||||
data.add(new Object[] { TestCase.ON_MESSAGE, false, false, false });
|
data.add(new Object[] { TestCase.ON_MESSAGE, false, false, false });
|
||||||
|
|
||||||
@ -149,9 +136,8 @@ public class P2PDataStoragePersistableNetworkPayloadTest {
|
|||||||
public void addPersistableNetworkPayloadDuplicate() {
|
public void addPersistableNetworkPayloadDuplicate() {
|
||||||
doAddAndVerify(this.persistableNetworkPayload, true, true);
|
doAddAndVerify(this.persistableNetworkPayload, true, true);
|
||||||
|
|
||||||
// Second call only succeeds if reBroadcast was set or we are adding through the init
|
// Second call only succeeds if reBroadcast was set
|
||||||
// path which just overwrites
|
boolean expectedReturnValue = this.reBroadcast;
|
||||||
boolean expectedReturnValue = this.reBroadcast || this.testCase == TestCase.INIT;
|
|
||||||
doAddAndVerify(this.persistableNetworkPayload, expectedReturnValue, false);
|
doAddAndVerify(this.persistableNetworkPayload, expectedReturnValue, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user