Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ETCM-697: Added TestEthBlockServiceWrapper to accommodate response ac…
…cording to eth spec for retesteth. Fixed genesis loading for regular node
- Loading branch information
Igor Grahovac
committed
Apr 15, 2021
1 parent
e597217
commit 8f71d32
Showing
9 changed files
with
181 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
src/main/scala/io/iohk/ethereum/testmode/TestEthBlockServiceWrapper.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package io.iohk.ethereum.testmode | ||
|
||
import io.iohk.ethereum.domain.Blockchain | ||
import io.iohk.ethereum.jsonrpc.EthBlocksService.{BlockByBlockHashResponse, BlockByNumberResponse} | ||
import io.iohk.ethereum.jsonrpc.{BaseBlockResponse, EthBlockResponse, EthBlocksService, ServiceResponse} | ||
import io.iohk.ethereum.ledger.Ledger | ||
import io.iohk.ethereum.utils.Logger | ||
|
||
class TestEthBlockServiceWrapper(blockchain: Blockchain, ledger: Ledger) | ||
extends EthBlocksService(blockchain, ledger) | ||
with Logger { | ||
|
||
/** | ||
* Implements the eth_getBlockByHash method that fetches a requested block. | ||
* | ||
* @param request with the hash of the block requested | ||
* @return the block requested or None if the client doesn't have the block | ||
*/ | ||
override def getByBlockHash( | ||
request: EthBlocksService.BlockByBlockHashRequest | ||
): ServiceResponse[EthBlocksService.BlockByBlockHashResponse] = super | ||
.getByBlockHash(request) | ||
.map( | ||
_.map(blockByBlockResponse => | ||
BlockByBlockHashResponse( | ||
blockByBlockResponse.blockResponse.map(response => toEthResponse(response)) | ||
) | ||
) | ||
) | ||
|
||
/** | ||
* Implements the eth_getBlockByNumber method that fetches a requested block. | ||
* | ||
* @param request with the block requested (by it's number or by tag) | ||
* @return the block requested or None if the client doesn't have the block | ||
*/ | ||
override def getBlockByNumber( | ||
request: EthBlocksService.BlockByNumberRequest | ||
): ServiceResponse[EthBlocksService.BlockByNumberResponse] = super | ||
.getBlockByNumber(request) | ||
.map( | ||
_.map(blockByBlockResponse => | ||
BlockByNumberResponse( | ||
blockByBlockResponse.blockResponse.map(response => toEthResponse(response)) | ||
) | ||
) | ||
) | ||
|
||
private def toEthResponse(response: BaseBlockResponse) = EthBlockResponse( | ||
response.number, | ||
response.hash, | ||
response.mixHash, | ||
response.parentHash, | ||
response.nonce, | ||
response.sha3Uncles, | ||
response.logsBloom, | ||
response.transactionsRoot, | ||
response.stateRoot, | ||
response.receiptsRoot, | ||
response.miner, | ||
response.difficulty, | ||
response.totalDifficulty, | ||
response.extraData, | ||
response.size, | ||
response.gasLimit, | ||
response.gasUsed, | ||
response.timestamp, | ||
response.transactions, | ||
response.uncles | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters