from bsvlib.curve import multiply, curve, Point, get_y, negative, add


def test():
    x = 0xe46dcd7991e5a4bd642739249b0158312e1aee56a60fd1bf622172ffe65bd789
    y = 0x97693d32c540ac253de7a3dc73f7e4ba7b38d2dc1ecc8e07920b496fb107d6b2
    p = Point(x, y)
    k = 0xf97c89aaacf0cd2e47ddbacc97dae1f88bec49106ac37716c451dcdd008a4b62

    g1 = Point(55066263022277343669578718895168534326250603453777594175500187360389116729240, 32670510020758816978083085130507043184471273380659243275938904335757337482424)
    g2 = Point(89565891926547004231252920425935692360644145829622209833684329913297188986597, 12158399299693830322967808612713398636155367887041628176798871954788371653930)
    g3 = Point(112711660439710606056748659173929673102114977341539408544630613555209775888121, 25583027980570883691656905877401976406448868254816295069919888960541586679410)
    g4 = Point(103388573995635080359749164254216598308788835304023601477803095234286494993683, 37057141145242123013015316630864329550140216928701153669873286428255828810018)
    r1 = Point(100666224722128857877725132532851949379802638616061419771233214330904298948965, 109582988301176589913370948512862386300180118579134964097462248199136488857646)
    r2 = Point(79076260692846752391569703858363112673457446919766350529110439023260379142781, 80223355407093911427572368727420817372404365964787981522070684657120243838069)
    r3 = Point(8608450666449670453100774944540474352109761940651728396172551748859656634656, 74056111031787015858238629897522379780728368232392890506333118900966757162026)
    r4 = Point(35815522524173952099259385326353790050561276039469228673834850433731629527147, 106058046035730461065453431298488283639544320945863068991044987913936484863297)

    assert y == get_y(x, y % 2 == 0)

    assert negative(None) is None

    assert add(p, None) == p
    assert add(None, p) == p
    assert add(p, negative(p)) is None

    assert add(g1, p) == r1
    assert add(g2, p) == r2
    assert add(g3, p) == r3
    assert add(g4, p) == r4

    assert multiply(k, curve.g) == p
    assert multiply(0, curve.g) is None
    assert multiply(1, None) is None
    assert multiply(-k, negative(curve.g)) == Point(x, y)

    assert multiply(1, curve.g) == g1
    assert multiply(2, curve.g) == g2
    assert multiply(3, curve.g) == g3
    assert multiply(4, curve.g) == g4

from bsvlib.curve import multiply, curve, Point, get_y, negative, add


def test():
    x = 0xe46dcd7991e5a4bd642739249b0158312e1aee56a60fd1bf622172ffe65bd789
    y = 0x97693d32c540ac253de7a3dc73f7e4ba7b38d2dc1ecc8e07920b496fb107d6b2
    p = Point(x, y)
    k = 0xf97c89aaacf0cd2e47ddbacc97dae1f88bec49106ac37716c451dcdd008a4b62

    g1 = Point(55066263022277343669578718895168534326250603453777594175500187360389116729240, 32670510020758816978083085130507043184471273380659243275938904335757337482424)
    g2 = Point(89565891926547004231252920425935692360644145829622209833684329913297188986597, 12158399299693830322967808612713398636155367887041628176798871954788371653930)
    g3 = Point(112711660439710606056748659173929673102114977341539408544630613555209775888121, 25583027980570883691656905877401976406448868254816295069919888960541586679410)
    g4 = Point(103388573995635080359749164254216598308788835304023601477803095234286494993683, 37057141145242123013015316630864329550140216928701153669873286428255828810018)
    r1 = Point(100666224722128857877725132532851949379802638616061419771233214330904298948965, 109582988301176589913370948512862386300180118579134964097462248199136488857646)
    r2 = Point(79076260692846752391569703858363112673457446919766350529110439023260379142781, 80223355407093911427572368727420817372404365964787981522070684657120243838069)
    r3 = Point(8608450666449670453100774944540474352109761940651728396172551748859656634656, 74056111031787015858238629897522379780728368232392890506333118900966757162026)
    r4 = Point(35815522524173952099259385326353790050561276039469228673834850433731629527147, 106058046035730461065453431298488283639544320945863068991044987913936484863297)

    assert y == get_y(x, y % 2 == 0)

    assert negative(None) is None

    assert add(p, None) == p
    assert add(None, p) == p
    assert add(p, negative(p)) is None

    assert add(g1, p) == r1
    assert add(g2, p) == r2
    assert add(g3, p) == r3
    assert add(g4, p) == r4

    assert multiply(k, curve.g) == p
    assert multiply(0, curve.g) is None
    assert multiply(1, None) is None
    assert multiply(-k, negative(curve.g)) == Point(x, y)

    assert multiply(1, curve.g) == g1
    assert multiply(2, curve.g) == g2
    assert multiply(3, curve.g) == g3
    assert multiply(4, curve.g) == g4
