Skip to content

Commit

Permalink
chore: fmt!
Browse files Browse the repository at this point in the history
  • Loading branch information
guidiaz committed Oct 8, 2024
1 parent 9c56956 commit 28a0c98
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 66 deletions.
1 change: 1 addition & 0 deletions contracts/core/WitnetDeployer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
pragma solidity >=0.8.0 <0.9.0;

import "./WitnetProxy.sol";

import "../libs/Create3.sol";

/// @notice WitnetDeployer contract used both as CREATE2 (EIP-1014) factory for Witnet artifacts,
Expand Down
112 changes: 56 additions & 56 deletions contracts/libs/Witnet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ library Witnet {
using WitnetCBOR for WitnetCBOR.CBOR;
using WitnetCBOR for WitnetCBOR.CBOR[];

uint32 constant internal WIT_1_GENESIS_TIMESTAMP = 0; // TBD
uint32 constant internal WIT_1_SECS_PER_EPOCH = 45;
uint32 constant internal WIT_1_GENESIS_TIMESTAMP = 0; // TBD
uint32 constant internal WIT_1_SECS_PER_EPOCH = 45;

uint32 constant internal WIT_2_GENESIS_BEACON_INDEX = 0; // TBD
uint32 constant internal WIT_2_GENESIS_BEACON_PREV_INDEX = 0; // TBD
Expand Down Expand Up @@ -424,7 +424,7 @@ library Witnet {


/// =======================================================================
/// --- Witnet.Beacon helper functions ------------------------------------
/// --- Beacon helper functions ------------------------------------

function equals(Beacon storage self, Beacon calldata other)
internal view returns (bool)
Expand Down Expand Up @@ -458,7 +458,7 @@ library Witnet {


/// =======================================================================
/// --- Witnet.FastForward helper functions -------------------------------
/// --- FastForward helper functions -------------------------------

function head(FastForward[] calldata rollup)
internal pure returns (Beacon calldata)
Expand All @@ -468,7 +468,7 @@ library Witnet {


/// ===============================================================================================================
/// --- Witnet.Query*Report helper methods ------------------------------------------------------------------------
/// --- Query*Report helper methods ------------------------------------------------------------------------

function queryRelayer(QueryResponseReport calldata self) internal pure returns (address) {
return recoverAddr(self.witDrRelayerSignature, self.queryHash);
Expand Down Expand Up @@ -496,15 +496,15 @@ library Witnet {


/// ===============================================================================================================
/// --- 'Witnet.Result' helper methods ----------------------------------------------------------------------------
/// --- 'Result' helper methods ----------------------------------------------------------------------------

modifier _isReady(Result memory result) {
require(result.success, "Witnet: tried to decode value from errored result.");
_;
}

/// @dev Decode an address from the Witnet.Result's CBOR value.
function asAddress(Witnet.Result memory result)
/// @dev Decode an address from the Result's CBOR value.
function asAddress(Result memory result)
internal pure
_isReady(result)
returns (address)
Expand All @@ -516,138 +516,138 @@ library Witnet {
}
}

/// @dev Decode a `bool` value from the Witnet.Result's CBOR value.
function asBool(Witnet.Result memory result)
/// @dev Decode a `bool` value from the Result's CBOR value.
function asBool(Result memory result)
internal pure
_isReady(result)
returns (bool)
{
return result.value.readBool();
}

/// @dev Decode a `bytes` value from the Witnet.Result's CBOR value.
function asBytes(Witnet.Result memory result)
/// @dev Decode a `bytes` value from the Result's CBOR value.
function asBytes(Result memory result)
internal pure
_isReady(result)
returns(bytes memory)
{
return result.value.readBytes();
}

/// @dev Decode a `bytes4` value from the Witnet.Result's CBOR value.
function asBytes4(Witnet.Result memory result)
/// @dev Decode a `bytes4` value from the Result's CBOR value.
function asBytes4(Result memory result)
internal pure
_isReady(result)
returns (bytes4)
{
return toBytes4(asBytes(result));
}

/// @dev Decode a `bytes32` value from the Witnet.Result's CBOR value.
function asBytes32(Witnet.Result memory result)
/// @dev Decode a `bytes32` value from the Result's CBOR value.
function asBytes32(Result memory result)
internal pure
_isReady(result)
returns (bytes32)
{
return toBytes32(asBytes(result));
}

/// @notice Returns the Witnet.Result's unread CBOR value.
function asCborValue(Witnet.Result memory result)
/// @notice Returns the Result's unread CBOR value.
function asCborValue(Result memory result)
internal pure
_isReady(result)
returns (WitnetCBOR.CBOR memory)
{
return result.value;
}

/// @notice Decode array of CBOR values from the Witnet.Result's CBOR value.
function asCborArray(Witnet.Result memory result)
/// @notice Decode array of CBOR values from the Result's CBOR value.
function asCborArray(Result memory result)
internal pure
_isReady(result)
returns (WitnetCBOR.CBOR[] memory)
{
return result.value.readArray();
}

/// @dev Decode a fixed16 (half-precision) numeric value from the Witnet.Result's CBOR value.
/// @dev Decode a fixed16 (half-precision) numeric value from the Result's CBOR value.
/// @dev Due to the lack of support for floating or fixed point arithmetic in the EVM, this method offsets all values.
/// by 5 decimal orders so as to get a fixed precision of 5 decimal positions, which should be OK for most `fixed16`.
/// use cases. In other words, the output of this method is 10,000 times the actual value, encoded into an `int32`.
function asFixed16(Witnet.Result memory result)
function asFixed16(Result memory result)
internal pure
_isReady(result)
returns (int32)
{
return result.value.readFloat16();
}

/// @dev Decode an array of fixed16 values from the Witnet.Result's CBOR value.
function asFixed16Array(Witnet.Result memory result)
/// @dev Decode an array of fixed16 values from the Result's CBOR value.
function asFixed16Array(Result memory result)
internal pure
_isReady(result)
returns (int32[] memory)
{
return result.value.readFloat16Array();
}

/// @dev Decode an `int64` value from the Witnet.Result's CBOR value.
function asInt(Witnet.Result memory result)
/// @dev Decode an `int64` value from the Result's CBOR value.
function asInt(Result memory result)
internal pure
_isReady(result)
returns (int)
{
return result.value.readInt();
}

/// @dev Decode an array of integer numeric values from a Witnet.Result as an `int[]` array.
/// @param result An instance of Witnet.Result.
/// @return The `int[]` decoded from the Witnet.Result.
function asIntArray(Witnet.Result memory result)
/// @dev Decode an array of integer numeric values from a Result as an `int[]` array.
/// @param result An instance of Result.
/// @return The `int[]` decoded from the Result.
function asIntArray(Result memory result)
internal pure
_isReady(result)
returns (int[] memory)
{
return result.value.readIntArray();
}

/// @dev Decode a `string` value from the Witnet.Result's CBOR value.
/// @param result An instance of Witnet.Result.
/// @return The `string` decoded from the Witnet.Result.
function asText(Witnet.Result memory result)
/// @dev Decode a `string` value from the Result's CBOR value.
/// @param result An instance of Result.
/// @return The `string` decoded from the Result.
function asText(Result memory result)
internal pure
_isReady(result)
returns(string memory)
{
return result.value.readString();
}

/// @dev Decode an array of strings from the Witnet.Result's CBOR value.
/// @param result An instance of Witnet.Result.
/// @return The `string[]` decoded from the Witnet.Result.
function asTextArray(Witnet.Result memory result)
/// @dev Decode an array of strings from the Result's CBOR value.
/// @param result An instance of Result.
/// @return The `string[]` decoded from the Result.
function asTextArray(Result memory result)
internal pure
_isReady(result)
returns (string[] memory)
{
return result.value.readStringArray();
}

/// @dev Decode a `uint64` value from the Witnet.Result's CBOR value.
/// @param result An instance of Witnet.Result.
/// @return The `uint` decoded from the Witnet.Result.
function asUint(Witnet.Result memory result)
/// @dev Decode a `uint64` value from the Result's CBOR value.
/// @param result An instance of Result.
/// @return The `uint` decoded from the Result.
function asUint(Result memory result)
internal pure
_isReady(result)
returns (uint)
{
return result.value.readUint();
}

/// @dev Decode an array of `uint64` values from the Witnet.Result's CBOR value.
/// @param result An instance of Witnet.Result.
/// @return The `uint[]` decoded from the Witnet.Result.
function asUintArray(Witnet.Result memory result)
/// @dev Decode an array of `uint64` values from the Result's CBOR value.
/// @param result An instance of Result.
/// @return The `uint[]` decoded from the Result.
function asUintArray(Result memory result)
internal pure
returns (uint[] memory)
{
Expand All @@ -656,7 +656,7 @@ library Witnet {


/// ===============================================================================================================
/// --- Witnet.ResultErrorCodes helper methods --------------------------------------------------------------------
/// --- ResultErrorCodes helper methods --------------------------------------------------------------------

function isCircumstantial(ResultErrorCodes self) internal pure returns (bool) {
return (self == ResultErrorCodes.CircumstantialFailure);
Expand Down Expand Up @@ -689,7 +689,7 @@ library Witnet {


/// ===============================================================================================================
/// --- 'Witnet.RadonSLA' helper methods --------------------------------------------------------------------------
/// --- 'RadonSLA' helper methods --------------------------------------------------------------------------

function equalOrGreaterThan(RadonSLA memory a, RadonSLA memory b)
internal pure returns (bool)
Expand All @@ -709,8 +709,8 @@ library Witnet {
);
}

function toV1(RadonSLA memory self) internal pure returns (Witnet.RadonSLAv1 memory) {
return Witnet.RadonSLAv1({
function toV1(RadonSLA memory self) internal pure returns (RadonSLAv1 memory) {
return RadonSLAv1({
numWitnesses: self.witNumWitnesses,
minConsensusPercentage: 51,
witnessReward: self.witUnitaryReward,
Expand Down Expand Up @@ -771,12 +771,12 @@ library Witnet {
}


/// @dev Transform given bytes into a Witnet.Result instance.
/// @dev Transform given bytes into a Result instance.
/// @param cborBytes Raw bytes representing a CBOR-encoded value.
/// @return A `Witnet.Result` instance.
/// @return A `Result` instance.
function toWitnetResult(bytes memory cborBytes)
internal pure
returns (Witnet.Result memory)
returns (Result memory)
{
WitnetCBOR.CBOR memory cborValue = WitnetCBOR.fromBytes(cborBytes);
return _resultFromCborValue(cborValue);
Expand Down Expand Up @@ -1001,15 +1001,15 @@ library Witnet {
}
}

/// @dev Decode a CBOR value into a Witnet.Result instance.
/// @dev Decode a CBOR value into a Result instance.
function _resultFromCborValue(WitnetCBOR.CBOR memory cbor)
private pure
returns (Witnet.Result memory)
returns (Result memory)
{
// Witnet uses CBOR tag 39 to represent RADON error code identifiers.
// [CBOR tag 39] Identifiers for CBOR: https://github.com/lucas-clemente/cbor-specs/blob/master/id.md
bool success = cbor.tag != 39;
return Witnet.Result(success, cbor);
return Result(success, cbor);
}

/// @dev Calculate length of string-equivalent to given bytes32.
Expand Down
2 changes: 1 addition & 1 deletion scripts/vanity2gen.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ module.exports = async function () {
} else if (argv === "--hits") {
hits = parseInt(args[index + 1])
} else if (argv === "--network") {
[ecosystem, network] = utils.getRealmNetworkFromString(args[index + 1].toLowerCase())
[, network] = utils.getRealmNetworkFromString(args[index + 1].toLowerCase())
} else if (argv === "--hexArgs") {
hexArgs = args[index + 1].toLowerCase()
if (hexArgs.startsWith("0x")) hexArgs = hexArgs.slice(2)
Expand Down
17 changes: 8 additions & 9 deletions test/witOracleRadonRegistry.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ import("chai")

const utils = require("../src/utils")
const { expectEvent, expectRevert } = require("@openzeppelin/test-helpers")
const { expectRevertCustomError } = require("custom-error-test-helper")

const WitOracleRadonRegistry = artifacts.require("WitOracleRadonRegistryDefault")
const WitOracleRadonEncodingLib = artifacts.require("WitOracleRadonEncodingLib")
const Witnet = artifacts.require("Witnet")

contract("WitOracleRadonRegistry", (accounts) => {
const creatorAddress = accounts[0]
Expand Down Expand Up @@ -87,8 +85,6 @@ contract("WitOracleRadonRegistry", (accounts) => {
})

context("IWitOracleRadonRegistry", async () => {
let slaHash

let concathashReducerHash
let modeNoFiltersReducerHash
let stdev15ReducerHash
Expand Down Expand Up @@ -146,7 +142,7 @@ contract("WitOracleRadonRegistry", (accounts) => {
"emits new data provider and source events when verifying a new http-get source for the first time", async () => {
const tx = await radonRegistry.verifyRadonRetrieval(
1, // requestMethod
"https://api.binance.us/api/v3/ticker/price?symbol=\\0\\\\1\\",
"https://api.binance.us/api/v3/ticker/price?symbol=\\0\\\\1\\",
"", // requestBody
[], // requestHeaders
"0x841877821864696c61737450726963658218571a000f4240185b", // requestRadonScript
Expand Down Expand Up @@ -188,7 +184,7 @@ contract("WitOracleRadonRegistry", (accounts) => {
it("fork existing retrieval by settling one out of two parameters", async () => {
const tx = await radonRegistry.verifyRadonRetrieval(
binanceTickerHash,
"USD"
"USD"
)
assert.equal(tx.logs.length, 1)
expectEvent(
Expand Down Expand Up @@ -242,7 +238,10 @@ contract("WitOracleRadonRegistry", (accounts) => {
assert.equal(ds.headers[0][1], "witnet-rust")
assert.equal(ds.headers[1][0], "content-type")
assert.equal(ds.headers[1][1], "text/html; charset=utf-8")
assert.equal(ds.radonScript, "0x861877821866646461746182186664706f6f6c8218646b746f6b656e3150726963658218571a000f4240185b")
assert.equal(
ds.radonScript,
"0x861877821866646461746182186664706f6f6c8218646b746f6b656e3150726963658218571a000f4240185b"
)
})
})
})
Expand Down Expand Up @@ -369,7 +368,7 @@ contract("WitOracleRadonRegistry", (accounts) => {
assert(tx.logs.length === 0)
})
it("generates same hash when verifying same randomness request offchain", async () => {
const hash = await radonRegistry.methods['verifyRadonRequest(bytes32[],bytes32,bytes32,uint16,string[][])'].call(
const hash = await radonRegistry.methods["verifyRadonRequest(bytes32[],bytes32,bytes32,uint16,string[][])"].call(
[ // sources
rngSourceHash,
],
Expand Down Expand Up @@ -513,7 +512,7 @@ contract("WitOracleRadonRegistry", (accounts) => {
tx.receipt,
"NewRadonRequest"
)
heavyRetrievalHash = tx.logs[0].args.radHash
// heavyRetrievalHash = tx.logs[0].args.radHash
})
})
})
Expand Down

0 comments on commit 28a0c98

Please sign in to comment.