Skip to content

Commit

Permalink
chore: state tests
Browse files Browse the repository at this point in the history
  • Loading branch information
stackchain committed Oct 22, 2023
1 parent 54480eb commit 350915f
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 69 deletions.
1 change: 0 additions & 1 deletion packages/swap/src/helpers/prices/getPriceAfterFee.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,5 +123,4 @@ describe('getPriceAfterFee', () => {
const expected = new BigNumber(10000000)
expect(result).toStrictEqual(expected)
})

})
146 changes: 78 additions & 68 deletions packages/swap/src/translators/reactjs/state/state.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,85 +46,95 @@ describe('State Actions', () => {
expect(state).toEqual(mockSwapStateDefault)
})

it('OrderTypeChanged', () => {
const stateTypeChanged: SwapState = {
...mockSwapStateDefault,
orderData: {
...mockSwapStateDefault.orderData,
amounts: {
sell: {
quantity: '10000',
tokenId: 'tokenA',
},
buy: {
quantity: '0',
tokenId: 'tokenB',
describe('OrderTypeChanged', () => {
it('change to limit', () => {
const stateTypeChanged: SwapState = {
...mockSwapStateDefault,
orderData: {
...mockSwapStateDefault.orderData,
amounts: {
sell: {
quantity: '10000',
tokenId: 'tokenA',
},
buy: {
quantity: '0',
tokenId: 'tokenB',
},
},
},
limitPrice: undefined,
slippage: 0,
type: 'market',
selectedPoolId: undefined,
selectedPoolCalculation: undefined,
limitPrice: undefined,
slippage: 0,
type: 'market',
selectedPoolId: undefined,
selectedPoolCalculation: undefined,

pools: [],
calculations: [],
bestPoolCalculation: undefined,
},
}
pools: [],
calculations: [],
bestPoolCalculation: undefined,
},
}

const action: SwapCreateOrderAction = {
type: SwapCreateOrderActionType.OrderTypeChanged,
orderType: 'limit',
}
const expectedState = produce(stateTypeChanged, (draft) => {
draft.orderData.type = 'limit'
const action: SwapCreateOrderAction = {
type: SwapCreateOrderActionType.OrderTypeChanged,
orderType: 'limit',
}
const expectedState = produce(stateTypeChanged, (draft) => {
draft.orderData.type = 'limit'
})
const state = combinedSwapReducers(expectedState, action)
expect(state).toEqual(expectedState)
})
const state = combinedSwapReducers(expectedState, action)
expect(state).toEqual(expectedState)
})

it('OrderTypeChanged limit', () => {
const stateTypeChanged: SwapState = {
...mockSwapStateDefault,
orderData: {
...mockSwapStateDefault.orderData,
amounts: {
sell: {
quantity: '10000',
tokenId: 'tokenA',
},
buy: {
quantity: '0',
tokenId: 'tokenB',
it('change to limit and back to market', () => {
const stateTypeChanged: SwapState = {
...mockSwapStateDefault,
orderData: {
...mockSwapStateDefault.orderData,
amounts: {
sell: {
quantity: '10000',
tokenId: 'tokenA',
},
buy: {
quantity: '0',
tokenId: 'tokenB',
},
},
limitPrice: undefined,
slippage: 0,
type: 'market',
selectedPoolId: undefined,
selectedPoolCalculation: undefined,

pools: [],
calculations: [],
bestPoolCalculation: undefined,
},
limitPrice: undefined,
slippage: 0,
type: 'market',
selectedPoolId: undefined,
selectedPoolCalculation: undefined,
}
const stateAfterPools = combinedSwapReducers(stateTypeChanged, {
type: SwapCreateOrderActionType.PoolPairsChanged,
pools: mocks.mockedPools6,
})

pools: [],
calculations: [],
bestPoolCalculation: undefined,
},
}
const stateAfterPools = combinedSwapReducers(stateTypeChanged, {
type: SwapCreateOrderActionType.PoolPairsChanged,
pools: mocks.mockedPools6,
})
const actionLimit: SwapCreateOrderAction = {
type: SwapCreateOrderActionType.OrderTypeChanged,
orderType: 'limit',
}

const actionLimit: SwapCreateOrderAction = {
type: SwapCreateOrderActionType.OrderTypeChanged,
orderType: 'limit',
}
const state = combinedSwapReducers(stateAfterPools, actionLimit)

const state = combinedSwapReducers(stateAfterPools, actionLimit)
expect(state.orderData.type).toBe('limit')
expect(state.orderData.limitPrice).toBe('0.5')
expect(state.orderData.amounts.buy.quantity).toBe('198')

expect(state.orderData.type).toBe('limit')
expect(state.orderData.limitPrice).toBe('0.5')
expect(state.orderData.amounts.buy.quantity).toBe('198')
const actionMarket: SwapCreateOrderAction = {
type: SwapCreateOrderActionType.OrderTypeChanged,
orderType: 'market',
}

const stateBack = combinedSwapReducers(state, actionMarket)
expect(stateBack.orderData.type).toBe('market')
})
})

it('UnsignedTxChanged', () => {
Expand Down

0 comments on commit 350915f

Please sign in to comment.