0xMiden / 0xMiden/protocol

Unit tests for stateless procedures implemented in MASM and Rust

Đang mở
#1,513 1 bình luận 0 reaction 0 người được giao Xem trên GitHub
kernels tests
Ngôn ngữ chính
Rust
Star
132
Fork
167
Merge trung bình
1 ngày 23 giờ
Pull request đã merge (30 ngày)
110

Mô tả

We should add unit tests to make sure that the follwing procedures/functions implemented in MASM and Rust are equivalent:
- `kernel::asset_vault::build_fungible_asset_vault_key` and `FungibleAsset::vault_key`
- `kernel::asset_vault::build_non_fungible_asset_vault_key` and `NonFungibleAsset::vault_key`

These could look similar to `test_is_faucet_procedure` or `test_account_type`.

A larger question is whether we should come up with a small unit test framework that makes writing such tests very convenient, since we should be testing probably all such functionality that is implemented in MASM and Rust (e.g. every procedure in `crates/miden-lib/asm/{shared_modules, shared_utils}`). That could also simplify the above-mentioned tests to avoid reimplementing the same setup every time.

For example, a rough API could just setup the input, expected output and the MASM code under test, e.g.:

```rust
// Test cases consisting of (input, expected_output) tuples.
let test_cases = [
ACCOUNT_ID_REGULAR_PUBLIC_ACCOUNT_IMMUTABLE_CODE,
ACCOUNT_ID_REGULAR_PRIVATE_ACCOUNT_UPDATABLE_CODE,
ACCOUNT_ID_PUBLIC_FUNGIBLE_FAUCET,
ACCOUNT_ID_PRIVATE_NON_FUNGIBLE_FAUCET,
]
.map(|id| {
let id = AccountId::try_from(id).unwrap();
(id.prefix().as_felt(), id.is_faucet())
});

let code = "
use.kernel::account_id

begin
exec.account_id::is_faucet
# => [is_faucet, account_id_prefix]

# truncate the stack
swap drop
end";

// This would place the account ID on the stack, and assert that the stack output from MASM matches the expected output passed in test cases.
MasmUnitTests::execute(code, test_cases)?;
```

The exact API needs to be figured out. If it is more convenient to add test cases in builder-style, then we should do that instead or offer alternatives.

So I would say the task here is to:
- Investigate if there are enough procedures/functions that are shared across MASM and Rust that could be tested in this way (stateless functions).
- If so, add a unit test framework as above and rewrite the mentioned tests to use it.
- If not, add tests for the vault key procedures.

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.