Skip to content

Commit

Permalink
Merge branch 'main' into messaging-rework
Browse files Browse the repository at this point in the history
  • Loading branch information
kariy committed Sep 28, 2023
2 parents 2c988d6 + 00dd22a commit bbd2b6e
Show file tree
Hide file tree
Showing 147 changed files with 5,821 additions and 7,592 deletions.
80 changes: 56 additions & 24 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,17 @@ toml = "0.7.4"
tracing = "0.1.34"
tracing-subscriber = { version = "0.3.16", features = [ "env-filter" ] }
url = "2.4.0"

# server
hyper = "0.14.27"
warp = "0.3"

# gRPC
prost = "0.12"
tonic = "0.10"
tonic-build = "0.10"
tonic-web = "0.10.1"

[patch."https://github.com/starkware-libs/blockifier"]
blockifier = { git = "https://github.com/dojoengine/blockifier", rev = "f7df9ba" }

Expand Down
25 changes: 12 additions & 13 deletions crates/dojo-core/src/database_test.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,11 @@ use array::SpanTrait;
use traits::{Into, TryInto};

use starknet::syscalls::deploy_syscall;
use starknet::class_hash::Felt252TryIntoClassHash;
use dojo::executor::{executor, IExecutorDispatcher, IExecutorDispatcherTrait};
use dojo::world::{Context, IWorldDispatcher};

use starknet::class_hash::{Felt252TryIntoClassHash, ClassHash};
use dojo::world::{IWorldDispatcher};
use dojo::executor::executor;
use dojo::database::{get, set, del, all};



#[test]
#[available_gas(1000000)]
fn test_database_basic() {
Expand All @@ -40,7 +37,7 @@ fn test_database_different_tables() {
let mut other = ArrayTrait::new();
other.append(0x3);
other.append(0x4);

let class_hash: starknet::ClassHash = executor::TEST_CLASS_HASH.try_into().unwrap();
set(class_hash, 'first', 'key', 0, values.span(), array![251, 251].span());
set(class_hash, 'second', 'key', 0, other.span(), array![251, 251].span());
Expand All @@ -63,7 +60,7 @@ fn test_database_different_keys() {
let mut other = ArrayTrait::new();
other.append(0x3);
other.append(0x4);

let class_hash: starknet::ClassHash = executor::TEST_CLASS_HASH.try_into().unwrap();
set(class_hash, 'table', 'key', 0, values.span(), array![251, 251].span());
set(class_hash, 'table', 'other', 0, other.span(), array![251, 251].span());
Expand All @@ -85,12 +82,14 @@ fn test_database_pagination() {
values.append(0x3);
values.append(0x4);
values.append(0x5);

let class_hash: starknet::ClassHash = executor::TEST_CLASS_HASH.try_into().unwrap();
set(class_hash, 'table', 'key', 1, values.span(), array![251, 251, 251, 251, 251].span());
let first_res = get(class_hash, 'table', 'key', 1, 3, array![251, 251, 251].span());
let second_res = get(class_hash, 'table', 'key', 3, 5, array![251, 251, 251, 251, 251].span());
let third_res = get(class_hash, 'table', 'key', 5, 7, array![251, 251, 251, 251, 251, 251, 251].span());
let third_res = get(
class_hash, 'table', 'key', 5, 7, array![251, 251, 251, 251, 251, 251, 251].span()
);

assert(*first_res.at(0) == *values.at(0), 'Values different at index 0!');
assert(*first_res.at(1) == *values.at(1), 'Values different at index 1!');
Expand All @@ -105,10 +104,10 @@ fn test_database_pagination() {
fn test_database_del() {
let mut values = ArrayTrait::new();
values.append(0x42);

let class_hash: starknet::ClassHash = executor::TEST_CLASS_HASH.try_into().unwrap();
set(class_hash, 'table', 'key', 0, values.span(), array![251].span());

let before = get(class_hash, 'table', 'key', 0, values.len(), array![251].span());
assert(*before.at(0) == *values.at(0), 'Values different at index 0!');

Expand All @@ -123,7 +122,7 @@ fn test_database_all() {
let mut even = ArrayTrait::new();
even.append(0x2);
even.append(0x4);

let mut odd = ArrayTrait::new();
odd.append(0x1);
odd.append(0x3);
Expand Down
28 changes: 0 additions & 28 deletions crates/dojo-core/src/executor.cairo
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
use starknet::ClassHash;

use dojo::world::Context;

#[starknet::interface]
trait IExecutor<T> {
fn execute(self: @T, class_hash: ClassHash, calldata: Span<felt252>) -> Span<felt252>;
fn call(
self: @T, class_hash: ClassHash, entrypoint: felt252, calldata: Span<felt252>
) -> Span<felt252>;
Expand All @@ -21,36 +18,11 @@ mod executor {
const EXECUTE_ENTRYPOINT: felt252 =
0x0240060cdb34fcc260f41eac7474ee1d7c80b7e3607daff9ac67c7ea2ebb1c44;

const WORLD_ADDRESS_OFFSET: u32 = 4;

#[storage]
struct Storage {}

#[external(v0)]
impl Executor of IExecutor<ContractState> {
/// Executes a System by calling its execute entrypoint.
///
/// # Arguments
///
/// * `class_hash` - Class Hash of the System.
/// * `calldata` - Calldata to pass to the System.
///
/// # Returns
///
/// The return value of the System's execute entrypoint.
fn execute(
self: @ContractState, class_hash: ClassHash, calldata: Span<felt252>
) -> Span<felt252> {
assert(
traits::Into::<starknet::ContractAddress,
felt252>::into(starknet::get_caller_address()) == *calldata
.at(calldata.len() - WORLD_ADDRESS_OFFSET),
'Only world caller'
);
starknet::syscalls::library_call_syscall(class_hash, EXECUTE_ENTRYPOINT, calldata)
.unwrap_syscall()
}

/// Call the provided `entrypoint` method on the given `class_hash`.
///
/// # Arguments
Expand Down
Loading

0 comments on commit bbd2b6e

Please sign in to comment.