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

Chore/Additional PoX-4 Rust Tests #4245

Merged
merged 25 commits into from
Jan 23, 2024
Merged

Conversation

setzeus
Copy link
Collaborator

@setzeus setzeus commented Jan 15, 2024

Description

This PR introduces three tests for core public PoX-4 functions currently missing unit tests, specifically:

  • Delegate-stack-extend
  • Stack-increase
  • Delegate-stack-increase

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.

Copy link

codecov bot commented Jan 15, 2024

Codecov Report

Attention: 122 lines in your changes are missing coverage. Please review.

Comparison is base (9af9c0b) 24.37% compared to head (14950a2) 65.19%.
Report is 25 commits behind head on next.

Files Patch % Lines
...tackslib/src/chainstate/stacks/boot/pox_4_tests.rs 71.22% 82 Missing ⚠️
stackslib/src/chainstate/stacks/boot/mod.rs 61.90% 40 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@friedger friedger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

stackslib/src/chainstate/stacks/boot/mod.rs Outdated Show resolved Hide resolved
stackslib/src/chainstate/stacks/boot/pox_4_tests.rs Outdated Show resolved Hide resolved
stackslib/src/chainstate/stacks/boot/pox_4_tests.rs Outdated Show resolved Hide resolved
stackslib/src/chainstate/stacks/boot/pox_4_tests.rs Outdated Show resolved Hide resolved
stackslib/src/chainstate/stacks/boot/pox_4_tests.rs Outdated Show resolved Hide resolved
stackslib/src/chainstate/stacks/boot/pox_4_tests.rs Outdated Show resolved Hide resolved
stackslib/src/chainstate/stacks/boot/pox_4_tests.rs Outdated Show resolved Hide resolved
stackslib/src/chainstate/stacks/boot/pox_4_tests.rs Outdated Show resolved Hide resolved
@jferrant jferrant self-requested a review January 18, 2024 16:08
Copy link
Collaborator

@jferrant jferrant left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good :D

Copy link
Collaborator

@friedger friedger left a 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)
Copy link
Collaborator

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

Copy link
Collaborator Author

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?

Copy link
Collaborator

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed & reverted change.

@setzeus setzeus force-pushed the chore/additional-pox-4-rust-tests branch from 4e100b8 to def25bb Compare January 18, 2024 16:38
@setzeus setzeus marked this pull request as ready for review January 18, 2024 16:39
Copy link
Collaborator

@friedger friedger left a 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(
Copy link
Collaborator

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")
Copy link
Collaborator

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrected.

Copy link
Member

@MarvinJanssen MarvinJanssen left a 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);
Copy link
Member

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:

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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

Comment on lines 1682 to 1684
assert_eq!(
state_signer_key.to_string(),
format!("0x{}", signer_public_key.to_hex())
);
Copy link
Member

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.

@setzeus setzeus force-pushed the chore/additional-pox-4-rust-tests branch from c7ec78f to 4e814ac Compare January 19, 2024 01:40
Copy link
Collaborator

@friedger friedger left a 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());
Copy link
Collaborator

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(
Copy link
Collaborator

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]
Copy link
Member

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.

Copy link
Member

@jcnelson jcnelson left a 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!

Copy link
Member

@MarvinJanssen MarvinJanssen left a 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};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused import?

Comment on lines 1748 to 1761
assert_eq!(
state_signer_key.to_string(),
format!("0x{}", signer_public_key.to_hex())
);
Copy link
Member

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.

Comment on lines 1776 to 1791
assert_eq!(
state_signer_key_new.to_string(),
format!("0x{}", new_signer_public_key.to_hex())
);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

@setzeus setzeus force-pushed the chore/additional-pox-4-rust-tests branch from f26089c to 3d48e83 Compare January 22, 2024 18:58
@setzeus setzeus requested a review from kantai January 22, 2024 20:48
Copy link
Member

@kantai kantai left a 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?

@setzeus
Copy link
Collaborator Author

setzeus commented Jan 23, 2024

@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.

Copy link
Member

@MarvinJanssen MarvinJanssen left a 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())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the map necessary?

Copy link
Collaborator Author

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.

Copy link
Member

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().

Copy link
Collaborator Author

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())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

Copy link
Collaborator

@friedger friedger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@setzeus setzeus force-pushed the chore/additional-pox-4-rust-tests branch from 5d94131 to ab805d7 Compare January 23, 2024 15:31
@setzeus setzeus force-pushed the chore/additional-pox-4-rust-tests branch from ab805d7 to 14950a2 Compare January 23, 2024 18:10
@jferrant jferrant merged commit 3da5768 into next Jan 23, 2024
2 checks passed
@blockstack-devops
Copy link
Contributor

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.

@stacks-network stacks-network locked as resolved and limited conversation to collaborators Nov 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants