Skip to content

Commit c092791

Browse files
committed
miner_getExtraData unit tests
Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>
1 parent 8ce9c93 commit c092791

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Copyright contributors to Hyperledger Besu.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
5+
* the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
10+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11+
* specific language governing permissions and limitations under the License.
12+
*
13+
* SPDX-License-Identifier: Apache-2.0
14+
*/
15+
package org.hyperledger.besu.ethereum.api.jsonrpc.internal.methods.miner;
16+
17+
import static org.assertj.core.api.Assertions.assertThat;
18+
19+
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequest;
20+
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext;
21+
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse;
22+
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse;
23+
import org.hyperledger.besu.ethereum.core.ImmutableMiningParameters;
24+
import org.hyperledger.besu.ethereum.core.MiningParameters;
25+
26+
import org.apache.tuweni.bytes.Bytes;
27+
import org.junit.jupiter.api.Test;
28+
29+
public class MinerGetExtraDataTest {
30+
31+
@Test
32+
public void shouldReturnDefaultExtraData() {
33+
final MiningParameters miningParameters = ImmutableMiningParameters.newDefault();
34+
final MinerGetExtraData method = new MinerGetExtraData(miningParameters);
35+
final JsonRpcRequestContext request =
36+
new JsonRpcRequestContext(new JsonRpcRequest("2.0", method.getName(), new Object[] {}));
37+
38+
final JsonRpcResponse expected = new JsonRpcSuccessResponse(request.getRequest().getId(), "0x");
39+
40+
final JsonRpcResponse actual = method.response(request);
41+
assertThat(actual).usingRecursiveComparison().isEqualTo(expected);
42+
}
43+
44+
@Test
45+
public void shouldReturnSetAtRuntimeExtraData() {
46+
final MiningParameters miningParameters = ImmutableMiningParameters.newDefault();
47+
final MinerGetExtraData method = new MinerGetExtraData(miningParameters);
48+
final var extraData = "0x123456";
49+
final Bytes extraDataAtRuntime = Bytes.fromHexString(extraData);
50+
51+
miningParameters.setExtraData(extraDataAtRuntime);
52+
53+
final JsonRpcRequestContext request =
54+
new JsonRpcRequestContext(new JsonRpcRequest("2.0", method.getName(), new Object[] {}));
55+
56+
final JsonRpcResponse expected =
57+
new JsonRpcSuccessResponse(request.getRequest().getId(), extraData);
58+
59+
final JsonRpcResponse actual = method.response(request);
60+
assertThat(actual).usingRecursiveComparison().isEqualTo(expected);
61+
}
62+
}

0 commit comments

Comments
 (0)