Skip to content

Commit

Permalink
conflicts resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
david weil committed Jul 12, 2024
1 parent 8fcf255 commit 4adc403
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 27 deletions.
58 changes: 36 additions & 22 deletions test/alexSDK.mock-externals.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,32 +26,32 @@ const stxAddress = 'SM2MARAVW6BEJCD13YV2RHGYHQWT7TDDNMNRB1MVT';

describe('AlexSDK - mock externals', () => {
beforeEach(() => {
fetchMock.get('https://alex-sdk-api.alexlab.co', 500);
fetchMock.get(configs.SDK_API_HOST, 500);
});
afterEach(() => {
fetchMock.restore();
});

it('Attempt to Get Latest Prices with incorrect Alex SDK Data', async () => {
await expect(sdk.getLatestPrices()).rejects.toThrow(
'Failed to fetch token mappings',
'Failed to fetch token mappings'
);
}, 10000);
it('Attempt to Get Fee with incorrect Alex SDK Data', async () => {
await expect(sdk.getFeeRate(tokenAlex, Currency.STX)).rejects.toThrow(
'Failed to fetch token mappings',
'Failed to fetch token mappings'
);
}, 10000);

it('Attempt to Get Router with incorrect Alex SDK Data', async () => {
await expect(sdk.getRouter(tokenAlex, Currency.STX)).rejects.toThrow(
'Failed to fetch token mappings',
'Failed to fetch token mappings'
);
}, 10000);

it('Attempt to Get Amount with incorrect Alex SDK Data', async () => {
await expect(
sdk.getAmountTo(Currency.STX, BigInt(2) * BigInt(1e8), tokenWUSDA),
sdk.getAmountTo(Currency.STX, BigInt(2) * BigInt(1e8), tokenWUSDA)
).rejects.toThrow('Failed to fetch token mappings');
}, 10000);

Expand All @@ -62,34 +62,34 @@ describe('AlexSDK - mock externals', () => {
tokenAlex,
tokenWUSDA,
BigInt(2) * BigInt(1e8),
BigInt(0),
),
BigInt(0)
)
).rejects.toThrow('Failed to fetch token mappings');
}, 10000);

it('Attempt to Get Latest Prices with incorrect Alex SDK Data', async () => {
await expect(sdk.getLatestPrices()).rejects.toThrow(
'Failed to fetch token mappings',
'Failed to fetch token mappings'
);
}, 10000);

it('Attempt to Get Balances with incorrect Alex SDK Data', async () => {
const stxAddress = 'SM2MARAVW6BEJCD13YV2RHGYHQWT7TDDNMNRB1MVT';
await expect(sdk.getBalances(stxAddress)).rejects.toThrow(
'Failed to fetch token mappings',
'Failed to fetch token mappings'
);
}, 10000);

it('Attempt to Fetch Swappable Currency with incorrect Alex SDK Data', async () => {
await expect(sdk.fetchSwappableCurrency()).rejects.toThrow(
'Failed to fetch token mappings',
'Failed to fetch token mappings'
);
}, 10000);
});

describe('AlexSDK - mock externals - API_HOST', () => {
describe('AlexSDK - mock externals - BACKEND_API_HOST', () => {
beforeEach(() => {
fetchMock.get(`${configs.API_HOST}/v2/public/token-prices`, {
fetchMock.get(`${configs.BACKEND_API_HOST}/v2/public/token-prices`, {
status: 500,
body: 'Internal Server Error',
});
Expand All @@ -100,33 +100,47 @@ describe('AlexSDK - mock externals - API_HOST', () => {
});

it('Attempt to get token prices with incorrect data', async () => {
await expect(getPrices(tokenMappings)).rejects.toThrow('Failed to fetch token mappings');
expect(fetchMock.calls(`${configs.API_HOST}/v2/public/token-prices`).length).toBe(1);
await expect(getPrices(tokenMappings)).rejects.toThrow(
'Failed to fetch token mappings'
);
expect(
fetchMock.calls(`${configs.BACKEND_API_HOST}/v2/public/token-prices`)
.length
).toBe(1);
}, 10000);
});

describe('Transfer Factory', () => {
it('Throws error in Transfer Factory', () => {
const transfer = transferFactory(tokenMappings);
expect(() => transfer(stxAddress, tokenAlex, BigInt(1000))).toThrow('Token mapping not found');
expect(() => transfer(stxAddress, tokenAlex, BigInt(1000))).toThrow(
'Token mapping not found'
);
});
});

describe('AlexSDK - mock externals - STACKS_API_HOST', () => {
beforeEach(() => {
fetchMock.get(`${configs.STACKS_API_HOST}/extended/v1/address/${stxAddress}/balances`, {
status: 500,
body: 'Internal Server Error',
});
fetchMock.get(
`${configs.STACKS_API_HOST}/extended/v1/address/${stxAddress}/balances`,
{
status: 500,
body: 'Internal Server Error',
}
);
});

afterEach(() => {
fetchMock.restore();
});

it('Attempt to Get Balances with incorrect data', async () => {
await expect(fetchBalanceForAccount(stxAddress, tokenMappings)).rejects.
toThrow(new
SyntaxError('Unexpected token \'I\', "Internal S"... is not valid JSON'));
await expect(
fetchBalanceForAccount(stxAddress, tokenMappings)
).rejects.toThrow(
new SyntaxError(
'Unexpected token \'I\', "Internal S"... is not valid JSON'
)
);
}, 10000);
});
8 changes: 3 additions & 5 deletions test/alexSDK.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe('AlexSDK', () => {
}, 10000);

it('Verify response of getFeeRate function (custom route)', async () => {
const customRoute = await sdk.getRoute(tokenAlex, Currency.STX);
const customRoute = await sdk.getRoute(tokenAlex, Currency.STX);
const result = await sdk.getFeeRate(tokenAlex, Currency.STX, customRoute);
expect(typeof result).toBe('bigint');
expect(result >= BigInt(0)).toBeTruthy();
Expand Down Expand Up @@ -235,10 +235,8 @@ describe('AlexSDK', () => {
expect(balances).toBeDefined();
expect(typeof balances).toBe('object');
Object.keys(balances).forEach((currency) => {

expect(typeof balances[currency as Currency]).toBe('bigint');
}
);
expect(typeof balances[currency as Currency]).toBe('bigint');
});
});

it('Attempt to get balances with invalid address', async () => {
Expand Down

0 comments on commit 4adc403

Please sign in to comment.