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 · 0 comments
Open

CPIs Lab code: Confusing amount of tokens minted #311

toblich opened this issue Aug 8, 2024 · 0 comments

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.

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

No branches or pull requests

1 participant