aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--packages/contracts/src/utils/assertions.ts12
-rw-r--r--packages/contracts/src/utils/constants.ts2
-rw-r--r--packages/contracts/test/ether_token.ts15
-rw-r--r--packages/contracts/test/unlimited_allowance_token.ts21
4 files changed, 29 insertions, 21 deletions
diff --git a/packages/contracts/src/utils/assertions.ts b/packages/contracts/src/utils/assertions.ts
index e3f31bf89..1e8d58b9f 100644
--- a/packages/contracts/src/utils/assertions.ts
+++ b/packages/contracts/src/utils/assertions.ts
@@ -18,3 +18,15 @@ export function expectRevertOrAlwaysFailingTransaction<T>(p: Promise<T>): Promis
);
});
}
+
+export function expectInsufficientFunds<T>(p: Promise<T>): PromiseLike<void> {
+ return expect(p)
+ .to.be.rejected()
+ .then(e => {
+ expect(e).to.satisfy(
+ (err: Error) =>
+ _.includes(err.message, 'insufficient funds') ||
+ _.includes(err.message, "sender doesn't have enough funds"),
+ );
+ });
+}
diff --git a/packages/contracts/src/utils/constants.ts b/packages/contracts/src/utils/constants.ts
index a0369c256..60f41b51b 100644
--- a/packages/contracts/src/utils/constants.ts
+++ b/packages/contracts/src/utils/constants.ts
@@ -25,6 +25,8 @@ export const constants = {
LIB_BYTES_GTE_20_LENGTH_REQUIRED: 'Length must be greater than or equal to 20.',
LIB_BYTES_GTE_32_LENGTH_REQUIRED: 'Length must be greater than or equal to 32.',
LIB_BYTES_INDEX_OUT_OF_BOUNDS: 'Specified array index is out of bounds.',
+ ERC20_INSUFFICIENT_BALANCE: 'Insufficient balance to complete transfer.',
+ ERC20_INSUFFICIENT_ALLOWANCE: 'Insufficient allowance to complete transfer.',
TESTRPC_NETWORK_ID: 50,
AWAIT_TRANSACTION_MINED_MS: 100,
MAX_ETHERTOKEN_WITHDRAW_GAS: 43000,
diff --git a/packages/contracts/test/ether_token.ts b/packages/contracts/test/ether_token.ts
index f63d143a6..ee1a0a876 100644
--- a/packages/contracts/test/ether_token.ts
+++ b/packages/contracts/test/ether_token.ts
@@ -6,6 +6,7 @@ import 'make-promises-safe';
import { WETH9Contract } from '../src/contract_wrappers/generated/weth9';
import { artifacts } from '../src/utils/artifacts';
+import { expectInsufficientFunds, expectRevertOrAlwaysFailingTransaction } from '../src/utils/assertions';
import { chaiSetup } from '../src/utils/chai_setup';
import { constants } from '../src/utils/constants';
import { provider, txDefaults, web3Wrapper } from '../src/utils/web3_wrapper';
@@ -41,14 +42,11 @@ describe('EtherToken', () => {
await blockchainLifecycle.revertAsync();
});
describe('deposit', () => {
- // TODO(albrow): AssertionError: expected promise to be rejected with an error including 'ender doesn\'t have enough funds to send tx.' but got 'insufficient funds for gas * price + value'
- it.skip('should throw if caller attempts to deposit more Ether than caller balance', async () => {
+ it('should throw if caller attempts to deposit more Ether than caller balance', async () => {
const initEthBalance = await web3Wrapper.getBalanceInWeiAsync(account);
const ethToDeposit = initEthBalance.plus(1);
- return expect(etherToken.deposit.sendTransactionAsync({ value: ethToDeposit })).to.be.rejectedWith(
- "ender doesn't have enough funds to send tx.",
- );
+ return expectInsufficientFunds(etherToken.deposit.sendTransactionAsync({ value: ethToDeposit }));
});
it('should convert deposited Ether to wrapped Ether tokens', async () => {
@@ -73,13 +71,12 @@ describe('EtherToken', () => {
});
describe('withdraw', () => {
- // TODO(albrow): AssertionError: expected promise to be rejected with an error including 'revert' but got 'gas required exceeds allowance or always failing transaction'
- it.skip('should throw if caller attempts to withdraw greater than caller balance', async () => {
+ it('should throw if caller attempts to withdraw greater than caller balance', async () => {
const initEthTokenBalance = await etherToken.balanceOf.callAsync(account);
const ethTokensToWithdraw = initEthTokenBalance.plus(1);
- return expect(etherToken.withdraw.sendTransactionAsync(ethTokensToWithdraw)).to.be.rejectedWith(
- constants.REVERT,
+ return expectRevertOrAlwaysFailingTransaction(
+ etherToken.withdraw.sendTransactionAsync(ethTokensToWithdraw),
);
});
diff --git a/packages/contracts/test/unlimited_allowance_token.ts b/packages/contracts/test/unlimited_allowance_token.ts
index 1bf29c7e9..ea20df040 100644
--- a/packages/contracts/test/unlimited_allowance_token.ts
+++ b/packages/contracts/test/unlimited_allowance_token.ts
@@ -53,12 +53,11 @@ describe('UnlimitedAllowanceToken', () => {
await blockchainLifecycle.revertAsync();
});
describe('transfer', () => {
- // TODO(albrow): AssertionError: expected promise to be rejected but it was fulfilled with true
- it.skip('should throw if owner has insufficient balance', async () => {
+ it('should throw if owner has insufficient balance', async () => {
const ownerBalance = await token.balanceOf.callAsync(owner);
const amountToTransfer = ownerBalance.plus(1);
- return expectRevertOrAlwaysFailingTransaction(
- token.transfer.callAsync(spender, amountToTransfer, { from: owner }),
+ return expect(token.transfer.callAsync(spender, amountToTransfer, { from: owner })).to.be.rejectedWith(
+ constants.ERC20_INSUFFICIENT_BALANCE,
);
});
@@ -88,23 +87,21 @@ describe('UnlimitedAllowanceToken', () => {
});
describe('transferFrom', () => {
- // TODO(albrow): AssertionError: expected promise to be rejected but it was fulfilled with true
- it.skip('should throw if owner has insufficient balance', async () => {
+ it('should throw if owner has insufficient balance', async () => {
const ownerBalance = await token.balanceOf.callAsync(owner);
const amountToTransfer = ownerBalance.plus(1);
await web3Wrapper.awaitTransactionSuccessAsync(
await token.approve.sendTransactionAsync(spender, amountToTransfer, { from: owner }),
constants.AWAIT_TRANSACTION_MINED_MS,
);
- return expectRevertOrAlwaysFailingTransaction(
+ return expect(
token.transferFrom.callAsync(owner, spender, amountToTransfer, {
from: spender,
}),
- );
+ ).to.be.rejectedWith(constants.ERC20_INSUFFICIENT_BALANCE);
});
- // TODO(albrow): AssertionError: expected promise to be rejected but it was fulfilled with true
- it.skip('should throw if spender has insufficient allowance', async () => {
+ it('should throw if spender has insufficient allowance', async () => {
const ownerBalance = await token.balanceOf.callAsync(owner);
const amountToTransfer = ownerBalance;
@@ -112,11 +109,11 @@ describe('UnlimitedAllowanceToken', () => {
const isSpenderAllowanceInsufficient = spenderAllowance.cmp(amountToTransfer) < 0;
expect(isSpenderAllowanceInsufficient).to.be.true();
- return expectRevertOrAlwaysFailingTransaction(
+ return expect(
token.transferFrom.callAsync(owner, spender, amountToTransfer, {
from: spender,
}),
- );
+ ).to.be.rejectedWith(constants.ERC20_INSUFFICIENT_ALLOWANCE);
});
it('should return true on a 0 value transfer', async () => {