Skip to content

Commit

Permalink
Merge pull request #463 from eqlabs/cairo_lang_0.9.1
Browse files Browse the repository at this point in the history
chore(py): upgrade to cairo-lang 0.9.1
  • Loading branch information
Joonas Koivunen committed Jul 20, 2022
2 parents 0531d43 + 8b728b5 commit 2b9c6cb
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 18 deletions.
8 changes: 4 additions & 4 deletions crates/pathfinder/src/cairo/ext_py.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,9 +423,9 @@ mod tests {
assert_eq!(
at_block_fee,
crate::rpc::types::reply::FeeEstimate {
consumed: H256::from_low_u64_be(3),
consumed: H256::from_low_u64_be(0x53f),
gas_price: H256::from_low_u64_be(1),
fee: H256::from_low_u64_be(4)
fee: H256::from_low_u64_be(0x540)
}
);

Expand All @@ -443,9 +443,9 @@ mod tests {
assert_eq!(
current_fee,
crate::rpc::types::reply::FeeEstimate {
consumed: H256::from_low_u64_be(3),
consumed: H256::from_low_u64_be(0x53f),
gas_price: H256::from_low_u64_be(10),
fee: H256::from_low_u64_be(35)
fee: H256::from_low_u64_be(0x3478)
}
);

Expand Down
2 changes: 1 addition & 1 deletion py/requirements-dev.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# see README.md
cairo-lang==0.9.0
cairo-lang==0.9.1
# We don't use rlp directly, however this needs to be defined for it to help pip-compile
eth-rlp==0.2.1
pip-tools==6.6.2
Expand Down
2 changes: 1 addition & 1 deletion py/requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ black==21.12b0
# via -r requirements-dev.in
cachetools==5.0.0
# via cairo-lang
cairo-lang==0.9.0
cairo-lang==0.9.1
# via -r requirements-dev.in
certifi==2021.10.8
# via requests
Expand Down
23 changes: 17 additions & 6 deletions py/src/call.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

# used from tests, and the query which asserts that the schema is of expected version.
EXPECTED_SCHEMA_REVISION = 14
EXPECTED_CAIRO_VERSION = "0.9.0"
EXPECTED_CAIRO_VERSION = "0.9.1"
SUPPORTED_COMMANDS = frozenset(["call", "estimate_fee"])


Expand Down Expand Up @@ -342,11 +342,11 @@ def resolve_block(connection, at_block, forced_gas_price):
# it has been decided that the latest is whatever pathfinder knows to be latest synced block
# regardless of it being the highest known (not yet synced)
cursor = connection.execute(
"select number, timestamp, root, gas_price, sequencer_address from starknet_blocks order by number desc limit 1"
"select number, timestamp, root, gas_price, sequencer_address, sn_ver.version from starknet_blocks left join starknet_versions sn_ver on (sn_ver.id = version_id) order by number desc limit 1"
)
elif type(at_block) == int:
cursor = connection.execute(
"select number, timestamp, root, gas_price, sequencer_address from starknet_blocks where number = ?",
"select number, timestamp, root, gas_price, sequencer_address, sn_ver.version from starknet_blocks left join starknet_versions sn_ver on (sn_ver.id = version_id) where number = ?",
[at_block],
)
else:
Expand All @@ -356,12 +356,21 @@ def resolve_block(connection, at_block, forced_gas_price):
at_block = b"\x00" * (32 - len(at_block)) + at_block

cursor = connection.execute(
"select number, timestamp, root, gas_price, sequencer_address from starknet_blocks where hash = ?",
"select number, timestamp, root, gas_price, sequencer_address, sn_ver.version from starknet_blocks left join starknet_versions sn_ver on (sn_ver.id = version_id) where hash = ?",
[at_block],
)

try:
[(block_number, block_time, global_root, gas_price, sequencer_address)] = cursor
[
(
block_number,
block_time,
global_root,
gas_price,
sequencer_address,
starknet_version,
)
] = cursor
except ValueError:
# zero rows, or wrong number of columns (unlikely)
raise NoSuchBlock(at_block)
Expand All @@ -375,7 +384,9 @@ def resolve_block(connection, at_block, forced_gas_price):
sequencer_address = int.from_bytes(sequencer_address, "big")

return (
BlockInfo(block_number, block_time, gas_price, sequencer_address),
BlockInfo(
block_number, block_time, gas_price, sequencer_address, starknet_version
),
global_root,
)

Expand Down
41 changes: 35 additions & 6 deletions py/src/test_call.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
from call import do_loop, loop_inner, EXPECTED_SCHEMA_REVISION, check_cairolang_version
from call import (
do_loop,
loop_inner,
EXPECTED_SCHEMA_REVISION,
check_cairolang_version,
resolve_block,
)
import sqlite3
import io
import json
Expand Down Expand Up @@ -88,13 +94,19 @@ def inmemory_with_tables():
ethereum_log_index INTEGER NOT NULL
);
CREATE TABLE starknet_versions (
id INTEGER NOT NULL PRIMARY KEY,
version TEXT NOT NULL UNIQUE
);
CREATE TABLE starknet_blocks (
number INTEGER PRIMARY KEY,
hash BLOB NOT NULL,
root BLOB NOT NULL,
timestamp INTEGER NOT NULL,
gas_price BLOB NOT NULL,
sequencer_address BLOB NOT NULL
sequencer_address BLOB NOT NULL,
version_id INTEGER REFERENCES starknet_versions(id)
);
"""
)
Expand Down Expand Up @@ -419,7 +431,7 @@ def test_fee_estimate_on_positive_directly():
(verb, output, _timings) = loop_inner(con, command)

assert output == {
"gas_consumed": 3,
"gas_consumed": 1343,
"gas_price": 0,
"overall_fee": 0,
}
Expand All @@ -441,7 +453,7 @@ def test_fee_estimate_on_positive():
assert first == {
"status": "ok",
"output": {
"gas_consumed": "0x" + (3).to_bytes(32, "big").hex(),
"gas_consumed": "0x" + (0x053F).to_bytes(32, "big").hex(),
"gas_price": "0x" + (0).to_bytes(32, "big").hex(),
"overall_fee": "0x" + (0).to_bytes(32, "big").hex(),
},
Expand All @@ -450,13 +462,30 @@ def test_fee_estimate_on_positive():
assert second == {
"status": "ok",
"output": {
"gas_consumed": "0x" + (3).to_bytes(32, "big").hex(),
"gas_consumed": "0x" + (0x053F).to_bytes(32, "big").hex(),
"gas_price": "0x" + (10).to_bytes(32, "big").hex(),
"overall_fee": "0x" + (35).to_bytes(32, "big").hex(),
"overall_fee": "0x" + (0x3478).to_bytes(32, "big").hex(),
},
}


def test_starknet_version_is_resolved():
# using the existing setup, but just updating the one block to have a bogus version
con = inmemory_with_tables()
_ = populate_test_contract_with_132_on_3(con)

con.execute("BEGIN")
cursor = con.execute(
"INSERT INTO starknet_versions (version) VALUES (?)", ["0.9.1"]
)
version_id = cursor.lastrowid

con.execute("UPDATE starknet_blocks SET version_id = ?", [version_id])
(info, _root) = resolve_block(con, "latest", None)

assert info.starknet_version == "0.9.1"


@pytest.mark.skip(reason="this requires up to 2804 block synced database")
def test_failing_mainnet_tx2():
from starkware.starknet.definitions.general_config import StarknetChainId
Expand Down

0 comments on commit 2b9c6cb

Please sign in to comment.