From ab81330f13266a3801911d3e55c76ca03137807b Mon Sep 17 00:00:00 2001 From: Antonio Sanso Date: Thu, 29 Feb 2024 09:51:02 +0100 Subject: [PATCH] add tests --- main.py | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/main.py b/main.py index 2cffe15..9b43fbb 100644 --- a/main.py +++ b/main.py @@ -100,45 +100,45 @@ def expect_exception(func, *args): def case01_add_G1(): # Commutativity - result1 = add(G1,P1) - result2 = add(P1,G1) - assert result1 == result2 - yield f'add_G1_bls_g1_plus_p1', [{ + result_comm1 = add(G1,P1) + result_comm2 = add(P1,G1) + assert result_comm1 == result_comm2 + # Doubling + result_doubling_G1 = add(G1,G1) + assert result_doubling_G1 == multiply(G1,2) + result_doubling_P1 = add(P1,P1) + assert result_doubling_P1 == multiply(P1,2) + + yield f'add_G1_bls', [ + { "Input": int_to_hex(int(G1[0]),64)+(int_to_hex(int(G1[1]),64))+int_to_hex(int(P1[0]),64)+(int_to_hex(int(P1[1]),64)), "Name": "bls_g1add_g1+p1", - "Expected": int_to_hex(int(result1[0]),64)+(int_to_hex(int(result1[1]),64)), + "Expected": int_to_hex(int(result_comm1[0]),64)+(int_to_hex(int(result_comm1[1]),64)), "Gas": BLS12_G1ADD_GAS, "NoBenchmark": False - }] - - yield f'add_G1_bls_p1_plus_g1', [{ + }, + { "Input": int_to_hex(int(P1[0]),64)+(int_to_hex(int(P1[1]),64))+int_to_hex(int(G1[0]),64)+(int_to_hex(int(G1[1]),64)), "Name": "bls_g1add_p1+g1", - "Expected": int_to_hex(int(result1[0]),64)+(int_to_hex(int(result1[1]),64)), + "Expected": int_to_hex(int(result_comm2[0]),64)+(int_to_hex(int(result_comm2[1]),64)), "Gas": BLS12_G1ADD_GAS, "NoBenchmark": False - }] - - # Doubling - result = add(G1,G1) - assert result == multiply(G1,2) - yield f'add_G1_bls_g1_twice', [{ + }, + { "Input": int_to_hex(int(G1[0]),64)+(int_to_hex(int(G1[1]),64))+int_to_hex(int(G1[0]),64)+(int_to_hex(int(G1[1]),64)), "Name": "bls_g1add_(g1+g1=2*g1)", - "Expected": int_to_hex(int(result[0]),64)+(int_to_hex(int(result[1]),64)), + "Expected": int_to_hex(int(result_doubling_G1[0]),64)+(int_to_hex(int(result_doubling_G1[1]),64)), "Gas": BLS12_G1ADD_GAS, "NoBenchmark": False - }] - - result = add(P1,P1) - assert result == multiply(P1,2) - yield f'add_G1_bls_p1_twice', [{ + }, + { "Input": int_to_hex(int(P1[0]),64)+(int_to_hex(int(P1[1]),64))+int_to_hex(int(P1[0]),64)+(int_to_hex(int(P1[1]),64)), "Name": "bls_p[1add_(p1+p1=2*p1)", - "Expected": int_to_hex(int(result[0]),64)+(int_to_hex(int(result[1]),64)), + "Expected": int_to_hex(int(result_doubling_P1[0]),64)+(int_to_hex(int(result_doubling_P1[1]),64)), "Gas": BLS12_G1ADD_GAS, "NoBenchmark": False - }] + } + ] # Credit # test vectors taken from