0xMiden / 0xMiden/protocol

Unit tests for stateless procedures implemented in MASM and Rust

Offen
#1,513 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
kernels tests
Vorherrschende Sprache
Rust
Sterne
132
Forks
167
Ø Merge
1 T. 23 Std.
Gemergte PRs (30 T.)
110

Beschreibung

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.

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.