Skip to content

Commit

Permalink
fix: Make previous list mandatory (#103)
Browse files Browse the repository at this point in the history
* fix: Make previous list mandatory

* Allow ignorePreviousList true if no prevArbifiedList is passed

* Add versioning for extensions, add unit test

* Get previous and current versions

* Fix syntax

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* WIP

* Cleanup

* Add prevArbifiedList to integration tests

* Fix prevArbifiedList in integration tests

* Map over paths for backup

* Fix paths

* Fix paths

* Fix paths

* Update array type

* Update paths access

* Update paths access

* Update paths access

* Update paths access

* Update paths access

* Update paths access

* Update paths access

* WIP

* WIP

* WIP

* Add all generation

* Try error

* Try error

* Test happy path

* Test happy path

* Test happy path

* Test error in online version

* Test error in new version

* Test error in backup

* Remove tests

* Simplify version parsing

* Add missing parenthesis

* Rework getVersion, remove previousList for fullList
  • Loading branch information
chrstph-dvx authored Sep 20, 2023
1 parent 5fd7561 commit 003d528
Show file tree
Hide file tree
Showing 10 changed files with 488 additions and 65 deletions.
6 changes: 6 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,10 @@ module.exports = {
ecmaVersion: 2018, // Allows for the parsing of modern ECMAScript features
sourceType: 'module', // Allows for the use of imports
},
rules: {
'@typescript-eslint/no-unused-vars': [
'error',
{ ignoreRestSiblings: true },
],
},
};
101 changes: 91 additions & 10 deletions .github/workflows/generate-token-lists.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,26 +56,65 @@ jobs:
matrix:
commands:
- name: Arb1 FullList
paths:
- ArbTokenLists/arbed_full.json
version: false
command: yarn fullList --l2NetworkID 42161 --newArbifiedList ./src/ArbTokenLists/arbed_full.json --skipValidation

- name: Arb1 Arbify Uniswap
command: yarn arbify --l2NetworkID 42161 --tokenList https://tokens.uniswap.org --newArbifiedList ./src/ArbTokenLists/arbed_uniswap_labs.json && cp ./src/ArbTokenLists/arbed_uniswap_labs.json ./src/ArbTokenLists/arbed_uniswap_labs_default.json
paths:
- ArbTokenLists/arbed_uniswap_labs.json
- ArbTokenLists/arbed_uniswap_labs_default.json
version: true
command: yarn arbify --l2NetworkID 42161 --prevArbifiedList https://tokenlist.arbitrum.io/ArbTokenLists/arbed_uniswap_labs.json --tokenList https://tokens.uniswap.org --newArbifiedList ./src/ArbTokenLists/arbed_uniswap_labs.json && cp ./src/ArbTokenLists/arbed_uniswap_labs.json ./src/ArbTokenLists/arbed_uniswap_labs_default.json

- name: Arb1 Arbify Gemini
command: yarn arbify --l2NetworkID 42161 --tokenList https://www.gemini.com/uniswap/manifest.json --newArbifiedList ./src/ArbTokenLists/arbed_gemini_token_list.json
paths:
- ArbTokenLists/arbed_gemini_token_list.json
version: true
command: yarn arbify --l2NetworkID 42161 --prevArbifiedList https://tokenlist.arbitrum.io/ArbTokenLists/arbed_gemini_token_list.json --tokenList https://www.gemini.com/uniswap/manifest.json --newArbifiedList ./src/ArbTokenLists/arbed_gemini_token_list.json

- name: Arb1 Arbify CMC
command: yarn arbify --l2NetworkID 42161 --tokenList https://api.coinmarketcap.com/data-api/v3/uniswap/all.json --newArbifiedList ./src/ArbTokenLists/arbed_coinmarketcap.json
paths:
- ArbTokenLists/arbed_coinmarketcap.json
version: true
command: yarn arbify --l2NetworkID 42161 --prevArbifiedList https://tokenlist.arbitrum.io/ArbTokenLists/arbed_coinmarketcap.json --tokenList https://api.coinmarketcap.com/data-api/v3/uniswap/all.json --newArbifiedList ./src/ArbTokenLists/arbed_coinmarketcap.json

- name: Arb1 Update Whitelist
command: yarn update --l2NetworkID 42161 --tokenList https://tokenlist.arbitrum.io/ArbTokenLists/arbed_arb_whitelist_era.json --includeOldDataFields true --newArbifiedList ./src/ArbTokenLists/arbed_arb_whitelist_era.json
paths:
- ArbTokenLists/arbed_arb_whitelist_era.json
version: true
command: yarn update --l2NetworkID 42161 --prevArbifiedList https://tokenlist.arbitrum.io/ArbTokenLists/arbed_arb_whitelist_era.json --tokenList https://tokenlist.arbitrum.io/ArbTokenLists/arbed_arb_whitelist_era.json --includeOldDataFields true --newArbifiedList ./src/ArbTokenLists/arbed_arb_whitelist_era.json

