Skip to content

Commit 91ad8e6

Browse files
author
Victor Wiebe
committed
feat: add more modification procedures
1 parent 6335f56 commit 91ad8e6

4 files changed

Lines changed: 85 additions & 25 deletions

File tree

src/procedures/__tests__/ModifyDividendsDefaultExclusionList.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable import/no-duplicates */
22
import { ImportMock, MockManager } from 'ts-mock-imports';
3-
import { spy, restore } from 'sinon';
3+
import sinon, { stub, restore } from 'sinon';
44
import * as contractWrappersModule from '@polymathnetwork/contract-wrappers';
55
import * as contextModule from '../../Context';
66
import * as wrappersModule from '../../PolymathBase';
@@ -100,21 +100,31 @@ describe('ModifyDividendsDefaultExclusionList', () => {
100100
Promise.resolve([erc20DividendsMock.getMockInstance()])
101101
);
102102

103-
erc20DividendsMock.mock('setDefaultExcluded', Promise.resolve('SetDefaultExcluded'));
103+
const setDefaultExcludedArgsSpy = sinon.spy();
104+
const addTransactionStub = stub(target, 'addTransaction');
104105

105-
const addTransactionSpy = spy(target, 'addTransaction');
106+
erc20DividendsMock.mock('setDefaultExcluded', Promise.resolve('SetDefaultExcluded'));
107+
const { setDefaultExcluded } = erc20DividendsMock.getMockInstance();
108+
addTransactionStub.withArgs(setDefaultExcluded).returns(setDefaultExcludedArgsSpy);
106109

110+
// Real Call
107111
await target.prepareTransactions();
108112

113+
// Verifications
114+
expect(setDefaultExcludedArgsSpy.getCall(0).args[0]).toEqual({
115+
excluded: params.shareholderAddresses,
116+
});
117+
expect(setDefaultExcludedArgsSpy.callCount).toEqual(1);
118+
109119
expect(
110-
addTransactionSpy
120+
addTransactionStub
111121
.getCall(0)
112122
.calledWith(erc20DividendsMock.getMockInstance().setDefaultExcluded)
113123
).toEqual(true);
114-
expect(addTransactionSpy.getCall(0).lastArg.tag).toEqual(
124+
expect(addTransactionStub.getCall(0).lastArg.tag).toEqual(
115125
PolyTransactionTag.SetDefaultExcluded
116126
);
117-
expect(addTransactionSpy.callCount).toEqual(1);
127+
expect(addTransactionStub.callCount).toEqual(1);
118128
});
119129
});
120130
});

src/procedures/__tests__/ModifyMaxHolderCount.ts

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

