forked from 1Hive/token-lists
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d3f8bdd
commit 7706ee0
Showing
4 changed files
with
146 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,31 @@ | ||
import { VersionUpgrade } from './getVersionUpgrade'; | ||
import { minVersionBump } from './minVersionBump'; | ||
import { TokenInfo, TokenList, Version } from './types'; | ||
import { Version } from './types'; | ||
|
||
/** | ||
* Returns the next version of the list given a base list and the updated token list. | ||
* @param base base list | ||
* @param updatedList updated list of tokens for the next list | ||
* Returns the next version of the list given a base version and the upgrade type | ||
* @param base current version | ||
* @param bump the upgrade type | ||
*/ | ||
export function nextVersion( | ||
base: TokenList, | ||
updatedList: TokenInfo[] | ||
): Version { | ||
const bump = minVersionBump(base.tokens, updatedList); | ||
export function nextVersion(base: Version, bump: VersionUpgrade): Version { | ||
switch (bump) { | ||
case VersionUpgrade.NONE: | ||
return base.version; | ||
return base; | ||
|
||
case VersionUpgrade.MAJOR: | ||
return { major: base.version.major + 1, minor: 0, patch: 0 }; | ||
return { major: base.major + 1, minor: 0, patch: 0 }; | ||
|
||
case VersionUpgrade.MINOR: | ||
return { | ||
major: base.version.major, | ||
minor: base.version.minor + 1, | ||
major: base.major, | ||
minor: base.minor + 1, | ||
patch: 0, | ||
}; | ||
|
||
case VersionUpgrade.PATCH: | ||
return { | ||
major: base.version.major, | ||
minor: base.version.minor, | ||
patch: base.version.patch + 1, | ||
major: base.major, | ||
minor: base.minor, | ||
patch: base.patch + 1, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { minVersionBump, TokenInfo, VersionUpgrade } from '../src'; | ||
const tokenA: TokenInfo = { | ||
chainId: 1, | ||
address: '0x0a', | ||
logoURI: 'ipfs://test', | ||
symbol: 'abcd', | ||
name: 'token a', | ||
decimals: 18, | ||
tags: ['hello', 'world'], | ||
}; | ||
const tokenAChangedNameDecimals: TokenInfo = { | ||
...tokenA, | ||
name: 'blah', | ||
decimals: 12, | ||
}; | ||
const tokenAChangedTags: TokenInfo = { | ||
...tokenA, | ||
tags: ['hello', 'worlds'], | ||
}; | ||
const tokenB: TokenInfo = { | ||
chainId: 1, | ||
address: '0x0b', | ||
logoURI: 'ipfs://blah', | ||
symbol: 'defg', | ||
name: 'token b', | ||
decimals: 9, | ||
tags: ['token', 'other'], | ||
}; | ||
describe('#minVersionBump', () => { | ||
it('empty', () => { | ||
expect(minVersionBump([], [])).toBe(VersionUpgrade.NONE); | ||
}); | ||
it('patch for tag changes only', () => { | ||
expect(minVersionBump([tokenA], [tokenAChangedTags])).toBe( | ||
VersionUpgrade.PATCH | ||
); | ||
}); | ||
it('patch for name/decimals changes', () => { | ||
expect(minVersionBump([tokenA], [tokenAChangedNameDecimals])).toBe( | ||
VersionUpgrade.PATCH | ||
); | ||
}); | ||
it('minor for remove only', () => { | ||
expect(minVersionBump([tokenA], [])).toBe(VersionUpgrade.MINOR); | ||
}); | ||
it('major for add', () => { | ||
expect(minVersionBump([], [tokenA])).toBe(VersionUpgrade.MAJOR); | ||
}); | ||
it('major for add/remove', () => { | ||
expect(minVersionBump([tokenB], [tokenA])).toBe(VersionUpgrade.MAJOR); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { nextVersion, VersionUpgrade } from '../src'; | ||
|
||
describe('#nextVersion', () => { | ||
it('none', () => { | ||
expect( | ||
nextVersion({ major: 1, minor: 0, patch: 0 }, VersionUpgrade.NONE) | ||
).toEqual({ major: 1, minor: 0, patch: 0 }); | ||
expect( | ||
nextVersion({ major: 1, minor: 2, patch: 0 }, VersionUpgrade.NONE) | ||
).toEqual({ major: 1, minor: 2, patch: 0 }); | ||
expect( | ||
nextVersion({ major: 2, minor: 5, patch: 3 }, VersionUpgrade.NONE) | ||
).toEqual({ major: 2, minor: 5, patch: 3 }); | ||
}); | ||
it('patch', () => { | ||
expect( | ||
nextVersion({ major: 1, minor: 0, patch: 0 }, VersionUpgrade.PATCH) | ||
).toEqual({ major: 1, minor: 0, patch: 1 }); | ||
expect( | ||
nextVersion({ major: 1, minor: 2, patch: 0 }, VersionUpgrade.PATCH) | ||
).toEqual({ major: 1, minor: 2, patch: 1 }); | ||
expect( | ||
nextVersion({ major: 2, minor: 5, patch: 3 }, VersionUpgrade.PATCH) | ||
).toEqual({ major: 2, minor: 5, patch: 4 }); | ||
}); | ||
it('minor', () => { | ||
expect( | ||
nextVersion({ major: 1, minor: 0, patch: 0 }, VersionUpgrade.MINOR) | ||
).toEqual({ major: 1, minor: 1, patch: 0 }); | ||
expect( | ||
nextVersion({ major: 1, minor: 2, patch: 0 }, VersionUpgrade.MINOR) | ||
).toEqual({ major: 1, minor: 3, patch: 0 }); | ||
expect( | ||
nextVersion({ major: 2, minor: 5, patch: 3 }, VersionUpgrade.MINOR) | ||
).toEqual({ major: 2, minor: 6, patch: 0 }); | ||
}); | ||
it('major', () => { | ||
expect( | ||
nextVersion({ major: 1, minor: 0, patch: 0 }, VersionUpgrade.MAJOR) | ||
).toEqual({ major: 2, minor: 0, patch: 0 }); | ||
expect( | ||
nextVersion({ major: 1, minor: 2, patch: 0 }, VersionUpgrade.MAJOR) | ||
).toEqual({ major: 2, minor: 0, patch: 0 }); | ||
expect( | ||
nextVersion({ major: 2, minor: 5, patch: 3 }, VersionUpgrade.MAJOR) | ||
).toEqual({ major: 3, minor: 0, patch: 0 }); | ||
}); | ||
}); |