Skip to content

Commit

Permalink
fix: feedback improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
shuffledex committed Jan 7, 2020
1 parent 0b60616 commit 25bca45
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions src/procedures/__tests__/PullDividendPayment.ts
Expand Up @@ -20,6 +20,8 @@ const params = {
dividendIndex: 0,
};

const addresses = ['0x01', '0x02', '0x03', '0x04'];

describe('PullDividendPayment', () => {
let target: PullDividendPayment;
let contextMock: MockManager<contextModule.Context>;
Expand Down Expand Up @@ -53,7 +55,7 @@ describe('PullDividendPayment', () => {
factoriesMockedSetup = mockFactories();
factoriesMockedSetup.dividendDistributionFactory = dividendFactoryMock.getMockInstance();
contextMock.set('factories', factoriesMockedSetup);
contextMock.set('currentWallet', new Wallet({ address: () => Promise.resolve('0x01') }));
contextMock.set('currentWallet', new Wallet({ address: () => Promise.resolve(addresses[0]) }));
target = new PullDividendPayment(params, contextMock.getMockInstance());
});

Expand Down Expand Up @@ -96,7 +98,10 @@ describe('PullDividendPayment', () => {
});

test('should throw if the owner address is not a shareholder', async () => {
contextMock.set('currentWallet', new Wallet({ address: () => Promise.resolve('0x04') }));
contextMock.set(
'currentWallet',
new Wallet({ address: () => Promise.resolve(addresses[3]) })
);

wrappersMock.mock(
'getAttachedModules',
Expand All @@ -106,16 +111,17 @@ describe('PullDividendPayment', () => {
wrappersMock.mock(
'getDividend',
Promise.resolve({
shareholders: [{ address: '0x01', paymentReceived: false, excluded: false }],
shareholders: [{ address: addresses[3], paymentReceived: false, excluded: false }],
})
);

// Real call
await expect(target.prepareTransactions()).rejects.toThrowError(
new PolymathError({
code: ErrorCode.ProcedureValidationError,
message:
'Current wallet 0x04 cannot receive dividend payments. Reason: not a shareholder',
message: `Current wallet ${
addresses[3]
} cannot receive dividend payments. Reason: not a shareholder`,
})
);
});
Expand All @@ -129,16 +135,17 @@ describe('PullDividendPayment', () => {
wrappersMock.mock(
'getDividend',
Promise.resolve({
shareholders: [{ address: '0x01', paymentReceived: true, excluded: false }],
shareholders: [{ address: addresses[0], paymentReceived: true, excluded: false }],
})
);

// Real call
await expect(target.prepareTransactions()).rejects.toThrowError(
new PolymathError({
code: ErrorCode.ProcedureValidationError,
message:
'Current wallet 0x01 cannot receive dividend payments. Reason: already received payment',
message: `Current wallet ${
addresses[0]
} cannot receive dividend payments. Reason: already received payment`,
})
);
});
Expand All @@ -152,21 +159,22 @@ describe('PullDividendPayment', () => {
wrappersMock.mock(
'getDividend',
Promise.resolve({
shareholders: [{ address: '0x01', paymentReceived: false, excluded: true }],
shareholders: [{ address: addresses[0], paymentReceived: false, excluded: true }],
})
);

// Real call
await expect(target.prepareTransactions()).rejects.toThrowError(
new PolymathError({
code: ErrorCode.ProcedureValidationError,
message:
'Current wallet 0x01 cannot receive dividend payments. Reason: address belongs to exclusion list',
message: `Current wallet ${
addresses[0]
} cannot receive dividend payments. Reason: address belongs to exclusion list`,
})
);
});

test('should add a transaction to pull a dividend payment', async () => {
test('should add a transaction to pull dividend payments', async () => {
wrappersMock.mock(
'getAttachedModules',
Promise.resolve([erc20DividendsMock.getMockInstance()])
Expand All @@ -176,9 +184,9 @@ describe('PullDividendPayment', () => {
'getDividend',
Promise.resolve({
shareholders: [
{ address: '0x01', paymentReceived: false, excluded: false },
{ address: '0x02', paymentReceived: false, excluded: false },
{ address: '0x03', paymentReceived: true, excluded: false },
{ address: addresses[0], paymentReceived: false, excluded: false },
{ address: addresses[1], paymentReceived: false, excluded: false },
{ address: addresses[2], paymentReceived: true, excluded: false },
],
})
);
Expand Down

0 comments on commit 25bca45

Please sign in to comment.