Skip to content

Commit

Permalink
fix: rlp zero values
Browse files Browse the repository at this point in the history
  • Loading branch information
ibrizsabin committed Nov 6, 2024
1 parent 5b8a269 commit d9f95c9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
25 changes: 25 additions & 0 deletions contracts/sui/libs/sui_rlp/sources/encoder.move
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ module sui_rlp::encoder {
let vec=vector::singleton(num);
encode(&vec)

}

public fun encode_u32(num:u32):vector<u8>{
let vec= utils::to_bytes_u32(num);
encode(&vec)

}

public fun encode_u64(num:u64):vector<u8>{
Expand Down Expand Up @@ -126,5 +132,24 @@ module sui_rlp::encoder {
vector<u8>[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");
}


}
7 changes: 5 additions & 2 deletions contracts/sui/libs/sui_rlp/sources/utils.move
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,11 @@ module sui_rlp::utils {

i = i + 1;
};

result
if (result.length()==0){
vector<u8>[0]
}else{
result
}
}


Expand Down

0 comments on commit d9f95c9

Please sign in to comment.