UNPKG

@iam4x/bsc-scan

Version:

An efficient BNB and token balance scanner

2 lines 1.78 kB
import{decode,encode,fromHex}from"@findeth/abi";import{EthereumProvider}from"eip1193-provider";import{network,ethers,waffle}from"hardhat";import{JsonRpcServer}from"hardhat/internal/hardhat-network/jsonrpc/server";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 EIP1193Provider from"./eip-1193";const{createFixtureLoader,provider}=waffle,{isProvider,call}=EIP1193Provider,loadFixture=createFixtureLoader(provider.getWallets(),provider),server=new JsonRpcServer({hostname:"127.0.0.1",port:8546,provider:network.provider}),ethereumProvider=new EthereumProvider("http://127.0.0.1:8546");beforeAll(async()=>{await server.listen()},1e5),afterAll(async()=>{await server.close()}),describe("isProvider",()=>{it("checks if a provider is an EIP-1193 provider",()=>{expect(isProvider(ethereumProvider)).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(ethereumProvider,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(ethereumProvider,a.address,d),f=decode(["uint256[]"],fromHex(e))[0];for(let a=0;a<b.length;a++)expect(f[a]).toBe(1000n)})}); //# sourceMappingURL=eip-1193.test.js.map