From 3941eed3b3229f1b66994e2469bfb7a10d041e37 Mon Sep 17 00:00:00 2001 From: lisicky Date: Thu, 15 Dec 2022 16:02:17 +0400 Subject: [PATCH 1/2] fix for protocol params update serialization --- rust/src/lib.rs | 36 ++++++++++++++++++++++++++++++++++++ rust/src/serialization.rs | 6 ++++++ 2 files changed, 42 insertions(+) diff --git a/rust/src/lib.rs b/rust/src/lib.rs index fabe5b42..87350a6f 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -3695,6 +3695,7 @@ impl From<&NativeScripts> for RequiredSignersSet { #[cfg(test)] mod tests { + use crate::tx_builder_constants::TxBuilderConstants; use super::*; #[test] @@ -3946,4 +3947,39 @@ mod tests { assert!(pks4.contains(&keyhash2)); assert!(pks4.contains(&keyhash3)); } + + #[test] + fn protocol_params_update_cbor_roundtrip() { + let mut orig_ppu = ProtocolParamUpdate::new(); + orig_ppu.set_max_tx_size(1234); + orig_ppu.set_max_block_body_size(5678); + orig_ppu.set_max_block_header_size(91011); + orig_ppu.set_minfee_a(&Coin::from(1u32)); + orig_ppu.set_minfee_b(&Coin::from(2u32)); + orig_ppu.set_key_deposit(&Coin::from(3u32)); + orig_ppu.set_pool_deposit(&Coin::from(4u32)); + orig_ppu.set_max_epoch(5); + orig_ppu.set_n_opt(6); + orig_ppu.set_pool_pledge_influence(&Rational::new(&BigNum::from(7u32), &BigNum::from(77u32))); + orig_ppu.set_expansion_rate(&UnitInterval::new(&BigNum::from(8u32), &BigNum::from(9u32))); + orig_ppu.set_treasury_growth_rate(&UnitInterval::new(&BigNum::from(10u32), &BigNum::from(11u32))); + orig_ppu.set_protocol_version(&ProtocolVersion::new(12u32,13u32)); + orig_ppu.set_min_pool_cost(&Coin::from(14u32)); + orig_ppu.set_ada_per_utxo_byte(&Coin::from(15u32)); + orig_ppu.set_cost_models(&TxBuilderConstants::plutus_vasil_cost_models()); + orig_ppu.set_execution_costs(&ExUnitPrices::new( + &SubCoin::new(&BigNum::from(16u32), &BigNum::from(17u32)), + &SubCoin::new(&BigNum::from(18u32), &BigNum::from(19u32)))); + orig_ppu.set_max_tx_ex_units(&ExUnits::new(&BigNum::from(20u32), &BigNum::from(21u32))); + orig_ppu.set_max_block_ex_units(&ExUnits::new(&BigNum::from(22u32), &BigNum::from(23u32))); + orig_ppu.set_max_value_size(24); + orig_ppu.set_collateral_percentage(25); + orig_ppu.set_max_collateral_inputs(25); + + let encoded = orig_ppu.to_bytes(); + let dencoded = ProtocolParamUpdate::from_bytes(encoded).unwrap(); + + assert_eq!(dencoded, orig_ppu); + assert_eq!(dencoded.to_bytes(), orig_ppu.to_bytes()); + } } diff --git a/rust/src/serialization.rs b/rust/src/serialization.rs index 984a0733..0fcdc8cd 100644 --- a/rust/src/serialization.rs +++ b/rust/src/serialization.rs @@ -3722,6 +3722,12 @@ impl cbor_event::se::Serialize for ProtocolParamUpdate { } + match &self.max_value_size { Some(_) => 1, None => 0, + } + match &self.collateral_percentage { + Some(_) => 1, + None => 0, + } + match &self.max_collateral_inputs { + Some(_) => 1, + None => 0, }, ))?; if let Some(field) = &self.minfee_a { From f191d8f4e08265774718b29c8f7afa0a6c77f3fb Mon Sep 17 00:00:00 2001 From: lisicky Date: Mon, 19 Dec 2022 01:45:59 +0400 Subject: [PATCH 2/2] version bump --- package-lock.json | 2 +- package.json | 2 +- rust/Cargo.toml | 2 +- rust/json-gen/Cargo.lock | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index b4ec4c2b..34026325 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "cardano-serialization-lib", - "version": "11.1.1", + "version": "11.2.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 434e995f..85b0d90d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cardano-serialization-lib", - "version": "11.1.1", + "version": "11.2.1", "description": "(De)serialization functions for the Cardano blockchain along with related utility functions", "scripts": { "rust:build-nodejs": "(rimraf ./rust/pkg && cd rust; wasm-pack build --target=nodejs; cd ..; npm run js:ts-json-gen; cd rust; wasm-pack pack) && npm run js:flowgen", diff --git a/rust/Cargo.toml b/rust/Cargo.toml index f057eac3..72f8118a 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cardano-serialization-lib" -version = "11.1.1" +version = "11.2.1" edition = "2018" authors = ["EMURGO"] license = "MIT" diff --git a/rust/json-gen/Cargo.lock b/rust/json-gen/Cargo.lock index 21e40ee0..b238d9c9 100644 --- a/rust/json-gen/Cargo.lock +++ b/rust/json-gen/Cargo.lock @@ -37,7 +37,7 @@ checksum = "a4a45a46ab1f2412e53d3a0ade76ffad2025804294569aae387231a0cd6e0899" [[package]] name = "cardano-serialization-lib" -version = "11.1.1" +version = "11.2.1" dependencies = [ "bech32", "cbor_event",