iroha icon indicating copy to clipboard operation
iroha copied to clipboard

[test] Add integration tests for `Perdicate`

Open Arjentix opened this issue 2 years ago • 0 comments

Right now we have some union tests for Predicate. We also need some integrations tests. This will be helpful to ensure the whole system with predicate works and also that would be an example for our SDK developers.

Examples of test cases

  • Find all assets with specific value in specific key in metadata
  • Find all accounts which have a key in metadata and which account name starts with some specific string
  • Something with or
  • You got the idea

Origin problem

@arndey says, that this test from Java SDK is not working:

@Test
@WithIroha(StoreAssetWithMetadata::class)
fun `find asset by metadata filters`(): Unit = runBlocking {
    val filter = PredicateBox.Raw(
        Predicate.Container(
            Container.ValueOfKey(
                ValueOfKey(
                    StoreAssetWithMetadata.ASSET_KEY,
                    Predicate.Identifiable(
                        jp.co.soramitsu.iroha2.generated.datamodel.predicate.string.Predicate.Is(
                            StoreAssetWithMetadata.ASSET_VALUE.string
                        )
                    )
                )
            )
        )
    )
    QueryBuilder.findAllAssets(filter)
        .account(ALICE_ACCOUNT_ID)
        .buildSigned(ALICE_KEYPAIR)
        .let { query ->
            client.sendQuery(query)
        }.also {
            assert(it.isNotEmpty())
        }
}

And it returns just empty list of assets.

genesis.json
{
  "transactions" : [ {
    "isi" : [ {
      "Register" : {
        "object" : {
          "Raw" : {
            "Identifiable" : {
              "NewDomain" : {
                "id" : {
                  "name" : "wonderland"
                },
                "logo" : null,
                "metadata" : { }
              }
            }
          }
        }
      }
    }, {
      "Register" : {
        "object" : {
          "Raw" : {
            "Identifiable" : {
              "NewAccount" : {
                "id" : {
                  "name" : "alice",
                  "domain_id" : {
                    "name" : "wonderland"
                  }
                },
                "signatories" : [ "ed01207944db0dce6eb51367b750c96154ba0b7d22bd7a7c63feb3029743a7b566db5c" ],
                "metadata" : { }
              }
            }
          }
        }
      }
    }, {
      "Register" : {
        "object" : {
          "Raw" : {
            "Identifiable" : {
              "NewAccount" : {
                "id" : {
                  "name" : "bob",
                  "domain_id" : {
                    "name" : "wonderland"
                  }
                },
                "signatories" : [ "ed01201c0dfd8f67cdaf890ef3fbfa4aa07aecbcf91fd91e4f97ea76cb7cff59f5f567" ],
                "metadata" : { }
              }
            }
          }
        }
      }
    }, {
      "Register" : {
        "object" : {
          "Raw" : {
            "Identifiable" : {
              "NewAssetDefinition" : {
                "id" : {
                  "name" : "foo",
                  "domain_id" : {
                    "name" : "wonderland"
                  }
                },
                "value_type" : "Store",
                "mintable" : "Infinitely",
                "metadata" : {
                  "key" : {
                    "String" : "value"
                  }
                }
              }
            }
          }
        }
      }
    }, {
      "SetKeyValue" : {
        "object_id" : {
          "Raw" : {
            "Id" : {
              "AssetId" : {
                "definition_id" : {
                  "name" : "foo",
                  "domain_id" : {
                    "name" : "wonderland"
                  }
                },
                "account_id" : {
                  "name" : "alice",
                  "domain_id" : {
                    "name" : "wonderland"
                  }
                }
              }
            }
          }
        },
        "key" : {
          "Raw" : {
            "Name" : "key"
          }
        },
        "value" : {
          "Raw" : {
            "String" : "value"
          }
        }
      }
    } ]
  } ]
}

Arjentix avatar Sep 05 '22 12:09 Arjentix