Skip to content

Commit

Permalink
Add runestone size test
Browse files Browse the repository at this point in the history
  • Loading branch information
casey committed Oct 13, 2023
1 parent bf6db2a commit 1d9e019
Show file tree
Hide file tree
Showing 2 changed files with 199 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/runes/edict.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::*;

#[derive(Default, Serialize, Debug, PartialEq)]
#[derive(Default, Serialize, Debug, PartialEq, Copy, Clone)]
pub struct Edict {
pub id: u128,
pub amount: u128,
Expand Down
198 changes: 198 additions & 0 deletions src/runes/runestone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -675,4 +675,202 @@ mod tests {
}))
);
}

#[test]
fn runestone_size() {
#[track_caller]
fn case(edicts: Vec<Edict>, etching: Option<Etching>, size: usize) {
assert_eq!(
Runestone { edicts, etching }.encipher().len() - 1 - b"RUNE_TEST".len(),
size
);
}

case(Vec::new(), None, 1);

case(
Vec::new(),
Some(Etching {
divisibility: 0,
rune: Rune(0),
}),
3,
);

case(
Vec::new(),
Some(Etching {
divisibility: MAX_DIVISIBILITY,
rune: Rune(0),
}),
4,
);

case(
Vec::new(),
Some(Etching {
divisibility: 0,
rune: Rune(u128::max_value()),
}),
21,
);

case(
vec![Edict {
amount: u128::max_value(),
id: RuneId {
height: 0,
index: 0,
}
.into(),
output: 0,
}],
Some(Etching {
divisibility: MAX_DIVISIBILITY,
rune: Rune(u128::max_value()),
}),
43,
);

case(
vec![Edict {
amount: u128::max_value(),
id: RuneId {
height: 1_000_000,
index: u16::max_value().into(),
}
.into(),
output: 0,
}],
None,
28,
);

case(
vec![
Edict {
amount: u128::max_value(),
id: RuneId {
height: 1_000_000,
index: u16::max_value().into(),
}
.into(),
output: 0,
},
Edict {
amount: u128::max_value(),
id: RuneId {
height: 1_000_000,
index: u16::max_value().into(),
}
.into(),
output: 0,
},
],
None,
54,
);

case(
vec![
Edict {
amount: u128::max_value(),
id: RuneId {
height: 1_000_000,
index: u16::max_value().into(),
}
.into(),
output: 0,
},
Edict {
amount: u128::max_value(),
id: RuneId {
height: 1_000_000,
index: u16::max_value().into(),
}
.into(),
output: 0,
},
Edict {
amount: u128::max_value(),
id: RuneId {
height: 1_000_000,
index: u16::max_value().into(),
}
.into(),
output: 0,
},
],
None,
81,
);

case(
vec![
Edict {
amount: u64::max_value().into(),
id: RuneId {
height: 1_000_000,
index: u16::max_value().into(),
}
.into(),
output: 0,
};
4
],
None,
70,
);

case(
vec![
Edict {
amount: u64::max_value().into(),
id: RuneId {
height: 1_000_000,
index: u16::max_value().into(),
}
.into(),
output: 0,
};
5
],
None,
88,
);

case(
vec![
Edict {
amount: u64::max_value().into(),
id: RuneId {
height: 0,
index: u16::max_value().into(),
}
.into(),
output: 0,
};
5
],
None,
72,
);

case(
vec![
Edict {
amount: 1_000_000_000_000_000_000,
id: RuneId {
height: 1_000_000,
index: u16::max_value().into(),
}
.into(),
output: 0,
};
5
],
None,
83,
);
}
}

0 comments on commit 1d9e019

Please sign in to comment.