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

feat(Payroll): include exchange rate used in SendPayment event #830

Merged
merged 2 commits into from
Apr 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions future-apps/payroll/contracts/Payroll.sol
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ contract Payroll is EtherTokenConstant, IForwarder, IsContract, AragonApp {
event TerminateEmployee(uint256 indexed employeeId, address indexed accountAddress, uint64 endDate);
event ChangeAddressByEmployee(uint256 indexed employeeId, address indexed oldAddress, address indexed newAddress);
event DetermineAllocation(uint256 indexed employeeId, address indexed employee);
event SendPayment(address indexed employee, address indexed token, uint256 amount, string paymentReference);
event SendPayment(address indexed employee, address indexed token, uint256 amount, uint128 exchangeRate, string paymentReference);
event SetPriceFeed(address indexed feed);
event SetRateExpiryTime(uint64 time);
event AddEmployee(
Expand Down Expand Up @@ -710,7 +710,7 @@ contract Payroll is EtherTokenConstant, IForwarder, IsContract, AragonApp {
tokenAmount = tokenAmount / (100 * ONE);

finance.newImmediatePayment(token, employeeAddress, tokenAmount, paymentReference);
emit SendPayment(employeeAddress, token, tokenAmount, paymentReference);
emit SendPayment(employeeAddress, token, tokenAmount, exchangeRate, paymentReference);
somethingPaid = true;
}
}
Expand Down
6 changes: 4 additions & 2 deletions future-apps/payroll/test/contracts/Payroll_bonuses.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { getEvents, getEventArgument } = require('../helpers/events')
const { NOW, ONE_MONTH, RATE_EXPIRATION_TIME } = require('../helpers/time')
const { bn, bigExp, annualSalaryPerSecond, ONE, MAX_UINT256 } = require('../helpers/numbers')(web3)
const { deployContracts, createPayrollAndPriceFeed } = require('../helpers/deploy')(artifacts, web3)
const { USD, DAI_RATE, ANT_RATE, exchangedAmount, deployDAI, deployANT, setTokenRates } = require('../helpers/tokens')(artifacts, web3)
const { USD, DAI_RATE, ANT_RATE, inverseRate, exchangedAmount, deployDAI, deployANT, setTokenRates } = require('../helpers/tokens')(artifacts, web3)

contract('Payroll bonuses', ([owner, employee, anyone]) => {
let dao, payroll, payrollBase, finance, vault, priceFeed, DAI, ANT
Expand Down Expand Up @@ -198,19 +198,21 @@ contract('Payroll bonuses', ([owner, employee, anyone]) => {
it('emits one event per allocated token', async () => {
const receipt = await payroll.payday(PAYMENT_TYPES.BONUS, requestedAmount, { from })

const events = receipt.logs.filter(l => l.event === 'SendPayment')
const events = getEvents(receipt, 'SendPayment')
assert.equal(events.length, 2, 'should have emitted two events')

const eventDAI = events.find(e => e.args.token === DAI.address).args
assert.equal(eventDAI.employee, employee, 'employee address does not match')
assert.equal(eventDAI.token, DAI.address, 'DAI address does not match')
assert.equal(eventDAI.amount.toString(), requestedDAI, 'payment amount does not match')
assert.equal(eventDAI.exchangeRate.toString(), inverseRate(DAI_RATE).toString(), 'payment exchange rate does not match')
assert.equal(eventDAI.paymentReference, 'Bonus', 'payment reference does not match')

const eventANT = events.find(e => e.args.token === ANT.address).args
assert.equal(eventANT.employee, employee, 'employee address does not match')
assert.equal(eventANT.token, ANT.address, 'token address does not match')
assert.equal(eventANT.amount.toString(), requestedANT, 'payment amount does not match')
assert.equal(eventANT.exchangeRate.toString(), inverseRate(ANT_RATE).toString(), 'payment exchange rate does not match')
assert.equal(eventANT.paymentReference, 'Bonus', 'payment reference does not match')
})
}
Expand Down
4 changes: 3 additions & 1 deletion future-apps/payroll/test/contracts/Payroll_payday.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { getEventArgument } = require('../helpers/events')
const { bn, ONE, MAX_UINT256, bigExp } = require('../helpers/numbers')(web3)
const { NOW, ONE_MONTH, TWO_MONTHS, RATE_EXPIRATION_TIME } = require('../helpers/time')
const { deployContracts, createPayrollAndPriceFeed } = require('../helpers/deploy')(artifacts, web3)
const { USD, DAI_RATE, ANT_RATE, exchangedAmount, deployDAI, deployANT, setTokenRates } = require('../helpers/tokens')(artifacts, web3)
const { USD, DAI_RATE, ANT_RATE, inverseRate, exchangedAmount, deployDAI, deployANT, setTokenRates } = require('../helpers/tokens')(artifacts, web3)

contract('Payroll payday', ([owner, employee, anyone]) => {
let dao, payroll, payrollBase, finance, vault, priceFeed, DAI, ANT
Expand Down Expand Up @@ -85,12 +85,14 @@ contract('Payroll payday', ([owner, employee, anyone]) => {
assert.equal(eventDAI.employee, employee, 'employee address does not match')
assert.equal(eventDAI.token, DAI.address, 'DAI address does not match')
assert.equal(eventDAI.amount.toString(), requestedDAI.toString(), 'payment amount does not match')
assert.equal(eventDAI.exchangeRate.toString(), inverseRate(DAI_RATE).toString(), 'payment exchange rate does not match')
assert.equal(eventDAI.paymentReference, 'Payroll', 'payment reference does not match')

const eventANT = events.find(e => e.args.token === ANT.address).args
assert.equal(eventANT.employee, employee, 'employee address does not match')
assert.equal(eventANT.token, ANT.address, 'ANT address does not match')
assert.equal(eventANT.amount.toString(), requestedANT.toString(), 'payment amount does not match')
assert.equal(eventANT.exchangeRate.toString(), inverseRate(ANT_RATE).toString(), 'payment exchange rate does not match')
assert.equal(eventANT.paymentReference, 'Payroll', 'payment reference does not match')
})

Expand Down
Loading