-
Notifications
You must be signed in to change notification settings - Fork 88
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
Showing
10 changed files
with
239 additions
and
33 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,13 @@ | ||
import {get24Time, getDate} from '../../utils'; | ||
|
||
describe('getDate', () => { | ||
it('should get date', () => { | ||
expect(getDate(1644828892412)).toEqual('14/02/2022'); | ||
}); | ||
}); | ||
|
||
describe('get24Time', () => { | ||
it('should get 24 time', () => { | ||
expect(get24Time(1644828892412).endsWith(':54:52')).toBeTruthy(); | ||
}); | ||
}); |
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,34 +1,39 @@ | ||
import {ChainType, TransactionHashPrefix} from '../../enums'; | ||
import {hashEquals, txHash} from '../../utils'; | ||
|
||
it('should calc tx hash', () => { | ||
const from_address = '0xcf98f0a8edc6a730e1ca6b64a2528c6be031cb12'; | ||
const to_address = '1384622289134235426972866085149619554404298343372540338336104355150443775597'; | ||
const selector = '1285101517810983806491589552491143496277809242732141897358598292095611420389'; | ||
const nonce = '55'; | ||
const payload = [ | ||
'17466514784613283928575916580398045172482824287888203092305238190565527099', | ||
'52145000000000', | ||
'0' | ||
]; | ||
describe('txHash', () => { | ||
it('should calc tx hash', () => { | ||
const from_address = '0xcf98f0a8edc6a730e1ca6b64a2528c6be031cb12'; | ||
const to_address = | ||
'1384622289134235426972866085149619554404298343372540338336104355150443775597'; | ||
const selector = '1285101517810983806491589552491143496277809242732141897358598292095611420389'; | ||
const nonce = '55'; | ||
const payload = [ | ||
'17466514784613283928575916580398045172482824287888203092305238190565527099', | ||
'52145000000000', | ||
'0' | ||
]; | ||
|
||
expect( | ||
txHash( | ||
TransactionHashPrefix.L1_HANDLER, | ||
from_address, | ||
to_address, | ||
selector, | ||
payload, | ||
ChainType.GOERLI.id, | ||
nonce | ||
) | ||
).toEqual('0x35ab0e4de971ac0736844ef36a05796dc41490c165373923c423f4b995983e8'); | ||
expect( | ||
txHash( | ||
TransactionHashPrefix.L1_HANDLER, | ||
from_address, | ||
to_address, | ||
selector, | ||
payload, | ||
ChainType.GOERLI.id, | ||
nonce | ||
) | ||
).toEqual('0x35ab0e4de971ac0736844ef36a05796dc41490c165373923c423f4b995983e8'); | ||
}); | ||
}); | ||
|
||
it('should compare hashes', () => { | ||
expect(hashEquals([1, 2])).toBeTruthy(); | ||
expect(hashEquals([1, 2, 3], [1, 2, 3])).toBeTruthy(); | ||
expect(hashEquals([1, 2, 3], [1, 2, 3], [1, 2, 3])).toBeTruthy(); | ||
expect(hashEquals([1, 2, 3], [1, 2, 3], [1])).toBeFalsy(); | ||
expect(hashEquals([1, 2, 3], [1, 2])).toBeFalsy(); | ||
describe('hashEquals', () => { | ||
it('should compare hashes', () => { | ||
expect(hashEquals([1, 2])).toBeTruthy(); | ||
expect(hashEquals([1, 2, 3], [1, 2, 3])).toBeTruthy(); | ||
expect(hashEquals([1, 2, 3], [1, 2, 3], [1, 2, 3])).toBeTruthy(); | ||
expect(hashEquals([1, 2, 3], [1, 2, 3], [1])).toBeFalsy(); | ||
expect(hashEquals([1, 2, 3], [1, 2])).toBeFalsy(); | ||
}); | ||
}); |
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,93 @@ | ||
import { | ||
parseFromDecimals, | ||
parseFromFelt, | ||
parseFromUint256, | ||
parseToDecimals, | ||
parseToUint256, | ||
UNIT_MAP | ||
} from '../../utils'; | ||
|
||
describe('UNIT_MAP', () => { | ||
it('should init unit map', () => { | ||
expect(UNIT_MAP).toEqual({ | ||
0: 'noether', | ||
1: 'wei', | ||
1000: 'femtoether', | ||
1000000: 'picoether', | ||
1000000000: 'nano', | ||
1000000000000: 'micro', | ||
1000000000000000: 'milli', | ||
1000000000000000000: 'ether', | ||
'1000000000000000000000': 'grand', | ||
'1000000000000000000000000': 'mether', | ||
'1000000000000000000000000000': 'gether', | ||
'1000000000000000000000000000000': 'tether' | ||
}); | ||
}); | ||
|
||
describe('parseToDecimals', () => { | ||
it('should parse to decimals', () => { | ||
expect(parseToDecimals('1')).toEqual('1000000000000000000'); | ||
expect(parseToDecimals('1', 3)).toEqual('1000'); | ||
expect(parseToDecimals('1', 6)).toEqual('1000000'); | ||
expect(parseToDecimals('1', 9)).toEqual('1000000000'); | ||
expect(parseToDecimals('1', 12)).toEqual('1000000000000'); | ||
expect(parseToDecimals('1', 15)).toEqual('1000000000000000'); | ||
expect(parseToDecimals('1', 18)).toEqual('1000000000000000000'); | ||
}); | ||
}); | ||
|
||
describe('parseFromDecimals', () => { | ||
it('should parse from decimals', () => { | ||
expect(parseFromDecimals('1000000000000000000')).toEqual(1); | ||
expect(parseFromDecimals('1000000000000000000', 3)).toEqual(1000000000000000); | ||
expect(parseFromDecimals('1000000000000000000', 6)).toEqual(1000000000000); | ||
expect(parseFromDecimals('1000000000000000000', 9)).toEqual(1000000000); | ||
expect(parseFromDecimals('1000000000000000000', 12)).toEqual(1000000); | ||
expect(parseFromDecimals('1000000000000000000', 15)).toEqual(1000); | ||
expect(parseFromDecimals('1000000000000000000', 18)).toEqual(1); | ||
}); | ||
}); | ||
|
||
describe('parseFromFelt', () => { | ||
it('should parse from felt', () => { | ||
expect(parseFromFelt('0x1')).toEqual(1); | ||
expect(parseFromFelt('0x10')).toEqual(16); | ||
expect(parseFromFelt('0x100')).toEqual(256); | ||
}); | ||
}); | ||
|
||
describe('parseToUint256', () => { | ||
it('should parse to uint256', () => { | ||
expect(parseToUint256('100')).toEqual({ | ||
high: '0x0', | ||
low: '0x56bc75e2d63100000', | ||
type: 'struct' | ||
}); | ||
expect(parseToUint256('10000')).toEqual({ | ||
high: '0x0', | ||
low: '0x21e19e0c9bab2400000', | ||
type: 'struct' | ||
}); | ||
expect(parseToUint256('10000000')).toEqual({ | ||
high: '0x0', | ||
low: '0x84595161401484a000000', | ||
type: 'struct' | ||
}); | ||
}); | ||
}); | ||
|
||
describe('parseFromUint256', () => { | ||
it('should parse from uint256', () => { | ||
expect(parseFromUint256({high: '0x0', low: '0x56bc75e2d63100000', type: 'struct'})).toEqual( | ||
100 | ||
); | ||
expect(parseFromUint256({high: '0x0', low: '0x21e19e0c9bab2400000', type: 'struct'})).toEqual( | ||
10000 | ||
); | ||
expect( | ||
parseFromUint256({high: '0x0', low: '0x84595161401484a000000', type: 'struct'}) | ||
).toEqual(10000000); | ||
}); | ||
}); | ||
}); |
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,8 @@ | ||
import {capitalize} from '../../utils'; | ||
|
||
describe('capitalize', () => { | ||
it('should capitalize string', () => { | ||
expect(capitalize('hello')).toEqual('Hello'); | ||
expect(capitalize('some message')).toEqual('Some message'); | ||
}); | ||
}); |
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 {isEth} from '../../utils'; | ||
|
||
describe('isEth', () => { | ||
it('should return true for eth symbol as string', () => { | ||
expect(isEth('ETH')).toBeTruthy(); | ||
}); | ||
|
||
it('should return true for eth token as object', () => { | ||
expect(isEth({symbol: 'ETH'})).toBeTruthy(); | ||
}); | ||
|
||
it('should return false for non-eth symbol as string', () => { | ||
expect(isEth('DAI')).toBeFalsy(); | ||
}); | ||
|
||
it('should return false for non-eth token as object', () => { | ||
expect(isEth({symbol: 'DAI'})).toBeFalsy(); | ||
}); | ||
}); |
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,31 @@ | ||
import {formatBalance, shortenAddress} from '../../utils'; | ||
|
||
describe('formatBalance', () => { | ||
it('should format balance to 5 digits precision', () => { | ||
expect(formatBalance(1.222243232)).toEqual(1.22224); | ||
expect(formatBalance(3000.232143123212)).toEqual(3000.23214); | ||
expect(formatBalance(10.000000001)).toEqual(10); | ||
}); | ||
|
||
it('should return N/A for non-numbers', () => { | ||
expect(formatBalance('')).toBe('N/A'); | ||
expect(formatBalance(null)).toBe('N/A'); | ||
expect(formatBalance()).toBe('N/A'); | ||
}); | ||
}); | ||
|
||
describe('shortenAddress', () => { | ||
it('should shorten long address', () => { | ||
expect(shortenAddress('0x9e2bd0a6b6b98f4586a867678f5ebd3dcfda02e7')).toEqual('0x9e2...2e7'); | ||
}); | ||
|
||
it('should return the same address for short address', () => { | ||
expect(shortenAddress('0x9ed0a')).toEqual('0x9ed0a'); | ||
}); | ||
|
||
it('should return empty string for bad input', () => { | ||
expect(shortenAddress('')).toBe(''); | ||
expect(shortenAddress()).toBe(''); | ||
expect(shortenAddress(null)).toBe(''); | ||
}); | ||
}); |
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