-
Notifications
You must be signed in to change notification settings - Fork 26
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
feat: TimeGate ADO #529
base: main
Are you sure you want to change the base?
feat: TimeGate ADO #529
Conversation
WalkthroughThe Andromeda Time Gate module has been enhanced with a new smart contract for managing time gate functionalities, a structured API for instantiation and querying, and improved testing utilities. These updates facilitate efficient interactions within the Andromeda ecosystem and provide a robust framework for time-based operations. Changes
Possibly related PRs
Suggested labels
Suggested reviewers
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 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 (
|
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: 2
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files ignored due to path filters (1)
Cargo.lock
is excluded by!**/*.lock
Files selected for processing (12)
- contracts/modules/andromeda-time-gate/.cargo/config (1 hunks)
- contracts/modules/andromeda-time-gate/Cargo.toml (1 hunks)
- contracts/modules/andromeda-time-gate/examples/schema.rs (1 hunks)
- contracts/modules/andromeda-time-gate/src/contract.rs (1 hunks)
- contracts/modules/andromeda-time-gate/src/lib.rs (1 hunks)
- contracts/modules/andromeda-time-gate/src/mock.rs (1 hunks)
- contracts/modules/andromeda-time-gate/src/state.rs (1 hunks)
- contracts/modules/andromeda-time-gate/src/testing/mock.rs (1 hunks)
- contracts/modules/andromeda-time-gate/src/testing/mod.rs (1 hunks)
- contracts/modules/andromeda-time-gate/src/testing/tests.rs (1 hunks)
- packages/andromeda-modules/src/lib.rs (1 hunks)
- packages/andromeda-modules/src/time_gate.rs (1 hunks)
Files skipped from review due to trivial changes (3)
- contracts/modules/andromeda-time-gate/.cargo/config
- contracts/modules/andromeda-time-gate/examples/schema.rs
- contracts/modules/andromeda-time-gate/src/testing/mod.rs
Additional comments not posted (50)
packages/andromeda-modules/src/lib.rs (1)
4-4
: Module declaration looks good.The new module
time_gate
is correctly declared and aligns with the existing structure.contracts/modules/andromeda-time-gate/src/lib.rs (4)
1-1
: Module declaration looks good.The module
contract
is correctly declared and aligns with the overall structure.
2-2
: Module declaration looks good.The module
state
is correctly declared and aligns with the overall structure.
3-4
: Module declaration looks good.The module
testing
is correctly declared and conditionally compiled for tests.
6-7
: Module declaration looks good.The module
mock
is correctly declared and conditionally compiled for non-WASM32 architectures with thetesting
feature.contracts/modules/andromeda-time-gate/src/state.rs (3)
1-2
: Imports look good.The imports are correct and necessary for the functionality.
4-4
: Constant declaration looks good.The constant
GATE_ADDRESSES
is correctly declared as anItem
with the key "gate_addresses".
5-5
: Constant declaration looks good.The constant
GATE_TIME
is correctly declared as anItem
with the key "gate_time".contracts/modules/andromeda-time-gate/Cargo.toml (6)
1-6
: Package metadata looks good.The package metadata is correctly defined.
7-9
: Crate type definition looks good.The crate type is correctly defined as both
cdylib
andrlib
.
10-16
: Feature flags look good.The feature flags are correctly defined and useful for debugging and testing.
18-27
: Dependencies look good.The dependencies are correctly defined and appropriate for the project.
28-31
: Target-specific dependencies look good.The target-specific dependencies are correctly defined and appropriate for non-WASM targets.
32-33
: Dev-dependencies look good.The dev-dependencies are correctly defined and appropriate for development purposes.
contracts/modules/andromeda-time-gate/src/testing/mock.rs (8)
1-4
: Imports look good.The imports are correctly defined and appropriate for the mock implementations.
5-13
: Additional imports look good.The additional imports are correctly defined and appropriate for the mock implementations.
15-35
:proper_initialization
function looks good.The function correctly initializes the mock dependencies and instantiates the contract.
37-45
:set_gate_time
function looks good.The function correctly sets the gate time using the
ExecuteMsg::SetGateTime
message.
47-55
:update_gate_addresses
function looks good.The function correctly updates the gate addresses using the
ExecuteMsg::UpdateGateAddresses
message.
57-63
:query_gate_time
function looks good.The function correctly queries the gate time using the
QueryMsg::GetGateTime
message.
65-71
:query_gate_addresses
function looks good.The function correctly queries the gate addresses using the
QueryMsg::GetGateAddresses
message.
73-79
:query_path
function looks good.The function correctly queries the path using the
QueryMsg::GetPathByCurrentTime
message.packages/andromeda-modules/src/time_gate.rs (5)
1-4
: Imports look good.The imports are correctly defined and appropriate for the "TimeGate ADO" feature.
5-10
:InstantiateMsg
struct looks good.The struct correctly includes the necessary fields for instantiation.
12-21
:ExecuteMsg
enum looks good.The enum correctly includes the necessary executable messages.
23-33
:QueryMsg
enum looks good.The enum correctly includes the necessary query messages.
35-49
:GateTime
andGateAddresses
structs look good.The structs correctly include the necessary fields for date, time, and addresses.
contracts/modules/andromeda-time-gate/src/mock.rs (7)
1-11
: LGTM! Imports and module attributes are appropriate.The imports and module attributes are necessary for the mock implementation and are correctly used.
13-14
: LGTM! Struct definition and macro usage are appropriate.The struct
MockTimeGate
and themock_ado
macro are correctly used for the mock implementation.
16-38
: LGTM! Instantiation method is correct.The
instantiate
method correctly creates and instantiates theMockTimeGate
contract.
40-53
: LGTM! Execution method for setting gate time is correct.The
execute_set_gate_time
method correctly handles the execution of theSetGateTime
contract function.
55-68
: LGTM! Execution method for updating gate addresses is correct.The
execute_update_gate_addresses
method correctly handles the execution of theUpdateGateAddresses
contract function.
70-86
: LGTM! Query methods are correct.The
query_gate_time
,query_gate_addresses
, andquery_path
methods correctly handle querying the contract states.
89-106
: LGTM! Helper functions are correct.The helper functions
mock_andromeda_time_gate
andmock_time_gate_instantiate_msg
are correctly implemented and necessary for the mock implementation.contracts/modules/andromeda-time-gate/src/testing/tests.rs (5)
1-8
: LGTM! Imports are appropriate.The imports are necessary for the unit tests and are correctly used.
10-45
: LGTM! Instantiation test is correct.The
test_instantiation
function correctly verifies the instantiation of the TimeGate ADO and the initial state.
47-104
: LGTM! Set gate time test is correct.The
test_set_gate_time
function correctly verifies the execution of theSetGateTime
function and the updated state.
106-148
: LGTM! Update gate addresses test is correct.The
test_update_gate_addresses
function correctly verifies the execution of theUpdateGateAddresses
function and the updated state.
150-169
: LGTM! Query path test is correct.The
test_query_path
function correctly verifies the execution of theGetPathByCurrentTime
query and the expected result.contracts/modules/andromeda-time-gate/src/contract.rs (11)
1-18
: LGTM! Imports and module attributes are appropriate.The imports and module attributes are necessary for the contract implementation and are correctly used.
20-22
: LGTM! Constant definitions are appropriate.The constants for the contract name and version are necessary for versioning and are correctly defined.
24-52
: LGTM! Instantiation function is correct.The
instantiate
function correctly initializes the contract state and ensures the gate time is valid.
54-68
: LGTM! Execution function is correct.The
execute
function correctly routes the execution to the appropriate handler.
70-92
: LGTM! Handle execute function is correct.The
handle_execute
function correctly handles the execution of the provided message.
94-122
: LGTM! Set gate time execution function is correct.The
execute_set_gate_time
function correctly handles the execution of theSetGateTime
contract function.
124-150
: LGTM! Update gate addresses execution function is correct.The
execute_update_gate_addressess
function correctly handles the execution of theUpdateGateAddresses
contract function.
152-160
: LGTM! Query function is correct.The
query
function correctly routes the query to the appropriate handler.
162-165
: LGTM! Get gate addresses query function is correct.The
get_gate_addresses
function correctly handles querying the gate addresses.
167-170
: LGTM! Get gate time query function is correct.The
get_gate_time
function correctly handles querying the gate time.
199-202
: LGTM! Migration function is correct.The
migrate
function correctly handles the migration of the contract state.
Please address Code Rabbit's comments and replace |
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: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (2)
- contracts/modules/andromeda-time-gate/src/contract.rs (1 hunks)
- packages/andromeda-modules/src/time_gate.rs (1 hunks)
Files skipped from review as they are similar to previous changes (2)
- contracts/modules/andromeda-time-gate/src/contract.rs
- packages/andromeda-modules/src/time_gate.rs
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: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files ignored due to path filters (1)
Cargo.lock
is excluded by!**/*.lock
Files selected for processing (9)
- CHANGELOG.md (1 hunks)
- DEADJOE (1 hunks)
- contracts/modules/andromeda-time-gate/src/contract.rs (1 hunks)
- contracts/modules/andromeda-time-gate/src/mock.rs (1 hunks)
- contracts/modules/andromeda-time-gate/src/state.rs (1 hunks)
- contracts/modules/andromeda-time-gate/src/testing/mock.rs (1 hunks)
- contracts/modules/andromeda-time-gate/src/testing/mod.rs (1 hunks)
- contracts/modules/andromeda-time-gate/src/testing/tests.rs (1 hunks)
- packages/andromeda-modules/src/time_gate.rs (1 hunks)
Files skipped from review due to trivial changes (2)
- DEADJOE
- contracts/modules/andromeda-time-gate/src/testing/mod.rs
Files skipped from review as they are similar to previous changes (6)
- contracts/modules/andromeda-time-gate/src/contract.rs
- contracts/modules/andromeda-time-gate/src/mock.rs
- contracts/modules/andromeda-time-gate/src/state.rs
- contracts/modules/andromeda-time-gate/src/testing/mock.rs
- contracts/modules/andromeda-time-gate/src/testing/tests.rs
- packages/andromeda-modules/src/time_gate.rs
Additional comments not posted (1)
CHANGELOG.md (1)
19-19
: Entry for "Time Gate ADO" looks good.The entry is correctly formatted and consistent with the rest of the file.
Is there a way we can make this cycle through a vector of addresses? Say every hour it moves to the next address in the vector, when it reaches the end of the vector it cycles back to the start. |
It can be implemented. |
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: 15
Outside diff range, codebase verification and nitpick comments (3)
contracts/modules/andromeda-time-gate/src/mock.rs (2)
14-15
: Consider adding documentation comments.Adding documentation comments to
MockTimeGate
and its methods would improve code readability and maintainability by explaining their purpose and usage./// MockTimeGate is a mock implementation for testing the TimeGate contract. pub struct MockTimeGate(Addr);
120-123
: Add documentation formock_andromeda_time_gate
.Adding a comment to describe the purpose of
mock_andromeda_time_gate
would improve code readability./// Creates a mock contract for the Andromeda Time Gate. pub fn mock_andromeda_time_gate() -> Box<dyn Contract<Empty>> {contracts/modules/andromeda-time-gate/src/contract.rs (1)
105-131
: Add logging for update operations.Consider adding logging for operations like
execute_update_cycle_start_time
to facilitate debugging and tracking contract state changes.log::info!("Updating cycle start time to {:?}", cycle_start_time);
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files ignored due to path filters (1)
Cargo.lock
is excluded by!**/*.lock
Files selected for processing (6)
- contracts/modules/andromeda-time-gate/src/contract.rs (1 hunks)
- contracts/modules/andromeda-time-gate/src/mock.rs (1 hunks)
- contracts/modules/andromeda-time-gate/src/state.rs (1 hunks)
- contracts/modules/andromeda-time-gate/src/testing/mock.rs (1 hunks)
- contracts/modules/andromeda-time-gate/src/testing/tests.rs (1 hunks)
- packages/andromeda-modules/src/time_gate.rs (1 hunks)
Additional comments not posted (5)
contracts/modules/andromeda-time-gate/src/state.rs (1)
5-7
: Verify the integration of storage items.Ensure that
GATE_ADDRESSES
,CYCLE_START_TIME
, andTIME_INTERVAL
are correctly used within the contract logic to store and retrieve data as intended.Verification successful
Storage Items Properly Integrated in Contract Logic
The storage items
GATE_ADDRESSES
,CYCLE_START_TIME
, andTIME_INTERVAL
are correctly used within the contract logic. They are imported intocontract.rs
and utilized for saving and retrieving data, indicating proper integration into the contract's functionality.
- File:
contracts/modules/andromeda-time-gate/src/contract.rs
- Usage: Methods like
save
andload
are used with these items, confirming their role in managing contract state.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the usage of storage items in the codebase. # Test: Search for the usage of each storage item. Expect: Proper integration within contract logic. rg --type rust 'GATE_ADDRESSES|CYCLE_START_TIME|TIME_INTERVAL'Length of output: 2518
packages/andromeda-modules/src/time_gate.rs (1)
95-95
: Fix the error message for second validation.The error message for the second validation should indicate "Second must be less than 60".
- ContractError::InvalidParameter { error: Some("Wrong minute range".to_string())} + ContractError::InvalidParameter { error: Some("Second must be less than 60".to_string())}contracts/modules/andromeda-time-gate/src/testing/mock.rs (1)
1-100
: Verify test coverage for mock functions.Ensure that the mock functions provided in this file are adequately covered by unit tests to validate their behavior.
Verification successful
Adequate Test Coverage for Mock Functions Verified
The mock functions in
contracts/modules/andromeda-time-gate/src/testing/mock.rs
are adequately covered by unit tests. The test filecontracts/modules/andromeda-time-gate/src/testing/tests.rs
contains multiple test functions and assertions that validate the behavior of these mock functions.
- Test functions found:
test_instantiation
,test_update_cycle_start_time
,test_update_gate_addresses
,test_query_current_ado_path_not_started_yet
,test_query_current_ado_path
.- Assertions are present to ensure expected outcomes.
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify test coverage for mock functions. # Test: Search for test functions that utilize the mock functions. Expect: Adequate test coverage. rg --type rust 'proper_initialization|update_cycle_start_time|update_gate_addresses|update_time_interval|query_cycle_start_time|query_gate_addresses|query_time_interval|query_current_ado_path'Length of output: 7470
Script:
#!/bin/bash # Description: Check for test functions and assertions involving mock functions. # Search for test functions in the relevant test file rg --type rust 'fn test_' contracts/modules/andromeda-time-gate/src/testing/tests.rs # Search for assertions involving mock functions in the test file rg --type rust 'assert' contracts/modules/andromeda-time-gate/src/testing/tests.rsLength of output: 692
contracts/modules/andromeda-time-gate/src/testing/tests.rs (1)
56-122
: Ensure comprehensive error checking.The
test_update_cycle_start_time
function checks for invalid parameters. Ensure that all possible error scenarios are covered, such as unauthorized access or invalid date formats.// Verify unauthorized access let unauthorized_info = mock_info("unauthorized_user", &[]); let err = update_cycle_start_time( deps.as_mut(), CycleStartTime { year: 2023, month: 1, day: 1, hour: 0, minute: 0, second: 0, }, unauthorized_info.sender.as_ref(), ) .unwrap_err(); assert_eq!(err, ContractError::Unauthorized {});contracts/modules/andromeda-time-gate/src/contract.rs (1)
211-257
: Ensure correct time calculations inget_current_ado_path
.The function
get_current_ado_path
performs time calculations. Ensure that all edge cases, such as leap seconds or daylight saving time changes, are correctly handled.// Verify calculations with edge cases
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: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (2)
- contracts/modules/andromeda-time-gate/src/contract.rs (1 hunks)
- contracts/modules/andromeda-time-gate/src/testing/tests.rs (1 hunks)
Files skipped from review as they are similar to previous changes (2)
- contracts/modules/andromeda-time-gate/src/contract.rs
- contracts/modules/andromeda-time-gate/src/testing/tests.rs
Version 2.0.0This version of Time Gate ADO returns the moved ado path of the vector each time. When it reaches the end of the vector, it loops back to the starting point. |
@coderabbitai review |
Actions performedReview triggered.
|
} | ||
|
||
#[cw_serde] | ||
pub struct CycleStartTime { |
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.
What's the reasoning for not using Timestamp
or Expiry
here?
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.
Of course, we can use Timestamp
or Expiry
.
By the way, I thought that it is a good way to use more visual methods via year, month, day... than only milliseconds.
If you want Timestamp
or Expiry
for this, I will do so.
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.
For consistency let's use our Expiry
type.
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.
resolved it.
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: 1
Outside diff range, codebase verification and nitpick comments (3)
contracts/modules/andromeda-time-gate/src/testing/tests.rs (1)
150-214
: LGTM with a suggestion!The test functions
test_query_current_ado_path_not_started_yet
andtest_query_current_ado_path
cover the scenarios for querying the current ADO path. Thetest_query_current_ado_path
function tests the scenario just after the cycle starts, which is great.Consider adding an additional test case for the scenario just before the cycle starts to ensure the correct behavior:
#[test] fn test_query_current_ado_path_just_before_start() { // ... (setup code) env.block.time = env.block.time.plus_seconds(5000099); let res = query_current_ado_path(deps.as_ref(), env.clone()).unwrap_err(); assert_eq!( res, ContractError::CustomError { msg: "Cycle is not started yet".to_string() } ); }contracts/modules/andromeda-time-gate/src/contract.rs (2)
30-68
: Refactor to simplify theinstantiate
function.Consider the following improvements:
- Remove the unused
cycle_start_time_millisecons
variable.- Combine the
cycle_start_time
andcycle_start_time_millisecons
variables into a single struct to simplify the code.Apply this diff to implement the suggested changes:
let (cycle_start_time, _) = get_and_validate_start_time(&env, msg.cycle_start_time)?; -let cycle_start_time_millisecons = match msg.cycle_start_time.clone() { - None => Milliseconds::from_nanos(env.block.time.nanos()), - Some(start_time) => start_time.get_time(&env.block), -}; - let time_interval_seconds = msg.time_interval.unwrap_or(DEFAULT_TIME_INTERVAL); GATE_ADDRESSES.save(deps.storage, &msg.gate_addresses)?; -CYCLE_START_TIME.save( - deps.storage, - &(cycle_start_time, cycle_start_time_millisecons), -)?; +CYCLE_START_TIME.save(deps.storage, &cycle_start_time)?; TIME_INTERVAL.save(deps.storage, &time_interval_seconds)?;
232-260
: Refactor to simplify theget_current_ado_path
function.Consider the following improvements:
- Remove the unused
cycle_start_time_milliseconds
variable.- Replace the
checked_mul
,checked_sub
,checked_div
, andchecked_rem
functions with the standard arithmetic operators for better readability.Apply this diff to implement the suggested changes:
pub fn get_current_ado_path(deps: Deps, env: Env) -> Result<Addr, ContractError> { let storage = deps.storage; - let (cycle_start_time, cycle_start_time_milliseconds) = CYCLE_START_TIME.load(storage)?; + let cycle_start_time = CYCLE_START_TIME.load(storage)?; let gate_addresses = GATE_ADDRESSES.load(storage)?; let time_interval = TIME_INTERVAL.load(storage)?; ensure!( cycle_start_time.is_expired(&env.block), ContractError::CustomError { msg: "Cycle is not started yet".to_string() } ); let current_time_nanos = env.block.time.nanos(); - let cycle_start_nanos = cycle_start_time_milliseconds.nanos(); + let cycle_start_nanos = cycle_start_time.nanos(); - let time_interval_nanos = time_interval.checked_mul(1_000_000_000).unwrap(); + let time_interval_nanos = time_interval * 1_000_000_000; let gate_length = gate_addresses.len() as u64; - let time_delta = current_time_nanos.checked_sub(cycle_start_nanos).unwrap(); - let index = time_delta - .checked_div(time_interval_nanos) - .unwrap() - .checked_rem(gate_length) - .unwrap() as usize; + let time_delta = current_time_nanos - cycle_start_nanos; + let index = (time_delta / time_interval_nanos) % gate_length as usize; let current_ado_path = &gate_addresses[index]; let result = current_ado_path.get_raw_address(&deps)?; Ok(result) }
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files ignored due to path filters (1)
Cargo.lock
is excluded by!**/*.lock
Files selected for processing (7)
- CHANGELOG.md (1 hunks)
- contracts/modules/andromeda-time-gate/Cargo.toml (1 hunks)
- contracts/modules/andromeda-time-gate/src/contract.rs (1 hunks)
- contracts/modules/andromeda-time-gate/src/state.rs (1 hunks)
- contracts/modules/andromeda-time-gate/src/testing/mock.rs (1 hunks)
- contracts/modules/andromeda-time-gate/src/testing/tests.rs (1 hunks)
- packages/andromeda-modules/src/time_gate.rs (1 hunks)
Additional comments not posted (23)
contracts/modules/andromeda-time-gate/src/state.rs (3)
1-3
: LGTM!The code changes are approved.
5-5
: LGTM!The code changes are approved.
6-7
: LGTM!The code changes are approved.
contracts/modules/andromeda-time-gate/Cargo.toml (5)
1-5
: LGTM!The package section is correctly configured with appropriate package name, version, Rust edition, and minimum supported Rust version.
7-8
: LGTM!The lib section correctly sets the crate type to
["cdylib", "rlib"]
, which is appropriate for a Rust library that can be used as a native library and a WebAssembly module.
10-15
: LGTM!The features section is correctly configured with appropriate feature flags:
- "backtraces" enables more explicit tests using
cosmwasm-std/backtraces
.- "library" disables all instantiate/execute/query exports.
- "testing" enables "cw-multi-test" and "andromeda-testing" for testing purposes.
18-25
: LGTM!The dependencies section is correctly configured with appropriate workspace dependencies:
cosmwasm-std
,cosmwasm-schema
,cw-storage-plus
, andcw-utils
are standard CosmWasm dependencies.andromeda-std
andandromeda-modules
are Andromeda-specific dependencies.The empty features array for
andromeda-std
is also correct.
27-32
: LGTM!The target-specific dependencies and dev-dependencies sections are correctly configured:
- The
cw-multi-test
andandromeda-testing
dependencies are correctly marked as optional and only included for non-wasm32 targets.- The
andromeda-app
workspace dependency is correctly included in the dev-dependencies section.packages/andromeda-modules/src/time_gate.rs (3)
12-16
: LGTM!The code changes are approved.
20-24
: LGTM!The code changes are approved.
29-38
: LGTM!The code changes are approved.
CHANGELOG.md (1)
19-19
: LGTM!The changelog entry for "Time Gate ADO" is consistent with the provided summary and follows the standard format. The pull request link is helpful for reference.
contracts/modules/andromeda-time-gate/src/testing/mock.rs (5)
19-42
: LGTM!The code changes are approved.
44-58
: LGTM!The code changes are approved.
60-70
: LGTM!The code changes are approved.
72-80
: LGTM!The code changes are approved.
82-94
: Skipping the existing comment.The existing comment on line 91 is still valid and applicable.
contracts/modules/andromeda-time-gate/src/testing/tests.rs (3)
13-46
: LGTM!The test function
test_instantiation
covers the basic instantiation scenario and verifies the gate addresses, cycle start time, and time interval. The code changes are approved.
48-94
: LGTM!The test function
test_update_cycle_start_time
comprehensively covers the update scenarios for cycle start time and time interval. It also verifies the error handling for updating with the same cycle start time. The code changes are approved.
96-148
: LGTM!The test function
test_update_gate_addresses
covers the update scenarios for gate addresses and verifies the error handling for updating with the same gate addresses. The code changes are approved.contracts/modules/andromeda-time-gate/src/contract.rs (3)
70-84
: LGTM!The code changes are approved.
204-213
: LGTM!The code changes are approved.
152-176
: Fix typo in the comment.The comment mentions
execute_update_gate_addressess
but the function name isexecute_update_gate_addresses
. Remove the extra 's' at the end of the comment.
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 (7)
contracts/math/andromeda-time-gate/src/contract.rs (2)
138-142
: Correct grammatical errors in error messagesThe error messages contain grammatical errors. The phrases "Same as an existed cycle start time" and "Same as existed gate addresses" should be corrected to "Same as existing cycle start time" and "Same as existing gate addresses", respectively.
Apply the following diffs:
// In execute_update_cycle_start_time - error: Some("Same as an existed cycle start time".to_string()) + error: Some("Same as existing cycle start time".to_string()) // In execute_update_gate_addresses - error: Some("Same as existed gate addresses".to_string()) + error: Some("Same as existing gate addresses".to_string())Also applies to: 167-171
239-243
: Clarify the usage ofis_expired
when checking if the cycle has startedUsing
is_expired
to check if the cycle has started may be semantically confusing since it implies expiration rather than initiation. Consider usingis_triggered
or a custom check to improve readability and correctness.Modify the condition to better reflect the intent:
- ensure!( - cycle_start_time.is_expired(&env.block), + ensure!( + !cycle_start_time.is_pending(&env.block), ContractError::CustomError { msg: "Cycle has not started yet".to_string() } );Alternatively, if
Expiration
does not provide the needed method, consider implementing a custom time check.contracts/math/andromeda-time-gate/src/mock.rs (1)
56-60
: Reduce code duplication in execute methodsThe pattern for handling optional funds is repeated across multiple methods. Consider extracting this into a helper method.
+impl MockTimeGate { + fn execute_with_optional_funds( + &self, + app: &mut MockApp, + sender: Addr, + msg: ExecuteMsg, + funds: Option<Coin>, + ) -> ExecuteResult { + match funds { + Some(funds) => app.execute_contract(sender, self.addr().clone(), &msg, &[funds]), + None => app.execute_contract(sender, self.addr().clone(), &msg, &[]), + } + } +}Then use it in the execute methods:
- if let Some(funds) = funds { - app.execute_contract(sender, self.addr().clone(), &msg, &[funds]) - } else { - app.execute_contract(sender, self.addr().clone(), &msg, &[]) - } + self.execute_with_optional_funds(app, sender, msg, funds)Also applies to: 73-77, 88-92
contracts/math/andromeda-time-gate/src/testing/tests.rs (3)
13-46
: Consider adding edge case tests for instantiationThe current test covers the happy path well, but consider adding tests for:
- Empty gate addresses vector
- Invalid time intervals (e.g., zero or negative values)
- Maximum/minimum bounds for time values
48-148
: Enhance update tests with additional scenariosConsider adding tests for:
- Concurrent update attempts
- Permission validation (unauthorized sender)
- Edge cases for time intervals and address updates
150-214
: Add boundary condition tests for time-based queriesConsider adding tests for:
- Exact boundary transitions between addresses
- Time overflow scenarios
- Behavior at maximum time values
CHANGELOG.md (1)
58-58
: Consider expanding the changelog entry with feature detailsThe current entry could be more informative by including:
- Brief description of the Time Gate ADO's purpose
- Key features and capabilities
- Breaking changes or migration notes, if any
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
⛔ Files ignored due to path filters (1)
Cargo.lock
is excluded by!**/*.lock
📒 Files selected for processing (12)
CHANGELOG.md
(1 hunks)contracts/math/andromeda-time-gate/.cargo/config
(1 hunks)contracts/math/andromeda-time-gate/Cargo.toml
(1 hunks)contracts/math/andromeda-time-gate/examples/schema.rs
(1 hunks)contracts/math/andromeda-time-gate/src/contract.rs
(1 hunks)contracts/math/andromeda-time-gate/src/interface.rs
(1 hunks)contracts/math/andromeda-time-gate/src/lib.rs
(1 hunks)contracts/math/andromeda-time-gate/src/mock.rs
(1 hunks)contracts/math/andromeda-time-gate/src/state.rs
(1 hunks)contracts/math/andromeda-time-gate/src/testing/mock.rs
(1 hunks)contracts/math/andromeda-time-gate/src/testing/mod.rs
(1 hunks)contracts/math/andromeda-time-gate/src/testing/tests.rs
(1 hunks)
✅ Files skipped from review due to trivial changes (5)
- contracts/math/andromeda-time-gate/examples/schema.rs
- contracts/math/andromeda-time-gate/src/testing/mod.rs
- contracts/math/andromeda-time-gate/.cargo/config
- contracts/math/andromeda-time-gate/src/interface.rs
- contracts/math/andromeda-time-gate/Cargo.toml
🔇 Additional comments (5)
contracts/math/andromeda-time-gate/src/lib.rs (1)
1-12
: Module declarations and conditional compilation are correctly set up
The module structure and conditional compilation directives are appropriately configured for the contract's functionality and testing environment.
contracts/math/andromeda-time-gate/src/state.rs (1)
1-7
: State definitions are clear and appropriate
The storage items are correctly defined with suitable types, facilitating proper state management within the contract.
contracts/math/andromeda-time-gate/src/testing/mock.rs (1)
1-130
: Mock functions for testing are well-structured
The testing utilities are properly implemented, allowing for effective unit tests of the contract's functionality.
contracts/math/andromeda-time-gate/src/mock.rs (2)
95-117
: LGTM! Query methods are well-implemented
The query methods follow a consistent pattern and are properly typed.
120-139
: LGTM! Helper functions are well-structured
The helper functions have clear responsibilities and proper parameter handling.
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: 1
🧹 Outside diff range and nitpick comments (1)
contracts/math/andromeda-time-gate/Cargo.toml (1)
10-15
: Consider adding documentation for feature flagsWhile the features section includes basic comments, it would be helpful to add more detailed documentation about:
- When and why to use the
library
feature- What additional capabilities the
testing
feature provides- Impact of enabling
backtraces
in production
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
⛔ Files ignored due to path filters (1)
Cargo.lock
is excluded by!**/*.lock
📒 Files selected for processing (1)
contracts/math/andromeda-time-gate/Cargo.toml
(1 hunks)
🔇 Additional comments (2)
contracts/math/andromeda-time-gate/Cargo.toml (2)
27-30
: LGTM: Proper configuration of non-WASM dependencies
The non-WASM target dependencies are correctly configured:
- They're properly isolated using the target-specific configuration
- Testing-related dependencies (
cw-multi-test
andandromeda-testing
) are marked as optional - They use workspace versions for consistency
19-25
: Verify workspace dependency versions
The dependencies use workspace-level version specifications. While this is generally good practice for maintaining consistency, we should ensure that the workspace versions are appropriate for this new contract.
✅ Verification successful
Let me gather more information about the workspace-level dependencies.
Let me check the specific versions defined in the workspace.
Workspace dependencies are properly configured and up-to-date
The workspace is using appropriate versions of dependencies:
- cosmwasm-std = "1.5.8" (patched version addressing known vulnerabilities)
- cw-utils = "1.0.3"
- Both andromeda-std and andromeda-math are internal workspace packages with proper versioning
The workspace-level dependency management is correctly implemented and the versions used are secure and consistent across the project.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Check workspace-level dependency versions
cat Cargo.toml | rg "workspace = true" -B 1 -A 1
# Check if there are any known vulnerabilities in the dependencies
gh api graphql -f query='
{
securityVulnerabilities(first: 5, ecosystem: RUST, package: "cosmwasm-std") {
nodes {
advisory {
summary
severity
publishedAt
}
vulnerableVersionRange
firstPatchedVersion {
identifier
}
}
}
}'
Length of output: 1035
Script:
#!/bin/bash
# Check the workspace root Cargo.toml for dependency versions
fd -t f "Cargo.toml" -x cat {} | rg "\[workspace\]" -A 20
# Check if andromeda-std and andromeda-math are internal workspace members
fd -t f "Cargo.toml" -x cat {} | rg "andromeda-(std|math)"
Length of output: 3552
Script:
#!/bin/bash
# Check workspace dependencies versions in the root Cargo.toml
fd -t f "Cargo.toml" -x cat {} | rg "^\[workspace.dependencies\]" -A 20
# Check the specific package versions for the core dependencies
fd -t f "Cargo.toml" -x cat {} | rg "^(cosmwasm-std|cosmwasm-schema|cw-storage-plus|cw-utils) ="
Length of output: 9045
@coderabbitai review |
✅ Actions performedReview triggered.
|
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: 1
🧹 Outside diff range and nitpick comments (5)
contracts/math/andromeda-time-gate/src/mock.rs (2)
17-44
: Consider documenting the use of unchecked addressWhile
Addr::unchecked
is acceptable in test code, it's worth adding a comment explaining why it's safe to use here to prevent confusion for future maintainers.- MockTimeGate(Addr::unchecked(addr)) + // Using unchecked address is safe here as this is test code and the address comes from the mock app + MockTimeGate(Addr::unchecked(addr))
46-91
: Reduce code duplication in execute methodsThe funds handling logic is duplicated across all execute methods. Consider extracting this pattern into a helper method.
+ impl MockTimeGate { + fn execute_with_optional_funds( + &self, + app: &mut MockApp, + sender: Addr, + msg: ExecuteMsg, + funds: Option<Coin>, + ) -> ExecuteResult { + if let Some(funds) = funds { + app.execute_contract(sender, self.addr().clone(), &msg, &[funds]) + } else { + app.execute_contract(sender, self.addr().clone(), &msg, &[]) + } + } + }Then use it in the execute methods:
pub fn mock_execute_update_cycle_start_time( &self, app: &mut MockApp, sender: Addr, cycle_start_time: CycleStartTime, funds: Option<Coin>, ) -> ExecuteResult { let msg = ExecuteMsg::UpdateCycleStartTime { cycle_start_time }; - if let Some(funds) = funds { - app.execute_contract(sender, self.addr().clone(), &msg, &[funds]) - } else { - app.execute_contract(sender, self.addr().clone(), &msg, &[]) - } + self.execute_with_optional_funds(app, sender, msg, funds) }contracts/math/andromeda-time-gate/src/contract.rs (3)
139-141
: Improve error message consistencyThe error messages for InvalidParameter should follow a consistent format and be more specific about the validation failure.
- error: Some("Same as an existed cycle start time".to_string()) + error: Some("New cycle start time must be different from current value".to_string()) - error: Some("Same as existed gate addresses".to_string()) + error: Some("New gate addresses must be different from current values".to_string()) - error: Some("Same as an existed time interval".to_string()) + error: Some("New time interval must be different from current value".to_string())Also applies to: 169-170, 195-196
227-230
: Return time interval as u64 instead of StringConverting the time interval to String is unnecessary and forces clients to parse it back to a number.
- pub fn get_time_interval(storage: &dyn Storage) -> Result<String, ContractError> { - let time_interval = TIME_INTERVAL.load(storage)?.to_string(); + pub fn get_time_interval(storage: &dyn Storage) -> Result<u64, ContractError> { + let time_interval = TIME_INTERVAL.load(storage)?; Ok(time_interval)
261-263
: Improve arithmetic error messagesThe error messages for division and modulo operations should better explain why the error occurred.
- msg: "Division by zero in time delta".to_string(), + msg: "Time interval cannot be zero when calculating current gate index".to_string(), - msg: "Modulo by zero in gate length".to_string(), + msg: "Gate addresses list cannot be empty when calculating current gate index".to_string(),Also applies to: 269-271
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (2)
contracts/math/andromeda-time-gate/src/contract.rs
(1 hunks)contracts/math/andromeda-time-gate/src/mock.rs
(1 hunks)
🔇 Additional comments (6)
contracts/math/andromeda-time-gate/src/mock.rs (4)
1-13
: LGTM! Well-structured test configuration
The file is properly configured for testing with appropriate conditional compilation and necessary imports.
14-16
: LGTM! Clean mock structure implementation
The mock structure follows Andromeda's standard patterns using the mock_ado! macro for consistent implementation.
93-115
: LGTM! Well-structured query implementations
The query methods are consistently implemented and properly typed, providing a clean interface for testing the contract's state.
118-137
: LGTM! Clean helper function implementations
The contract creation and instantiation message helpers are well-structured and provide all necessary parameters for the time gate functionality.
contracts/math/andromeda-time-gate/src/contract.rs (2)
58-59
: 🛠️ Refactor suggestion
Consider explicit overflow handling for time interval
While unwrap_or()
safely handles the Option, the time interval value should be validated to prevent potential overflows when converting to nanoseconds later.
Add validation:
- let time_interval_seconds = msg.time_interval.unwrap_or(DEFAULT_TIME_INTERVAL);
+ let time_interval_seconds = msg.time_interval.unwrap_or(DEFAULT_TIME_INTERVAL);
+ ensure!(
+ time_interval_seconds.checked_mul(1_000_000_000).is_some(),
+ ContractError::Overflow {}
+ );
232-279
: Verify time calculation edge cases
The time-based routing is critical for contract security. Please verify the following edge cases:
- Behavior when current time equals cycle start time
- Handling of extremely large time intervals
- Proper wrapping of indices for long-running contracts
✅ Verification successful
Time calculations are properly handled with comprehensive safeguards
The code has robust protection against the edge cases:
- When current time equals cycle start time: Properly handled through
test_query_current_ado_path_not_started_yet
test which verifies the "Cycle is not started yet" error - Extremely large time intervals: Protected through checked arithmetic operations:
checked_mul
for time interval conversion to nanoschecked_sub
for time delta calculationchecked_div
for index calculation- All operations return appropriate errors (Overflow/Underflow) on arithmetic issues
- Index wrapping: Verified in
test_query_current_ado_path
which demonstrates correct wrapping back to first address after completing a cycle
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Search for test cases covering time-based edge cases
rg -A 5 "mod tests.*time"
rg -A 5 "test.*overflow"
Length of output: 54
Script:
#!/bin/bash
# Search for test files in the contract directory
fd "test.*\.rs" contracts/math/andromeda-time-gate/src/
# Search for any test functions related to time calculations
rg -l "test.*time" contracts/math/andromeda-time-gate/src/
# Look for test functions with overflow/underflow scenarios
ast-grep --pattern 'fn test_$_overflow$_() { $$$ }'
# Search for test functions that verify time-based routing
ast-grep --pattern '#[test]
fn $_($$$) {
$$$time$$$
}'
Length of output: 343
Script:
#!/bin/bash
# Let's examine the content of the test file to see the actual test cases
cat contracts/math/andromeda-time-gate/src/testing/tests.rs
# Also search for any time-related error handling in the contract
rg -A 3 "Overflow|Underflow|CustomError" contracts/math/andromeda-time-gate/src/
Length of output: 8792
Motivation
A request comes in, the ADO checks if the current time/date and if it’s before a specific time it returns the path ADO1, if it’s after that time, then ADO2.
Implementation
Testing
Unit test cases are added to codebase.
Version Changes
The version is set as 1.0.0
Summary by CodeRabbit
Summary by CodeRabbit
New Features
Testing Enhancements
Module Structure
Data Integrity