diff --git a/contracts/sui/libs/sui_rlp/sources/encoder.move b/contracts/sui/libs/sui_rlp/sources/encoder.move index 60456f1f..99bfa7e6 100644 --- a/contracts/sui/libs/sui_rlp/sources/encoder.move +++ b/contracts/sui/libs/sui_rlp/sources/encoder.move @@ -83,6 +83,12 @@ module sui_rlp::encoder { let vec=vector::singleton(num); encode(&vec) + } + + public fun encode_u32(num:u32):vector{ + let vec= utils::to_bytes_u32(num); + encode(&vec) + } public fun encode_u64(num:u64):vector{ @@ -126,5 +132,24 @@ module sui_rlp::encoder { vector[0] } + #[test] + fun test_encode_zero_value(){ + let num=0_u128; + let bytes=encode_u128(num); + assert!(bytes==x"00"); + + let num=0_u64; + let bytes=encode_u64(num); + assert!(bytes==x"00"); + + let num=0_u32; + let bytes=encode_u32(num); + assert!(bytes==x"00"); + + let num=0_u8; + let bytes=encode_u8(num); + assert!(bytes==x"00"); + } + } \ No newline at end of file diff --git a/contracts/sui/libs/sui_rlp/sources/utils.move b/contracts/sui/libs/sui_rlp/sources/utils.move index 5dd8c721..af37a07d 100644 --- a/contracts/sui/libs/sui_rlp/sources/utils.move +++ b/contracts/sui/libs/sui_rlp/sources/utils.move @@ -89,8 +89,11 @@ module sui_rlp::utils { i = i + 1; }; - - result + if (result.length()==0){ + vector[0] + }else{ + result + } }