import { ethers, utils } from 'ethers'; | |
let provider = new ethers.providers.JsonRpcProvider('https://kovan.infura.io/v3/your_key'); | |
const abi = []; // https://ethereumdev.io/abi-for-erc20-contract-on-ethereum/ | |
test('network sanity check', async () => { | |
let network = await provider.getNetwork(); | |
expect(network.chainId).toEqual(42); | |
}); | |
test('Confirm correct on-chain data DAI (18 decimals)', async () => { | |
const daiKovanAddr = '0x1528F3FCc26d13F7079325Fb78D9442607781c8C'; | |
const tokenContract = new ethers.Contract(daiKovanAddr, abi, provider); // See bottom of page for abi | |
const tokenSymbol = await tokenContract.symbol(); | |
const tokenDecimals = await tokenContract.decimals(); | |
expect(tokenSymbol).toEqual('DAI'); | |
expect(tokenDecimals).toEqual(18); | |
}); | |
test('Confirm correct on-chain data USDC (6 decimals)', async () => { | |
const usdcKovanAddr = '0x2F375e94FC336Cdec2Dc0cCB5277FE59CBf1cAe5'; | |
const tokenContract = new ethers.Contract(usdcKovanAddr, abi, provider); | |
const tokenSymbol = await tokenContract.symbol(); | |
const tokenDecimals = await tokenContract.decimals(); | |
expect(tokenSymbol).toEqual('USDC'); | |
expect(tokenDecimals).toEqual(6); | |
}); | |
test('Confirm checksum address conversion', async () => { | |
const nonCheckSumAddr = '0xd115bffabbdd893a6f7cea402e7338643ced44a6'; | |
const checkSumAddr = utils.getAddress(nonCheckSumAddr); | |
expect(checkSumAddr).toEqual('0xD115BFFAbbdd893A6f7ceA402e7338643Ced44a6'); | |
expect(nonCheckSumAddr).not.toBe( | |
'0xD115BFFAbbdd893A6f7ceA402e7338643Ced44a6' | |
); | |
}); | |
test('Invalid checksum address conversion', async () => { | |
const nonCheckSumAddr = '0xD115BFfabbdd893a6f7cea402E7338643ced44a6'; | |
let checkSumAddr; | |
try { | |
checkSumAddr = utils.getAddress(nonCheckSumAddr); | |
} catch { | |
checkSumAddr = false; | |
} | |
expect(checkSumAddr).toEqual(false); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment