示例#1
0
def test_game_doesnt_exist(contract, owner, user):
    key = owner.key
    address = contract.address
    game_id = contract.game_id
    sig = sign_score(key, address, game_id, user.address, SCORE)
    vrs = (sig['v'], sig['r'], sig['s'])
    receipt = contract.claim_highscore(SCORE, vrs, from_addr=user)
    assert receipt['status'] == 0
 def sign(self, key, score):
     vrs = sign_score(
         key,
         self.contract.address,
         self.contract.game_id,
         self.player,
         score,
     )
     return vrs
示例#3
0
def test_user_is_not_signed_user(contract, owner, user, user2):
    contract.add_game(PRICE, PERCENT_FEE, from_addr=owner)
    contract.pay(PAYMENT_CODE, value=PRICE, from_addr=user)
    key = owner.key
    address = contract.address
    game_id = contract.game_id
    sig = sign_score(key, address, game_id, user2.address, SCORE)
    vrs = (sig['v'], sig['r'], sig['s'])
    receipt = contract.claim_highscore(SCORE, vrs, from_addr=user)
    assert receipt['status'] == 0
示例#4
0
def test_score_too_low(contract, owner, user):
    contract.add_game(PRICE, PERCENT_FEE, from_addr=owner)
    contract.pay(PAYMENT_CODE, value=PRICE, from_addr=user)
    low_score = 0
    key = owner.key
    address = contract.address
    game_id = contract.game_id
    sig = sign_score(key, address, game_id, user.address, low_score)
    vrs = (sig['v'], sig['r'], sig['s'])
    receipt = contract.claim_highscore(low_score, vrs, from_addr=user)
    assert receipt['status'] == 0
示例#5
0
def test_uploads_wrong_score(web3, contract, owner, user):
    contract.add_game(PRICE, PERCENT_FEE, from_addr=owner)
    contract.pay(PAYMENT_CODE, value=PRICE, from_addr=user)
    key = owner.key
    address = contract.address
    game_id = contract.game_id
    sig = sign_score(key, address, game_id, user.address, SCORE)
    vrs = (sig['v'], sig['r'], sig['s'])
    bad_score = SCORE + 1
    receipt = contract.claim_highscore(bad_score, vrs, from_addr=user)
    assert receipt['status'] == 0
示例#6
0
def test_jackpot(contract, owner, user):
    contract.add_game(PRICE, PERCENT_FEE, from_addr=owner)
    contract.pay(PAYMENT_CODE, value=PRICE, from_addr=user)
    expected_jackpot = 0
    key = owner.key
    address = contract.address
    game_id = contract.game_id
    sig = sign_score(key, address, game_id, user.address, SCORE)
    vrs = (sig['v'], sig['r'], sig['s'])
    receipt = contract.claim_highscore(SCORE, vrs, from_addr=user)
    assert receipt['status'] == 1
    jackpot = contract.get_jackpot()
    assert jackpot == expected_jackpot
示例#7
0
def test_owner_gets_paid_fee(web3, contract, owner, user):
    contract.add_game(PRICE, PERCENT_FEE, from_addr=owner)
    contract.pay(PAYMENT_CODE, value=PRICE, from_addr=user)

    jackpot = contract.get_jackpot()
    fee = jackpot * PERCENT_FEE // 100
    expected_balance = web3.eth.getBalance(owner.address) + fee
    key = owner.key
    address = contract.address
    game_id = contract.game_id
    sig = sign_score(key, address, game_id, user.address, SCORE)
    vrs = (sig['v'], sig['r'], sig['s'])
    receipt = contract.claim_highscore(SCORE, vrs, from_addr=user)
    assert receipt['status'] == 1
    balance = web3.eth.getBalance(owner.address)
    assert balance == expected_balance
示例#8
0
def test_game_id_doesnt_match_arcade_signer(contract, owner, user):
    contract.add_game(PRICE, PERCENT_FEE, from_addr=owner)
    contract.pay(PAYMENT_CODE, value=PRICE, from_addr=user)
    wrong_game_id = '0xf7ba25e4cb13d1cac1dffb5044ac9001438eb1251b07a484fbe3428bc825099b'  # noqa: E501
    key = owner.key
    address = contract.address
    game_id = contract.game_id
    sig = sign_score(key, address, game_id, user.address, SCORE)
    vrs = (sig['v'], sig['r'], sig['s'])
    contract.game_id = wrong_game_id
    receipt = contract.claim_highscore(
        SCORE,
        vrs,
        from_addr=user,
    )
    assert receipt['status'] == 0
示例#9
0
def test_user_balance(web3, contract, owner, user):
    contract.add_game(PRICE, PERCENT_FEE, from_addr=owner)
    contract.pay(PAYMENT_CODE, value=PRICE, from_addr=user)

    initial_balance = web3.eth.getBalance(user.address)
    jackpot = contract.get_jackpot()
    fee = jackpot * PERCENT_FEE // 100
    key = owner.key
    address = contract.address
    game_id = contract.game_id
    sig = sign_score(key, address, game_id, user.address, SCORE)
    vrs = (sig['v'], sig['r'], sig['s'])
    receipt = contract.claim_highscore(SCORE, vrs, from_addr=user)
    assert receipt['status'] == 1
    gas_cost = receipt['gasPrice'] * receipt['gasUsed']
    expected_balance = initial_balance + jackpot - gas_cost - fee
    balance = web3.eth.getBalance(user.address)
    assert balance == expected_balance
示例#10
0
def test_sign_score(user, owner, monkeypatch):
    expected_signer = owner.address
    sig = sign_score(owner.key, CONTRACT, GAME_ID, user.address, SCORE)
    types = ['bytes32', 'address', 'uint256']
    values = [
        HexBytes(GAME_ID),
        user.address,
        SCORE,
    ]
    encoded_values = encode_abi_packed(types, values)
    message = encode_intended_validator(
        validator_address=CONTRACT,
        primitive=encoded_values,
    )
    vrs = (sig['v'], sig['r'], sig['s'])
    actual_signer = Account.recover_message(
        message,
        vrs=vrs,
    )

    assert actual_signer == expected_signer