-
Notifications
You must be signed in to change notification settings - Fork 176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
opt-fix(torii-core): fix and optimize partial updates #2427
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
4c1117e
opt-fix(torii-core): fix and optimize partial updates
Larkooo 96b7ab6
fmt
Larkooo 97221ed
values
Larkooo c9f8555
fix: store update whne recursive set
Larkooo 7992391
fmt
Larkooo 2ce452e
test from lambda
Larkooo c210a64
remove get entity keys test
Larkooo 6a3ed4a
fix clippy
Larkooo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -22,6 +22,8 @@ use crate::processors::generate_event_processors_map; | |||||
use crate::processors::register_model::RegisterModelProcessor; | ||||||
use crate::processors::store_del_record::StoreDelRecordProcessor; | ||||||
use crate::processors::store_set_record::StoreSetRecordProcessor; | ||||||
use crate::processors::store_update_member::StoreUpdateMemberProcessor; | ||||||
use crate::processors::store_update_record::StoreUpdateRecordProcessor; | ||||||
use crate::sql::Sql; | ||||||
|
||||||
pub async fn bootstrap_engine<P>( | ||||||
|
@@ -42,6 +44,8 @@ where | |||||
event: generate_event_processors_map(vec![ | ||||||
Box::new(RegisterModelProcessor), | ||||||
Box::new(StoreSetRecordProcessor), | ||||||
Box::new(StoreUpdateRecordProcessor), | ||||||
Box::new(StoreUpdateMemberProcessor), | ||||||
Box::new(StoreDelRecordProcessor), | ||||||
])?, | ||||||
..Processors::default() | ||||||
|
@@ -292,24 +296,31 @@ async fn test_load_from_remote_del() { | |||||
db.execute().await.unwrap(); | ||||||
} | ||||||
|
||||||
// Start of Selection | ||||||
#[tokio::test(flavor = "multi_thread")] | ||||||
async fn test_get_entity_keys() { | ||||||
async fn test_update_with_set_record() { | ||||||
// Initialize the SQLite in-memory database | ||||||
let options = | ||||||
SqliteConnectOptions::from_str("sqlite::memory:").unwrap().create_if_missing(true); | ||||||
let pool = SqlitePoolOptions::new().max_connections(5).connect_with(options).await.unwrap(); | ||||||
sqlx::migrate!("../migrations").run(&pool).await.unwrap(); | ||||||
|
||||||
// Set up the compiler test environment | ||||||
let setup = CompilerTestSetup::from_examples("../../dojo-core", "../../../examples/"); | ||||||
let config = setup.build_test_config("spawn-and-move", Profile::DEV); | ||||||
|
||||||
let ws = scarb::ops::read_workspace(config.manifest_path(), &config).unwrap(); | ||||||
let manifest_path = Utf8PathBuf::from(config.manifest_path().parent().unwrap()); | ||||||
let target_dir = Utf8PathBuf::from(ws.target_dir().to_string()).join("dev"); | ||||||
|
||||||
// Configure and start the KatanaRunner | ||||||
let seq_config = KatanaRunnerConfig { n_accounts: 10, ..Default::default() } | ||||||
.with_db_dir(copy_spawn_and_move_db().as_str()); | ||||||
|
||||||
let sequencer = KatanaRunner::new_with_config(seq_config).expect("Failed to start runner."); | ||||||
let account = sequencer.account(0); | ||||||
|
||||||
// Prepare migration with world and seed | ||||||
let (strat, _) = prepare_migration_with_world_and_seed( | ||||||
manifest_path, | ||||||
target_dir, | ||||||
|
@@ -327,10 +338,9 @@ async fn test_get_entity_keys() { | |||||
strat.world_address, | ||||||
); | ||||||
|
||||||
let account = sequencer.account(0); | ||||||
|
||||||
let world = WorldContract::new(strat.world_address, &account); | ||||||
|
||||||
// Grant writer permissions | ||||||
let res = world | ||||||
.grant_writer(&compute_bytearray_hash("dojo_examples"), &ContractAddress(actions_address)) | ||||||
.send_with_cfg(&TxnConfig::init_wait()) | ||||||
|
@@ -339,8 +349,8 @@ async fn test_get_entity_keys() { | |||||
|
||||||
TransactionWaiter::new(res.transaction_hash, &account.provider()).await.unwrap(); | ||||||
|
||||||
// spawn | ||||||
let res = account | ||||||
// Send spawn transaction | ||||||
let spawn_res = account | ||||||
.execute_v1(vec![Call { | ||||||
to: actions_address, | ||||||
selector: get_selector_from_name("spawn").unwrap(), | ||||||
|
@@ -350,23 +360,28 @@ async fn test_get_entity_keys() { | |||||
.await | ||||||
.unwrap(); | ||||||
|
||||||
TransactionWaiter::new(res.transaction_hash, &account.provider()).await.unwrap(); | ||||||
|
||||||
let world_reader = WorldContractReader::new(strat.world_address, account.provider()); | ||||||
|
||||||
let mut db = Sql::new(pool.clone(), world_reader.address).await.unwrap(); | ||||||
TransactionWaiter::new(spawn_res.transaction_hash, &account.provider()).await.unwrap(); | ||||||
|
||||||
let _ = bootstrap_engine(world_reader, db.clone(), account.provider()).await; | ||||||
// Send move transaction | ||||||
let move_res = account | ||||||
.execute_v1(vec![Call { | ||||||
to: actions_address, | ||||||
selector: get_selector_from_name("move").unwrap(), | ||||||
calldata: vec![Felt::ZERO], | ||||||
}]) | ||||||
.send_with_cfg(&TxnConfig::init_wait()) | ||||||
.await | ||||||
.unwrap(); | ||||||
|
||||||
let keys = db.get_entity_keys_def("dojo_examples-Moves").await.unwrap(); | ||||||
assert_eq!(keys, vec![("player".to_string(), "ContractAddress".to_string()),]); | ||||||
TransactionWaiter::new(move_res.transaction_hash, &account.provider()).await.unwrap(); | ||||||
|
||||||
let entity_id = poseidon_hash_many(&[account.address()]); | ||||||
let world_reader = WorldContractReader::new(strat.world_address, account.provider()); | ||||||
|
||||||
let keys = db.get_entity_keys(entity_id, "dojo_examples-Moves").await.unwrap(); | ||||||
assert_eq!(keys, vec![account.address()]); | ||||||
let db = Sql::new(pool.clone(), world_reader.address).await.unwrap(); | ||||||
|
||||||
db.execute().await.unwrap(); | ||||||
// Expect bootstrap_engine to error out due to the existing bug | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
stale comment from when i was trying to see if without the fixes it actually errors out, can be changed to this now |
||||||
let result = bootstrap_engine(world_reader, db.clone(), account.provider()).await; | ||||||
assert!(result.is_ok(), "bootstrap_engine should not fail"); | ||||||
} | ||||||
|
||||||
/// Count the number of rows in a table. | ||||||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.