Skip to content

Commit

Permalink
Merge pull request #121 from alephium/testnet-add-alephium
Browse files Browse the repository at this point in the history
Add Alephium to testnet token list
  • Loading branch information
polarker authored Mar 26, 2024
2 parents 487884b + a0cbc27 commit 20a0b03
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 10 deletions.
4 changes: 2 additions & 2 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ along with the library. If not, see <http://www.gnu.org/licenses/>.

import mainnetTokenList from '../tokens/mainnet.json'
import testnetTokenList from '../tokens/testnet.json'
import { TokenInfo, TokenList } from './types'
import { NetworkId, TokenInfo, TokenList } from './types'

export * from './types'

Expand All @@ -28,6 +28,6 @@ export const testnet = testnetTokenList as TokenList
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
export const ALPH: TokenInfo = mainnet.tokens.find((token) => token.symbol === 'ALPH')!

export function getTokensURL(networkId: 'mainnet' | 'testnet'): string {
export function getTokensURL(networkId: NetworkId): string {
return `https://raw.githubusercontent.com/alephium/token-list/master/tokens/${networkId}.json`
}
2 changes: 2 additions & 0 deletions lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ export interface TokenInfo {
description: string
logoURI: string
}

export type NetworkId = 'mainnet' | 'testnet'
11 changes: 10 additions & 1 deletion test/token-list/devnet.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
{
"networkId": 2,
"tokens": [
{
"id": "0000000000000000000000000000000000000000000000000000000000000000",
"name": "Alephium",
"symbol": "ALPH",
"decimals": 18,
"description": "Alephium is a scalable, decentralized, and secure blockchain platform that enables the creation of fast and secure applications.",
"logoURI": "https://raw.githubusercontent.com/alephium/token-list/master/logos/ALPH.png"
},
{
"id": "8342e4f9a27d1f9c31eb85bde36a4b39332648fef67dd43a0d5dc2771de0abc5",
"name": "Shiny Token",
"symbol": "SHNY",
"decimals": 0,
"description": "Sniny Token (SHNY) is a decentralized token for the Alephium community.",
"logoURI": "https://raw.githubusercontent.com/alephium/token-list/master/logos/SHNY.png"
},{
},
{
"id": "141af4f9a27d1f9c31eb85bde36a4b39332648fef67dd43a0d5dc2771de0a381",
"name": "Steak Token",
"symbol": "STK",
Expand Down
18 changes: 11 additions & 7 deletions test/token-list/token-list.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ along with the library. If not, see <http://www.gnu.org/licenses/>.

import { FungibleTokenMetaData, hexToString, NodeProvider } from '@alephium/web3'

import { ALPH } from '../../lib/index'
import { TokenInfo, TokenList } from '../../lib/types'
import mainnetJson from '../../tokens/mainnet.json'
import testnetJson from '../../tokens/testnet.json'
Expand Down Expand Up @@ -82,7 +81,7 @@ describe('TokenList', function () {
})

it('should have ALPH token', () => {
const expected: TokenInfo = {
const expectedALPH: TokenInfo = {
id: ''.padStart(64, '0'),
name: 'Alephium',
symbol: 'ALPH',
Expand All @@ -91,15 +90,20 @@ describe('TokenList', function () {
'Alephium is a scalable, decentralized, and secure blockchain platform that enables the creation of fast and secure applications.',
logoURI: 'https://raw.githubusercontent.com/alephium/token-list/master/logos/ALPH.png'
}
expect(ALPH).toEqual(expected)

tokenLists.forEach((tokenList) => {
expect(tokenList.tokens.find((token) => token.symbol === 'ALPH')).toEqual(expectedALPH)
})
})

const testnetNodeProvider = new NodeProvider(testnetURL)
testnetTokenList.tokens.forEach((token) => {
it(`validate testnet ${token.name}`, async () => {
await validateTokenMetadata(token, testnetNodeProvider)
await validateTokenType(token, testnetNodeProvider)
})
if (token.symbol !== 'ALPH') {
it(`validate testnet ${token.name}`, async () => {
await validateTokenMetadata(token, testnetNodeProvider)
await validateTokenType(token, testnetNodeProvider)
})
}
})

async function validateTokenType(token: TokenInfo, nodeProvider: NodeProvider) {
Expand Down
8 changes: 8 additions & 0 deletions tokens/testnet.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
{
"networkId": 1,
"tokens": [
{
"id": "0000000000000000000000000000000000000000000000000000000000000000",
"name": "Alephium",
"symbol": "ALPH",
"decimals": 18,
"description": "Alephium is a scalable, decentralized, and secure blockchain platform that enables the creation of fast and secure applications.",
"logoURI": "https://raw.githubusercontent.com/alephium/token-list/master/logos/ALPH.png"
},
{
"id": "bed35ce97166170f91a8cdb35948b8696aa67dbd573ee0c5cc572bb8c44ddb01",
"name": "Test BTC",
Expand Down

0 comments on commit 20a0b03

Please sign in to comment.