typo, add test for parameter not present

Signed-off-by: garyschulte <garyschulte@gmail.com>
garyschulte 1 day ago
parent 09f55b8a56
commit 5ef0329d68
  1. 6
      ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugSetHead.java
  2. 46
      ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/DebugSetHeadTest.java

@ -75,7 +75,11 @@ public class DebugSetHead extends AbstractBlockParameterOrBlockHashMethod {
if (archive.isWorldStateAvailable(blockHeader.getStateRoot(), blockHeader.getBlockHash())) {
// WARNING, this can be dangerous for a DiffBasedWorldstate if a concurrent
// process attempts to move or modify the head worldstate.
// for Foreset worldstates, this is essentially a no-op.
// Ensure no block processing is occuring when using this feature.
// No engine-api, block import, sync, or mining should be running.
// Even p2p transaction processing will be very expensive and should be disabled.
//
// for Forest worldstates, this is essentially a no-op.
archive.getMutable(blockHeader.getStateRoot(), blockHeader.getBlockHash());
}
}

@ -14,6 +14,8 @@
*/
package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods;
import static java.lang.Boolean.FALSE;
import static java.lang.Boolean.TRUE;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
import org.hyperledger.besu.crypto.Hash;
@ -68,6 +70,27 @@ public class DebugSetHeadTest extends AbstractJsonRpcHttpServiceTest {
startService();
}
@ParameterizedTest
@ValueSource(
strings = {"0x01", "0x4e9a67b663f9abe03e7e9fd5452c9497998337077122f44ee78a466f6a7358de"})
public void assertOnlyChainHeadMovesWorldParameterAbsent(final String blockParam) {
var chainTip = blockchain.getChainHead().getBlockHeader();
var blockOne = getBlockHeaderForHashOrNumber(blockParam).orElse(null);
assertThat(blockOne).isNotNull();
assertThat(blockOne).isNotEqualTo(chainTip);
// move the head to param val, number or hash
debugSetHead.response(debugSetHead(blockParam, Optional.empty()));
// get the new chainTip:
var newChainTip = blockchain.getChainHead().getBlockHeader();
// assert the chain moved, and the worldstate did not
assertThat(newChainTip).isEqualTo(blockOne);
assertThat(archive.getMutable().rootHash()).isEqualTo(chainTip.getStateRoot());
}
@ParameterizedTest
@ValueSource(
strings = {
@ -84,7 +107,7 @@ public class DebugSetHeadTest extends AbstractJsonRpcHttpServiceTest {
assertThat(blockOne).isNotEqualTo(chainTip);
// move the head to param val, number or hash
debugSetHead.response(debugSetHead(blockParam, false));
debugSetHead.response(debugSetHead(blockParam, Optional.of(FALSE)));
// get the new chainTip:
var newChainTip = blockchain.getChainHead().getBlockHeader();
@ -110,7 +133,7 @@ public class DebugSetHeadTest extends AbstractJsonRpcHttpServiceTest {
assertThat(blockOne).isNotEqualTo(chainTip);
// move the head and worldstate to param val number or hash
debugSetHead.response(debugSetHead(blockParam, true));
debugSetHead.response(debugSetHead(blockParam, Optional.of(TRUE)));
// get the new chainTip:
var newChainTip = blockchain.getChainHead().getBlockHeader();
@ -125,13 +148,16 @@ public class DebugSetHeadTest extends AbstractJsonRpcHttpServiceTest {
var chainTip = blockchain.getChainHead().getBlockHeader();
// move the head to number just after chain head
var resp = debugSetHead.response(debugSetHead("" + chainTip.getNumber() + 1, false));
var resp =
debugSetHead.response(debugSetHead("" + chainTip.getNumber() + 1, Optional.of(TRUE)));
assertThat(resp.getType()).isEqualTo(RpcResponseType.ERROR);
// move the head to some arbitrary hash
var resp2 =
debugSetHead.response(
debugSetHead(Hash.keccak256(Bytes.fromHexString("0xdeadbeef")).toHexString(), false));
debugSetHead(
Hash.keccak256(Bytes.fromHexString("0xdeadbeef")).toHexString(),
Optional.of(TRUE)));
assertThat(resp2.getType()).isEqualTo(RpcResponseType.ERROR);
// get the new chainTip:
@ -143,9 +169,15 @@ public class DebugSetHeadTest extends AbstractJsonRpcHttpServiceTest {
}
private JsonRpcRequestContext debugSetHead(
final String numberOrHash, final Boolean moveWorldState) {
return new JsonRpcRequestContext(
new JsonRpcRequest("2.0", "debug_setHead", new Object[] {numberOrHash, moveWorldState}));
final String numberOrHash, final Optional<Boolean> moveWorldState) {
if (moveWorldState.isPresent()) {
return new JsonRpcRequestContext(
new JsonRpcRequest(
"2.0", "debug_setHead", new Object[] {numberOrHash, moveWorldState.get()}));
} else {
return new JsonRpcRequestContext(
new JsonRpcRequest("2.0", "debug_setHead", new Object[] {numberOrHash}));
}
}
private Optional<BlockHeader> getBlockHeaderForHashOrNumber(final String input) {

Loading…
Cancel
Save