forked from Uniswap/interface
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: make token list version bump error quieter (Uniswap#6271)
* fix: use console.debug for expected transient error * fix: add tests * fix: name and lints
- Loading branch information
Showing
3 changed files
with
87 additions
and
8 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
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,64 @@ | ||
import { TokenList, VersionUpgrade } from '@uniswap/token-lists' | ||
|
||
import { shouldAcceptVersionUpdate } from './utils' | ||
|
||
function buildTokenList(count: number): TokenList { | ||
const tokens = [] | ||
for (let i = 0; i < count; i++) { | ||
tokens.push({ | ||
name: `Token ${i}`, | ||
address: `0x${i.toString().padStart(40, '0')}`, | ||
symbol: `T${i}`, | ||
decimals: 18, | ||
chainId: 1, | ||
logoURI: `https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0x${i | ||
.toString() | ||
.padStart(40, '0')}/logo.png`, | ||
}) | ||
} | ||
return { | ||
name: 'Defi', | ||
logoURI: | ||
'https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0x514910771AF9Ca656af840dff83E8264EcF986CA/logo.png', | ||
keywords: ['defi', 'uniswap'], | ||
timestamp: '2021-03-12T00:00:00.000Z', | ||
version: { | ||
major: 1, | ||
minor: 0, | ||
patch: 0, | ||
}, | ||
tokens, | ||
} | ||
} | ||
|
||
describe('shouldAcceptMinorVersionUpdate', () => { | ||
it('returns false for patch when tokens have changed', () => { | ||
expect(shouldAcceptVersionUpdate('test_list', buildTokenList(1), buildTokenList(2), VersionUpgrade.PATCH)).toEqual( | ||
false | ||
) | ||
}) | ||
|
||
it('returns true for patch when tokens are the same', () => { | ||
expect(shouldAcceptVersionUpdate('test_list', buildTokenList(1), buildTokenList(1), VersionUpgrade.PATCH)).toEqual( | ||
true | ||
) | ||
}) | ||
|
||
it('returns true for minor version bump with tokens added', () => { | ||
expect(shouldAcceptVersionUpdate('test_list', buildTokenList(1), buildTokenList(2), VersionUpgrade.MINOR)).toEqual( | ||
true | ||
) | ||
}) | ||
|
||
it('returns true for no version bump', () => { | ||
expect(shouldAcceptVersionUpdate('test_list', buildTokenList(1), buildTokenList(2), VersionUpgrade.MINOR)).toEqual( | ||
true | ||
) | ||
}) | ||
|
||
it('returns false for minor version bump with tokens removed', () => { | ||
expect(shouldAcceptVersionUpdate('test_list', buildTokenList(2), buildTokenList(1), VersionUpgrade.MINOR)).toEqual( | ||
false | ||
) | ||
}) | ||
}) |
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,19 @@ | ||
import { minVersionBump, TokenList, VersionUpgrade } from '@uniswap/token-lists' | ||
|
||
export function shouldAcceptVersionUpdate( | ||
listUrl: string, | ||
current: TokenList, | ||
update: TokenList, | ||
targetBump: VersionUpgrade.PATCH | VersionUpgrade.MINOR | ||
): boolean { | ||
const min = minVersionBump(current.tokens, update.tokens) | ||
// Automatically update minor/patch as long as bump matches the min update. | ||
if (targetBump >= min) { | ||
return true | ||
} else { | ||
console.debug( | ||
`List at url ${listUrl} could not automatically update because the version bump was only PATCH/MINOR while the update had breaking changes and should have been MAJOR` | ||
) | ||
return false | ||
} | ||
} |