-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor ContractCallSystemPrecompileHistoricalTest (#9185)
This PR refactors ContractCallSystemPrecompileHistoricalTest to use the web3j plugin test. This PR modifies: ContractCallSystemPrecompileHistoricalTest now uses the web3j plugin. Added prng and exchange rate historical solidity files. The rest of the modifications are via the spotlessApply --------- Signed-off-by: Kristiyan Selveliev <[email protected]>
- Loading branch information
1 parent
44a47ac
commit 764b172
Showing
7 changed files
with
109 additions
and
85 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
24 changes: 24 additions & 0 deletions
24
hedera-mirror-web3/src/test/solidity_historical/ExchangeRatePrecompileHistorical.sol
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,24 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
pragma solidity >=0.5.0 <0.9.0; | ||
|
||
contract ExchangeRatePrecompileHistorical { | ||
|
||
uint256 constant TINY_PARTS_PER_WHOLE = 100_000_000; | ||
address constant PRECOMPILE_ADDRESS = address(0x168); | ||
bytes4 constant TINYCENTS_TO_TINYBARS = bytes4(keccak256("tinycentsToTinybars(uint256)")); | ||
bytes4 constant TINYBARS_TO_TINYCENTS = bytes4(keccak256("tinybarsToTinycents(uint256)")); | ||
|
||
function tinycentsToTinybars(uint256 tinycents) external payable returns (uint256 tinybars) { | ||
(bool success, bytes memory result) = PRECOMPILE_ADDRESS.call{value: msg.value}( | ||
abi.encodeWithSelector(TINYCENTS_TO_TINYBARS, tinycents)); | ||
require(success); | ||
tinybars = abi.decode(result, (uint256)); | ||
} | ||
|
||
function tinybarsToTinycents(uint256 tinybars) external payable returns (uint256 tinycents) { | ||
(bool success, bytes memory result) = PRECOMPILE_ADDRESS.call{value: msg.value}( | ||
abi.encodeWithSelector(TINYBARS_TO_TINYCENTS, tinybars)); | ||
require(success); | ||
tinycents = abi.decode(result, (uint256)); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
hedera-mirror-web3/src/test/solidity_historical/IPrngSystemContractHistorical.sol
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,8 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
pragma solidity >=0.5.0 <0.9.0; | ||
|
||
interface IPrngSystemContractHistorical { | ||
// Generates a 256-bit pseudorandom seed using the first 256-bits of running hash from the latest RecordFile in the database. | ||
// Users can generate a pseudorandom number in a specified range using the seed by (integer value of seed % range) | ||
function getPseudorandomSeed() external returns (bytes32); | ||
} |
15 changes: 15 additions & 0 deletions
15
hedera-mirror-web3/src/test/solidity_historical/PrngSystemContractHistorical.sol
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,15 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
pragma solidity >=0.5.0 <0.9.0; | ||
|
||
import "./IPrngSystemContractHistorical.sol"; | ||
|
||
contract PrngSystemContractHistorical { | ||
address constant PRECOMPILE_ADDRESS = address(0x169); | ||
|
||
function getPseudorandomSeed() external payable returns (bytes32 randomBytes) { | ||
(bool success, bytes memory result) = PRECOMPILE_ADDRESS.call{value: msg.value}( | ||
abi.encodeWithSelector(IPrngSystemContractHistorical.getPseudorandomSeed.selector)); | ||
require(success); | ||
randomBytes = abi.decode(result, (bytes32)); | ||
} | ||
} |