Skip to content

Commit

Permalink
Revert "EPROD 653 define how to handle panics in the task scheduler (#…
Browse files Browse the repository at this point in the history
…202)"

This reverts commit 0d80b82.
  • Loading branch information
ufoscout authored Feb 19, 2024
1 parent 0d80b82 commit cd1b20d
Show file tree
Hide file tree
Showing 28 changed files with 215 additions and 971 deletions.
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ members = [
"ic-storage",
"ic-storage/ic-storage-derive",
"ic-task-scheduler",
"ic-task-scheduler/tests/dummy_scheduler_canister",
"ic-test-utils",
]

Expand Down
6 changes: 0 additions & 6 deletions dfx.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,6 @@
"candid": "target/wasm32-unknown-unknown/release/log_canister.did",
"wasm": "target/wasm32-unknown-unknown/release/examples/log_canister.wasm",
"type": "custom"
},
"dummy_scheduler_canister": {
"build": "",
"candid": "target/wasm32-unknown-unknown/release/dummy_scheduler_canister.did",
"wasm": "target/wasm32-unknown-unknown/release/dummy_scheduler_canister.wasm",
"type": "custom"
}
},
"networks": {
Expand Down
10 changes: 0 additions & 10 deletions ic-stable-structures/src/structure/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,16 +187,6 @@ pub trait UnboundedMapStructure<K, V> {
fn clear(&mut self);
}

pub trait IterableUnboundedMapStructure<K, V>: UnboundedMapStructure<K, V> {
/// Map iterator type
type Iterator<'a>: Iterator<Item = (K, V)>
where
Self: 'a;

/// Returns iterator over the whole collection
fn iter(&self) -> Self::Iterator<'_>;
}

pub trait VecStructure<T> {
/// Returns if vector is empty
fn is_empty(&self) -> bool;
Expand Down
15 changes: 1 addition & 14 deletions ic-stable-structures/src/structure/stable_storage/unbounded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::mem;
use dfinity_stable_structures::storable::Bound;
use dfinity_stable_structures::{btreemap, Memory, StableBTreeMap, Storable};

use crate::structure::{IterableUnboundedMapStructure, UnboundedMapStructure};
use crate::structure::UnboundedMapStructure;
use crate::{Bounds, SlicedStorable};

type ChunkIndex = u16;
Expand Down Expand Up @@ -184,19 +184,6 @@ where
}
}

impl<K, V, M> IterableUnboundedMapStructure<K, V> for StableUnboundedMap<K, V, M>
where
K: Storable,
V: SlicedStorable,
M: Memory,
{
type Iterator<'a> = StableUnboundedIter<'a, K, V, M> where Self: 'a;

fn iter(&self) -> Self::Iterator<'_> {
self.iter()
}
}

/// Wrapper for the key.
///
/// # Memory layout
Expand Down
6 changes: 3 additions & 3 deletions ic-stable-structures/tests/pocket_ic_tests/btreemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use super::with_pocket_ic_context;

