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 b33db4e
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 9 deletions.
19 changes: 11 additions & 8 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
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
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
)
{}
}
30 changes: 30 additions & 0 deletions contracts/mocks/WitnetRequestBoardMock.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// SPDX-License-Identifier: MIT

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

import "./WitnetRequestFactoryMock.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
)
{
__factory = WitnetRequestFactory(address(new WitnetRequestFactoryMock(_registry)));
}

function factory() override public view returns (WitnetRequestFactory) {
return __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 "./WitnetBytecodesMock.sol";
import "../core/defaults/WitnetRequestFactoryDefault.sol";

contract WitnetRequestFactoryMock
is
WitnetRequestFactoryDefault
{
constructor (WitnetBytecodesMock _registry)
WitnetRequestFactoryDefault(
WitnetRequestBoard(msg.sender),
WitnetBytecodes(address(_registry)),
false,
bytes32("mocked")
)
{}
}

0 comments on commit b33db4e

Please sign in to comment.