0xMiden / 0xMiden/miden-vm

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

Đang mở
#2,021 3 bình luận 0 reaction 0 người được giao Xem trên GitHub
processor
Ngôn ngữ chính
Rust
Star
772
Fork
352
Merge trung bình
1 ngày 12 giờ
Pull request đã merge (30 ngày)
93

Mô tả

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?

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.