You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
2.0 KiB
60 lines
2.0 KiB
7 years ago
|
const BigNumber = web3.BigNumber;
|
||
8 years ago
|
|
||
|
require('chai')
|
||
|
.use(require('chai-as-promised'))
|
||
|
.use(require('chai-bignumber')(BigNumber))
|
||
7 years ago
|
.should();
|
||
8 years ago
|
|
||
7 years ago
|
import ether from './helpers/ether';
|
||
|
import EVMRevert from './helpers/EVMRevert';
|
||
8 years ago
|
|
||
7 years ago
|
const RefundVault = artifacts.require('RefundVault');
|
||
8 years ago
|
|
||
|
contract('RefundVault', function ([_, owner, wallet, investor]) {
|
||
7 years ago
|
const value = ether(42);
|
||
8 years ago
|
|
||
|
beforeEach(async function () {
|
||
7 years ago
|
this.vault = await RefundVault.new(wallet, { from: owner });
|
||
|
});
|
||
8 years ago
|
|
||
|
it('should accept contributions', async function () {
|
||
7 years ago
|
await this.vault.deposit(investor, { value, from: owner }).should.be.fulfilled;
|
||
|
});
|
||
8 years ago
|
|
||
|
it('should not refund contribution during active state', async function () {
|
||
7 years ago
|
await this.vault.deposit(investor, { value, from: owner });
|
||
|
await this.vault.refund(investor).should.be.rejectedWith(EVMRevert);
|
||
|
});
|
||
8 years ago
|
|
||
|
it('only owner can enter refund mode', async function () {
|
||
7 years ago
|
await this.vault.enableRefunds({ from: _ }).should.be.rejectedWith(EVMRevert);
|
||
|
await this.vault.enableRefunds({ from: owner }).should.be.fulfilled;
|
||
|
});
|
||
8 years ago
|
|
||
|
it('should refund contribution after entering refund mode', async function () {
|
||
7 years ago
|
await this.vault.deposit(investor, { value, from: owner });
|
||
|
await this.vault.enableRefunds({ from: owner });
|
||
8 years ago
|
|
||
7 years ago
|
const pre = web3.eth.getBalance(investor);
|
||
|
await this.vault.refund(investor);
|
||
|
const post = web3.eth.getBalance(investor);
|
||
8 years ago
|
|
||
7 years ago
|
post.minus(pre).should.be.bignumber.equal(value);
|
||
|
});
|
||
8 years ago
|
|
||
|
it('only owner can close', async function () {
|
||
7 years ago
|
await this.vault.close({ from: _ }).should.be.rejectedWith(EVMRevert);
|
||
|
await this.vault.close({ from: owner }).should.be.fulfilled;
|
||
|
});
|
||
8 years ago
|
|
||
|
it('should forward funds to wallet after closing', async function () {
|
||
7 years ago
|
await this.vault.deposit(investor, { value, from: owner });
|
||
8 years ago
|
|
||
7 years ago
|
const pre = web3.eth.getBalance(wallet);
|
||
|
await this.vault.close({ from: owner });
|
||
|
const post = web3.eth.getBalance(wallet);
|
||
8 years ago
|
|
||
7 years ago
|
post.minus(pre).should.be.bignumber.equal(value);
|
||
|
});
|
||
|
});
|