6565
describe('ModifyMaxHolderCount', () => {
6666
test('should add a transaction to the queue to modify max holder count', async () => {
67-
const addTransactionSpy = spy(target, 'addTransaction');
67+
const changeHolderCountArgsSpy = sinon.spy();
68+
const addTransactionStub = stub(target, 'addTransaction');
6869
countTransferMock.mock('changeHolderCount', Promise.resolve('ChangeHolderCount'));
70+
const { changeHolderCount } = countTransferMock.getMockInstance();
71+
addTransactionStub.withArgs(changeHolderCount).returns(changeHolderCountArgsSpy);
6972

7073
// Real call
7174
await target.prepareTransactions();
7275

7376
// Verifications
77+
expect(changeHolderCountArgsSpy.getCall(0).args[0]).toEqual({
78+
maxHolderCount: params.maxHolderCount,
79+
});
80+
expect(changeHolderCountArgsSpy.callCount).toEqual(1);
81+
7482
expect(
75-
addTransactionSpy
83+
addTransactionStub
7684
.getCall(0)
7785
.calledWithExactly(countTransferMock.getMockInstance().changeHolderCount, {
7886
tag: PolyTransactionTag.ChangeHolderCount,
7987
})
8088
).toEqual(true);
81-
expect(addTransactionSpy.callCount).toEqual(1);
89+
expect(addTransactionStub.callCount).toEqual(1);
8290
});
8391

8492
test('should throw if there is no valid security token supplied', async () => {

src/procedures/__tests__/ModifyMaxHolderPercentage.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable import/no-duplicates */
22
import { ImportMock, MockManager } from 'ts-mock-imports';
3-
import { spy, restore } from 'sinon';
3+
import sinon, { restore, stub } from 'sinon';
44
import { BigNumber } from '@polymathnetwork/contract-wrappers';
55
import * as contractWrappersModule from '@polymathnetwork/contract-wrappers';
66
import * as contextModule from '../../Context';
@@ -72,24 +72,32 @@ describe('ModifyMaxHolderPercentage', () => {
7272

7373
describe('ModifyMaxHolderPercentage', () => {
7474
test('should add a transaction to the queue to modify max holder percentage', async () => {
75-
const addTransactionSpy = spy(target, 'addTransaction');
75+
const changeHolderPercentageArgsSpy = sinon.spy();
76+
const addTransactionStub = stub(target, 'addTransaction');
7677
percentageTransferMock.mock(
7778
'changeHolderPercentage',
7879
Promise.resolve('ChangeHolderPercentage')
7980
);
81+
const { changeHolderPercentage } = percentageTransferMock.getMockInstance();
82+
addTransactionStub.withArgs(changeHolderPercentage).returns(changeHolderPercentageArgsSpy);
8083

8184
// Real call
8285
await target.prepareTransactions();
8386

8487
// Verifications
88+
expect(changeHolderPercentageArgsSpy.getCall(0).args[0]).toEqual({
89+
maxHolderPercentage: params.maxHolderPercentage,
90+
});
91+
expect(changeHolderPercentageArgsSpy.callCount).toEqual(1);
92+
8593
expect(
86-
addTransactionSpy
94+
addTransactionStub
8795
.getCall(0)
8896
.calledWithExactly(percentageTransferMock.getMockInstance().changeHolderPercentage, {
8997
tag: PolyTransactionTag.ChangeHolderPercentage,
9098
})
9199
).toEqual(true);
92-
expect(addTransactionSpy.callCount).toEqual(1);
100+
expect(addTransactionStub.callCount).toEqual(1);
93101
});
94102

95103
test('should throw if there is no valid security token supplied', async () => {

src/procedures/__tests__/ModifyPercentageExemptions.ts

Lines changed: 45 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 { spy, restore } from 'sinon';
2+
import sinon, { restore, stub } from 'sinon';
33
import * as contractWrappersModule from '@polymathnetwork/contract-wrappers';
44
import * as contextModule from '../../Context';
55
import * as wrappersModule from '../../PolymathBase';
@@ -85,30 +85,41 @@ describe('ModifyPercentageExemptions', () => {
8585
{ symbol: params.symbol, allowPrimaryIssuance: true },
8686
contextMock.getMockInstance()
8787
);
88-
const addTransactionSpy = spy(target, 'addTransaction');
88+
const setAllowPrimaryIssuanceArgsSpy = sinon.spy();
89+
const addTransactionStub = stub(target, 'addTransaction');
8990

9091
percentageTransferMock.mock(
9192
'setAllowPrimaryIssuance',
9293
Promise.resolve('SetAllowPrimaryIssuance')
9394
);
9495
percentageTransferMock.mock('allowPrimaryIssuance', Promise.resolve(false));
9596

97+
const { setAllowPrimaryIssuance } = percentageTransferMock.getMockInstance();
98+
addTransactionStub.withArgs(setAllowPrimaryIssuance).returns(setAllowPrimaryIssuanceArgsSpy);
99+
96100
// Real call
97101
await target.prepareTransactions();
98102

99103
// Verifications
104+
expect(setAllowPrimaryIssuanceArgsSpy.getCall(0).args[0]).toEqual({
105+
allowPrimaryIssuance: params.allowPrimaryIssuance,
106+
});
107+
expect(setAllowPrimaryIssuanceArgsSpy.callCount).toEqual(1);
108+
100109
expect(
101-
addTransactionSpy
110+
addTransactionStub
102111
.getCall(0)
103112
.calledWithExactly(percentageTransferMock.getMockInstance().setAllowPrimaryIssuance, {
104113
tag: PolyTransactionTag.SetAllowPrimaryIssuance,
105114
})
106115
).toEqual(true);
107-
expect(addTransactionSpy.callCount).toEqual(1);
116+
expect(addTransactionStub.callCount).toEqual(1);
108117
});
109118

110119
test('should add a transaction to the queue to modify percentage exemptions and make a change to allow primary issuance', async () => {
111-
const addTransactionSpy = spy(target, 'addTransaction');
120+
const setAllowPrimaryIssuanceArgsSpy = sinon.spy();
121+
const modifyWhitelistMultiArgsSpy = sinon.spy();
122+
const addTransactionStub = stub(target, 'addTransaction');
112123

113124
percentageTransferMock.mock(
114125
'setAllowPrimaryIssuance',
@@ -117,26 +128,40 @@ describe('ModifyPercentageExemptions', () => {
117128
percentageTransferMock.mock('modifyWhitelistMulti', Promise.resolve('ModifyWhitelistMulti'));
118129
percentageTransferMock.mock('allowPrimaryIssuance', Promise.resolve(false));
119130

131+
const { modifyWhitelistMulti } = percentageTransferMock.getMockInstance();
132+
addTransactionStub.withArgs(modifyWhitelistMulti).returns(modifyWhitelistMultiArgsSpy);
133+
const { setAllowPrimaryIssuance } = percentageTransferMock.getMockInstance();
134+
addTransactionStub.withArgs(setAllowPrimaryIssuance).returns(setAllowPrimaryIssuanceArgsSpy);
135+
120136
// Real call
121137
await target.prepareTransactions();
122138

123139
// Verifications
140+
expect(modifyWhitelistMultiArgsSpy.getCall(0).args[0]).toEqual({
141+
investors: [params.whitelistEntries![0].address, params.whitelistEntries![1].address],
142+
valids: [params.whitelistEntries![0].whitelisted, params.whitelistEntries![1].whitelisted],
143+
});
144+
expect(modifyWhitelistMultiArgsSpy.callCount).toEqual(1);
124145
expect(
125-
addTransactionSpy
146+
addTransactionStub
126147
.getCall(0)
127148
.calledWithExactly(percentageTransferMock.getMockInstance().modifyWhitelistMulti, {
128149
tag: PolyTransactionTag.ModifyWhitelistMulti,
129150
})
130151
).toEqual(true);
131152

153+
expect(setAllowPrimaryIssuanceArgsSpy.getCall(0).args[0]).toEqual({
154+
allowPrimaryIssuance: params.allowPrimaryIssuance,
155+
});
156+
expect(setAllowPrimaryIssuanceArgsSpy.callCount).toEqual(1);
132157
expect(
133-
addTransactionSpy
158+
addTransactionStub
134159
.getCall(1)
135160
.calledWithExactly(percentageTransferMock.getMockInstance().setAllowPrimaryIssuance, {
136161
tag: PolyTransactionTag.SetAllowPrimaryIssuance,
137162
})
138163
).toEqual(true);
139-
expect(addTransactionSpy.callCount).toEqual(2);
164+
expect(addTransactionStub.callCount).toEqual(2);
140165
});
141166

142167
test('should add a transaction to the queue to only modify percentage exemptions', async () => {
@@ -146,21 +171,30 @@ describe('ModifyPercentageExemptions', () => {
146171
contextMock.getMockInstance()
147172
);
148173

174+
const modifyWhitelistMultiArgsSpy = sinon.spy();
175+
const addTransactionStub = stub(target, 'addTransaction');
149176
percentageTransferMock.mock('modifyWhitelistMulti', Promise.resolve('ModifyWhitelistMulti'));
150-
const addTransactionSpy = spy(target, 'addTransaction');
177+
const { modifyWhitelistMulti } = percentageTransferMock.getMockInstance();
178+
addTransactionStub.withArgs(modifyWhitelistMulti).returns(modifyWhitelistMultiArgsSpy);
151179

152180
// Real call
153181
await target.prepareTransactions();
154182

155183
// Verifications
184+
expect(modifyWhitelistMultiArgsSpy.getCall(0).args[0]).toEqual({
185+
investors: [params.whitelistEntries![0].address, params.whitelistEntries![1].address],
186+
valids: [params.whitelistEntries![0].whitelisted, params.whitelistEntries![1].whitelisted],
187+
});
188+
expect(modifyWhitelistMultiArgsSpy.callCount).toEqual(1);
189+
156190
expect(
157-
addTransactionSpy
191+
addTransactionStub
158192
.getCall(0)
159193
.calledWithExactly(percentageTransferMock.getMockInstance().modifyWhitelistMulti, {
160194
tag: PolyTransactionTag.ModifyWhitelistMulti,
161195
})
162196
).toEqual(true);
163-
expect(addTransactionSpy.callCount).toEqual(1);
197+
expect(addTransactionStub.callCount).toEqual(1);
164198
});
165199

166200
test('should throw if there is no valid security token supplied', async () => {

0 commit comments

Comments
 (0)