Skip to content

Commit

Permalink
fix(tests): udpate policies and fix spawn and move migration
Browse files Browse the repository at this point in the history
  • Loading branch information
glihm committed Nov 3, 2024
1 parent 533bb77 commit cb896d4
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 54 deletions.
35 changes: 33 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ Inside `bin` and `crates` you will find source code related to Dojo stack compon
- `katana`: The Starknet sequencer tailored for gaming.
- `sozo`: The contract manager and Dojo compiler.
- `torii`: The indexer that store the state of your World.
- `dojo-core`: The core contract of Dojo written in Cairo.
- `dojo-lang`: The Dojo plugin for the Cairo compiler.
- `dojo/core`: The core contract of Dojo written in Cairo.
- `dojo/lang`: The Dojo plugin for the Cairo compiler.

It is important to note that `bin` should only contain applications that gathers user inputs and delegates the work to the libraries present into the crates.

Expand All @@ -51,6 +51,37 @@ Please use meaningful names for your branches. For example, if you're working on

As you're making changes, make sure you follow the coding conventions used throughout the Dojo project. Consistent code style makes it easier for others to read and understand your code.

## Testing the changes

To speed the test suite and avoid migrating dojo projects again, `katana` databases are compressed and stored in the repo.

If you don't have any change in the `dojo/core` crate or any cairo example, you only have to extract the databases:

```bash
bash scripts/extract_test_db.sh
```

To test your changes, if you have modified the `dojo/core` crate or any cairo example, you will need to regenerate the databases:

```bash
# Prints the policies to then be copied into the `sozo/tests/test_data/policies.json` test file to ensure entrypoints and addresses are up to date.
POLICIES_FIX=1 cargo nextest run --all-features --build-jobs 20 --workspace --nocapture policies

# Ensures the test databases are up to date.
bash scripts/rebuild_test_artifacts.sh
```

Then you can run the tests:

```bash
# If you don't have any change in Katana:
cargo nextest run --all-features --build-jobs 20 --workspace

# If you have changes in Katana, you must use local Katana to test.
cargo build -r --bin katana
KATANA_RUNNER_BIN=./target/release/katana cargo nextest run --all-features --build-jobs 20 --workspace
```

## Submitting a Pull Request

