From 1cc9d9c0713a56b59717498fcae6dc2720ca4fb0 Mon Sep 17 00:00:00 2001 From: Alex Browne Date: Tue, 22 May 2018 12:47:37 -0700 Subject: Replace constant.REVERT test assertions with expectRevertOrAlwaysFailingTransaction --- packages/contracts/test/unlimited_allowance_token.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'packages/contracts/test/unlimited_allowance_token.ts') diff --git a/packages/contracts/test/unlimited_allowance_token.ts b/packages/contracts/test/unlimited_allowance_token.ts index b2acdebaa..baa616f59 100644 --- a/packages/contracts/test/unlimited_allowance_token.ts +++ b/packages/contracts/test/unlimited_allowance_token.ts @@ -7,6 +7,7 @@ import * as Web3 from 'web3'; import { DummyERC20TokenContract } from '../src/contract_wrappers/generated/dummy_e_r_c20_token'; import { artifacts } from '../src/utils/artifacts'; +import { 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'; @@ -93,11 +94,11 @@ describe('UnlimitedAllowanceToken', () => { await token.approve.sendTransactionAsync(spender, amountToTransfer, { from: owner }), constants.AWAIT_TRANSACTION_MINED_MS, ); - return expect( + return expectRevertOrAlwaysFailingTransaction( token.transferFrom.callAsync(owner, spender, amountToTransfer, { from: spender, }), - ).to.be.rejectedWith(constants.REVERT); + ); }); it('should throw if spender has insufficient allowance', async () => { @@ -108,11 +109,11 @@ describe('UnlimitedAllowanceToken', () => { const isSpenderAllowanceInsufficient = spenderAllowance.cmp(amountToTransfer) < 0; expect(isSpenderAllowanceInsufficient).to.be.true(); - return expect( + return expectRevertOrAlwaysFailingTransaction( token.transferFrom.callAsync(owner, spender, amountToTransfer, { from: spender, }), - ).to.be.rejectedWith(constants.REVERT); + ); }); it('should return true on a 0 value transfer', async () => { -- cgit From 00bf957b53c22f3ccdd6c2e7ad75f0c9e15caa38 Mon Sep 17 00:00:00 2001 From: Alex Browne Date: Wed, 23 May 2018 18:13:18 -0700 Subject: Add more transactions to Geth on init. Skip tests that are failing. --- packages/contracts/test/unlimited_allowance_token.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'packages/contracts/test/unlimited_allowance_token.ts') diff --git a/packages/contracts/test/unlimited_allowance_token.ts b/packages/contracts/test/unlimited_allowance_token.ts index baa616f59..1bf29c7e9 100644 --- a/packages/contracts/test/unlimited_allowance_token.ts +++ b/packages/contracts/test/unlimited_allowance_token.ts @@ -53,11 +53,12 @@ describe('UnlimitedAllowanceToken', () => { await blockchainLifecycle.revertAsync(); }); describe('transfer', () => { - it('should throw if owner has insufficient balance', async () => { + // TODO(albrow): AssertionError: expected promise to be rejected but it was fulfilled with true + it.skip('should throw if owner has insufficient balance', async () => { const ownerBalance = await token.balanceOf.callAsync(owner); const amountToTransfer = ownerBalance.plus(1); - return expect(token.transfer.callAsync(spender, amountToTransfer, { from: owner })).to.be.rejectedWith( - constants.REVERT, + return expectRevertOrAlwaysFailingTransaction( + token.transfer.callAsync(spender, amountToTransfer, { from: owner }), ); }); @@ -87,7 +88,8 @@ describe('UnlimitedAllowanceToken', () => { }); describe('transferFrom', () => { - it('should throw if owner has insufficient balance', async () => { + // TODO(albrow): AssertionError: expected promise to be rejected but it was fulfilled with true + it.skip('should throw if owner has insufficient balance', async () => { const ownerBalance = await token.balanceOf.callAsync(owner); const amountToTransfer = ownerBalance.plus(1); await web3Wrapper.awaitTransactionSuccessAsync( @@ -101,7 +103,8 @@ describe('UnlimitedAllowanceToken', () => { ); }); - it('should throw if spender has insufficient allowance', async () => { + // TODO(albrow): AssertionError: expected promise to be rejected but it was fulfilled with true + it.skip('should throw if spender has insufficient allowance', async () => { const ownerBalance = await token.balanceOf.callAsync(owner); const amountToTransfer = ownerBalance; -- cgit From 2dfc4680941293ca9f4a55f3ca58b9ee68872754 Mon Sep 17 00:00:00 2001 From: Alex Browne Date: Fri, 1 Jun 2018 15:59:34 -0700 Subject: Update more tests to pass on Geth --- .../contracts/test/unlimited_allowance_token.ts | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) (limited to 'packages/contracts/test/unlimited_allowance_token.ts') 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 () => { -- cgit From d6d7f4e875b161aa7284467a61f67989f76ec89e Mon Sep 17 00:00:00 2001 From: Alex Browne Date: Tue, 5 Jun 2018 16:20:38 -0700 Subject: Update more things to work with both Geth and Ganache --- packages/contracts/test/unlimited_allowance_token.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'packages/contracts/test/unlimited_allowance_token.ts') diff --git a/packages/contracts/test/unlimited_allowance_token.ts b/packages/contracts/test/unlimited_allowance_token.ts index ea20df040..a66d0055b 100644 --- a/packages/contracts/test/unlimited_allowance_token.ts +++ b/packages/contracts/test/unlimited_allowance_token.ts @@ -7,7 +7,7 @@ import * as Web3 from 'web3'; import { DummyERC20TokenContract } from '../src/contract_wrappers/generated/dummy_e_r_c20_token'; import { artifacts } from '../src/utils/artifacts'; -import { expectRevertOrAlwaysFailingTransaction } from '../src/utils/assertions'; +import { expectRevertOrAlwaysFailingTransaction, expectRevertOrOtherError } 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'; @@ -56,7 +56,8 @@ describe('UnlimitedAllowanceToken', () => { it('should throw if owner has insufficient balance', async () => { const ownerBalance = await token.balanceOf.callAsync(owner); const amountToTransfer = ownerBalance.plus(1); - return expect(token.transfer.callAsync(spender, amountToTransfer, { from: owner })).to.be.rejectedWith( + return expectRevertOrOtherError( + token.transfer.callAsync(spender, amountToTransfer, { from: owner }), constants.ERC20_INSUFFICIENT_BALANCE, ); }); @@ -94,11 +95,12 @@ describe('UnlimitedAllowanceToken', () => { await token.approve.sendTransactionAsync(spender, amountToTransfer, { from: owner }), constants.AWAIT_TRANSACTION_MINED_MS, ); - return expect( + return expectRevertOrOtherError( token.transferFrom.callAsync(owner, spender, amountToTransfer, { from: spender, }), - ).to.be.rejectedWith(constants.ERC20_INSUFFICIENT_BALANCE); + constants.ERC20_INSUFFICIENT_BALANCE, + ); }); it('should throw if spender has insufficient allowance', async () => { @@ -109,11 +111,12 @@ describe('UnlimitedAllowanceToken', () => { const isSpenderAllowanceInsufficient = spenderAllowance.cmp(amountToTransfer) < 0; expect(isSpenderAllowanceInsufficient).to.be.true(); - return expect( + return expectRevertOrOtherError( token.transferFrom.callAsync(owner, spender, amountToTransfer, { from: spender, }), - ).to.be.rejectedWith(constants.ERC20_INSUFFICIENT_ALLOWANCE); + constants.ERC20_INSUFFICIENT_ALLOWANCE, + ); }); it('should return true on a 0 value transfer', async () => { -- cgit From 167a38e27d09af12af6c59f1b486c835420fbac1 Mon Sep 17 00:00:00 2001 From: Alex Browne Date: Tue, 5 Jun 2018 16:56:16 -0700 Subject: Add Async suffix to relevant assertions --- packages/contracts/test/unlimited_allowance_token.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'packages/contracts/test/unlimited_allowance_token.ts') diff --git a/packages/contracts/test/unlimited_allowance_token.ts b/packages/contracts/test/unlimited_allowance_token.ts index a66d0055b..9aa0a040a 100644 --- a/packages/contracts/test/unlimited_allowance_token.ts +++ b/packages/contracts/test/unlimited_allowance_token.ts @@ -7,7 +7,7 @@ import * as Web3 from 'web3'; import { DummyERC20TokenContract } from '../src/contract_wrappers/generated/dummy_e_r_c20_token'; import { artifacts } from '../src/utils/artifacts'; -import { expectRevertOrAlwaysFailingTransaction, expectRevertOrOtherError } from '../src/utils/assertions'; +import { expectRevertOrAlwaysFailingTransactionAsync, expectRevertOrOtherErrorAsync } 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'; @@ -56,7 +56,7 @@ describe('UnlimitedAllowanceToken', () => { it('should throw if owner has insufficient balance', async () => { const ownerBalance = await token.balanceOf.callAsync(owner); const amountToTransfer = ownerBalance.plus(1); - return expectRevertOrOtherError( + return expectRevertOrOtherErrorAsync( token.transfer.callAsync(spender, amountToTransfer, { from: owner }), constants.ERC20_INSUFFICIENT_BALANCE, ); @@ -95,7 +95,7 @@ describe('UnlimitedAllowanceToken', () => { await token.approve.sendTransactionAsync(spender, amountToTransfer, { from: owner }), constants.AWAIT_TRANSACTION_MINED_MS, ); - return expectRevertOrOtherError( + return expectRevertOrOtherErrorAsync( token.transferFrom.callAsync(owner, spender, amountToTransfer, { from: spender, }), @@ -111,7 +111,7 @@ describe('UnlimitedAllowanceToken', () => { const isSpenderAllowanceInsufficient = spenderAllowance.cmp(amountToTransfer) < 0; expect(isSpenderAllowanceInsufficient).to.be.true(); - return expectRevertOrOtherError( + return expectRevertOrOtherErrorAsync( token.transferFrom.callAsync(owner, spender, amountToTransfer, { from: spender, }), -- cgit