#[test]
fn should_init_tx_btreemap() {
with_pocket_ic_context(|ctx| {
with_pocket_ic_context(|_, ctx| {
assert!(ctx.get_tx_from_btreemap(0)?.is_some());

Ok(())
Expand All @@ -12,7 +12,7 @@ fn should_init_tx_btreemap() {

#[test]
fn should_push_tx_to_btreemap() {
with_pocket_ic_context(|ctx| {
with_pocket_ic_context(|_, ctx| {
ctx.insert_tx_to_btreemap(1, 1, 10)?;

assert!(ctx.get_tx_from_btreemap(1).unwrap().is_some());
Expand All @@ -24,7 +24,7 @@ fn should_push_tx_to_btreemap() {

#[test]
fn should_persist_btreemap_tx_after_upgrade() {
with_pocket_ic_context(|ctx| {
with_pocket_ic_context(|_, ctx| {
ctx.insert_tx_to_btreemap(1, 1, 10)?;

assert!(ctx.get_tx_from_btreemap(1)?.is_some());
Expand Down
6 changes: 3 additions & 3 deletions ic-stable-structures/tests/pocket_ic_tests/cached_btreemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use super::with_pocket_ic_context;

#[test]
fn should_init_tx_cached_btreemap() {
with_pocket_ic_context(|ctx| {
with_pocket_ic_context(|_, ctx| {
assert!(ctx.get_tx_from_cached_btreemap(0)?.is_some());

Ok(())
Expand All @@ -12,7 +12,7 @@ fn should_init_tx_cached_btreemap() {

#[test]
fn should_push_tx_to_cached_btreemap() {
with_pocket_ic_context(|ctx| {
with_pocket_ic_context(|_, ctx| {
// We saturate the cache to force eviction
for i in 1..100 {
ctx.insert_tx_to_cached_btreemap(i, i, 10 + i)?;
Expand All @@ -30,7 +30,7 @@ fn should_push_tx_to_cached_btreemap() {

#[test]
fn should_persist_cached_btreemap_tx_after_upgrade() {
with_pocket_ic_context(|ctx| {
with_pocket_ic_context(|_, ctx| {
ctx.insert_tx_to_cached_btreemap(1, 1, 10)?;

assert!(ctx.get_tx_from_cached_btreemap(1)?.is_some());
Expand Down
6 changes: 3 additions & 3 deletions ic-stable-structures/tests/pocket_ic_tests/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use super::with_pocket_ic_context;

#[test]
fn should_init_tx_cell() {
with_pocket_ic_context(|ctx| {
with_pocket_ic_context(|_, ctx| {
assert_eq!(ctx.get_tx_from_cell()?.from, 0);

Ok(())
Expand All @@ -12,7 +12,7 @@ fn should_init_tx_cell() {

#[test]
fn should_push_tx_to_cell() {
with_pocket_ic_context(|ctx| {
with_pocket_ic_context(|_, ctx| {
ctx.insert_tx_to_cell(1, 1, 10)?;

assert_eq!(ctx.get_tx_from_cell()?.from, 1);
Expand All @@ -24,7 +24,7 @@ fn should_push_tx_to_cell() {

#[test]
fn should_persist_cell_tx_after_upgrade() {
with_pocket_ic_context(|ctx| {
with_pocket_ic_context(|_, ctx| {
ctx.insert_tx_to_cell(1, 1, 10)?;

assert_eq!(ctx.get_tx_from_cell()?.from, 1);
Expand Down
6 changes: 3 additions & 3 deletions ic-stable-structures/tests/pocket_ic_tests/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use super::with_pocket_ic_context;

#[test]
fn should_init_tx_log() {
with_pocket_ic_context(|ctx| {
with_pocket_ic_context(|_, ctx| {
let res = ctx.get_tx_from_log(0)?;
assert!(res.is_some());
Ok(())
Expand All @@ -12,7 +12,7 @@ fn should_init_tx_log() {

#[test]
fn should_push_tx_to_log() {
with_pocket_ic_context(|ctx| {
with_pocket_ic_context(|_, ctx| {
ctx.push_tx_to_log(1, 1, 10)?;

assert!(ctx.get_tx_from_log(1)?.is_some());
Expand All @@ -24,7 +24,7 @@ fn should_push_tx_to_log() {

#[test]
fn should_persist_log_tx_after_upgrade() {
with_pocket_ic_context(|ctx| {
with_pocket_ic_context(|_, ctx| {
ctx.push_tx_to_log(1, 1, 10)?;

assert!(ctx.get_tx_from_log(1)?.is_some());
Expand Down
6 changes: 3 additions & 3 deletions ic-stable-structures/tests/pocket_ic_tests/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use super::with_pocket_ic_context;

#[test]
fn should_init_tx_map() {
with_pocket_ic_context(|ctx| {
with_pocket_ic_context(|_, ctx| {
assert!(ctx.get_tx_from_unboundedmap(0)?.is_some());

Ok(())
Expand All @@ -12,7 +12,7 @@ fn should_init_tx_map() {

#[test]
fn should_push_tx_to_map() {
with_pocket_ic_context(|ctx| {
with_pocket_ic_context(|_, ctx| {
ctx.insert_tx_to_unboundedmap(1, 1, 10)?;

assert!(ctx.get_tx_from_unboundedmap(1).unwrap().is_some());
Expand All @@ -24,7 +24,7 @@ fn should_push_tx_to_map() {

#[test]
fn should_persist_map_tx_after_upgrade() {
with_pocket_ic_context(|ctx| {
with_pocket_ic_context(|_, ctx| {
ctx.insert_tx_to_unboundedmap(1, 1, 10)?;

assert!(ctx.get_tx_from_unboundedmap(1)?.is_some());
Expand Down
71 changes: 52 additions & 19 deletions ic-stable-structures/tests/pocket_ic_tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use anyhow::Result;
use candid::{CandidType, Decode, Deserialize, Encode, Principal};
use did::*;
use ic_exports::ic_kit::mock_principals::alice;
use ic_exports::ic_kit::{ic, inject};
use ic_exports::pocket_ic::{self, PocketIc, WasmResult};
use wasm_utils::get_dummy_canister_bytecode;

Expand Down Expand Up @@ -67,22 +68,32 @@ impl PocketIcTestContext {

pub fn get_tx_from_btreemap(&self, key: u64) -> Result<Option<BoundedTransaction>> {
let args = Encode!(&key).unwrap();
let res = self.query_as(alice(), self.dummy_canister, "get_tx_from_btreemap", args);
let res = self.query_as(
ic::caller(),
self.dummy_canister,
"get_tx_from_btreemap",
args,
);

Ok(res)
}

pub fn insert_tx_to_btreemap(&self, from: u8, to: u8, value: u8) -> Result<u64> {
let args = Encode!(&BoundedTransaction { from, to, value }).unwrap();
let res = self.update_call_as(alice(), self.dummy_canister, "insert_tx_to_btreemap", args);
let res = self.update_call_as(
ic::caller(),
self.dummy_canister,
"insert_tx_to_btreemap",
args,
);

Ok(res)
}

pub fn get_tx_from_cached_btreemap(&self, key: u64) -> Result<Option<BoundedTransaction>> {
let args = Encode!(&key).unwrap();
let res = self.query_as(
alice(),
ic::caller(),
self.dummy_canister,
"get_tx_from_cached_btreemap",
args,
Expand All @@ -94,7 +105,7 @@ impl PocketIcTestContext {
pub fn insert_tx_to_cached_btreemap(&self, from: u8, to: u8, value: u8) -> Result<u64> {
let args = Encode!(&BoundedTransaction { from, to, value }).unwrap();
let res = self.update_call_as(
alice(),
ic::caller(),
self.dummy_canister,
"insert_tx_to_cached_btreemap",
args,
Expand All @@ -105,22 +116,22 @@ impl PocketIcTestContext {

pub fn get_tx_from_cell(&self) -> Result<BoundedTransaction> {
let args = Encode!(&()).unwrap();
let res = self.query_as(alice(), self.dummy_canister, "get_tx_from_cell", args);
let res = self.query_as(ic::caller(), self.dummy_canister, "get_tx_from_cell", args);

Ok(res)
}

pub fn insert_tx_to_cell(&self, from: u8, to: u8, value: u8) -> Result<BoundedTransaction> {
let args = Encode!(&BoundedTransaction { from, to, value }).unwrap();
let res = self.update_call_as(alice(), self.dummy_canister, "insert_tx_to_cell", args);
let res = self.update_call_as(ic::caller(), self.dummy_canister, "insert_tx_to_cell", args);

Ok(res)
}

pub fn get_tx_from_unboundedmap(&self, key: u64) -> Result<Option<UnboundedTransaction>> {
let args = Encode!(&key).unwrap();
let res = self.query_as(
alice(),
ic::caller(),
self.dummy_canister,
"get_tx_from_unboundedmap",
args,
Expand All @@ -132,7 +143,7 @@ impl PocketIcTestContext {
pub fn insert_tx_to_unboundedmap(&self, from: u8, to: u8, value: u8) -> Result<u64> {
let args = Encode!(&UnboundedTransaction { from, to, value }).unwrap();
let res = self.update_call_as(
alice(),
ic::caller(),
self.dummy_canister,
"insert_tx_to_unboundedmap",
args,
Expand All @@ -143,36 +154,46 @@ impl PocketIcTestContext {

pub fn get_tx_from_multimap(&self, key: u64) -> Result<Option<BoundedTransaction>> {
let args = Encode!(&key).unwrap();
let res = self.query_as(alice(), self.dummy_canister, "get_tx_from_multimap", args);
let res = self.query_as(
ic::caller(),
self.dummy_canister,
"get_tx_from_multimap",
args,
);

Ok(res)
}

pub fn insert_tx_to_multimap(&self, from: u8, to: u8, value: u8) -> Result<u64> {
let args = Encode!(&BoundedTransaction { from, to, value }).unwrap();
let res = self.update_call_as(alice(), self.dummy_canister, "insert_tx_to_multimap", args);
let res = self.update_call_as(
ic::caller(),
self.dummy_canister,
"insert_tx_to_multimap",
args,
);

Ok(res)
}

pub fn get_tx_from_vec(&self, index: u64) -> Result<Option<BoundedTransaction>> {
let args = Encode!(&index).unwrap();
let res = self.query_as(alice(), self.dummy_canister, "get_tx_from_vec", args);
let res = self.query_as(ic::caller(), self.dummy_canister, "get_tx_from_vec", args);

Ok(res)
}

pub fn push_tx_to_vec(&self, from: u8, to: u8, value: u8) -> Result<u64> {
let args = Encode!(&BoundedTransaction { from, to, value }).unwrap();
let res = self.update_call_as(alice(), self.dummy_canister, "push_tx_to_vec", args);
let res = self.update_call_as(ic::caller(), self.dummy_canister, "push_tx_to_vec", args);

Ok(res)
}

pub fn get_tx_from_ring_buffer(&self, index: u64) -> Result<Option<BoundedTransaction>> {
let args = Encode!(&index).unwrap();
let res = self.query_as(
alice(),
ic::caller(),
self.dummy_canister,
"get_tx_from_ring_buffer",
args,
Expand All @@ -183,30 +204,40 @@ impl PocketIcTestContext {

pub fn push_tx_to_ring_buffer(&self, from: u8, to: u8, value: u8) -> Result<u64> {
let args = Encode!(&BoundedTransaction { from, to, value }).unwrap();
let res = self.update_call_as(alice(), self.dummy_canister, "push_tx_to_ring_buffer", args);
let res = self.update_call_as(
ic::caller(),
self.dummy_canister,
"push_tx_to_ring_buffer",
args,
);

Ok(res)
}

pub fn get_tx_from_log(&self, index: u64) -> Result<Option<BoundedTransaction>> {
let args = Encode!(&index).unwrap();
let res = self.query_as(alice(), self.dummy_canister, "get_tx_from_log", args);
let res = self.query_as(ic::caller(), self.dummy_canister, "get_tx_from_log", args);

Ok(res)
}

pub fn push_tx_to_log(&self, from: u8, to: u8, value: u8) -> Result<u64> {
let args = Encode!(&BoundedTransaction { from, to, value }).unwrap();
let res = self.update_call_as(alice(), self.dummy_canister, "push_tx_to_log", args);
let res = self.update_call_as(ic::caller(), self.dummy_canister, "push_tx_to_log", args);

Ok(res)
}
}

pub fn with_pocket_ic_context<F>(f: F) -> Result<()>
pub fn with_pocket_ic_context<'a, F>(f: F) -> Result<()>
where
F: FnOnce(&PocketIcTestContext) -> Result<()>,
F: FnOnce(&'a mut ic_exports::ic_kit::MockContext, &PocketIcTestContext) -> Result<()>,
{
ic_exports::ic_kit::MockContext::new()
.with_caller(alice())
.with_id(alice())
.inject();

let env = pocket_ic::init_pocket_ic();
let dummy_canister = deploy_dummy_canister(&env).unwrap();

Expand All @@ -215,7 +246,9 @@ where
dummy_canister,
};

f(&test_ctx)?;
let ctx = inject::get_context();

f(ctx, &test_ctx)?;

Ok(())
}
Expand Down
Loading

0 comments on commit cd1b20d

Please sign in to comment.