def fill_state_test(filler: Dict[str, Any]) -> Dict[str, Dict[str, Any]]: """ Filler function for filling state tests. """ test_name = get_test_name(filler) test = filler[test_name] environment = normalize_environment(test["env"]) pre_state = normalize_state(test["pre"]) transaction_group = normalize_transaction_group(test["transaction"]) post = defaultdict(list) # type: Dict[int, List[Dict[str, str]]] for expect in test["expect"]: indexes = expect["indexes"] networks = normalize_networks(expect["networks"]) result = normalize_state(expect["result"]) post_state = deep_merge(pre_state, result) for network in networks: state_class = STATE_CLASSES[network] post_state_root = calc_state_root(post_state, state_class) post[network].append({ "hash": encode_hex(post_state_root), "indexes": indexes, }) return { test_name: { "env": environment, "pre": pre_state, "transaction": transaction_group, "post": post } }
def _expect(post_state: Dict[str, Any], networks: Any, transaction: TransactionDict, filler: Dict[str, Any]) -> Dict[str, Any]: test_name = get_test_name(filler) test = filler[test_name] test_update = {test_name: {}} # type: Dict[str, Dict[Any, Any]] pre_state = test.get("pre", {}) post_state = normalize_state(post_state or {}) defaults = { address: { "balance": 0, "nonce": 0, "code": b"", "storage": {}, } for address in post_state } result = deep_merge(defaults, pre_state, normalize_state(post_state)) new_expect = {"result": result} if transaction is not None: transaction = normalize_transaction( merge(get_default_transaction(networks), transaction)) if "transaction" not in test: transaction_group = apply_formatters_to_dict( { "data": wrap_in_list, "gasLimit": wrap_in_list, "value": wrap_in_list, }, transaction) indexes = { index_key: 0 for transaction_key, index_key in [ ("gasLimit", "gas"), ("value", "value"), ("data", "data"), ] if transaction_key in transaction_group } else: transaction_group, indexes = add_transaction_to_group( test["transaction"], transaction) new_expect = assoc(new_expect, "indexes", indexes) test_update = assoc_in(test_update, [test_name, "transaction"], transaction_group) if networks is not None: networks = normalize_networks(networks) new_expect = assoc(new_expect, "networks", networks) existing_expects = test.get("expect", []) expect = existing_expects + [new_expect] test_update = assoc_in(test_update, [test_name, "expect"], expect) return deep_merge(filler, test_update)