Skip to content

Commit 2e968a3

Browse files
author
Victor Wiebe
committed
fix: finish refining tests that throw errors
1 parent a60392d commit 2e968a3

9 files changed

+68
-84
lines changed

src/procedures/__tests__/AssignSecurityTokenRole.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ImportMock, MockManager } from 'ts-mock-imports';
2-
import { stub, spy, restore } from 'sinon';
2+
import { spy, restore } from 'sinon';
33
import * as contractWrappersModule from '@polymathnetwork/contract-wrappers';
44
import { ModuleName, Perm } from '@polymathnetwork/contract-wrappers';
55
import * as contextModule from '../../Context';
@@ -115,14 +115,12 @@ describe('AssignSecurityTokenRole', () => {
115115
});
116116

117117
test('should throw if there is no valid security token being provided', async () => {
118-
tokenFactoryMock.set(
119-
'getSecurityTokenInstanceFromTicker',
120-
stub()
121-
.withArgs({ address: params.symbol })
122-
.throws()
123-
);
118+
tokenFactoryMock
119+
.mock('getSecurityTokenInstanceFromTicker')
120+
.withArgs(params.symbol)
121+
.throws();
124122

125-
expect(target.prepareTransactions()).rejects.toThrow(
123+
await expect(target.prepareTransactions()).rejects.toThrow(
126124
new PolymathError({
127125
code: ErrorCode.ProcedureValidationError,
128126
message: `There is no Security Token with symbol ${params.symbol}`,
@@ -133,7 +131,7 @@ describe('AssignSecurityTokenRole', () => {
133131
test('should throw if permission feature is not enabled', async () => {
134132
wrappersMock.mock('getAttachedModules', Promise.resolve([]));
135133
// Real call
136-
expect(target.prepareTransactions()).rejects.toThrowError(
134+
await expect(target.prepareTransactions()).rejects.toThrowError(
137135
new PolymathError({
138136
code: ErrorCode.ProcedureValidationError,
139137
message: 'You must enable the Permissions feature',
@@ -144,7 +142,7 @@ describe('AssignSecurityTokenRole', () => {
144142
test('should throw if role has already been assigned to delegate', async () => {
145143
gpmMock.mock('getAllDelegatesWithPerm', Promise.resolve([params.delegateAddress]));
146144
// Real call
147-
expect(target.prepareTransactions()).rejects.toThrowError(
145+
await expect(target.prepareTransactions()).rejects.toThrowError(
148146
new PolymathError({
149147
code: ErrorCode.ProcedureValidationError,
150148
message: `Role ${params.role} has already been assigned to delegate.`,
@@ -158,7 +156,7 @@ describe('AssignSecurityTokenRole', () => {
158156
contextMock.getMockInstance()
159157
);
160158
// Real call
161-
expect(target.prepareTransactions()).rejects.toThrowError(
159+
await expect(target.prepareTransactions()).rejects.toThrowError(
162160
new PolymathError({
163161
code: ErrorCode.ProcedureValidationError,
164162
message: `Role ${params.role} has already been revoked from delegate.`,
@@ -175,7 +173,7 @@ describe('AssignSecurityTokenRole', () => {
175173
},
176174
});
177175
// Real call
178-
expect(target.prepareTransactions()).rejects.toThrowError(
176+
await expect(target.prepareTransactions()).rejects.toThrowError(
179177
new PolymathError({
180178
code: ErrorCode.FeatureNotEnabled,
181179
message: `You must enable the Permissions feature`,

src/procedures/__tests__/AssignStoRole.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ImportMock, MockManager } from 'ts-mock-imports';
2-
import { stub, spy } from 'sinon';
2+
import { spy } from 'sinon';
33
import * as contractWrappersModule from '@polymathnetwork/contract-wrappers';
44
import * as contextModule from '../../Context';
55
import * as wrappersModule from '../../PolymathBase';
@@ -104,14 +104,12 @@ describe('AssignStoRole', () => {
104104
});
105105

106106
test('should throw if there is no valid security token supplied', async () => {
107-
tokenFactoryMock.set(
108-
'getSecurityTokenInstanceFromTicker',
109-
stub()
110-
.withArgs({ address: params.symbol })
111-
.throws()
112-
);
107+
tokenFactoryMock
108+
.mock('getSecurityTokenInstanceFromTicker')
109+
.withArgs(params.symbol)
110+
.throws();
113111

114-
expect(target.prepareTransactions()).rejects.toThrow(
112+
await expect(target.prepareTransactions()).rejects.toThrow(
115113
new PolymathError({
116114
code: ErrorCode.ProcedureValidationError,
117115
message: `There is no Security Token with symbol ${params.symbol}`,
@@ -122,7 +120,7 @@ describe('AssignStoRole', () => {
122120
test('should throw if permission feature is not enabled', async () => {
123121
wrappersMock.mock('getAttachedModules', Promise.resolve([]));
124122
// Real call
125-
expect(target.prepareTransactions()).rejects.toThrowError(
123+
await expect(target.prepareTransactions()).rejects.toThrowError(
126124
new PolymathError({
127125
code: ErrorCode.ProcedureValidationError,
128126
message: 'You must enable the Permissions feature',
@@ -133,7 +131,7 @@ describe('AssignStoRole', () => {
133131
test('should throw if role has already been assigned to delegate', async () => {
134132
gpmMock.mock('getAllDelegatesWithPerm', Promise.resolve([params.delegateAddress]));
135133
// Real call
136-
expect(target.prepareTransactions()).rejects.toThrowError(
134+
await expect(target.prepareTransactions()).rejects.toThrowError(
137135
new PolymathError({
138136
code: ErrorCode.ProcedureValidationError,
139137
message: `Role ${params.role} has already been assigned to delegate for this STO.`,
@@ -144,7 +142,7 @@ describe('AssignStoRole', () => {
144142
test('should throw if role has already been revoked from delegate', async () => {
145143
target = new AssignStoRole({ ...params, assign: false }, contextMock.getMockInstance());
146144
// Real call
147-
expect(target.prepareTransactions()).rejects.toThrowError(
145+
await expect(target.prepareTransactions()).rejects.toThrowError(
148146
new PolymathError({
149147
code: ErrorCode.ProcedureValidationError,
150148
message: `Role ${params.role} has already been revoked from delegate for this STO.`,

src/procedures/__tests__/ControllerTransfer.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ImportMock, MockManager } from 'ts-mock-imports';
2-
import { stub, spy } from 'sinon';
2+
import { spy } from 'sinon';
33
import { BigNumber } from '@polymathnetwork/contract-wrappers';
44
import * as contractWrappersModule from '@polymathnetwork/contract-wrappers';
55
import * as contextModule from '../../Context';
@@ -79,14 +79,12 @@ describe('ControllerTransfer', () => {
7979
});
8080

8181
test('should throw if there is no valid security token supplied', async () => {
82-
tokenFactoryMock.set(
83-
'getSecurityTokenInstanceFromTicker',
84-
stub()
85-
.withArgs({ address: params.symbol })
86-
.throws()
87-
);
82+
tokenFactoryMock
83+
.mock('getSecurityTokenInstanceFromTicker')
84+
.withArgs(params.symbol)
85+
.throws();
8886

89-
expect(target.prepareTransactions()).rejects.toThrow(
87+
await expect(target.prepareTransactions()).rejects.toThrow(
9088
new PolymathError({
9189
code: ErrorCode.ProcedureValidationError,
9290
message: `There is no Security Token with symbol ${params.symbol}`,
@@ -97,7 +95,7 @@ describe('ControllerTransfer', () => {
9795
test('should throw error if balanceOf is less than amount being transferred', async () => {
9896
securityTokenMock.mock('balanceOf', Promise.resolve(new BigNumber(0)));
9997
// Real call
100-
expect(target.prepareTransactions()).rejects.toThrowError(
98+
await expect(target.prepareTransactions()).rejects.toThrowError(
10199
new PolymathError({
102100
code: ErrorCode.InsufficientBalance,
103101
message: `Sender's balance of 0 is less than the requested amount of ${params.amount.toNumber()}`,
@@ -108,7 +106,7 @@ describe('ControllerTransfer', () => {
108106
test('should throw an error if the current wallet is not the Security Token controller', async () => {
109107
securityTokenMock.mock('controller', Promise.resolve('Random'));
110108
// Real call
111-
expect(target.prepareTransactions()).rejects.toThrowError(
109+
await expect(target.prepareTransactions()).rejects.toThrowError(
112110
new PolymathError({
113111
code: ErrorCode.ProcedureValidationError,
114112
message: `You must be the controller of this Security Token to perform forced transfers. Did you remember to call "setController"?`,
@@ -126,7 +124,7 @@ describe('ControllerTransfer', () => {
126124
contextMock.getMockInstance()
127125
);
128126
// Real call rejects
129-
expect(target.prepareTransactions()).rejects.toThrowError(
127+
await expect(target.prepareTransactions()).rejects.toThrowError(
130128
new PolymathError({
131129
code: ErrorCode.InvalidAddress,
132130
message: `Provided "to" address is invalid: Inappropriate`,
@@ -144,7 +142,7 @@ describe('ControllerTransfer', () => {
144142
contextMock.getMockInstance()
145143
);
146144
// Real call rejects
147-
expect(target.prepareTransactions()).rejects.toThrowError(
145+
await expect(target.prepareTransactions()).rejects.toThrowError(
148146
new PolymathError({
149147
code: ErrorCode.InvalidAddress,
150148
message: `Provided "from" address is invalid: Inappropriate`,

src/procedures/__tests__/CreateCheckpoint.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ImportMock, MockManager } from 'ts-mock-imports';
2-
import { stub, spy, restore } from 'sinon';
2+
import { spy, restore } from 'sinon';
33
import * as contractWrappersModule from '@polymathnetwork/contract-wrappers';
44
import { TransactionReceiptWithDecodedLogs } from 'ethereum-protocol';
55
import { BigNumber } from '@polymathnetwork/contract-wrappers';
@@ -86,7 +86,7 @@ describe('CreateCheckpoint', () => {
8686
// Real call
8787
const resolver = await target.prepareTransactions();
8888

89-
expect(resolver.run({} as TransactionReceiptWithDecodedLogs)).rejects.toThrow(
89+
await expect(resolver.run({} as TransactionReceiptWithDecodedLogs)).rejects.toThrow(
9090
new PolymathError({
9191
code: ErrorCode.UnexpectedEventLogs,
9292
message:
@@ -119,14 +119,12 @@ describe('CreateCheckpoint', () => {
119119
});
120120

121121
test('should throw if there is no valid security token supplied', async () => {
122-
tokenFactoryMock.set(
123-
'getSecurityTokenInstanceFromTicker',
124-
stub()
125-
.withArgs({ address: params.symbol })
126-
.throws()
127-
);
122+
tokenFactoryMock
123+
.mock('getSecurityTokenInstanceFromTicker')
124+
.withArgs(params.symbol)
125+
.throws();
128126

129-
expect(target.prepareTransactions()).rejects.toThrow(
127+
await expect(target.prepareTransactions()).rejects.toThrow(
130128
new PolymathError({
131129
code: ErrorCode.ProcedureValidationError,
132130
message: `There is no Security Token with symbol ${params.symbol}`,

src/procedures/__tests__/CreateErc20DividendDistribution.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ImportMock, MockManager } from 'ts-mock-imports';
2-
import { stub, spy, restore } from 'sinon';
2+
import { spy, restore } from 'sinon';
33
import { BigNumber } from '@polymathnetwork/contract-wrappers';
44
import * as contractWrappersModule from '@polymathnetwork/contract-wrappers';
55
import { TransactionReceiptWithDecodedLogs } from 'ethereum-protocol';
@@ -145,14 +145,12 @@ describe('CreateErc20DividendDistribution', () => {
145145
});
146146

147147
test('should throw if there is no valid security token supplied', async () => {
148-
tokenFactoryMock.set(
149-
'getSecurityTokenInstanceFromTicker',
150-
stub()
151-
.withArgs({ address: params.symbol })
152-
.throws()
153-
);
148+
tokenFactoryMock
149+
.mock('getSecurityTokenInstanceFromTicker')
150+
.withArgs(params.symbol)
151+
.throws();
154152

155-
expect(target.prepareTransactions()).rejects.toThrow(
153+
await expect(target.prepareTransactions()).rejects.toThrow(
156154
new PolymathError({
157155
code: ErrorCode.ProcedureValidationError,
158156
message: `There is no Security Token with symbol ${params.symbol}`,
@@ -166,7 +164,7 @@ describe('CreateErc20DividendDistribution', () => {
166164
// Real call
167165
const resolver = await target.prepareTransactions();
168166

169-
expect(resolver.run({} as TransactionReceiptWithDecodedLogs)).rejects.toThrow(
167+
await expect(resolver.run({} as TransactionReceiptWithDecodedLogs)).rejects.toThrow(
170168
new PolymathError({
171169
code: ErrorCode.UnexpectedEventLogs,
172170
message:
@@ -201,7 +199,7 @@ describe('CreateErc20DividendDistribution', () => {
201199
test('should throw error if the erc20 dividends manager has not been enabled', async () => {
202200
wrappersMock.mock('getAttachedModules', Promise.resolve([]));
203201
// Real call
204-
expect(target.prepareTransactions()).rejects.toThrowError(
202+
await expect(target.prepareTransactions()).rejects.toThrowError(
205203
new PolymathError({
206204
code: ErrorCode.ProcedureValidationError,
207205
message: "The ERC20 Dividends Manager hasn't been enabled",

src/procedures/__tests__/CreateEtherDividendDistribution.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ImportMock, MockManager } from 'ts-mock-imports';
2-
import { stub, spy, restore } from 'sinon';
2+
import { spy, restore } from 'sinon';
33
import { BigNumber } from '@polymathnetwork/contract-wrappers';
44
import { TransactionReceiptWithDecodedLogs } from 'ethereum-protocol';
55
import * as contractWrappersModule from '@polymathnetwork/contract-wrappers';
@@ -131,7 +131,7 @@ describe('CreateEtherDividendDistribution', () => {
131131
// Real call
132132
const resolver = await target.prepareTransactions();
133133

134-
expect(resolver.run({} as TransactionReceiptWithDecodedLogs)).rejects.toThrow(
134+
await expect(resolver.run({} as TransactionReceiptWithDecodedLogs)).rejects.toThrow(
135135
new PolymathError({
136136
code: ErrorCode.UnexpectedEventLogs,
137137
message:
@@ -166,7 +166,7 @@ describe('CreateEtherDividendDistribution', () => {
166166
test('should throw if eth dividends manager has not been enabled', async () => {
167167
wrappersMock.mock('getAttachedModules', Promise.resolve([]));
168168
// Real call
169-
expect(target.prepareTransactions()).rejects.toThrowError(
169+
await expect(target.prepareTransactions()).rejects.toThrowError(
170170
new PolymathError({
171171
code: ErrorCode.ProcedureValidationError,
172172
message: "The ETH Dividends Manager hasn't been enabled",
@@ -175,14 +175,12 @@ describe('CreateEtherDividendDistribution', () => {
175175
});
176176

177177
test('should throw if there is no valid security token supplied', async () => {
178-
tokenFactoryMock.set(
179-
'getSecurityTokenInstanceFromTicker',
180-
stub()
181-
.withArgs({ address: params.symbol })
182-
.throws()
183-
);
178+
tokenFactoryMock
179+
.mock('getSecurityTokenInstanceFromTicker')
180+
.withArgs(params.symbol)
181+
.throws();
184182

185-
expect(target.prepareTransactions()).rejects.toThrow(
183+
await expect(target.prepareTransactions()).rejects.toThrow(
186184
new PolymathError({
187185
code: ErrorCode.ProcedureValidationError,
188186
message: `There is no Security Token with symbol ${params.symbol}`,

src/procedures/__tests__/CreateSecurityToken.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ describe('CreateSecurityToken', () => {
9595
test('should throw error if token is not reserved ', async () => {
9696
securityTokenRegistryMock.mock('tickerAvailable', Promise.resolve(true));
9797
// Real call
98-
expect(target.prepareTransactions()).rejects.toThrowError(
98+
await expect(target.prepareTransactions()).rejects.toThrowError(
9999
new PolymathError({
100100
code: ErrorCode.ProcedureValidationError,
101101
message: `The security token symbol ${
@@ -111,7 +111,7 @@ describe('CreateSecurityToken', () => {
111111
// Real call
112112
const resolver = await target.prepareTransactions();
113113

114-
expect(resolver.run({} as TransactionReceiptWithDecodedLogs)).rejects.toThrow(
114+
await expect(resolver.run({} as TransactionReceiptWithDecodedLogs)).rejects.toThrow(
115115
new PolymathError({
116116
code: ErrorCode.UnexpectedEventLogs,
117117
message:
@@ -150,7 +150,7 @@ describe('CreateSecurityToken', () => {
150150
test('should throw error if token has been reserved by other user', async () => {
151151
securityTokenRegistryMock.mock('isTickerRegisteredByCurrentIssuer', Promise.resolve(false));
152152
// Real call
153-
expect(target.prepareTransactions()).rejects.toThrowError(
153+
await expect(target.prepareTransactions()).rejects.toThrowError(
154154
new PolymathError({
155155
code: ErrorCode.ProcedureValidationError,
156156
message: `The security token symbol ${
@@ -163,7 +163,7 @@ describe('CreateSecurityToken', () => {
163163
test('should throw error if the token has already been launched', async () => {
164164
securityTokenRegistryMock.mock('isTokenLaunched', Promise.resolve(true));
165165
// Real call
166-
expect(target.prepareTransactions()).rejects.toThrowError(
166+
await expect(target.prepareTransactions()).rejects.toThrowError(
167167
new PolymathError({
168168
code: ErrorCode.ProcedureValidationError,
169169
message: `The security token symbol ${params.symbol} has already been launched.`,

src/procedures/__tests__/EnableDividendManagers.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ImportMock, MockManager } from 'ts-mock-imports';
2-
import { stub, spy, restore } from 'sinon';
2+
import { spy, restore } from 'sinon';
33
import { BigNumber } from '@polymathnetwork/contract-wrappers';
44
import * as contractWrappersModule from '@polymathnetwork/contract-wrappers';
55
import * as contextModule from '../../Context';
@@ -85,14 +85,12 @@ describe('EnableDividendManagers', () => {
8585
});
8686

8787
test('should throw if there is no valid security token supplied', async () => {
88-
tokenFactoryMock.set(
89-
'getSecurityTokenInstanceFromTicker',
90-
stub()
91-
.withArgs({ address: params.symbol })
92-
.throws()
93-
);
88+
tokenFactoryMock
89+
.mock('getSecurityTokenInstanceFromTicker')
90+
.withArgs(params.symbol)
91+
.throws();
9492

95-
expect(target.prepareTransactions()).rejects.toThrow(
93+
await expect(target.prepareTransactions()).rejects.toThrow(
9694
new PolymathError({
9795
code: ErrorCode.ProcedureValidationError,
9896
message: `There is no Security Token with symbol ${params.symbol}`,

src/procedures/__tests__/EnableGeneralPermissionManager.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ImportMock, MockManager } from 'ts-mock-imports';
2-
import { stub, spy, restore } from 'sinon';
2+
import { spy, restore } from 'sinon';
33
import { BigNumber } from '@polymathnetwork/contract-wrappers';
44
import * as contractWrappersModule from '@polymathnetwork/contract-wrappers';
55
import * as contextModule from '../../Context';
@@ -76,14 +76,12 @@ describe('EnableGeneralPermissionManager', () => {
7676
});
7777

7878
test('should throw if there is no valid security token supplied', async () => {
79-
tokenFactoryMock.set(
80-
'getSecurityTokenInstanceFromTicker',
81-
stub()
82-
.withArgs({ address: params.symbol })
83-
.throws()
84-
);
79+
tokenFactoryMock
80+
.mock('getSecurityTokenInstanceFromTicker')
81+
.withArgs(params.symbol)
82+
.throws();
8583

86-
expect(target.prepareTransactions()).rejects.toThrow(
84+
await expect(target.prepareTransactions()).rejects.toThrow(
8785
new PolymathError({
8886
code: ErrorCode.ProcedureValidationError,
8987
message: `There is no Security Token with symbol ${params.symbol}`,

0 commit comments

Comments
 (0)