Skip to content

Commit

Permalink
feat: add mocking contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
guidiaz committed Nov 29, 2023
1 parent 565c3bc commit cd14024
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 15 deletions.
25 changes: 14 additions & 11 deletions contracts/core/defaults/WitnetRequestBoardTrustableBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ abstract contract WitnetRequestBoardTrustableBase
using WitnetV2 for WitnetV2.Response;

bytes4 public immutable override specs = type(IWitnetRequestBoard).interfaceId;

WitnetRequestFactory immutable public override factory;
WitnetBytecodes immutable public override registry;

WitnetRequestFactory immutable private __factory;

modifier checkCallbackRecipient(address _addr, uint96 _callbackGasLimit) {
require(
Expand Down Expand Up @@ -76,8 +76,7 @@ abstract contract WitnetRequestBoardTrustableBase
"io.witnet.proxiable.board"
)
{
assert(address(_factory) != address(0) && address(_registry) != address(0));
factory = _factory;
__factory = _factory;
registry = _registry;
}

Expand All @@ -104,6 +103,10 @@ abstract contract WitnetRequestBoardTrustableBase
return bytes4(keccak256(abi.encode(address(this), block.chainid)));
}

function factory() virtual override public view returns (WitnetRequestFactory) {
return __factory;
}


// ================================================================================================================
// --- Yet to be implemented virtual methods ----------------------------------------------------------------------
Expand Down Expand Up @@ -158,16 +161,16 @@ abstract contract WitnetRequestBoardTrustableBase
__storage().base = base();

require(
address(factory).code.length > 0,
address(__factory).code.length > 0,
"WitnetRequestBoardTrustableBase: inexistent factory"
);
require(
factory.specs() == type(IWitnetRequestFactory).interfaceId,
__factory.specs() == type(IWitnetRequestFactory).interfaceId,
"WitnetRequestBoardTrustableBase: uncompliant factory"
);
require(
address(factory.witnet()) == address(this)
&& address(factory.registry()) == address(registry),
address(__factory.witnet()) == address(this)
&& address(__factory.registry()) == address(registry),
"WitnetRequestBoardTrustableBase: discordant factory"
);

Expand Down Expand Up @@ -734,7 +737,7 @@ abstract contract WitnetRequestBoardTrustableBase
/// Tells whether given address is included in the active reporters control list.
/// @param _reporter The address to be checked.
function isReporter(address _reporter) public view override returns (bool) {
return _acls().isReporter_[_reporter];
return __acls().isReporter_[_reporter];
}

/// Adds given addresses to the active reporters control list.
Expand All @@ -760,7 +763,7 @@ abstract contract WitnetRequestBoardTrustableBase
{
for (uint ix = 0; ix < _exReporters.length; ix ++) {
address _reporter = _exReporters[ix];
_acls().isReporter_[_reporter] = false;
__acls().isReporter_[_reporter] = false;
}
emit ReportersUnset(_exReporters);
}
Expand Down Expand Up @@ -983,7 +986,7 @@ abstract contract WitnetRequestBoardTrustableBase
{
for (uint ix = 0; ix < _reporters.length; ix ++) {
address _reporter = _reporters[ix];
_acls().isReporter_[_reporter] = true;
__acls().isReporter_[_reporter] = true;
}
emit ReportersSet(_reporters);
}
Expand Down
1 change: 0 additions & 1 deletion contracts/core/defaults/WitnetRequestFactoryDefault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ contract WitnetRequestFactoryDefault
"io.witnet.requests.factory"
)
{
assert(address(_witnet) != address(0) && address(_registry) != address(0));
witnet = _witnet;
registry = _registry;
// let logic contract be used as a factory, while avoiding further initializations:
Expand Down
6 changes: 3 additions & 3 deletions contracts/data/WitnetRequestBoardDataACLs.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ abstract contract WitnetRequestBoardDataACLs
}

constructor() {
_acls().isReporter_[msg.sender] = true;
__acls().isReporter_[msg.sender] = true;
}

modifier onlyReporters {
require(
_acls().isReporter_[msg.sender],
__acls().isReporter_[msg.sender],
"WitnetRequestBoard: unauthorized reporter"
);
_;
Expand All @@ -33,7 +33,7 @@ abstract contract WitnetRequestBoardDataACLs
// ================================================================================================================
// --- Internal functions -----------------------------------------------------------------------------------------

function _acls() internal pure returns (WitnetBoardACLs storage _struct) {
function __acls() internal pure returns (WitnetBoardACLs storage _struct) {
assembly {
_struct.slot := _WITNET_BOARD_ACLS_SLOTHASH
}
Expand Down
15 changes: 15 additions & 0 deletions contracts/mocks/WitnetBytecodesMock.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// SPDX-License-Identifier: MIT

pragma solidity >=0.7.0 <0.9.0;
pragma experimental ABIEncoderV2;

import "../core/defaults/WitnetBytecodesDefault.sol";

contract WitnetBytecodesMock is WitnetBytecodesDefault {
constructor()
WitnetBytecodesDefault(
false,
bytes32("mocked")
)
{}
}
15 changes: 15 additions & 0 deletions contracts/mocks/WitnetPriceFeedsMock.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// SPDX-License-Identifier: MIT

pragma solidity >=0.7.0 <0.9.0;
pragma experimental ABIEncoderV2;

import "../apps/WitnetPriceFeeds.sol";

contract WitnetPriceFeedsMock is WitnetPriceFeeds {
constructor(WitnetRequestBoard _wrb)
WitnetPriceFeeds(
msg.sender,
_wrb
)
{}
}
34 changes: 34 additions & 0 deletions contracts/mocks/WitnetRequestBoardMock.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// SPDX-License-Identifier: MIT

pragma solidity >=0.7.0 <0.9.0;
pragma experimental ABIEncoderV2;

import "./WitnetBytecodesMock.sol";
import "../core/defaults/WitnetRequestBoardTrustableDefault.sol";

contract WitnetRequestBoardMock
is
WitnetRequestBoardTrustableDefault
{
WitnetRequestFactory private __factory;

constructor(WitnetBytecodesMock _registry)
WitnetRequestBoardTrustableDefault(
WitnetRequestFactory(address(0)),
WitnetBytecodes(address(_registry)),
false,
bytes32("mocked"),
60000, 65000, 70000, 20000
)
{
__acls().isReporter_[msg.sender] = true;
}

function factory() override public view returns (WitnetRequestFactory) {
return __factory;
}

function setFactory(WitnetRequestFactory _factory) external onlyOwner {
__factory = _factory;
}
}
21 changes: 21 additions & 0 deletions contracts/mocks/WitnetRequestFactoryMock.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// SPDX-License-Identifier: MIT

pragma solidity >=0.7.0 <0.9.0;
pragma experimental ABIEncoderV2;

import "./WitnetRequestBoardMock.sol";
import "../core/defaults/WitnetRequestFactoryDefault.sol";

contract WitnetRequestFactoryMock
is
WitnetRequestFactoryDefault
{
constructor (WitnetRequestBoardMock _wrb)
WitnetRequestFactoryDefault(
WitnetRequestBoard(address(_wrb)),
WitnetBytecodes(_wrb.registry()),
false,
bytes32("mocked")
)
{}
}

0 comments on commit cd14024

Please sign in to comment.