#!/bin/bash
set -eo pipefail

{
    anvil --port 8545 --steps-tracing --block-base-fee-per-gas 0 &
    pid=$!
    sleep 0.1
    
    acc=0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
    code=6080604052348015600e575f80fd5b506101588061001c5f395ff3fe608060405234801561000f575f80fd5b5060043610610034575f3560e01c80636537214714610038578063b74413ea14610056575b5f80fd5b610040610060565b60405161004d9190610109565b60405180910390f35b61005e610065565b005b5f5481565b608051806101005260ff610110535961012051806101305260116101405360226101415360336101425360446101435360886102475361015051610160518160705280610180528161019052806102a052303b605560445360666101455360776112c053805f80303c836102a552365f6102b0373d5f6102d03e836102e0526102e05150505050505050565b5f819050919050565b610103816100f1565b82525050565b5f60208201905061011c5f8301846100fa565b9291505056fea2646970667358221220c380c45d7330268c2b1d0e42eafe937a5468dae2872e1fd9b700c0e82235c9e164736f6c63430008190033
    contract=$(cast send --rpc-url http://127.0.0.1:8545 --json --unlocked --from $acc --create $code | jq -r '.contractAddress')
    hash0=$(cast send --rpc-url http://127.0.0.1:8545 --json --unlocked --from $acc "$contract" "memoryOperations()" | jq -r '.transactionHash')
} > /dev/null 2>&1

cargo run -- --transaction $hash0 && kill $pid