From bad3019490fd9376686046b2638da8b310fdeab6 Mon Sep 17 00:00:00 2001 From: Ignacio Hagopian Date: Sun, 17 Dec 2023 18:29:14 -0300 Subject: [PATCH] add more test cases Signed-off-by: Ignacio Hagopian --- src/stealth_address.zig | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/stealth_address.zig b/src/stealth_address.zig index da63a8b..ac7cf44 100644 --- a/src/stealth_address.zig +++ b/src/stealth_address.zig @@ -105,4 +105,25 @@ test "generate and check" { const ok = try EIP5564.checkStealthAddress(ga.stealth_address, ga.ephemeral_pubkey, viewing_key, spending_pubkey, null); try std.testing.expect(ok); } + + // Check with wrong tag + { + const ok = try EIP5564.checkStealthAddress(ga.stealth_address, ga.ephemeral_pubkey, viewing_key, spending_pubkey, ga.view_tag +% 1); + try std.testing.expect(!ok); + } + + // Check with wrong spending pubkey + { + const wrong_spending_pubkey = try EIP5564.pubKeyFromHex("02706c71da3dd07932cd4a3c748a744f262db6a16de4df5bee58de0d03acba1260"); + const ok = try EIP5564.checkStealthAddress(ga.stealth_address, ga.ephemeral_pubkey, viewing_key, wrong_spending_pubkey, ga.view_tag +% 1); + try std.testing.expect(!ok); + } + + // Check with wrong viewing key + { + var wrong_viewing_key: Privkey = undefined; + _ = try std.fmt.hexToBytes(&wrong_viewing_key, "cc3dc00a8a9fbd1093a43282fe7c865b64cdbfd5a8350d1432a188f0504a6700"); + const ok = try EIP5564.checkStealthAddress(ga.stealth_address, ga.ephemeral_pubkey, wrong_viewing_key, spending_pubkey, ga.view_tag +% 1); + try std.testing.expect(!ok); + } }