Skip to content

Commit

Permalink
Merge branch 'master' into meta3
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei-marinica authored Jan 23, 2023
2 parents a777bcb + 9daa73b commit 23cbce7
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,22 @@
"status": "4",
"message": "str:cast to i64 error"
}
},
{
"step": "scQuery",
"id": "4",
"tx": {
"to": "sc:basic-features",
"function": "biguint_from_u128",
"arguments": []
},
"expect": {
"out": [
"0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
],
"status": "0",
"message": ""
}
}
]
}
5 changes: 5 additions & 0 deletions contracts/feature-tests/basic-features/src/big_num_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ pub trait BigIntMethods {
small.into()
}

#[endpoint]
fn biguint_from_u128(&self) -> BigUint {
BigUint::from(u128::MAX)
}

#[endpoint]
fn big_uint_from_managed_buffer(&self, mb: ManagedBuffer) -> BigUint {
BigUint::from(mb)
Expand Down
5 changes: 3 additions & 2 deletions contracts/feature-tests/basic-features/wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
////////////////////////////////////////////////////

// Init: 1
// Endpoints: 339
// Endpoints: 340
// Async Callback: 1
// Total number of exported functions: 341
// Total number of exported functions: 342

#![no_std]
#![feature(alloc_error_handler, lang_items)]
Expand All @@ -34,6 +34,7 @@ multiversx_sc_wasm_adapter::endpoints! {
big_uint_zero
big_uint_from_u64_1
big_uint_from_u64_2
biguint_from_u128
big_uint_from_managed_buffer
big_uint_from_managed_buffer_ref
big_int_zero
Expand Down
6 changes: 6 additions & 0 deletions framework/base/src/types/managed/basic/big_uint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ impl<M: ManagedTypeApi> ManagedType<M> for BigUint<M> {
}
}

impl<M: ManagedTypeApi> From<u128> for BigUint<M> {
fn from(value: u128) -> Self {
BigUint::from_bytes_be(&value.to_be_bytes()[..])
}
}

impl<M: ManagedTypeApi> From<ManagedBuffer<M>> for BigUint<M> {
#[inline]
fn from(item: ManagedBuffer<M>) -> Self {
Expand Down

0 comments on commit 23cbce7

Please sign in to comment.