def test_dissoc():
    assert dissoc({"a": 1}, "a") == {}
    assert dissoc({"a": 1, "b": 2}, "a") == {"b": 2}
    assert dissoc({"a": 1, "b": 2}, "b") == {"a": 1}

    # Verify immutability:
    d = {"x": 1}
    oldd = d
    d2 = dissoc(d, "x")
    assert d is oldd
    assert d2 is not oldd
Esempio n. 2
0
    def test_dissoc(self):
        D, kw = self.D, self.kw
        assert dissoc(D({"a": 1}), "a") == D({})
        assert dissoc(D({"a": 1, "b": 2}), "a") == D({"b": 2})
        assert dissoc(D({"a": 1, "b": 2}), "b") == D({"a": 1})

        # Verify immutability:
        d = D({"x": 1})
        oldd = d
        d2 = dissoc(d, "x")
        assert d is oldd
        assert d2 is not oldd
    def test_dissoc(self):
        D, kw = self.D, self.kw
        assert dissoc(D({"a": 1}), "a") == D({})
        assert dissoc(D({"a": 1, "b": 2}), "a") == D({"b": 2})
        assert dissoc(D({"a": 1, "b": 2}), "b") == D({"a": 1})

        # Verify immutability:
        d = D({'x': 1})
        oldd = d
        d2 = dissoc(d, 'x')
        assert d is oldd
        assert d2 is not oldd
Esempio n. 4
0
 def run(self, *args, **kwargs):
     custom_kwargs = kwargs.get('custom_kwargs', None)
     if (custom_kwargs is not None) and (self.node_index in custom_kwargs):
         custom_cmd = custom_kwargs[self.node_index]
         orig_kwargs = dicttoolz.dissoc(kwargs, 'custom_kwargs')
         return super().run(custom_cmd, **orig_kwargs)
     return super().run(*args, **kwargs)
Esempio n. 5
0
 def __init__(self, *args, **kwargs):
     if 'node_index' not in kwargs:
         raise ValueError("init error")
     # self.node_index = kwargs['node_index']
     self.node_index = kwargs['node_index']
     orig_kwargs = dicttoolz.dissoc(kwargs, 'node_index')
     super().__init__(
         *args,
         **orig_kwargs,
     )
Esempio n. 6
0
    def test_can_estimate_gas_after_exception_raised_estimating_gas(self, eth_tester):
        self.skip_if_no_evm_execution()

        throws_address = _deploy_throws(eth_tester)
        call_will_throw_transaction = _make_call_throws_transaction(
            eth_tester,
            throws_address,
            'willThrow',
        )
        with pytest.raises(TransactionFailed):
            eth_tester.estimate_gas(dissoc(call_will_throw_transaction, 'gas'))

        call_set_value_transaction = _make_call_throws_transaction(
            eth_tester,
            throws_address,
            'setValue',
            fn_args=(2,),
        )
        gas_estimation = eth_tester.estimate_gas(dissoc(call_set_value_transaction, 'gas'))
        assert gas_estimation
Esempio n. 7
0
    def sign_transaction(self, transaction_dict: dict) -> bytes:

        # Do not include a 'to' field for contract creation.
        if transaction_dict['to'] == b'':
            transaction_dict = dissoc(transaction_dict, 'to')

        # Sign
        result = self.w3.eth.signTransaction(transaction=transaction_dict)

        # Return RLP bytes
        rlp_encoded_transaction = result.raw
        return rlp_encoded_transaction
    def test_dissoc(self):
        D, kw = self.D, self.kw
        assert dissoc(D({"a": 1}), "a", **kw) == D({})
        assert dissoc(D({"a": 1, "b": 2}), "a", **kw) == D({"b": 2})
        assert dissoc(D({"a": 1, "b": 2}), "b", **kw) == D({"a": 1})
        assert dissoc(D({"a": 1, "b": 2}), "a", "b", **kw) == D({})
        assert dissoc(D({"a": 1}), "a",
                      **kw) == dissoc(dissoc(D({"a": 1}), "a", **kw), "a",
                                      **kw)

        # Verify immutability:
        d = D({"x": 1})
        oldd = d
        d2 = dissoc(d, "x", **kw)
        assert d is oldd
        assert d2 is not oldd
Esempio n. 9
0
 def mine_blocks(self, num_blocks=1, coinbase=None):
     for _ in range(num_blocks):
         block_to_mine = dissoc(self.block, 'hash')
         block_hash = fake_rlp_hash(block_to_mine)
         mined_block = assoc(block_to_mine, 'hash', block_hash)
         assign_block_info = compose(
             partial(assoc, key='block_number',
                     value=mined_block['number']),
             partial(assoc, key='block_hash', value=mined_block['hash']),
         )
         mined_block['transactions'] = tuple(
             assign_block_info(transaction)
             for transaction in mined_block['transactions'])
         self.blocks.append(mined_block)
         self.block = make_block_from_parent(mined_block)
         yield block_hash
Esempio n. 10
0
    def sign_transaction(self, transaction_dict: dict) -> HexBytes:
        """
        Produce a raw signed ethereum transaction signed by the account specified
        in the 'from' field of the transaction dictionary.
        """

        sender = transaction_dict['from']
        signer = self.__get_signer(account=sender)

        # TODO: Handle this at a higher level?
        # Do not include a 'to' field for contract creation.
        if not transaction_dict['to']:
            transaction_dict = dissoc(transaction_dict, 'to')

        raw_transaction = signer.sign_transaction(
            transaction_dict=transaction_dict).rawTransaction
        return raw_transaction
Esempio n. 11
0
    "to": BURN_ADDRESS,
    "gas_price": NON_DEFAULT_GAS_PRICE,
    "value": 0,
    "gas": 21000,
}


TRANSACTION_WTH_NONCE = assoc(SIMPLE_TRANSACTION, 'nonce', 0)

CONTRACT_TRANSACTION_EMPTY_TO = {
    "to": '',
    "gas_price": NON_DEFAULT_GAS_PRICE,
    "value": 0,
    "gas": 100000,
}
CONTRACT_TRANSACTION_MISSING_TO = dissoc(CONTRACT_TRANSACTION_EMPTY_TO, 'to')

BLOCK_KEYS = {
    "number",
    "hash",
    "parent_hash",
    "nonce",
    "sha3_uncles",
    "logs_bloom",
    "transactions_root",
    "receipts_root",
    "state_root",
    "miner",
    "difficulty",
    "total_difficulty",
    "size",
Esempio n. 12
0
 def send_signed_transaction(self, signed_transaction):
     transaction = dissoc(signed_transaction, 'r', 's', 'v')
     return self.send_transaction(transaction)