Skip to content

Commit

Permalink
rusk: change last_provisioners_change to return Vec
Browse files Browse the repository at this point in the history
  • Loading branch information
herr-seppia committed Apr 12, 2024
1 parent e45fa5e commit d3bf46d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 22 deletions.
4 changes: 2 additions & 2 deletions rusk/src/lib/chain/rusk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ impl Rusk {
pub fn last_provisioners_change(
&self,
base_commit: Option<[u8; 32]>,
) -> Result<impl Iterator<Item = (BlsPublicKey, Option<StakeData>)>> {
) -> Result<Vec<(BlsPublicKey, Option<StakeData>)>> {
let (sender, receiver) = mpsc::channel();
self.feeder_query(
STAKE_CONTRACT,
Expand All @@ -366,7 +366,7 @@ impl Rusk {
rkyv::from_bytes::<(BlsPublicKey, Option<StakeData>)>(&bytes).expect(
"The contract should only return (pk, Option<stake_data>) tuples",
)
}))
}).collect())
}

pub fn provisioner(&self, pk: &BlsPublicKey) -> Result<Option<StakeData>> {
Expand Down
25 changes: 5 additions & 20 deletions rusk/tests/services/stake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,10 +321,7 @@ pub async fn slash() -> Result<()> {
)
.expect("to work");

let last_changes = rusk
.last_provisioners_change(None)
.unwrap()
.collect::<Vec<_>>();
let last_changes = rusk.last_provisioners_change(None).unwrap();
let (_, prev) = last_changes.first().expect("Something changed").clone();
let prev = prev.expect("to have something");
assert_eq!(prev.reward, dusk(3.0));
Expand All @@ -347,10 +344,7 @@ pub async fn slash() -> Result<()> {
)
.expect("to work");

let last_changes = rusk
.last_provisioners_change(None)
.unwrap()
.collect::<Vec<_>>();
let last_changes = rusk.last_provisioners_change(None).unwrap();
let (_, prev) = last_changes.first().expect("Something changed").clone();
let prev = prev.expect("to have something");
assert_eq!(prev.reward, 0);
Expand All @@ -373,10 +367,7 @@ pub async fn slash() -> Result<()> {
)
.expect("to work");

let last_changes = rusk
.last_provisioners_change(None)
.unwrap()
.collect::<Vec<_>>();
let last_changes = rusk.last_provisioners_change(None).unwrap();
let (_, prev) = last_changes.first().expect("Something changed").clone();
let prev = prev.expect("to have something");
assert_eq!(prev.reward, 0);
Expand All @@ -399,21 +390,15 @@ pub async fn slash() -> Result<()> {
.expect_err("Slashing a public key that never staked must fail");

//Ensure we still have previous changes, because generator procedure failed
let last_changes = rusk
.last_provisioners_change(None)
.unwrap()
.collect::<Vec<_>>();
let last_changes = rusk.last_provisioners_change(None).unwrap();
let (_, prev) = last_changes.first().expect("Something changed").clone();
let prev = prev.expect("to have something");
assert_eq!(prev.reward, 0);
assert_eq!(prev.amount, Some((dusk(20.0), 4320)));

generator_procedure(&rusk, &[], 9001, BLOCK_GAS_LIMIT, vec![], None)
.expect("To work properly");
let last_changes = rusk
.last_provisioners_change(None)
.unwrap()
.collect::<Vec<_>>();
let last_changes = rusk.last_provisioners_change(None).unwrap();
assert_eq!(0, last_changes.len(), "No changes expected");

// Check the state's root is changed from the original one
Expand Down

0 comments on commit d3bf46d

Please sign in to comment.