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
519ba896
Unverified
Commit
519ba896
authored
Sep 26, 2023
by
eddie
Committed by
GitHub
Sep 26, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test: unit tests for parseRemote (#7359)
parent
ec784ccb
Changes
4
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
906 additions
and
1 deletion
+906
-1
parseRemote.test.tsx.snap
...ortfolio/Activity/__snapshots__/parseRemote.test.tsx.snap
+338
-0
activity.ts
...AccountDrawer/MiniPortfolio/Activity/fixtures/activity.ts
+441
-0
parseRemote.test.tsx
...AccountDrawer/MiniPortfolio/Activity/parseRemote.test.tsx
+126
-0
util.tsx
src/graphql/data/util.tsx
+1
-1
No files found.
src/components/AccountDrawer/MiniPortfolio/Activity/__snapshots__/parseRemote.test.tsx.snap
0 → 100644
View file @
519ba896
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`parseRemote parseRemoteActivities should parse NFT approval 1`] = `
Object {
"chainId": 1,
"descriptor": "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
"from": "0x50EC05ADe8280758E2077fcBC08D878D4aef79C3",
"hash": "someHash",
"logos": Array [],
"nonce": 12345,
"status": "CONFIRMED",
"timestamp": 10000,
"title": "Unknown Approval",
}
`;
exports[`parseRemote parseRemoteActivities should parse NFT approval for all 1`] = `
Object {
"chainId": 1,
"descriptor": "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
"from": "0x50EC05ADe8280758E2077fcBC08D878D4aef79C3",
"hash": "someHash",
"logos": Array [],
"nonce": 12345,
"status": "CONFIRMED",
"timestamp": 10000,
"title": "Unknown Approval",
}
`;
exports[`parseRemote parseRemoteActivities should parse NFT receive 1`] = `
Object {
"chainId": 1,
"currencies": undefined,
"descriptor": "1 SomeCollectionName from ",
"from": "0x50EC05ADe8280758E2077fcBC08D878D4aef79C3",
"hash": "someHash",
"logos": Array [
"imageUrl",
],
"nonce": 12345,
"otherAccount": "0x50EC05ADe8280758E2077fcBC08D878D4aef79C3",
"status": "CONFIRMED",
"timestamp": 10000,
"title": "Received",
}
`;
exports[`parseRemote parseRemoteActivities should parse NFT transfer 1`] = `
Object {
"chainId": 1,
"descriptor": "1 SomeCollectionName",
"from": "0x50EC05ADe8280758E2077fcBC08D878D4aef79C3",
"hash": "someHash",
"logos": Array [
"imageUrl",
],
"nonce": 12345,
"status": "CONFIRMED",
"timestamp": 10000,
"title": "Minted",
}
`;
exports[`parseRemote parseRemoteActivities should parse closed UniswapX order 1`] = `
Object {
"chainId": 1,
"currencies": Array [
Token {
"address": "0x6B175474E89094C44Da98b954EedeAC495271d0F",
"chainId": 1,
"decimals": 18,
"isNative": false,
"isToken": true,
"name": "DAI",
"symbol": "DAI",
},
Token {
"address": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
"chainId": 1,
"decimals": 18,
"isNative": false,
"isToken": true,
"name": "Wrapped Ether",
"symbol": "WETH",
},
],
"descriptor": "100 DAI for 200 WETH",
"from": "someOfferer",
"hash": "someHash",
"logos": Array [
"someUrl",
"someUrl",
],
"offchainOrderStatus": "expired",
"prefixIconSrc": "bolt.svg",
"status": "FAILED",
"statusMessage": "Your swap could not be fulfilled at this time. Please try again.",
"timestamp": 10000,
"title": "Swap expired",
}
`;
exports[`parseRemote parseRemoteActivities should parse moonpay purchase 1`] = `
Object {
"chainId": 1,
"currencies": Array [
Token {
"address": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
"chainId": 1,
"decimals": 18,
"isNative": false,
"isToken": true,
"name": "Wrapped Ether",
"symbol": "WETH",
},
],
"descriptor": "100 WETH for 100",
"from": "0x50EC05ADe8280758E2077fcBC08D878D4aef79C3",
"hash": "someHash",
"logos": Array [
"moonpay.svg",
],
"nonce": 12345,
"status": "CONFIRMED",
"timestamp": 10000,
"title": "Purchased",
}
`;
exports[`parseRemote parseRemoteActivities should parse nft purchase 1`] = `
Object {
"chainId": 1,
"descriptor": "1 SomeCollectionName",
"from": "0x50EC05ADe8280758E2077fcBC08D878D4aef79C3",
"hash": "someHash",
"logos": Array [
"imageUrl",
],
"nonce": 12345,
"status": "CONFIRMED",
"timestamp": 10000,
"title": "Bought",
}
`;
exports[`parseRemote parseRemoteActivities should parse receive 1`] = `
Object {
"chainId": 1,
"currencies": Array [
Token {
"address": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
"chainId": 1,
"decimals": 18,
"isNative": false,
"isToken": true,
"name": "Wrapped Ether",
"symbol": "WETH",
},
],
"descriptor": "100 WETH from ",
"from": "0x50EC05ADe8280758E2077fcBC08D878D4aef79C3",
"hash": "someHash",
"logos": Array [
"logoUrl",
],
"nonce": 12345,
"otherAccount": "0x50EC05ADe8280758E2077fcBC08D878D4aef79C3",
"status": "CONFIRMED",
"timestamp": 10000,
"title": "Received",
}
`;
exports[`parseRemote parseRemoteActivities should parse remove liquidity 1`] = `
Object {
"chainId": 1,
"currencies": Array [
Token {
"address": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
"chainId": 1,
"decimals": 18,
"isNative": false,
"isToken": true,
"name": "Wrapped Ether",
"symbol": "WETH",
},
Token {
"address": "0x6B175474E89094C44Da98b954EedeAC495271d0F",
"chainId": 1,
"decimals": 18,
"isNative": false,
"isToken": true,
"name": "DAI",
"symbol": "DAI",
},
],
"descriptor": "100 WETH and 100 DAI",
"from": "0x50EC05ADe8280758E2077fcBC08D878D4aef79C3",
"hash": "someHash",
"logos": Array [
"logoUrl",
"logoUrl",
],
"nonce": 12345,
"status": "CONFIRMED",
"timestamp": 10000,
"title": "Removed Liquidity",
}
`;
exports[`parseRemote parseRemoteActivities should parse send 1`] = `
Object {
"chainId": 1,
"currencies": Array [
Token {
"address": "0x6B175474E89094C44Da98b954EedeAC495271d0F",
"chainId": 1,
"decimals": 18,
"isNative": false,
"isToken": true,
"name": "DAI",
"symbol": "DAI",
},
],
"descriptor": "100 DAI to ",
"from": "0x50EC05ADe8280758E2077fcBC08D878D4aef79C3",
"hash": "someHash",
"logos": Array [
"logoUrl",
],
"nonce": 12345,
"otherAccount": "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
"status": "CONFIRMED",
"timestamp": 10000,
"title": "Sent",
}
`;
exports[`parseRemote parseRemoteActivities should parse swap 1`] = `
Object {
"chainId": 1,
"currencies": Array [
Token {
"address": "0x6B175474E89094C44Da98b954EedeAC495271d0F",
"chainId": 1,
"decimals": 18,
"isNative": false,
"isToken": true,
"name": "DAI",
"symbol": "DAI",
},
Token {
"address": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
"chainId": 1,
"decimals": 18,
"isNative": false,
"isToken": true,
"name": "Wrapped Ether",
"symbol": "WETH",
},
],
"descriptor": "100 DAI for 100 WETH",
"from": "0x50EC05ADe8280758E2077fcBC08D878D4aef79C3",
"hash": "someHash",
"logos": Array [
"logoUrl",
],
"nonce": 12345,
"status": "CONFIRMED",
"timestamp": 10000,
"title": "Swapped",
}
`;
exports[`parseRemote parseRemoteActivities should parse swap order 1`] = `
Object {
"chainId": 1,
"currencies": Array [
Token {
"address": "0x6B175474E89094C44Da98b954EedeAC495271d0F",
"chainId": 1,
"decimals": 18,
"isNative": false,
"isToken": true,
"name": "DAI",
"symbol": "DAI",
},
Token {
"address": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
"chainId": 1,
"decimals": 18,
"isNative": false,
"isToken": true,
"name": "Wrapped Ether",
"symbol": "WETH",
},
],
"descriptor": "100 DAI for 100 WETH",
"from": "0x50EC05ADe8280758E2077fcBC08D878D4aef79C3",
"hash": "someHash",
"logos": Array [
"logoUrl",
],
"nonce": 12345,
"prefixIconSrc": "bolt.svg",
"status": "CONFIRMED",
"timestamp": 10000,
"title": "Swapped",
}
`;
exports[`parseRemote parseRemoteActivities should parse token approval 1`] = `
Object {
"chainId": 1,
"currencies": Array [
Token {
"address": "0x6B175474E89094C44Da98b954EedeAC495271d0F",
"chainId": 1,
"decimals": 18,
"isNative": false,
"isToken": true,
"name": "DAI",
"symbol": "DAI",
},
],
"descriptor": "DAI",
"from": "0x50EC05ADe8280758E2077fcBC08D878D4aef79C3",
"hash": "someHash",
"logos": Array [
"logoUrl",
],
"nonce": 12345,
"status": "CONFIRMED",
"timestamp": 10000,
"title": "Approved",
}
`;
src/components/AccountDrawer/MiniPortfolio/Activity/fixtures/activity.ts
0 → 100644
View file @
519ba896
This diff is collapsed.
Click to expand it.
src/components/AccountDrawer/MiniPortfolio/Activity/parseRemote.test.tsx
0 → 100644
View file @
519ba896
import
{
act
,
renderHook
}
from
'
@testing-library/react
'
import
ms
from
'
ms
'
import
{
MockClosedUniswapXOrder
,
MockMoonpayPurchase
,
MockNFTApproval
,
MockNFTApprovalForAll
,
MockNFTPurchase
,
MockNFTReceive
,
MockNFTTransfer
,
MockOpenUniswapXOrder
,
MockRemoveLiquidity
,
MockSwapOrder
,
MockTokenApproval
,
MockTokenReceive
,
MockTokenSend
,
MockTokenTransfer
,
}
from
'
./fixtures/activity
'
import
{
parseRemoteActivities
,
useTimeSince
}
from
'
./parseRemote
'
describe
(
'
parseRemote
'
,
()
=>
{
beforeEach
(()
=>
{
jest
.
useFakeTimers
()
})
describe
(
'
parseRemoteActivities
'
,
()
=>
{
it
(
'
should not parse open UniswapX order
'
,
()
=>
{
const
result
=
parseRemoteActivities
(
jest
.
fn
(),
[
MockOpenUniswapXOrder
])
expect
(
result
).
toEqual
({})
})
it
(
'
should parse closed UniswapX order
'
,
()
=>
{
const
result
=
parseRemoteActivities
(
jest
.
fn
(),
[
MockClosedUniswapXOrder
])
expect
(
result
?.[
'
someHash
'
]).
toMatchSnapshot
()
})
it
(
'
should parse NFT approval
'
,
()
=>
{
const
result
=
parseRemoteActivities
(
jest
.
fn
(),
[
MockNFTApproval
])
expect
(
result
?.[
'
someHash
'
]).
toMatchSnapshot
()
})
it
(
'
should parse NFT approval for all
'
,
()
=>
{
const
result
=
parseRemoteActivities
(
jest
.
fn
(),
[
MockNFTApprovalForAll
])
expect
(
result
?.[
'
someHash
'
]).
toMatchSnapshot
()
})
it
(
'
should parse NFT transfer
'
,
()
=>
{
const
result
=
parseRemoteActivities
(
jest
.
fn
(),
[
MockNFTTransfer
])
expect
(
result
?.[
'
someHash
'
]).
toMatchSnapshot
()
})
it
(
'
should parse swap
'
,
()
=>
{
const
result
=
parseRemoteActivities
(
jest
.
fn
().
mockReturnValue
(
'
100
'
),
[
MockTokenTransfer
])
expect
(
result
?.[
'
someHash
'
]).
toMatchSnapshot
()
})
it
(
'
should parse nft purchase
'
,
()
=>
{
const
result
=
parseRemoteActivities
(
jest
.
fn
().
mockReturnValue
(
'
100
'
),
[
MockNFTPurchase
])
expect
(
result
?.[
'
someHash
'
]).
toMatchSnapshot
()
})
it
(
'
should parse token approval
'
,
()
=>
{
const
result
=
parseRemoteActivities
(
jest
.
fn
(),
[
MockTokenApproval
])
expect
(
result
?.[
'
someHash
'
]).
toMatchSnapshot
()
})
it
(
'
should parse send
'
,
()
=>
{
const
result
=
parseRemoteActivities
(
jest
.
fn
().
mockReturnValue
(
100
),
[
MockTokenSend
])
expect
(
result
?.[
'
someHash
'
]).
toMatchSnapshot
()
})
it
(
'
should parse receive
'
,
()
=>
{
const
result
=
parseRemoteActivities
(
jest
.
fn
().
mockReturnValue
(
100
),
[
MockTokenReceive
])
expect
(
result
?.[
'
someHash
'
]).
toMatchSnapshot
()
})
it
(
'
should parse NFT receive
'
,
()
=>
{
const
result
=
parseRemoteActivities
(
jest
.
fn
().
mockReturnValue
(
100
),
[
MockNFTReceive
])
expect
(
result
?.[
'
someHash
'
]).
toMatchSnapshot
()
})
it
(
'
should parse remove liquidity
'
,
()
=>
{
const
result
=
parseRemoteActivities
(
jest
.
fn
().
mockReturnValue
(
100
),
[
MockRemoveLiquidity
])
expect
(
result
?.[
'
someHash
'
]).
toMatchSnapshot
()
})
it
(
'
should parse moonpay purchase
'
,
()
=>
{
const
result
=
parseRemoteActivities
(
jest
.
fn
().
mockReturnValue
(
'
100
'
),
[
MockMoonpayPurchase
])
expect
(
result
?.[
'
someHash
'
]).
toMatchSnapshot
()
})
it
(
'
should parse swap order
'
,
()
=>
{
const
result
=
parseRemoteActivities
(
jest
.
fn
().
mockReturnValue
(
'
100
'
),
[
MockSwapOrder
])
expect
(
result
?.[
'
someHash
'
]).
toMatchSnapshot
()
})
})
describe
(
'
useTimeSince
'
,
()
=>
{
beforeEach
(()
=>
{
jest
.
useFakeTimers
()
})
afterEach
(()
=>
{
jest
.
useRealTimers
()
})
it
(
'
should initialize with the correct time since
'
,
()
=>
{
const
timestamp
=
Math
.
floor
(
Date
.
now
()
/
1000
)
-
60
// 60 seconds ago
const
{
result
}
=
renderHook
(()
=>
useTimeSince
(
timestamp
))
expect
(
result
.
current
).
toBe
(
'
1m
'
)
})
it
(
'
should update time since every second
'
,
async
()
=>
{
const
timestamp
=
Math
.
floor
(
Date
.
now
()
/
1000
)
-
50
// 50 seconds ago
const
{
result
,
rerender
}
=
renderHook
(()
=>
useTimeSince
(
timestamp
))
act
(()
=>
{
jest
.
advanceTimersByTime
(
ms
(
'
1.1s
'
))
})
rerender
()
expect
(
result
.
current
).
toBe
(
'
51s
'
)
})
it
(
'
should stop updating after 61 seconds
'
,
()
=>
{
const
timestamp
=
Math
.
floor
(
Date
.
now
()
/
1000
)
-
61
// 61 seconds ago
const
{
result
,
rerender
}
=
renderHook
(()
=>
useTimeSince
(
timestamp
))
act
(()
=>
{
jest
.
advanceTimersByTime
(
ms
(
'
121.1s
'
))
})
rerender
()
// maxes out at 1m
expect
(
result
.
current
).
toBe
(
'
1m
'
)
})
})
})
src/graphql/data/util.tsx
View file @
519ba896
...
...
@@ -118,7 +118,7 @@ export function gqlToCurrency(token: {
const
chainId
=
supportedChainIdFromGQLChain
(
token
.
chain
)
if
(
!
chainId
)
return
undefined
if
(
token
.
standard
===
TokenStandard
.
Native
||
!
token
.
address
)
return
nativeOnChain
(
chainId
)
else
return
new
Token
(
chainId
,
token
.
address
,
token
.
decimals
??
18
,
token
.
name
,
token
.
symbol
)
else
return
new
Token
(
chainId
,
token
.
address
,
token
.
decimals
??
18
,
token
.
symbol
,
token
.
name
)
}
const
URL_CHAIN_PARAM_TO_BACKEND
:
{
[
key
:
string
]:
InterfaceGqlChain
}
=
{
...
...
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