Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
interface
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
LuckySwap
interface
Commits
709fad08
Unverified
Commit
709fad08
authored
Apr 04, 2023
by
eddie
Committed by
GitHub
Apr 04, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test: add unit test coverage to some redux state files (#6285)
parent
573f4c87
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
281 additions
and
1 deletion
+281
-1
hooks.test.tsx
src/state/user/hooks.test.tsx
+21
-0
reducer.test.ts
src/state/user/reducer.test.ts
+198
-1
hooks.test.tsx
src/state/wallets/hooks.test.tsx
+22
-0
reducer.test.ts
src/state/wallets/reducer.test.ts
+40
-0
No files found.
src/state/user/hooks.test.tsx
0 → 100644
View file @
709fad08
import
{
USDC_MAINNET
}
from
'
constants/tokens
'
import
{
deserializeToken
,
serializeToken
}
from
'
./hooks
'
describe
(
'
serializeToken
'
,
()
=>
{
it
(
'
serializes the token
'
,
()
=>
{
expect
(
serializeToken
(
USDC_MAINNET
)).
toEqual
({
chainId
:
1
,
decimals
:
6
,
name
:
'
USD//C
'
,
symbol
:
'
USDC
'
,
address
:
'
0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48
'
,
})
})
})
describe
(
'
deserializeToken
'
,
()
=>
{
it
(
'
deserializes the token
'
,
()
=>
{
expect
(
deserializeToken
(
serializeToken
(
USDC_MAINNET
))).
toEqual
(
USDC_MAINNET
)
})
})
src/state/user/reducer.test.ts
View file @
709fad08
...
...
@@ -2,7 +2,33 @@ import { createStore, Store } from 'redux'
import
{
DEFAULT_DEADLINE_FROM_NOW
}
from
'
../../constants/misc
'
import
{
updateVersion
}
from
'
../global/actions
'
import
reducer
,
{
initialState
,
UserState
}
from
'
./reducer
'
import
reducer
,
{
addSerializedPair
,
addSerializedToken
,
initialState
,
updateHideClosedPositions
,
updateHideUniswapWalletBanner
,
updateSelectedWallet
,
updateUserClientSideRouter
,
updateUserDeadline
,
updateUserExpertMode
,
updateUserLocale
,
updateUserSlippageTolerance
,
UserState
,
}
from
'
./reducer
'
function
buildSerializedPair
(
token0Address
:
string
,
token1Address
:
string
,
chainId
:
number
)
{
return
{
token0
:
{
chainId
,
address
:
token0Address
,
},
token1
:
{
chainId
,
address
:
token1Address
,
},
}
}
describe
(
'
swap reducer
'
,
()
=>
{
let
store
:
Store
<
UserState
>
...
...
@@ -30,5 +56,176 @@ describe('swap reducer', () => {
expect
(
store
.
getState
().
userDeadline
).
toEqual
(
DEFAULT_DEADLINE_FROM_NOW
)
expect
(
store
.
getState
().
userSlippageTolerance
).
toEqual
(
'
auto
'
)
})
it
(
'
sets allowed slippage and deadline to auto
'
,
()
=>
{
store
=
createStore
(
reducer
,
{
...
initialState
,
userSlippageTolerance
:
10
,
userSlippageToleranceHasBeenMigratedToAuto
:
undefined
,
}
as
any
)
store
.
dispatch
(
updateVersion
())
expect
(
store
.
getState
().
userSlippageToleranceHasBeenMigratedToAuto
).
toEqual
(
true
)
})
})
describe
(
'
updateSelectedWallet
'
,
()
=>
{
it
(
'
updates the selected wallet
'
,
()
=>
{
store
.
dispatch
(
updateSelectedWallet
({
wallet
:
'
metamask
'
}))
expect
(
store
.
getState
().
selectedWallet
).
toEqual
(
'
metamask
'
)
})
})
describe
(
'
updateUserExpertMode
'
,
()
=>
{
it
(
'
updates the userExpertMode
'
,
()
=>
{
store
.
dispatch
(
updateUserExpertMode
({
userExpertMode
:
true
}))
expect
(
store
.
getState
().
userExpertMode
).
toEqual
(
true
)
})
})
describe
(
'
updateUserLocale
'
,
()
=>
{
it
(
'
updates the userLocale
'
,
()
=>
{
store
.
dispatch
(
updateUserLocale
({
userLocale
:
'
en
'
}))
expect
(
store
.
getState
().
userLocale
).
toEqual
(
'
en
'
)
})
})
describe
(
'
updateUserSlippageTolerance
'
,
()
=>
{
it
(
'
updates the userSlippageTolerance
'
,
()
=>
{
store
.
dispatch
(
updateUserSlippageTolerance
({
userSlippageTolerance
:
'
0.5
'
}))
expect
(
store
.
getState
().
userSlippageTolerance
).
toEqual
(
'
0.5
'
)
})
})
describe
(
'
updateUserDeadline
'
,
()
=>
{
it
(
'
updates the userDeadline
'
,
()
=>
{
store
.
dispatch
(
updateUserDeadline
({
userDeadline
:
5
}))
expect
(
store
.
getState
().
userDeadline
).
toEqual
(
5
)
})
})
describe
(
'
updateUserClientSideRouter
'
,
()
=>
{
it
(
'
updates the userClientSideRouter
'
,
()
=>
{
store
.
dispatch
(
updateUserClientSideRouter
({
userClientSideRouter
:
true
}))
expect
(
store
.
getState
().
userClientSideRouter
).
toEqual
(
true
)
})
})
describe
(
'
updateHideClosedPositions
'
,
()
=>
{
it
(
'
updates the userHideClosedPositions
'
,
()
=>
{
store
.
dispatch
(
updateHideClosedPositions
({
userHideClosedPositions
:
true
}))
expect
(
store
.
getState
().
userHideClosedPositions
).
toEqual
(
true
)
})
})
describe
(
'
updateHideUniswapWalletBanner
'
,
()
=>
{
it
(
'
updates the hideUniswapWalletBanner
'
,
()
=>
{
store
.
dispatch
(
updateHideUniswapWalletBanner
({
hideUniswapWalletBanner
:
true
}))
expect
(
store
.
getState
().
hideUniswapWalletBanner
).
toEqual
(
true
)
})
})
describe
(
'
addSerializedToken
'
,
()
=>
{
it
(
'
adds a token to the uninitialized list
'
,
()
=>
{
store
=
createStore
(
reducer
,
{
...
initialState
,
tokens
:
undefined
as
any
,
})
store
.
dispatch
(
addSerializedToken
({
serializedToken
:
{
chainId
:
1
,
address
:
'
0x123
'
,
},
})
)
expect
(
store
.
getState
().
tokens
).
toEqual
({
1
:
{
'
0x123
'
:
{
address
:
'
0x123
'
,
chainId
:
1
}
}
})
})
it
(
'
adds a token to the initialized list, no duplicates
'
,
()
=>
{
store
.
dispatch
(
addSerializedToken
({
serializedToken
:
{
chainId
:
1
,
address
:
'
0x123
'
}
}))
store
.
dispatch
(
addSerializedToken
({
serializedToken
:
{
chainId
:
1
,
address
:
'
0x123
'
}
}))
expect
(
store
.
getState
().
tokens
).
toEqual
({
1
:
{
'
0x123
'
:
{
address
:
'
0x123
'
,
chainId
:
1
}
}
})
})
it
(
'
adds a new token to the initialized list
'
,
()
=>
{
store
.
dispatch
(
addSerializedToken
({
serializedToken
:
{
chainId
:
1
,
address
:
'
0x123
'
}
}))
store
.
dispatch
(
addSerializedToken
({
serializedToken
:
{
chainId
:
1
,
address
:
'
0x456
'
}
}))
expect
(
store
.
getState
().
tokens
).
toEqual
({
1
:
{
'
0x123
'
:
{
address
:
'
0x123
'
,
chainId
:
1
},
'
0x456
'
:
{
address
:
'
0x456
'
,
chainId
:
1
},
},
})
})
})
describe
(
'
addSerializedPair
'
,
()
=>
{
it
(
'
adds a pair to the uninitialized list
'
,
()
=>
{
store
=
createStore
(
reducer
,
{
...
initialState
,
})
store
.
dispatch
(
addSerializedPair
({
serializedPair
:
buildSerializedPair
(
'
0x123
'
,
'
0x456
'
,
1
),
})
)
expect
(
store
.
getState
().
pairs
).
toEqual
({
1
:
{
'
0x123;0x456
'
:
buildSerializedPair
(
'
0x123
'
,
'
0x456
'
,
1
)
},
})
})
it
(
'
adds two pair to the initialized list, no duplicates
'
,
()
=>
{
store
.
dispatch
(
addSerializedPair
({
serializedPair
:
buildSerializedPair
(
'
0x123
'
,
'
0x456
'
,
1
),
})
)
store
.
dispatch
(
addSerializedPair
({
serializedPair
:
buildSerializedPair
(
'
0x123
'
,
'
0x456
'
,
1
),
})
)
expect
(
store
.
getState
().
pairs
).
toEqual
({
1
:
{
'
0x123;0x456
'
:
buildSerializedPair
(
'
0x123
'
,
'
0x456
'
,
1
)
},
})
})
it
(
'
adds two new pairs to the initialized list, same chain
'
,
()
=>
{
store
.
dispatch
(
addSerializedPair
({
serializedPair
:
buildSerializedPair
(
'
0x123
'
,
'
0x456
'
,
1
),
})
)
store
.
dispatch
(
addSerializedPair
({
serializedPair
:
buildSerializedPair
(
'
0x123
'
,
'
0x789
'
,
1
),
})
)
expect
(
store
.
getState
().
pairs
).
toEqual
({
1
:
{
'
0x123;0x456
'
:
buildSerializedPair
(
'
0x123
'
,
'
0x456
'
,
1
),
'
0x123;0x789
'
:
buildSerializedPair
(
'
0x123
'
,
'
0x789
'
,
1
),
},
})
})
it
(
'
adds two new pairs to the initialized list, different chains
'
,
()
=>
{
store
.
dispatch
(
addSerializedPair
({
serializedPair
:
buildSerializedPair
(
'
0x123
'
,
'
0x456
'
,
1
),
})
)
store
.
dispatch
(
addSerializedPair
({
serializedPair
:
buildSerializedPair
(
'
0x123
'
,
'
0x456
'
,
5
),
})
)
expect
(
store
.
getState
().
pairs
).
toEqual
({
1
:
{
'
0x123;0x456
'
:
buildSerializedPair
(
'
0x123
'
,
'
0x456
'
,
1
),
},
5
:
{
'
0x123;0x456
'
:
buildSerializedPair
(
'
0x123
'
,
'
0x456
'
,
5
),
},
})
})
})
})
src/state/wallets/hooks.test.tsx
0 → 100644
View file @
709fad08
import
{
act
,
renderHook
}
from
'
test-utils
'
import
{
useConnectedWallets
}
from
'
./hooks
'
import
{
Wallet
}
from
'
./types
'
describe
(
'
useConnectedWallets
'
,
()
=>
{
it
(
'
should return the connected wallets
'
,
()
=>
{
const
{
result
}
=
renderHook
(()
=>
useConnectedWallets
())
expect
(
result
.
current
[
0
]).
toEqual
([])
})
it
(
'
should add a wallet
'
,
()
=>
{
const
{
result
}
=
renderHook
(()
=>
useConnectedWallets
())
const
wallet
:
Wallet
=
{
walletType
:
'
injected
'
,
account
:
'
0x123
'
,
}
act
(()
=>
{
result
.
current
[
1
](
wallet
)
})
expect
(
result
.
current
[
0
]).
toEqual
([
wallet
])
})
})
src/state/wallets/reducer.test.ts
0 → 100644
View file @
709fad08
import
walletsReducer
from
'
./reducer
'
import
{
Wallet
}
from
'
./types
'
describe
(
'
walletsSlice reducers
'
,
()
=>
{
it
(
'
should add a connected wallet
'
,
()
=>
{
const
initialState
=
{
connectedWallets
:
[],
}
const
wallet
=
{
address
:
'
0x123
'
,
chainId
:
1
,
}
const
action
=
{
type
:
'
wallets/addConnectedWallet
'
,
payload
:
wallet
,
}
const
expectedState
=
{
connectedWallets
:
[
wallet
],
}
expect
(
walletsReducer
(
initialState
,
action
)).
toEqual
(
expectedState
)
})
it
(
'
should remove a connected wallet
'
,
()
=>
{
const
wallet
:
Wallet
=
{
walletType
:
'
metamask
'
,
account
:
'
0x123
'
,
}
const
initialState
=
{
connectedWallets
:
[
wallet
],
}
const
action
=
{
type
:
'
wallets/removeConnectedWallet
'
,
payload
:
wallet
,
}
const
expectedState
=
{
connectedWallets
:
[],
}
expect
(
walletsReducer
(
initialState
,
action
)).
toEqual
(
expectedState
)
})
})
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment