Skip to content

Commit

Permalink
refactor: toggle allow pre issuing args check
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor Wiebe committed Feb 5, 2020
1 parent f715eb8 commit 1e1bb40
Showing 1 changed file with 50 additions and 22 deletions.
72 changes: 50 additions & 22 deletions src/procedures/__tests__/ToggleAllowPreIssuing.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable import/no-duplicates */
import { ImportMock, MockManager } from 'ts-mock-imports';
import { restore, spy } from 'sinon';
import sinon, { restore, stub } from 'sinon';
import * as contractWrappersModule from '@polymathnetwork/contract-wrappers';
import { ContractVersion } from '@polymathnetwork/contract-wrappers';
import { ToggleAllowPreIssuing } from '../ToggleAllowPreIssuing';
Expand Down Expand Up @@ -109,20 +109,26 @@ describe('ToggleAllowPreIssuing', () => {

describe('ToggleAllowPreIssuing', () => {
test('should add the transaction to the queue to allow pre issuing in a simple sto', async () => {
const addTransactionSpy = spy(target, 'addTransaction');
const allowPreMintingArgsSpy = sinon.spy();
const addTransactionStub = stub(target, 'addTransaction');
simpleSto_3_1_0_Mock.mock('allowPreMinting', Promise.resolve('AllowPreMinting'));
const { allowPreMinting } = simpleSto_3_1_0_Mock.getMockInstance();
addTransactionStub.withArgs(allowPreMinting).returns(allowPreMintingArgsSpy);

// Real call
await target.prepareTransactions();

// Verifications
expect(allowPreMintingArgsSpy.getCall(0).args[0]).toEqual({});
expect(allowPreMintingArgsSpy.callCount).toEqual(1);

expect(
addTransactionSpy
addTransactionStub
.getCall(0)
.calledWith(simpleSto_3_1_0_Mock.getMockInstance().allowPreMinting)
).toEqual(true);
expect(addTransactionSpy.getCall(0).lastArg.tag).toEqual(PolyTransactionTag.AllowPreMinting);
expect(addTransactionSpy.callCount).toEqual(1);
expect(addTransactionStub.getCall(0).lastArg.tag).toEqual(PolyTransactionTag.AllowPreMinting);
expect(addTransactionStub.callCount).toEqual(1);
});

test('should add the transaction to the queue to revoke pre issuing in a simple sto', async () => {
Expand All @@ -131,62 +137,84 @@ describe('ToggleAllowPreIssuing', () => {
contextMock.getMockInstance()
);
simpleSto_3_1_0_Mock.mock('preMintAllowed', Promise.resolve(true));
const addTransactionSpy = spy(target, 'addTransaction');
const revokePreMintFlagArgsSpy = sinon.spy();
const addTransactionStub = stub(target, 'addTransaction');
simpleSto_3_1_0_Mock.mock('revokePreMintFlag', Promise.resolve('RevokePreMintFlag'));
const { revokePreMintFlag } = simpleSto_3_1_0_Mock.getMockInstance();
addTransactionStub.withArgs(revokePreMintFlag).returns(revokePreMintFlagArgsSpy);

// Real call
await target.prepareTransactions();

// Verifications
expect(revokePreMintFlagArgsSpy.getCall(0).args[0]).toEqual({});
expect(revokePreMintFlagArgsSpy.callCount).toEqual(1);

expect(
addTransactionSpy
addTransactionStub
.getCall(0)
.calledWith(simpleSto_3_1_0_Mock.getMockInstance().revokePreMintFlag)
).toEqual(true);
expect(addTransactionSpy.getCall(0).lastArg.tag).toEqual(PolyTransactionTag.RevokePreMinting);
expect(addTransactionSpy.callCount).toEqual(1);
expect(addTransactionStub.getCall(0).lastArg.tag).toEqual(
PolyTransactionTag.RevokePreMinting
);
expect(addTransactionStub.callCount).toEqual(1);
});

test('should add the transaction to the queue to allow pre issuing in a tiered sto', async () => {
moduleWrapperFactoryMock.mock('getModuleInstance', tieredSto_3_1_0_Mock.getMockInstance());
target = new ToggleAllowPreIssuing(tieredParams, contextMock.getMockInstance());

const addTransactionSpy = spy(target, 'addTransaction');
tieredSto_3_1_0_Mock.mock('allowPreMinting', Promise.resolve('ChangeAllowPreIssuing'));
const allowPreMintingArgsSpy = sinon.spy();
const addTransactionStub = stub(target, 'addTransaction');
tieredSto_3_1_0_Mock.mock('allowPreMinting', Promise.resolve('AllowPreMinting'));
const { allowPreMinting } = tieredSto_3_1_0_Mock.getMockInstance();
addTransactionStub.withArgs(allowPreMinting).returns(allowPreMintingArgsSpy);

// Real call
await target.prepareTransactions();

// Verifications
expect(allowPreMintingArgsSpy.getCall(0).args[0]).toEqual({});
expect(allowPreMintingArgsSpy.callCount).toEqual(1);

expect(
addTransactionSpy
addTransactionStub
.getCall(0)
.calledWith(tieredSto_3_1_0_Mock.getMockInstance().allowPreMinting)
).toEqual(true);
expect(addTransactionSpy.getCall(0).lastArg.tag).toEqual(PolyTransactionTag.AllowPreMinting);
expect(addTransactionSpy.callCount).toEqual(1);
expect(addTransactionStub.getCall(0).lastArg.tag).toEqual(PolyTransactionTag.AllowPreMinting);
expect(addTransactionStub.callCount).toEqual(1);
});

test('should add the transaction to the queue to revoke pre issuing in a tiered sto', async () => {
target = new ToggleAllowPreIssuing(
{ ...tieredParams, allowPreIssuing: false },
contextMock.getMockInstance()
);
simpleSto_3_1_0_Mock.mock('preMintAllowed', Promise.resolve(true));
const addTransactionSpy = spy(target, 'addTransaction');
simpleSto_3_1_0_Mock.mock('revokePreMintFlag', Promise.resolve('RevokePreMintFlag'));
moduleWrapperFactoryMock.mock('getModuleInstance', tieredSto_3_1_0_Mock.getMockInstance());
tieredSto_3_1_0_Mock.mock('preMintAllowed', Promise.resolve(true));
const revokePreMintFlagArgsSpy = sinon.spy();
const addTransactionStub = stub(target, 'addTransaction');
tieredSto_3_1_0_Mock.mock('revokePreMintFlag', Promise.resolve('RevokePreMintFlag'));
const { revokePreMintFlag } = tieredSto_3_1_0_Mock.getMockInstance();
addTransactionStub.withArgs(revokePreMintFlag).returns(revokePreMintFlagArgsSpy);

// Real call
await target.prepareTransactions();

// Verifications
expect(revokePreMintFlagArgsSpy.getCall(0).args[0]).toEqual({});
expect(revokePreMintFlagArgsSpy.callCount).toEqual(1);

expect(
addTransactionSpy
addTransactionStub
.getCall(0)
.calledWith(simpleSto_3_1_0_Mock.getMockInstance().revokePreMintFlag)
.calledWith(tieredSto_3_1_0_Mock.getMockInstance().revokePreMintFlag)
).toEqual(true);
expect(addTransactionSpy.getCall(0).lastArg.tag).toEqual(PolyTransactionTag.RevokePreMinting);
expect(addTransactionSpy.callCount).toEqual(1);
expect(addTransactionStub.getCall(0).lastArg.tag).toEqual(
PolyTransactionTag.RevokePreMinting
);
expect(addTransactionStub.callCount).toEqual(1);
});

test('should throw if there is an invalid sto address', async () => {
Expand Down

0 comments on commit 1e1bb40

Please sign in to comment.