Skip to content

Commit

Permalink
test(icrc_ledger): FI-1399: Add an InMemoryLedger for verifying ICRC …
Browse files Browse the repository at this point in the history
…ledger state (#719)

Add an `InMemoryLedger` that creates an expected ICRC ledger state based
on blocks retrieved from a deployed ICRC ledger and archive(s). Provide
a `verify_ledger_state` helper function that takes a `StateMachine` and
the ledger `CanisterId`, and retrieves the blocks from the ledger and
its archive(s), reconstructs the expected ledger state wrt. account
balances and allowances, and verifies that the balances and allowances
on the deployed ledger matches those of the `InMemoryLedger`.
  • Loading branch information
mbjorkqvist authored Aug 3, 2024
1 parent 87f1ea3 commit 99813d3
Show file tree
Hide file tree
Showing 6 changed files with 980 additions and 35 deletions.
87 changes: 56 additions & 31 deletions rs/rosetta-api/icrc1/ledger/sm-tests/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,7 +1,39 @@
load("@rules_rust//rust:defs.bzl", "rust_library")
load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test")

package(default_visibility = ["//visibility:public"])

DEPENDENCIES = [
# Keep sorted.
"//packages/ic-ledger-hash-of:ic_ledger_hash_of",
"//packages/icrc-ledger-types:icrc_ledger_types",
"//rs/rosetta-api/icrc1",
"//rs/rosetta-api/icrc1/ledger",
"//rs/rosetta-api/ledger_canister_core",
"//rs/rosetta-api/ledger_core",
"//rs/rust_canisters/http_types",
"//rs/state_machine_tests",
"//rs/types/base_types",
"//rs/types/error_types",
"//rs/types/management_canister_types",
"//rs/types/types",
"//rs/universal_canister/lib",
"@crate_index//:anyhow",
"@crate_index//:candid",
"@crate_index//:cddl",
"@crate_index//:futures",
"@crate_index//:hex",
"@crate_index//:icrc1-test-env",
"@crate_index//:icrc1-test-suite",
"@crate_index//:num-traits",
"@crate_index//:proptest",
"@crate_index//:serde",
]

MACRO_DEPENDENCIES = [
# Keep sorted.
"@crate_index//:async-trait",
]

[
rust_library(
name = "sm-tests" + name_suffix,
Expand All @@ -14,37 +46,30 @@ package(default_visibility = ["//visibility:public"])
data = [
"//rs/rosetta-api/icrc1/ledger:block.cddl",
],
proc_macro_deps = [
# Keep sorted.
"@crate_index//:async-trait",
],
proc_macro_deps = MACRO_DEPENDENCIES,
version = "0.9.0",
deps = [
# Keep sorted.
"//packages/ic-ledger-hash-of:ic_ledger_hash_of",
"//packages/icrc-ledger-types:icrc_ledger_types",
"//rs/rosetta-api/icrc1",
"//rs/rosetta-api/icrc1/ledger",
"//rs/rosetta-api/ledger_canister_core",
"//rs/rosetta-api/ledger_core",
"//rs/rust_canisters/http_types",
"//rs/state_machine_tests",
"//rs/types/base_types",
"//rs/types/error_types",
"//rs/types/management_canister_types",
"//rs/types/types",
"//rs/universal_canister/lib",
"@crate_index//:anyhow",
"@crate_index//:candid",
"@crate_index//:cddl",
"@crate_index//:futures",
"@crate_index//:hex",
"@crate_index//:icrc1-test-env",
"@crate_index//:icrc1-test-suite",
"@crate_index//:num-traits",
"@crate_index//:proptest",
"@crate_index//:serde",
] + extra_deps,
deps = DEPENDENCIES + extra_deps,
)
for (name_suffix, features, extra_deps) in [
(
"",
[],
["//rs/rosetta-api/icrc1/tokens_u64"],
),
(
"_u256",
["u256-tokens"],
["//rs/rosetta-api/icrc1/tokens_u256"],
),
]
]

[
rust_test(
name = "sm-tests-unit-tests" + name_suffix,
crate = ":sm-tests" + name_suffix,
crate_features = features,
deps = DEPENDENCIES + extra_deps,
)
for (name_suffix, features, extra_deps) in [
(
Expand Down
Loading

0 comments on commit 99813d3

Please sign in to comment.