Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
leighmcculloch committed Nov 22, 2023
1 parent 49d1ba0 commit 6208a52
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 67 deletions.
13 changes: 8 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ rev = "d6f8ece2c89809d5e2800b9df64ae60787ee492b"
default-features = false
features = ["curr"]

#[patch."https://github.com/stellar/rs-soroban-env"]
#soroban-env-common = { path = "../rs-soroban-env/soroban-env-common" }
#soroban-env-guest = { path = "../rs-soroban-env/soroban-env-guest" }
#soroban-env-host = { path = "../rs-soroban-env/soroban-env-host/" }
[patch."https://github.com/stellar/rs-soroban-env"]
soroban-env-common = { path = "../rs-soroban-env/soroban-env-common" }
soroban-env-guest = { path = "../rs-soroban-env/soroban-env-guest" }
soroban-env-host = { path = "../rs-soroban-env/soroban-env-host/" }
#[patch."https://github.com/stellar/rs-stellar-xdr"]
#stellar-xdr = { path = "../rs-stellar-xdr/" }

Expand Down
14 changes: 1 addition & 13 deletions soroban-sdk/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,6 @@ use internal::{
pub struct MaybeEnv {
maybe_env_impl: internal::MaybeEnvImpl,
#[cfg(any(test, feature = "testutils"))]
in_contract: Option<bool>,
#[cfg(any(test, feature = "testutils"))]
generators: Option<Rc<RefCell<Generators>>>,
#[cfg(any(test, feature = "testutils"))]
auth_snapshot: Option<Rc<RefCell<AuthSnapshot>>>,
Expand Down Expand Up @@ -182,8 +180,6 @@ impl MaybeEnv {
Self {
maybe_env_impl: None,
#[cfg(any(test, feature = "testutils"))]
in_contract: None,
#[cfg(any(test, feature = "testutils"))]
generators: None,
#[cfg(any(test, feature = "testutils"))]
auth_snapshot: None,
Expand Down Expand Up @@ -215,8 +211,6 @@ impl TryFrom<MaybeEnv> for Env {
Ok(Env {
env_impl,
#[cfg(any(test, feature = "testutils"))]
in_contract: value.in_contract.unwrap_or_default(),
#[cfg(any(test, feature = "testutils"))]
generators: value.generators.unwrap_or_default(),
#[cfg(any(test, feature = "testutils"))]
auth_snapshot: value.auth_snapshot.unwrap_or_default(),
Expand All @@ -235,8 +229,6 @@ impl From<Env> for MaybeEnv {
MaybeEnv {
maybe_env_impl: Some(value.env_impl.clone()),
#[cfg(any(test, feature = "testutils"))]
in_contract: Some(value.in_contract),
#[cfg(any(test, feature = "testutils"))]
generators: Some(value.generators.clone()),
#[cfg(any(test, feature = "testutils"))]
auth_snapshot: Some(value.auth_snapshot.clone()),
Expand All @@ -258,8 +250,6 @@ impl From<Env> for MaybeEnv {
pub struct Env {
env_impl: internal::EnvImpl,
#[cfg(any(test, feature = "testutils"))]
in_contract: bool,
#[cfg(any(test, feature = "testutils"))]
generators: Rc<RefCell<Generators>>,
#[cfg(any(test, feature = "testutils"))]
auth_snapshot: Rc<RefCell<AuthSnapshot>>,
Expand Down Expand Up @@ -477,7 +467,7 @@ use xdr::{
impl Env {
#[doc(hidden)]
pub fn in_contract(&self) -> bool {
self.in_contract
self.env_impl.has_frame().unwrap()
}

#[doc(hidden)]
Expand Down Expand Up @@ -563,7 +553,6 @@ impl Env {

let env = Env {
env_impl,
in_contract: false,
generators: generators.unwrap_or_default(),
snapshot,
auth_snapshot,
Expand Down Expand Up @@ -621,7 +610,6 @@ impl Env {
) -> Option<Val> {
let env = Env {
env_impl: env_impl.clone(),
in_contract: true,
generators: Default::default(),
auth_snapshot: Default::default(),
snapshot: None,
Expand Down
70 changes: 35 additions & 35 deletions soroban-sdk/src/tests/prng.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fn test_prng_shuffle() {

e.as_contract(&id, || {
let v = vec![&e, 1, 2, 3];
assert_eq!(v.to_shuffled(), vec![&e, 3, 2, 1]);
assert_eq!(v.to_shuffled(), vec![&e, 3, 1, 2]);
});

e.as_contract(&id, || {
Expand All @@ -54,7 +54,7 @@ fn test_vec_shuffle() {
e.as_contract(&id, || {
let v = vec![&e, 1, 2, 3];
let s = v.to_shuffled();
assert_eq!(s, vec![&e, 3, 2, 1]);
assert_eq!(s, vec![&e, 3, 1, 2]);
assert_eq!(v, vec![&e, 1, 2, 3]);
});

Expand All @@ -74,9 +74,9 @@ fn test_prng_fill_u64() {
e.as_contract(&id, || {
let mut v: u64 = 0;
e.prng().fill(&mut v);
assert_eq!(v, 15905370036469238889);
assert_eq!(v, 6775509081846337106);
e.prng().fill(&mut v);
assert_eq!(v, 9820564573332354559);
assert_eq!(v, 2134185115815765970);
});
}

Expand All @@ -86,8 +86,8 @@ fn test_prng_gen_u64() {
let id = e.register_contract(None, TestPrngContract);

e.as_contract(&id, || {
assert_eq!(e.prng().gen::<u64>(), 15905370036469238889);
assert_eq!(e.prng().gen::<u64>(), 9820564573332354559);
assert_eq!(e.prng().gen::<u64>(), 6775509081846337106);
assert_eq!(e.prng().gen::<u64>(), 2134185115815765970);
});
}

Expand All @@ -97,7 +97,7 @@ fn test_prng_gen_range_u64() {
let id = e.register_contract(None, TestPrngContract);

e.as_contract(&id, || {
assert_eq!(e.prng().gen_range::<u64>(..), 15905370036469238889);
assert_eq!(e.prng().gen_range::<u64>(..), 6775509081846337106);
assert_eq!(e.prng().gen_range::<u64>(u64::MAX..), u64::MAX);
assert_eq!(
e.prng().gen_range::<u64>(u64::MAX - 1..u64::MAX),
Expand Down Expand Up @@ -134,8 +134,8 @@ fn test_prng_fill_bytes() {
Bytes::from_array(
&e,
&[
105, 12, 228, 36, 199, 57, 187, 220, 255, 181, 66, 167, 114, 167, 73, 136, 126,
229, 99, 124, 156, 9, 231, 42, 211, 148, 110, 234, 189, 179, 224, 119
82, 78, 226, 155, 156, 113, 7, 94, 210, 231, 31, 49, 14, 38, 158, 29, 119, 169,
67, 74, 0, 33, 229, 5, 124, 88, 142, 155, 100, 252, 88, 124
]
)
);
Expand All @@ -145,8 +145,8 @@ fn test_prng_fill_bytes() {
Bytes::from_array(
&e,
&[
12, 120, 166, 125, 4, 130, 72, 67, 232, 216, 155, 171, 240, 65, 91, 25, 149,
135, 147, 217, 131, 98, 2, 123, 78, 144, 194, 14, 36, 113, 79, 193
135, 192, 91, 227, 201, 91, 94, 147, 96, 233, 24, 221, 122, 144, 212, 16, 4,
136, 28, 41, 249, 105, 126, 159, 101, 184, 58, 122, 80, 8, 9, 250
]
)
);
Expand All @@ -164,8 +164,8 @@ fn test_prng_gen_len_bytes() {
Bytes::from_array(
&e,
&[
105, 12, 228, 36, 199, 57, 187, 220, 255, 181, 66, 167, 114, 167, 73, 136, 126,
229, 99, 124, 156, 9, 231, 42, 211, 148, 110, 234, 189, 179, 224, 119
82, 78, 226, 155, 156, 113, 7, 94, 210, 231, 31, 49, 14, 38, 158, 29, 119, 169,
67, 74, 0, 33, 229, 5, 124, 88, 142, 155, 100, 252, 88, 124
]
)
);
Expand All @@ -174,8 +174,8 @@ fn test_prng_gen_len_bytes() {
Bytes::from_array(
&e,
&[
12, 120, 166, 125, 4, 130, 72, 67, 232, 216, 155, 171, 240, 65, 91, 25, 149,
135, 147, 217, 131, 98, 2, 123, 78, 144, 194, 14, 36, 113, 79, 193
135, 192, 91, 227, 201, 91, 94, 147, 96, 233, 24, 221, 122, 144, 212, 16, 4,
136, 28, 41, 249, 105, 126, 159, 101, 184, 58, 122, 80, 8, 9, 250
]
)
);
Expand All @@ -195,8 +195,8 @@ fn test_prng_fill_bytesn() {
BytesN::from_array(
&e,
&[
105, 12, 228, 36, 199, 57, 187, 220, 255, 181, 66, 167, 114, 167, 73, 136, 126,
229, 99, 124, 156, 9, 231, 42, 211, 148, 110, 234, 189, 179, 224, 119
82, 78, 226, 155, 156, 113, 7, 94, 210, 231, 31, 49, 14, 38, 158, 29, 119, 169,
67, 74, 0, 33, 229, 5, 124, 88, 142, 155, 100, 252, 88, 124
]
)
);
Expand All @@ -206,8 +206,8 @@ fn test_prng_fill_bytesn() {
BytesN::from_array(
&e,
&[
12, 120, 166, 125, 4, 130, 72, 67, 232, 216, 155, 171, 240, 65, 91, 25, 149,
135, 147, 217, 131, 98, 2, 123, 78, 144, 194, 14, 36, 113, 79, 193
135, 192, 91, 227, 201, 91, 94, 147, 96, 233, 24, 221, 122, 144, 212, 16, 4,
136, 28, 41, 249, 105, 126, 159, 101, 184, 58, 122, 80, 8, 9, 250
]
)
);
Expand All @@ -225,8 +225,8 @@ fn test_prng_gen_bytesn() {
BytesN::from_array(
&e,
&[
105, 12, 228, 36, 199, 57, 187, 220, 255, 181, 66, 167, 114, 167, 73, 136, 126,
229, 99, 124, 156, 9, 231, 42, 211, 148, 110, 234, 189, 179, 224, 119
82, 78, 226, 155, 156, 113, 7, 94, 210, 231, 31, 49, 14, 38, 158, 29, 119, 169,
67, 74, 0, 33, 229, 5, 124, 88, 142, 155, 100, 252, 88, 124
]
)
);
Expand All @@ -235,8 +235,8 @@ fn test_prng_gen_bytesn() {
BytesN::from_array(
&e,
&[
12, 120, 166, 125, 4, 130, 72, 67, 232, 216, 155, 171, 240, 65, 91, 25, 149,
135, 147, 217, 131, 98, 2, 123, 78, 144, 194, 14, 36, 113, 79, 193
135, 192, 91, 227, 201, 91, 94, 147, 96, 233, 24, 221, 122, 144, 212, 16, 4,
136, 28, 41, 249, 105, 126, 159, 101, 184, 58, 122, 80, 8, 9, 250
]
)
);
Expand All @@ -255,16 +255,16 @@ fn test_prng_fill_slice() {
assert_eq!(
v,
[
105, 12, 228, 36, 199, 57, 187, 220, 255, 181, 66, 167, 114, 167, 73, 136, 126,
229, 99, 124, 156, 9, 231, 42, 211, 148, 110, 234, 189, 179, 224, 119
82, 78, 226, 155, 156, 113, 7, 94, 210, 231, 31, 49, 14, 38, 158, 29, 119, 169, 67,
74, 0, 33, 229, 5, 124, 88, 142, 155, 100, 252, 88, 124
]
);
e.prng().fill(v);
assert_eq!(
v,
[
12, 120, 166, 125, 4, 130, 72, 67, 232, 216, 155, 171, 240, 65, 91, 25, 149, 135,
147, 217, 131, 98, 2, 123, 78, 144, 194, 14, 36, 113, 79, 193
135, 192, 91, 227, 201, 91, 94, 147, 96, 233, 24, 221, 122, 144, 212, 16, 4, 136,
28, 41, 249, 105, 126, 159, 101, 184, 58, 122, 80, 8, 9, 250
]
);
});
Expand All @@ -281,16 +281,16 @@ fn test_prng_fill_array() {
assert_eq!(
v,
[
105, 12, 228, 36, 199, 57, 187, 220, 255, 181, 66, 167, 114, 167, 73, 136, 126,
229, 99, 124, 156, 9, 231, 42, 211, 148, 110, 234, 189, 179, 224, 119
82, 78, 226, 155, 156, 113, 7, 94, 210, 231, 31, 49, 14, 38, 158, 29, 119, 169, 67,
74, 0, 33, 229, 5, 124, 88, 142, 155, 100, 252, 88, 124
]
);
e.prng().fill(&mut v);
assert_eq!(
v,
[
12, 120, 166, 125, 4, 130, 72, 67, 232, 216, 155, 171, 240, 65, 91, 25, 149, 135,
147, 217, 131, 98, 2, 123, 78, 144, 194, 14, 36, 113, 79, 193
135, 192, 91, 227, 201, 91, 94, 147, 96, 233, 24, 221, 122, 144, 212, 16, 4, 136,
28, 41, 249, 105, 126, 159, 101, 184, 58, 122, 80, 8, 9, 250
]
);
});
Expand All @@ -305,15 +305,15 @@ fn test_prng_gen_array() {
assert_eq!(
e.prng().gen::<[u8; 32]>(),
[
105, 12, 228, 36, 199, 57, 187, 220, 255, 181, 66, 167, 114, 167, 73, 136, 126,
229, 99, 124, 156, 9, 231, 42, 211, 148, 110, 234, 189, 179, 224, 119
82, 78, 226, 155, 156, 113, 7, 94, 210, 231, 31, 49, 14, 38, 158, 29, 119, 169, 67,
74, 0, 33, 229, 5, 124, 88, 142, 155, 100, 252, 88, 124
]
);
assert_eq!(
e.prng().gen::<[u8; 32]>(),
[
12, 120, 166, 125, 4, 130, 72, 67, 232, 216, 155, 171, 240, 65, 91, 25, 149, 135,
147, 217, 131, 98, 2, 123, 78, 144, 194, 14, 36, 113, 79, 193
135, 192, 91, 227, 201, 91, 94, 147, 96, 233, 24, 221, 122, 144, 212, 16, 4, 136,
28, 41, 249, 105, 126, 159, 101, 184, 58, 122, 80, 8, 9, 250
]
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
"contract": "GAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEGWF",
"key": {
"ledger_key_nonce": {
"nonce": 5827323990544907992
"nonce": 801925984706572462
}
},
"durability": "temporary"
Expand All @@ -119,7 +119,7 @@
"contract": "GAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEGWF",
"key": {
"ledger_key_nonce": {
"nonce": 5827323990544907992
"nonce": 801925984706572462
}
},
"durability": "temporary",
Expand Down Expand Up @@ -208,7 +208,7 @@
"contract": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAITA4",
"key": {
"ledger_key_nonce": {
"nonce": 1851768990755774890
"nonce": 5541220902715666415
}
},
"durability": "temporary"
Expand All @@ -223,7 +223,7 @@
"contract": "CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAITA4",
"key": {
"ledger_key_nonce": {
"nonce": 1851768990755774890
"nonce": 5541220902715666415
}
},
"durability": "temporary",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
"contract": "GAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEGWF",
"key": {
"ledger_key_nonce": {
"nonce": 5827323990544907992
"nonce": 801925984706572462
}
},
"durability": "temporary"
Expand All @@ -118,7 +118,7 @@
"contract": "GAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEGWF",
"key": {
"ledger_key_nonce": {
"nonce": 5827323990544907992
"nonce": 801925984706572462
}
},
"durability": "temporary",
Expand Down
Loading

0 comments on commit 6208a52

Please sign in to comment.