finish refactoring

This commit is contained in:
Roman Storm 2018-06-11 20:33:16 -07:00
parent 7d9065124f
commit 0da0ade2fd
9 changed files with 188 additions and 294 deletions

View File

@ -88,10 +88,6 @@ contract BasicBridge is EternalStorage, Validatable {
return dailyLimit() >= nextLimit && _amount <= maxPerTx() && _amount >= minPerTx();
}
function requiredSignatures() public view returns(uint256) {
return validatorContract().requiredSignatures();
}
function claimTokens(address _token, address _to) public onlyOwner {
require(_to != address(0));
if (_token == address(0)) {

View File

@ -23,11 +23,11 @@ contract BasicForeignBridge is EternalStorage, Validatable {
emit RelayedMessage(recipient, amount, txHash);
}
function onExecuteMessage(address _recipient, uint256 _amount) private returns(bool){
function onExecuteMessage(address, uint256) internal returns(bool){
// has to be defined
}
function setRelayedMessages(bytes32 _txHash, bool _status) private {
function setRelayedMessages(bytes32 _txHash, bool _status) internal {
boolStorage[keccak256(abi.encodePacked("relayedMessages", _txHash))] = _status;
}

View File

@ -0,0 +1,145 @@
pragma solidity 0.4.24;
import "../upgradeability/EternalStorage.sol";
import "../libraries/SafeMath.sol";
import "openzeppelin-solidity/contracts/token/ERC20/ERC20Basic.sol";
import "./Validatable.sol";
import "../libraries/Message.sol";
contract BasicHomeBridge is EternalStorage, Validatable {
using SafeMath for uint256;
event UserRequestForSignature(address recipient, uint256 value);
event AffirmationCompleted (address recipient, uint256 value, bytes32 transactionHash);
event SignedForUserRequest(address indexed signer, bytes32 messageHash);
event SignedForAffirmation(address indexed signer, bytes32 transactionHash);
event CollectedSignatures(address authorityResponsibleForRelay, bytes32 messageHash, uint256 NumberOfCollectedSignatures);
function executeAffirmation(address recipient, uint256 value, bytes32 transactionHash) external onlyValidator {
bytes32 hashMsg = keccak256(abi.encodePacked(recipient, value, transactionHash));
bytes32 hashSender = keccak256(abi.encodePacked(msg.sender, hashMsg));
// Duplicated deposits
require(!affirmationsSigned(hashSender));
setAffirmationsSigned(hashSender, true);
uint256 signed = numAffirmationsSigned(hashMsg);
require(!isAlreadyProcessed(signed));
// the check above assumes that the case when the value could be overflew will not happen in the addition operation below
signed = signed + 1;
setNumAffirmationsSigned(hashMsg, signed);
emit SignedForAffirmation(msg.sender, transactionHash);
if (signed >= requiredSignatures()) {
// If the bridge contract does not own enough tokens to transfer
// it will couse funds lock on the home side of the bridge
setNumAffirmationsSigned(hashMsg, markAsProcessed(signed));
require(onExecuteAffirmation(recipient, value));
emit AffirmationCompleted(recipient, value, transactionHash);
}
}
function submitSignature(bytes signature, bytes message) external onlyValidator {
// ensure that `signature` is really `message` signed by `msg.sender`
require(Message.isMessageValid(message));
require(msg.sender == Message.recoverAddressFromSignedMessage(signature, message));
bytes32 hashMsg = keccak256(abi.encodePacked(message));
bytes32 hashSender = keccak256(abi.encodePacked(msg.sender, hashMsg));
uint256 signed = numMessagesSigned(hashMsg);
require(!isAlreadyProcessed(signed));
// the check above assumes that the case when the value could be overflew will not happen in the addition operation below
signed = signed + 1;
if (signed > 1) {
// Duplicated signatures
require(!messagesSigned(hashSender));
} else {
setMessages(hashMsg, message);
}
setMessagesSigned(hashSender, true);
bytes32 signIdx = keccak256(abi.encodePacked(hashMsg, (signed-1)));
setSignatures(signIdx, signature);
setNumMessagesSigned(hashMsg, signed);
emit SignedForUserRequest(msg.sender, hashMsg);
uint256 reqSigs = requiredSignatures();
if (signed >= reqSigs) {
setNumMessagesSigned(hashMsg, markAsProcessed(signed));
emit CollectedSignatures(msg.sender, hashMsg, reqSigs);
}
}
function setMessagesSigned(bytes32 _hash, bool _status) internal {
boolStorage[keccak256(abi.encodePacked("messagesSigned", _hash))] = _status;
}
function onExecuteAffirmation(address, uint256) internal returns(bool) {
}
function numAffirmationsSigned(bytes32 _withdrawal) public view returns(uint256) {
return uintStorage[keccak256(abi.encodePacked("numAffirmationsSigned", _withdrawal))];
}
function setAffirmationsSigned(bytes32 _withdrawal, bool _status) internal {
boolStorage[keccak256(abi.encodePacked("affirmationsSigned", _withdrawal))] = _status;
}
function setNumAffirmationsSigned(bytes32 _withdrawal, uint256 _number) internal {
uintStorage[keccak256(abi.encodePacked("numAffirmationsSigned", _withdrawal))] = _number;
}
function affirmationsSigned(bytes32 _withdrawal) public view returns(bool) {
return boolStorage[keccak256(abi.encodePacked("affirmationsSigned", _withdrawal))];
}
function signature(bytes32 _hash, uint256 _index) public view returns (bytes) {
bytes32 signIdx = keccak256(abi.encodePacked(_hash, _index));
return signatures(signIdx);
}
function messagesSigned(bytes32 _message) public view returns(bool) {
return boolStorage[keccak256(abi.encodePacked("messagesSigned", _message))];
}
function messages(bytes32 _hash) internal view returns(bytes) {
return bytesStorage[keccak256(abi.encodePacked("messages", _hash))];
}
function signatures(bytes32 _hash) internal view returns(bytes) {
return bytesStorage[keccak256(abi.encodePacked("signatures", _hash))];
}
function setSignatures(bytes32 _hash, bytes _signature) internal {
bytesStorage[keccak256(abi.encodePacked("signatures", _hash))] = _signature;
}
function setMessages(bytes32 _hash, bytes _message) internal {
bytesStorage[keccak256(abi.encodePacked("messages", _hash))] = _message;
}
function message(bytes32 _hash) public view returns (bytes) {
return messages(_hash);
}
function setNumMessagesSigned(bytes32 _message, uint256 _number) internal {
uintStorage[keccak256(abi.encodePacked("numMessagesSigned", _message))] = _number;
}
function markAsProcessed(uint256 _v) internal pure returns(uint256) {
return _v | 2 ** 255;
}
function isAlreadyProcessed(uint256 _number) public pure returns(bool) {
return _number & 2**255 == 2**255;
}
function numMessagesSigned(bytes32 _message) public view returns(uint256) {
return uintStorage[keccak256(abi.encodePacked("numMessagesSigned", _message))];
}
}

View File

@ -17,4 +17,9 @@ contract Validatable is EternalStorage {
require(validatorContract().owner() == msg.sender);
_;
}
function requiredSignatures() public view returns(uint256) {
return validatorContract().requiredSignatures();
}
}

View File

@ -33,7 +33,7 @@ contract ForeignBridgeErcToErc is BasicBridge, BasicForeignBridge {
return ERC20Basic(addressStorage[keccak256(abi.encodePacked("erc20token"))]);
}
function onExecuteMessage(address _recipient, uint256 _amount) private returns(bool){
function onExecuteMessage(address _recipient, uint256 _amount) internal returns(bool){
return erc20token().transfer(_recipient, _amount);
}

View File

@ -5,16 +5,10 @@ import "../BasicBridge.sol";
import "../../upgradeability/EternalStorage.sol";
import "../../IBurnableMintableERC677Token.sol";
import "../../ERC677Receiver.sol";
import "../BasicHomeBridge.sol";
contract HomeBridgeErcToErc is ERC677Receiver, EternalStorage, BasicBridge {
using SafeMath for uint256;
event Withdraw (address recipient, uint256 value);
event Deposit (address recipient, uint256 value, bytes32 transactionHash);
event SignedForWithdraw(address indexed signer, bytes32 messageHash);
event SignedForDeposit(address indexed signer, bytes32 transactionHash);
event CollectedSignatures(address authorityResponsibleForRelay, bytes32 messageHash);
contract HomeBridgeErcToErc is ERC677Receiver, EternalStorage, BasicBridge, BasicHomeBridge {
function initialize (
address _validatorContract,
@ -50,45 +44,8 @@ contract HomeBridgeErcToErc is ERC677Receiver, EternalStorage, BasicBridge {
revert();
}
function deposit(address recipient, uint256 value, bytes32 transactionHash) external onlyValidator {
bytes32 hashMsg = keccak256(abi.encodePacked(recipient, value, transactionHash));
bytes32 hashSender = keccak256(abi.encodePacked(msg.sender, hashMsg));
// Duplicated deposits
require(!depositsSigned(hashSender));
setDepositsSigned(hashSender, true);
uint256 signed = numDepositsSigned(hashMsg);
require(!isAlreadyProcessed(signed));
// the check above assumes that the case when the value could be overflew will not happen in the addition operation below
signed = signed + 1;
setNumDepositsSigned(hashMsg, signed);
emit SignedForDeposit(msg.sender, transactionHash);
if (signed >= requiredSignatures()) {
// If the bridge contract does not own enough tokens to transfer
// it will couse funds lock on the home side of the bridge
setNumDepositsSigned(hashMsg, markAsProcessed(signed));
erc677token().mint(recipient, value);
emit Deposit(recipient, value, transactionHash);
}
}
function numDepositsSigned(bytes32 _deposit) public view returns(uint256) {
return uintStorage[keccak256(abi.encodePacked("numDepositsSigned", _deposit))];
}
function setDepositsSigned(bytes32 _deposit, bool _status) private {
boolStorage[keccak256(abi.encodePacked("depositsSigned", _deposit))] = _status;
}
function setNumDepositsSigned(bytes32 _deposit, uint256 _number) private {
uintStorage[keccak256(abi.encodePacked("numDepositsSigned", _deposit))] = _number;
}
function depositsSigned(bytes32 _deposit) public view returns(bool) {
return boolStorage[keccak256(abi.encodePacked("depositsSigned", _deposit))];
function onExecuteAffirmation(address _recipient, uint256 _value) internal returns(bool) {
return erc677token().mint(_recipient, _value);
}
function onTokenTransfer(address _from, uint256 _value, bytes /*_data*/) external returns(bool) {
@ -96,96 +53,14 @@ contract HomeBridgeErcToErc is ERC677Receiver, EternalStorage, BasicBridge {
require(withinLimit(_value));
setTotalSpentPerDay(getCurrentDay(), totalSpentPerDay(getCurrentDay()).add(_value));
erc677token().burn(_value);
emit Withdraw(_from, _value);
emit UserRequestForSignature(_from, _value);
return true;
}
function submitSignature(bytes signature, bytes message) external onlyValidator {
// ensure that `signature` is really `message` signed by `msg.sender`
require(Message.isMessageValid(message));
require(msg.sender == Message.recoverAddressFromSignedMessage(signature, message));
bytes32 hashMsg = keccak256(abi.encodePacked(message));
bytes32 hashSender = keccak256(abi.encodePacked(msg.sender, hashMsg));
uint256 signed = numMessagesSigned(hashMsg);
require(!isAlreadyProcessed(signed));
// the check above assumes that the case when the value could be overflew will not happen in the addition operation below
signed = signed + 1;
if (signed > 1) {
// Duplicated signatures
require(!messagesSigned(hashSender));
} else {
setMessages(hashMsg, message);
}
setMessagesSigned(hashSender, true);
bytes32 signIdx = keccak256(abi.encodePacked(hashMsg, (signed-1)));
setSignatures(signIdx, signature);
setNumMessagesSigned(hashMsg, signed);
emit SignedForWithdraw(msg.sender, hashMsg);
if (signed >= validatorContract().requiredSignatures()) {
setNumMessagesSigned(hashMsg, markAsProcessed(signed));
emit CollectedSignatures(msg.sender, hashMsg);
}
}
function signature(bytes32 _hash, uint256 _index) public view returns (bytes) {
bytes32 signIdx = keccak256(abi.encodePacked(_hash, _index));
return signatures(signIdx);
}
function messagesSigned(bytes32 _message) public view returns(bool) {
return boolStorage[keccak256(abi.encodePacked("messagesSigned", _message))];
}
function message(bytes32 _hash) public view returns (bytes) {
return messages(_hash);
}
function isAlreadyProcessed(uint256 _number) public pure returns(bool) {
return _number & 2**255 == 2**255;
}
function numMessagesSigned(bytes32 _message) public view returns(uint256) {
return uintStorage[keccak256(abi.encodePacked("numMessagesSigned", _message))];
}
function erc677token() public view returns(IBurnableMintableERC677Token) {
return IBurnableMintableERC677Token(addressStorage[keccak256(abi.encodePacked("erc677token"))]);
}
// PRIVATE Methods
function setMessagesSigned(bytes32 _hash, bool _status) private {
boolStorage[keccak256(abi.encodePacked("messagesSigned", _hash))] = _status;
}
function messages(bytes32 _hash) private view returns(bytes) {
return bytesStorage[keccak256(abi.encodePacked("messages", _hash))];
}
function signatures(bytes32 _hash) private view returns(bytes) {
return bytesStorage[keccak256(abi.encodePacked("signatures", _hash))];
}
function setSignatures(bytes32 _hash, bytes _signature) private {
bytesStorage[keccak256(abi.encodePacked("signatures", _hash))] = _signature;
}
function setMessages(bytes32 _hash, bytes _message) private {
bytesStorage[keccak256(abi.encodePacked("messages", _hash))] = _message;
}
function setNumMessagesSigned(bytes32 _message, uint256 _number) private {
uintStorage[keccak256(abi.encodePacked("numMessagesSigned", _message))] = _number;
}
function markAsProcessed(uint256 _v) private pure returns(uint256) {
return _v | 2 ** 255;
}
function setErc677token(address _token) private {
require(_token != address(0));
addressStorage[keccak256(abi.encodePacked("erc677token"))] = _token;

View File

@ -53,7 +53,7 @@ contract ForeignBridgeNativeToErc is ERC677Receiver, BasicBridge, BasicForeignBr
return IBurnableMintableERC677Token(addressStorage[keccak256(abi.encodePacked("erc677token"))]);
}
function onExecuteMessage(address _recipient, uint256 _amount) private returns(bool){
function onExecuteMessage(address _recipient, uint256 _amount) internal returns(bool){
return erc677token().mint(_recipient, _amount);
}

View File

@ -3,17 +3,9 @@ import "../../libraries/SafeMath.sol";
import "../../libraries/Message.sol";
import "../BasicBridge.sol";
import "../../upgradeability/EternalStorage.sol";
import "../BasicHomeBridge.sol";
contract HomeBridgeNativeToErc is EternalStorage, BasicBridge {
using SafeMath for uint256;
event GasConsumptionLimitsUpdated(uint256 gas);
event UserRequestForSignature(address recipient, uint256 value);
event AffirmationCompleted (address recipient, uint256 value, bytes32 transactionHash);
event SignedForUserRequest(address indexed signer, bytes32 messageHash);
event SignedForAffirmation(address indexed signer, bytes32 transactionHash);
event CollectedSignatures(address authorityResponsibleForRelay, bytes32 messageHash, uint256 NumberOfCollectedSignatures);
contract HomeBridgeNativeToErc is EternalStorage, BasicBridge, BasicHomeBridge {
function initialize (
address _validatorContract,
@ -49,127 +41,8 @@ contract HomeBridgeNativeToErc is EternalStorage, BasicBridge {
emit UserRequestForSignature(msg.sender, msg.value);
}
function executeAffirmation(address recipient, uint256 value, bytes32 transactionHash) external onlyValidator {
bytes32 hashMsg = keccak256(abi.encodePacked(recipient, value, transactionHash));
bytes32 hashSender = keccak256(abi.encodePacked(msg.sender, hashMsg));
// Duplicated deposits
require(!affirmationsSigned(hashSender));
setAffirmationsSigned(hashSender, true);
uint256 signed = numAffirmationsSigned(hashMsg);
require(!isAlreadyProcessed(signed));
// the check above assumes that the case when the value could be overflew will not happen in the addition operation below
signed = signed + 1;
setNumAffirmationsSigned(hashMsg, signed);
emit SignedForAffirmation(msg.sender, transactionHash);
if (signed >= requiredSignatures()) {
// If the bridge contract does not own enough tokens to transfer
// it will couse funds lock on the home side of the bridge
setNumAffirmationsSigned(hashMsg, markAsProcessed(signed));
recipient.transfer(value);
emit AffirmationCompleted(recipient, value, transactionHash);
}
function onExecuteAffirmation(address _recipient, uint256 _value) internal returns(bool) {
_recipient.transfer(_value);
return true;
}
function numAffirmationsSigned(bytes32 _withdrawal) public view returns(uint256) {
return uintStorage[keccak256(abi.encodePacked("numAffirmationsSigned", _withdrawal))];
}
function setAffirmationsSigned(bytes32 _withdrawal, bool _status) private {
boolStorage[keccak256(abi.encodePacked("affirmationsSigned", _withdrawal))] = _status;
}
function setNumAffirmationsSigned(bytes32 _withdrawal, uint256 _number) private {
uintStorage[keccak256(abi.encodePacked("numAffirmationsSigned", _withdrawal))] = _number;
}
function affirmationsSigned(bytes32 _withdrawal) public view returns(bool) {
return boolStorage[keccak256(abi.encodePacked("affirmationsSigned", _withdrawal))];
}
function submitSignature(bytes signature, bytes message) external onlyValidator {
// ensure that `signature` is really `message` signed by `msg.sender`
require(Message.isMessageValid(message));
require(msg.sender == Message.recoverAddressFromSignedMessage(signature, message));
bytes32 hashMsg = keccak256(abi.encodePacked(message));
bytes32 hashSender = keccak256(abi.encodePacked(msg.sender, hashMsg));
uint256 signed = numMessagesSigned(hashMsg);
require(!isAlreadyProcessed(signed));
// the check above assumes that the case when the value could be overflew will not happen in the addition operation below
signed = signed + 1;
if (signed > 1) {
// Duplicated signatures
require(!messagesSigned(hashSender));
} else {
setMessages(hashMsg, message);
}
setMessagesSigned(hashSender, true);
bytes32 signIdx = keccak256(abi.encodePacked(hashMsg, (signed-1)));
setSignatures(signIdx, signature);
setNumMessagesSigned(hashMsg, signed);
emit SignedForUserRequest(msg.sender, hashMsg);
uint256 reqSigs = requiredSignatures();
if (signed >= reqSigs) {
setNumMessagesSigned(hashMsg, markAsProcessed(signed));
emit CollectedSignatures(msg.sender, hashMsg, reqSigs);
}
}
function setMessagesSigned(bytes32 _hash, bool _status) private {
boolStorage[keccak256(abi.encodePacked("messagesSigned", _hash))] = _status;
}
function signature(bytes32 _hash, uint256 _index) public view returns (bytes) {
bytes32 signIdx = keccak256(abi.encodePacked(_hash, _index));
return signatures(signIdx);
}
function messagesSigned(bytes32 _message) public view returns(bool) {
return boolStorage[keccak256(abi.encodePacked("messagesSigned", _message))];
}
function messages(bytes32 _hash) private view returns(bytes) {
return bytesStorage[keccak256(abi.encodePacked("messages", _hash))];
}
function signatures(bytes32 _hash) private view returns(bytes) {
return bytesStorage[keccak256(abi.encodePacked("signatures", _hash))];
}
function setSignatures(bytes32 _hash, bytes _signature) private {
bytesStorage[keccak256(abi.encodePacked("signatures", _hash))] = _signature;
}
function setMessages(bytes32 _hash, bytes _message) private {
bytesStorage[keccak256(abi.encodePacked("messages", _hash))] = _message;
}
function message(bytes32 _hash) public view returns (bytes) {
return messages(_hash);
}
function setNumMessagesSigned(bytes32 _message, uint256 _number) private {
uintStorage[keccak256(abi.encodePacked("numMessagesSigned", _message))] = _number;
}
function markAsProcessed(uint256 _v) private pure returns(uint256) {
return _v | 2 ** 255;
}
function isAlreadyProcessed(uint256 _number) public pure returns(bool) {
return _number & 2**255 == 2**255;
}
function numMessagesSigned(bytes32 _message) public view returns(uint256) {
return uintStorage[keccak256(abi.encodePacked("numMessagesSigned", _message))];
}
}

View File

@ -95,7 +95,7 @@ contract('HomeBridge_ERC20_to_ERC20', async (accounts) => {
})
})
describe('#deposit', async () => {
describe('#executeAffirmation', async () => {
let homeBridge;
beforeEach(async () => {
homeBridge = await HomeBridge.new();
@ -108,13 +108,13 @@ contract('HomeBridge_ERC20_to_ERC20', async (accounts) => {
const value = halfEther;
const balanceBefore = await token.balanceOf(recipient)
const transactionHash = "0x806335163828a8eda675cff9c84fa6e6c7cf06bb44cc6ec832e42fe789d01415";
const {logs} = await homeBridge.deposit(recipient, value, transactionHash, {from: authorities[0]})
logs[0].event.should.be.equal("SignedForDeposit");
const {logs} = await homeBridge.executeAffirmation(recipient, value, transactionHash, {from: authorities[0]})
logs[0].event.should.be.equal("SignedForAffirmation");
logs[0].args.should.be.deep.equal({
signer: authorities[0],
transactionHash
});
logs[1].event.should.be.equal("Deposit");
logs[1].event.should.be.equal("AffirmationCompleted");
logs[1].args.should.be.deep.equal({
recipient,
value,
@ -127,10 +127,10 @@ contract('HomeBridge_ERC20_to_ERC20', async (accounts) => {
const msgHash = Web3Utils.soliditySha3(recipient, value, transactionHash);
const senderHash = Web3Utils.soliditySha3(authorities[0], msgHash)
true.should.be.equal(await homeBridge.depositsSigned(senderHash))
true.should.be.equal(await homeBridge.affirmationsSigned(senderHash))
const markedAsProcessed = new web3.BigNumber(2).pow(255).add(1);
markedAsProcessed.should.be.bignumber.equal(await homeBridge.numDepositsSigned(msgHash));
await homeBridge.deposit(recipient, value, transactionHash, {from: authorities[0]}).should.be.rejectedWith(ERROR_MSG)
markedAsProcessed.should.be.bignumber.equal(await homeBridge.numAffirmationsSigned(msgHash));
await homeBridge.executeAffirmation(recipient, value, transactionHash, {from: authorities[0]}).should.be.rejectedWith(ERROR_MSG)
})
it('test with 2 signatures required', async () => {
@ -148,23 +148,23 @@ contract('HomeBridge_ERC20_to_ERC20', async (accounts) => {
const balanceBefore = await token2sig.balanceOf(recipient)
const msgHash = Web3Utils.soliditySha3(recipient, value, transactionHash);
const {logs} = await homeBridgeWithTwoSigs.deposit(recipient, value, transactionHash, {from: authoritiesTwoAccs[0]}).should.be.fulfilled;
logs[0].event.should.be.equal("SignedForDeposit");
const {logs} = await homeBridgeWithTwoSigs.executeAffirmation(recipient, value, transactionHash, {from: authoritiesTwoAccs[0]}).should.be.fulfilled;
logs[0].event.should.be.equal("SignedForAffirmation");
logs[0].args.should.be.deep.equal({
signer: authorities[0],
transactionHash
});
'0'.should.be.bignumber.equal(await token2sig.totalSupply())
const notProcessed = await homeBridgeWithTwoSigs.numDepositsSigned(msgHash);
const notProcessed = await homeBridgeWithTwoSigs.numAffirmationsSigned(msgHash);
notProcessed.should.be.bignumber.equal(1);
await homeBridgeWithTwoSigs.deposit(recipient, value, transactionHash, {from: authoritiesTwoAccs[0]}).should.be.rejectedWith(ERROR_MSG);
const secondSignature = await homeBridgeWithTwoSigs.deposit(recipient, value, transactionHash, {from: authoritiesTwoAccs[1]}).should.be.fulfilled;
await homeBridgeWithTwoSigs.executeAffirmation(recipient, value, transactionHash, {from: authoritiesTwoAccs[0]}).should.be.rejectedWith(ERROR_MSG);
const secondSignature = await homeBridgeWithTwoSigs.executeAffirmation(recipient, value, transactionHash, {from: authoritiesTwoAccs[1]}).should.be.fulfilled;
const balanceAfter = await token2sig.balanceOf(recipient)
balanceAfter.should.be.bignumber.equal(balanceBefore.add(value))
secondSignature.logs[1].event.should.be.equal("Deposit");
secondSignature.logs[1].event.should.be.equal("AffirmationCompleted");
secondSignature.logs[1].args.should.be.deep.equal({
recipient,
value,
@ -172,12 +172,12 @@ contract('HomeBridge_ERC20_to_ERC20', async (accounts) => {
})
const senderHash = Web3Utils.soliditySha3(authoritiesTwoAccs[0], msgHash)
true.should.be.equal(await homeBridgeWithTwoSigs.depositsSigned(senderHash))
true.should.be.equal(await homeBridgeWithTwoSigs.affirmationsSigned(senderHash))
const senderHash2 = Web3Utils.soliditySha3(authoritiesTwoAccs[1], msgHash);
true.should.be.equal(await homeBridgeWithTwoSigs.depositsSigned(senderHash2))
true.should.be.equal(await homeBridgeWithTwoSigs.affirmationsSigned(senderHash2))
const markedAsProcessed = await homeBridgeWithTwoSigs.numDepositsSigned(msgHash);
const markedAsProcessed = await homeBridgeWithTwoSigs.numAffirmationsSigned(msgHash);
const processed = new web3.BigNumber(2).pow(255).add(2);
markedAsProcessed.should.be.bignumber.equal(processed)
})
@ -185,15 +185,15 @@ contract('HomeBridge_ERC20_to_ERC20', async (accounts) => {
const recipient = accounts[5];
const value = '1';
const transactionHash = "0x806335163828a8eda675cff9c84fa6e6c7cf06bb44cc6ec832e42fe789d01415";
await homeBridge.deposit(recipient, value, transactionHash, {from: authorities[0]}).should.be.fulfilled;
await homeBridge.deposit(recipient, value, transactionHash, {from: authorities[0]}).should.be.rejectedWith(ERROR_MSG);
await homeBridge.executeAffirmation(recipient, value, transactionHash, {from: authorities[0]}).should.be.fulfilled;
await homeBridge.executeAffirmation(recipient, value, transactionHash, {from: authorities[0]}).should.be.rejectedWith(ERROR_MSG);
})
it('should not allow non-authorities to execute deposit', async () => {
const recipient = accounts[5];
const value = oneEther;
const transactionHash = "0x806335163828a8eda675cff9c84fa6e6c7cf06bb44cc6ec832e42fe789d01415";
await homeBridge.deposit(recipient, value, transactionHash, {from: accounts[7]}).should.be.rejectedWith(ERROR_MSG);
await homeBridge.executeAffirmation(recipient, value, transactionHash, {from: accounts[7]}).should.be.rejectedWith(ERROR_MSG);
})
it('doesnt allow to deposit if requiredSignatures has changed', async () => {
@ -211,13 +211,13 @@ contract('HomeBridge_ERC20_to_ERC20', async (accounts) => {
const balanceBefore = await token.balanceOf(recipient)
const msgHash = Web3Utils.soliditySha3(recipient, value, transactionHash);
await homeBridgeWithTwoSigs.deposit(recipient, value, transactionHash, {from: authoritiesTwoAccs[0]}).should.be.fulfilled;
await homeBridgeWithTwoSigs.deposit(recipient, value, transactionHash, {from: authoritiesTwoAccs[1]}).should.be.fulfilled;
await homeBridgeWithTwoSigs.executeAffirmation(recipient, value, transactionHash, {from: authoritiesTwoAccs[0]}).should.be.fulfilled;
await homeBridgeWithTwoSigs.executeAffirmation(recipient, value, transactionHash, {from: authoritiesTwoAccs[1]}).should.be.fulfilled;
balanceBefore.add(value).should.be.bignumber.equal(await token2sig.balanceOf(recipient))
await validatorContractWith2Signatures.setRequiredSignatures(3).should.be.fulfilled;
await homeBridgeWithTwoSigs.deposit(recipient, value, transactionHash, {from: authoritiesTwoAccs[2]}).should.be.rejectedWith(ERROR_MSG);
await homeBridgeWithTwoSigs.executeAffirmation(recipient, value, transactionHash, {from: authoritiesTwoAccs[2]}).should.be.rejectedWith(ERROR_MSG);
await validatorContractWith2Signatures.setRequiredSignatures(1).should.be.fulfilled;
await homeBridgeWithTwoSigs.deposit(recipient, value, transactionHash, {from: authoritiesTwoAccs[2]}).should.be.rejectedWith(ERROR_MSG);
await homeBridgeWithTwoSigs.executeAffirmation(recipient, value, transactionHash, {from: authoritiesTwoAccs[2]}).should.be.rejectedWith(ERROR_MSG);
balanceBefore.add(value).should.be.bignumber.equal(await token2sig.balanceOf(recipient))
})
@ -252,7 +252,7 @@ contract('HomeBridge_ERC20_to_ERC20', async (accounts) => {
var message = createMessage(recipientAccount, value, transactionHash);
var signature = await sign(authoritiesTwoAccs[0], message)
const {logs} = await homeBridgeWithTwoSigs.submitSignature(signature, message, {from: authorities[0]}).should.be.fulfilled;
logs[0].event.should.be.equal('SignedForWithdraw')
logs[0].event.should.be.equal('SignedForUserRequest')
const msgHashFromLog = logs[0].args.messageHash
const signatureFromContract = await homeBridgeWithTwoSigs.signature(msgHashFromLog, 0);
const messageFromContract = await homeBridgeWithTwoSigs.message(msgHashFromLog);