Skip to content

Commit

Permalink
Merge branch 'main' into improve-stats
Browse files Browse the repository at this point in the history
  • Loading branch information
lambda-0x committed May 29, 2024
2 parents 0a444fc + 6153192 commit 2d2e189
Show file tree
Hide file tree
Showing 76 changed files with 3,846 additions and 623 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ env:

jobs:
test:
runs-on: ubuntu-latest-16-cores
runs-on: ubuntu-latest-32-cores
container:
image: ghcr.io/dojoengine/dojo-dev:v0.7.0-alpha.4
steps:
- uses: actions/checkout@v3
- uses: Swatinem/rust-cache@v2
- run: |
cargo build -r --bin katana
KATANA_RUNNER_BIN=$(pwd)/target/release/katana cargo llvm-cov nextest --no-report --all-features --workspace --exclude katana --build-jobs 10
KATANA_RUNNER_BIN=$(pwd)/target/release/katana cargo llvm-cov nextest --no-report --all-features --workspace --exclude katana --build-jobs 20
cargo llvm-cov nextest --no-report -p katana
# TODO(kariy): uncomment this line when `sir` feature support Cairo 2.6.3
# cargo llvm-cov nextest --no-report -p katana --no-default-features --features sir
Expand Down
8 changes: 8 additions & 0 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ dojo-test-utils = { path = "crates/dojo-test-utils" }
dojo-types = { path = "crates/dojo-types" }
dojo-world = { path = "crates/dojo-world" }

# dojo-world
topological-sort = "0.2"

# katana
katana-cairo = { path = "crates/katana/cairo" }
katana-codecs = { path = "crates/katana/storage/codecs" }
Expand Down
36 changes: 36 additions & 0 deletions bin/sozo/src/commands/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,37 @@ pub enum ModelCommand {
starknet: StarknetOptions,
},

#[command(about = "Displays the model's layout into dojo storage.\n
The Dojo storage system uses the poseidon_hash function to compute
hashes, called 'hash' in the following documentation.
How storage locations are computed ?
model key = hash(model_keys)
fixed layout key = parent_key
struct layout field key = hash(parent_key, field_selector)
tuple layout item key = hash(parent_key, item_index)
enum layout
variant key = parent_key
data key = hash(parent_key, variant_index)
array layout
length key = parent_key
item key = hash(parent_key, item_index)
byte array layout = parent_key
final storage location = hash('dojo_storage', model_selector, record_key)")]
Layout {
#[arg(help = "The name of the model")]
name: String,

#[command(flatten)]
world: WorldOptions,

#[command(flatten)]
starknet: StarknetOptions,
},

