How to test/verify the icrc3_get_tip_certificate() method?

for now this is my implementation:

stable var tip_cert = MerkleTree.empty();
func updateTipCert() = CertifiedData.set(MerkleTree.treeHash(tip_cert));
system func postupgrade() = updateTipCert();

// whenever there's a new block
// ...
tip_cert := MerkleTree.empty();
tip_cert := MerkleTree.put(tip_cert, [Text.encodeUtf8(Constants.LAST_BLOCK_INDEX)], block_id);
tip_cert := MerkleTree.put(tip_cert, [Text.encodeUtf8(Constants.LAST_BLOCK_HASH)], block_hash);
updateTipCert();

// getting the tip cert
public shared query func icrc3_get_tip_certificate() : async ?Types.DataCertificate {
  let certificate = switch (CertifiedData.getCertificate()) {
    case (?found) found;
    case _ return null;
  };
  let index_witness = MerkleTree.reveal(tip_cert, [Text.encodeUtf8(Constants.LAST_BLOCK_INDEX)]);
  let hash_witness = MerkleTree.reveal(tip_cert, [Text.encodeUtf8(Constants.LAST_BLOCK_HASH)]);
  let merge = MerkleTree.merge(index_witness, hash_witness);
  let witness = MerkleTree.encodeWitness(merge); // CBOR encoded
  return ?{ certificate; hash_tree = witness };
};

(did i miss anything important that i should add to my implementation? if so, pls let me know)

As for the hash_tree, since it’s CBOR encoded, I decoded it and it returned me this;


not sure how to make sense from that. I want to get the last_block_id and last_block_hash to validate all blocks, but I dont know how to start.

and as for certificate, how do I verify it? or this is too low-level for me?

in case you’re wondering about system func postupgrade() = updateTipCert();, it’s something i picked up from @nomeata 's Certified Asset tutorial:

I have some tests here: icrc3.mo/testActor/test_runner.mo at df223cdd9b3802e7504299edca166c72e6b2bc47 · PanIndustrial-Org/icrc3.mo · GitHub

Of course they assume that the underlying repindyhash module is correct x if you come up with any bright ideas, let me know as I’d love to add the tests here as well.