01-edu / public

📚 @01-edu's Public Repository
http://public.01-edu.org/
214 stars 440 forks source link

[BUG] local-node-info subject #2411

Open MalekLahbib opened 7 months ago

MalekLahbib commented 7 months ago

local-node-info

I wrote a code that's working fine locally, but doesn't pass the test, I tried with "web3" package and "ethers" package, here's my code:

<!DOCTYPE html>
<body>
    <h1>NETWORK INFOS</h1>
  <h2>Chain ID: <span id="chainId"></span></h2>
  <h2>Number of blocks : <span id="blockNumber"></span></h2>

  <script src="https://cdn.ethers.io/scripts/ethers-v4.min.js"
        charset="utf-8"
        type="text/javascript">
  </script>
  <script type="text/javascript">
    document.addEventListener('DOMContentLoaded', async () => {
      try {
        // Connect to a local Ethereum node
        const provider = new ethers.providers.JsonRpcProvider('http://localhost:8545');

        // Get the chain ID
        const chainId = await provider.getNetwork().then(network => network.chainId);

        // Get the block number
        //let blockNumber = 0;
        const blockNumber = await provider.getBlockNumber();

        // Display information on the page
        document.getElementById('chainId').textContent = chainId;
        document.getElementById('blockNumber').textContent = blockNumber;
      } catch (error) {
        console.error('Error:', error.message);
      }
    });
  </script>
</body>
</html>

and here's the test response: [1m Puppeteer old Headless deprecation warning: In the near feature headless: true will default to the new Headless mode for Chrome instead of the old Headless implementation. For more information, please see https://developer.chrome.com/articles/new-headless/. Consider opting in early by passing headless: "new" to puppeteer.launch() If you encounter any bugs, please report them to https://github.com/puppeteer/puppeteer/issues/new/choose.

Local node info 1) Should have the correct chainID 2) Should have the correct number of blocks

0 passing (12s) 2 failing

1) Local node info Should have the correct chainID: Error: Timeout of 10000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (/jail/test/local-node-info.test.js) at listOnTimeout (node:internal/timers:569:17) at processTimers (node:internal/timers:512:7)

2) Local node info Should have the correct number of blocks:

  AssertionError: expected NaN to equal +0
  + expected - actual

  -NaN
  +0

  at Context.<anonymous> (test/local-node-info.test.js:54:45)
  at processTicksAndRejections (node:internal/process/task_queues:95:5)
nprimo commented 7 months ago

Hi @MalekLahbib, I have tried to run your solution locally, and it does not work for me :) I might have tried an incomplete version: could you please send me the full solution text using this formatting?

MalekLahbib commented 7 months ago

@nprimo thanks for the formatting advice, I didn't give attention to it, from now I will, I updated my comment so now you have the full code. I launched a local eth node with "npx hardhat node", and when I open my html file it works.

MalekLahbib commented 7 months ago

Hello @nprimo,

I'm still waiting for a response to this issue.

Best Regards

nprimo commented 7 months ago

Hi @MalekLahbib, I am currently working on this

Xalava commented 6 months ago

Hello @MalekLahbib,

Thank you for submitting this issue.