hyperledger-iroha / iroha

Iroha - A simple, enterprise-grade decentralized ledger
https://wiki.hyperledger.org/display/iroha
Apache License 2.0
438 stars 280 forks source link

iroha_schema: `no_extra_or_missing_schemas` test gives misleading message when `Box<...>` type is missing from `types!` #5041

Closed DCNick3 closed 1 month ago

DCNick3 commented 1 month ago

How to reproduce:

  1. Remove Box<CompoundPredicate<AccountPredicateBox>> from the types! macro in schema/gen/lib.rs
  2. Run tests::no_extra_or_missing_schemas test in iroha_schema_gen
  3. Observe the error message:
Missing types: {
    (
        "CompoundPredicate<AccountPredicateBox>",
        Enum(
            EnumMeta {
                variants: [
                    EnumVariant {
                        tag: "Atom",
                        discriminant: 0,
                        ty: Some(
                            TypeId {
                                t: (
                                    10095233817367655734,
                                    3465063886364562919,
                                ),
                            },
                        ),
                    },
                    EnumVariant {
                        tag: "Not",
                        discriminant: 1,
                        ty: Some(
                            TypeId {
                                t: (
                                    14448333017410507765,
                                    1039736120081770805,
                                ),
                            },
                        ),
                    },
                    EnumVariant {
                        tag: "And",
                        discriminant: 2,
                        ty: Some(
                            TypeId {
                                t: (
                                    13976757441058666220,
                                    14378548965820588092,
                                ),
                            },
                        ),
                    },
                    EnumVariant {
                        tag: "Or",
                        discriminant: 3,
                        ty: Some(
                            TypeId {
                                t: (
                                    13976757441058666220,
                                    14378548965820588092,
                                ),
                            },
                        ),
                    },
                ],
            },
        ),
    ),
}

This error message is confusing, because it references CompoundPredicate<AccountPredicateBox> which is, in fact included in the types! invocation. The problem is that the type map from build_schemas() actually distinguishes between Boxed and non-Boxed types, while our schema JSON doesn't (and, therefore, those are assigned the same string-based type id).

I see two possible solutions:

  1. If we want to enforce the presence of Boxed types in the schema, we should improve the test to actually track the original rust type names.
  2. If we don't need to Box copies, make the build_schemas() map based on the string identifiers, not rust TypeIds