|
@@ -14,93 +14,118 @@ const RefundEscrow = artifacts.require('RefundEscrow');
|
|
|
contract('RefundEscrow', function ([_, owner, beneficiary, refundee1, refundee2]) {
|
|
|
const amount = web3.toWei(54.0, 'ether');
|
|
|
const refundees = [refundee1, refundee2];
|
|
|
+ const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';
|
|
|
|
|
|
- beforeEach(async function () {
|
|
|
- this.escrow = await RefundEscrow.new(beneficiary, { from: owner });
|
|
|
+ it('requires a non-null beneficiary', async function () {
|
|
|
+ await expectThrow(
|
|
|
+ RefundEscrow.new(ZERO_ADDRESS, { from: owner })
|
|
|
+ );
|
|
|
});
|
|
|
|
|
|
- context('active state', function () {
|
|
|
- it('accepts deposits', async function () {
|
|
|
- await this.escrow.deposit(refundee1, { from: owner, value: amount });
|
|
|
-
|
|
|
- const deposit = await this.escrow.depositsOf(refundee1);
|
|
|
- deposit.should.be.bignumber.equal(amount);
|
|
|
+ context('once deployed', function () {
|
|
|
+ beforeEach(async function () {
|
|
|
+ this.escrow = await RefundEscrow.new(beneficiary, { from: owner });
|
|
|
});
|
|
|
|
|
|
- it('does not refund refundees', async function () {
|
|
|
- await this.escrow.deposit(refundee1, { from: owner, value: amount });
|
|
|
- await expectThrow(this.escrow.withdraw(refundee1), EVMRevert);
|
|
|
+ context('active state', function () {
|
|
|
+ it('accepts deposits', async function () {
|
|
|
+ await this.escrow.deposit(refundee1, { from: owner, value: amount });
|
|
|
+
|
|
|
+ const deposit = await this.escrow.depositsOf(refundee1);
|
|
|
+ deposit.should.be.bignumber.equal(amount);
|
|
|
+ });
|
|
|
+
|
|
|
+ it('does not refund refundees', async function () {
|
|
|
+ await this.escrow.deposit(refundee1, { from: owner, value: amount });
|
|
|
+ await expectThrow(this.escrow.withdraw(refundee1), EVMRevert);
|
|
|
+ });
|
|
|
+
|
|
|
+ it('does not allow beneficiary withdrawal', async function () {
|
|
|
+ await this.escrow.deposit(refundee1, { from: owner, value: amount });
|
|
|
+ await expectThrow(this.escrow.beneficiaryWithdraw(), EVMRevert);
|
|
|
+ });
|
|
|
});
|
|
|
|
|
|
- it('does not allow beneficiary withdrawal', async function () {
|
|
|
- await this.escrow.deposit(refundee1, { from: owner, value: amount });
|
|
|
- await expectThrow(this.escrow.beneficiaryWithdraw(), EVMRevert);
|
|
|
+ it('only owner can enter closed state', async function () {
|
|
|
+ await expectThrow(this.escrow.close({ from: beneficiary }), EVMRevert);
|
|
|
+
|
|
|
+ const receipt = await this.escrow.close({ from: owner });
|
|
|
+
|
|
|
+ expectEvent.inLogs(receipt.logs, 'Closed');
|
|
|
});
|
|
|
- });
|
|
|
|
|
|
- it('only owner can enter closed state', async function () {
|
|
|
- await expectThrow(this.escrow.close({ from: beneficiary }), EVMRevert);
|
|
|
+ context('closed state', function () {
|
|
|
+ beforeEach(async function () {
|
|
|
+ await Promise.all(refundees.map(refundee => this.escrow.deposit(refundee, { from: owner, value: amount })));
|
|
|
|
|
|
- const receipt = await this.escrow.close({ from: owner });
|
|
|
+ await this.escrow.close({ from: owner });
|
|
|
+ });
|
|
|
|
|
|
- expectEvent.inLogs(receipt.logs, 'Closed');
|
|
|
- });
|
|
|
+ it('rejects deposits', async function () {
|
|
|
+ await expectThrow(this.escrow.deposit(refundee1, { from: owner, value: amount }), EVMRevert);
|
|
|
+ });
|
|
|
|
|
|
- context('closed state', function () {
|
|
|
- beforeEach(async function () {
|
|
|
- await Promise.all(refundees.map(refundee => this.escrow.deposit(refundee, { from: owner, value: amount })));
|
|
|
+ it('does not refund refundees', async function () {
|
|
|
+ await expectThrow(this.escrow.withdraw(refundee1), EVMRevert);
|
|
|
+ });
|
|
|
|
|
|
- await this.escrow.close({ from: owner });
|
|
|
- });
|
|
|
+ it('allows beneficiary withdrawal', async function () {
|
|
|
+ const beneficiaryInitialBalance = await ethGetBalance(beneficiary);
|
|
|
+ await this.escrow.beneficiaryWithdraw();
|
|
|
+ const beneficiaryFinalBalance = await ethGetBalance(beneficiary);
|
|
|
|
|
|
- it('rejects deposits', async function () {
|
|
|
- await expectThrow(this.escrow.deposit(refundee1, { from: owner, value: amount }), EVMRevert);
|
|
|
- });
|
|
|
+ beneficiaryFinalBalance.sub(beneficiaryInitialBalance).should.be.bignumber.equal(amount * refundees.length);
|
|
|
+ });
|
|
|
+
|
|
|
+ it('prevents entering the refund state', async function () {
|
|
|
+ await expectThrow(this.escrow.enableRefunds({ from: owner }), EVMRevert);
|
|
|
+ });
|
|
|
|
|
|
- it('does not refund refundees', async function () {
|
|
|
- await expectThrow(this.escrow.withdraw(refundee1), EVMRevert);
|
|
|
+ it('prevents re-entering the closed state', async function () {
|
|
|
+ await expectThrow(this.escrow.close({ from: owner }), EVMRevert);
|
|
|
+ });
|
|
|
});
|
|
|
|
|
|
- it('allows beneficiary withdrawal', async function () {
|
|
|
- const beneficiaryInitialBalance = await ethGetBalance(beneficiary);
|
|
|
- await this.escrow.beneficiaryWithdraw();
|
|
|
- const beneficiaryFinalBalance = await ethGetBalance(beneficiary);
|
|
|
+ it('only owner can enter refund state', async function () {
|
|
|
+ await expectThrow(this.escrow.enableRefunds({ from: beneficiary }), EVMRevert);
|
|
|
|
|
|
- beneficiaryFinalBalance.sub(beneficiaryInitialBalance).should.be.bignumber.equal(amount * refundees.length);
|
|
|
- });
|
|
|
- });
|
|
|
+ const receipt = await this.escrow.enableRefunds({ from: owner });
|
|
|
|
|
|
- it('only owner can enter refund state', async function () {
|
|
|
- await expectThrow(this.escrow.enableRefunds({ from: beneficiary }), EVMRevert);
|
|
|
+ expectEvent.inLogs(receipt.logs, 'RefundsEnabled');
|
|
|
+ });
|
|
|
|
|
|
- const receipt = await this.escrow.enableRefunds({ from: owner });
|
|
|
+ context('refund state', function () {
|
|
|
+ beforeEach(async function () {
|
|
|
+ await Promise.all(refundees.map(refundee => this.escrow.deposit(refundee, { from: owner, value: amount })));
|
|
|
|
|
|
- expectEvent.inLogs(receipt.logs, 'RefundsEnabled');
|
|
|
- });
|
|
|
+ await this.escrow.enableRefunds({ from: owner });
|
|
|
+ });
|
|
|
|
|
|
- context('refund state', function () {
|
|
|
- beforeEach(async function () {
|
|
|
- await Promise.all(refundees.map(refundee => this.escrow.deposit(refundee, { from: owner, value: amount })));
|
|
|
+ it('rejects deposits', async function () {
|
|
|
+ await expectThrow(this.escrow.deposit(refundee1, { from: owner, value: amount }), EVMRevert);
|
|
|
+ });
|
|
|
|
|
|
- await this.escrow.enableRefunds({ from: owner });
|
|
|
- });
|
|
|
+ it('refunds refundees', async function () {
|
|
|
+ for (const refundee of [refundee1, refundee2]) {
|
|
|
+ const refundeeInitialBalance = await ethGetBalance(refundee);
|
|
|
+ await this.escrow.withdraw(refundee, { from: owner });
|
|
|
+ const refundeeFinalBalance = await ethGetBalance(refundee);
|
|
|
|
|
|
- it('rejects deposits', async function () {
|
|
|
- await expectThrow(this.escrow.deposit(refundee1, { from: owner, value: amount }), EVMRevert);
|
|
|
- });
|
|
|
+ refundeeFinalBalance.sub(refundeeInitialBalance).should.be.bignumber.equal(amount);
|
|
|
+ }
|
|
|
+ });
|
|
|
|
|
|
- it('refunds refundees', async function () {
|
|
|
- for (const refundee of [refundee1, refundee2]) {
|
|
|
- const refundeeInitialBalance = await ethGetBalance(refundee);
|
|
|
- await this.escrow.withdraw(refundee, { from: owner });
|
|
|
- const refundeeFinalBalance = await ethGetBalance(refundee);
|
|
|
+ it('does not allow beneficiary withdrawal', async function () {
|
|
|
+ await expectThrow(this.escrow.beneficiaryWithdraw(), EVMRevert);
|
|
|
+ });
|
|
|
|
|
|
- refundeeFinalBalance.sub(refundeeInitialBalance).should.be.bignumber.equal(amount);
|
|
|
- }
|
|
|
- });
|
|
|
+ it('prevents entering the closed state', async function () {
|
|
|
+ await expectThrow(this.escrow.close({ from: owner }), EVMRevert);
|
|
|
+ });
|
|
|
|
|
|
- it('does not allow beneficiary withdrawal', async function () {
|
|
|
- await expectThrow(this.escrow.beneficiaryWithdraw(), EVMRevert);
|
|
|
+ it('prevents re-entering the refund state', async function () {
|
|
|
+ await expectThrow(this.escrow.enableRefunds({ from: owner }), EVMRevert);
|
|
|
+ });
|
|
|
});
|
|
|
});
|
|
|
});
|