Once your changes are ready, commit them and push the branch to your forked repo on GitHub. Then you can open a pull request from your branch to the `main` branch of the Dojo repo.
Expand Down
70 changes: 35 additions & 35 deletions bin/sozo/tests/test_data/policies.json
Original file line number Diff line number Diff line change
@@ -1,118 +1,118 @@
[
{
"target": "0x7bc340927668bc87eea10d95cb2dfe0fa10be12075fe8189f363643205c34d4",
"target": "0x197ece4113fa10c435129f63ffe00877c93446f36a8e3f803b846f76d496ed8",
"method": "upgrade"
},
{
"target": "0x5e6ead52b5ea1146be22fdc3cffbc28d9eca3452f790f991a010ceeb12e339b",
"method": "upgrade"
},
{
"target": "0x48c075712ddb98febd836b09049e3d36c7b061fc7027ba5021f8cf00778b7bf",
"method": "spawn"
},
{
"target": "0x7bc340927668bc87eea10d95cb2dfe0fa10be12075fe8189f363643205c34d4",
"target": "0x48c075712ddb98febd836b09049e3d36c7b061fc7027ba5021f8cf00778b7bf",
"method": "move"
},
{
"target": "0x7bc340927668bc87eea10d95cb2dfe0fa10be12075fe8189f363643205c34d4",
"target": "0x48c075712ddb98febd836b09049e3d36c7b061fc7027ba5021f8cf00778b7bf",
"method": "set_player_config"
},
{
"target": "0x7bc340927668bc87eea10d95cb2dfe0fa10be12075fe8189f363643205c34d4",
"target": "0x48c075712ddb98febd836b09049e3d36c7b061fc7027ba5021f8cf00778b7bf",
"method": "reset_player_config"
},
{
"target": "0x7bc340927668bc87eea10d95cb2dfe0fa10be12075fe8189f363643205c34d4",
"target": "0x48c075712ddb98febd836b09049e3d36c7b061fc7027ba5021f8cf00778b7bf",
"method": "set_player_server_profile"
},
{
"target": "0x7bc340927668bc87eea10d95cb2dfe0fa10be12075fe8189f363643205c34d4",
"target": "0x48c075712ddb98febd836b09049e3d36c7b061fc7027ba5021f8cf00778b7bf",
"method": "set_models"
},
{
"target": "0x7bc340927668bc87eea10d95cb2dfe0fa10be12075fe8189f363643205c34d4",
"target": "0x48c075712ddb98febd836b09049e3d36c7b061fc7027ba5021f8cf00778b7bf",
"method": "enter_dungeon"
},
{
"target": "0x7bc340927668bc87eea10d95cb2dfe0fa10be12075fe8189f363643205c34d4",
"method": "upgrade"
},
{
"target": "0x200cd8070a7dbe0894c74426d2f4c9d778b13042ce955203cb189d85cfb43d1",
"method": "upgrade"
},
{
"target": "0x2e7d504b81c2f1b60986c95de64b650feb8ae625f04c6cd924150fab3cad4a8",
"target": "0x48c075712ddb98febd836b09049e3d36c7b061fc7027ba5021f8cf00778b7bf",
"method": "upgrade"
},
{
"target": "0x41ceb76687e3653610fffc3c830607d90079e9c5d96cfb6f270c8231e9ee9db",
"target": "0x317a11a6cb0c66389ad53e1a9c282a64e8b94a7811b139da94138284ce019a4",
"method": "upgrade"
},
{
"target": "0x234d358c2ec21c98a229966bd2bae6dbf2c517969c361bc649361f9055afc32",
"target": "0xecd610a15ce418719008d506c662ec3e420cf17b4b6d086e53281f30425115",
"method": "uuid"
},
{
"target": "0x234d358c2ec21c98a229966bd2bae6dbf2c517969c361bc649361f9055afc32",
"target": "0xecd610a15ce418719008d506c662ec3e420cf17b4b6d086e53281f30425115",
"method": "set_metadata"
},
{
"target": "0x234d358c2ec21c98a229966bd2bae6dbf2c517969c361bc649361f9055afc32",
"target": "0xecd610a15ce418719008d506c662ec3e420cf17b4b6d086e53281f30425115",
"method": "register_namespace"
},
{
"target": "0x234d358c2ec21c98a229966bd2bae6dbf2c517969c361bc649361f9055afc32",
"target": "0xecd610a15ce418719008d506c662ec3e420cf17b4b6d086e53281f30425115",
"method": "register_event"
},
{
"target": "0x234d358c2ec21c98a229966bd2bae6dbf2c517969c361bc649361f9055afc32",
"target": "0xecd610a15ce418719008d506c662ec3e420cf17b4b6d086e53281f30425115",
"method": "register_model"
},
{
"target": "0x234d358c2ec21c98a229966bd2bae6dbf2c517969c361bc649361f9055afc32",
"target": "0xecd610a15ce418719008d506c662ec3e420cf17b4b6d086e53281f30425115",
"method": "register_contract"
},
{
"target": "0x234d358c2ec21c98a229966bd2bae6dbf2c517969c361bc649361f9055afc32",
"target": "0xecd610a15ce418719008d506c662ec3e420cf17b4b6d086e53281f30425115",
"method": "init_contract"
},
{
"target": "0x234d358c2ec21c98a229966bd2bae6dbf2c517969c361bc649361f9055afc32",
"target": "0xecd610a15ce418719008d506c662ec3e420cf17b4b6d086e53281f30425115",
"method": "upgrade_event"
},
{
"target": "0x234d358c2ec21c98a229966bd2bae6dbf2c517969c361bc649361f9055afc32",
"target": "0xecd610a15ce418719008d506c662ec3e420cf17b4b6d086e53281f30425115",
"method": "upgrade_model"
},
{
"target": "0x234d358c2ec21c98a229966bd2bae6dbf2c517969c361bc649361f9055afc32",
"target": "0xecd610a15ce418719008d506c662ec3e420cf17b4b6d086e53281f30425115",
"method": "upgrade_contract"
},
{
"target": "0x234d358c2ec21c98a229966bd2bae6dbf2c517969c361bc649361f9055afc32",
"target": "0xecd610a15ce418719008d506c662ec3e420cf17b4b6d086e53281f30425115",
"method": "emit_event"
},
{
"target": "0x234d358c2ec21c98a229966bd2bae6dbf2c517969c361bc649361f9055afc32",
"target": "0xecd610a15ce418719008d506c662ec3e420cf17b4b6d086e53281f30425115",
"method": "set_entity"
},
{
"target": "0x234d358c2ec21c98a229966bd2bae6dbf2c517969c361bc649361f9055afc32",
"target": "0xecd610a15ce418719008d506c662ec3e420cf17b4b6d086e53281f30425115",
"method": "delete_entity"
},
{
"target": "0x234d358c2ec21c98a229966bd2bae6dbf2c517969c361bc649361f9055afc32",
"target": "0xecd610a15ce418719008d506c662ec3e420cf17b4b6d086e53281f30425115",
"method": "grant_owner"
},
{
"target": "0x234d358c2ec21c98a229966bd2bae6dbf2c517969c361bc649361f9055afc32",
"target": "0xecd610a15ce418719008d506c662ec3e420cf17b4b6d086e53281f30425115",
"method": "revoke_owner"
},
{
"target": "0x234d358c2ec21c98a229966bd2bae6dbf2c517969c361bc649361f9055afc32",
"target": "0xecd610a15ce418719008d506c662ec3e420cf17b4b6d086e53281f30425115",
"method": "grant_writer"
},
{
"target": "0x234d358c2ec21c98a229966bd2bae6dbf2c517969c361bc649361f9055afc32",
"target": "0xecd610a15ce418719008d506c662ec3e420cf17b4b6d086e53281f30425115",
"method": "revoke_writer"
},
{
"target": "0x234d358c2ec21c98a229966bd2bae6dbf2c517969c361bc649361f9055afc32",
"target": "0xecd610a15ce418719008d506c662ec3e420cf17b4b6d086e53281f30425115",
"method": "upgrade"
},
{
Expand Down
2 changes: 1 addition & 1 deletion examples/spawn-and-move/dojo_dev.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ rpc_url = "http://localhost:5050/"
# Default account for katana with seed = 0
account_address = "0x2af9427c5a277474c079a1283c880ee8a6f0f8fbf73ce969c08d88befec1bba"
private_key = "0x1800000000300000180000000000030000000000003006001800006600"
world_address = "0x234d358c2ec21c98a229966bd2bae6dbf2c517969c361bc649361f9055afc32"
world_address = "0xecd610a15ce418719008d506c662ec3e420cf17b4b6d086e53281f30425115"

[init_call_args]
"ns-others" = ["0xff"]
Expand Down
6 changes: 6 additions & 0 deletions scripts/extract_test_db.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Ensures that the user has locally the db dir in /tmp.

rm -rf /tmp/spawn-and-move-db
rm -rf /tmp/types-test-db
tar xzf spawn-and-move-db.tar.gz -C /tmp/
tar xzf types-test-db.tar.gz -C /tmp/
16 changes: 7 additions & 9 deletions scripts/rebuild_test_artifacts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@
# This script gives an easy way to remove those artifacts.

cargo build -r --bin katana
cargo build -r --bin sozo

# some formatting:
# Some formatting.
cargo +nightly-2024-08-28 fmt --all -- "$@"

scarb --manifest-path examples/spawn-and-move/Scarb.toml fmt
scarb --manifest-path examples/simple/Scarb.toml fmt
scarb --manifest-path crates/dojo/core/Scarb.toml fmt
scarb --manifest-path crates/dojo/core-cairo-test/Scarb.toml fmt

cargo build -r --bin sozo

# Cleanup
# Manual forced cleanup.
rm -rf examples/spawn-and-move/target
rm -rf crates/torii/types-test/target
rm -rf crates/dojo/lang/src/manifest_test_data/compiler_cairo/target
Expand All @@ -37,8 +36,7 @@ cargo +nightly-2024-08-28 fmt --all -- "$@"

# Generates the database for testing by migrating the spawn and move example.
KATANA_RUNNER_BIN=./target/release/katana cargo generate-test-db
# Ensure the user has locally the db dir in /tmp.
rm -rf /tmp/spawn-and-move-db
rm -rf /tmp/types-test-db
tar xzf spawn-and-move-db.tar.gz -C /tmp/
tar xzf types-test-db.tar.gz -C /tmp/

# Extracts the database for testing.
bash ./scripts/extract_test_db.sh

Binary file modified spawn-and-move-db.tar.gz
Binary file not shown.
Binary file modified types-test-db.tar.gz
Binary file not shown.
29 changes: 22 additions & 7 deletions xtask/generate-test-db/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,29 @@ async fn migrate_spawn_and_move(db_path: &Path) -> Result<Manifest> {
let profile_config = ws.load_profile_config()?;

let world_local = ws.load_world_local()?;
let world_address = if let Some(env) = &profile_config.env {
env.world_address().map_or_else(
|| world_local.deterministic_world_address(),
|wa| Ok(Felt::from_str(wa).unwrap()),
)

// In the case of testing, if the addresses are different it means that the example hasn't been
// migrated correctly.
let deterministic_world_address = world_local.deterministic_world_address().unwrap();
let config_world_address = if let Some(env) = &profile_config.env {
env.world_address()
.map_or_else(
|| world_local.deterministic_world_address(),
|wa| Ok(Felt::from_str(wa).unwrap()),
)
.unwrap()

Check warning on line 49 in xtask/generate-test-db/src/main.rs

View check run for this annotation

Codecov / codecov/patch

xtask/generate-test-db/src/main.rs#L42-L49

Added lines #L42 - L49 were not covered by tests
} else {
world_local.deterministic_world_address()
deterministic_world_address

Check warning on line 51 in xtask/generate-test-db/src/main.rs

View check run for this annotation

Codecov / codecov/patch

xtask/generate-test-db/src/main.rs#L51

Added line #L51 was not covered by tests
};

if deterministic_world_address != config_world_address {
panic!(
"The deterministic world address is different from the config world address. Please \
review the `dojo_dev.toml` file of spawn-and-move example."
);

Check warning on line 58 in xtask/generate-test-db/src/main.rs

View check run for this annotation

Codecov / codecov/patch

xtask/generate-test-db/src/main.rs#L54-L58

Added lines #L54 - L58 were not covered by tests
}
.unwrap();

let world_address = deterministic_world_address;

Check warning on line 61 in xtask/generate-test-db/src/main.rs

View check run for this annotation

Codecov / codecov/patch

xtask/generate-test-db/src/main.rs#L60-L61

Added lines #L60 - L61 were not covered by tests

let world_diff =
WorldDiff::new_from_chain(world_address, world_local, &runner.provider()).await?;
Expand Down Expand Up @@ -82,6 +96,7 @@ async fn migrate_types_test(db_path: &Path) -> Result<Manifest> {

let profile_config = ws.load_profile_config()?;

// No world address in config, so it should always pick the deterministic one.
let world_local = ws.load_world_local()?;
let world_address = if let Some(env) = &profile_config.env {
env.world_address().map_or_else(
Expand Down

0 comments on commit cb896d4

Please sign in to comment.