Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
asanso committed Feb 29, 2024
1 parent f95c16d commit ab81330
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ab81330

Please sign in to comment.