-
-
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.
v2.1.0: adds
readable
to create human-readable numbers from BigInt
- Loading branch information
1 parent
db3c0b5
commit 24b132f
Showing
9 changed files
with
271 additions
and
9 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
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
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
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,65 @@ | ||
import { Token } from '../../../../../src' | ||
import BEP20 from '../../../../../src/blockchains/bsc/BEP20' | ||
import { mock, resetMocks } from 'depay-web3-mock' | ||
|
||
describe('readable', () => { | ||
|
||
beforeEach(resetMocks) | ||
afterEach(resetMocks) | ||
|
||
let blockchain = 'bsc' | ||
|
||
beforeEach(()=> { | ||
mock({ | ||
blockchain, | ||
call: { | ||
to: '0xa0bEd124a09ac2Bd941b10349d8d224fe3c955eb', | ||
api: BEP20, | ||
method: 'decimals', | ||
return: 18 | ||
} | ||
}) | ||
}) | ||
|
||
it('turns a given BigInt number into a human-readable number', async ()=> { | ||
|
||
expect( | ||
(await Token.readable({ | ||
amount: '1231251211232111000000000', | ||
blockchain, | ||
address: '0xa0bed124a09ac2bd941b10349d8d224fe3c955eb' | ||
})).toString() | ||
).toEqual('1231251.211232111') | ||
|
||
expect( | ||
await (new Token({ blockchain, address: '0xa0bed124a09ac2bd941b10349d8d224fe3c955eb' })) | ||
.readable('1231251211232111000000000') | ||
).toEqual('1231251.211232111') | ||
|
||
expect( | ||
(await Token.readable({ | ||
amount: '1231251000000000000000000', | ||
blockchain, | ||
address: '0xa0bed124a09ac2bd941b10349d8d224fe3c955eb' | ||
})).toString() | ||
).toEqual('1231251') | ||
|
||
expect( | ||
await (new Token({ blockchain, address: '0xa0bed124a09ac2bd941b10349d8d224fe3c955eb' })) | ||
.readable('1231251000000000000000000') | ||
).toEqual('1231251') | ||
|
||
expect( | ||
(await Token.readable({ | ||
amount: '1231251100000000000000000', | ||
blockchain, | ||
address: '0xa0bed124a09ac2bd941b10349d8d224fe3c955eb' | ||
})).toString() | ||
).toEqual('1231251.1') | ||
|
||
expect( | ||
await (new Token({ blockchain, address: '0xa0bed124a09ac2bd941b10349d8d224fe3c955eb' })) | ||
.readable('1231251100000000000000000') | ||
).toEqual('1231251.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { Token } from '../../../../../src' | ||
import ERC20 from '../../../../../src/blockchains/ethereum/ERC20' | ||
import { mock, resetMocks } from 'depay-web3-mock' | ||
|
||
describe('readable', () => { | ||
|
||
beforeEach(resetMocks) | ||
afterEach(resetMocks) | ||
|
||
let blockchain = 'ethereum' | ||
|
||
beforeEach(()=> { | ||
mock({ | ||
blockchain, | ||
call: { | ||
to: '0xa0bEd124a09ac2Bd941b10349d8d224fe3c955eb', | ||
api: ERC20, | ||
method: 'decimals', | ||
return: 18 | ||
} | ||
}) | ||
}) | ||
|
||
it('turns a given BigInt number into a human-readable number', async ()=> { | ||
|
||
expect( | ||
(await Token.readable({ | ||
amount: '1231251211232111000000000', | ||
blockchain, | ||
address: '0xa0bed124a09ac2bd941b10349d8d224fe3c955eb' | ||
})).toString() | ||
).toEqual('1231251.211232111') | ||
|
||
expect( | ||
await (new Token({ blockchain, address: '0xa0bed124a09ac2bd941b10349d8d224fe3c955eb' })) | ||
.readable('1231251211232111000000000') | ||
).toEqual('1231251.211232111') | ||
|
||
expect( | ||
(await Token.readable({ | ||
amount: '1231251000000000000000000', | ||
blockchain, | ||
address: '0xa0bed124a09ac2bd941b10349d8d224fe3c955eb' | ||
})).toString() | ||
).toEqual('1231251') | ||
|
||
expect( | ||
await (new Token({ blockchain, address: '0xa0bed124a09ac2bd941b10349d8d224fe3c955eb' })) | ||
.readable('1231251000000000000000000') | ||
).toEqual('1231251') | ||
|
||
expect( | ||
(await Token.readable({ | ||
amount: '1231251100000000000000000', | ||
blockchain, | ||
address: '0xa0bed124a09ac2bd941b10349d8d224fe3c955eb' | ||
})).toString() | ||
).toEqual('1231251.1') | ||
|
||
expect( | ||
await (new Token({ blockchain, address: '0xa0bed124a09ac2bd941b10349d8d224fe3c955eb' })) | ||
.readable('1231251100000000000000000') | ||
).toEqual('1231251.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Token } from 'src' | ||
|
||
describe('Token', () => { | ||
describe('standards', () => { | ||
|
||
it('exports the "ethreum" standard token', async ()=> { | ||
expect(typeof(Token.ethereum.DEFAULT) != 'undefined').toEqual(true) | ||
expect(Token.ethereum.DEFAULT).toEqual(Token.ethereum.ERC20) | ||
}) | ||
|
||
it('exports the "bsc" standard token', async ()=> { | ||
expect(typeof(Token.bsc.DEFAULT) != 'undefined').toEqual(true) | ||
expect(Token.bsc.DEFAULT).toEqual(Token.bsc.BEP20) | ||
}) | ||
}) | ||
}) |