From 79b18c7bab3cc8cc0f4f104fe2fb80512d7f7097 Mon Sep 17 00:00:00 2001 From: Guilherme Soares Date: Mon, 22 Jan 2024 14:04:42 +0100 Subject: [PATCH 1/2] feat: Fixed unit tests and add tests for the new federation version --- bridge/.gitignore | 1 + bridge/abi/FederationV3.json | 711 ++++++++++++++++++ bridge/contracts/Federation/FederationV3.sol | 263 +++++++ bridge/deploy/06_deploy_federation.js | 6 +- bridge/deploy/07_deploy_federationProxy.js | 7 +- .../deploy/upgrades/02_upgrade_federation.js | 4 +- bridge/deployed/deployHelper.js | 1 + bridge/package.json | 2 +- bridge/test/AllowTokens_test.js | 4 +- bridge/test/BridgeV3_to_bridgeV4_test.js | 10 +- bridge/test/Bridge_upgrade_test.js | 22 +- bridge/test/Federation_test.js | 259 ++----- 12 files changed, 1075 insertions(+), 215 deletions(-) create mode 100644 bridge/abi/FederationV3.json create mode 100644 bridge/contracts/Federation/FederationV3.sol diff --git a/bridge/.gitignore b/bridge/.gitignore index aa5a812af..238058d99 100644 --- a/bridge/.gitignore +++ b/bridge/.gitignore @@ -56,3 +56,4 @@ pids # Script files arguments.js +database.json diff --git a/bridge/abi/FederationV3.json b/bridge/abi/FederationV3.json new file mode 100644 index 000000000..c5914398f --- /dev/null +++ b/bridge/abi/FederationV3.json @@ -0,0 +1,711 @@ +[ + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "bridge", + "type": "address" + } + ], + "name": "BridgeChanged", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "federator", + "type": "address" + }, + { + "indexed": true, + "internalType": "bytes32", + "name": "transactionHash", + "type": "bytes32" + }, + { + "indexed": true, + "internalType": "bytes32", + "name": "transactionId", + "type": "bytes32" + }, + { + "indexed": false, + "internalType": "address", + "name": "originalTokenAddress", + "type": "address" + }, + { + "indexed": false, + "internalType": "address", + "name": "sender", + "type": "address" + }, + { + "indexed": false, + "internalType": "address", + "name": "receiver", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "bytes32", + "name": "blockHash", + "type": "bytes32" + }, + { + "indexed": false, + "internalType": "uint32", + "name": "logIndex", + "type": "uint32" + } + ], + "name": "Executed", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "sender", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "fedRskBlock", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "fedEthBlock", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "string", + "name": "federatorVersion", + "type": "string" + }, + { + "indexed": false, + "internalType": "string", + "name": "nodeRskInfo", + "type": "string" + }, + { + "indexed": false, + "internalType": "string", + "name": "nodeEthInfo", + "type": "string" + } + ], + "name": "HeartBeat", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "member", + "type": "address" + } + ], + "name": "MemberAddition", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "member", + "type": "address" + } + ], + "name": "MemberRemoval", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "previousOwner", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "newOwner", + "type": "address" + } + ], + "name": "OwnershipTransferred", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint256", + "name": "required", + "type": "uint256" + } + ], + "name": "RequirementChange", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "federator", + "type": "address" + }, + { + "indexed": true, + "internalType": "bytes32", + "name": "transactionHash", + "type": "bytes32" + }, + { + "indexed": true, + "internalType": "bytes32", + "name": "transactionId", + "type": "bytes32" + }, + { + "indexed": false, + "internalType": "address", + "name": "originalTokenAddress", + "type": "address" + }, + { + "indexed": false, + "internalType": "address", + "name": "sender", + "type": "address" + }, + { + "indexed": false, + "internalType": "address", + "name": "receiver", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "bytes32", + "name": "blockHash", + "type": "bytes32" + }, + { + "indexed": false, + "internalType": "uint32", + "name": "logIndex", + "type": "uint32" + } + ], + "name": "Voted", + "type": "event" + }, + { + "inputs": [], + "name": "MAX_MEMBER_COUNT", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_newMember", + "type": "address" + } + ], + "name": "addMember", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "bridge", + "outputs": [ + { + "internalType": "contract IBridgeV3", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_required", + "type": "uint256" + } + ], + "name": "changeRequirement", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "fedRskBlock", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "fedEthBlock", + "type": "uint256" + }, + { + "internalType": "string", + "name": "federatorVersion", + "type": "string" + }, + { + "internalType": "string", + "name": "nodeRskInfo", + "type": "string" + }, + { + "internalType": "string", + "name": "nodeEthInfo", + "type": "string" + } + ], + "name": "emitHeartbeat", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "getMembers", + "outputs": [ + { + "internalType": "address[]", + "name": "", + "type": "address[]" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "transactionId", + "type": "bytes32" + } + ], + "name": "getTransactionCount", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "originalTokenAddress", + "type": "address" + }, + { + "internalType": "address", + "name": "sender", + "type": "address" + }, + { + "internalType": "address", + "name": "receiver", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "blockHash", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "transactionHash", + "type": "bytes32" + }, + { + "internalType": "uint32", + "name": "logIndex", + "type": "uint32" + } + ], + "name": "getTransactionId", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "transactionId", + "type": "bytes32" + } + ], + "name": "hasVoted", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address[]", + "name": "_members", + "type": "address[]" + }, + { + "internalType": "uint256", + "name": "_required", + "type": "uint256" + }, + { + "internalType": "address", + "name": "_bridge", + "type": "address" + }, + { + "internalType": "address", + "name": "owner", + "type": "address" + } + ], + "name": "initialize", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "sender", + "type": "address" + } + ], + "name": "initialize", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "name": "isMember", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "isOwner", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "name": "members", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "owner", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "name": "processed", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_oldMember", + "type": "address" + } + ], + "name": "removeMember", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "renounceOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "required", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "_bridge", + "type": "address" + } + ], + "name": "setBridge", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "transactionId", + "type": "bytes32" + } + ], + "name": "transactionWasProcessed", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "newOwner", + "type": "address" + } + ], + "name": "transferOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "version", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "originalTokenAddress", + "type": "address" + }, + { + "internalType": "address payable", + "name": "sender", + "type": "address" + }, + { + "internalType": "address payable", + "name": "receiver", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + }, + { + "internalType": "bytes32", + "name": "blockHash", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "transactionHash", + "type": "bytes32" + }, + { + "internalType": "uint32", + "name": "logIndex", + "type": "uint32" + } + ], + "name": "voteTransaction", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + }, + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "name": "votes", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "view", + "type": "function" + } +] diff --git a/bridge/contracts/Federation/FederationV3.sol b/bridge/contracts/Federation/FederationV3.sol new file mode 100644 index 000000000..e2aa85961 --- /dev/null +++ b/bridge/contracts/Federation/FederationV3.sol @@ -0,0 +1,263 @@ +// SPDX-License-Identifier: MIT + +pragma solidity ^0.8.0; + +// Upgradables +import "../zeppelin/upgradable/Initializable.sol"; +import "../zeppelin/upgradable/ownership/UpgradableOwnable.sol"; + +import "../Bridge/IBridgeV3.sol"; + +contract FederationV3 is Initializable, UpgradableOwnable { + uint constant public MAX_MEMBER_COUNT = 50; + address constant private NULL_ADDRESS = address(0); + + IBridgeV3 public bridge; + address[] public members; + uint public required; + + mapping (address => bool) public isMember; + mapping (bytes32 => mapping (address => bool)) public votes; + mapping(bytes32 => bool) public processed; + + event Executed( + address indexed federator, + bytes32 indexed transactionHash, + bytes32 indexed transactionId, + address originalTokenAddress, + address sender, + address receiver, + uint256 amount, + bytes32 blockHash, + uint32 logIndex + ); + event MemberAddition(address indexed member); + event MemberRemoval(address indexed member); + event RequirementChange(uint required); + event BridgeChanged(address bridge); + event Voted( + address indexed federator, + bytes32 indexed transactionHash, + bytes32 indexed transactionId, + address originalTokenAddress, + address sender, + address receiver, + uint256 amount, + bytes32 blockHash, + uint32 logIndex + ); + event HeartBeat( + address indexed sender, + uint256 fedRskBlock, + uint256 fedEthBlock, + string federatorVersion, + string nodeRskInfo, + string nodeEthInfo + ); + + modifier onlyMember() { + require(isMember[_msgSender()], "Federation: Not Federator"); + _; + } + + modifier validRequirement(uint membersCount, uint _required) { + // solium-disable-next-line max-len + require(_required <= membersCount && _required != 0 && membersCount != 0, "Federation: Invalid requirements"); + _; + } + + function initialize(address[] memory _members, uint _required, address _bridge, address owner) + validRequirement(_members.length, _required) public initializer { + UpgradableOwnable.initialize(owner); + require(_members.length <= MAX_MEMBER_COUNT, "Federation: Too many members"); + members = _members; + for (uint i = 0; i < _members.length; i++) { + require(!isMember[_members[i]] && _members[i] != NULL_ADDRESS, "Federation: Invalid members"); + isMember[_members[i]] = true; + emit MemberAddition(_members[i]); + } + required = _required; + emit RequirementChange(required); + _setBridge(_bridge); + } + + function version() external pure returns (string memory) { + return "v3"; + } + + function setBridge(address _bridge) external onlyOwner { + _setBridge(_bridge); + } + + function _setBridge(address _bridge) internal { + require(_bridge != NULL_ADDRESS, "Federation: Empty bridge"); + bridge = IBridgeV3(_bridge); + emit BridgeChanged(_bridge); + } + + function voteTransaction( + address originalTokenAddress, + address payable sender, + address payable receiver, + uint256 amount, + bytes32 blockHash, + bytes32 transactionHash, + uint32 logIndex + ) + public onlyMember returns(bool) + { + bytes32 transactionId = getTransactionId( + originalTokenAddress, + sender, + receiver, + amount, + blockHash, + transactionHash, + logIndex + ); + + require(votes[transactionId][_msgSender()] == false, "Federation: Federator already vote for this transaction"); + require(processed[transactionId] == false, "Federation: Transaction already processed"); + + votes[transactionId][_msgSender()] = true; + emit Voted( + _msgSender(), + transactionHash, + transactionId, + originalTokenAddress, + sender, + receiver, + amount, + blockHash, + logIndex + ); + + uint transactionCount = getTransactionCount(transactionId); + if (transactionCount >= required && transactionCount >= members.length / 2 + 1) { + processed[transactionId] = true; + bridge.acceptTransfer( + originalTokenAddress, + sender, + receiver, + amount, + blockHash, + transactionHash, + logIndex + ); + emit Executed( + _msgSender(), + transactionHash, + transactionId, + originalTokenAddress, + sender, + receiver, + amount, + blockHash, + logIndex + ); + return true; + } + + return true; + } + + function getTransactionCount(bytes32 transactionId) public view returns(uint) { + uint count = 0; + for (uint i = 0; i < members.length; i++) { + if (votes[transactionId][members[i]]) + count += 1; + } + return count; + } + + function hasVoted(bytes32 transactionId) external view returns(bool) + { + return votes[transactionId][_msgSender()]; + } + + function transactionWasProcessed(bytes32 transactionId) external view returns(bool) + { + return processed[transactionId]; + } + + function getTransactionId( + address originalTokenAddress, + address sender, + address receiver, + uint256 amount, + bytes32 blockHash, + bytes32 transactionHash, + uint32 logIndex + ) public pure returns(bytes32) + { + return keccak256( + abi.encodePacked( + originalTokenAddress, + sender, + receiver, + amount, + blockHash, + transactionHash, + logIndex + ) + ); + } + + function addMember(address _newMember) external onlyOwner + { + require(_newMember != NULL_ADDRESS, "Federation: Empty member"); + require(!isMember[_newMember], "Federation: Member already exists"); + require(members.length < MAX_MEMBER_COUNT, "Federation: Max members reached"); + + isMember[_newMember] = true; + members.push(_newMember); + emit MemberAddition(_newMember); + } + + function removeMember(address _oldMember) external onlyOwner + { + require(_oldMember != NULL_ADDRESS, "Federation: Empty member"); + require(isMember[_oldMember], "Federation: Member doesn't exists"); + require(members.length > 1, "Federation: Can't remove all the members"); + require(members.length - 1 >= required, "Federation: Can't have less than required members"); + + isMember[_oldMember] = false; + for (uint i = 0; i < members.length - 1; i++) { + if (members[i] == _oldMember) { + members[i] = members[members.length - 1]; + break; + } + } + members.pop(); // remove an element from the end of the array. + emit MemberRemoval(_oldMember); + } + + function getMembers() external view returns (address[] memory) + { + return members; + } + + function changeRequirement(uint _required) external onlyOwner validRequirement(members.length, _required) + { + require(_required >= 2, "Federation: Requires at least 2"); + required = _required; + emit RequirementChange(_required); + } + + function emitHeartbeat( + uint256 fedRskBlock, + uint256 fedEthBlock, + string calldata federatorVersion, + string calldata nodeRskInfo, + string calldata nodeEthInfo + ) external onlyMember { + emit HeartBeat( + _msgSender(), + fedRskBlock, + fedEthBlock, + federatorVersion, + nodeRskInfo, + nodeEthInfo + ); + } +} \ No newline at end of file diff --git a/bridge/deploy/06_deploy_federation.js b/bridge/deploy/06_deploy_federation.js index f18d50db5..1c87217a7 100644 --- a/bridge/deploy/06_deploy_federation.js +++ b/bridge/deploy/06_deploy_federation.js @@ -9,7 +9,7 @@ module.exports = async function(hre) { // HardhatRuntimeEnvironment const federationProxyAddress = await address.getFederationProxyAddress(hre); if (federationProxyAddress) { - const Federation = await deployments.getArtifact('FederationV2'); + const Federation = await deployments.getArtifact('FederationV3'); const federation = new web3.eth.Contract(Federation.abi, federationProxyAddress); const currentFederationVersion = federation.methods.version().call(); if (currentFederationVersion === FEDERATION_LAST_VERSION) { @@ -17,7 +17,7 @@ module.exports = async function(hre) { // HardhatRuntimeEnvironment } } - const deployResult = await deploy('FederationV2', { + const deployResult = await deploy('FederationV3', { from: deployer, log: true }); @@ -35,4 +35,4 @@ module.exports = async function(hre) { // HardhatRuntimeEnvironment } }; module.exports.id = 'deploy_federation'; // id required to prevent reexecution -module.exports.tags = ['FederationV2', 'Upgrade', 'DeployFromScratch', 'IntegrationTest']; +module.exports.tags = ['FederationV3', 'Upgrade', 'DeployFromScratch', 'IntegrationTest']; diff --git a/bridge/deploy/07_deploy_federationProxy.js b/bridge/deploy/07_deploy_federationProxy.js index a347e752d..a3ca08c6f 100644 --- a/bridge/deploy/07_deploy_federationProxy.js +++ b/bridge/deploy/07_deploy_federationProxy.js @@ -11,7 +11,7 @@ module.exports = async function(hre) { // HardhatRuntimeEnvironment return; } - const Federation = await deployments.get('FederationV2'); + const Federation = await deployments.get('FederationV3'); const proxyAdminAddress = await address.getProxyAdminAddress(hre); const multiSigAddress = await address.getMultiSigAddress(hre); const bridgeProxyAddress = await address.getBridgeProxyAddress(hre); @@ -54,11 +54,12 @@ module.exports = async function(hre) { // HardhatRuntimeEnvironment }; module.exports.id = 'deploy_federation_proxy'; // id required to prevent reexecution module.exports.tags = ['FederationProxy', 'DeployFromScratch', 'IntegrationTest']; -module.exports.dependencies = ['MultiSigWallet', 'ProxyAdmin', 'FederationV2', 'BridgeProxy']; +module.exports.dependencies = ['MultiSigWallet', 'ProxyAdmin', 'FederationV3', 'BridgeProxy']; function getFederationConf(deployer, network) { const networkName = network.name.toLowerCase(); - if (networkName.includes('testnet') || networkName.includes('kovan') || networkName.includes('rinkeby') ) { + if (networkName.includes('testnet') || networkName.includes('kovan') + || networkName.includes('rinkeby') || networkName.includes('sepolia') ) { return { members: ['0xD1B27867E42E3DE1A32217Ff773B32b48888fb3B'], required: 1, diff --git a/bridge/deploy/upgrades/02_upgrade_federation.js b/bridge/deploy/upgrades/02_upgrade_federation.js index 65b0d5cae..e4561a6eb 100644 --- a/bridge/deploy/upgrades/02_upgrade_federation.js +++ b/bridge/deploy/upgrades/02_upgrade_federation.js @@ -5,7 +5,7 @@ module.exports = async function (hre) { // HardhatRuntimeEnvironment const {deployer, federationProxy, proxyAdmin, multiSig} = await getNamedAccounts(); const {log} = deployments; - const federationDeployed = await deployments.get('FederationV2'); + const federationDeployed = await deployments.get('FederationV3'); const proxyAdminArtifact = await deployments.getArtifact('ProxyAdmin'); const multiSigWalletDeployment = await deployments.getArtifact('MultiSigWallet'); @@ -23,4 +23,4 @@ module.exports = async function (hre) { // HardhatRuntimeEnvironment }; module.exports.id = 'upgrade_federation'; // id required to prevent reexecution module.exports.tags = ['UpgradeFederation', 'Upgrade']; -module.exports.dependencies = ['FederationV2']; +module.exports.dependencies = ['FederationV3']; diff --git a/bridge/deployed/deployHelper.js b/bridge/deployed/deployHelper.js index 90d40a9ab..9491d3bf8 100644 --- a/bridge/deployed/deployHelper.js +++ b/bridge/deployed/deployHelper.js @@ -7,6 +7,7 @@ function isMainnet(network) { function isLocalNetwork(network) { return !network.toLowerCase().includes('mainnet') && !network.toLowerCase().includes('kovan') + && !network.toLowerCase().includes('sepolia') && !network.toLowerCase().includes('testnet'); } diff --git a/bridge/package.json b/bridge/package.json index f5e815e49..6663b86aa 100644 --- a/bridge/package.json +++ b/bridge/package.json @@ -10,7 +10,7 @@ "start": "npm run lint && npm run migrate && npm run test", "lint": "npx solhint \"contracts/**/*.sol\"", "compile": "npx hardhat compile --show-stack-traces", - "test": "npx hardhat test --show-stack-traces", + "test": "npm run compile && npx hardhat test --show-stack-traces", "coverage": "npx hardhat coverage", "size": "npx hardhat size-contracts", "flatten": "npx waffle flatten", diff --git a/bridge/test/AllowTokens_test.js b/bridge/test/AllowTokens_test.js index 0991914f2..972116058 100644 --- a/bridge/test/AllowTokens_test.js +++ b/bridge/test/AllowTokens_test.js @@ -101,7 +101,7 @@ contract('AllowTokens', async function (accounts) { await truffleAssertions.fails( this.allowTokens.setToken(this.token.address, 0, { from: unauthorizedAccount }), truffleAssertions.ErrorType.REVERT, - 'AllowTokensV1.sol: unauthorized sender' + 'AllowTokens: unauthorized sender' ); }); @@ -110,7 +110,7 @@ contract('AllowTokens', async function (accounts) { await truffleAssertions.fails( this.allowTokens.setToken(this.token.address, currentTypeDescriptionLength + 1, { from: manager }), truffleAssertions.ErrorType.REVERT, - 'AllowTokensV1.sol: typeId does not exist' + 'AllowTokens: typeId does not exist' ); }); }); diff --git a/bridge/test/BridgeV3_to_bridgeV4_test.js b/bridge/test/BridgeV3_to_bridgeV4_test.js index 4da7e506c..a7efec09e 100644 --- a/bridge/test/BridgeV3_to_bridgeV4_test.js +++ b/bridge/test/BridgeV3_to_bridgeV4_test.js @@ -3,11 +3,11 @@ const BridgeV4 = artifacts.require('BridgeV3'); const BridgeV3 = artifacts.require('BridgeV3'); const ProxyAdmin = artifacts.require('ProxyAdmin'); const SideTokenFactory = artifacts.require('SideTokenFactory'); -const FederationV3 = artifacts.require('FederationV2'); +const FederationV3 = artifacts.require('FederationV3'); const FederationV2 = artifacts.require('FederationV2'); const BridgeProxy = artifacts.require('BridgeProxy'); const FederationProxy = artifacts.require('FederationProxy'); -const AllowTokens = artifacts.require('AllowTokens'); +const AllowTokens = artifacts.require('AllowTokensV1'); const utils = require("./utils"); const chains = require('../hardhat/helper/chains'); const MainToken = artifacts.require('./MainToken'); @@ -75,7 +75,7 @@ contract('Bridge Multichain Deploy Check', async function (accounts) { const bridgeV4Implementation = new web3.eth.Contract(this.bridgeV4.abi, bridgeProxy.address); result = await bridgeV4Implementation.methods.version().call(); - assert.equal(result, 'v4'); + assert.equal(result, 'v3'); }); it('should ReceiveTokensTo start in v3 finish in v4', async function () { @@ -149,9 +149,7 @@ contract('Bridge Multichain Deploy Check', async function (accounts) { amount, crossEvent.blockHash, crossEvent.transactionHash, - crossEvent.logIndex, - chains.ETHEREUM_MAIN_NET_CHAIN_ID, - chains.HARDHAT_TEST_NET_CHAIN_ID, + crossEvent.logIndex ).send({from: federatorMember2}); await bridgeV4Implementation.methods.claim( diff --git a/bridge/test/Bridge_upgrade_test.js b/bridge/test/Bridge_upgrade_test.js index 1045efab4..6ea89fd18 100644 --- a/bridge/test/Bridge_upgrade_test.js +++ b/bridge/test/Bridge_upgrade_test.js @@ -140,7 +140,7 @@ contract('Bridge upgrade test', async (accounts) => { const newProxy = new web3.eth.Contract(BridgeV4.abi, this.proxyBridge.options.address); result = await newProxy.methods.version().call(); - assert.equal(result, 'v4'); + assert.equal(result, 'v3'); result = await newProxy.methods.owner().call(); assert.equal(result, managerAddress); @@ -226,7 +226,7 @@ contract('Bridge upgrade test', async (accounts) => { this.sideTokenFactory = await SideTokenFactory.new(); await this.sideTokenFactory.transferPrimary(this.proxyBridge.options.address); const result = await this.proxyBridge.methods.version().call(); - assert.equal(result, 'v4'); + assert.equal(result, 'v3'); }); it('should have new method changeSideTokenFactory', async () => { @@ -256,15 +256,14 @@ contract('Bridge upgrade test', async (accounts) => { await this.token.transfer(anAccount, amount, { from: deployerAddress }); await this.token.approve(this.proxyBridge.options.address, amount, { from: anAccount }); - const tx = await this.proxyBridge.methods.receiveTokensTo(chains.ETHEREUM_MAIN_NET_CHAIN_ID, + const tx = await this.proxyBridge.methods.receiveTokensTo( this.token.address, anAccount, amount).send({ from: anAccount, gas: 200_000}); assert.equal(Number(tx.status), 1, "Should be a succesful Tx"); assert.equal(tx.events.Cross.event, 'Cross'); const balance = await this.token.balanceOf(this.proxyBridge.options.address); assert.equal(balance, amount); - const isKnownToken = await this.proxyBridge.methods.knownToken( - chains.ETHEREUM_MAIN_NET_CHAIN_ID, + const isKnownToken = await this.proxyBridge.methods.knownTokens( this.token.address ).call(); assert.equal(isKnownToken, true); @@ -277,19 +276,14 @@ contract('Bridge upgrade test', async (accounts) => { 18, 'rMAIN', 'MAIN on RSK', - chains.ETHEREUM_MAIN_NET_CHAIN_ID, ).send({from: managerAddress, gas: 4_000_000}); - const sideTokenAddress = await this.proxyBridge.methods.sideTokenByOriginalToken( - chains.ETHEREUM_MAIN_NET_CHAIN_ID, + const sideTokenAddress = await this.proxyBridge.methods.mappedTokens( this.token.address ).call(); let sideToken = await SideToken.at(sideTokenAddress); const sideTokenSymbol = await sideToken.symbol(); - assert.equal(sideTokenSymbol, "rMAIN"); - - const originalToken = await this.proxyBridge.methods.getOriginalTokenBySideToken(sideTokenAddress).call(); - assert.equal(originalToken.tokenAddress, this.token.address); + assert.equal(sideTokenSymbol, "rrMAIN"); const blockHash = utils.getRandomHash(); const txHash = utils.getRandomHash(); @@ -301,9 +295,7 @@ contract('Bridge upgrade test', async (accounts) => { this.amount, blockHash, txHash, - logIndex, - chains.ETHEREUM_MAIN_NET_CHAIN_ID, - chains.HARDHAT_TEST_NET_CHAIN_ID + logIndex ).send({ from: federationAddress, gas: 200_000}); assert.equal(Number(tx.status), 1, "Should be a succesful Tx"); diff --git a/bridge/test/Federation_test.js b/bridge/test/Federation_test.js index 153f566b9..1970beb2a 100644 --- a/bridge/test/Federation_test.js +++ b/bridge/test/Federation_test.js @@ -1,6 +1,6 @@ -const Federation = artifacts.require('FederationV2'); +const Federation = artifacts.require('FederationV3'); const AllowTokens = artifacts.require('./AllowTokensV1.sol'); -const Bridge = artifacts.require('./Bridge'); +const Bridge = artifacts.require('./BridgeV3'); const SideTokenFactory = artifacts.require('./SideTokenFactory'); const truffleAssertions = require('truffle-assertions'); @@ -9,7 +9,7 @@ const chains = require('../hardhat/helper/chains'); const BN = web3.utils.BN; const toWei = web3.utils.toWei; -contract('FederationV2', async function (accounts) { +contract('FederationV3', async function (accounts) { const deployer = accounts[0]; const anAccount = accounts[1]; const federator1 = accounts[2]; @@ -332,7 +332,7 @@ contract('FederationV2', async function (accounts) { const fedRskChainId = '30'; const fedEthChainId = '1'; const fedBscChainId = '56'; - const federatorVersion = '3.0.0'; + const federatorVersion = '2.0.0'; const nodeRskInfo = 'rskjar/2.2.0'; const nodeEthInfo = 'geth/1.13.15'; const nodeBscInfo = 'geth/1.1.5'; @@ -342,76 +342,38 @@ contract('FederationV2', async function (accounts) { it('should be succesful', async function() { const receipt = await this.federators.emitHeartbeat( + fedRskBlock, + fedEthBlock, federatorVersion, - [ fedRskChainId, fedEthChainId, fedBscChainId ], - [ fedRskBlock, fedEthBlock, fedBscBlock ], - [ nodeRskInfo, nodeEthInfo, nodeBscInfo ], + nodeRskInfo, + nodeEthInfo, {from: federator1} ); utils.checkRcpt(receipt); assert.equal(receipt.logs[0].event, 'HeartBeat'); assert.equal(receipt.logs[0].args[0], federator1); - assert.equal(receipt.logs[0].args[1], await web3.eth.net.getId() ); - assert.equal(receipt.logs[0].args[2], await web3.eth.getBlockNumber()); + assert.equal(receipt.logs[0].args[1], fedRskBlock ); + assert.equal(receipt.logs[0].args[2], fedEthBlock); assert.equal(receipt.logs[0].args[3], federatorVersion); - assert.deepEqual(arrayMembersToString(receipt.logs[0].args[4]), - [ fedRskChainId, fedEthChainId, fedBscChainId ] - ); - assert.deepEqual(arrayMembersToString(receipt.logs[0].args[5]), [ fedRskBlock, fedEthBlock, fedBscBlock ]); - assert.deepEqual(arrayMembersToString(receipt.logs[0].args[6]), [ nodeRskInfo, nodeEthInfo, nodeBscInfo ]); + assert.equal(receipt.logs[0].args[4], nodeRskInfo); + assert.equal(receipt.logs[0].args[5], nodeEthInfo); }); it('should fail if not a memeber', async function() { await truffleAssertions.fails( this.federators.emitHeartbeat( + fedRskBlock, + fedEthBlock, federatorVersion, - [ fedRskChainId, fedEthChainId, fedBscChainId ], - [ fedRskBlock, fedEthBlock, fedBscBlock ], - [ nodeRskInfo, nodeEthInfo, nodeBscInfo ], + nodeRskInfo, + nodeEthInfo, {from: anAccount} ), truffleAssertions.ErrorType.REVERT ); }); - - it('should fail if different array size', async function() { - await truffleAssertions.fails( - this.federators.emitHeartbeat( - federatorVersion, - [ fedRskChainId, fedEthChainId, fedBscChainId ], - [ fedRskBlock, fedEthBlock, fedBscBlock ], - [ nodeRskInfo, nodeEthInfo ], - {from: anAccount} - ), - truffleAssertions.ErrorType.REVERT - ); - - await truffleAssertions.fails( - this.federators.emitHeartbeat( - federatorVersion, - [ fedRskChainId, fedEthChainId ], - [ fedRskBlock, fedEthBlock, fedBscBlock ], - [ nodeRskInfo, nodeEthInfo, nodeBscInfo ], - {from: anAccount} - ), - truffleAssertions.ErrorType.REVERT - ); - - await truffleAssertions.fails( - this.federators.emitHeartbeat( - federatorVersion, - [ fedRskChainId, fedEthChainId, fedBscChainId ], - [ fedRskBlock, fedEthBlock ], - [ nodeRskInfo, nodeEthInfo, nodeBscInfo ], - {from: anAccount} - ), - truffleAssertions.ErrorType.REVERT - ); - }); - }); - }); describe('Transactions', async function() { @@ -446,8 +408,14 @@ contract('FederationV2', async function (accounts) { await this.allowTokens.setToken(originalTokenAddress, typeId); this.sideTokenFactory = await SideTokenFactory.new(); this.bridge = await Bridge.new(); - await this.bridge.methods['initialize(address,address,address,address)'](deployer, this.federators.address, - this.allowTokens.address, this.sideTokenFactory.address); + await this.bridge.methods['initialize(address,address,address,address,string)'] + ( + deployer, + this.federators.address, + this.allowTokens.address, + this.sideTokenFactory.address, + 'bd' + ); await this.sideTokenFactory.transferPrimary(this.bridge.address); await this.allowTokens.transferPrimary(this.bridge.address); await this.federators.setBridge(this.bridge.address); @@ -457,9 +425,7 @@ contract('FederationV2', async function (accounts) { originalTokenAddress, decimals, 'MAIN', - 'MAIN', - chains.HARDHAT_TEST_NET_CHAIN_ID - ); + 'MAIN'); }); it('voteTransaction should be successful with 1/1 federators require 1', async function() { @@ -471,9 +437,7 @@ contract('FederationV2', async function (accounts) { amount, blockHash, transactionHash, - logIndex, - chains.HARDHAT_TEST_NET_CHAIN_ID, - chains.HARDHAT_TEST_NET_CHAIN_ID, + logIndex ); let transactionCount = await this.federators.getTransactionCount(transactionId); assert.equal(transactionCount, 0); @@ -489,8 +453,6 @@ contract('FederationV2', async function (accounts) { blockHash, transactionHash, logIndex, - chains.HARDHAT_TEST_NET_CHAIN_ID, - chains.HARDHAT_TEST_NET_CHAIN_ID, {from: federator1} ); utils.checkRcpt(receipt); @@ -512,9 +474,7 @@ contract('FederationV2', async function (accounts) { amount, blockHash, transactionHash, - logIndex, - chains.HARDHAT_TEST_NET_CHAIN_ID, - chains.HARDHAT_TEST_NET_CHAIN_ID, + logIndex ); let bridgeTransactionDataWasProcessed = await this.bridge.transactionsDataHashes(transactionHash); assert.equal(transactionDataHash, bridgeTransactionDataWasProcessed); @@ -538,9 +498,7 @@ contract('FederationV2', async function (accounts) { amount, blockHash, transactionHash, - logIndex, - chains.HARDHAT_TEST_NET_CHAIN_ID, - chains.HARDHAT_TEST_NET_CHAIN_ID + logIndex ); let transactionCount = await this.federators.getTransactionCount(transactionId); assert.equal(transactionCount, 0); @@ -557,8 +515,6 @@ contract('FederationV2', async function (accounts) { blockHash, transactionHash, logIndex, - chains.HARDHAT_TEST_NET_CHAIN_ID, - chains.HARDHAT_TEST_NET_CHAIN_ID, {from: federator1} ), truffleAssertions.ErrorType.REVERT @@ -578,9 +534,7 @@ contract('FederationV2', async function (accounts) { amount, blockHash, transactionHash, - logIndex, - chains.HARDHAT_TEST_NET_CHAIN_ID, - chains.HARDHAT_TEST_NET_CHAIN_ID + logIndex ); transactionWasProcessed = await this.bridge.hasCrossed(bridgeTransactionId); assert.equal(transactionWasProcessed, false); @@ -595,9 +549,7 @@ contract('FederationV2', async function (accounts) { amount, blockHash, transactionHash, - logIndex, - chains.HARDHAT_TEST_NET_CHAIN_ID, - chains.HARDHAT_TEST_NET_CHAIN_ID, + logIndex ); let transactionCount = await this.federators.getTransactionCount(transactionId); assert.equal(transactionCount, 0); @@ -615,8 +567,6 @@ contract('FederationV2', async function (accounts) { blockHash, transactionHash, logIndex, - chains.HARDHAT_TEST_NET_CHAIN_ID, - chains.HARDHAT_TEST_NET_CHAIN_ID, {from: federator1} ); utils.checkRcpt(receipt); @@ -651,9 +601,7 @@ contract('FederationV2', async function (accounts) { amount, blockHash, transactionHash, - logIndex, - chains.HARDHAT_TEST_NET_CHAIN_ID, - chains.HARDHAT_TEST_NET_CHAIN_ID, + logIndex ); let transactionCount = await this.federators.getTransactionCount(transactionId); assert.equal(transactionCount, 0); @@ -671,8 +619,6 @@ contract('FederationV2', async function (accounts) { blockHash, transactionHash, logIndex, - chains.HARDHAT_TEST_NET_CHAIN_ID, - chains.HARDHAT_TEST_NET_CHAIN_ID, {from: federator1} ); utils.checkRcpt(receipt); @@ -682,19 +628,19 @@ contract('FederationV2', async function (accounts) { hasVotedFederator2 = await this.federators.hasVoted(transactionId, {from: federator2}); assert.equal(hasVotedFederator2, false); - const secondReceipt = await this.federators.voteTransaction( - originalTokenAddress, - anAccount, - anAccount, - amount, - blockHash, - transactionHash, - logIndex, - chains.HARDHAT_TEST_NET_CHAIN_ID, - chains.HARDHAT_TEST_NET_CHAIN_ID, - {from: federator1} + await truffleAssertions.fails( + this.federators.voteTransaction( + originalTokenAddress, + anAccount, + anAccount, + amount, + blockHash, + transactionHash, + logIndex, + {from: federator1} + ), + truffleAssertions.ErrorType.REVERT ); - utils.checkRcpt(secondReceipt); hasVotedFederator1 = await this.federators.hasVoted(transactionId, {from: federator1}); assert.equal(hasVotedFederator1, true); @@ -725,9 +671,7 @@ contract('FederationV2', async function (accounts) { amount, blockHash, transactionHash, - logIndex, - chains.HARDHAT_TEST_NET_CHAIN_ID, - chains.HARDHAT_TEST_NET_CHAIN_ID + logIndex ); let transactionCount = await this.federators.getTransactionCount(transactionId); assert.equal(transactionCount, 0); @@ -745,8 +689,6 @@ contract('FederationV2', async function (accounts) { blockHash, transactionHash, logIndex, - chains.HARDHAT_TEST_NET_CHAIN_ID, - chains.HARDHAT_TEST_NET_CHAIN_ID, {from: federator1} ); utils.checkRcpt(receipt); @@ -770,8 +712,6 @@ contract('FederationV2', async function (accounts) { blockHash, transactionHash, logIndex, - chains.HARDHAT_TEST_NET_CHAIN_ID, - chains.HARDHAT_TEST_NET_CHAIN_ID, {from: federator2} ); utils.checkRcpt(receipt); @@ -792,9 +732,7 @@ contract('FederationV2', async function (accounts) { amount, blockHash, transactionHash, - logIndex, - chains.HARDHAT_TEST_NET_CHAIN_ID, - chains.HARDHAT_TEST_NET_CHAIN_ID + logIndex ); const bridgeTransactionHash = await this.bridge.transactionsDataHashes(transactionHash); assert.equal(bridgeTransactionHash, expectedHash); @@ -812,9 +750,7 @@ contract('FederationV2', async function (accounts) { amount, blockHash, transactionHash, - logIndex, - chains.HARDHAT_TEST_NET_CHAIN_ID, - chains.HARDHAT_TEST_NET_CHAIN_ID + logIndex ); let transactionCount = await this.federators.getTransactionCount(transactionId); assert.equal(transactionCount, 0); @@ -832,8 +768,6 @@ contract('FederationV2', async function (accounts) { blockHash, transactionHash, logIndex, - chains.HARDHAT_TEST_NET_CHAIN_ID, - chains.HARDHAT_TEST_NET_CHAIN_ID, {from: federator1} ); utils.checkRcpt(receipt); @@ -857,8 +791,6 @@ contract('FederationV2', async function (accounts) { blockHash, transactionHash, logIndex, - chains.HARDHAT_TEST_NET_CHAIN_ID, - chains.HARDHAT_TEST_NET_CHAIN_ID, {from: federator2} ); utils.checkRcpt(receipt); @@ -880,8 +812,6 @@ contract('FederationV2', async function (accounts) { blockHash, transactionHash, logIndex, - chains.HARDHAT_TEST_NET_CHAIN_ID, - chains.HARDHAT_TEST_NET_CHAIN_ID, ); const bridgeTransactionHash = await this.bridge.transactionsDataHashes(transactionHash); assert.equal(bridgeTransactionHash, expectedHash); @@ -900,9 +830,7 @@ contract('FederationV2', async function (accounts) { amount, blockHash, transactionHash, - logIndex, - chains.HARDHAT_TEST_NET_CHAIN_ID, - chains.HARDHAT_TEST_NET_CHAIN_ID, + logIndex ); let hasVotedFederator1 = await this.federators.hasVoted(transactionId, {from: federator1}); @@ -920,8 +848,6 @@ contract('FederationV2', async function (accounts) { blockHash, transactionHash, logIndex, - chains.HARDHAT_TEST_NET_CHAIN_ID, - chains.HARDHAT_TEST_NET_CHAIN_ID, {from: federator1} ); @@ -943,8 +869,6 @@ contract('FederationV2', async function (accounts) { blockHash, transactionHash, logIndex, - chains.HARDHAT_TEST_NET_CHAIN_ID, - chains.HARDHAT_TEST_NET_CHAIN_ID, {from: federator2} ); @@ -970,8 +894,6 @@ contract('FederationV2', async function (accounts) { blockHash, transactionHash, logIndex, - chains.HARDHAT_TEST_NET_CHAIN_ID, - chains.HARDHAT_TEST_NET_CHAIN_ID, ); const bridgeTransactionHash = await this.bridge.transactionsDataHashes(transactionHash); assert.equal(bridgeTransactionHash, expectedHash); @@ -992,8 +914,6 @@ contract('FederationV2', async function (accounts) { blockHash, transactionHash, logIndex, - chains.HARDHAT_TEST_NET_CHAIN_ID, - chains.HARDHAT_TEST_NET_CHAIN_ID, ); let hasVotedFederator1 = await this.federators.hasVoted(transactionId, {from: federator1}); @@ -1011,8 +931,6 @@ contract('FederationV2', async function (accounts) { blockHash, transactionHash, logIndex, - chains.HARDHAT_TEST_NET_CHAIN_ID, - chains.HARDHAT_TEST_NET_CHAIN_ID, {from: federator1} ); @@ -1034,8 +952,6 @@ contract('FederationV2', async function (accounts) { blockHash, transactionHash, logIndex, - chains.HARDHAT_TEST_NET_CHAIN_ID, - chains.HARDHAT_TEST_NET_CHAIN_ID, {from: federator2} ); @@ -1058,8 +974,6 @@ contract('FederationV2', async function (accounts) { blockHash, transactionHash, logIndex, - chains.HARDHAT_TEST_NET_CHAIN_ID, - chains.HARDHAT_TEST_NET_CHAIN_ID, ); const bridgeTransactionHash = await this.bridge.transactionsDataHashes(transactionHash); assert.equal(bridgeTransactionHash, expectedHash); @@ -1079,8 +993,6 @@ contract('FederationV2', async function (accounts) { blockHash, transactionHash, logIndex, - chains.HARDHAT_TEST_NET_CHAIN_ID, - chains.HARDHAT_TEST_NET_CHAIN_ID, ); let hasVotedFederator1 = await this.federators.hasVoted(transactionId, {from: federator1}); @@ -1098,8 +1010,6 @@ contract('FederationV2', async function (accounts) { blockHash, transactionHash, logIndex, - chains.HARDHAT_TEST_NET_CHAIN_ID, - chains.HARDHAT_TEST_NET_CHAIN_ID, {from: federator1} ); @@ -1121,8 +1031,6 @@ contract('FederationV2', async function (accounts) { blockHash, transactionHash, logIndex, - chains.HARDHAT_TEST_NET_CHAIN_ID, - chains.HARDHAT_TEST_NET_CHAIN_ID, {from: federator2} ); @@ -1144,9 +1052,7 @@ contract('FederationV2', async function (accounts) { amount, blockHash, transactionHash, - logIndex, - chains.HARDHAT_TEST_NET_CHAIN_ID, - chains.HARDHAT_TEST_NET_CHAIN_ID, + logIndex ); const bridgeTransactionHash = await this.bridge.transactionsDataHashes(transactionHash); assert.equal(bridgeTransactionHash, expectedHash); @@ -1154,17 +1060,18 @@ contract('FederationV2', async function (accounts) { transactionWasProcessed = await this.bridge.hasCrossed(transactionHash); assert.equal(transactionWasProcessed, true); - receipt = await this.federators.voteTransaction( - originalTokenAddress, - anAccount, - anAccount, - amount, - blockHash, - transactionHash, - logIndex, - chains.HARDHAT_TEST_NET_CHAIN_ID, - chains.HARDHAT_TEST_NET_CHAIN_ID, - {from: federator3} + await truffleAssertions.fails( + this.federators.voteTransaction( + originalTokenAddress, + anAccount, + anAccount, + amount, + blockHash, + transactionHash, + logIndex, + {from: federator3} + ), + truffleAssertions.ErrorType.REVERT ); hasVotedFederator1 = await this.federators.hasVoted(transactionId, {from: federator1}); @@ -1190,8 +1097,6 @@ contract('FederationV2', async function (accounts) { blockHash, transactionHash, logIndex, - chains.HARDHAT_TEST_NET_CHAIN_ID, - chains.HARDHAT_TEST_NET_CHAIN_ID, ); let hasVotedFederator1 = await this.federators.hasVoted(transactionId, {from: federator1}); @@ -1209,8 +1114,6 @@ contract('FederationV2', async function (accounts) { blockHash, transactionHash, logIndex, - chains.HARDHAT_TEST_NET_CHAIN_ID, - chains.HARDHAT_TEST_NET_CHAIN_ID, {from: federator1} ); @@ -1232,8 +1135,6 @@ contract('FederationV2', async function (accounts) { blockHash, transactionHash, logIndex, - chains.HARDHAT_TEST_NET_CHAIN_ID, - chains.HARDHAT_TEST_NET_CHAIN_ID, {from: federator2} ); @@ -1264,8 +1165,6 @@ contract('FederationV2', async function (accounts) { blockHash, transactionHash, logIndex, - chains.HARDHAT_TEST_NET_CHAIN_ID, - chains.HARDHAT_TEST_NET_CHAIN_ID, {from: federator3} ); @@ -1287,9 +1186,7 @@ contract('FederationV2', async function (accounts) { amount, blockHash, transactionHash, - logIndex, - chains.HARDHAT_TEST_NET_CHAIN_ID, - chains.HARDHAT_TEST_NET_CHAIN_ID, + logIndex ); bridgeTransactionHash = await this.bridge.transactionsDataHashes(transactionHash); assert.equal(bridgeTransactionHash, expectedHash); @@ -1301,8 +1198,7 @@ contract('FederationV2', async function (accounts) { it('should fail if not federators member', async function() { await truffleAssertions.fails( this.federators.voteTransaction(originalTokenAddress, - anAccount, anAccount, amount, blockHash, transactionHash, logIndex, - chains.HARDHAT_TEST_NET_CHAIN_ID, chains.HARDHAT_TEST_NET_CHAIN_ID + anAccount, anAccount, amount, blockHash, transactionHash, logIndex ), truffleAssertions.ErrorType.REVERT ); @@ -1316,9 +1212,7 @@ contract('FederationV2', async function (accounts) { amount, blockHash, transactionHash, - logIndex, - chains.ETHEREUM_MAIN_NET_CHAIN_ID, - chains.HARDHAT_TEST_NET_CHAIN_ID, + logIndex ); const transactionCount = await this.federators.getTransactionCount(transactionId); assert.equal(transactionCount, 0); @@ -1334,8 +1228,6 @@ contract('FederationV2', async function (accounts) { blockHash, transactionHash, logIndex, - chains.ETHEREUM_MAIN_NET_CHAIN_ID, - chains.HARDHAT_TEST_NET_CHAIN_ID, {from: federator1} ); utils.checkRcpt(receipt); @@ -1343,19 +1235,20 @@ contract('FederationV2', async function (accounts) { hasVotedFederator1 = await this.federators.hasVoted(transactionId, {from: federator1}); assert.equal(hasVotedFederator1, true); - receipt = await this.federators.voteTransaction( - originalTokenAddress, - anAccount, - anAccount, - amount, - blockHash, - transactionHash, - logIndex, - chains.HARDHAT_TEST_NET_CHAIN_ID, - chains.HARDHAT_TEST_NET_CHAIN_ID, - {from: federator1} + await truffleAssertions.fails( + this.federators.voteTransaction( + originalTokenAddress, + anAccount, + anAccount, + amount, + blockHash, + transactionHash, + logIndex, + {from: federator1} + ), + truffleAssertions.ErrorType.REVERT ); - utils.checkRcpt(receipt); + hasVotedFederator1 = await this.federators.hasVoted(transactionId, {from: federator1}); assert.equal(hasVotedFederator1, true); }); From 5b0b90f5eabfee683697eeb378dcce178c13c96a Mon Sep 17 00:00:00 2001 From: Guilherme Soares Date: Tue, 23 Jan 2024 12:53:50 +0100 Subject: [PATCH 2/2] Removed return from vote method --- bridge/abi/FederationV3.json | 8 +------- bridge/contracts/Federation/FederationV3.sol | 5 +---- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/bridge/abi/FederationV3.json b/bridge/abi/FederationV3.json index c5914398f..0b064da78 100644 --- a/bridge/abi/FederationV3.json +++ b/bridge/abi/FederationV3.json @@ -674,13 +674,7 @@ } ], "name": "voteTransaction", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], + "outputs": [], "stateMutability": "nonpayable", "type": "function" }, diff --git a/bridge/contracts/Federation/FederationV3.sol b/bridge/contracts/Federation/FederationV3.sol index e2aa85961..608e0666b 100644 --- a/bridge/contracts/Federation/FederationV3.sol +++ b/bridge/contracts/Federation/FederationV3.sol @@ -104,7 +104,7 @@ contract FederationV3 is Initializable, UpgradableOwnable { bytes32 transactionHash, uint32 logIndex ) - public onlyMember returns(bool) + public onlyMember { bytes32 transactionId = getTransactionId( originalTokenAddress, @@ -155,10 +155,7 @@ contract FederationV3 is Initializable, UpgradableOwnable { blockHash, logIndex ); - return true; } - - return true; } function getTransactionCount(bytes32 transactionId) public view returns(uint) {