@iam4x/bsc-scan
Version:
An efficient BNB and token balance scanner
2 lines • 1.41 kB
JavaScript
import{decode,encode,fromHex}from"@findeth/abi";import{ethers,waffle}from"hardhat";import{ETHER_BALANCES_ID,ETHER_BALANCES_TYPE,TOKEN_BALANCES_ID,TOKEN_BALANCES_TYPE}from"../constants";import{fixture}from"../eth-scan.test";import{withId}from"../utils/abi";import EthersProvider from"./ethers";const{createFixtureLoader,provider}=waffle,{isProvider,call}=EthersProvider,loadFixture=createFixtureLoader(provider.getWallets(),provider);describe("isProvider",()=>{it("checks if a provider is an Ethers.js provider",()=>{expect(isProvider(ethers.provider)).toBe(!0),expect(isProvider({})).toBe(!1)})}),describe("call",()=>{it("gets the Ether balances from the contract",async()=>{const{contract:a,addresses:b}=await loadFixture(fixture),c=withId(ETHER_BALANCES_ID,encode(ETHER_BALANCES_TYPE,[b])),d=await call(ethers.provider,a.address,c),e=decode(["uint256[]"],fromHex(d))[0];for(let a=0;a<b.length;a++){const c=BigInt((await ethers.provider.getBalance(b[a])).toHexString());expect(c).toBe(e[a])}}),it("gets the token balances from the contract",async()=>{const{contract:a,addresses:b,token:c}=await loadFixture(fixture);await c.mock.balanceOf.returns("1000");const d=withId(TOKEN_BALANCES_ID,encode(TOKEN_BALANCES_TYPE,[b,c.address])),e=await call(ethers.provider,a.address,d),f=decode(["uint256[]"],fromHex(e))[0];for(let a=0;a<b.length;a++)expect(f[a]).toBe(1000n)})});
//# sourceMappingURL=ethers.test.js.map