-
Notifications
You must be signed in to change notification settings - Fork 677
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
Chore/Additional PoX-4 Rust Tests #4245
Conversation
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## next #4245 +/- ##
===========================================
+ Coverage 24.37% 65.19% +40.81%
===========================================
Files 432 432
Lines 306556 306898 +342
===========================================
+ Hits 74735 200081 +125346
+ Misses 231821 106817 -125004 ☔ View full report in Codecov by Sentry. |
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.
👍
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.
Looks good :D
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.
comment related to issue #4230
@@ -1144,8 +1144,8 @@ | |||
(define-public (delegate-stack-extend | |||
(stacker principal) | |||
(pox-addr { version: (buff 1), hashbytes: (buff 32) }) | |||
(signer-key (buff 33)) | |||
(extend-count uint)) | |||
(extend-count uint) |
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 change should be a different PR related to this issue: #4230
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 already address it here & wrote tests for it accordingly. I'd rather update the description to address #4230 as well then revert the changes across all files.
That work?
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 issue does not contain a preferred solution, still unclear what/whether should 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.
Addressed & reverted change.
4e100b8
to
def25bb
Compare
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.
One test needs to be fixed
make_tx(key, nonce, 0, payload) | ||
} | ||
|
||
pub fn make_pox_4_delegate_increase( |
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 about stacking by pool operator, not delegation. Therefore, better make_pox_4_delegate_stack_increase
&latest_block, | ||
&key_to_stacks_addr(stacker_key).to_account_principal(), | ||
) | ||
.expect("No stacking state, stack-stx failed") |
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 stack-stx
? Should be delegate-stack-stx
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.
Corrected.
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.
Good to have more tests.
.clone() | ||
.expect_u128(); | ||
|
||
assert_eq!(total_locked, min_ustx * 2); |
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 would consider constructing an "expected tuple" and comparing them with assert_eq!
.
For example:
stacks-core/stackslib/src/chainstate/stacks/boot/signers_tests.rs
Lines 60 to 83 in 5c8f091
assert_eq!( | |
readonly_call( | |
&mut peer, | |
&latest_block, | |
"signers".into(), | |
"stackerdb-get-config".into(), | |
vec![], | |
), | |
Value::okay(Value::Tuple( | |
TupleData::from_data(vec![ | |
("chunk-size".into(), Value::UInt(4096)), | |
("write-freq".into(), Value::UInt(0)), | |
("max-writes".into(), Value::UInt(4096)), | |
("max-neighbors".into(), Value::UInt(32)), | |
( | |
"hint-replicas".into(), | |
Value::cons_list_unsanitized(vec![]).unwrap() | |
) | |
]) | |
.unwrap() | |
)) | |
.unwrap() | |
); | |
} |
.clone() | ||
.expect_u128(); | ||
|
||
assert_eq!(total_locked, min_ustx * 2); |
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 as above.
assert_eq!( | ||
state_signer_key.to_string(), | ||
format!("0x{}", signer_public_key.to_hex()) | ||
); |
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.
You can compare the values directly.
c7ec78f
to
4e814ac
Compare
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.
Apart from #4230, this looks good.
pox_addr: PoxAddress, | ||
amount: u128, | ||
) -> StacksTransaction { | ||
//let addr_tuple = Value::Tuple(pox_addr.as_clarity_tuple().unwrap()); |
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 commented code, but add more comments :-)
make_tx(key, nonce, 0, payload) | ||
} | ||
|
||
pub fn make_pox_4_stack_increase( |
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.
nit, the order of the make functions is not clear to me.
); | ||
} | ||
|
||
#[test] |
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.
It's worth adding a comment here that the reason this test is so spartan is because stack-increase is the same in pox-4 as it is in pox-3. Same goes for delegate-stack-increase.
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.
Thanks for this @setzeus! Overall this looks good, but please address the other reviewers' comments. Also, could you please add docstrings to your tests, and comment on what's going on each time you perform a contract-call? Thanks!
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.
Some small items.
@@ -14,7 +14,7 @@ | |||
// You should have received a copy of the GNU General Public License | |||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
|
|||
use std::collections::{HashMap, HashSet, VecDeque}; | |||
use std::collections::{BTreeMap, HashMap, HashSet, VecDeque}; |
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.
Unused import?
assert_eq!( | ||
state_signer_key.to_string(), | ||
format!("0x{}", signer_public_key.to_hex()) | ||
); |
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 think it's better to compare the values directly instead of formatting to string.
assert_eq!( | ||
state_signer_key_new.to_string(), | ||
format!("0x{}", new_signer_public_key.to_hex()) | ||
); |
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 as above.
f26089c
to
3d48e83
Compare
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.
These tests look good to me -- can you just add like a couple sentences of comments for each of the test in pox_4_tests
that describe the test: the behavior it is trying to test, and then how it tests it?
@kantai refactored with more reader-friendly Alice/Bob context & added comments to the three tests in this PR. Once the comments are accepted / up to standard I'll open an issue against the remaining tests in pox_4_tests.rs to update them accordingly. |
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.
Looks good!
|
||
let actual_result = stacker_transactions | ||
.first() | ||
.map(|tx| tx.result.clone()) |
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.
Is the map necessary?
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.
Yes. Removing it breaks 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.
I mean, first()
returns an Option
, since you are just cloning you could perhaps use cloned()
.
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.
Ah, yeap, understood & updated to use .cloned() instead.
|
||
let actual_result = delegate_transactions | ||
.first() | ||
.map(|tx| tx.result.clone()) |
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 as above.
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 as above.
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.
LGTM
5d94131
to
ab805d7
Compare
ab805d7
to
14950a2
Compare
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Description
This PR introduces three tests for core public PoX-4 functions currently missing unit tests, specifically:
All three tests live in .boot/pox_4_tests.rs with a few helpers defined in .boot/contract_tests.rs.
Applicable issues
N/A, general Argon/PoX-4 workflow.
Additional info (benefits, drawbacks, caveats)
Increases code coverage for PoX-4. There's a Response(DataResponse...) extract that might end up being refactored for standardization but no immediate drawbacks.