Skip to content

Commit

Permalink
transfer-contract: add next_pos tests
Browse files Browse the repository at this point in the history
  • Loading branch information
herr-seppia committed Jan 16, 2024
1 parent 8253ee9 commit 5021237
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion contracts/transfer/tests/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@ fn leaves_from_pos(session: &mut Session, pos: u64) -> Result<Vec<TreeLeaf>> {
.collect())
}

fn next_pos(session: &mut Session) -> Result<u64> {
session
.call(TRANSFER_CONTRACT, "next_pos", &(), u64::MAX)
.map(|r| r.data)
}

fn update_root(session: &mut Session) -> Result<()> {
session
.call(TRANSFER_CONTRACT, "update_root", &(), POINT_LIMIT)
Expand Down Expand Up @@ -254,6 +260,13 @@ fn transfer() {

assert_eq!(leaves.len(), 1, "There should be one note in the state");

let pos = next_pos(session).expect("Getting last post should succeed");
assert_eq!(
pos,
leaves.last().expect("note to exists").note.pos() + 1,
"next_pos should match position of last note + 1"
);

let leaves = leaves_from_pos(session, 0)
.expect("Getting leaves in the given range should succeed");

Expand Down Expand Up @@ -364,7 +377,14 @@ fn transfer() {
"There should be three notes in the tree at this block height"
);

let leaves = leaves_from_height(session, input_note.pos() + 1)
let pos = next_pos(session).expect("Getting last post should succeed");
assert_eq!(
pos,
leaves.last().expect("note to exists").note.pos() + 1,
"next_pos should match position of last note + 1"
);

let leaves = leaves_from_pos(session, input_note.pos() + 1)
.expect("Getting the notes should succeed");
assert_eq!(
leaves.len(),
Expand Down

0 comments on commit 5021237

Please sign in to comment.