Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] local-node-info subject #2411

Closed
MalekLahbib opened this issue Jan 26, 2024 · 5 comments · Fixed by #2444 · May be fixed by 01-edu/Branch-Blockchain#91
Closed

[BUG] local-node-info subject #2411

MalekLahbib opened this issue Jan 26, 2024 · 5 comments · Fixed by #2444 · May be fixed by 01-edu/Branch-Blockchain#91
Assignees
Labels

Comments

@MalekLahbib
Copy link

MalekLahbib commented Jan 26, 2024

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�[43m�[30m
Puppeteer old Headless deprecation warning:�[0m�[33m
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.�[0m

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. (test/local-node-info.test.js:54:45)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)

@nprimo nprimo self-assigned this Jan 26, 2024
@nprimo
Copy link
Contributor

nprimo commented Jan 26, 2024

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
Copy link
Author

@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
Copy link
Author

Hello @nprimo,

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

Best Regards

@nprimo
Copy link
Contributor

nprimo commented Feb 6, 2024

Hi @MalekLahbib, I am currently working on this

Xalava added a commit to Xalava/01-edu-public that referenced this issue Feb 16, 2024
Xalava added a commit to Xalava/01-edu-public that referenced this issue Feb 16, 2024
Xalava added a commit to Xalava/01-edu-public that referenced this issue Feb 16, 2024
@Xalava
Copy link
Contributor

Xalava commented Feb 16, 2024

Hello @MalekLahbib,

Thank you for submitting this issue.

  • Your page is correct. However, the test environment does not have access to the internet for security reasons, which is why your library import fails. You can download the library, add it to your repository, and import it locally. I've updated the instructions for clarity.
  • The warning issue is harmless, but I've submitted a PR to remove it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
4 participants