Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test scaffolding for cross-chain tests #1121

Merged
merged 12 commits into from
Mar 13, 2023
37 changes: 36 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ step_setup_global_packages: &step_setup_global_packages
npm set cache ~/.npm
sudo npm install -g [email protected]
npm ci
git submodule update --remote --init
git submodule update --init
npm run provision:token:contracts
cd ./lib/safe-contracts && yarn --ignore-scripts && cd ../../
npm run provision:safe:contracts
step_pull_solc_docker: &step_pull_solc_docker
run:
name: "Pull solc docker image"
Expand Down Expand Up @@ -279,6 +281,36 @@ jobs:
- coverage-chainid-5
- coverage-chainid-100
- coverage-chainid-777
test-bridging-coverage:
<<: *job_common
steps:
- checkout
- <<: *step_restore_cache
- setup_remote_docker:
version: 19.03.13
- <<: *step_pull_solc_docker
- <<: *step_setup_global_packages
- run:
name: "Running coverage tests for home-side of bridge"
command: npm run test:contracts:bridging:1:coverage
environment:
NODE_OPTIONS: --max_old_space_size=4096
- run:
name: "Reset chains"
command: |
sudo apt-get update
sudo apt-get install lsof
npm run stop:blockchain:client
- run:
name: "Running coverage tests for foreign-side of bridge"
command: npm run test:contracts:bridging:2:coverage
environment:
NODE_OPTIONS: --max_old_space_size=4096
- persist_to_workspace:
root: ./
paths:
- coverage-cross-chain-foreign
- coverage-cross-chain-home
check-coverage:
<<: *job_common
steps:
Expand Down Expand Up @@ -343,6 +375,8 @@ workflows:
context: dockerhub-credentials
- test-upgrade-coverage:
context: dockerhub-credentials
- test-bridging-coverage:
context: dockerhub-credentials
- check-coverage:
context: dockerhub-credentials
requires:
Expand All @@ -351,6 +385,7 @@ workflows:
- test-reputation-coverage
- test-chainid-coverage
- test-upgrade-coverage
- test-bridging-coverage
# nightly:
# triggers:
# - schedule:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ coverage-contracts
coverage-merged
coverage-reputation
coverage-chainid-*
coverage-cross-chain-*
coverage.json
.nyc_output
coverage-miner
Expand Down
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@
path = lib/colonyToken
url = https://github.com/JoinColony/colonyToken.git
branch = master
[submodule "lib/safe-contracts"]
path = lib/safe-contracts
url = https://github.com/safe-global/safe-contracts
ignore = dirty
23 changes: 23 additions & 0 deletions .solcover.crosschain.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const config = require("./.solcover.js")
const log = console.log;
const { execSync } = require("child_process");

const existingCompileComplete = config.onCompileComplete;

config.istanbulFolder = `./coverage-cross-chain-${process.env.TRUFFLE_HOME ? "home" : "foreign"}`


function provisionSafeContracts(){
let output;
const provisionSafeContracts = `yarn run provision:safe:contracts`;

log('Provisioning Safe contracts...')
execSync(provisionSafeContracts);
}

config.onCompileComplete = function() {
existingCompileComplete();
provisionSafeContracts();
}

module.exports = config
33 changes: 30 additions & 3 deletions .solcover.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@ const log = console.log;
// Copies pre-built token artifacts to .coverage_artifacts/contracts
function provisionTokenContracts(config){
let output;
const provisionColonyToken = `bash ./scripts/provision-token-contracts.sh`;
const provisionColonyToken = `BUILD_DIR="build-coverage" bash ./scripts/provision-token-contracts.sh`;

log('Provisioning ColonyToken contracts...')
output = execSync(provisionColonyToken);
log(output.toString())

const provisionSafeContracts = `BUILD_DIR="build-coverage" bash ./scripts/provision-safe-contracts.sh`;

log('Provisioning Safe contracts...')
output = execSync(provisionSafeContracts);
log(output.toString())

}

module.exports = {
Expand All @@ -25,9 +32,29 @@ module.exports = {
network_id: 1999,
account_keys_path: "./ganache-accounts.json",
vmErrorsOnRPCResponse: false,
total_accounts: 18
total_accounts: 18,
accounts: [
{secretKey:"0x0355596cdb5e5242ad082c4fe3f8bbe48c9dba843fe1f99dd8272f487e70efae","balance":"100000000000000000000"},
{secretKey:"0xe9aebe8791ad1ebd33211687e9c53f13fe8cca53b271a6529c7d7ba05eda5ce2","balance":"100000000000000000000"},
{secretKey:"0x6f36842c663f5afc0ef3ac986ec62af9d09caa1bbf59a50cdb7334c9cc880e65","balance":"100000000000000000000"},
{secretKey:"0xf184b7741073fc5983df87815e66425928fa5da317ef18ef23456241019bd9c7","balance":"100000000000000000000"},
{secretKey:"0x7770023bfebe3c8e832b98d6c0874f75580730baba76d7ec05f2780444cc7ed3","balance":"100000000000000000000"},
{secretKey:"0xa9442c0092fe38933fcf2319d5cf9fd58e3be5409a26e2045929f9d2a16fb090","balance":"100000000000000000000"},
{secretKey:"0x06af2c8000ab1b096f2ee31539b1e8f3783236eba5284808c2b17cfb49f0f538","balance":"100000000000000000000"},
{secretKey:"0x7edaec9e5f8088a10b74c1d86108ce879dccded88fa9d4a5e617353d2a88e629","balance":"100000000000000000000"},
{secretKey:"0xe31c452e0631f67a629e88790d3119ea9505fae758b54976d2bf12bd8300ef4a","balance":"100000000000000000000"},
{secretKey:"0x5e383d2f98ac821c555333e5bb6109ca41ae89d613cb84887a2bdb933623c4e3","balance":"100000000000000000000"},
{secretKey:"0x33d2f6f6cc410c1d46d58f17efdd2b53a71527b27eaa7f2edcade351feb87425","balance":"100000000000000000000"},
{secretKey:"0x32400a48ff16119c134eef44e2627502ce6e367bc4810be07642275a9db47bf7","balance":"100000000000000000000"},
{secretKey:"0x2a0f58ae46261b4ec4b635bde4bfabb680245c2a3abff7f54945ae44f7629b1d","balance":"100000000000000000000"},
{secretKey:"0x94fe165ae1db4f7d24fa5506ecbf083dcb934823600cb56e2a191722f0b40903","balance":"100000000000000000000"},
{secretKey:"0xc93aad16dd4aca2fa61316f83307362306ad6b2fc3e4a91801ce9010be7d9b63","balance":"100000000000000000000"},
{secretKey:"0x27f8f0be23a027196c7b8f4c98502b113e3fa1474fc10eda21ef3b5473c1b773","balance":"100000000000000000000"},
{secretKey:"0xb6245e0d2b64a92c0e6359500231087278f499de46fdfa351d4f1e09faf95a47","balance":"100000000000000000000"},
{secretKey:"0xfe6066af949ec3c2c88ac10f47907c6d4e200c37b28b5af49e7d0ffd5c301c5c","balance":"100000000000000000000"}
]
},
onCompileComplete: provisionTokenContracts,
istanbulFolder: "./coverage-contracts",
modifierWhitelist: ["always"],
}
}
44 changes: 44 additions & 0 deletions contracts/testHelpers/BridgeMock.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
This file is part of The Colony Network.

