1
//! An entity is a list on the wire, so it counts toward `MAX_WIRE_LIST_DEPTH`.
2

            
3
use super::*;
4

            
5
2
async fn decode_nested_entity(levels: usize) -> wasmtime::Result<EvalValue> {
6
2
    let mut form = r#"(list (ent) "x")"#.to_string();
7
2
    for _ in 2..levels {
8
121
        form = format!("(list {form})");
9
    }
10
2
    try_entity_widened_to_anyref(
11
2
        nomiscript::EntityKind::SshKey,
12
2
        "alloc_ssh_key",
13
2
        &[b"k", b"f", b"n", b"t", b"c", b"u"],
14
2
        &form,
15
2
    )
16
2
    .await
17
2
}
18

            
19
#[tokio::test(flavor = "current_thread")]
20
1
async fn an_entity_at_the_ceiling_decodes() {
21
1
    assert!(decode_nested_entity(MAX_WIRE_LIST_DEPTH).await.is_ok());
22
1
}
23

            
24
#[tokio::test(flavor = "current_thread")]
25
1
async fn an_entity_one_level_deeper_is_a_depth_error() {
26
1
    let err = decode_nested_entity(MAX_WIRE_LIST_DEPTH + 1)
27
1
        .await
28
        .unwrap_err();
29
1
    assert!(err.to_string().contains("depth limit"), "{err}");
30
1
}