Skip to content

Commit

Permalink
Add LedgerInfo setters (#1255)
Browse files Browse the repository at this point in the history
### What

Resolves #745
  • Loading branch information
sisuresh authored Apr 21, 2024
1 parent c30bc76 commit d4f79c2
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 4 deletions.
48 changes: 48 additions & 0 deletions soroban-sdk/src/ledger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,54 @@ impl testutils::Ledger for Ledger {
env.host().set_ledger_info(li).unwrap();
}

fn set_protocol_version(&self, protocol_version: u32) {
self.with_mut(|ledger_info| {
ledger_info.protocol_version = protocol_version;
});
}

fn set_sequence_number(&self, sequence_number: u32) {
self.with_mut(|ledger_info| {
ledger_info.sequence_number = sequence_number;
});
}

fn set_timestamp(&self, timestamp: u64) {
self.with_mut(|ledger_info| {
ledger_info.timestamp = timestamp;
});
}

fn set_network_id(&self, network_id: [u8; 32]) {
self.with_mut(|ledger_info| {
ledger_info.network_id = network_id;
});
}

fn set_base_reserve(&self, base_reserve: u32) {
self.with_mut(|ledger_info| {
ledger_info.base_reserve = base_reserve;
});
}

fn set_min_temp_entry_ttl(&self, min_temp_entry_ttl: u32) {
self.with_mut(|ledger_info| {
ledger_info.min_temp_entry_ttl = min_temp_entry_ttl;
});
}

fn set_min_persistent_entry_ttl(&self, min_persistent_entry_ttl: u32) {
self.with_mut(|ledger_info| {
ledger_info.min_persistent_entry_ttl = min_persistent_entry_ttl;
});
}

fn set_max_entry_ttl(&self, max_entry_ttl: u32) {
self.with_mut(|ledger_info| {
ledger_info.max_entry_ttl = max_entry_ttl;
});
}

fn get(&self) -> testutils::LedgerInfo {
let env = self.env();
env.host().with_ledger_info(|li| Ok(li.clone())).unwrap()
Expand Down
6 changes: 2 additions & 4 deletions soroban-sdk/src/tests/max_ttl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ fn max() {
let e = Env::default();
let contract_id = e.register_contract(None, Contract);

let mut ledger_info = e.ledger().get();
ledger_info.sequence_number = 1;
ledger_info.max_entry_ttl = 5;
e.ledger().set(ledger_info);
e.ledger().set_sequence_number(1);
e.ledger().set_max_entry_ttl(5);

e.as_contract(&contract_id, || {
assert_eq!(e.storage().max_ttl(), 5);
Expand Down
24 changes: 24 additions & 0 deletions soroban-sdk/src/testutils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,30 @@ pub trait Ledger {
/// Set ledger info.
fn set(&self, l: LedgerInfo);

/// Sets the protocol version.
fn set_protocol_version(&self, protocol_version: u32);

/// Sets the sequence number.
fn set_sequence_number(&self, sequence_number: u32);

/// Sets the timestamp.
fn set_timestamp(&self, timestamp: u64);

/// Sets the network ID.
fn set_network_id(&self, network_id: [u8; 32]);

/// Sets the base reserve.
fn set_base_reserve(&self, base_reserve: u32);

/// Sets the minimum temporary entry time-to-live.
fn set_min_temp_entry_ttl(&self, min_temp_entry_ttl: u32);

/// Sets the minimum persistent entry time-to-live.
fn set_min_persistent_entry_ttl(&self, min_persistent_entry_ttl: u32);

/// Sets the maximum entry time-to-live.
fn set_max_entry_ttl(&self, max_entry_ttl: u32);

/// Get ledger info.
fn get(&self) -> LedgerInfo;

Expand Down

0 comments on commit d4f79c2

Please sign in to comment.