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

CPIs Lab code: Confusing amount of tokens minted #311

Open
toblich opened this issue Aug 8, 2024 · 3 comments · May be fixed by #664
Open

CPIs Lab code: Confusing amount of tokens minted #311

toblich opened this issue Aug 8, 2024 · 3 comments · May be fixed by #664

Comments

@toblich
Copy link

toblich commented Aug 8, 2024

The following lines (program and test) actually yields 98 instead of the expected 10 million.

expect(Number(userAta.amount)).to.equal((10 * 10) ^ 6);

This is actually doing a bit-XOR between 10 * 10 = 100 and 6. In the provided test code, you can just print it and see. It actually does

100 ---> 0b1100100
6   ---> 0b0000110
----------------------
98  <--- 0b1100010  (result of XOR'ing the bits)

The math should be fixed (i.e. use the proper operators/methods) to actually yield 10 million, that is 10 tokens using 6 decimal places. As this stackoverflow answer points out, the ^ in Rust is doing a bitwise XOR and not exponentiation.

Copy link

github-actions bot commented Dec 4, 2024

This issue has been automatically marked as stale because it has not had recent activity. Remove stale label or comment or this will be closed in 5 days.

@toblich
Copy link
Author

toblich commented Dec 4, 2024

I've just checked and the bad math is still present in the latest docs, so this issue is still valid...

@Woody4618
Copy link
Collaborator

Woody4618 commented Dec 4, 2024

Oh true good catch, it should probably be something like
let amount: u64 = 10u64 * 10u64.pow(6);

Could you open a PR?

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