#[command(about = "Retrieve the schema for a model")]
Schema {
#[arg(help = "The name of the model")]
Expand Down Expand Up @@ -92,6 +123,11 @@ impl ModelArgs {
let provider = starknet.provider(env_metadata.as_ref()).unwrap();
model::model_contract_address(name, world_address, provider).await
}
ModelCommand::Layout { name, starknet, world } => {
let world_address = world.address(env_metadata.as_ref()).unwrap();
let provider = starknet.provider(env_metadata.as_ref()).unwrap();
model::model_layout(name, world_address, provider).await
}
ModelCommand::Schema { name, to_json, starknet, world } => {
let world_address = world.address(env_metadata.as_ref()).unwrap();
let provider = starknet.provider(env_metadata.as_ref()).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion crates/dojo-bindgen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ mod tests {
)
.unwrap();

assert_eq!(data.models.len(), 5);
assert_eq!(data.models.len(), 6);

assert_eq!(data.world.name, "dojo_example");

Expand Down
28 changes: 22 additions & 6 deletions crates/dojo-core/src/base_test.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,20 @@ fn deploy_world() -> IWorldDispatcher {
spawn_test_world(array![])
}

// A test contract needs to be used instead of previously used base contract since.
// contracts now require a `dojo_init` method which normal base contract doesn't have
#[dojo::contract]
mod test_contract {}

#[test]
#[available_gas(6000000)]
fn test_upgrade_from_world() {
let world = deploy_world();

let base_address = world.deploy_contract('salt', base::TEST_CLASS_HASH.try_into().unwrap());
let base_address = world
.deploy_contract(
'salt', test_contract::TEST_CLASS_HASH.try_into().unwrap(), array![].span()
);
let new_class_hash: ClassHash = contract_upgrade::TEST_CLASS_HASH.try_into().unwrap();

world.upgrade_contract(base_address, new_class_hash);
Expand All @@ -74,7 +82,10 @@ fn test_upgrade_from_world() {
fn test_upgrade_from_world_not_world_provider() {
let world = deploy_world();

let base_address = world.deploy_contract('salt', base::TEST_CLASS_HASH.try_into().unwrap());
let base_address = world
.deploy_contract(
'salt', test_contract::TEST_CLASS_HASH.try_into().unwrap(), array![].span()
);
let new_class_hash: ClassHash = contract_invalid_upgrade::TEST_CLASS_HASH.try_into().unwrap();

world.upgrade_contract(base_address, new_class_hash);
Expand All @@ -86,7 +97,10 @@ fn test_upgrade_from_world_not_world_provider() {
fn test_upgrade_direct() {
let world = deploy_world();

let base_address = world.deploy_contract('salt', base::TEST_CLASS_HASH.try_into().unwrap());
let base_address = world
.deploy_contract(
'salt', test_contract::TEST_CLASS_HASH.try_into().unwrap(), array![].span()
);
let new_class_hash: ClassHash = contract_upgrade::TEST_CLASS_HASH.try_into().unwrap();

let upgradeable_dispatcher = IUpgradeableDispatcher { contract_address: base_address };
Expand Down Expand Up @@ -144,8 +158,9 @@ mod invalid_model {
#[abi(embed_v0)]
impl InvalidModelSelector of super::IMetadataOnly<ContractState> {
fn selector(self: @ContractState) -> felt252 {
// NOTE: Need to update this value if address changes
// Pre-computed address of a contract deployed through the world.
0x455fe9471cb954574b16581868043841391545b9225af00bf545f9acf923295
0x15f0ffa36184d74ead97aa501b09aed53ee7236e364997a0c21879194340ab6
}

fn name(self: @ContractState) -> ByteArray {
Expand Down Expand Up @@ -179,12 +194,13 @@ mod invalid_model_world {
fn test_deploy_from_world_invalid_model() {
let world = deploy_world();

let base_address = world.deploy_contract(0, base::TEST_CLASS_HASH.try_into().unwrap());
let contract_address = world
.deploy_contract(0, test_contract::TEST_CLASS_HASH.try_into().unwrap(), array![].span());

// This print allows to know the address of the deployed contract which must be returned
// by the selector() function of invalid model, to simulate a ACL issue
// (see register_model function)
base_address.print();
contract_address.print();

world.register_model(invalid_model::TEST_CLASS_HASH.try_into().unwrap());
}
Expand Down
18 changes: 5 additions & 13 deletions crates/dojo-core/src/database/introspect.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ enum Layout {
ByteArray,
// there is one layout per variant.
// the `selector` field identifies the variant
// the `layout` field defines the full variant layout (variant value + optional variant data)
// the `layout` defines the variant data (could be empty for variant without data).
Enum: Span<FieldLayout>,
}

Expand Down Expand Up @@ -203,18 +203,10 @@ impl Introspect_option<T, +Introspect<T>> of Introspect<Option<T>> {
fn layout() -> Layout {
Layout::Enum(
array![
FieldLayout {
// Some
selector: 0,
layout: Layout::Tuple(
array![Layout::Fixed(array![8].span()), Introspect::<T>::layout()].span()
)
},
FieldLayout {
// None
selector: 1,
layout: Layout::Tuple(array![Layout::Fixed(array![8].span())].span())
},
FieldLayout { // Some
selector: 0, layout: Introspect::<T>::layout() },
FieldLayout { // None
selector: 1, layout: Layout::Fixed(array![].span()) },
]
.span()
)
Expand Down
Loading

0 comments on commit 2d2e189

Please sign in to comment.