-
Notifications
You must be signed in to change notification settings - Fork 9
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
F/auction #49
Conversation
Caution Review failedThe pull request is closed. WalkthroughThe pull request introduces several updates to the Changes
Possibly related PRs
Suggested reviewers
Poem
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
@@ -36,7 +36,7 @@ func InitTestEnv() uint64 { | |||
defer mu.Unlock() | |||
|
|||
// temp: suppress noise from stdout | |||
os.Stdout = nil | |||
// os.Stdout = nil |
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.
Why not remove ?
packages/test-tube/src/bindings.rs
Outdated
extern "C" { | ||
pub fn Execute(envId: GoUint64, base64ReqDeliverTx: GoString) -> *mut ::std::os::raw::c_char; | ||
} | ||
// extern "C" { |
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.
Remove coment
@@ -102,8 +102,8 @@ where | |||
.into_iter() | |||
.map(|a| -> Result<Attribute, Utf8Error> { | |||
Ok(Attribute { | |||
key: a.key.to_string(), | |||
value: a.value.to_string(), | |||
key: std::str::from_utf8(a.key_bytes())?.to_string(), |
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.
why not import fuction ?
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.
Small coments but otherwise LG
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.
Actionable comments posted: 4
🧹 Outside diff range and nitpick comments (4)
packages/injective-test-tube/Cargo.toml (1)
7-7
: Version update looks good, don't forget to update the changelog.The version change to "1.13.2-auction" is appropriate for a pre-release version focusing on auction features. This is consistent with the PR title "F/auction".
Ensure that the CHANGELOG.md file is updated to reflect this new version and the changes introduced in this PR.
packages/test-tube/src/runner/result.rs (2)
55-56
: Approve changes with a suggestion for optimizationThe changes improve the robustness of the code by explicitly handling UTF-8 conversion for attribute keys and values. This is a good practice when dealing with data that might not be valid UTF-8.
However, consider caching the converted strings to avoid repeated conversions in case the
Attribute
struct is used multiple times. This could potentially improve performance, especially for large numbers of attributes.Consider caching the converted strings:
let key = std::str::from_utf8(a.key_bytes())?.to_string(); let value = std::str::from_utf8(a.value_bytes())?.to_string(); Ok(Attribute { key, value })This way, the conversion is done only once per attribute.
105-106
: Approve changes with a suggestion for code reuseThe changes here are consistent with the previous implementation, which is good for maintaining uniform behavior across different
TryFrom
implementations.However, the repetition of this code in multiple places increases the maintenance burden and the risk of inconsistencies in future updates. Consider extracting this logic into a separate function to promote code reuse.
Consider extracting the attribute conversion logic into a separate function:
fn convert_attribute(a: &AttributeProto) -> Result<Attribute, Utf8Error> { Ok(Attribute { key: std::str::from_utf8(a.key_bytes())?.to_string(), value: std::str::from_utf8(a.value_bytes())?.to_string(), }) }Then use this function in both
TryFrom
implementations:e.attributes .into_iter() .map(convert_attribute) .collect::<Result<Vec<Attribute>, Utf8Error>>()?This approach will make the code more maintainable and reduce the risk of inconsistencies.
packages/test-tube/src/runner/app.rs (1)
Hardcoded
denom
Usage Detected inget_first_validator_signing_account
The following calls to
get_first_validator_signing_account
are using the hardcoded"inj"
denomination. Please update these to pass dynamicdenom
values to ensure flexibility and prevent potential transaction fee issues:
packages/injective-test-tube/src/module/oracle.rs
🔗 Analysis chain
Line range hint
106-111
: Verify the correct usage ofdenom
inget_first_validator_signing_account
The function
get_first_validator_signing_account
now uses thedenom
parameter instead of the hardcoded"inj"
denomination in the fee setting. Please ensure that all calls to this function pass the appropriate denomination to prevent any issues with transaction fees.To verify the function usage across the codebase, you can run the following script:
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Find all calls to `get_first_validator_signing_account` and check the `denom` parameter. # Search for function calls and display the relevant lines rg --type rust 'get_first_validator_signing_account\(' -A 2Length of output: 1217
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (11)
- packages/injective-test-tube/CHANGELOG.md (1 hunks)
- packages/injective-test-tube/Cargo.toml (1 hunks)
- packages/injective-test-tube/libinjectivetesttube/main.go (1 hunks)
- packages/injective-test-tube/libinjectivetesttube/testenv/setup.go (0 hunks)
- packages/injective-test-tube/src/module/auction.rs (1 hunks)
- packages/injective-test-tube/src/module/mod.rs (2 hunks)
- packages/injective-test-tube/src/module/oracle.rs (0 hunks)
- packages/test-tube/Cargo.toml (1 hunks)
- packages/test-tube/src/bindings.rs (1 hunks)
- packages/test-tube/src/runner/app.rs (7 hunks)
- packages/test-tube/src/runner/result.rs (2 hunks)
💤 Files with no reviewable changes (2)
- packages/injective-test-tube/libinjectivetesttube/testenv/setup.go
- packages/injective-test-tube/src/module/oracle.rs
🧰 Additional context used
🔇 Additional comments (14)
packages/injective-test-tube/src/module/mod.rs (3)
1-1
: LGTM: New module declaration is consistent with existing structure.The new 'auction' module declaration is correctly placed and maintains the alphabetical order of module declarations.
Line range hint
1-28
: LGTM: File structure and consistency maintained.The additions to this file (new module declaration and public export) maintain the existing structure and organization. The alphabetical order and grouping of declarations and exports remain consistent.
16-16
: LGTM: New public export is consistent with existing structure.The new 'Auction' export is correctly placed and follows the established pattern.
To ensure the correctness of this export, please verify that the
Auction
type is properly defined in theauction
module. Run the following script to check its definition:packages/test-tube/Cargo.toml (4)
12-12
: LGTM: Consistent formatting for base64 dependency.The
base64
dependency version remains unchanged at "0.21.5". The formatting adjustment improves consistency in theCargo.toml
file.
14-14
: LGTM: Consistent formatting for unchanged dependencies.The versions of
cosmwasm-std
,serde
,serde_json
, andthiserror
dependencies remain unchanged. The formatting adjustments improve consistency in theCargo.toml
file.Also applies to: 16-18
13-13
: Verify the cosmrs version downgrade and its implications.The
cosmrs
dependency version has been changed to "0.20.0". However, this appears to be a downgrade from the previous version "0.15.0" mentioned in the AI summary. This is unusual as typically version numbers increase.Please confirm if this version change is intentional and explain the rationale behind it. Consider running the following script to check for any breaking changes or compatibility issues:
✅ Verification successful
Confirm the cosmrs version upgrade and its impact.
The
cosmrs
dependency version has been changed from "0.15.0" to "0.20.0", which is an upgrade rather than a downgrade as initially mentioned. No breaking changes or compatibility issues were found in the documentation.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Check for breaking changes in cosmrs between versions 0.15.0 and 0.20.0 # Test: Search for any mentions of breaking changes or compatibility issues rg --type md -i '(breaking change|compatibility|upgrade|downgrade).*0\.(15|16|17|18|19|20)' $(fd -e md -e rst) # Test: Check if the cosmrs crate is used in the codebase rg --type rust 'use cosmrs::'Length of output: 873
Script:
#!/bin/bash # Description: Check for mentions of breaking changes or compatibility issues between cosmrs versions 0.15.0 and 0.20.0 # Search for any mentions of breaking changes or compatibility issues in markdown and reStructuredText files rg --type md -i '(breaking change|compatibility|upgrade|downgrade).*0\.(15|16|17|18|19|20)' $(fd -e md -e rst) # Check if the cosmrs crate is used in the Rust codebase without using regex look-around rg --type rust 'use\s+cosmrs::'Length of output: 1348
15-15
: Verify prost dependency changes and their implications.The
prost
dependency has been updated to version "0.13.3" with default features disabled and only the "prost-derive" feature explicitly included. This change might affect the functionality of the package.Please confirm the following:
- The rationale behind disabling default features and only including "prost-derive".
- That this change doesn't break any existing functionality.
- That there are no breaking changes in the minor version update from 0.12.4 to 0.13.3.
Consider running the following script to check for any potential issues:
packages/injective-test-tube/Cargo.toml (2)
19-19
: Dependency version update: Verify compatibility.The update of
injective-std
to version "=1.13.2-auction" aligns with the package version update. The use of an exact version match ensures consistency across the project.Please ensure that this version of
injective-std
is compatible with all other dependencies and that it includes all necessary features for the auction functionality. You may want to run your test suite to verify everything works as expected with this new version.To verify the usage and impact of this dependency update, you can run the following script:
#!/bin/bash # Description: Check for usage of injective-std in the codebase and potential incompatibilities # Test: Search for imports or uses of injective-std rg --type rust 'use injective_std::|use injective_std |from injective_std' # Test: Check for any compiler warnings or errors related to injective-std cargo check 2>&1 | rg 'injective-std'
15-15
: New dependency added: Please provide usage details.The addition of the
cosmwasm-schema
dependency is noted. This suggests that the project now requires schema-related functionality from the CosmWasm ecosystem.Could you please provide more information on how this new dependency will be used in the project? This will help ensure that it's necessary and being used correctly.
To verify the usage of this new dependency, you can run the following script:
packages/test-tube/src/bindings.rs (1)
223-225
:⚠️ Potential issueVerify the impact of removing the
Execute
functionThe
Execute
function has been commented out, effectively removing it from the Rust bindings. While this change is consistent with the AI-generated summary, it's important to verify its impact:
- Please confirm that this change is intentional and aligns with the PR objectives.
- Ensure that no other parts of the codebase are relying on this function. If they are, they will need to be updated accordingly.
- Consider adding a comment explaining why this function was removed to improve code maintainability.
To help verify the impact of this change, you can run the following script:
This will help identify any potential places where the
Execute
function was being used and might need to be updated.✅ Verification successful
Removal of the
Execute
function has been verifiedThe
Execute
function was commented out inpackages/test-tube/src/bindings.rs
, and a comprehensive search confirmed that it is not used elsewhere in the codebase. Therefore, removing this function does not impact any existing functionality.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Search for any usage of the Execute function in Rust files rg --type rust "Execute\s*\(" ./srcLength of output: 83
Script:
#!/bin/bash # Search for any usage of the Execute function in all Rust files within the repository rg --type rust "Execute\s*\(" .Length of output: 171
packages/injective-test-tube/libinjectivetesttube/main.go (1)
39-39
: Clarify the purpose and impact of commenting out stdout suppression.The commented-out line
// os.Stdout = nil
suggests a change in how stdout is handled during test environment initialization. While this may help with debugging by allowing more verbose output, it could potentially impact tests that rely on controlled stdout behavior.Consider the following:
- Clarify the relationship between this change and the "Temp fix for concurrency issue" mentioned in the comment above the function.
- Document the specific reason for this change. Is it for debugging purposes, or does it address a particular problem?
- If this is indeed temporary, add a TODO comment with a ticket number or description of when and how this should be reverted.
- Evaluate and document any potential impacts on existing tests that might rely on suppressed stdout.
To help assess the impact of this change, you can run the following command to search for tests that might be affected:
This will help identify any tests that might need adjustment due to this change.
✅ Verification successful
Stdout suppression change does not impact existing tests.
The search confirmed that no tests capture or assert on
os.Stdout
. Commenting out// os.Stdout = nil
does not affect any current tests.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Search for tests that capture or assert on stdout content rg --type go '(os\.Stdout|t\.CaptureOutput|bytes\.Buffer.*os\.Stdout)' test/Length of output: 124
Script:
#!/bin/bash # Recursively search for tests that capture or assert on stdout across the entire codebase rg --type go '(os\.Stdout|t\.CaptureOutput|bytes\.Buffer.*os\.Stdout)' --ignore-dir=node_modules --ignore-dir=dist --ignore-dir=buildLength of output: 578
Script:
#!/bin/bash # Recursively search for tests that capture or assert on stdout across the entire codebase, excluding specific directories rg --type go '(os\.Stdout|t\.CaptureOutput|bytes\.Buffer.*os\.Stdout)' --glob '!node_modules/**' --glob '!dist/**' --glob '!build/**'Length of output: 213
packages/test-tube/src/runner/result.rs (1)
Line range hint
1-280
: Summary of changes and recommendationsThe changes in this file improve the robustness of attribute handling by explicitly managing UTF-8 conversion. This is a positive change that aligns with best practices for handling potentially non-UTF-8 data.
Key points and recommendations:
- The changes are consistent across different
TryFrom
implementations, which is good for maintaining uniform behavior.- Consider optimizing performance by caching the converted strings, especially if attributes are used multiple times.
- To reduce code duplication and improve maintainability, extract the attribute conversion logic into a separate function that can be reused across different implementations.
- No changes were made to public interfaces or exported entities, which helps maintain backwards compatibility.
Overall, these changes represent an improvement in code quality and robustness. Implementing the suggested optimizations and refactoring would further enhance the code's efficiency and maintainability.
packages/injective-test-tube/src/module/auction.rs (1)
11-40
: LGTM: Correct implementation of theAuction
moduleThe
Auction
module is well-implemented with the correct use of lifetimes and generics. Thefn_query!
macro is properly utilized to define the query methods, and the code is clean and adheres to Rust's best practices.packages/test-tube/src/runner/app.rs (1)
315-323
: Good use ofDrop
trait for resource cleanupImplementing the
Drop
trait forBaseApp
ensures that resources are properly released when the instance goes out of scope, preventing potential memory leaks or dangling resources.
## 1.13.2-auction - 2024-08-10 | ||
|
||
### Changed | ||
|
||
- Updated to use `[email protected]` which is a manual fix for the Auction protos |
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.
Date inconsistency and version clarification needed
The new changelog entry follows the established format and provides clear information about the changes. However, there are two points that need attention:
-
The date (2024-08-10) is earlier than the date of the previous entry (1.13.2 - 2024-28-08). This creates a chronological inconsistency in the changelog.
-
The version number (1.13.2-auction) suggests this is a special version based on 1.13.2. It would be helpful to add a brief explanation of why this special version was created and how it relates to the main version line.
Consider the following actions:
- Adjust the date to maintain chronological order, or if the date is correct, consider moving this entry after the 1.13.2 entry.
- Add a brief note explaining the purpose of this special "auction" version and how it fits into the version history.
Example:
## 1.13.2-auction - 2024-08-10
### Changed
- Updated to use `[email protected]` which is a manual fix for the Auction protos
- Note: This is a special version created to address specific Auction proto issues. It is based on version 1.13.2 but is not part of the main release line.
#[test] | ||
fn auction_integration() { | ||
let app = InjectiveTestApp::new(); | ||
|
||
let auction = Auction::new(&app); | ||
|
||
let response = auction | ||
.query_auction_params(&QueryAuctionParamsRequest {}) | ||
.unwrap(); | ||
assert_eq!( | ||
response.params, | ||
Some(Params { | ||
auction_period: 604800, | ||
min_next_bid_increment_rate: 2_500_000_000_000_000u128.to_string() | ||
}) | ||
); | ||
|
||
let response = auction | ||
.query_last_auction_result(&QueryLastAuctionResultRequest {}) | ||
.unwrap(); | ||
assert!(response.last_auction_result.is_some()); | ||
|
||
let result = response.last_auction_result.unwrap(); | ||
assert_eq!( | ||
result, | ||
LastAuctionResult { | ||
amount: Some(BaseCoin { | ||
denom: "inj".to_string(), | ||
amount: "0".to_string() | ||
}), | ||
winner: "".to_string(), | ||
round: 0u64, | ||
} | ||
); | ||
} |
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.
🛠️ Refactor suggestion
Add tests for all query methods in the Auction
module
Currently, the test module includes tests for query_auction_params
and query_last_auction_result
functions. To ensure comprehensive test coverage and verify the functionality of all query methods, consider adding tests for the query_current_auction_basket
and query_module_state
functions.
Would you like assistance in writing these additional tests or opening a GitHub issue to track this task?
/// Get the current block time | ||
pub fn get_block_timestamp(&self) -> Timestamp { | ||
let result = unsafe { GetBlockTime(self.id) }; | ||
|
||
Timestamp::from_nanos(result as u64) | ||
} |
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.
Handle potential negative values in get_block_timestamp
The GetBlockTime(self.id)
function returns an i64
, which may be negative. Casting a negative i64
to u64
can lead to incorrect timestamp values due to integer underflow. Consider checking for negative values before casting to u64
to ensure correctness.
Apply the following diff to handle potential negative block times:
pub fn get_block_timestamp(&self) -> Timestamp {
let result = unsafe { GetBlockTime(self.id) };
+ if result < 0 {
+ // Handle negative block time appropriately
+ // For example, return an error or a default Timestamp
+ panic!("Block time is negative");
+ }
Timestamp::from_nanos(result as u64)
}
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
/// Get the current block time | |
pub fn get_block_timestamp(&self) -> Timestamp { | |
let result = unsafe { GetBlockTime(self.id) }; | |
Timestamp::from_nanos(result as u64) | |
} | |
/// Get the current block time | |
pub fn get_block_timestamp(&self) -> Timestamp { | |
let result = unsafe { GetBlockTime(self.id) }; | |
if result < 0 { | |
// Handle negative block time appropriately | |
// For example, return an error or a default Timestamp | |
panic!("Block time is negative"); | |
} | |
Timestamp::from_nanos(result as u64) | |
} |
pub fn default_simulation_fee(&self) -> Fee { | ||
Fee::from_amount_and_gas( | ||
cosmrs::Coin { | ||
denom: self.fee_denom.parse().unwrap(), | ||
amount: INJECTIVE_MIN_GAS_PRICE, | ||
}, | ||
0u64, | ||
) | ||
} |
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.
Handle potential parsing errors when parsing fee_denom
In the default_simulation_fee
method, using self.fee_denom.parse().unwrap()
can cause a panic if fee_denom
cannot be parsed into the expected type. To enhance robustness, consider handling the parsing error gracefully.
Apply this diff to handle the parsing error:
pub fn default_simulation_fee(&self) -> Fee {
Fee::from_amount_and_gas(
cosmrs::Coin {
- denom: self.fee_denom.parse().unwrap(),
+ denom: match self.fee_denom.parse() {
+ Ok(denom) => denom,
+ Err(e) => {
+ // Handle the error, possibly by returning a Result or a default value
+ panic!("Invalid fee_denom '{}': {}", self.fee_denom, e);
+ }
+ },
amount: INJECTIVE_MIN_GAS_PRICE,
},
0u64,
)
}
Committable suggestion was skipped due to low confidence.
see changelog
Summary by CodeRabbit
New Features
BaseApp
with new methods for retrieving blockchain-related information.Bug Fixes
Chores