Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Payroll: Support employees bonus #775

Merged
merged 2 commits into from Apr 16, 2019
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -88,8 +88,9 @@ contract('Payroll employees addition', ([owner, employee, anotherEmployee, anyon
assert.equal(event.startDate.toString(), (await currentTimestamp()).toString(), 'employee start date does not match')
assert.equal(event.initialDenominationSalary.toString(), anotherSalary.toString(), 'employee salary does not match')

const [address, employeeSalary, accruedValue, accruedSalary, lastPayroll, endDate] = await payroll.getEmployee(anotherEmployeeId)
const [address, employeeSalary, bonus, accruedValue, accruedSalary, lastPayroll, endDate] = await payroll.getEmployee(anotherEmployeeId)
assert.equal(address, anotherEmployee, 'employee account does not match')
assert.equal(bonus.toString(), 0, 'employee bonus does not match')
assert.equal(accruedValue, 0, 'employee accrued value does not match')
assert.equal(accruedSalary, 0, 'employee accrued salary does not match')
assert.equal(employeeSalary.toString(), anotherSalary.toString(), 'employee salary does not match')
@@ -195,8 +196,9 @@ contract('Payroll employees addition', ([owner, employee, anotherEmployee, anyon
assert.equal(event.startDate.toString(), startDate, 'employee start date does not match')
assert.equal(event.initialDenominationSalary.toString(), anotherSalary.toString(), 'employee salary does not match')

const [address, employeeSalary, accruedValue, accruedSalary, lastPayroll, endDate] = await payroll.getEmployee(anotherEmployeeId)
const [address, employeeSalary, bonus, accruedValue, accruedSalary, 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(accruedValue, 0, 'employee accrued value does not match')
assert.equal(accruedSalary, 0, 'employee accrued salary does not match')
assert.equal(employeeSalary.toString(), anotherSalary.toString(), 'employee salary does not match')
@@ -14,6 +14,7 @@ contract('Payroll allowed tokens,', ([owner, employee, anotherEmployee, anyone])
const RATE_EXPIRATION_TIME = TWO_MONTHS

const TOKEN_DECIMALS = 18
const PAYROLL_PAYMENT_TYPE = 0

before('setup base apps and tokens', async () => {
({ dao, finance, vault, priceFeed, payrollBase } = await deployContracts(owner))
@@ -101,7 +102,7 @@ contract('Payroll allowed tokens,', ([owner, employee, anotherEmployee, anyone])
const allocationTx = await payroll.determineAllocation(tokenAddresses, allocations, { from: employee })
assert.isBelow(allocationTx.receipt.cumulativeGasUsed, MAX_GAS_USED, 'Too much gas consumed for allocation')

const paydayTx = await payroll.payday({ from: employee })
const paydayTx = await payroll.payday(PAYROLL_PAYMENT_TYPE, 0, { from: employee })
assert.isBelow(paydayTx.receipt.cumulativeGasUsed, MAX_GAS_USED, 'Too much gas consumed for payday')
})
})

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -10,6 +10,7 @@ contract('Payroll gas costs', ([owner, employee, anotherEmployee]) => {
const RATE_EXPIRATION_TIME = TWO_MONTHS

const TOKEN_DECIMALS = 18
const PAYROLL_PAYMENT_TYPE = 0

before('setup base apps and tokens', async () => {
({ dao, finance, vault, priceFeed, payrollBase } = await deployContracts(owner))
@@ -45,7 +46,7 @@ contract('Payroll gas costs', ([owner, employee, anotherEmployee]) => {
await payroll.addAllowedToken(denominationToken.address)
await payroll.determineAllocation([denominationToken.address], [100], { from: employee })

const { receipt: { cumulativeGasUsed } } = await payroll.payday({ from: employee })
const { receipt: { cumulativeGasUsed } } = await payroll.payday(PAYROLL_PAYMENT_TYPE, 0, { from: employee })

assert.isBelow(cumulativeGasUsed, 317000, 'payout gas cost for a single allowed token should be ~314k')
})
@@ -60,10 +61,10 @@ contract('Payroll gas costs', ([owner, employee, anotherEmployee]) => {

it('expends ~270k gas per allowed token', async () => {
await payroll.determineAllocation([denominationToken.address, erc20Token1.address], [60, 40], { from: employee })
const { receipt: { cumulativeGasUsed: employeePayoutGasUsed } } = await payroll.payday({ from: employee })
const { receipt: { cumulativeGasUsed: employeePayoutGasUsed } } = await payroll.payday(PAYROLL_PAYMENT_TYPE, 0, { from: employee })

await payroll.determineAllocation([denominationToken.address, erc20Token1.address, erc20Token2.address], [65, 25, 10], { from: anotherEmployee })
const { receipt: { cumulativeGasUsed: anotherEmployeePayoutGasUsed } } = await payroll.payday({ from: anotherEmployee })
const { receipt: { cumulativeGasUsed: anotherEmployeePayoutGasUsed } } = await payroll.payday(PAYROLL_PAYMENT_TYPE, 0, { from: anotherEmployee })

const gasPerAllowedToken = anotherEmployeePayoutGasUsed - employeePayoutGasUsed
assert.isBelow(gasPerAllowedToken, 280000, 'payout gas cost increment per allowed token should be ~270k')
@@ -41,9 +41,10 @@ contract('Payroll employee getters', ([owner, employee]) => {
})

it('adds a new employee', async () => {
const [address, salary, accruedValue, accruedSalary, lastPayroll, endDate] = await payroll.getEmployee(employeeId)
const [address, salary, bonus, accruedValue, accruedSalary, 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(accruedValue, 0, 'employee accrued value does not match')
assert.equal(accruedSalary, 0, 'employee accrued salary does not match')
assert.equal(salary.toString(), 1000, 'employee salary does not match')
@@ -86,10 +87,11 @@ contract('Payroll employee getters', ([owner, employee]) => {
})

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

assert.equal(id.toString(), employeeId.toString(), 'employee id does not match')
assert.equal(salary.toString(), 1000, 'employee salary does not match')
assert.equal(bonus.toString(), 0, 'employee bonus does not match')
assert.equal(accruedValue.toString(), 0, 'employee accrued value 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')
@@ -60,7 +60,7 @@ contract('Payroll employees modification', ([owner, employee, anotherEmployee, a
const receipt = await payroll.setEmployeeSalary(employeeId, newSalary, { from })
await payroll.mockAddTimestamp(ONE_MONTH)

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

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

const accruedSalary = (await payroll.getEmployee(employeeId))[3]
const accruedSalary = (await payroll.getEmployee(employeeId))[4]
const expectedAccruedSalary = previousSalary * ONE_MONTH + newSalary * ONE_MONTH
assert.equal(accruedSalary.toString(), expectedAccruedSalary, 'accrued salary does not match')
})
Oops, something went wrong.
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.