- name: ArbNova Arbify Uniswap
command: yarn arbify --l2NetworkID 42170 --tokenList https://tokens.uniswap.org --newArbifiedList ./src/ArbTokenLists/42170_arbed_uniswap_labs.json && cp ./src/ArbTokenLists/42170_arbed_uniswap_labs.json ./src/ArbTokenLists/42170_arbed_uniswap_labs_default.json
paths:
- ArbTokenLists/42170_arbed_uniswap_labs.json
- ArbTokenLists/42170_arbed_uniswap_labs_default.json
version: true
command: yarn arbify --l2NetworkID 42170 --prevArbifiedList https://tokenlist.arbitrum.io/ArbTokenLists/42170_arbed_uniswap_labs_default.json --newArbifiedList ./src/ArbTokenLists/42170_arbed_uniswap_labs.json --tokenList https://tokens.uniswap.org && cp ./src/ArbTokenLists/42170_arbed_uniswap_labs.json ./src/ArbTokenLists/42170_arbed_uniswap_labs_default.json

- name: ArbNova Arbify Gemini
command: yarn arbify --l2NetworkID 42170 --tokenList https://www.gemini.com/uniswap/manifest.json --newArbifiedList ./src/ArbTokenLists/42170_arbed_gemini_token_list.json
paths:
- ArbTokenLists/42170_arbed_gemini_token_list.json
version: true
command: yarn arbify --l2NetworkID 42170 --prevArbifiedList https://tokenlist.arbitrum.io/ArbTokenLists/42170_arbed_gemini_token_list.json --tokenList https://www.gemini.com/uniswap/manifest.json --newArbifiedList ./src/ArbTokenLists/42170_arbed_gemini_token_list.json

- name: ArbNova Arbify CMC
command: yarn arbify --l2NetworkID 42170 --tokenList https://api.coinmarketcap.com/data-api/v3/uniswap/all.json --newArbifiedList ./src/ArbTokenLists/42170_arbed_coinmarketcap.json
paths:
- ArbTokenLists/42170_arbed_coinmarketcap.json
version: true
command: yarn arbify --l2NetworkID 42170 --prevArbifiedList https://tokenlist.arbitrum.io/ArbTokenLists/42170_arbed_coinmarketcap.json --tokenList https://api.coinmarketcap.com/data-api/v3/uniswap/all.json --newArbifiedList ./src/ArbTokenLists/42170_arbed_coinmarketcap.json

- name: ArbGoerli Arbify CMC
command: yarn arbify --l2NetworkID 421613 --tokenList https://api.coinmarketcap.com/data-api/v3/uniswap/all.json --newArbifiedList ./src/ArbTokenLists/421613_arbed_coinmarketcap.json
paths:
- ArbTokenLists/421613_arbed_coinmarketcap.json
version: true
command: yarn arbify --l2NetworkID 421613 --prevArbifiedList https://tokenlist.arbitrum.io/ArbTokenLists/421613_arbed_coinmarketcap.json --tokenList https://api.coinmarketcap.com/data-api/v3/uniswap/all.json --newArbifiedList ./src/ArbTokenLists/421613_arbed_coinmarketcap.json

- name: ArbGoerli FullList
paths:
- ArbTokenLists/421613_arbed_full.json
version: false
command: yarn fullList --l2NetworkID 421613 --newArbifiedList ./src/ArbTokenLists/421613_arbed_full.json --skipValidation
env:
INFURA_KEY: '${{ secrets.INFURA_KEY }}'
Expand All @@ -98,13 +137,55 @@ jobs:
if: success()
run: ${{ matrix.commands.command }}

