Skip to content

Commit

Permalink
test: pair info and staking info parsers
Browse files Browse the repository at this point in the history
  • Loading branch information
AustinWoetzel committed Oct 31, 2023
1 parent 9eb2f33 commit 32fea02
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 149 deletions.
20 changes: 18 additions & 2 deletions src/contracts/services/swap.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,30 @@ import {
parseFactoryConfig,
parseFactoryPairs,
parsePairConfig,
parsePairInfo,
parseStakingInfo,
queryFactoryConfig$,
queryFactoryPairs$,
queryPairConfig$,
} from '~/contracts/services/swap';
import factoryConfigResponse from '~/test/mocks/swap/factoryConfig.json';
import factoryPairsResponse from '~/test/mocks/swap/factoryPairs.json';
import pairConfigResponse from '~/test/mocks/swap/pairConfig.json';
import pairInfoResponse from '~/test/mocks/swap/pairInfoResponse.json';
import stakingInfoResponse from '~/test/mocks/swap/stakingConfig.json';
import { of } from 'rxjs';
import {
FactoryConfigResponse,
FactoryPairsResponse,
PairConfigResponse,
PairInfoResponse,
StakingConfigResponse,
} from '~/types/contracts/swap/response';
import { factoryConfigParsed } from '~/test/mocks/swap/factoryConfigParsed';
import { factoryPairsParsed } from '~/test/mocks/swap/factoryPairsParsed';
import { pairConfigParsed } from '~/test/mocks/swap/pairConfigParsed';
import { pairInfoParsed } from '~/test/mocks/swap/pairInfoParsed';
import { stakingConfigParsed } from '~/test/mocks/swap/stakingConfigParsed';

const sendSecretClientContractQuery$ = vi.hoisted(() => vi.fn());

Expand Down Expand Up @@ -61,6 +69,16 @@ test('it can parse the pair config response', () => {
expect(parsePairConfig(pairConfigResponse as PairConfigResponse)).toStrictEqual(pairConfigParsed);
});

test('it can parse the pair info response', () => {
expect(parsePairInfo(pairInfoResponse as PairInfoResponse)).toStrictEqual(pairInfoParsed);
});

test('it can parse the staking info response', () => {
expect(parseStakingInfo(
stakingInfoResponse as StakingConfigResponse,
)).toStrictEqual(stakingConfigParsed);
});

test('it can call the query factory config service', () => {
sendSecretClientContractQuery$.mockReturnValue(of(factoryConfigResponse));

Expand All @@ -86,8 +104,6 @@ test('it can call the query factory config service', () => {
});

expect(output).toStrictEqual(factoryConfigParsed);

vi.doUnmock('~/client/services/clientServices');
});

