-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #118 from peanutprotocol/getTokenBalance
getTokenBalance function
- Loading branch information
Showing
5 changed files
with
153 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import * as peanut from '../../src/index' | ||
|
||
describe('getTokenBalance', function () { | ||
it('get erc20 token balance with type and decimals', async () => { | ||
const tokenAddress = '0xe9bc9ad74cca887aff32ba09a121b1256fc9f052' | ||
const walletAddress = '0x2d826aD1EAD5c8a2bC46ab93d9D0c6BEe0d39918' | ||
const chainId = '137' | ||
const tokenType = peanut.interfaces.EPeanutLinkType.erc20 | ||
const tokenDecimals = 18 | ||
|
||
const result = await peanut.getTokenBalance({ tokenAddress, walletAddress, chainId, tokenType, tokenDecimals }) | ||
|
||
expect(Number(result)).toBeGreaterThan(0) | ||
}, 1000000000) | ||
|
||
it('get erc20 token balance with type', async () => { | ||
const tokenAddress = '0xe9bc9ad74cca887aff32ba09a121b1256fc9f052' | ||
const walletAddress = '0x2d826aD1EAD5c8a2bC46ab93d9D0c6BEe0d39918' | ||
const chainId = '137' | ||
const tokenType = peanut.interfaces.EPeanutLinkType.erc20 | ||
|
||
const result = await peanut.getTokenBalance({ tokenAddress, walletAddress, chainId, tokenType }) | ||
|
||
expect(Number(result)).toBeGreaterThan(0) | ||
}, 1000000000) | ||
|
||
it('get erc20 token balance with decimals', async () => { | ||
const tokenAddress = '0xe9bc9ad74cca887aff32ba09a121b1256fc9f052' | ||
const walletAddress = '0x2d826aD1EAD5c8a2bC46ab93d9D0c6BEe0d39918' | ||
const chainId = '137' | ||
const tokenDecimals = 18 | ||
const result = await peanut.getTokenBalance({ tokenAddress, walletAddress, chainId, tokenDecimals }) | ||
|
||
expect(Number(result)).toBeGreaterThan(0) | ||
}, 1000000000) | ||
|
||
it('get erc20 token balance without type and decimals', async () => { | ||
const tokenAddress = '0xe9bc9ad74cca887aff32ba09a121b1256fc9f052' | ||
const walletAddress = '0x2d826aD1EAD5c8a2bC46ab93d9D0c6BEe0d39918' | ||
const chainId = '137' | ||
|
||
const result = await peanut.getTokenBalance({ tokenAddress, walletAddress, chainId }) | ||
|
||
expect(Number(result)).toBeGreaterThan(0) | ||
}, 1000000000) | ||
|
||
it('get native token balance without type and decimals', async () => { | ||
const tokenAddress = '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee' | ||
const walletAddress = '0x2d826aD1EAD5c8a2bC46ab93d9D0c6BEe0d39918' | ||
const chainId = '137' | ||
|
||
const result = await peanut.getTokenBalance({ tokenAddress, walletAddress, chainId }) | ||
|
||
expect(Number(result)).toBeGreaterThan(0) | ||
}, 1000000000) | ||
|
||
it('get native token balance without type and decimals', async () => { | ||
const tokenAddress = '0x0000000000000000000000000000000000000000' | ||
const walletAddress = '0x2d826aD1EAD5c8a2bC46ab93d9D0c6BEe0d39918' | ||
const chainId = '137' | ||
|
||
const result = await peanut.getTokenBalance({ tokenAddress, walletAddress, chainId }) | ||
|
||
expect(Number(result)).toBeGreaterThan(0) | ||
}, 1000000000) | ||
}) |