-
Notifications
You must be signed in to change notification settings - Fork 146
tighten docs/tests for pubkey #177
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
base: main
Are you sure you want to change the base?
Conversation
@febo sir, is it helpfull or should I close this? |
sdk/pubkey/src/lib.rs
Outdated
@@ -4,6 +4,17 @@ pub use five8_const::decode_32_const; | |||
pub use pinocchio; | |||
|
|||
/// Convenience macro to define a static `Pubkey` value. | |||
/// | |||
/// This macro validates the pubkey at compile time, ensuring it's a valid |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not always in compile time – it depends on the input. The const
qualifier allows it to be done in compile time when the input is static.
sdk/pubkey/README.md
Outdated
@@ -48,8 +48,7 @@ pinocchio_pubkey::declare_id!("Ping111111111111111111111111111111111111111"); | |||
|
|||
3) Creating a `Pubkey` from a `&str`: | |||
```rust | |||
let address = String::from("7qtAvP4CJuSKauWHtHZJt9wmQRgvcFeUcU3xKrFzxKf1"); | |||
let owner = pinocchio_pubkey::from_str(&address); | |||
const OWNER: pinocchio::pubkey::Pubkey = pinocchio_pubkey::from_str("7qtAvP4CJuSKauWHtHZJt9wmQRgvcFeUcU3xKrFzxKf1"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure what is the benefit of changing this example.
sdk/pubkey/src/lib.rs
Outdated
/// This macro also defines a helper function to check whether a given pubkey is | ||
/// equal to the program ID. | ||
/// This macro also defines helper functions to check whether a given pubkey is | ||
/// equal to the program ID, providing a complete program identity management solution. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The part of "providing a complete program identity management solution." is strange, does not read right.
/// ```rust | ||
/// use pinocchio_pubkey::declare_id; | ||
/// | ||
/// declare_id!("11111111111111111111111111111111"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This example needs to be more complete, e.g., show how the helper functions can be used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added more uses of helper function.
sdk/pubkey/src/lib.rs
Outdated
@@ -35,8 +59,51 @@ macro_rules! declare_id { | |||
}; | |||
} | |||
|
|||
/// Create a `Pubkey` from a `&str`. | |||
/// Create a `Pubkey` from a `&str` at compile time. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment about the "compile time".
fn test_const_pubkey_creation() { | ||
const SYSTEM_PROGRAM: Pubkey = from_str("11111111111111111111111111111111"); | ||
// This test just ensures compilation works | ||
assert_eq!(SYSTEM_PROGRAM.len(), 32); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs more asserts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added more asserts with different cases
It could eventually be helpful, but needs some fixes. Left some comments. |
#[inline(always)] | ||
pub const fn from_str(value: &str) -> pinocchio::pubkey::Pubkey { | ||
decode_32_const(value) | ||
} | ||
|
||
/// Type alias for the Pubkey type for convenience. | ||
pub type Pubkey = pinocchio::pubkey::Pubkey; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is strange and unnecessary. You can just import the Pubkey
type if you need it. Most likely you want to import the type for your tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a small nit. Could you please also rebase the PR since there are changes on main on the same package?
Added Docs and testcases for pubkey crate.