Skip to content
This repository was archived by the owner on Jul 6, 2022. It is now read-only.

Commit 05e5353

Browse files
committed
fix: 🐛 make tests pass and fix examples
1 parent 70e441c commit 05e5353

File tree

3 files changed

+41
-45
lines changed

3 files changed

+41
-45
lines changed

examples/mintTokenToInvestor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ window.addEventListener('load', async () => {
5959

6060
console.log('Security Token Generated');
6161

62-
const tokenAddress = await polymathAPI.securityTokenRegistry.getSecurityTokenAddress(ticker!);
62+
const tokenAddress = await polymathAPI.securityTokenRegistry.getSecurityTokenAddress({ ticker: ticker! });
6363
const tickerSecurityTokenInstance = await polymathAPI.tokenFactory.getSecurityTokenInstanceFromAddress(tokenAddress);
6464

6565
const investorAddress = '0x1111111111111111111111111111111111111111';

src/contract_wrappers/registries/__tests__/security_token_registry_wrapper.test.ts

Lines changed: 39 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -611,17 +611,11 @@ describe('SecurityTokenRegistryWrapper', () => {
611611
// Stub the request
612612
when(mockedOwnerMethod.callAsync()).thenResolve(expectedOwnerResult);
613613

614-
// Get Ticker Details
615-
const expectedTickerDetailsResult = [
616-
'0x0123456789012345678901234567890123456789',
617-
new BigNumber(1735689600),
618-
new BigNumber(1735689605),
619-
'ticker',
620-
false,
621-
];
622-
const mockedGetTickerDetailsMethod = mock(MockedCallMethod);
623-
when(mockedContract.getTickerDetails).thenReturn(instance(mockedGetTickerDetailsMethod));
624-
when(mockedGetTickerDetailsMethod.callAsync(ticker)).thenResolve(expectedTickerDetailsResult);
614+
// Get Ticker Availability
615+
const expectedTickerAvailability = true;
616+
const mockedTickerAvailableMethod = mock(MockedCallMethod);
617+
when(mockedContract.tickerAvailable).thenReturn(instance(mockedTickerAvailableMethod));
618+
when(mockedTickerAvailableMethod.callAsync(ticker)).thenResolve(expectedTickerAvailability);
625619

626620
when(mockedWrapper.getAvailableAddressesAsync()).thenResolve([expectedOwnerResult]);
627621

@@ -673,9 +667,8 @@ describe('SecurityTokenRegistryWrapper', () => {
673667
mockedParams.txData,
674668
mockedParams.safetyFactor,
675669
),
676-
).once();
677-
verify(mockedContract.getTickerDetails).once();
678-
verify(mockedGetTickerDetailsMethod.callAsync(ticker)).once();
670+
).once();
671+
verify(mockedTickerAvailableMethod.callAsync(ticker)).once();
679672
verify(mockedContract.getTickerRegistrationFee).once();
680673
verify(mockedTickerRegistrationFeeMethod.callAsync()).once();
681674
verify(mockedPolyTokenContract.balanceOf).once();
@@ -1187,17 +1180,11 @@ describe('SecurityTokenRegistryWrapper', () => {
11871180
// Stub the request
11881181
when(mockedOwnerMethod.callAsync()).thenResolve(expectedOwnerResult);
11891182

1190-
// Get Ticker Details
1191-
const expectedTickerDetailsResult = [
1192-
'0x0123456789012345678901234567890123456789',
1193-
new BigNumber(1735689600),
1194-
new BigNumber(1735689605),
1195-
'ticker',
1196-
false,
1197-
];
1198-
const mockedGetTickerDetailsMethod = mock(MockedCallMethod);
1199-
when(mockedContract.getTickerDetails).thenReturn(instance(mockedGetTickerDetailsMethod));
1200-
when(mockedGetTickerDetailsMethod.callAsync(ticker)).thenResolve(expectedTickerDetailsResult);
1183+
// Get Ticker Availability
1184+
const expectedTickerAvailability = true;
1185+
const mockedTickerAvailableMethod = mock(MockedCallMethod);
1186+
when(mockedContract.tickerAvailable).thenReturn(instance(mockedTickerAvailableMethod));
1187+
when(mockedTickerAvailableMethod.callAsync(ticker)).thenResolve(expectedTickerAvailability);
12011188

12021189
when(mockedWrapper.getAvailableAddressesAsync()).thenResolve([expectedOwnerResult]);
12031190

@@ -1252,9 +1239,8 @@ describe('SecurityTokenRegistryWrapper', () => {
12521239
mockedParams.txData,
12531240
mockedParams.safetyFactor,
12541241
),
1255-
).once();
1256-
verify(mockedContract.getTickerDetails).once();
1257-
verify(mockedGetTickerDetailsMethod.callAsync(ticker)).once();
1242+
).once();
1243+
verify(mockedTickerAvailableMethod.callAsync(ticker)).once();
12581244
verify(mockedContract.getTickerRegistrationFee).once();
12591245
verify(mockedTickerRegistrationFeeMethod.callAsync()).once();
12601246
verify(mockedPolyTokenContract.balanceOf).once();
@@ -1489,7 +1475,7 @@ describe('SecurityTokenRegistryWrapper', () => {
14891475
when(mockedMethod.callAsync(ticker)).thenResolve(expectedResult);
14901476

14911477
// Real call
1492-
const result = await target.getSecurityTokenAddress(ticker);
1478+
const result = await target.getSecurityTokenAddress({ ticker });
14931479
// Result expectation
14941480
expect(result).toBe(expectedResult);
14951481
// Verifications
@@ -1500,39 +1486,33 @@ describe('SecurityTokenRegistryWrapper', () => {
15001486

15011487
describe('TickerAvailable', () => {
15021488
test('should return false as ticker is registered and deployed', async () => {
1503-
const expectedResult = [
1504-
'0x0123456789012345678901234567890123456789',
1505-
new BigNumber(1),
1506-
new BigNumber(1),
1507-
'tokenName',
1508-
true,
1509-
];
1489+
const expectedResult = false;
15101490
const ticker = 'TICK';
15111491
// Mocked method
15121492
const mockedMethod = mock(MockedCallMethod);
15131493
// Stub the method
1514-
when(mockedContract.getTickerDetails).thenReturn(instance(mockedMethod));
1494+
when(mockedContract.tickerAvailable).thenReturn(instance(mockedMethod));
15151495
// Stub the request
15161496
when(mockedMethod.callAsync(ticker)).thenResolve(expectedResult);
15171497

1518-
// Real call
1519-
const result = await target.tickerAvailable({ ticker });
1498+
// Real call
1499+
const result = await target.tickerAvailable({ ticker });
15201500
// Result expectation
15211501
expect(result).toEqual(false);
15221502
// Verifications
1523-
verify(mockedContract.getTickerDetails).once();
1503+
verify(mockedContract.tickerAvailable).once();
15241504
verify(mockedMethod.callAsync(ticker)).once();
15251505
});
15261506

15271507
test.todo('should return false as ticker is registered and not expired');
15281508

15291509
test('should return true as ticker is not registered', async () => {
1530-
const expectedResult = ['', new BigNumber(0), new BigNumber(0), '', false];
1510+
const expectedResult = true;
15311511
const ticker = 'TICK';
15321512
// Mocked method
15331513
const mockedMethod = mock(MockedCallMethod);
15341514
// Stub the method
1535-
when(mockedContract.getTickerDetails).thenReturn(instance(mockedMethod));
1515+
when(mockedContract.tickerAvailable).thenReturn(instance(mockedMethod));
15361516
// Stub the request
15371517
when(mockedMethod.callAsync(ticker)).thenResolve(expectedResult);
15381518

@@ -1541,7 +1521,7 @@ describe('SecurityTokenRegistryWrapper', () => {
15411521
// Result expectation
15421522
expect(result).toEqual(true);
15431523
// Verifications
1544-
verify(mockedContract.getTickerDetails).once();
1524+
verify(mockedContract.tickerAvailable).once();
15451525
verify(mockedMethod.callAsync(ticker)).once();
15461526
});
15471527

@@ -1558,6 +1538,12 @@ describe('SecurityTokenRegistryWrapper', () => {
15581538
// Stub the method
15591539
const expectedAddrResult = [ownerAddress];
15601540

1541+
// Get Ticker Availability
1542+
const expectedTickerAvailability = false;
1543+
const mockedTickerAvailableMethod = mock(MockedCallMethod);
1544+
when(mockedContract.tickerAvailable).thenReturn(instance(mockedTickerAvailableMethod));
1545+
when(mockedTickerAvailableMethod.callAsync(ticker)).thenResolve(expectedTickerAvailability);
1546+
15611547
when(mockedWrapper.getAvailableAddressesAsync()).thenResolve(expectedAddrResult);
15621548

15631549
when(mockedContract.getTickerDetails).thenReturn(instance(mockedMethod));
@@ -1569,7 +1555,9 @@ describe('SecurityTokenRegistryWrapper', () => {
15691555
expect(result).toEqual(true);
15701556
// Verifications
15711557
verify(mockedContract.getTickerDetails).once();
1558+
verify(mockedContract.tickerAvailable).once();
15721559
verify(mockedMethod.callAsync(ticker)).once();
1560+
verify(mockedTickerAvailableMethod.callAsync(ticker)).once();
15731561
verify(mockedWrapper.getAvailableAddressesAsync()).once();
15741562
});
15751563

@@ -1588,6 +1576,12 @@ describe('SecurityTokenRegistryWrapper', () => {
15881576
// Stub the method
15891577
const expectedAddrResult = ['0x1111111111111111111111111111111111111111'];
15901578

1579+
// Get Ticker Availability
1580+
const expectedTickerAvailability = false;
1581+
const mockedTickerAvailableMethod = mock(MockedCallMethod);
1582+
when(mockedContract.tickerAvailable).thenReturn(instance(mockedTickerAvailableMethod));
1583+
when(mockedTickerAvailableMethod.callAsync(ticker)).thenResolve(expectedTickerAvailability);
1584+
15911585
when(mockedWrapper.getAvailableAddressesAsync()).thenResolve(expectedAddrResult);
15921586

15931587
when(mockedContract.getTickerDetails).thenReturn(instance(mockedMethod));
@@ -1599,7 +1593,9 @@ describe('SecurityTokenRegistryWrapper', () => {
15991593
expect(result).toEqual(false);
16001594
// Verifications
16011595
verify(mockedContract.getTickerDetails).once();
1596+
verify(mockedContract.tickerAvailable).once();
16021597
verify(mockedMethod.callAsync(ticker)).once();
1598+
verify(mockedTickerAvailableMethod.callAsync(ticker)).once();
16031599
verify(mockedWrapper.getAvailableAddressesAsync()).once();
16041600
});
16051601
});

src/factories/tokenWrapperFactory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export default class TokenWrapperFactory {
7777
* @memberof SecurityTokenWrapperFactory
7878
*/
7979
public getSecurityTokenInstanceFromTicker = async (ticker: string): Promise<SecurityTokenWrapper> => {
80-
const address = await this.securityTokenRegistry.getSecurityTokenAddress(ticker);
80+
const address = await this.securityTokenRegistry.getSecurityTokenAddress({ ticker });
8181
assert.isNonZeroETHAddressHex('address', address);
8282
return new SecurityTokenWrapper(
8383
this.web3Wrapper,

0 commit comments

Comments
 (0)