0xMiden / 0xMiden/miden-vm

test-utils: `build_test!()` and `Test::expect_stack()` take opposite stack orders

Abierto
#2,021 3 comentarios 0 reacciones 0 asignados Ver en GitHub
processor
Lenguaje dominante
Rust
Estrellas
772
Forks
352
Merge medio
1 d 12 h
PR fusionados (30 d)
93

Descripción

The `build_test!()` family of macros take an input operand stack: https://github.com/0xMiden/miden-vm/blob/469c13972fb96036e89d326367b4cbe43a9f072b/crates/utils/testing/src/test_builders.rs#L112-L137

and `Test::expect_stack()` takes an expected output operand stack: https://github.com/0xMiden/miden-vm/blob/469c13972fb96036e89d326367b4cbe43a9f072b/crates/utils/testing/src/lib.rs#L225-L232

However these two parameters are in *opposite order* from each other. That is, the following test succeeds:

```rust
#[test]
fn test_stack_order() {
build_test!("begin nop end", &[0, 1, 2, 3]).expect_stack(&[3, 2, 1, 0]);
}
```

Technically the `build_test!()` family simply pass the input stack slice as `Test { stack_inputs }`. `stack_inputs` is of type `StackInputs`, which is documented to be in "stack-order": https://github.com/0xMiden/miden-vm/blob/469c13972fb96036e89d326367b4cbe43a9f072b/core/src/stack/inputs.rs#L12-L17

And *internally* `expect_stack()` uses `StackOutputs`, which is documented to be in the opposite order (though this is not called out so explicitly): https://github.com/0xMiden/miden-vm/blob/469c13972fb96036e89d326367b4cbe43a9f072b/core/src/stack/outputs.rs#L12-L20

So upon investigation, this behavior is consistent, but it *is* very confusing; none of the docs for the testing functions, macros, or structs mention this. In fact, `expect_stack()` claims that its parameter is in stack order:
> Builds a final stack from the provided **stack-ordered** array and asserts that executing the test will result in the expected final stack state.

\[Emphasis mine\]

Was `expect_stack()` intended to take stack-order, or is this purely a docs issue?

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.