Skip to content

Commit

Permalink
ci
Browse files Browse the repository at this point in the history
  • Loading branch information
eternauta1337 committed Mar 11, 2024
1 parent 3f55808 commit 397dc72
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 33 deletions.
17 changes: 13 additions & 4 deletions packages/ethernaut-interact/src/tasks/token-address.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
44 changes: 15 additions & 29 deletions packages/ethernaut-interact/test/tasks/token-address.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})
})

0 comments on commit 397dc72

Please sign in to comment.