Skip to content

Commit 22db96c

Browse files
committed
Split NFT collections in seperate file
1 parent ed287fc commit 22db96c

11 files changed

Lines changed: 139 additions & 53 deletions

File tree

‎jestconfig.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"transform": {
33
"^.+\\.(t|j)sx?$": "ts-jest"
44
},
5-
"testRegex": "(/test/(?!fixtures).*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
5+
"testMatch": ["**/(src|test)/**/*.test.ts"],
66
"moduleFileExtensions": ["ts", "tsx", "js", "jsx", "json", "node"],
77
"collectCoverage": true,
88
"coverageDirectory": "./coverage/",

‎lib/index.ts‎

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,29 @@ You should have received a copy of the GNU Lesser General Public License
1616
along with the library. If not, see <http://www.gnu.org/licenses/>.
1717
*/
1818

19-
import mainnet from '../tokens/mainnet.json'
20-
import testnet from '../tokens/testnet.json'
21-
import { TokenInfo, TokenList } from './types'
19+
import mainnetNFTCollectionList from '../nft-collections/mainnet.json'
20+
import testnetNFTCollectionList from '../nft-collections/testnet.json'
21+
import mainnetTokenList from '../tokens/mainnet.json'
22+
import testnetTokenList from '../tokens/testnet.json'
23+
import { NFTCollectionList, TokenInfo, TokenList } from './types'
2224

2325
export * from './types'
2426

25-
export const mainnetTokensMetadata = mainnet as TokenList
26-
27-
export const testnetTokensMetadata = testnet as TokenList
28-
29-
export default { mainnet: mainnetTokensMetadata, testnet: testnetTokensMetadata }
27+
export const mainnetTokensMetadata = mainnetTokenList as TokenList
28+
export const testnetTokensMetadata = testnetTokenList as TokenList
29+
export const mainnetNFTCollectionsMetadata = mainnetNFTCollectionList as NFTCollectionList
30+
export const testnetNFTCollectionsMetadata = testnetNFTCollectionList as NFTCollectionList
31+
32+
export default {
33+
mainnet: {
34+
tokens: mainnetTokensMetadata,
35+
nftCollections: mainnetNFTCollectionsMetadata
36+
},
37+
testnet: {
38+
tokens: testnetTokensMetadata,
39+
nftCollections: testnetNFTCollectionsMetadata
40+
}
41+
}
3042

3143
export const ALPH: TokenInfo = {
3244
id: ''.padStart(64, '0'),

‎lib/types.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ along with the library. If not, see <http://www.gnu.org/licenses/>.
1919
export interface TokenList {
2020
networkId: number
2121
tokens: TokenInfo[]
22-
nftCollections: NFTCollectionInfo[]
2322
}
2423

2524
export interface TokenInfo {
@@ -31,6 +30,11 @@ export interface TokenInfo {
3130
logoURI?: string
3231
}
3332

33+
export interface NFTCollectionList {
34+
networkId: number
35+
nftCollections: NFTCollectionInfo[]
36+
}
37+
3438
export interface NFTCollectionInfo {
3539
id: string
3640
name: string

‎nft-collections/mainnet.json‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"networkId": 0,
3+
"nftCollections": []
4+
}

‎nft-collections/testnet.json‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"networkId": 1,
3+
"nftCollections": []
4+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"networkId": 2,
3+
"nftCollections": [
4+
{
5+
"id": "f02ff3b9327b72dea0ef9530f62243b7762debcf290f9554b0d616c10f601100",
6+
"name": "Alehpium Punks",
7+
"symbol": "APUNK",
8+
"description": "Alephium Punks (APUNK) is a collection of 1000 uniquely generated punks."
9+
},{
10+
"id": "66a5fbef6d372fffd2ca5a2d696b9ab2c0ab04112b99f2a0e6962607afe917db",
11+
"name": "Alephium Wizards",
12+
"symbol": "AWIZD",
13+
"description": "Alephium Wizards (AWIZD) is a collection of 2121 uniquely generated wizards."
14+
}
15+
]
16+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
Copyright 2018 - 2023 The Alephium Authors
3+
This file is part of the alephium project.
4+
5+
The library is free software: you can redistribute it and/or modify
6+
it under the terms of the GNU Lesser General Public License as published by
7+
the Free Software Foundation, either version 3 of the License, or
8+
(at your option) any later version.
9+
10+
The library is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU Lesser General Public License for more details.
14+
15+
You should have received a copy of the GNU Lesser General Public License
16+
along with the library. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
19+
import { NFTCollectionList } from '../../lib/types'
20+
import mainnetJson from '../../nft-collections/mainnet.json'
21+
import testnetJson from '../../nft-collections/testnet.json'
22+
import { checkDuplicates } from '../utils'
23+
import devnetJson from './devnet.json'
24+
25+
const mainnetNFTCollectionList = mainnetJson as NFTCollectionList
26+
const testnetNFTCollectionList = testnetJson as NFTCollectionList
27+
const devnetNFTCollectionList = devnetJson as NFTCollectionList
28+
29+
const nftCollectionLists = [mainnetNFTCollectionList, testnetNFTCollectionList, devnetNFTCollectionList]
30+
31+
describe('NFTCollectionList', function () {
32+
it('should contains no duplicate', () => {
33+
nftCollectionLists.forEach((nftCollectionList) => checkDuplicates(nftCollectionList.nftCollections))
34+
})
35+
36+
it('should have valid networkId', () => {
37+
nftCollectionLists.forEach((nftCollectionList) => {
38+
expect(nftCollectionList.networkId).toBeGreaterThanOrEqual(0)
39+
})
40+
})
41+
42+
it('should have a networkId matching file name', () => {
43+
expect(mainnetJson.networkId).toEqual(0)
44+
expect(testnetJson.networkId).toEqual(1)
45+
})
46+
})
Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,5 @@
1616
"description": "Steak Token (STK) is a meme token for the Proof of Steak community.",
1717
"logoURI": "https://raw.githubusercontent.com/alephium/tokens-meta/master/logos/STK.png"
1818
}
19-
],
20-
"nftCollections": [
21-
{
22-
"id": "f02ff3b9327b72dea0ef9530f62243b7762debcf290f9554b0d616c10f601100",
23-
"name": "Alehpium Punks",
24-
"symbol": "APUNK",
25-
"description": "Alephium Punks (APUNK) is a collection of 1000 uniquely generated punks."
26-
},{
27-
"id": "66a5fbef6d372fffd2ca5a2d696b9ab2c0ab04112b99f2a0e6962607afe917db",
28-
"name": "Alephium Wizards",
29-
"symbol": "AWIZD",
30-
"description": "Alephium Wizards (AWIZD) is a collection of 2121 uniquely generated wizards."
31-
}
3219
]
3320
}
Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ You should have received a copy of the GNU Lesser General Public License
1616
along with the library. If not, see <http://www.gnu.org/licenses/>.
1717
*/
1818

