mirror of
https://github.com/orionprotocol/sdk.git
synced 2026-03-15 14:42:38 +03:00
Semantics improvements
This commit is contained in:
@@ -82,29 +82,29 @@ describe('Orion', () => {
|
||||
expect(orion.referralSystem).toBeInstanceOf(ReferralSystem);
|
||||
expect(orion.unitsArray.length).toBe(4); // eth, bsc, polygon, fantom
|
||||
|
||||
const orionUnitBSC = orion.units[SupportedChainId.BSC_TESTNET];
|
||||
expect(orionUnitBSC?.chainId).toBe(SupportedChainId.BSC_TESTNET);
|
||||
// expect(orionUnitBSC?.env).toBe('testing');
|
||||
const unitBSC = orion.units[SupportedChainId.BSC_TESTNET];
|
||||
expect(unitBSC?.chainId).toBe(SupportedChainId.BSC_TESTNET);
|
||||
// expect(unitBSC?.env).toBe('testing');
|
||||
expect(orion.getSiblingsOf(SupportedChainId.BSC_TESTNET)).toHaveLength(3);
|
||||
expect(orionUnitBSC?.networkCode).toBe('bsc');
|
||||
expect(unitBSC?.networkCode).toBe('bsc');
|
||||
|
||||
const orionUnitRopsten = orion.units[SupportedChainId.ROPSTEN]
|
||||
expect(orionUnitRopsten?.chainId).toBe(SupportedChainId.ROPSTEN);
|
||||
// expect(orionUnitRopsten?.env).toBe('testing');
|
||||
const unitRopsten = orion.units[SupportedChainId.ROPSTEN]
|
||||
expect(unitRopsten?.chainId).toBe(SupportedChainId.ROPSTEN);
|
||||
// expect(unitRopsten?.env).toBe('testing');
|
||||
expect(orion.getSiblingsOf(SupportedChainId.ROPSTEN)).toHaveLength(3);
|
||||
expect(orionUnitRopsten?.networkCode).toBe('eth');
|
||||
expect(unitRopsten?.networkCode).toBe('eth');
|
||||
|
||||
const orionUnitPolygon = orion.units[SupportedChainId.POLYGON_TESTNET];
|
||||
expect(orionUnitPolygon?.chainId).toBe(SupportedChainId.POLYGON_TESTNET);
|
||||
// expect(orionUnitPolygon?.env).toBe('testing');
|
||||
const unitPolygon = orion.units[SupportedChainId.POLYGON_TESTNET];
|
||||
expect(unitPolygon?.chainId).toBe(SupportedChainId.POLYGON_TESTNET);
|
||||
// expect(unitPolygon?.env).toBe('testing');
|
||||
expect(orion.getSiblingsOf(SupportedChainId.POLYGON_TESTNET)).toHaveLength(3);
|
||||
expect(orionUnitPolygon?.networkCode).toBe('polygon');
|
||||
expect(unitPolygon?.networkCode).toBe('polygon');
|
||||
|
||||
const orionUnitFantom = orion.units[SupportedChainId.FANTOM_TESTNET];
|
||||
expect(orionUnitFantom?.chainId).toBe(SupportedChainId.FANTOM_TESTNET);
|
||||
// expect(orionUnitFantom?.env).toBe('testing');
|
||||
const unitFantom = orion.units[SupportedChainId.FANTOM_TESTNET];
|
||||
expect(unitFantom?.chainId).toBe(SupportedChainId.FANTOM_TESTNET);
|
||||
// expect(unitFantom?.env).toBe('testing');
|
||||
expect(orion.getSiblingsOf(SupportedChainId.FANTOM_TESTNET)).toHaveLength(3);
|
||||
expect(orionUnitFantom?.networkCode).toBe('ftm');
|
||||
expect(unitFantom?.networkCode).toBe('ftm');
|
||||
});
|
||||
|
||||
test('Init Orion production', () => {
|
||||
@@ -113,35 +113,35 @@ describe('Orion', () => {
|
||||
expect(orion.referralSystem).toBeInstanceOf(ReferralSystem);
|
||||
expect(orion.unitsArray.length).toBe(5); // eth, bsc, polygon, fantom, okc
|
||||
|
||||
const orionUnitBSC = orion.units[SupportedChainId.BSC];
|
||||
expect(orionUnitBSC?.chainId).toBe(SupportedChainId.BSC);
|
||||
// expect(orionUnitBSC?.env).toBe('production');
|
||||
const unitBSC = orion.units[SupportedChainId.BSC];
|
||||
expect(unitBSC?.chainId).toBe(SupportedChainId.BSC);
|
||||
// expect(unitBSC?.env).toBe('production');
|
||||
expect(orion.getSiblingsOf(SupportedChainId.BSC)).toHaveLength(4);
|
||||
expect(orionUnitBSC?.networkCode).toBe('bsc');
|
||||
expect(unitBSC?.networkCode).toBe('bsc');
|
||||
|
||||
const orionUnitETH = orion.units[SupportedChainId.MAINNET]
|
||||
expect(orionUnitETH?.chainId).toBe(SupportedChainId.MAINNET);
|
||||
// expect(orionUnitETH?.env).toBe('production');
|
||||
const unitETH = orion.units[SupportedChainId.MAINNET]
|
||||
expect(unitETH?.chainId).toBe(SupportedChainId.MAINNET);
|
||||
// expect(unitETH?.env).toBe('production');
|
||||
expect(orion.getSiblingsOf(SupportedChainId.MAINNET)).toHaveLength(4);
|
||||
expect(orionUnitETH?.networkCode).toBe('eth');
|
||||
expect(unitETH?.networkCode).toBe('eth');
|
||||
|
||||
const orionUnitPolygon = orion.units[SupportedChainId.POLYGON];
|
||||
expect(orionUnitPolygon?.chainId).toBe(SupportedChainId.POLYGON);
|
||||
// expect(orionUnitPolygon?.env).toBe('production');
|
||||
const unitPolygon = orion.units[SupportedChainId.POLYGON];
|
||||
expect(unitPolygon?.chainId).toBe(SupportedChainId.POLYGON);
|
||||
// expect(unitPolygon?.env).toBe('production');
|
||||
expect(orion.getSiblingsOf(SupportedChainId.POLYGON)).toHaveLength(4);
|
||||
expect(orionUnitPolygon?.networkCode).toBe('polygon');
|
||||
expect(unitPolygon?.networkCode).toBe('polygon');
|
||||
|
||||
const orionUnitFantom = orion.units[SupportedChainId.FANTOM_OPERA];
|
||||
expect(orionUnitFantom?.chainId).toBe(SupportedChainId.FANTOM_OPERA);
|
||||
// expect(orionUnitFantom?.env).toBe('production');
|
||||
const unitFantom = orion.units[SupportedChainId.FANTOM_OPERA];
|
||||
expect(unitFantom?.chainId).toBe(SupportedChainId.FANTOM_OPERA);
|
||||
// expect(unitFantom?.env).toBe('production');
|
||||
expect(orion.getSiblingsOf(SupportedChainId.FANTOM_OPERA)).toHaveLength(4);
|
||||
expect(orionUnitFantom?.networkCode).toBe('ftm');
|
||||
expect(unitFantom?.networkCode).toBe('ftm');
|
||||
|
||||
const orionUnitOKC = orion.units[SupportedChainId.OKC];
|
||||
expect(orionUnitOKC?.chainId).toBe(SupportedChainId.OKC);
|
||||
// expect(orionUnitOKC?.env).toBe('production');
|
||||
const unitOKC = orion.units[SupportedChainId.OKC];
|
||||
expect(unitOKC?.chainId).toBe(SupportedChainId.OKC);
|
||||
// expect(unitOKC?.env).toBe('production');
|
||||
expect(orion.getSiblingsOf(SupportedChainId.OKC)).toHaveLength(4);
|
||||
expect(orionUnitOKC?.networkCode).toBe('okc');
|
||||
expect(unitOKC?.networkCode).toBe('okc');
|
||||
});
|
||||
|
||||
test('Init Orion custom', async () => {
|
||||
@@ -153,8 +153,8 @@ describe('Orion', () => {
|
||||
throw new Error('Server port is undefined');
|
||||
}
|
||||
|
||||
const orionBlockchainAPI = `http://localhost:${server0.port}`;
|
||||
const orionAggregatorAPI = `http://localhost:${server1.port}`;
|
||||
const blockchainServiceAPI = `http://localhost:${server0.port}`;
|
||||
const aggregatorAPI = `http://localhost:${server1.port}`;
|
||||
const orionPriceFeedAPI = `http://localhost:${server2.port}`;
|
||||
|
||||
const orion = new Orion({
|
||||
@@ -166,11 +166,11 @@ describe('Orion', () => {
|
||||
chainId: SupportedChainId.MAINNET,
|
||||
nodeJsonRpc: 'https://cloudflare-eth.com/',
|
||||
services: {
|
||||
orionBlockchain: {
|
||||
http: orionBlockchainAPI,
|
||||
blockchainService: {
|
||||
http: blockchainServiceAPI,
|
||||
},
|
||||
orionAggregator: {
|
||||
http: orionAggregatorAPI + '/backend',
|
||||
aggregator: {
|
||||
http: aggregatorAPI + '/backend',
|
||||
ws: `http://localhost:${server1.port}/v1`,
|
||||
},
|
||||
priceFeed: {
|
||||
@@ -181,28 +181,28 @@ describe('Orion', () => {
|
||||
}
|
||||
});
|
||||
|
||||
const [orionUnit] = orion.unitsArray;
|
||||
if (!orionUnit) {
|
||||
const [unit] = orion.unitsArray;
|
||||
if (!unit) {
|
||||
throw new Error('Orion unit is not defined');
|
||||
}
|
||||
expect(orion.referralSystem).toBeInstanceOf(ReferralSystem);
|
||||
expect(orion.unitsArray.length).toBe(1); // eth
|
||||
expect(orion.referralSystem.api).toBe('https://referral-api.orionprotocol.io');
|
||||
expect(orionUnit.chainId).toBe(SupportedChainId.MAINNET);
|
||||
// expect(orionUnit.env).toBeUndefined();
|
||||
// expect(orion.units[0]?.orionAggregator.api).toBe('http://localhost:3001');
|
||||
expect(orionUnit.orionAggregator.ws.api).toBe(`ws://localhost:${server1.port}/v1`);
|
||||
expect(orionUnit.orionBlockchain.api).toBe(orionBlockchainAPI);
|
||||
expect(orionUnit.priceFeed.api).toBe(orionPriceFeedAPI + '/price-feed');
|
||||
expect(orionUnit.provider.connection.url).toBe('https://cloudflare-eth.com/');
|
||||
expect(unit.chainId).toBe(SupportedChainId.MAINNET);
|
||||
// expect(unit.env).toBeUndefined();
|
||||
// expect(orion.units[0]?.aggregator.api).toBe('http://localhost:3001');
|
||||
expect(unit.aggregator.ws.api).toBe(`ws://localhost:${server1.port}/v1`);
|
||||
expect(unit.blockchainService.api).toBe(blockchainServiceAPI);
|
||||
expect(unit.priceFeed.api).toBe(orionPriceFeedAPI + '/price-feed');
|
||||
expect(unit.provider.connection.url).toBe('https://cloudflare-eth.com/');
|
||||
|
||||
const info = await simpleFetch(orionUnit.orionBlockchain.getInfo)();
|
||||
const info = await simpleFetch(unit.blockchainService.getInfo)();
|
||||
expect(info).toBeDefined();
|
||||
|
||||
const spotData = await simpleFetch(orionUnit.orionAggregator.getPairConfigs)('spot');
|
||||
const spotData = await simpleFetch(unit.aggregator.getPairConfigs)('spot');
|
||||
expect(spotData).toBeDefined();
|
||||
|
||||
const priceData = await simpleFetch(orionUnit.priceFeed.getCandles)(
|
||||
const priceData = await simpleFetch(unit.priceFeed.getCandles)(
|
||||
'BTC-USDT',
|
||||
Math.floor((Date.now() - 1000 * 60 * 60 * 24 * 30) / 1000), // 1 month ago
|
||||
Math.floor(Date.now() / 1000), // now
|
||||
@@ -211,7 +211,7 @@ describe('Orion', () => {
|
||||
expect(priceData).toBeDefined();
|
||||
|
||||
const allTickersDone = await new Promise<boolean>((resolve, reject) => {
|
||||
const { unsubscribe } = orionUnit.priceFeed.ws.subscribe(
|
||||
const { unsubscribe } = unit.priceFeed.ws.subscribe(
|
||||
'allTickers',
|
||||
{
|
||||
callback: () => {
|
||||
@@ -223,7 +223,7 @@ describe('Orion', () => {
|
||||
)
|
||||
const timeout = setTimeout(() => {
|
||||
unsubscribe();
|
||||
reject(new Error(`Timeout: ${orionUnit.priceFeed.wsUrl}`));
|
||||
reject(new Error(`Timeout: ${unit.priceFeed.wsUrl}`));
|
||||
}, 10000);
|
||||
});
|
||||
expect(allTickersDone).toBe(true);
|
||||
@@ -244,24 +244,24 @@ describe('Orion', () => {
|
||||
}
|
||||
});
|
||||
|
||||
const bscOrionUnit = orion.units[SupportedChainId.BSC_TESTNET]
|
||||
expect(bscOrionUnit?.provider.connection.url).toBe('https://data-seed-prebsc-1-s1.binance.org:8545/');
|
||||
const bscUnit = orion.units[SupportedChainId.BSC_TESTNET]
|
||||
expect(bscUnit?.provider.connection.url).toBe('https://data-seed-prebsc-1-s1.binance.org:8545/');
|
||||
expect(orion.referralSystem.api).toBe('https://zxczxc.orionprotocol.io');
|
||||
});
|
||||
|
||||
test('Orion Responses', async () => {
|
||||
const orion = new Orion('testing');
|
||||
|
||||
const orionUnitBSC = orion.units[SupportedChainId.BSC_TESTNET]
|
||||
if (!orionUnitBSC) {
|
||||
const unitBSC = orion.units[SupportedChainId.BSC_TESTNET]
|
||||
if (!unitBSC) {
|
||||
throw new Error('Orion unit not found');
|
||||
}
|
||||
const info = await simpleFetch(orionUnitBSC.orionBlockchain.getInfo)();
|
||||
const info = await simpleFetch(unitBSC.blockchainService.getInfo)();
|
||||
expect(info).toBeDefined();
|
||||
expect(info.chainId).toBe(97);
|
||||
expect(info.chainName).toBe('bsc-testnet');
|
||||
|
||||
const pairConfigs = await simpleFetch(orionUnitBSC.orionAggregator.getPairConfigs)('spot');
|
||||
const pairConfigs = await simpleFetch(unitBSC.aggregator.getPairConfigs)('spot');
|
||||
expect(pairConfigs).toBeDefined();
|
||||
expect(pairConfigs.length).toBeGreaterThan(0);
|
||||
|
||||
@@ -270,17 +270,17 @@ describe('Orion', () => {
|
||||
reject(new Error('Timeout'));
|
||||
}, 10000);
|
||||
|
||||
orionUnitBSC.orionAggregator.ws.subscribe('aobus', {
|
||||
unitBSC.aggregator.ws.subscribe('aobus', {
|
||||
payload: 'ORN-USDT',
|
||||
callback: () => {
|
||||
resolve(true);
|
||||
orionUnitBSC.orionAggregator.ws.destroy();
|
||||
unitBSC.aggregator.ws.destroy();
|
||||
clearTimeout(timeout);
|
||||
}
|
||||
})
|
||||
});
|
||||
expect(aobusDone).toBe(true);
|
||||
const candles = await simpleFetch(orionUnitBSC.priceFeed.getCandles)(
|
||||
const candles = await simpleFetch(unitBSC.priceFeed.getCandles)(
|
||||
'BTC-USDT',
|
||||
Math.floor((Date.now() - 1000 * 60 * 60 * 24 * 30) / 1000), // 1 month ago
|
||||
Math.floor(Date.now() / 1000), // now
|
||||
@@ -293,7 +293,7 @@ describe('Orion', () => {
|
||||
reject(new Error('Timeout'));
|
||||
}, 10000);
|
||||
|
||||
const { unsubscribe } = orionUnitBSC.priceFeed.ws.subscribe(
|
||||
const { unsubscribe } = unitBSC.priceFeed.ws.subscribe(
|
||||
'allTickers',
|
||||
{
|
||||
callback: () => {
|
||||
@@ -306,9 +306,9 @@ describe('Orion', () => {
|
||||
});
|
||||
expect(allTickersDone).toBe(true);
|
||||
|
||||
const blockNumber = await orionUnitBSC.provider.getBlockNumber();
|
||||
const blockNumber = await unitBSC.provider.getBlockNumber();
|
||||
expect(blockNumber).toBeDefined();
|
||||
const network = await orionUnitBSC.provider.getNetwork();
|
||||
const network = await unitBSC.provider.getNetwork();
|
||||
expect(network.chainId).toBe(97);
|
||||
|
||||
const zeroAddressWithout0x = ethers.constants.AddressZero.slice(2);
|
||||
@@ -319,11 +319,11 @@ describe('Orion', () => {
|
||||
|
||||
test('Get Orion unit by networkCode', () => {
|
||||
const orionTesting = new Orion('testing');
|
||||
const orionUnitBSCTesting = orionTesting.getUnit('bsc');
|
||||
expect(orionUnitBSCTesting.chainId).toBe(SupportedChainId.BSC_TESTNET);
|
||||
const unitBSCTesting = orionTesting.getUnit('bsc');
|
||||
expect(unitBSCTesting.chainId).toBe(SupportedChainId.BSC_TESTNET);
|
||||
|
||||
const orionMainnet = new Orion('production');
|
||||
const orionUnitBSCMainnet = orionMainnet.getUnit('bsc');
|
||||
expect(orionUnitBSCMainnet.chainId).toBe(SupportedChainId.BSC);
|
||||
const unitBSCMainnet = orionMainnet.getUnit('bsc');
|
||||
expect(unitBSCMainnet.chainId).toBe(SupportedChainId.BSC);
|
||||
})
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user