Skip to content

Commit e6e48ac

Browse files
authored
Merge pull request #106 from Havven/queue-check
Changed mechanism for struct initialisation.
2 parents 22ca406 + 9c4894e commit e6e48ac

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

contracts/Depot.sol

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,9 @@ contract Depot is SelfDestructible, Pausable {
296296
// Ok, this deposit can fulfill the whole remainder. We don't need
297297
// to change anything about our queue we can just fulfill it.
298298
// Subtract the amount from our deposit and total.
299-
deposit.amount = deposit.amount.sub(remainingToFulfill);
299+
uint newAmount = deposit.amount.sub(remainingToFulfill);
300+
deposits[i] = synthDeposit({ user: deposit.user, amount: newAmount});
301+
300302
totalSellableDeposits = totalSellableDeposits.sub(remainingToFulfill);
301303

302304
// Transfer the ETH to the depositor. Send is used instead of transfer

test/Depot.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,55 @@ contract('Depot', async function(accounts) {
495495
);
496496
});
497497

498+
it('is less than one deposit (and that the queue is correctly updated)', async function() {
499+
const synthsToDeposit = toUnit('500');
500+
const ethToSend = toUnit('0.5');
501+
502+
// Send the synths to the Token Depot.
503+
await synth.transferSenderPaysFee(depot.address, synthsToDeposit, {
504+
from: depositor,
505+
});
506+
507+
const depositStartIndex = await depot.depositStartIndex();
508+
const depositEndIndex = await depot.depositEndIndex();
509+
510+
// Assert that there is now one deposit in the queue.
511+
assert.equal(depositStartIndex, 0);
512+
assert.equal(depositEndIndex, 1);
513+
514+
// And assert that our total has increased by the right amount.
515+
const totalSellableDeposits = await depot.totalSellableDeposits();
516+
assert.bnEqual(totalSellableDeposits, synthsToDeposit);
517+
518+
assert.bnEqual(await depot.totalSellableDeposits(), (await depot.deposits(0)).amount);
519+
520+
// Now purchase some.
521+
const txn = await depot.exchangeEtherForSynths({
522+
from: purchaser,
523+
value: ethToSend,
524+
});
525+
526+
// Exchange("ETH", msg.value, "sUSD", fulfilled);
527+
const exchangeEvent = txn.logs.find(log => log.event === 'Exchange');
528+
assert.eventEqual(exchangeEvent, 'Exchange', {
529+
fromCurrency: 'ETH',
530+
fromAmount: ethToSend,
531+
toCurrency: 'sUSD',
532+
toAmount: synthsToDeposit.div(web3.utils.toBN('2')),
533+
});
534+
535+
// We should have one deposit in the queue with half the amount
536+
assert.equal(await depot.depositStartIndex(), 0);
537+
assert.equal(await depot.depositEndIndex(), 1);
538+
539+
assert.bnEqual(await depot.totalSellableDeposits(), (await depot.deposits(0)).amount);
540+
541+
assert.bnEqual(
542+
await depot.totalSellableDeposits(),
543+
synthsToDeposit.div(web3.utils.toBN('2'))
544+
);
545+
});
546+
498547
it('exceeds one deposit (and that the queue is correctly updated)', async function() {
499548
const synthsToDeposit = web3.utils.toWei('600');
500549
const totalSynthsDeposit = web3.utils.toWei('1200');

0 commit comments

Comments
 (0)