Exemple #1
0
def test_signing_with_key_and_rpc_should_return_same_result():
    # given
    web3 = Web3(HTTPProvider("http://localhost:8555"))
    web3.eth.defaultAccount = web3.eth.accounts[0]

    assert Address(web3.eth.defaultAccount) == Address(
        '0x9596c16d7bf9323265c2f2e22f43e6c80eb3d943')

    # and
    text = "abc"
    msg = bytes(text, 'utf-8')

    rpc_signature = eth_sign(msg, web3)

    # when
    keyfile_path = pkg_resources.resource_filename(
        __name__, "accounts/0_0x9596c16d7bf9323265c2f2e22f43e6c80eb3d943.json")
    passfile_path = pkg_resources.resource_filename(__name__, "accounts/pass")

    register_key_file(web3, keyfile_path, passfile_path)

    # and
    # [we do this in order to make sure that the message was signed using the local key]
    # [with `request_blocking` set to `None` any http requests will basically fail]
    web3.manager.request_blocking = None

    # and
    local_signature = eth_sign(msg, web3)

    # then
    assert rpc_signature == local_signature
Exemple #2
0
 def _check_account_unlocked(self):
     try:
         eth_sign(bytes("pyflex testing if account is unlocked", "utf-8"),
                  self.web3)
     except:
         self.logger.exception(
             f"Account {self.web3.eth.defaultAccount} is not unlocked and no private key supplied for it"
         )
         self.logger.fatal(
             f"Unlocking the account or providing the private key is necessary for the keeper to operate"
         )
         exit(-1)
Exemple #3
0
def test_signing():
    # given
    web3 = Web3(HTTPProvider("http://localhost:8555"))
    web3.eth.defaultAccount = web3.eth.accounts[0]

    # and
    text = "abc"
    msg = bytes(text, 'utf-8')

    # expect
    assert eth_sign(msg, web3).startswith("0x")
Exemple #4
0
    def sign_order(self, order: Order) -> Order:
        """Signs an order so it can be submitted to the relayer.

        Order will be signed by the `web3.eth.defaultAccount` account.

        Args:
            order: Order you want to sign.

        Returns:
            Signed order. Copy of the order passed as a parameter with the `signature` field filled with signature.
        """
        assert (isinstance(order, Order))

        signature = eth_sign(hexstring_to_bytes(self.get_order_hash(order)),
                             self.web3)
        v, r, s = to_vrs(signature)

        signed_order = copy.copy(order)
        signed_order.signature = bytes_to_hexstring(bytes([v])) + \
                                 bytes_to_hexstring(r)[2:] + \
                                 bytes_to_hexstring(s)[2:] + \
                                 "03"  # EthSign
        return signed_order