- name: Get online version
id: onlineVersion
if: ${{ matrix.commands.version == true && matrix.commands.version == true }}
run: |
version=$(curl https://tokenlist.arbitrum.io/${{ matrix.commands.paths[0] }} | jq .version | jq 'join(".")')
if [[ -n $version ]]; then
echo "onlineVersion=$version" >> $GITHUB_OUTPUT
else
# Make sure failure from curl or jq fails the generation
exit 1
fi
- name: Get new version
id: newVersion
if: ${{ matrix.commands.version == true && matrix.commands.version == true }}
run: |
version=$(cat ./src/${{ matrix.commands.paths[0] }} | jq .version | jq 'join(".")')
if [[ -n $version ]]; then
echo "newVersion=$version" >> $GITHUB_OUTPUT
else
# Make sure failure from curl or jq fails the generation
exit 1
fi
- name: Backup (Test folder)
if: ${{ inputs.environment == 'Test' && matrix.commands.version == true }}
run: |
paths=(${{ join(matrix.commands.paths, ' ') }})
for path in ${paths[*]}
do
aws s3 cp s3://${{ secrets.AWS_BUCKET }}/TestFolder/$path s3://${{ secrets.AWS_BUCKET }}/TestFolder/${{ steps.onlineVersion.outputs.onlineVersion }}/
done
- name: Deploy (Test folder)
if: ${{ inputs.environment == 'Test' }}
run: 'aws s3 sync ./src/ s3://${{ secrets.AWS_BUCKET }}/TestFolder --exclude "*" --include "FullList/*.json" --include "ArbTokenLists/*.json"'
run: aws s3 sync ./src/ s3://${{ secrets.AWS_BUCKET }}/TestFolder --exclude "*" --include "FullList/*.json" --include "ArbTokenLists/*.json"

- name: Backup
if: ${{ inputs.environment == 'CI' && matrix.commands.version == true }}
run: |
paths=(${{ join(matrix.commands.paths, ' ') }})
for path in ${paths[*]}
do
aws s3 cp s3://${{ secrets.AWS_BUCKET }}/$path s3://${{ secrets.AWS_BUCKET }}/${{ steps.onlineVersion.outputs.onlineVersion }}/
done
- name: Deploy
if: ${{ inputs.environment == 'CI' }}
run: 'aws s3 sync ./src/ s3://${{ secrets.AWS_BUCKET }} --exclude "*" --include "FullList/*.json" --include "ArbTokenLists/*.json" --acl "public-read"'
run: aws s3 sync ./src/ s3://${{ secrets.AWS_BUCKET }} --exclude "*" --include "FullList/*.json" --include "ArbTokenLists/*.json" --acl "public-read"

error-alerts:
runs-on: ubuntu-latest
Expand Down
15 changes: 8 additions & 7 deletions __test__/integration/validateLists.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ describe('Token Lists', () => {
runCommand(Action.Arbify, [
'--l2NetworkID=42161',
'--tokenList=https://tokens.uniswap.org',
'--ignorePreviousList=true',
'--prevArbifiedList=https://tokenlist.arbitrum.io/ArbTokenLists/arbed_uniswap_labs.json',
'--newArbifiedList=./src/ArbTokenLists/arbed_uniswap_labs.json',
]),
fetch(
Expand All @@ -88,7 +88,7 @@ describe('Token Lists', () => {
runCommand(Action.Arbify, [
'--l2NetworkID=42161',
'--tokenList=https://www.gemini.com/uniswap/manifest.json',
'--ignorePreviousList=true',
'--prevArbifiedList=https://tokenlist.arbitrum.io/ArbTokenLists/arbed_gemini_token_list.json',
'--newArbifiedList=./src/ArbTokenLists/arbed_gemini_token_list.json',
]),
fetch(
Expand All @@ -106,7 +106,7 @@ describe('Token Lists', () => {
runCommand(Action.Arbify, [
'--l2NetworkID=42161',
'--tokenList=https://api.coinmarketcap.com/data-api/v3/uniswap/all.json',
'--ignorePreviousList=true',
'--prevArbifiedList=https://tokenlist.arbitrum.io/ArbTokenLists/arbed_coinmarketcap.json',
'--newArbifiedList=./src/ArbTokenLists/arbed_coinmarketcap.json',
]),
fetch(
Expand All @@ -124,7 +124,7 @@ describe('Token Lists', () => {
runCommand(Action.Arbify, [
'--l2NetworkID=42170',
'--tokenList=https://tokens.uniswap.org',
'--ignorePreviousList=true',
'--prevArbifiedList=https://tokenlist.arbitrum.io/ArbTokenLists/42170_arbed_uniswap_labs.json',
'--newArbifiedList=./src/ArbTokenLists/42170_arbed_uniswap_labs.json',
]),
fetch(
Expand All @@ -142,7 +142,7 @@ describe('Token Lists', () => {
runCommand(Action.Arbify, [
'--l2NetworkID=42170',
'--tokenList=https://www.gemini.com/uniswap/manifest.json',
'--ignorePreviousList=true',
'--prevArbifiedList=https://tokenlist.arbitrum.io/ArbTokenLists/42170_arbed_gemini_token_list.json',
'--newArbifiedList=./src/ArbTokenLists/42170_arbed_gemini_token_list.json',
]),
fetch(
Expand All @@ -160,7 +160,7 @@ describe('Token Lists', () => {
runCommand(Action.Arbify, [
'--l2NetworkID=42170',
'--tokenList=https://api.coinmarketcap.com/data-api/v3/uniswap/all.json',
'--ignorePreviousList=true',
'--prevArbifiedList=https://tokenlist.arbitrum.io/ArbTokenLists/42170_arbed_coinmarketcap.json',
'--newArbifiedList=./src/ArbTokenLists/42170_arbed_coinmarketcap.json',
]),
fetch(
Expand All @@ -178,7 +178,7 @@ describe('Token Lists', () => {
runCommand(Action.Arbify, [
'--l2NetworkID=421613',
'--tokenList=https://api.coinmarketcap.com/data-api/v3/uniswap/all.json',
'--ignorePreviousList=true',
'--prevArbifiedList=https://tokenlist.arbitrum.io/ArbTokenLists/421613_arbed_coinmarketcap.json',
'--newArbifiedList=./src/ArbTokenLists/421613_arbed_coinmarketcap.json',
]),
fetch(
Expand All @@ -199,6 +199,7 @@ describe('Token Lists', () => {
'--l2NetworkID=42161',
'--tokenList=https://tokenlist.arbitrum.io/ArbTokenLists/arbed_arb_whitelist_era.json',
'--includeOldDataFields=true',
'--prevArbifiedList=https://tokenlist.arbitrum.io/ArbTokenLists/arbed_arb_whitelist_era.json',
'--newArbifiedList=./src/ArbTokenLists/arbed_arb_whitelist_era.json',
]),
fetch(
Expand Down
121 changes: 121 additions & 0 deletions __test__/unit/getVersion.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
import { getVersion } from '../../src/lib/getVersion';
import {
baseList,
majorList,
minorList,
patchList,
withoutExtensions,
} from './getVersionMockup';

describe('getVersion', () => {
it('Should return 1.0.0 version if no previous list is passed', () => {
const version = getVersion(null, baseList().tokens);
expect(version).toStrictEqual({
major: 1,
minor: 0,
patch: 0,
});

const versionWithoutExtensions = getVersion(
null,
withoutExtensions(baseList().tokens),
);
expect(versionWithoutExtensions).toStrictEqual({
major: 1,
minor: 0,
patch: 0,
});
});

it('Should not bump version if lists are equal', () => {
const version = getVersion(baseList(), baseList().tokens);
expect(version).toStrictEqual({
major: 2,
minor: 3,
patch: 4,
});

const prevList = baseList();
const versionWithoutExtensions = getVersion(
{
...prevList,
tokens: withoutExtensions(prevList.tokens),
},
withoutExtensions(baseList().tokens),
);
expect(versionWithoutExtensions).toStrictEqual({
major: 2,
minor: 3,
patch: 4,
});
});

it('Should bump patch version if extensions are different', () => {
const [prevList, newList] = patchList();
const version = getVersion(prevList, newList);
expect(version).toStrictEqual({
major: 2,
minor: 3,
patch: 5,
});

const versionWithoutExtensions = getVersion(
{
...prevList,
tokens: withoutExtensions(prevList.tokens),
},
withoutExtensions(newList),
);
expect(versionWithoutExtensions).toStrictEqual({
major: 2,
minor: 3,
patch: 4,
});
});

it('Should bump minor version if extensions are added', () => {
const [prevList, newList] = minorList();
const version = getVersion(prevList, newList);
expect(version).toStrictEqual({
major: 2,
minor: 4,
patch: 0,
});

const versionWithoutExtensions = getVersion(
{
...prevList,
tokens: withoutExtensions(prevList.tokens),
},
withoutExtensions(newList),
);
expect(versionWithoutExtensions).toStrictEqual({
major: 2,
minor: 3,
patch: 4,
});
});

it('Should bump major version if extensions are removed', () => {
const [prevList, newList] = majorList();
const version = getVersion(prevList, newList);
expect(version).toStrictEqual({
major: 3,
minor: 0,
patch: 0,
});

const versionWithoutExtensions = getVersion(
{
...prevList,
tokens: withoutExtensions(prevList.tokens),
},
withoutExtensions(newList),
);
expect(versionWithoutExtensions).toStrictEqual({
major: 2,
minor: 3,
patch: 4,
});
});
});
Loading

0 comments on commit 003d528

Please sign in to comment.