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

Commit 13543ed

Browse files
author
Victor Wiebe
committed
feat: add usdTieredSTO modifyOracle method and test
1 parent fb0d174 commit 13543ed

File tree

2 files changed

+93
-2
lines changed

2 files changed

+93
-2
lines changed

src/contract_wrappers/modules/sto/__tests__/usd_tiered_sto_wrapper.test.ts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2434,6 +2434,72 @@ describe('USDTieredSTOWrapper', () => {
24342434
});
24352435
});
24362436

2437+
describe('ModifyOracle', () => {
2438+
test('should modifyOracle', async () => {
2439+
// Mock Only Owner and Security Token
2440+
const expectedOwnerResult = '0x5555555555555555555555555555555555555555';
2441+
// Security Token Address expected
2442+
const expectedSecurityTokenAddress = '0x3333333333333333333333333333333333333333';
2443+
// Setup get Security Token Address
2444+
const mockedGetSecurityTokenAddressMethod = mock(MockedCallMethod);
2445+
when(mockedContract.securityToken).thenReturn(instance(mockedGetSecurityTokenAddressMethod));
2446+
when(mockedGetSecurityTokenAddressMethod.callAsync()).thenResolve(expectedSecurityTokenAddress);
2447+
when(mockedContractFactory.getSecurityTokenContract(expectedSecurityTokenAddress)).thenResolve(
2448+
instance(mockedSecurityTokenContract),
2449+
);
2450+
const mockedSecurityTokenOwnerMethod = mock(MockedCallMethod);
2451+
when(mockedSecurityTokenOwnerMethod.callAsync()).thenResolve(expectedOwnerResult);
2452+
when(mockedSecurityTokenContract.owner).thenReturn(instance(mockedSecurityTokenOwnerMethod));
2453+
2454+
// Mock web3 wrapper owner
2455+
when(mockedWrapper.getAvailableAddressesAsync()).thenResolve([expectedOwnerResult]);
2456+
2457+
const mockedParams = {
2458+
oracleAddress: '0x1111111111111111111111111111111111111111',
2459+
fundRaiseType: FundRaiseType.ETH,
2460+
txData: {},
2461+
safetyFactor: 10,
2462+
};
2463+
2464+
const expectedResult = getMockedPolyResponse();
2465+
// Mocked method
2466+
const mockedMethod = mock(MockedSendMethod);
2467+
// Stub the method
2468+
when(mockedContract.modifyOracle).thenReturn(instance(mockedMethod));
2469+
// Stub the request
2470+
when(
2471+
mockedMethod.sendTransactionAsync(
2472+
mockedParams.fundRaiseType,
2473+
mockedParams.oracleAddress,
2474+
mockedParams.txData,
2475+
mockedParams.safetyFactor,
2476+
),
2477+
).thenResolve(expectedResult);
2478+
2479+
// Real call
2480+
const result = await target.modifyOracle(mockedParams);
2481+
2482+
// Result expectation
2483+
expect(result).toBe(expectedResult);
2484+
// Verifications
2485+
verify(mockedContract.modifyOracle).once();
2486+
verify(
2487+
mockedMethod.sendTransactionAsync(
2488+
mockedParams.fundRaiseType,
2489+
mockedParams.oracleAddress,
2490+
mockedParams.txData,
2491+
mockedParams.safetyFactor,
2492+
),
2493+
).once();
2494+
verify(mockedContract.securityToken).once();
2495+
verify(mockedGetSecurityTokenAddressMethod.callAsync()).once();
2496+
verify(mockedContractFactory.getSecurityTokenContract(expectedSecurityTokenAddress)).once();
2497+
verify(mockedSecurityTokenOwnerMethod.callAsync()).once();
2498+
verify(mockedSecurityTokenContract.owner).once();
2499+
verify(mockedWrapper.getAvailableAddressesAsync()).once();
2500+
});
2501+
});
2502+
24372503
describe('ModifyLimits', () => {
24382504
test('should modifyLimits', async () => {
24392505
// Mock Only Owner and Security Token

src/contract_wrappers/modules/sto/usd_tiered_sto_wrapper.ts

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
import {
2+
GeneralTransferManagerContract,
23
USDTieredSTOContract,
34
USDTieredSTOEventArgs,
45
USDTieredSTOEvents,
56
USDTieredSTOFundsReceivedEventArgs,
67
USDTieredSTOPauseEventArgs,
78
USDTieredSTOReserveTokenMintEventArgs,
8-
USDTieredSTOSetTreasuryWalletEventArgs,
99
USDTieredSTOSetAddressesEventArgs,
1010
USDTieredSTOSetAllowBeneficialInvestmentsEventArgs,
1111
USDTieredSTOSetFundRaiseTypesEventArgs,
1212
USDTieredSTOSetLimitsEventArgs,
1313
USDTieredSTOSetNonAccreditedLimitEventArgs,
1414
USDTieredSTOSetTiersEventArgs,
1515
USDTieredSTOSetTimesEventArgs,
16+
USDTieredSTOSetTreasuryWalletEventArgs,
1617
USDTieredSTOTokenPurchaseEventArgs,
1718
USDTieredSTOUnpauseEventArgs,
18-
GeneralTransferManagerContract,
1919
} from '@polymathnetwork/abi-wrappers';
2020
import { USDTieredSTO } from '@polymathnetwork/contract-artifacts';
2121
import { Web3Wrapper } from '@0x/web3-wrapper';
@@ -256,6 +256,14 @@ interface ModifyLimitsParams extends TxParams {
256256
nonAccreditedLimitUSD: BigNumber;
257257
minimumInvestmentUSD: BigNumber;
258258
}
259+
/**
260+
* @param nonAccreditedLimitUSD max non accredited invets limit
261+
* @param minimumInvestmentUSD overall minimum investment limit
262+
*/
263+
interface ModifyOracleParams extends TxParams {
264+
fundRaiseType: FundRaiseType;
265+
oracleAddress: string;
266+
}
259267

260268
/**
261269
* @param fundRaiseTypes Array of fund raise types to allow
@@ -791,6 +799,23 @@ export default class USDTieredSTOWrapper extends STOWrapper {
791799
);
792800
};
793801

802+
/**
803+
* Modifies oracle
804+
*/
805+
public modifyOracle = async (params: ModifyOracleParams) => {
806+
assert.assert(await this.isCallerTheSecurityTokenOwner(params.txData), 'The caller must be the ST owner');
807+
assert.assert(
808+
params.fundRaiseType === FundRaiseType.POLY || params.fundRaiseType === FundRaiseType.ETH,
809+
'Invalid currency',
810+
);
811+
return (await this.contract).modifyOracle.sendTransactionAsync(
812+
params.fundRaiseType,
813+
params.oracleAddress,
814+
params.txData,
815+
params.safetyFactor,
816+
);
817+
};
818+
794819
/**
795820
* Modifies max non accredited invets limit and overall minimum investment limit
796821
*/

0 commit comments

Comments
 (0)