Permalink
Browse files

payroll: Move EtherToken dependency to Finance app

  • Loading branch information...
bingen committed Feb 6, 2018
1 parent 786dac9 commit 61e6c2f336745f3e9b84280afffecccc2464bc89
@@ -96,6 +96,17 @@ contract Finance is AragonApp, ERC677Receiver {
_;
}

/**
* @dev Sends ETH to Vault. This contract should never receive funds,
* but in case it happens, this function recovers them sending them
* to Vault.
* @notice Allows to send ETH from this contract to Vault, to avoid locking them in contract forever.
*/
function escapeHatch() public payable {
// convert ETH to EtherToken
etherToken.wrapAndCall.value(this.balance)(address(this), "Adding Funds");
}

/**
* @notice Initialize Finance app for `_vault` with duration `_periodDuration`
* @param _vault Address of the vault Finance will rely on (non changeable)
@@ -173,6 +173,23 @@ contract('Finance App', accounts => {
assert.equal(await app.currentPeriodId(), 2, 'should have transitioned 2 periods')
})

it("escapes hatch, recovers ETH", async () => {
let vaultInitialBalance = await getBalance(vault.address)
let vaultTokenInitialBalance = await etherToken.balanceOf(vault.address)
let financeInitialBalance = await getBalance(app.address)
let financeTokenInitialBalance = await etherToken.balanceOf(app.address)
let amount = web3.toWei(1, 'ether')
await app.escapeHatch({value: amount})
let vaultFinalBalance = await getBalance(vault.address)
let vaultTokenFinalBalance = await etherToken.balanceOf(vault.address)
let financeFinalBalance = await getBalance(app.address)
let financeTokenFinalBalance = await etherToken.balanceOf(app.address)
assert.equal(financeFinalBalance.valueOf(), 0, "Funds not recovered (Finance)!")
assert.equal(financeTokenFinalBalance.valueOf(), 0, "Funds not recovered (Finance)!")
assert.equal(vaultFinalBalance.toString(), 0, "Funds not recovered (Vault)!")
assert.equal(vaultTokenFinalBalance.toString(), vaultTokenInitialBalance.add(amount).toString(), "Funds not recovered (Vault)!")
})

context('setting budget', () => {
const recipient = accounts[1]
const time = 22
@@ -2,7 +2,6 @@ pragma solidity 0.4.18;

import "@aragon/os/contracts/apps/AragonApp.sol";
import "@aragon/os/contracts/common/Initializable.sol";
import "@aragon/os/contracts/common/EtherToken.sol";
import "@aragon/os/contracts/common/IForwarder.sol";

import "@aragon/os/contracts/lib/zeppelin/token/ERC20.sol";
@@ -40,7 +39,6 @@ contract Payroll is AragonApp { // , IForwarder { makes coverage crash (removes

Finance public finance;
ERC20 public denominationToken;
EtherToken public etherToken;
mapping(address => uint256) private exchangeRates;
mapping(address => bool) private allowedTokens;
address[] private allowedTokensArray;
@@ -60,12 +58,10 @@ contract Payroll is AragonApp { // , IForwarder { makes coverage crash (removes
/**
* @notice Initialize Payroll app for `_finance`. Set ETH and Denomination tokens
* @param _finance Address of the finance Payroll will rely on (non changeable)
* @param _etherToken Address of EtherToken
* @param _denominationToken Address of Denomination Token
*/
function initialize(
Finance _finance,
EtherToken _etherToken,
ERC20 _denominationToken
) external
onlyInit
@@ -74,7 +70,6 @@ contract Payroll is AragonApp { // , IForwarder { makes coverage crash (removes

nextEmployee = 1; // leave 0 to check null address mapping
finance = _finance;
etherToken = _etherToken;
denominationToken = _denominationToken;
exchangeRates[address(denominationToken)] = 1;
}
@@ -229,8 +224,7 @@ contract Payroll is AragonApp { // , IForwarder { makes coverage crash (removes
* @notice Allows to send ETH from this contract to Finance, to avoid locking them in contract forever.
*/
function escapeHatch() external {
// convert ETH to EtherToken
etherToken.wrapAndCall.value(this.balance)(address(finance), "Adding Funds");
finance.escapeHatch.value(this.balance)();
}

/**
@@ -75,21 +75,21 @@ contract('Payroll', function(accounts) {
payroll = await Payroll.new();
usdToken = await deployErc20Token("USD");
oracle = await OracleMock.new();
await payroll.initialize(finance.address, etherToken.address, usdToken.address);
await payroll.initialize(finance.address, usdToken.address);
// transfer ETH to Payroll contract
for (let i = 1; i < 9; i++)
await etherToken.wrapAndCall(finance.address, "Initial funds from account " + i, { from: accounts[i], value: web3.toWei(90, 'ether') });
});

it('fails on reinitialization', async () => {
return assertRevert(async () => {
await payroll.initialize(finance.address, etherToken.address, usdToken.address);
await payroll.initialize(finance.address, usdToken.address);
});
});

it("checks that initial values match", async () => {
let tmpEther = await payroll.etherToken();
assert.equal(tmpEther.valueOf(), etherToken.address, "USD Token address is wrong");
let tmpFinance = await payroll.finance();
assert.equal(tmpFinance.valueOf(), finance.address, "Finance address is wrong");
let tmpUsd = await payroll.denominationToken();
assert.equal(tmpUsd.valueOf(), usdToken.address, "USD Token address is wrong");
});
@@ -334,7 +334,7 @@ contract('Payroll', function(accounts) {

it("fails on payday with no token allocation", async () => {
payroll2 = await Payroll.new();
await payroll2.initialize(finance.address, etherToken.address, usdToken.address);
await payroll2.initialize(finance.address, usdToken.address);
// add allowed tokens
let tokens = [etherToken, usdToken, erc20Token1, erc677Token1];
for (let i in tokens) {
@@ -47,7 +47,7 @@ contract('Payroll', function(accounts) {
payroll = await Payroll.new();
usdToken = await deployErc20Token("USD");
oracle = await OracleMock.new();
await payroll.initialize(finance.address, etherToken.address, usdToken.address);
await payroll.initialize(finance.address, usdToken.address);
});

const convertAndRoundSalary = function (a) {

0 comments on commit 61e6c2f

Please sign in to comment.