Skip to content

Commit

Permalink
Rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
SirTyson committed Nov 18, 2024
1 parent 83f363c commit a2ca6da
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 55 deletions.
10 changes: 6 additions & 4 deletions soroban-simulation/src/snapshot_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl<T: SnapshotSourceWithArchive> AutoRestoringSnapshotSource<T> {
Ok(Self {
snapshot_source,
min_persistent_live_until_ledger: ledger_info.min_live_until_ledger_checked(
ContractDataDurability::Persistent).ok_or_else(||
ContractDataDurability::Persistent).ok_or_else(||
anyhow!("minimum persistent live until ledger overflows - ledger info is misconfigured"))?,
current_ledger_sequence: ledger_info.sequence_number,
new_keys_requiring_proof: RefCell::new(Default::default()),
Expand All @@ -91,7 +91,9 @@ impl<T: SnapshotSourceWithArchive> AutoRestoringSnapshotSource<T> {
if keys.is_empty() {
return Ok(None);
}
Ok(Some(self.snapshot_source.generate_new_entries_proof(keys.iter().cloned().collect::<Vec<_>>().as_slice())?))
Ok(Some(self.snapshot_source.generate_new_entries_proof(
keys.iter().cloned().collect::<Vec<_>>().as_slice(),
)?))
}

/// Simulates a `RestoreFootprintOp` for all the keys that have been
Expand Down Expand Up @@ -294,7 +296,7 @@ impl<'a> SnapshotSource for SimulationSnapshotSource<'a> {
.borrow_mut()
.maybe_update_entry(key, entry)
{
return Ok(Some((updated_entry, live_until.clone())));
return Ok(Some((updated_entry, *live_until)));
}
}
Ok(entry_with_live_until)
Expand All @@ -318,7 +320,7 @@ impl<'a, T: SnapshotSourceWithArchive> SnapshotSourceWithArchive
{
return Ok(LedgerEntryWithArchivalState {
entry: Some(updated_entry),
live_until_ledger: entry_state.live_until_ledger.clone(),
live_until_ledger: entry_state.live_until_ledger,
state: entry_state.state,
});
}
Expand Down
28 changes: 18 additions & 10 deletions soroban-simulation/src/test/simulation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@ use soroban_env_host::e2e_testutils::{
};
use soroban_env_host::fees::{FeeConfiguration, RentFeeConfiguration};
use soroban_env_host::xdr::{
AccountId, AlphaNum4, AssetCode4, ContractCostParamEntry, ContractCostParams, ContractCostType,
ContractDataDurability, ContractDataEntry, ContractExecutable, ExtensionPoint, Hash,
HostFunction, Int128Parts, InvokeContractArgs, LedgerEntry, LedgerEntryData, LedgerFootprint,
LedgerKey, LedgerKeyContractData, LedgerKeyTrustLine, PublicKey, ScAddress, ScBytes,
ScContractInstance, ScErrorCode, ScErrorType, ScMap, ScNonceKey, ScString, ScSymbol, ScVal,
AccountId, AlphaNum4, ArchivalProof, ArchivalProofBody, AssetCode4, ContractCostParamEntry,
ContractCostParams, ContractCostType, ContractDataDurability, ContractDataEntry,
ContractExecutable, ExtensionPoint, Hash, HostFunction, Int128Parts, InvokeContractArgs,
LedgerEntry, LedgerEntryData, LedgerFootprint, LedgerKey, LedgerKeyContractData,
LedgerKeyTrustLine, NonexistenceProofBody, PublicKey, ScAddress, ScBytes, ScContractInstance,
ScErrorCode, ScErrorType, ScMap, ScNonceKey, ScString, ScSymbol, ScVal,
SorobanAddressCredentials, SorobanAuthorizationEntry, SorobanAuthorizedFunction,
SorobanAuthorizedInvocation, SorobanCredentials, SorobanResources, SorobanTransactionData,
TrustLineAsset, TrustLineEntry, TrustLineEntryExt, TrustLineFlags, Uint256, VecM,
SorobanTransactionDataExt, TrustLineAsset, TrustLineEntry, TrustLineEntryExt, TrustLineFlags,
Uint256, VecM,
};
use soroban_env_host::HostError;
use soroban_test_wasms::{ADD_I32, AUTH_TEST_CONTRACT, TRY_CALL_SAC};
Expand Down Expand Up @@ -1144,8 +1146,10 @@ fn test_simulate_successful_sac_call() {
)
.unwrap(),
);
let snapshot_source =
Rc::new(AutoRestoringSnapshotSource::new(snapshot_source, &ledger_info).unwrap());
let res = simulate_invoke_host_function_op(
snapshot_source,
snapshot_source.clone(),
&network_config,
&SimulationAdjustmentConfig::no_adjustments(),
&ledger_info,
Expand All @@ -1154,6 +1158,7 @@ fn test_simulate_successful_sac_call() {
&source_account,
[1; 32],
true,
|| snapshot_source.get_new_keys_proof(),
)
.unwrap();
assert_eq!(res.invoke_result.unwrap(), ScVal::Void);
Expand All @@ -1175,7 +1180,7 @@ fn test_simulate_successful_sac_call() {
assert_eq!(
res.transaction_data,
Some(SorobanTransactionData {
ext: ExtensionPoint::V0,
ext: SorobanTransactionDataExt::V0,
resources: SorobanResources {
footprint: LedgerFootprint {
read_only: vec![ledger_entry_to_ledger_key(&contract_instance_le).unwrap(),]
Expand Down Expand Up @@ -1243,9 +1248,11 @@ fn test_simulate_unsuccessful_sac_call_with_try_call() {
)
.unwrap(),
);
let snapshot_source =
Rc::new(AutoRestoringSnapshotSource::new(snapshot_source, &ledger_info).unwrap());

let res = simulate_invoke_host_function_op(
snapshot_source,
snapshot_source.clone(),
&network_config,
&SimulationAdjustmentConfig::no_adjustments(),
&ledger_info,
Expand All @@ -1254,6 +1261,7 @@ fn test_simulate_unsuccessful_sac_call_with_try_call() {
&source_account,
[1; 32],
true,
|| snapshot_source.get_new_keys_proof(),
)
.unwrap();
// The return value indicates the whether the internal `mint` call has
Expand All @@ -1271,7 +1279,7 @@ fn test_simulate_unsuccessful_sac_call_with_try_call() {
assert_eq!(
res.transaction_data,
Some(SorobanTransactionData {
ext: ExtensionPoint::V0,
ext: SorobanTransactionDataExt::V0,
resources: SorobanResources {
footprint: LedgerFootprint {
read_only: vec![
Expand Down
2 changes: 1 addition & 1 deletion soroban-simulation/src/test/snapshot_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ fn test_automatic_restoration_with_archival_state() {
b"persistent_archived_need_proof_no_entry"
)))
.is_err());
// We don't try to restore the non-existent entires (this shouldn't
// We don't try to restore the non-existent entires (this shouldn't
// normally be called at all though in such case).
assert_eq!(
auto_restoring_snapshot
Expand Down
20 changes: 10 additions & 10 deletions soroban-simulation/src/testutils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ pub struct MockSnapshotSource {
map: BTreeMap<Rc<LedgerKey>, LedgerEntryWithArchivalState>,
}

pub type EntriesWithArchivalState = Vec<(
Option<LedgerKey>,
Option<LedgerEntry>,
Option<u32>,
LedgerEntryArchivalState,
)>;

impl MockSnapshotSource {
pub fn from_entries(
entries: Vec<(LedgerEntry, Option<u32>)>,
Expand All @@ -33,7 +40,7 @@ impl MockSnapshotSource {
let state = if let Some(live_until_ledger) = &live_until_ledger {
if *live_until_ledger < current_ledger_seq {
if matches!(
get_key_durability(&*key),
get_key_durability(&key),
Some(ContractDataDurability::Persistent)
) {
LedgerEntryArchivalState::Archived(false)
Expand Down Expand Up @@ -68,14 +75,7 @@ impl MockSnapshotSource {
Ok(Self { map })
}

pub fn from_entries_with_archival_state(
entries: Vec<(
Option<LedgerKey>,
Option<LedgerEntry>,
Option<u32>,
LedgerEntryArchivalState,
)>,
) -> Result<Self> {
pub fn from_entries_with_archival_state(entries: EntriesWithArchivalState) -> Result<Self> {
let mut map = BTreeMap::<Rc<LedgerKey>, LedgerEntryWithArchivalState>::new();
for (maybe_key, maybe_entry, live_until_ledger, state) in entries {
let key = if let Some(k) = maybe_key {
Expand Down Expand Up @@ -195,7 +195,7 @@ impl SnapshotSource for MockSnapshotSource {
) -> std::result::Result<Option<EntryWithLiveUntil>, HostError> {
if let Some(entry_state) = self.map.get(key) {
if let Some(entry) = &entry_state.entry {
Ok(Some((entry.clone(), entry_state.live_until_ledger.clone())))
Ok(Some((entry.clone(), entry_state.live_until_ledger)))
} else {
if matches!(entry_state.state, LedgerEntryArchivalState::Archived(_)) {
Err(HostError::from((
Expand Down
Loading

0 comments on commit a2ca6da

Please sign in to comment.