Skip to content

Commit

Permalink
tests: update tests to use WlStorage
Browse files Browse the repository at this point in the history
  • Loading branch information
tzemanovic committed Jan 12, 2023
1 parent bb435d3 commit a673458
Show file tree
Hide file tree
Showing 16 changed files with 246 additions and 144 deletions.
4 changes: 2 additions & 2 deletions core/src/ledger/storage_api/collections/lazy_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -512,11 +512,11 @@ where
#[cfg(test)]
mod test {
use super::*;
use crate::ledger::storage::testing::TestStorage;
use crate::ledger::storage::testing::TestWlStorage;

#[test]
fn test_lazy_map_basics() -> storage_api::Result<()> {
let mut storage = TestStorage::default();
let mut storage = TestWlStorage::default();

let key = storage::Key::parse("test").unwrap();
let lazy_map = LazyMap::<u32, String>::open(key);
Expand Down
4 changes: 2 additions & 2 deletions core/src/ledger/storage_api/collections/lazy_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,11 +476,11 @@ where
#[cfg(test)]
mod test {
use super::*;
use crate::ledger::storage::testing::TestStorage;
use crate::ledger::storage::testing::TestWlStorage;

#[test]
fn test_lazy_vec_basics() -> storage_api::Result<()> {
let mut storage = TestStorage::default();
let mut storage = TestWlStorage::default();

let key = storage::Key::parse("test").unwrap();
let lazy_vec = LazyVec::<u32>::open(key);
Expand Down
5 changes: 3 additions & 2 deletions core/src/ledger/testnet_pow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -523,14 +523,15 @@ mod test_with_tx_and_vp_env {
tx_env.spawn_accounts([&faucet_address, &source]);

init_faucet_storage(
&mut tx_env.storage,
&mut tx_env.wl_storage,
&faucet_address,
difficulty,
withdrawal_limit,
)?;
tx_env.commit_genesis();

let challenge = Challenge::new(
&mut tx_env.storage,
&mut tx_env.wl_storage,
&faucet_address,
source.clone(),
)?;
Expand Down
4 changes: 2 additions & 2 deletions tests/src/native_vp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ impl TestNativeVpEnv {
let ctx = Ctx {
iterators: Default::default(),
gas_meter: Default::default(),
storage: &self.tx_env.storage,
write_log: &self.tx_env.write_log,
storage: &self.tx_env.wl_storage.storage,
write_log: &self.tx_env.wl_storage.write_log,
tx: &self.tx_env.tx,
tx_index: &self.tx_env.tx_index,
vp_wasm_cache: self.tx_env.vp_wasm_cache.clone(),
Expand Down
21 changes: 12 additions & 9 deletions tests/src/native_vp/pos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,20 @@ pub fn init_pos(
tx_host_env::with(|tx_env| {
// Ensure that all the used
// addresses exist
let native_token = tx_env.storage.native_token.clone();
let native_token = tx_env.wl_storage.storage.native_token.clone();
tx_env.spawn_accounts([&native_token]);
for validator in genesis_validators {
tx_env.spawn_accounts([&validator.address]);
}
tx_env.storage.block.epoch = start_epoch;
tx_env.wl_storage.storage.block.epoch = start_epoch;
// Initialize PoS storage
tx_env
.storage
.wl_storage
.init_genesis(params, genesis_validators.iter(), start_epoch)
.unwrap();

// Commit changes in WL to genesis state
tx_env.commit_genesis();
});
}

Expand Down Expand Up @@ -248,7 +251,7 @@ mod tests {
if !test_state.is_current_tx_valid {
// Clear out the changes
tx_host_env::with(|env| {
env.write_log.drop_tx();
env.wl_storage.drop_tx();
});
}

Expand All @@ -262,13 +265,13 @@ mod tests {
tx_host_env::with(|env| {
// Clear out the changes
if !test_state.is_current_tx_valid {
env.write_log.drop_tx();
env.wl_storage.drop_tx();
}
// Also commit the last transaction(s) changes, if any
env.commit_tx_and_block();

env.storage.block.epoch =
env.storage.block.epoch.next();
env.wl_storage.storage.block.epoch =
env.wl_storage.storage.block.epoch.next();
});

// Starting a new tx
Expand Down Expand Up @@ -298,7 +301,7 @@ mod tests {

// Clear out the invalid changes
tx_host_env::with(|env| {
env.write_log.drop_tx();
env.wl_storage.drop_tx();
})
}
}
Expand Down Expand Up @@ -851,7 +854,7 @@ pub mod testing {
// Reset the gas meter on each change, so that we never run
// out in this test
env.gas_meter.reset();
env.storage.block.epoch
env.wl_storage.storage.block.epoch
});
println!("Current epoch {}", current_epoch);

Expand Down
2 changes: 1 addition & 1 deletion tests/src/storage_api/collections/lazy_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ mod tests {
match &transition {
Transition::CommitTx => {
// commit the tx without committing the block
tx_host_env::with(|env| env.write_log.commit_tx());
tx_host_env::with(|env| env.wl_storage.commit_tx());
}
Transition::CommitTxAndBlock => {
// commit the tx and the block
Expand Down
2 changes: 1 addition & 1 deletion tests/src/storage_api/collections/lazy_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ mod tests {
match &transition {
Transition::CommitTx => {
// commit the tx without committing the block
tx_host_env::with(|env| env.write_log.commit_tx());
tx_host_env::with(|env| env.wl_storage.commit_tx());
}
Transition::CommitTxAndBlock => {
// commit the tx and the block
Expand Down
2 changes: 1 addition & 1 deletion tests/src/storage_api/collections/nested_lazy_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ mod tests {
match &transition {
Transition::CommitTx => {
// commit the tx without committing the block
tx_host_env::with(|env| env.write_log.commit_tx());
tx_host_env::with(|env| env.wl_storage.commit_tx());
}
Transition::CommitTxAndBlock => {
// commit the tx and the block
Expand Down
20 changes: 13 additions & 7 deletions tests/src/vm_host_env/ibc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ pub fn validate_ibc_vp_from_tx<'a>(
tx: &'a Tx,
) -> std::result::Result<bool, namada::ledger::ibc::vp::Error> {
let (verifiers, keys_changed) = tx_env
.wl_storage
.write_log
.verifiers_and_changed_keys(&tx_env.verifiers);
let addr = Address::Internal(InternalAddress::Ibc);
Expand All @@ -129,8 +130,8 @@ pub fn validate_ibc_vp_from_tx<'a>(

let ctx = Ctx::new(
&ADDRESS,
&tx_env.storage,
&tx_env.write_log,
&tx_env.wl_storage.storage,
&tx_env.wl_storage.write_log,
tx,
&TxIndex(0),
VpGasMeter::new(0),
Expand All @@ -150,6 +151,7 @@ pub fn validate_token_vp_from_tx<'a>(
target: &Key,
) -> std::result::Result<bool, namada::ledger::ibc::vp::IbcTokenError> {
let (verifiers, keys_changed) = tx_env
.wl_storage
.write_log
.verifiers_and_changed_keys(&tx_env.verifiers);
if !keys_changed.contains(target) {
Expand All @@ -164,8 +166,8 @@ pub fn validate_token_vp_from_tx<'a>(

let ctx = Ctx::new(
&ADDRESS,
&tx_env.storage,
&tx_env.write_log,
&tx_env.wl_storage.storage,
&tx_env.wl_storage.write_log,
tx,
&TxIndex(0),
VpGasMeter::new(0),
Expand All @@ -181,10 +183,14 @@ pub fn validate_token_vp_from_tx<'a>(
/// Initialize the test storage. Requires initialized [`tx_host_env::ENV`].
pub fn init_storage() -> (Address, Address) {
tx_host_env::with(|env| {
init_genesis_storage(&mut env.storage);
init_genesis_storage(&mut env.wl_storage.storage);
// block header to check timeout timestamp
env.storage.set_header(tm_dummy_header()).unwrap();
env.storage
env.wl_storage
.storage
.set_header(tm_dummy_header())
.unwrap();
env.wl_storage
.storage
.begin_block(BlockHash::default(), BlockHeight(1))
.unwrap();
});
Expand Down
Loading

0 comments on commit a673458

Please sign in to comment.