The Colony Network is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

The Colony Network is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with The Colony Network. If not, see <http://www.gnu.org/licenses/>.
*/

pragma solidity 0.7.3;


contract BridgeMock {
event UserRequestForSignature(bytes32 indexed messageId, bytes encodedData);

function requireToPassMessage(address _target, bytes memory _data, uint256 _gasLimit) public {
emit UserRequestForSignature(keccak256(abi.encodePacked(_target,_data,block.timestamp)), abi.encode(_target, _data, _gasLimit, msg.sender));
}

event RelayedMessage(address sender, address executor, bytes32 messageId, bool status);

function execute(address _target, bytes memory _data, uint256 _gasLimit, bytes32 _messageId, address _sender) public {
bool success;
assembly {
// call contract at address a with input mem[in…(in+insize))
// providing g gas and v wei and output area mem[out…(out+outsize))
// returning 0 on error (eg. out of gas) and 1 on success

// call(g, a, v, in, insize, out, outsize)
success := call(_gasLimit, _target, 0, add(_data, 0x20), mload(_data), 0, 0)
}

emit RelayedMessage(_sender, msg.sender, _messageId, success);
}

}
80 changes: 80 additions & 0 deletions contracts/testHelpers/ERC721Mock.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
This file is part of The Colony Network.

The Colony Network is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

The Colony Network is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with The Colony Network. If not, see <http://www.gnu.org/licenses/>.
*/

pragma solidity 0.7.3;

contract ERC721Mock {

event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);

// Mapping owner address to token count
mapping(address => uint256) private _balances;

// Mapping from token ID to owner address
mapping(uint256 => address) private _owners;

// Mapping from owner to operator approvals
mapping(address => mapping(address => bool)) private _operatorApprovals;

function mint(address to, uint256 tokenId) external virtual {
require(to != address(0), "ERC721: mint to the zero address");

_balances[to] += 1;

_owners[tokenId] = to;

emit Transfer(address(0), to, tokenId);
}

function balanceOf(address owner) public view virtual returns (uint256) {
require(owner != address(0), "ERC721: address zero is not a valid owner");
return _balances[owner];
}

function ownerOf(uint256 tokenId) public view virtual returns (address) {
address owner = _owners[tokenId];
require(owner != address(0), "ERC721: invalid token ID");
return owner;
}

function safeTransferFrom(
address from,
address to,
uint256 tokenId
) public virtual {
require(msg.sender == ownerOf(tokenId), "ERC721: caller is not token owner or approved");
// just using simple transfer for mock purposes.
_transfer(from, to, tokenId);
}

function _transfer(
address from,
address to,
uint256 tokenId
) internal virtual {
require(ownerOf(tokenId) == from, "ERC721: transfer from incorrect owner");
require(to != address(0), "ERC721: transfer to the zero address");

_balances[from] -= 1;
_balances[to] += 1;

_owners[tokenId] = to;

emit Transfer(from, to, tokenId);
}

}
42 changes: 42 additions & 0 deletions contracts/testHelpers/ZodiacBridgeModuleMock.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
This file is part of The Colony Network.

The Colony Network is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

The Colony Network is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with The Colony Network. If not, see <http://www.gnu.org/licenses/>.
*/

pragma solidity 0.7.3;

interface IAvatar {
function execTransactionFromModule(
address to,
uint256 value,
bytes memory data,
uint8 operation
) external returns (bool success);
}

contract ZodiacBridgeModuleMock {
event SafeTransactionExecuted(bool success);

address avatar;
constructor (address _avatar) {
avatar = _avatar;
}

function executeTransaction(address _target, uint256 _value, bytes memory _data, uint8 _operation) public {
require(_operation == 0, "operation-must-be-zero");
bool success = IAvatar(avatar).execTransactionFromModule(_target, _value, _data, _operation);
emit SafeTransactionExecuted(success);
}
}
1 change: 1 addition & 0 deletions lib/safe-contracts
Submodule safe-contracts added at 767ef3
Loading