0xMiden / 0xMiden/protocol

Unit tests for stateless procedures implemented in MASM and Rust

オープン
#1,513 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る
kernels tests
主要言語
Rust
スター
132
フォーク
167
平均マージ
1日 23時間
マージ済み PR(30日)
110

説明

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.

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。