Skip to content

Commit

Permalink
script stake keys have different prefix then regular stake keys
Browse files Browse the repository at this point in the history
  • Loading branch information
logicalmechanism committed Jan 25, 2024
1 parent 5249275 commit 2865c00
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 7 deletions.
1 change: 1 addition & 0 deletions example-contracts/scripts/cbor/mint_and_fee.cbor
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
84a8008182582043bc43c57ee7893f3f29606ca9a5c8aaa70354863615a2ede100a7c73ef07c0e000d818258206e34390c14ea8041c85963cf4b00a4ac900ebfd4e7bbcc9df7ed9345393777f300128382582030654b610586213ada3a9c0de5f730f1b6510ea4925a28b402a20e665cadbe6200825820e1f052af6746ff1e27bf50db7b89b2545009627c4c1931ce16a6e5fecd6ad03801825820f5967b09bd6d9cb00b0f0395c8cf6099582329088bc4d8383e03cc3ef2e001aa010181a30058393067b7dfc1f2c715ee42ef98d7e24c386934c01d9cb83bc017f82eb96b7b87ba462312b0c48ed71f24b51ae9340d19eba9b9cc18d44758010401821a002d2bd1a2581c20f604a8cd5f0f88f30719f2951c1993de340dc5f1cafb0e76d4c86fa15820001bc2800180d690ad49224b4b63c09500b134a6c92dbd55d16ad37f6d76bd5a1a05f5e100581c897f05de9aa0a1d78cc0010228abd329e9b4b5636c030c5a5eb86e56a15820a110ca7ab1e00000abd3dc076824771bf7f595574d1eaf2c378b48eb02ce62fd01028201d818589bd8799fd8799f581c39f29cfe6ab0765578a6e0d8871e1a3bc18f5d277b257095aabf1cd840ffd8799f581c20f604a8cd5f0f88f30719f2951c1993de340dc5f1cafb0e76d4c86f5820001bc2800180d690ad49224b4b63c09500b134a6c92dbd55d16ad37f6d76bd5a01ffa1581c015d83f25700c83d708fbf8ad57783dc257b01a932ffceac9dcd0c3da14843757272656e6379021a05f5e100ff021a000502510e82581cb834fb41c45bd80e5fd9d99119723637fe9d1e3fc467bc1c57ae9aee581ce6f85717b932788e3b1e57b11e9f8bf190d257c57d369979c18a02dd09a1581c897f05de9aa0a1d78cc0010228abd329e9b4b5636c030c5a5eb86e56a15820a110ca7ab1e00000abd3dc076824771bf7f595574d1eaf2c378b48eb02ce62fd010b58207993c8fb6a86eba475c847ec2ee7b3533e6a6098d60838c773d6679bb178a9dda10582840000d87a9fd8799f581c897f05de9aa0a1d78cc0010228abd329e9b4b5636c030c5a5eb86e565820a110ca7ab1e00000abd3dc076824771bf7f595574d1eaf2c378b48eb02ce62fd01ffff821a000f42401a14dc9380840100d87980821a0007a1201a08f0d180f5f6
8 changes: 8 additions & 0 deletions tests/test_from_cbor.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,11 @@ def test_from_cbor_multi():
# print('output', output)
expected_output = [{'mem': 7295, 'cpu': 2296335}, {'mem': 133896, 'cpu': 57999931}, {'mem': 75076, 'cpu': 33128313}]
assert output == expected_output


def test_mint_and_fee():
valid_hex_cbor = get_first_line("./example-contracts/scripts/cbor/mint_and_fee.cbor")
output = from_cbor(valid_hex_cbor, False, debug=True)
# print('output', output)
expected_output = [{'mem': 757860, 'cpu': 273948262}, {'mem': 340297, 'cpu': 117528124}]
assert output == expected_output
16 changes: 13 additions & 3 deletions tests/test_run_bech32.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,19 @@ def test_to_bytes_with_invalid_hex2():
assert "non-standard format in run_bech32() arg at position 1" in str(excinfo.value), "Incorrect error message for invalid input"


def test_stake_run_bech32():
assert run_bech32("stake_test1uzl65wzu364hh0wxex94qsf5xkeaq2mnmc7xgnsnsjuqr4qruvxwu") == "bfaa385c8eab7bbdc6c98b50413435b3d02b73de3c644e1384b801d4"
def test_stake_run_bech32_not_contract():
key, flag = run_bech32("stake_test1uzl65wzu364hh0wxex94qsf5xkeaq2mnmc7xgnsnsjuqr4qruvxwu")
assert flag is False
assert key == "bfaa385c8eab7bbdc6c98b50413435b3d02b73de3c644e1384b801d4"


def test_stake_run_bech32_contract():
key, flag = run_bech32("stake_test17pac0wjxyvftp3yw6u0jfdg6ay6q6x0t4xuucxx5gavqzpqdw9kfm")
assert flag is True
assert (key == "7b87ba462312b0c48ed71f24b51ae9340d19eba9b9cc18d447580104")


def test_address_run_bech32():
assert run_bech32("addr_test1qrvnxkaylr4upwxfxctpxpcumj0fl6fdujdc72j8sgpraa9l4gu9er4t0w7udjvt2pqngddn6q4h8h3uv38p8p9cq82qav4lmp") == "d9335ba4f8ebc0b8c9361613071cdc9e9fe92de49b8f2a4782023ef4bfaa385c8eab7bbdc6c98b50413435b3d02b73de3c644e1384b801d4"
key, flag = run_bech32("addr_test1qrvnxkaylr4upwxfxctpxpcumj0fl6fdujdc72j8sgpraa9l4gu9er4t0w7udjvt2pqngddn6q4h8h3uv38p8p9cq82qav4lmp")
assert flag is True
assert key == "d9335ba4f8ebc0b8c9361613071cdc9e9fe92de49b8f2a4782023ef4bfaa385c8eab7bbdc6c98b50413435b3d02b73de3c644e1384b801d4"
15 changes: 11 additions & 4 deletions tx_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ def run_bech32(key: str) -> str:
hex_string = ''.join(format(x, '02x') for x in data8)

# remove the network tag
return hex_string[2:]
print('hex string', hex_string)
if hex_string[:2] == "e0":
return hex_string[2:], False
else:
return hex_string[2:], True
except TypeError:
raise TypeError("non-standard format in run_bech32() arg at position 1")

Expand Down Expand Up @@ -219,8 +223,11 @@ def build_resolved_output(tx_id: str, tx_idx: int, outputs: list[dict], network:
network_flag = "71" if network is True else "70"
pkh = network_flag + txo['payment_addr']['cred']
else:
network_flag = "11" if network is True else "10"
stake_key = run_bech32(txo["stake_addr"])
stake_key, flag = run_bech32(txo["stake_addr"])
if flag is True:
network_flag = "31" if network is True else "30"
else:
network_flag = "11" if network is True else "10"
pkh = network_flag + txo['payment_addr']['cred'] + stake_key
# correct format
pkh = to_bytes(pkh)
Expand All @@ -236,7 +243,7 @@ def build_resolved_output(tx_id: str, tx_idx: int, outputs: list[dict], network:
pkh = network_flag + txo['payment_addr']['cred']
else:
network_flag = "01" if network is True else "00"
stake_key = run_bech32(txo["stake_addr"])
stake_key, _ = run_bech32(txo["stake_addr"])
pkh = network_flag + txo['payment_addr']['cred'] + stake_key
pkh = network_flag + txo['payment_addr']['cred']
pkh = to_bytes(pkh)
Expand Down

0 comments on commit 2865c00

Please sign in to comment.