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]: Command solana-test-validator --bpf-program... not recognized as used #159

Closed
gikf opened this issue May 3, 2023 · 5 comments · Fixed by #166
Closed

[BUG]: Command solana-test-validator --bpf-program... not recognized as used #159

gikf opened this issue May 3, 2023 · 5 comments · Fixed by #166

Comments

@gikf
Copy link
Member

gikf commented May 3, 2023

Issue/Experience

Learn the Metaplex SDK by Minting an NFT - Lesson 35 requires running in terminal command:

solana-test-validator --bpf-program metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s ./mlp_token.so --reset

Despite of running it, test might not recognize that. Due to how command from terminal is saved in temp for tests.


I had some troubles with passing this test. Seemingly everything was fine, but it still couldn't pass.

await new Promise(res => setTimeout(() => res(), 2000));
// TODO: Tests do not watch `.temp.log`
const temp = await __helpers.getTemp();
console.log(temp.slice(0, 500));
assert.include(
temp,
'solana-test-validator --bpf-program metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s ./mlp_token.so --reset',
'Run `solana-test-validator --bpf-program metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s ./mlp_token.so --reset` in the terminal'
);

Meanwhile, copied from the actual field in the client console:

\u001b[01;32mroot\u001b[00m \u001b[01;34m/workspace/solana-curriculum/learn-the-metaplex-sdk-by-minting-an-nft\u001b[00m (main) $ \u001b[K🟢 DEBUG:  2023-05-02 13:49:48 Watcher: change - /workspace/solana-curriculum/.logs/.terminal-out.log
solana-test-validator --bpf-program metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s ./mlp_token.so --r\rreset
🟢 DEBUG:  2023-05-02 13:50:50 Watcher: change - /workspace/solana-curriculum/curriculum/locales/english/learn-the-metaplex-sdk-by-minting-an-nft.md
Ledger location: test-ledger
Log: test-ledger/validator.log
Initializing...
Waiting for fees to stabilize 1...
Waiting for fees to stabilize 2...
Connecting...
(...)

Relevant line:

solana-test-validator --bpf-program metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s ./mlp_token.so --r\rreset

As it can be seen ending differs from what is desired. How does r\rr gets there? It's from when long line entered to the terminal wraps itself.

After widening terminal a bit, so it doesn't wrap, test passed without issues.


Looks like terminal wrapping needs to be handled at some point. But, here in test, or at the step of reading from temp?

Output of running node tooling/camper-info.js from the workspace root

🔵 INFO:   Project:  learn-the-metaplex-sdk-by-minting-an-nft
🔵 INFO:   Lesson Number:  1
🔵 INFO:   Curriculum Version:  0.2.0
🔵 INFO:   freeCodeCamp - Courses:  undefined
🔵 INFO:   Commit:  0ed5a55 chore(deps): update react monorepo

🔵 INFO:   OS Info: 
    Architecture: x64
    Platform: linux
    Release: 5.15.0-71-generic
    Type: Linux
@ShaunSHamilton
Copy link
Member

Thanks for opening this.

If there is no easy way around the wrapping, the test could be changed to:

const command = `curl http://127.0.0.1:8899 -X POST -H "Content-Type: application/json" -d '
  {
    "jsonrpc": "2.0",
    "id": 1,
    "method": "getProgramAccounts",
    "params": [
      "BPFLoader2111111111111111111111111111111111", {
        "encoding": "base64",
        "dataSlice": {
          "length": 0,
          "offset": 0
        }
      }
    ]
}'`;
const { stdout, stderr } = await __helpers.getCommandOutput(command);
try {
  const jsonOut = JSON.parse(stdout);
  assert.exists(
    jsonOut.result.find(
      r => r.pubkey === 'metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s'
    )
  );
} catch (e) {
  assert.fail(
    e,
    'Try running `solana-test-validator --bpf-program metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s ./mlp_token.so --reset`'
  );
}

@gikf
Copy link
Member Author

gikf commented May 5, 2023

I've unsuccessfully tried to change in .bashrc command saving to the log, to remove the \r in the text that's saved, but keep it in the terminal.

What worked was changing getTemp to return string with \r removed:

  return tempLogs.replace(/(.)\r\1/g, '$1');

Which appears to be much simpler. I'm unable to come up with an example when keeping \r might be needed for test case.

What do you think?

@ShaunSHamilton
Copy link
Member

What do you think?

Is the character before the \r always repeated after?

I'm unable to come up with an example when keeping \r might be needed for test case.

I can imagine some cases where a \n might be important (see Tom's Bash/RDB course), but am not sure when a \r is useful over a \n - I do not understand why there is a \r and not a \n.

@gikf
Copy link
Member Author

gikf commented May 6, 2023

Is the character before the \r always repeated after?

I thought so, but it's more interesting. When typing by hand character is not repeated, meanwhile it is repeated when text is pasted to the terminal. 👀

However, when typing it, one can encounter different issue - any mistake will prevent test from passing. Even if it's corrected before command is submitted. The line in .temp.log will contain ie. \b for pressing backspace.

@ShaunSHamilton
Copy link
Member

Ah, yes. I was not thinking about the prompt input like that.

In that case, I will document this behaviour as a warning when using .temp.log, and we should change this test to what I previously mentioned.

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

Successfully merging a pull request may close this issue.

2 participants