0xMiden / 0xMiden/miden-vm

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

未關閉
#2,021 3 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
processor
主要語言
Rust
星號
772
分支
352
平均合併
1 天 12 小時
30 天內合併 PR
93

描述

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?

貢獻指南

開啟貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。