chore: Fix lint warnings for all targets (#240)
This commit is contained in:
parent
2f1270f8e8
commit
381a46f2cf
15 changed files with 93 additions and 94 deletions
|
|
@ -2,7 +2,7 @@ use pallas::network::{
|
||||||
miniprotocols::{
|
miniprotocols::{
|
||||||
blockfetch,
|
blockfetch,
|
||||||
handshake::{self, n2n::VersionTable},
|
handshake::{self, n2n::VersionTable},
|
||||||
Point, PROTOCOL_N2N_BLOCK_FETCH, PROTOCOL_N2N_HANDSHAKE, TESTNET_MAGIC,
|
Point, MAINNET_MAGIC, PROTOCOL_N2N_BLOCK_FETCH, PROTOCOL_N2N_HANDSHAKE,
|
||||||
},
|
},
|
||||||
multiplexer::{bearers::Bearer, StdPlexer},
|
multiplexer::{bearers::Bearer, StdPlexer},
|
||||||
};
|
};
|
||||||
|
|
@ -10,7 +10,7 @@ use pallas::network::{
|
||||||
fn main() {
|
fn main() {
|
||||||
env_logger::init();
|
env_logger::init();
|
||||||
|
|
||||||
let bearer = Bearer::connect_tcp("relays-new.cardano-testnet.iohkdev.io:3001").unwrap();
|
let bearer = Bearer::connect_tcp("relays-new.cardano-mainnet.iohk.io:3001").unwrap();
|
||||||
|
|
||||||
let mut plexer = StdPlexer::new(bearer);
|
let mut plexer = StdPlexer::new(bearer);
|
||||||
let handshake = plexer.use_client_channel(PROTOCOL_N2N_HANDSHAKE);
|
let handshake = plexer.use_client_channel(PROTOCOL_N2N_HANDSHAKE);
|
||||||
|
|
@ -19,15 +19,15 @@ fn main() {
|
||||||
plexer.muxer.spawn();
|
plexer.muxer.spawn();
|
||||||
plexer.demuxer.spawn();
|
plexer.demuxer.spawn();
|
||||||
|
|
||||||
let versions = VersionTable::v4_and_above(TESTNET_MAGIC);
|
let versions = VersionTable::v4_and_above(MAINNET_MAGIC);
|
||||||
let mut hs_client = handshake::N2NClient::new(handshake);
|
let mut hs_client = handshake::N2NClient::new(handshake);
|
||||||
let handshake = hs_client.handshake(versions).unwrap();
|
let handshake = hs_client.handshake(versions).unwrap();
|
||||||
|
|
||||||
assert!(matches!(handshake, handshake::Confirmation::Accepted(..)));
|
assert!(matches!(handshake, handshake::Confirmation::Accepted(..)));
|
||||||
|
|
||||||
let point = Point::Specific(
|
let point = Point::Specific(
|
||||||
63528597,
|
49159253,
|
||||||
hex::decode("3f3d81c7b88f0fa28867541c5fea8794125cccf6d6c9ee0037a1dbb064130dfd").unwrap(),
|
hex::decode("d034a2d0e4c3076f57368ed59319010c265718f0923057f8ff914a3b6bfd1314").unwrap(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut bf_client = blockfetch::Client::new(blockfetch);
|
let mut bf_client = blockfetch::Client::new(blockfetch);
|
||||||
|
|
|
||||||
|
|
@ -734,17 +734,17 @@ mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
const MAINNET_TEST_VECTORS: &[(&str, u8)] = &[
|
const MAINNET_TEST_VECTORS: &[(&str, u8)] = &[
|
||||||
("addr1qx2fxv2umyhttkxyxp8x0dlpdt3k6cwng5pxj3jhsydzer3n0d3vllmyqwsx5wktcd8cc3sq835lu7drv2xwl2wywfgse35a3x", 00u8),
|
("addr1qx2fxv2umyhttkxyxp8x0dlpdt3k6cwng5pxj3jhsydzer3n0d3vllmyqwsx5wktcd8cc3sq835lu7drv2xwl2wywfgse35a3x", 0u8),
|
||||||
("addr1z8phkx6acpnf78fuvxn0mkew3l0fd058hzquvz7w36x4gten0d3vllmyqwsx5wktcd8cc3sq835lu7drv2xwl2wywfgs9yc0hh", 01u8),
|
("addr1z8phkx6acpnf78fuvxn0mkew3l0fd058hzquvz7w36x4gten0d3vllmyqwsx5wktcd8cc3sq835lu7drv2xwl2wywfgs9yc0hh", 1u8),
|
||||||
("addr1yx2fxv2umyhttkxyxp8x0dlpdt3k6cwng5pxj3jhsydzerkr0vd4msrxnuwnccdxlhdjar77j6lg0wypcc9uar5d2shs2z78ve", 02u8),
|
("addr1yx2fxv2umyhttkxyxp8x0dlpdt3k6cwng5pxj3jhsydzerkr0vd4msrxnuwnccdxlhdjar77j6lg0wypcc9uar5d2shs2z78ve", 2u8),
|
||||||
("addr1x8phkx6acpnf78fuvxn0mkew3l0fd058hzquvz7w36x4gt7r0vd4msrxnuwnccdxlhdjar77j6lg0wypcc9uar5d2shskhj42g", 03u8),
|
("addr1x8phkx6acpnf78fuvxn0mkew3l0fd058hzquvz7w36x4gt7r0vd4msrxnuwnccdxlhdjar77j6lg0wypcc9uar5d2shskhj42g", 3u8),
|
||||||
("addr1gx2fxv2umyhttkxyxp8x0dlpdt3k6cwng5pxj3jhsydzer5pnz75xxcrzqf96k", 04u8),
|
("addr1gx2fxv2umyhttkxyxp8x0dlpdt3k6cwng5pxj3jhsydzer5pnz75xxcrzqf96k", 4u8),
|
||||||
("addr128phkx6acpnf78fuvxn0mkew3l0fd058hzquvz7w36x4gtupnz75xxcrtw79hu", 05u8),
|
("addr128phkx6acpnf78fuvxn0mkew3l0fd058hzquvz7w36x4gtupnz75xxcrtw79hu", 5u8),
|
||||||
("addr1vx2fxv2umyhttkxyxp8x0dlpdt3k6cwng5pxj3jhsydzers66hrl8", 06u8),
|
("addr1vx2fxv2umyhttkxyxp8x0dlpdt3k6cwng5pxj3jhsydzers66hrl8", 6u8),
|
||||||
("addr1w8phkx6acpnf78fuvxn0mkew3l0fd058hzquvz7w36x4gtcyjy7wx", 07u8),
|
("addr1w8phkx6acpnf78fuvxn0mkew3l0fd058hzquvz7w36x4gtcyjy7wx", 7u8),
|
||||||
("stake1uyehkck0lajq8gr28t9uxnuvgcqrc6070x3k9r8048z8y5gh6ffgw", 14u8),
|
("stake1uyehkck0lajq8gr28t9uxnuvgcqrc6070x3k9r8048z8y5gh6ffgw", 14u8),
|
||||||
("stake178phkx6acpnf78fuvxn0mkew3l0fd058hzquvz7w36x4gtcccycj5", 15u8),
|
("stake178phkx6acpnf78fuvxn0mkew3l0fd058hzquvz7w36x4gtcccycj5", 15u8),
|
||||||
("37btjrVyb4KDXBNC4haBVPCrro8AQPHwvCMp3RFhhSVWwfFmZ6wwzSK6JK1hY6wHNmtrpTf1kdbva8TCneM2YsiXT7mrzT21EacHnPpz5YyUdj64na", 08u8),
|
("37btjrVyb4KDXBNC4haBVPCrro8AQPHwvCMp3RFhhSVWwfFmZ6wwzSK6JK1hY6wHNmtrpTf1kdbva8TCneM2YsiXT7mrzT21EacHnPpz5YyUdj64na", 8u8),
|
||||||
];
|
];
|
||||||
|
|
||||||
const PAYMENT_PUBLIC_KEY: &str =
|
const PAYMENT_PUBLIC_KEY: &str =
|
||||||
|
|
@ -820,7 +820,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
ShelleyPaymentPart::Script(hash) => {
|
ShelleyPaymentPart::Script(hash) => {
|
||||||
let (_, expected) = &decode_bech32(SCRIPT_HASH).unwrap();
|
let (_, expected) = &decode_bech32(SCRIPT_HASH).unwrap();
|
||||||
let expected = &Hash::<28>::from_str(&hex::encode(&expected)).unwrap();
|
let expected = &Hash::<28>::from_str(&hex::encode(expected)).unwrap();
|
||||||
assert_eq!(hash, expected);
|
assert_eq!(hash, expected);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -832,7 +832,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
ShelleyDelegationPart::Script(hash) => {
|
ShelleyDelegationPart::Script(hash) => {
|
||||||
let (_, expected) = &decode_bech32(SCRIPT_HASH).unwrap();
|
let (_, expected) = &decode_bech32(SCRIPT_HASH).unwrap();
|
||||||
let expected = &Hash::<28>::from_str(&hex::encode(&expected)).unwrap();
|
let expected = &Hash::<28>::from_str(&hex::encode(expected)).unwrap();
|
||||||
assert_eq!(hash, expected);
|
assert_eq!(hash, expected);
|
||||||
}
|
}
|
||||||
ShelleyDelegationPart::Pointer(ptr) => {
|
ShelleyDelegationPart::Pointer(ptr) => {
|
||||||
|
|
@ -850,13 +850,12 @@ mod tests {
|
||||||
}
|
}
|
||||||
StakePayload::Script(hash) => {
|
StakePayload::Script(hash) => {
|
||||||
let (_, expected) = &decode_bech32(SCRIPT_HASH).unwrap();
|
let (_, expected) = &decode_bech32(SCRIPT_HASH).unwrap();
|
||||||
let expected = &Hash::<28>::from_str(&hex::encode(&expected)).unwrap();
|
let expected = &Hash::<28>::from_str(&hex::encode(expected)).unwrap();
|
||||||
assert_eq!(hash, expected);
|
assert_eq!(hash, expected);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Address::Byron(_) => {
|
Address::Byron(_) => {
|
||||||
// byron has it's own payload tests
|
// byron has it's own payload tests
|
||||||
()
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,16 @@
|
||||||
use blake2::Blake2bVar;
|
use bech32::{self, Error, ToBase32, Variant};
|
||||||
use blake2::digest::{Update, VariableOutput};
|
use blake2::digest::{Update, VariableOutput};
|
||||||
use bech32 :: {self, Variant, Error, ToBase32};
|
use blake2::Blake2bVar;
|
||||||
use hex::{self};
|
use hex::{self};
|
||||||
use std::error::Error as Err;
|
use std::error::Error as Err;
|
||||||
|
|
||||||
const DATA: &str = "asset";
|
const DATA: &str = "asset";
|
||||||
|
|
||||||
pub struct AssetFingerprint {
|
pub struct AssetFingerprint {
|
||||||
hash_buf : [u8;20]
|
hash_buf: [u8; 20],
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AssetFingerprint {
|
impl AssetFingerprint {
|
||||||
|
|
||||||
pub fn from_parts(policy_id: &str, asset_name: &str) -> Result<AssetFingerprint, Box<dyn Err>> {
|
pub fn from_parts(policy_id: &str, asset_name: &str) -> Result<AssetFingerprint, Box<dyn Err>> {
|
||||||
let mut hasher = Blake2bVar::new(20).unwrap();
|
let mut hasher = Blake2bVar::new(20).unwrap();
|
||||||
let c = format!("{policy_id}{asset_name}");
|
let c = format!("{policy_id}{asset_name}");
|
||||||
|
|
@ -20,12 +19,11 @@ impl AssetFingerprint {
|
||||||
let mut buf = [0u8; 20];
|
let mut buf = [0u8; 20];
|
||||||
hasher.finalize_variable(&mut buf)?;
|
hasher.finalize_variable(&mut buf)?;
|
||||||
|
|
||||||
Ok(AssetFingerprint { hash_buf : buf })
|
Ok(AssetFingerprint { hash_buf: buf })
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn finger_print(&self) -> Result<String, Error> {
|
pub fn finger_print(&self) -> Result<String, Error> {
|
||||||
|
bech32::encode(DATA, self.hash_buf.to_base32(), Variant::Bech32)
|
||||||
bech32::encode(DATA, self.hash_buf.to_base32(), Variant::Bech32)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -35,17 +33,23 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn finger_print_test1() {
|
fn finger_print_test1() {
|
||||||
let af = AssetFingerprint::from_parts("7eae28af2208be856f7a119668ae52a49b73725e326dc16579dcc373", "").unwrap();
|
let af = AssetFingerprint::from_parts(
|
||||||
|
"7eae28af2208be856f7a119668ae52a49b73725e326dc16579dcc373",
|
||||||
|
"",
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
let result = af.finger_print().unwrap();
|
let result = af.finger_print().unwrap();
|
||||||
assert_eq!(result, "asset1rjklcrnsdzqp65wjgrg55sy9723kw09mlgvlc3");
|
assert_eq!(result, "asset1rjklcrnsdzqp65wjgrg55sy9723kw09mlgvlc3");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn finger_print_test2() {
|
fn finger_print_test2() {
|
||||||
let af = AssetFingerprint::from_parts("1e349c9bdea19fd6c147626a5260bc44b71635f398b67c59881df209", "504154415445").unwrap();
|
let af = AssetFingerprint::from_parts(
|
||||||
|
"1e349c9bdea19fd6c147626a5260bc44b71635f398b67c59881df209",
|
||||||
|
"504154415445",
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
let result = af.finger_print().unwrap();
|
let result = af.finger_print().unwrap();
|
||||||
assert_eq!(result, "asset1hv4p5tv2a837mzqrst04d0dcptdjmluqvdx9k3");
|
assert_eq!(result, "asset1hv4p5tv2a837mzqrst04d0dcptdjmluqvdx9k3");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ use pallas_codec::Fragment;
|
||||||
use pallas_multiplexer::agents::{Channel, ChannelBuffer, ChannelError};
|
use pallas_multiplexer::agents::{Channel, ChannelBuffer, ChannelError};
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
use tracing::{debug, instrument};
|
use tracing::debug;
|
||||||
|
|
||||||
use crate::common::Point;
|
use crate::common::Point;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ use pallas_miniprotocols::{
|
||||||
blockfetch,
|
blockfetch,
|
||||||
chainsync::{self, NextResponse},
|
chainsync::{self, NextResponse},
|
||||||
handshake::{self, Confirmation},
|
handshake::{self, Confirmation},
|
||||||
txsubmission::{self, EraTxBody, EraTxId, Reply, Server, TxIdAndSize},
|
txsubmission::{self, EraTxId, Reply, TxIdAndSize},
|
||||||
Point, PROTOCOL_N2N_BLOCK_FETCH, PROTOCOL_N2N_CHAIN_SYNC, PROTOCOL_N2N_HANDSHAKE,
|
Point, PROTOCOL_N2N_BLOCK_FETCH, PROTOCOL_N2N_CHAIN_SYNC, PROTOCOL_N2N_HANDSHAKE,
|
||||||
PROTOCOL_N2N_TX_SUBMISSION,
|
PROTOCOL_N2N_TX_SUBMISSION,
|
||||||
};
|
};
|
||||||
|
|
@ -62,14 +62,14 @@ pub fn chainsync_history_happy_path() {
|
||||||
assert!(matches!(client.state(), chainsync::State::Idle));
|
assert!(matches!(client.state(), chainsync::State::Idle));
|
||||||
|
|
||||||
match point {
|
match point {
|
||||||
Some(point) => assert_eq!(point, known_point.clone()),
|
Some(point) => assert_eq!(point, known_point),
|
||||||
None => panic!("expected point"),
|
None => panic!("expected point"),
|
||||||
}
|
}
|
||||||
|
|
||||||
let next = client.request_next().unwrap();
|
let next = client.request_next().unwrap();
|
||||||
|
|
||||||
match next {
|
match next {
|
||||||
NextResponse::RollBackward(point, _) => assert_eq!(point, known_point.clone()),
|
NextResponse::RollBackward(point, _) => assert_eq!(point, known_point),
|
||||||
_ => panic!("expected rollback"),
|
_ => panic!("expected rollback"),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -142,7 +142,7 @@ pub fn blockfetch_happy_path() {
|
||||||
|
|
||||||
let mut client = blockfetch::Client::new(blockfetch);
|
let mut client = blockfetch::Client::new(blockfetch);
|
||||||
|
|
||||||
let range_ok = client.request_range((known_point.clone(), known_point.clone()));
|
let range_ok = client.request_range((known_point.clone(), known_point));
|
||||||
|
|
||||||
assert!(matches!(client.state(), blockfetch::State::Streaming));
|
assert!(matches!(client.state(), blockfetch::State::Streaming));
|
||||||
|
|
||||||
|
|
@ -227,8 +227,8 @@ pub fn txsubmission_server_happy_path() {
|
||||||
));
|
));
|
||||||
|
|
||||||
match server.receive_next_reply() {
|
match server.receive_next_reply() {
|
||||||
Ok(Reply::Done) => return, // Server aint havin none of our sh*t
|
Ok(Reply::Done) => (), // Server aint havin none of our sh*t
|
||||||
Ok(Reply::TxIds(tx_ids)) => assert_eq!(tx_ids.len(), 3),
|
Ok(Reply::TxIds(tx_ids)) => assert_eq!(tx_ids.len(), 3),
|
||||||
Ok(_) | Err(_) => assert!(false),
|
Ok(_) | Err(_) => unreachable!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,7 @@ fn one_way_small_sequence_of_payloads() {
|
||||||
active_plexer.muxer.spawn();
|
active_plexer.muxer.spawn();
|
||||||
passive_plexer.demuxer.spawn();
|
passive_plexer.demuxer.spawn();
|
||||||
|
|
||||||
for _ in [0..100] {
|
for _ in 0..100 {
|
||||||
let payload = random_payload(50);
|
let payload = random_payload(50);
|
||||||
sender_channel.enqueue_chunk(payload.clone()).unwrap();
|
sender_channel.enqueue_chunk(payload.clone()).unwrap();
|
||||||
let received_payload = receiver_channel.dequeue_chunk().unwrap();
|
let received_payload = receiver_channel.dequeue_chunk().unwrap();
|
||||||
|
|
|
||||||
|
|
@ -96,10 +96,10 @@ mod tests {
|
||||||
for (idx, (block_str, jsonl_str)) in test_blocks.iter().enumerate() {
|
for (idx, (block_str, jsonl_str)) in test_blocks.iter().enumerate() {
|
||||||
println!("decoding json block {}", idx + 1);
|
println!("decoding json block {}", idx + 1);
|
||||||
|
|
||||||
let bytes = hex::decode(block_str).expect(&format!("bad block file {idx}"));
|
let bytes = hex::decode(block_str).unwrap_or_else(|_| panic!("bad block file {idx}"));
|
||||||
|
|
||||||
let (_, block): BlockWrapper =
|
let (_, block): BlockWrapper = minicbor::decode(&bytes[..])
|
||||||
minicbor::decode(&bytes[..]).expect(&format!("error decoding cbor for file {idx}"));
|
.unwrap_or_else(|_| panic!("error decoding cbor for file {idx}"));
|
||||||
|
|
||||||
let mut datums = jsonl_str.lines();
|
let mut datums = jsonl_str.lines();
|
||||||
|
|
||||||
|
|
@ -126,10 +126,10 @@ mod tests {
|
||||||
for (idx, (block_str, jsonl_str)) in test_blocks.iter().enumerate() {
|
for (idx, (block_str, jsonl_str)) in test_blocks.iter().enumerate() {
|
||||||
println!("decoding json block {}", idx + 1);
|
println!("decoding json block {}", idx + 1);
|
||||||
|
|
||||||
let bytes = hex::decode(block_str).expect(&format!("bad block file {idx}"));
|
let bytes = hex::decode(block_str).unwrap_or_else(|_| panic!("bad block file {idx}"));
|
||||||
|
|
||||||
let (_, block): BlockWrapper =
|
let (_, block): BlockWrapper = minicbor::decode(&bytes[..])
|
||||||
minicbor::decode(&bytes[..]).expect(&format!("error decoding cbor for file {idx}"));
|
.unwrap_or_else(|_| panic!("error decoding cbor for file {idx}"));
|
||||||
|
|
||||||
let mut scripts = jsonl_str.lines();
|
let mut scripts = jsonl_str.lines();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1623,12 +1623,13 @@ mod tests {
|
||||||
|
|
||||||
for (idx, block_str) in test_blocks.iter().enumerate() {
|
for (idx, block_str) in test_blocks.iter().enumerate() {
|
||||||
println!("decoding test block {}", idx + 1);
|
println!("decoding test block {}", idx + 1);
|
||||||
let bytes = hex::decode(block_str).expect(&format!("bad block file {idx}"));
|
let bytes = hex::decode(block_str).unwrap_or_else(|_| panic!("bad block file {idx}"));
|
||||||
|
|
||||||
let block: BlockWrapper =
|
let block: BlockWrapper = minicbor::decode(&bytes[..])
|
||||||
minicbor::decode(&bytes[..]).expect(&format!("error decoding cbor for file {idx}"));
|
.unwrap_or_else(|_| panic!("error decoding cbor for file {idx}"));
|
||||||
|
|
||||||
let bytes2 = to_vec(block).expect(&format!("error encoding block cbor for file {idx}"));
|
let bytes2 = to_vec(block)
|
||||||
|
.unwrap_or_else(|_| panic!("error encoding block cbor for file {idx}"));
|
||||||
|
|
||||||
assert!(bytes.eq(&bytes2), "re-encoded bytes didn't match original");
|
assert!(bytes.eq(&bytes2), "re-encoded bytes didn't match original");
|
||||||
}
|
}
|
||||||
|
|
@ -1643,13 +1644,13 @@ mod tests {
|
||||||
|
|
||||||
for (idx, header_str) in test_headers.iter().enumerate() {
|
for (idx, header_str) in test_headers.iter().enumerate() {
|
||||||
println!("decoding test header {}", idx + 1);
|
println!("decoding test header {}", idx + 1);
|
||||||
let bytes = hex::decode(header_str).expect(&format!("bad header file {idx}"));
|
let bytes = hex::decode(header_str).unwrap_or_else(|_| panic!("bad header file {idx}"));
|
||||||
|
|
||||||
let header: Header =
|
let header: Header = minicbor::decode(&bytes[..])
|
||||||
minicbor::decode(&bytes[..]).expect(&format!("error decoding cbor for file {idx}"));
|
.unwrap_or_else(|_| panic!("error decoding cbor for file {idx}"));
|
||||||
|
|
||||||
let bytes2 =
|
let bytes2 = to_vec(header)
|
||||||
to_vec(header).expect(&format!("error encoding header cbor for file {idx}"));
|
.unwrap_or_else(|_| panic!("error encoding header cbor for file {idx}"));
|
||||||
|
|
||||||
assert!(bytes.eq(&bytes2), "re-encoded bytes didn't match original");
|
assert!(bytes.eq(&bytes2), "re-encoded bytes didn't match original");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -764,13 +764,13 @@ mod tests {
|
||||||
|
|
||||||
for (idx, block_str) in test_blocks.iter().enumerate() {
|
for (idx, block_str) in test_blocks.iter().enumerate() {
|
||||||
println!("decoding test block {}", idx + 1);
|
println!("decoding test block {}", idx + 1);
|
||||||
let bytes = hex::decode(block_str).expect(&format!("bad block file {idx}"));
|
let bytes = hex::decode(block_str).unwrap_or_else(|_| panic!("bad block file {idx}"));
|
||||||
|
|
||||||
let block: BlockWrapper =
|
let block: BlockWrapper = minicbor::decode(&bytes[..])
|
||||||
minicbor::decode(&bytes[..]).expect(&format!("error decoding cbor for file {idx}"));
|
.unwrap_or_else(|_| panic!("error decoding cbor for file {idx}"));
|
||||||
|
|
||||||
let bytes2 = minicbor::to_vec(block)
|
let bytes2 = minicbor::to_vec(block)
|
||||||
.expect(&format!("error encoding block cbor for file {idx}"));
|
.unwrap_or_else(|_| panic!("error encoding block cbor for file {idx}"));
|
||||||
|
|
||||||
assert!(bytes.eq(&bytes2), "re-encoded bytes didn't match original");
|
assert!(bytes.eq(&bytes2), "re-encoded bytes didn't match original");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -833,12 +833,13 @@ mod tests {
|
||||||
|
|
||||||
for (idx, block_str) in test_blocks.iter().enumerate() {
|
for (idx, block_str) in test_blocks.iter().enumerate() {
|
||||||
println!("decoding test block {}", idx + 1);
|
println!("decoding test block {}", idx + 1);
|
||||||
let bytes = hex::decode(block_str).expect(&format!("bad block file {idx}"));
|
let bytes = hex::decode(block_str).unwrap_or_else(|_| panic!("bad block file {idx}"));
|
||||||
|
|
||||||
let block: BlockWrapper =
|
let block: BlockWrapper = minicbor::decode(&bytes[..])
|
||||||
minicbor::decode(&bytes[..]).expect(&format!("error decoding cbor for file {idx}"));
|
.unwrap_or_else(|_| panic!("error decoding cbor for file {idx}"));
|
||||||
|
|
||||||
let bytes2 = to_vec(block).expect(&format!("error encoding block cbor for file {idx}"));
|
let bytes2 = to_vec(block)
|
||||||
|
.unwrap_or_else(|_| panic!("error encoding block cbor for file {idx}"));
|
||||||
|
|
||||||
assert_eq!(hex::encode(bytes), hex::encode(bytes2));
|
assert_eq!(hex::encode(bytes), hex::encode(bytes2));
|
||||||
}
|
}
|
||||||
|
|
@ -861,12 +862,13 @@ mod tests {
|
||||||
|
|
||||||
for (idx, block_str) in test_blocks.iter().enumerate() {
|
for (idx, block_str) in test_blocks.iter().enumerate() {
|
||||||
println!("decoding test block {}", idx + 1);
|
println!("decoding test block {}", idx + 1);
|
||||||
let bytes = hex::decode(block_str).expect(&format!("bad block file {idx}"));
|
let bytes = hex::decode(block_str).unwrap_or_else(|_| panic!("bad block file {idx}"));
|
||||||
|
|
||||||
let block: BlockWrapper =
|
let block: BlockWrapper = minicbor::decode(&bytes[..])
|
||||||
minicbor::decode(&bytes[..]).expect(&format!("error decoding cbor for file {idx}"));
|
.unwrap_or_else(|_| panic!("error decoding cbor for file {idx}"));
|
||||||
|
|
||||||
let bytes2 = to_vec(block).expect(&format!("error encoding block cbor for file {idx}"));
|
let bytes2 = to_vec(block)
|
||||||
|
.unwrap_or_else(|_| panic!("error encoding block cbor for file {idx}"));
|
||||||
|
|
||||||
assert_eq!(hex::encode(bytes), hex::encode(bytes2));
|
assert_eq!(hex::encode(bytes), hex::encode(bytes2));
|
||||||
}
|
}
|
||||||
|
|
@ -878,13 +880,13 @@ mod tests {
|
||||||
|
|
||||||
for (idx, str) in subjects.iter().enumerate() {
|
for (idx, str) in subjects.iter().enumerate() {
|
||||||
println!("decoding test header {}", idx + 1);
|
println!("decoding test header {}", idx + 1);
|
||||||
let bytes = hex::decode(str).expect(&format!("bad header file {idx}"));
|
let bytes = hex::decode(str).unwrap_or_else(|_| panic!("bad header file {idx}"));
|
||||||
|
|
||||||
let block: BlockHead = minicbor::decode(&bytes[..])
|
let block: BlockHead = minicbor::decode(&bytes[..])
|
||||||
.expect(&format!("error decoding cbor for file {}", idx));
|
.unwrap_or_else(|_| panic!("error decoding cbor for file {idx}"));
|
||||||
|
|
||||||
let bytes2 =
|
let bytes2 = to_vec(block)
|
||||||
to_vec(block).expect(&format!("error encoding header cbor for file {idx}"));
|
.unwrap_or_else(|_| panic!("error encoding header cbor for file {idx}"));
|
||||||
|
|
||||||
assert_eq!(bytes, bytes2);
|
assert_eq!(bytes, bytes2);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -44,19 +44,18 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn known_fee_matches() {
|
fn known_fee_matches() {
|
||||||
// TODO: expand this test to include more test blocks
|
// TODO: expand this test to include more test blocks
|
||||||
let block_idx = 1;
|
|
||||||
let block_str = include_str!("../../test_data/byron4.block");
|
let block_str = include_str!("../../test_data/byron4.block");
|
||||||
|
|
||||||
let block_bytes = hex::decode(block_str).expect(&format!("bad block file {block_idx}"));
|
let block_bytes = hex::decode(block_str).expect("bad block file");
|
||||||
let block = crate::MultiEraBlock::decode_byron(&block_bytes).unwrap();
|
let block = crate::MultiEraBlock::decode_byron(&block_bytes).unwrap();
|
||||||
let txs = block.txs();
|
let txs = block.txs();
|
||||||
|
|
||||||
// don't want to pass if we don't have tx in the block
|
// don't want to pass if we don't have tx in the block
|
||||||
assert!(txs.len() > 0);
|
assert!(!txs.is_empty());
|
||||||
|
|
||||||
for tx in txs.iter().take(1) {
|
for tx in txs.iter().take(1) {
|
||||||
let byron = tx.as_byron().unwrap();
|
let byron = tx.as_byron().unwrap();
|
||||||
let fee = compute_byron_fee(&byron, None);
|
let fee = compute_byron_fee(byron, None);
|
||||||
assert_eq!(fee, 171070);
|
assert_eq!(fee, 171070);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -144,7 +144,7 @@ impl ComputeHash<32> for babbage::DatumOption {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::{Era, MultiEraBlock, MultiEraTx};
|
use crate::{Era, MultiEraTx};
|
||||||
|
|
||||||
use super::{ComputeHash, OriginalHash};
|
use super::{ComputeHash, OriginalHash};
|
||||||
use pallas_codec::utils::Int;
|
use pallas_codec::utils::Int;
|
||||||
|
|
@ -159,12 +159,11 @@ mod tests {
|
||||||
type BlockWrapper<'b> = (u16, byron::MintedBlock<'b>);
|
type BlockWrapper<'b> = (u16, byron::MintedBlock<'b>);
|
||||||
|
|
||||||
// TODO: expand this test to include more test blocks
|
// TODO: expand this test to include more test blocks
|
||||||
let block_idx = 1;
|
|
||||||
let block_str = include_str!("../../test_data/byron1.block");
|
let block_str = include_str!("../../test_data/byron1.block");
|
||||||
|
|
||||||
let block_bytes = hex::decode(block_str).expect(&format!("bad block file {block_idx}"));
|
let block_bytes = hex::decode(block_str).expect("bad block file");
|
||||||
let (_, block_model): BlockWrapper = minicbor::decode(&block_bytes[..])
|
let (_, block_model): BlockWrapper =
|
||||||
.expect(&format!("error decoding cbor for file {block_idx}"));
|
minicbor::decode(&block_bytes[..]).expect("error decoding cbor for file");
|
||||||
|
|
||||||
let computed_hash = block_model.header.original_hash();
|
let computed_hash = block_model.header.original_hash();
|
||||||
|
|
||||||
|
|
@ -179,12 +178,11 @@ mod tests {
|
||||||
type BlockWrapper<'b> = (u16, alonzo::MintedBlock<'b>);
|
type BlockWrapper<'b> = (u16, alonzo::MintedBlock<'b>);
|
||||||
|
|
||||||
// TODO: expand this test to include more test blocks
|
// TODO: expand this test to include more test blocks
|
||||||
let block_idx = 1;
|
|
||||||
let block_str = include_str!("../../test_data/alonzo1.block");
|
let block_str = include_str!("../../test_data/alonzo1.block");
|
||||||
|
|
||||||
let block_bytes = hex::decode(block_str).expect(&format!("bad block file {block_idx}"));
|
let block_bytes = hex::decode(block_str).expect("bad block file");
|
||||||
let (_, block_model): BlockWrapper = minicbor::decode(&block_bytes[..])
|
let (_, block_model): BlockWrapper =
|
||||||
.expect(&format!("error decoding cbor for file {block_idx}"));
|
minicbor::decode(&block_bytes[..]).expect("error decoding cbor for file");
|
||||||
|
|
||||||
let valid_hashes = vec![
|
let valid_hashes = vec![
|
||||||
"8ae0cd531635579a9b52b954a840782d12235251fb1451e5c699e864c677514a",
|
"8ae0cd531635579a9b52b954a840782d12235251fb1451e5c699e864c677514a",
|
||||||
|
|
@ -209,9 +207,10 @@ mod tests {
|
||||||
let block_idx = 1;
|
let block_idx = 1;
|
||||||
let block_str = include_str!("../../test_data/babbage1.block");
|
let block_str = include_str!("../../test_data/babbage1.block");
|
||||||
|
|
||||||
let block_bytes = hex::decode(block_str).expect(&format!("bad block file {block_idx}"));
|
let block_bytes =
|
||||||
|
hex::decode(block_str).unwrap_or_else(|_| panic!("bad block file {block_idx}"));
|
||||||
let (_, block_model): BlockWrapper = minicbor::decode(&block_bytes[..])
|
let (_, block_model): BlockWrapper = minicbor::decode(&block_bytes[..])
|
||||||
.expect(&format!("error decoding cbor for file {block_idx}"));
|
.unwrap_or_else(|_| panic!("error decoding cbor for file {block_idx}"));
|
||||||
|
|
||||||
let valid_hashes = vec!["3fad302595665b004971a6b76909854a39a0a7ecdbff3692f37b77ae37dbe882"];
|
let valid_hashes = vec!["3fad302595665b004971a6b76909854a39a0a7ecdbff3692f37b77ae37dbe882"];
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -103,11 +103,12 @@ pub enum MultiEraCert<'b> {
|
||||||
AlonzoCompatible(Box<Cow<'b, alonzo::Certificate>>),
|
AlonzoCompatible(Box<Cow<'b, alonzo::Certificate>>),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone, Default)]
|
||||||
#[non_exhaustive]
|
#[non_exhaustive]
|
||||||
pub enum MultiEraMeta<'b> {
|
pub enum MultiEraMeta<'b> {
|
||||||
NotApplicable,
|
#[default]
|
||||||
Empty,
|
Empty,
|
||||||
|
NotApplicable,
|
||||||
AlonzoCompatible(&'b alonzo::Metadata),
|
AlonzoCompatible(&'b alonzo::Metadata),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,6 @@ use pallas_primitives::alonzo;
|
||||||
|
|
||||||
use crate::MultiEraMeta;
|
use crate::MultiEraMeta;
|
||||||
|
|
||||||
impl Default for MultiEraMeta<'_> {
|
|
||||||
fn default() -> Self {
|
|
||||||
MultiEraMeta::Empty
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'b> MultiEraMeta<'b> {
|
impl<'b> MultiEraMeta<'b> {
|
||||||
pub fn as_alonzo(&self) -> Option<&alonzo::Metadata> {
|
pub fn as_alonzo(&self) -> Option<&alonzo::Metadata> {
|
||||||
match self {
|
match self {
|
||||||
|
|
|
||||||
|
|
@ -97,7 +97,7 @@ impl Error {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn custom(error: Box<dyn std::error::Error>) -> Error {
|
pub fn custom(error: Box<dyn std::error::Error>) -> Error {
|
||||||
Error::Custom(format!("{}", error))
|
Error::Custom(format!("{error}"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue