Skip to content
Permalink
Browse files

feat: reorder accruedSalary storage to be beside employee's denominat…

…ionSalary
  • Loading branch information...
sohkai committed May 9, 2019
1 parent bf5ce8b commit 094116b1a8684d4f5f31d4a4a4c198e33a036567
@@ -63,9 +63,9 @@ contract Payroll is EtherTokenConstant, IForwarder, IsContract, AragonApp {
address accountAddress; // unique, but can be changed over time
mapping(address => uint256) allocation;
uint256 denominationTokenSalary; // salary per second in denomination Token
uint256 accruedSalary; // keep track of any leftover accrued salary when changing salaries
uint256 bonus;
uint256 reimbursements;
uint256 accruedSalary;
uint64 lastPayroll;
uint64 endDate;
}
@@ -92,9 +92,9 @@ contract Payroll is EtherTokenConstant, IForwarder, IsContract, AragonApp {
);
event TerminateEmployee(uint256 indexed employeeId, uint64 endDate);
event SetEmployeeSalary(uint256 indexed employeeId, uint256 denominationSalary);
event AddEmployeeAccruedSalary(uint256 indexed employeeId, uint256 amount);
event AddEmployeeBonus(uint256 indexed employeeId, uint256 amount);
event AddEmployeeReimbursement(uint256 indexed employeeId, uint256 amount);
event AddEmployeeAccruedSalary(uint256 indexed employeeId, uint256 amount);
event ChangeAddressByEmployee(uint256 indexed employeeId, address indexed newAccountAddress, address indexed oldAccountAddress);
event DetermineAllocation(uint256 indexed employeeId);
event SendPayment(
@@ -403,9 +403,9 @@ contract Payroll is EtherTokenConstant, IForwarder, IsContract, AragonApp {
* @param _accountAddress Employee's address to receive payments
* @return Employee's identifier
* @return Employee's salary, per second in denomination token
* @return Employee's accrued salary
* @return Employee's bonus amount
* @return Employee's reimbursements amount
* @return Employee's accrued salary
* @return Employee's last salary payment date
* @return Employee's termination date (max uint64 if none)
*/
@@ -416,9 +416,9 @@ contract Payroll is EtherTokenConstant, IForwarder, IsContract, AragonApp {
returns (
uint256 employeeId,
uint256 denominationSalary,
uint256 accruedSalary,
uint256 bonus,
uint256 reimbursements,
uint256 accruedSalary,
uint64 lastPayroll,
uint64 endDate
)
@@ -428,9 +428,9 @@ contract Payroll is EtherTokenConstant, IForwarder, IsContract, AragonApp {
Employee storage employee = employees[employeeId];

denominationSalary = employee.denominationTokenSalary;
accruedSalary = employee.accruedSalary;
bonus = employee.bonus;
reimbursements = employee.reimbursements;
accruedSalary = employee.accruedSalary;
lastPayroll = employee.lastPayroll;
endDate = employee.endDate;
}
@@ -440,9 +440,9 @@ contract Payroll is EtherTokenConstant, IForwarder, IsContract, AragonApp {
* @param _employeeId Employee's identifier
* @return Employee's address to receive payments
* @return Employee's salary, per second in denomination token
* @return Employee's accrued salary
* @return Employee's bonus amount
* @return Employee's reimbursements amount
* @return Employee's accrued salary
* @return Employee's last payment date
* @return Employee's termination date (max uint64 if none)
*/
@@ -453,9 +453,9 @@ contract Payroll is EtherTokenConstant, IForwarder, IsContract, AragonApp {
returns (
address accountAddress,
uint256 denominationSalary,
uint256 accruedSalary,
uint256 bonus,
uint256 reimbursements,
uint256 accruedSalary,
uint64 lastPayroll,
uint64 endDate
)
@@ -464,9 +464,9 @@ contract Payroll is EtherTokenConstant, IForwarder, IsContract, AragonApp {

accountAddress = employee.accountAddress;
denominationSalary = employee.denominationTokenSalary;
accruedSalary = employee.accruedSalary;
bonus = employee.bonus;
reimbursements = employee.reimbursements;
accruedSalary = employee.accruedSalary;
lastPayroll = employee.lastPayroll;
endDate = employee.endDate;
}
@@ -633,7 +633,7 @@ contract Payroll is EtherTokenConstant, IForwarder, IsContract, AragonApp {

if (
employee.lastPayroll == employee.endDate &&
(employee.reimbursements == 0 && employee.accruedSalary == 0 && employee.bonus == 0)
(employee.accruedSalary == 0 && employee.bonus == 0 && employee.reimbursements == 0)
) {
delete employeeIds[employee.accountAddress];
delete employees[_employeeId];
@@ -79,12 +79,12 @@ contract('Payroll employees addition', ([owner, employee, anotherEmployee, anyon
assert.equal(event.startDate.toString(), startDate, 'employee start date does not match')
assert.equal(event.role, anotherRole, 'employee role does not match')

const [address, employeeSalary, bonus, reimbursements, accruedSalary, lastPayroll, endDate] = await payroll.getEmployee(anotherEmployeeId)
const [address, employeeSalary, accruedSalary, bonus, reimbursements, lastPayroll, endDate] = await payroll.getEmployee(anotherEmployeeId)
assert.equal(address, anotherEmployee, 'employee address does not match')
assert.equal(bonus.toString(), 0, 'employee bonus does not match')
assert.equal(reimbursements, 0, 'employee reimbursements does not match')
assert.equal(accruedSalary, 0, 'employee accrued salary does not match')
assert.equal(employeeSalary.toString(), anotherSalary.toString(), 'employee salary does not match')
assert.equal(accruedSalary.toString(), 0, 'employee accrued salary does not match')
assert.equal(bonus.toString(), 0, 'employee bonus does not match')
assert.equal(reimbursements.toString(), 0, 'employee reimbursements does not match')
assert.equal(lastPayroll.toString(), startDate.toString(), 'employee last payroll does not match')
assert.equal(endDate.toString(), MAX_UINT64, 'employee end date does not match')
})
@@ -45,10 +45,10 @@ contract('Payroll bonuses', ([owner, employee, anyone]) => {

const itAddsBonusesSuccessfully = amount => {
it('adds given bonus amount', async () => {
const previousBonus = (await payroll.getEmployee(employeeId))[2]
const previousBonus = (await payroll.getEmployee(employeeId))[3]
await payroll.addBonus(employeeId, amount, { from })

const currentBonus = (await payroll.getEmployee(employeeId))[2]
const currentBonus = (await payroll.getEmployee(employeeId))[3]
assert.equal(previousBonus.plus(amount).toString(), currentBonus.toString(), 'bonus amount does not match')
})

@@ -221,10 +221,10 @@ contract('Payroll bonuses', ([owner, employee, anyone]) => {

const assertEmployeeIsNotRemoved = (requestedAmount, expectedRequestedAmount = requestedAmount) => {
it('does not remove the employee and resets the bonus amount', async () => {
const previousBonus = (await payroll.getEmployee(employeeId))[2]
const previousBonus = (await payroll.getEmployee(employeeId))[3]
await payroll.payday(PAYMENT_TYPES.BONUS, requestedAmount, { from })

const [address, employeeSalary, bonus] = await payroll.getEmployee(employeeId)
const [address, employeeSalary, , bonus] = await payroll.getEmployee(employeeId)

assert.equal(address, employee, 'employee address does not match')
assert.equal(employeeSalary.toString(), salary.toString(), 'employee salary does not match')
@@ -36,13 +36,13 @@ contract('Payroll employee getters', ([owner, employee]) => {
})

it('adds a new employee', async () => {
const [address, employeeSalary, bonus, reimbursements, accruedSalary, lastPayroll, endDate] = await payroll.getEmployee(employeeId)
const [address, employeeSalary, accruedSalary, bonus, reimbursements, lastPayroll, endDate] = await payroll.getEmployee(employeeId)

assert.equal(address, employee, 'employee address does not match')
assert.equal(bonus.toString(), 0, 'employee bonus does not match')
assert.equal(reimbursements, 0, 'employee reimbursements does not match')
assert.equal(accruedSalary, 0, 'employee accrued salary does not match')
assert.equal(employeeSalary.toString(), salary.toString(), 'employee salary does not match')
assert.equal(accruedSalary.toString(), 0, 'employee accrued salary does not match')
assert.equal(bonus.toString(), 0, 'employee bonus does not match')
assert.equal(reimbursements.toString(), 0, 'employee reimbursements does not match')
assert.equal(lastPayroll.toString(), (await currentTimestamp()).toString(), 'employee last payroll does not match')
assert.equal(endDate.toString(), MAX_UINT64, 'employee end date does not match')
})
@@ -83,13 +83,13 @@ contract('Payroll employee getters', ([owner, employee]) => {
})

it('adds a new employee', async () => {
const [id, employeeSalary, bonus, reimbursements, accruedSalary, lastPayroll, endDate] = await payroll.getEmployeeByAddress(address)
const [id, employeeSalary, accruedSalary, bonus, reimbursements, lastPayroll, endDate] = await payroll.getEmployeeByAddress(address)

assert.equal(id.toString(), employeeId.toString(), 'employee id does not match')
assert.equal(employeeSalary.toString(), salary.toString(), 'employee salary does not match')
assert.equal(accruedSalary.toString(), 0, 'employee accrued salary does not match')
assert.equal(bonus.toString(), 0, 'employee bonus does not match')
assert.equal(reimbursements.toString(), 0, 'employee reimbursements does not match')
assert.equal(accruedSalary.toString(), 0, 'employee accrued salary does not match')
assert.equal(lastPayroll.toString(), (await currentTimestamp()).toString(), 'employee last payroll does not match')
assert.equal(endDate.toString(), MAX_UINT64, 'employee end date does not match')
})
@@ -57,7 +57,7 @@ contract('Payroll employees modification', ([owner, employee, anotherEmployee, a
const receipt = await payroll.setEmployeeSalary(employeeId, newSalary, { from })
await increaseTime(ONE_MONTH)

const accruedSalary = (await payroll.getEmployee(employeeId))[4]
const accruedSalary = (await payroll.getEmployee(employeeId))[2]
const expectedAccruedSalary = previousSalary.mul(ONE_MONTH)
assert.equal(accruedSalary.toString(), expectedAccruedSalary.toString(), 'accrued salary does not match')

@@ -73,7 +73,7 @@ contract('Payroll employees modification', ([owner, employee, anotherEmployee, a
await increaseTime(ONE_MONTH)
await payroll.setEmployeeSalary(employeeId, newSalary.mul(2), { from })

const accruedSalary = (await payroll.getEmployee(employeeId))[4]
const accruedSalary = (await payroll.getEmployee(employeeId))[2]
const expectedAccruedSalary = previousSalary.mul(ONE_MONTH).plus(newSalary.mul(ONE_MONTH))
assert.equal(accruedSalary.toString(), expectedAccruedSalary.toString(), 'accrued salary does not match')
})
@@ -128,7 +128,7 @@ contract('Payroll payday', ([owner, employee, anyone]) => {
const assertEmployeeIsUpdatedCorrectly = (requestedAmount, expectedRequestedAmount) => {
it('updates the accrued salary and the last payroll date', async () => {
let expectedLastPayrollDate, expectedAccruedSalary
const [previousAccruedSalary, previousPayrollDate] = (await payroll.getEmployee(employeeId)).slice(4, 6)
const [previousAccruedSalary, , , previousPayrollDate] = (await payroll.getEmployee(employeeId)).slice(2, 6)

if (expectedRequestedAmount >= previousAccruedSalary) {
expectedAccruedSalary = bn(0)
@@ -141,7 +141,7 @@ contract('Payroll payday', ([owner, employee, anyone]) => {

await payroll.payday(PAYMENT_TYPES.PAYROLL, requestedAmount, { from })

const [accruedSalary, lastPayrollDate] = (await payroll.getEmployee(employeeId)).slice(4, 6)
const [accruedSalary, , , lastPayrollDate] = (await payroll.getEmployee(employeeId)).slice(2, 6)
assert.equal(accruedSalary.toString(), expectedAccruedSalary.toString(), 'accrued salary does not match')
assert.equal(lastPayrollDate.toString(), expectedLastPayrollDate.toString(), 'last payroll date does not match')
})
@@ -47,7 +47,7 @@ contract('Payroll reimbursements', ([owner, employee, anyone]) => {
it('adds requested reimbursement', async () => {
await payroll.addReimbursement(employeeId, reimburse, { from })

const reimbursements = (await payroll.getEmployee(employeeId))[3]
const reimbursements = (await payroll.getEmployee(employeeId))[4]
assert.equal(reimbursements.toString(), reimburse.toString(), 'reimbursement does not match')
})

@@ -210,10 +210,10 @@ contract('Payroll reimbursements', ([owner, employee, anyone]) => {

const assertEmployeeIsNotRemoved = (requestedAmount, expectedRequestedAmount = requestedAmount) => {
it('does not remove the employee and resets the reimbursements', async () => {
const previousReimbursements = (await payroll.getEmployee(employeeId))[3]
const previousReimbursements = (await payroll.getEmployee(employeeId))[4]
await payroll.payday(PAYMENT_TYPES.REIMBURSEMENT, requestedAmount, { from })

const [address, employeeSalary, _, reimbursements] = await payroll.getEmployee(employeeId)
const [address, employeeSalary, , , reimbursements] = await payroll.getEmployee(employeeId)

assert.equal(address, employee, 'employee address does not match')
assert.equal(employeeSalary.toString(), salary.toString(), 'employee salary does not match')
@@ -116,13 +116,13 @@ contract('Payroll employees termination', ([owner, employee, anyone]) => {
const receipt = await payroll.addEmployee(employee, salary, await payroll.getTimestampPublic(), 'Boss')
const newEmployeeId = getEventArgument(receipt, 'AddEmployee', 'employeeId')

const [address, employeeSalary, bonus, reimbursements, accruedSalary, lastPayroll, date] = await payroll.getEmployee(newEmployeeId)
const [address, employeeSalary, accruedSalary, bonus, reimbursements, lastPayroll, date] = await payroll.getEmployee(newEmployeeId)
assert.equal(address, employee, 'employee account does not match')
assert.equal(employeeSalary.toString(), salary.toString(), 'employee salary does not match')
assert.equal(lastPayroll.toString(), (await currentTimestamp()).toString(), 'employee last payroll date does not match')
assert.equal(accruedSalary.toString(), 0, 'employee accrued salary does not match')
assert.equal(bonus.toString(), 0, 'employee bonus does not match')
assert.equal(reimbursements.toString(), 0, 'employee reimbursements does not match')
assert.equal(accruedSalary.toString(), 0, 'employee accrued salary does not match')
assert.equal(lastPayroll.toString(), (await currentTimestamp()).toString(), 'employee last payroll date does not match')
assert.equal(date.toString(), MAX_UINT64, 'employee end date does not match')
})
})

0 comments on commit 094116b

Please sign in to comment.
You can’t perform that action at this time.