Example #1
0
def sign_txs(ipc_path, unsigned_file, signed_file):
    web3 = Web3(IPCProvider(ipc_path))
    signer = Signer(web3)

    unsigned = json.loads(unsigned_file.read())

    signed = signer.sign_transactions(unsigned)

    signed_file.write(json.dumps(signed))
def test_small_flow(web3, prepared_contracts, creator, airdrops):
    _, omg_token = prepared_contracts

    transactions = creator.create_txs(airdrops, BATCH_SIZE)
    signed = Signer(web3).sign_transactions(transactions)
    Sender(web3).send_transactions(signed, transactions)

    check_entirely_airdropped(airdrops, omg_token)
Example #3
0
async def contract_factory(
) -> Tuple[Starknet, Account, Account, StarknetContract]:
    starknet = await Starknet.empty()
    some_signer = Signer(private_key=12345)
    owner_account = Account(
        signer=some_signer,
        contract=await
        starknet.deploy("contracts/Account.cairo",
                        constructor_calldata=[some_signer.public_key]),
    )
    some_other_signer = Signer(private_key=123456789)
    signer_account = Account(
        signer=some_other_signer,
        contract=await starknet.deploy(
            "contracts/Account.cairo",
            constructor_calldata=[some_other_signer.public_key],
        ),
    )
    contract = await starknet.deploy("contracts/contract.cairo")
    return starknet, owner_account, signer_account, contract
def test_entire_flow(web3, prepared_contracts, creator, input_file):

    airdropper, omg_token = prepared_contracts
    airdrops = process(input_file.read())
    transactions = creator.create_txs(airdrops, BATCH_SIZE)

    # this being a long-running test, the unlocking from web3 fixture might have expired
    web3.personal.unlockAccount(web3.eth.accounts[0], "")

    signed = Signer(web3).sign_transactions(transactions)
    Sender(web3).send_transactions(signed, transactions)

    check_entirely_airdropped(airdrops, omg_token)
def test_secondary_oog_protection(web3, transactions, mocker):
    """
    "Do we halt the sending when an oog occurs?" - continued.
    Check the secondary, double-checking protection
    """

    transactions[0]['tx']['gas'] = web3.toHex(transactions[0]['gasEstimate'] -
                                              1)

    signed = Signer(web3).sign_transactions(transactions)

    # check the secondary OOG-detection measure, by tricking the primary
    mocker.patch('utils.Sender._did_oog')
    Sender._did_oog.side_effect = [False, False]

    with pytest.raises(AirdropOOGException):
        Sender(web3).send_transactions(signed, transactions)
def test_throw_in_contract_handling(web3, prepared_contracts, transactions,
                                    airdrops):
    _, omg_token = prepared_contracts

    # whoops, omg_token got paused! omg_token should throw now
    pause_tx_hash = omg_token.transact().pause()
    Wait(web3).for_receipt(pause_tx_hash)

    # need to bump nonce in the pre-prepared transactions
    for transaction in transactions:
        transaction['tx']['nonce'] = web3.toHex(
            web3.toDecimal(transaction['tx']['nonce']) + 1)
    signed = Signer(web3).sign_transactions(transactions)

    with pytest.raises(AirdropOOGException):
        Sender(web3).send_transactions(signed, transactions)

    check_none_airdropped(airdrops, omg_token)
def test_oog_handling(web3, prepared_contracts, transactions, airdrops):
    """
    Do we halt the sending when an oog occurs?
    """
    _, omg_token = prepared_contracts

    transactions[0]['tx']['gas'] = web3.toHex(transactions[0]['gasEstimate'] -
                                              1)

    signed = Signer(web3).sign_transactions(transactions)

    with pytest.raises(AirdropOOGException):
        Sender(web3).send_transactions(signed, transactions)

    check_none_airdropped(airdrops, omg_token)

    # check recovery works with OOG
    unsent, unsent_unsigned = Sender(web3).recover_unsent(signed, transactions)

    assert unsent == signed
    assert unsent_unsigned == transactions
def test_recover_sent_airdrops(web3, prepared_contracts, transactions, signed,
                               airdrops, creator):
    """
    Assuming partially sent airdrops, when there's need to sign transactions again
    e.g. when it turned out that too little gas was allowed (unlikely)
    """
    airdropper, omg_token = prepared_contracts

    Sender(web3).send_transactions(signed[:1], transactions[:1])

    # airdrop partially done by now
    check_entirely_airdropped(airdrops[0:BATCH_SIZE], omg_token)

    not_airdropped = Sender(web3).recover_unsent_airdrops(
        airdrops, signed, airdropper, omg_token)

    assert not_airdropped == airdrops[BATCH_SIZE:]

    unsigned = creator.create_txs(not_airdropped, BATCH_SIZE)
    new_signed = Signer(web3).sign_transactions(unsigned)
    Sender(web3).send_transactions(new_signed, unsigned)

    check_entirely_airdropped(airdrops, omg_token)
def signed(web3, transactions):

    signed = Signer(web3).sign_transactions(transactions)

    return signed