test('it can call the query factory pairs service', () => {
Expand Down
10 changes: 6 additions & 4 deletions src/contracts/services/swap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ function parsePairConfig(response: PairConfigResponse): PairConfig {
/**
* parses the single pair info response
*/
function parsePairInfoResponse(
function parsePairInfo(
response: PairInfoResponse,
): PairInfo {
const { get_pair_info: pairInfo } = response;
Expand Down Expand Up @@ -199,13 +199,13 @@ const parseBatchQueryPairInfoResponse = (
response: BatchQueryParsedResponse,
): BatchPairsInfo => response.map((item) => ({
pairContractAddress: item.id as string,
pairInfo: parsePairInfoResponse(item.response),
pairInfo: parsePairInfo(item.response),
}));

/**
* parses the single staking info response
*/
function parseStakingInfoResponse(response: StakingConfigResponse): StakingInfo {
function parseStakingInfo(response: StakingConfigResponse): StakingInfo {
const {
lp_token: lpToken,
amm_pair: ammPair,
Expand Down Expand Up @@ -251,7 +251,7 @@ const parseBatchQueryStakingInfoResponse = (
response: BatchQueryParsedResponse,
): BatchStakingInfo => response.map((item) => ({
stakingContractAddress: item.id as string,
stakingInfo: parseStakingInfoResponse(item.response),
stakingInfo: parseStakingInfo(item.response),
}));

/**
Expand Down Expand Up @@ -410,6 +410,8 @@ export {
parseFactoryConfig,
parseFactoryPairs,
parsePairConfig,
parsePairInfo,
parseStakingInfo,
queryFactoryConfig$,
queryFactoryPairs$,
queryPairConfig$,
Expand Down
42 changes: 42 additions & 0 deletions src/test/mocks/swap/pairInfoParsed.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { PairInfo } from '~/types/contracts/swap/model';

const pairInfoParsed: PairInfo = {
token0Amount: '3218142110921700343525',
token1Amount: '6366867216411002795778',
lpTokenAmount: '4783477681443035000237',
priceRatio: '1.08921896906564985',
pairSettings: {
lpFee: 0.0005,
daoFee: 0.0005,
stableLpFee: 0.0005,
stableDaoFee: 0.0005,
daoContractAddress: 'secret1g86l6j393vtzd9jmmxu57mx4q8y9gza0tncjpp',
stableParams: {
alpha: '150',
gamma1: '6',
gamma2: '50',
oracle: {
address: 'secret10n2xl5jmez6r9umtdrth78k0vwmce0l5m9f5dm',
codeHash: '32c4710842b97a526c243a68511b15f58d6e72a388af38a7221ff3244c754e91',
},
token0Data: {
oracleKey: 'Stableswap Rate Base',
decimals: 18,
},
token1Data: {
oracleKey: 'Stride INJ Rate',
decimals: 18,
},
minTradeSizeXForY: '0.000000001',
minTradeSizeYForX: '0.000000001',
maxPriceImpactAllowed: '1000',
customIterationControls: null,
},

},
contractVersion: 1,
};

export {
pairInfoParsed,
};
165 changes: 22 additions & 143 deletions src/test/mocks/swap/stakingConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,148 +14,27 @@
},
"total_amount_staked":"160118027695",
"reward_tokens":[
{
"token":{
"address":"secret153wu605vvp934xhd4k9dtd640zsep5jkesstdm",
"code_hash":"638a3e1d50175fbcb8373cf801565283e3eb23d88a9b7b7f99fcc5eb1e6b561e"
},
"decimals":8,
"reward_per_second":"231481",
"reward_per_staked_token":"74",
"valid_to":1688490000,
"last_updated":1688490000
},
{
"token":{
"address":"secret153wu605vvp934xhd4k9dtd640zsep5jkesstdm",
"code_hash":"638a3e1d50175fbcb8373cf801565283e3eb23d88a9b7b7f99fcc5eb1e6b561e"
},
"decimals":8,
"reward_per_second":"231481",
"reward_per_staked_token":"2",
"valid_to":1690305188,
"last_updated":1690305188
},
{
"token":{
"address":"secret153wu605vvp934xhd4k9dtd640zsep5jkesstdm",
"code_hash":"638a3e1d50175fbcb8373cf801565283e3eb23d88a9b7b7f99fcc5eb1e6b561e"
},
"decimals":8,
"reward_per_second":"244212",
"reward_per_staked_token":"3",
"valid_to":1692896400,
"last_updated":1692896400
},
{
"token":{
"address":"secret153wu605vvp934xhd4k9dtd640zsep5jkesstdm",
"code_hash":"638a3e1d50175fbcb8373cf801565283e3eb23d88a9b7b7f99fcc5eb1e6b561e"
},
"decimals":8,
"reward_per_second":"244201",
"reward_per_staked_token":"3",
"valid_to":1695315600,
"last_updated":1695315600
},
{
"token":{
"address":"secret153wu605vvp934xhd4k9dtd640zsep5jkesstdm",
"code_hash":"638a3e1d50175fbcb8373cf801565283e3eb23d88a9b7b7f99fcc5eb1e6b561e"
},
"decimals":8,
"reward_per_second":"244201",
"reward_per_staked_token":"1",
"valid_to":1696093200,
"last_updated":1696093200
},
{
"token":{
"address":"secret153wu605vvp934xhd4k9dtd640zsep5jkesstdm",
"code_hash":"638a3e1d50175fbcb8373cf801565283e3eb23d88a9b7b7f99fcc5eb1e6b561e"
},
"decimals":8,
"reward_per_second":"244212",
"reward_per_staked_token":"1",
"valid_to":1697025600,
"last_updated":1697025600
},
{
"token":{
"address":"secret153wu605vvp934xhd4k9dtd640zsep5jkesstdm",
"code_hash":"638a3e1d50175fbcb8373cf801565283e3eb23d88a9b7b7f99fcc5eb1e6b561e"
},
"decimals":8,
"reward_per_second":"244201",
"reward_per_staked_token":"1",
"valid_to":1697907600,
"last_updated":1697907600
},
{
"token":{
"address":"secret153wu605vvp934xhd4k9dtd640zsep5jkesstdm",
"code_hash":"638a3e1d50175fbcb8373cf801565283e3eb23d88a9b7b7f99fcc5eb1e6b561e"
},
"decimals":8,
"reward_per_second":"202546",
"reward_per_staked_token":"0",
"valid_to":1699297200,
"last_updated":1698415408
},
{
"token":{
"address":"secret1rfhgs3ryqt7makakr2qw9zsqq4h5wdqawfa2aa",
"code_hash":"638a3e1d50175fbcb8373cf801565283e3eb23d88a9b7b7f99fcc5eb1e6b561e"
},
"decimals":6,
"reward_per_second":"2314",
"reward_per_staked_token":"0",
"valid_to":1689778800,
"last_updated":1689778800
},
{
"token":{
"address":"secret1rfhgs3ryqt7makakr2qw9zsqq4h5wdqawfa2aa",
"code_hash":"638a3e1d50175fbcb8373cf801565283e3eb23d88a9b7b7f99fcc5eb1e6b561e"
},
"decimals":6,
"reward_per_second":"2314",
"reward_per_staked_token":"0",
"valid_to":1692381600,
"last_updated":1692381600
},
{
"token":{
"address":"secret1rfhgs3ryqt7makakr2qw9zsqq4h5wdqawfa2aa",
"code_hash":"638a3e1d50175fbcb8373cf801565283e3eb23d88a9b7b7f99fcc5eb1e6b561e"
},
"decimals":6,
"reward_per_second":"2314",
"reward_per_staked_token":"0",
"valid_to":1694970000,
"last_updated":1694970000
},
{
"token":{
"address":"secret1rfhgs3ryqt7makakr2qw9zsqq4h5wdqawfa2aa",
"code_hash":"638a3e1d50175fbcb8373cf801565283e3eb23d88a9b7b7f99fcc5eb1e6b561e"
},
"decimals":6,
"reward_per_second":"1157",
"reward_per_staked_token":"0",
"valid_to":1698339600,
"last_updated":1698339600
},
{
"token":{
"address":"secret1rfhgs3ryqt7makakr2qw9zsqq4h5wdqawfa2aa",
"code_hash":"638a3e1d50175fbcb8373cf801565283e3eb23d88a9b7b7f99fcc5eb1e6b561e"
},
"decimals":6,
"reward_per_second":"1157",
"reward_per_staked_token":"0",
"valid_to":1700935200,
"last_updated":1698415408
}
{
"token":{
"address":"secret153wu605vvp934xhd4k9dtd640zsep5jkesstdm",
"code_hash":"638a3e1d50175fbcb8373cf801565283e3eb23d88a9b7b7f99fcc5eb1e6b561e"
},
"decimals":8,
"reward_per_second":"231481",
"reward_per_staked_token":"74",
"valid_to":1688490000,
"last_updated":1688490000
},
{
"token":{
"address":"secret153wu605vvp934xhd4k9dtd640zsep5jkesstdm",
"code_hash":"638a3e1d50175fbcb8373cf801565283e3eb23d88a9b7b7f99fcc5eb1e6b561e"
},
"decimals":8,
"reward_per_second":"231481",
"reward_per_staked_token":"2",
"valid_to":1690305188,
"last_updated":1690305188
}
]
}
42 changes: 42 additions & 0 deletions src/test/mocks/swap/stakingConfigParsed.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { StakingInfo } from '~/types/contracts/swap/model';

const stakingConfigParsed: StakingInfo = {
lpTokenContract: {
address: 'secret1u3mp0jtmszw0xn7s5dn69gl0332lx9f60kt8xk',
codeHash: 'b0c2048d28a0ca0b92274549b336703622ecb24a8c21f417e70c03aa620fcd7b',
},
pairContractAddress: 'secret14xsrnkfv5r5qh7m3csps72z9vg49tkgf7an0d5',
adminAuthContract: {
address: 'secret1hcz23784w6znz3cmqml7ha8g4x6s7qq9v93mtl',
codeHash: '6666d046c049b04197326e6386b3e65dbe5dd9ae24266c62b333876ce57adaa8',
},
queryAuthContract: {
address: 'secret1nd56rl8n63auxmwekkyqqq030paeqpap3dmw0w',
codeHash: '1b7a863cd327d24323bfd067dbb975e03dc8a51edee55717ad6b9849b3d35234',
},
totalStakedAmount: '160118027695',
rewardTokens: [{
token: {
address: 'secret153wu605vvp934xhd4k9dtd640zsep5jkesstdm',
codeHash: '638a3e1d50175fbcb8373cf801565283e3eb23d88a9b7b7f99fcc5eb1e6b561e',
},
rewardPerSecond: '231481',
rewardPerStakedToken: '74',
validTo: 1688490000,
lastUpdated: 1688490000,
},
{
token: {
address: 'secret153wu605vvp934xhd4k9dtd640zsep5jkesstdm',
codeHash: '638a3e1d50175fbcb8373cf801565283e3eb23d88a9b7b7f99fcc5eb1e6b561e',
},
rewardPerSecond: '231481',
rewardPerStakedToken: '2',
validTo: 1690305188,
lastUpdated: 1690305188,
}],
};

export {
stakingConfigParsed,
};

0 comments on commit 32fea02

Please sign in to comment.