From 397dc72c6f247fb0095553ed491cedea9718c127 Mon Sep 17 00:00:00 2001 From: Alejandro Date: Mon, 11 Mar 2024 10:47:13 -0300 Subject: [PATCH] ci --- .../src/tasks/token-address.js | 17 +++++-- .../test/tasks/token-address.test.js | 44 +++++++------------ 2 files changed, 28 insertions(+), 33 deletions(-) diff --git a/packages/ethernaut-interact/src/tasks/token-address.js b/packages/ethernaut-interact/src/tasks/token-address.js index f699543e..d13522b4 100644 --- a/packages/ethernaut-interact/src/tasks/token-address.js +++ b/packages/ethernaut-interact/src/tasks/token-address.js @@ -15,13 +15,22 @@ require('../scopes/interact') undefined, types.string, ) - .setAction(async ({ name }, hre) => { + .addOptionalParam( + 'chainId', + 'The chain id of the network where the token is deployed', + undefined, + types.string, + ) + .setAction(async ({ name, chainId }, hre) => { try { // Id network - const network = (await hre.ethers.provider.getNetwork()).toJSON() - const chainId = Number(network.chainId) + if (!chainId) { + const network = (await hre.ethers.provider.getNetwork()).toJSON() + chainId = Number(network.chainId) + } else { + chainId = Number(chainId) + } const chainInfo = chains.find((c) => c.chainId === chainId) - console.log('>', chainId) // Filter candidates by network const candidates = tokens.filter((t) => { diff --git a/packages/ethernaut-interact/test/tasks/token-address.test.js b/packages/ethernaut-interact/test/tasks/token-address.test.js index dbbbb07a..2320aa42 100644 --- a/packages/ethernaut-interact/test/tasks/token-address.test.js +++ b/packages/ethernaut-interact/test/tasks/token-address.test.js @@ -3,40 +3,26 @@ const { Terminal } = require('ethernaut-common/src/terminal') describe('token-address', function () { const terminal = new Terminal() - let getNetworkCache - - before('simulate network', async function () { - getNetworkCache = hre.ethers.provider.getNetwork - hre.ethers.provider.getNetwork = async function () { - return { - chainId: 1, - } - } + before('make call', async function () { + await terminal.run( + 'npx hardhat interact token-address USDT --chain-id 1', + 2000, + ) }) - after('restore provider', async function () { - hre.ethers.provider.getNetwork = getNetworkCache + it('shows the token name', async function () { + terminal.has('Token name: USDT') }) - describe('when querying for the address of USDT on mainnet', function () { - before('make call', async function () { - await terminal.run('npx hardhat interact token-address USDT', 2000) - }) - - it('shows the token name', async function () { - terminal.has('Token name: USDT') - }) - - it('shows the network', async function () { - terminal.has('Network: Ethereum Mainnet') - }) + it('shows the network', async function () { + terminal.has('Network: Ethereum Mainnet') + }) - it('shows the symbol', async function () { - terminal.has('Symbol: USDT') - }) + it('shows the symbol', async function () { + terminal.has('Symbol: USDT') + }) - it('shows the address', async function () { - terminal.has('Address: 0xdac17f958d2ee523a2206206994597c13d831ec7') - }) + it('shows the address', async function () { + terminal.has('Address: 0xdac17f958d2ee523a2206206994597c13d831ec7') }) })