Skip to content

Instantly share code, notes, and snippets.

@tzaffi
Last active January 14, 2022 20:27
Show Gist options
  • Save tzaffi/6166662066920ca321b598bc56389c05 to your computer and use it in GitHub Desktop.
Save tzaffi/6166662066920ca321b598bc56389c05 to your computer and use it in GitHub Desktop.
Alas, poor Yorick! I knew him, Horatio.
[
{
"spin(application,application)(byte[3],byte[17],byte[17],byte[17])": [
{ "appl": "appl" },
{ "appl": "appl" },
{ "appl": "appl" }
]
},
{
"spin(application,application)(byte[3],byte[17],byte[17],byte[17])": [
{ "appl": "appl" },
{ "appl": "appl" },
{ "appl": "appl" }
]
},
"setReels(string,string,string)void",
{
"spin(application,application)(byte[3],byte[17],byte[17],byte[17])": [
{ "appl": "appl" },
{ "appl": "appl" },
{ "appl": "appl" }
]
},
{
"spin(application,application)(byte[3],byte[17],byte[17],byte[17])": [
{ "appl": "appl" },
{ "appl": "appl" },
{ "appl": "appl" }
]
}
]
[
{
"spin(application,application)(byte[3],byte[17],byte[17],byte[17])": [
{ "appl": "appl" },
{ "appl": "appl" },
{ "appl": "appl" }
]
},
{
"spin(application,application)(byte[3],byte[17],byte[17],byte[17])": [
{ "appl": "appl" },
{ "appl": "appl" },
{ "appl": "appl" }
]
}
]
# The commit that removed this friend of mine: https://github.com/algorand/algorand-sdk-testing/pull/156/commits/cbc271a9382f6853b272cffcd6563eb464a8013b
def transactions_trace(
atc: AtomicTransactionComposer, results: List[ABIResult], quote='"'
) -> str:
"""
Return a json-like representation of the transactions call graph that occured during execution
TODO: this only works when all the transactions are method calls. Should make this work when
other kinds of transactions are added with AtomicTransactionComposer.add_transaction()
"""
def _wrap(k, v):
return "{" + quote + k + quote + ":" + v + "}"
def _wrap_iter(vs):
vs = list(vs)
return vs[0] if len(vs) == 1 else "[" + ",".join(vs) + "]"
def _tt(tx: Union[int, list, dict]) -> str:
if isinstance(tx, list):
_wrap_iter(tx)
if isinstance(tx, dict):
k = tx["txn"]["txn"]["type"]
tx_info = tx
# top level only:
else:
assert isinstance(tx, int)
tx_info = results[tx].tx_info
k = (
atc.method_dict[tx].get_signature()
if tx in atc.method_dict
else tx_info["txn"]["txn"]["type"]
)
vs = tx_info.get("inner-txns", [])
return _wrap(k, _wrap_iter(map(_tt, vs))) if vs else quote + k + quote
return _wrap_iter(map(_tt, range(len(atc.tx_ids))))
@then(
'I can retrieve all inner transactions that were called from the atomic transaction with call graph "{callGraph}".'
)
def can_retrieve_all_inner_txns(context, callGraph):
actual = transactions_trace(
context.atomic_transaction_composer,
context.atomic_transaction_composer_return.abi_results,
quote="'",
)
assert actual == callGraph, f"expected: {callGraph} but got: {actual}"
[{'spin(application,application)(byte[3],byte[17],byte[17],byte[17])':[{'appl':'appl'},{'appl':'appl'},{'appl':'appl'}]},{'spin(application,application)(byte[3],byte[17],byte[17],byte[17])':[{'appl':'appl'},{'appl':'appl'},{'appl':'appl'}]}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment