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

Allow specifying satpoint in batch inscription entry #3115

Merged
merged 26 commits into from
Feb 15, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Batchfile parsing tests
  • Loading branch information
raphjaph committed Feb 14, 2024
commit 9c048a64f703ccb5bf59f613b8a6b223613c6021
139 changes: 139 additions & 0 deletions src/wallet/inscribe/batch_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,142 @@ impl Batchfile {
Ok((inscriptions, postages, destinations))
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn batchfile_not_sat_and_satpoint() {
let tempdir = tempfile::TempDir::new().unwrap();
let batch_file = tempdir.path().join("batch.yaml");
fs::write(
batch_file.clone(),
r#"
mode: same-sat
sat: 55555
satpoint: 4651dc5e964879b1eb9183d467d1187dcd252504698002b01853446c460db2c5:0:0
inscriptions:
- file: inscription.txt
- file: tulip.png
- file: meow.wav
"#,
)
.unwrap();

assert_eq!(
Batchfile::load(batch_file.as_path())
.unwrap_err()
.to_string(),
"batchfile cannot set both `sat` and `satpoint`"
);
}

#[test]
fn batchfile_wrong_mode_for_satpoints() {
let tempdir = tempfile::TempDir::new().unwrap();
let batch_file = tempdir.path().join("batch.yaml");
fs::write(
batch_file.clone(),
r#"
mode: separate-outputs
inscriptions:
- file: inscription.txt
satpoint: bc4c30829a9564c0d58e6287195622b53ced54a25711d1b86be7cd3a70ef61ed:0:0
- file: tulip.png
satpoint: 5fddcbdc3eb21a93e8dd1dd3f9087c3677f422b82d5ba39a6b1ec37338154af6:0:0
- file: meow.wav
satpoint: 4651dc5e964879b1eb9183d467d1187dcd252504698002b01853446c460db2c5:0:0
"#,
)
.unwrap();

assert_eq!(
Batchfile::load(batch_file.as_path())
.unwrap_err()
.to_string(),
"specifying `satpoint` in an inscription only works in `satpoints` mode"
);
}

#[test]
fn batchfile_missing_satpoint() {
let tempdir = tempfile::TempDir::new().unwrap();
let batch_file = tempdir.path().join("batch.yaml");
fs::write(
batch_file.clone(),
r#"
mode: satpoints
inscriptions:
- file: inscription.txt
satpoint: bc4c30829a9564c0d58e6287195622b53ced54a25711d1b86be7cd3a70ef61ed:0:0
- file: tulip.png
- file: meow.wav
satpoint: 4651dc5e964879b1eb9183d467d1187dcd252504698002b01853446c460db2c5:0:0
"#,
)
.unwrap();

assert_eq!(
Batchfile::load(batch_file.as_path())
.unwrap_err()
.to_string(),
"if `satpoint` is set for any inscription, then all inscriptions need to specify a satpoint"
);
}

#[test]
fn batchfile_only_first_sat_of_outpoint() {
let tempdir = tempfile::TempDir::new().unwrap();
let batch_file = tempdir.path().join("batch.yaml");
fs::write(
batch_file.clone(),
r#"
mode: satpoints
inscriptions:
- file: inscription.txt
satpoint: bc4c30829a9564c0d58e6287195622b53ced54a25711d1b86be7cd3a70ef61ed:0:0
- file: tulip.png
satpoint: 5fddcbdc3eb21a93e8dd1dd3f9087c3677f422b82d5ba39a6b1ec37338154af6:0:21
- file: meow.wav
satpoint: 4651dc5e964879b1eb9183d467d1187dcd252504698002b01853446c460db2c5:0:0
"#,
)
.unwrap();

assert_eq!(
Batchfile::load(batch_file.as_path())
.unwrap_err()
.to_string(),
"`satpoint` can only be specified for first sat of an output"
);
}

#[test]
fn batchfile_no_postage_if_mode_satpoints() {
let tempdir = tempfile::TempDir::new().unwrap();
let batch_file = tempdir.path().join("batch.yaml");
fs::write(
batch_file.clone(),
r#"
mode: satpoints
postage: 1111
inscriptions:
- file: inscription.txt
satpoint: bc4c30829a9564c0d58e6287195622b53ced54a25711d1b86be7cd3a70ef61ed:0:0
- file: tulip.png
satpoint: 5fddcbdc3eb21a93e8dd1dd3f9087c3677f422b82d5ba39a6b1ec37338154af6:0:0
- file: meow.wav
satpoint: 4651dc5e964879b1eb9183d467d1187dcd252504698002b01853446c460db2c5:0:0
"#,
)
.unwrap();

assert_eq!(
Batchfile::load(batch_file.as_path())
.unwrap_err()
.to_string(),
"`postage` cannot be set if `satpoint` is set for any inscription"
);
}
}
Loading