|
@@ -8,20 +8,20 @@ const { expect } = require('chai');
|
|
|
const RefundEscrow = contract.fromArtifact('RefundEscrow');
|
|
|
|
|
|
describe('RefundEscrow', function () {
|
|
|
- const [ primary, beneficiary, refundee1, refundee2 ] = accounts;
|
|
|
+ const [ owner, beneficiary, refundee1, refundee2 ] = accounts;
|
|
|
|
|
|
const amount = ether('54');
|
|
|
const refundees = [refundee1, refundee2];
|
|
|
|
|
|
it('requires a non-null beneficiary', async function () {
|
|
|
await expectRevert(
|
|
|
- RefundEscrow.new(ZERO_ADDRESS, { from: primary }), 'RefundEscrow: beneficiary is the zero address'
|
|
|
+ RefundEscrow.new(ZERO_ADDRESS, { from: owner }), 'RefundEscrow: beneficiary is the zero address'
|
|
|
);
|
|
|
});
|
|
|
|
|
|
context('once deployed', function () {
|
|
|
beforeEach(async function () {
|
|
|
- this.escrow = await RefundEscrow.new(beneficiary, { from: primary });
|
|
|
+ this.escrow = await RefundEscrow.new(beneficiary, { from: owner });
|
|
|
});
|
|
|
|
|
|
context('active state', function () {
|
|
@@ -31,44 +31,44 @@ describe('RefundEscrow', function () {
|
|
|
});
|
|
|
|
|
|
it('accepts deposits', async function () {
|
|
|
- await this.escrow.deposit(refundee1, { from: primary, value: amount });
|
|
|
+ await this.escrow.deposit(refundee1, { from: owner, value: amount });
|
|
|
|
|
|
expect(await this.escrow.depositsOf(refundee1)).to.be.bignumber.equal(amount);
|
|
|
});
|
|
|
|
|
|
it('does not refund refundees', async function () {
|
|
|
- await this.escrow.deposit(refundee1, { from: primary, value: amount });
|
|
|
+ await this.escrow.deposit(refundee1, { from: owner, value: amount });
|
|
|
await expectRevert(this.escrow.withdraw(refundee1),
|
|
|
'ConditionalEscrow: payee is not allowed to withdraw'
|
|
|
);
|
|
|
});
|
|
|
|
|
|
it('does not allow beneficiary withdrawal', async function () {
|
|
|
- await this.escrow.deposit(refundee1, { from: primary, value: amount });
|
|
|
+ await this.escrow.deposit(refundee1, { from: owner, value: amount });
|
|
|
await expectRevert(this.escrow.beneficiaryWithdraw(),
|
|
|
'RefundEscrow: beneficiary can only withdraw while closed'
|
|
|
);
|
|
|
});
|
|
|
});
|
|
|
|
|
|
- it('only the primary account can enter closed state', async function () {
|
|
|
+ it('only the owner can enter closed state', async function () {
|
|
|
await expectRevert(this.escrow.close({ from: beneficiary }),
|
|
|
- 'Secondary: caller is not the primary account'
|
|
|
+ 'Ownable: caller is not the owner'
|
|
|
);
|
|
|
|
|
|
- const { logs } = await this.escrow.close({ from: primary });
|
|
|
+ const { logs } = await this.escrow.close({ from: owner });
|
|
|
expectEvent.inLogs(logs, 'RefundsClosed');
|
|
|
});
|
|
|
|
|
|
context('closed state', function () {
|
|
|
beforeEach(async function () {
|
|
|
- await Promise.all(refundees.map(refundee => this.escrow.deposit(refundee, { from: primary, value: amount })));
|
|
|
+ await Promise.all(refundees.map(refundee => this.escrow.deposit(refundee, { from: owner, value: amount })));
|
|
|
|
|
|
- await this.escrow.close({ from: primary });
|
|
|
+ await this.escrow.close({ from: owner });
|
|
|
});
|
|
|
|
|
|
it('rejects deposits', async function () {
|
|
|
- await expectRevert(this.escrow.deposit(refundee1, { from: primary, value: amount }),
|
|
|
+ await expectRevert(this.escrow.deposit(refundee1, { from: owner, value: amount }),
|
|
|
'RefundEscrow: can only deposit while active'
|
|
|
);
|
|
|
});
|
|
@@ -86,36 +86,36 @@ describe('RefundEscrow', function () {
|
|
|
});
|
|
|
|
|
|
it('prevents entering the refund state', async function () {
|
|
|
- await expectRevert(this.escrow.enableRefunds({ from: primary }),
|
|
|
+ await expectRevert(this.escrow.enableRefunds({ from: owner }),
|
|
|
'RefundEscrow: can only enable refunds while active'
|
|
|
);
|
|
|
});
|
|
|
|
|
|
it('prevents re-entering the closed state', async function () {
|
|
|
- await expectRevert(this.escrow.close({ from: primary }),
|
|
|
+ await expectRevert(this.escrow.close({ from: owner }),
|
|
|
'RefundEscrow: can only close while active'
|
|
|
);
|
|
|
});
|
|
|
});
|
|
|
|
|
|
- it('only the primary account can enter refund state', async function () {
|
|
|
+ it('only the owner can enter refund state', async function () {
|
|
|
await expectRevert(this.escrow.enableRefunds({ from: beneficiary }),
|
|
|
- 'Secondary: caller is not the primary account'
|
|
|
+ 'Ownable: caller is not the owner'
|
|
|
);
|
|
|
|
|
|
- const { logs } = await this.escrow.enableRefunds({ from: primary });
|
|
|
+ const { logs } = await this.escrow.enableRefunds({ from: owner });
|
|
|
expectEvent.inLogs(logs, 'RefundsEnabled');
|
|
|
});
|
|
|
|
|
|
context('refund state', function () {
|
|
|
beforeEach(async function () {
|
|
|
- await Promise.all(refundees.map(refundee => this.escrow.deposit(refundee, { from: primary, value: amount })));
|
|
|
+ await Promise.all(refundees.map(refundee => this.escrow.deposit(refundee, { from: owner, value: amount })));
|
|
|
|
|
|
- await this.escrow.enableRefunds({ from: primary });
|
|
|
+ await this.escrow.enableRefunds({ from: owner });
|
|
|
});
|
|
|
|
|
|
it('rejects deposits', async function () {
|
|
|
- await expectRevert(this.escrow.deposit(refundee1, { from: primary, value: amount }),
|
|
|
+ await expectRevert(this.escrow.deposit(refundee1, { from: owner, value: amount }),
|
|
|
'RefundEscrow: can only deposit while active'
|
|
|
);
|
|
|
});
|
|
@@ -123,7 +123,7 @@ describe('RefundEscrow', function () {
|
|
|
it('refunds refundees', async function () {
|
|
|
for (const refundee of [refundee1, refundee2]) {
|
|
|
const balanceTracker = await balance.tracker(refundee);
|
|
|
- await this.escrow.withdraw(refundee, { from: primary });
|
|
|
+ await this.escrow.withdraw(refundee, { from: owner });
|
|
|
expect(await balanceTracker.delta()).to.be.bignumber.equal(amount);
|
|
|
}
|
|
|
});
|
|
@@ -135,13 +135,13 @@ describe('RefundEscrow', function () {
|
|
|
});
|
|
|
|
|
|
it('prevents entering the closed state', async function () {
|
|
|
- await expectRevert(this.escrow.close({ from: primary }),
|
|
|
+ await expectRevert(this.escrow.close({ from: owner }),
|
|
|
'RefundEscrow: can only close while active'
|
|
|
);
|
|
|
});
|
|
|
|
|
|
it('prevents re-entering the refund state', async function () {
|
|
|
- await expectRevert(this.escrow.enableRefunds({ from: primary }),
|
|
|
+ await expectRevert(this.escrow.enableRefunds({ from: owner }),
|
|
|
'RefundEscrow: can only enable refunds while active'
|
|
|
);
|
|
|
});
|