0xMiden / 0xMiden/miden-vm

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

Ouverte
#2,021 3 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
processor
Langage dominant
Rust
Étoiles
772
Forks
352
Merge moyen
1 j 12 h
PR mergées (30 j)
93

Description

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?

Guide de contribution

Ouvrir le guide de contribution

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.