19-
import { TokenList } from '../lib/types'
20-
import mainnetJson from './../tokens/mainnet.json'
21-
import testnetJson from './../tokens/testnet.json'
19+
import { TokenList } from '../../lib/types'
20+
import mainnetJson from '../../tokens/mainnet.json'
21+
import testnetJson from '../../tokens/testnet.json'
22+
import { checkDuplicates } from '../utils'
2223
import devnetJson from './devnet.json'
2324

2425
const mainnetTokenList = mainnetJson as TokenList
@@ -29,7 +30,7 @@ const tokenLists = [mainnetTokenList, testnetTokenList, devnetTokenList]
2930

3031
describe('TokenList', function () {
3132
it('should contains no duplicate', () => {
32-
tokenLists.forEach(checkDuplicates)
33+
tokenLists.forEach((tokenList) => checkDuplicates(tokenList.tokens))
3334
})
3435

3536
it('should have valid logoURI', () => {
@@ -64,27 +65,3 @@ describe('TokenList', function () {
6465
expect(testnetJson.networkId).toEqual(1)
6566
})
6667
})
67-
68-
function checkDuplicates(tokenList: TokenList): void {
69-
const ids = new Map<string, boolean>()
70-
const names = new Map<string, boolean>()
71-
const symbols = new Map<string, boolean>()
72-
73-
const tokensLike = (tokenList.tokens as { id: string; name: string; symbol: string }[]).concat(
74-
tokenList.nftCollections
75-
)
76-
77-
for (const token of tokensLike) {
78-
//Ids
79-
expect(ids.get(token.id)).toBeUndefined()
80-
ids.set(token.id, true)
81-
82-
//Name
83-
expect(names.get(token.name)).toBeUndefined()
84-
names.set(token.name, true)
85-
86-
//Symbol
87-
expect(symbols.get(token.symbol)).toBeUndefined()
88-
symbols.set(token.symbol, true)
89-
}
90-
}

‎test/utils.ts‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
Copyright 2018 - 2023 The Alephium Authors
3+
This file is part of the alephium project.
4+
5+
The library is free software: you can redistribute it and/or modify
6+
it under the terms of the GNU Lesser General Public License as published by
7+
the Free Software Foundation, either version 3 of the License, or
8+
(at your option) any later version.
9+
10+
The library is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU Lesser General Public License for more details.
14+
15+
You should have received a copy of the GNU Lesser General Public License
16+
along with the library. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
19+
export function checkDuplicates(tokensLike: { id: string; name: string; symbol: string }[]): void {
20+
const ids = new Map<string, boolean>()
21+
const names = new Map<string, boolean>()
22+
const symbols = new Map<string, boolean>()
23+
24+
for (const token of tokensLike) {
25+
//Ids
26+
expect(ids.get(token.id)).toBeUndefined()
27+
ids.set(token.id, true)
28+
29+
//Name
30+
expect(names.get(token.name)).toBeUndefined()
31+
names.set(token.name, true)
32+
33+
//Symbol
34+
expect(symbols.get(token.symbol)).toBeUndefined()
35+
symbols.set(token.symbol, true)
36+
}
37+
}

0 commit comments

Comments
 (0)