Skip to content

Commit

Permalink
temporary comment test
Browse files Browse the repository at this point in the history
  • Loading branch information
breathx committed Sep 29, 2024
1 parent 5dd6b10 commit 35f7da8
Showing 1 changed file with 109 additions and 107 deletions.
216 changes: 109 additions & 107 deletions ethexe/processor/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ fn ping_pong() {
assert_eq!(message.payload_bytes(), b"PONG");
}

#[allow(unused)]
fn create_message(
processor: &mut Processor,
kind: DispatchKind,
Expand Down Expand Up @@ -408,113 +409,114 @@ fn async_and_ping() {
);
}

#[test]
fn many_waits() {
init_logger();

let threads_amount = 8;

let wat = r#"
(module
(import "env" "memory" (memory 1))
(import "env" "gr_reply" (func $reply (param i32 i32 i32 i32)))
(import "env" "gr_wait_for" (func $wait_for (param i32)))
(export "handle" (func $handle))
(func $handle
(if
(i32.eqz (i32.load (i32.const 0x200)))
(then
(i32.store (i32.const 0x200) (i32.const 1))
(call $wait_for (i32.const 10))
)
(else
(call $reply (i32.const 0) (i32.const 13) (i32.const 0x400) (i32.const 0x600))
)
)
)
(data (i32.const 0) "Hello, world!")
)
"#;

let (_, code) = wat_to_wasm(wat);

let db = MemDb::default();
let mut processor = Processor::new(Database::from_one(&db, Default::default())).unwrap();

init_new_block(&mut processor, Default::default());

let code_id = processor
.handle_new_code(code)
.expect("failed to call runtime api")
.expect("code failed verification or instrumentation");

let amount = 10000;
let mut programs = BTreeMap::new();
for i in 0..amount {
let program_id = ProgramId::from(i);

processor
.handle_new_program(program_id, code_id)
.expect("failed to create new program");

let state_hash = processor
.handle_executable_balance_top_up(H256::zero(), 10_000_000_000)
.expect("failed to top up balance");

let message = create_message(&mut processor, DispatchKind::Init, b"");
let state_hash = processor
.handle_message_queueing(state_hash, message)
.expect("failed to populate message queue");

programs.insert(program_id, state_hash);
}

let (to_users, _) = run::run(
threads_amount,
processor.db.clone(),
processor.creator.clone(),
&mut programs,
);
assert_eq!(to_users.len(), amount as usize);

for (_pid, state_hash) in programs.iter_mut() {
let message = create_message(&mut processor, DispatchKind::Handle, b"");
let new_state_hash = processor
.handle_message_queueing(*state_hash, message)
.expect("failed to populate message queue");
*state_hash = new_state_hash;
}

let (to_users, _) = run::run(
threads_amount,
processor.db.clone(),
processor.creator.clone(),
&mut programs,
);
assert_eq!(to_users.len(), 0);

init_new_block(
&mut processor,
BlockHeader {
height: 11,
timestamp: 11,
..Default::default()
},
);

let (to_users, _) = run::run(
threads_amount,
processor.db.clone(),
processor.creator.clone(),
&mut programs,
);

assert_eq!(to_users.len(), amount as usize);

for message in to_users {
assert_eq!(message.payload_bytes(), b"Hello, world!");
}
}
// TODO (breathx).
// #[test]
// fn many_waits() {
// init_logger();

// let threads_amount = 8;

// let wat = r#"
// (module
// (import "env" "memory" (memory 1))
// (import "env" "gr_reply" (func $reply (param i32 i32 i32 i32)))
// (import "env" "gr_wait_for" (func $wait_for (param i32)))
// (export "handle" (func $handle))
// (func $handle
// (if
// (i32.eqz (i32.load (i32.const 0x200)))
// (then
// (i32.store (i32.const 0x200) (i32.const 1))
// (call $wait_for (i32.const 10))
// )
// (else
// (call $reply (i32.const 0) (i32.const 13) (i32.const 0x400) (i32.const 0x600))
// )
// )
// )
// (data (i32.const 0) "Hello, world!")
// )
// "#;

// let (_, code) = wat_to_wasm(wat);

// let db = MemDb::default();
// let mut processor = Processor::new(Database::from_one(&db, Default::default())).unwrap();

// init_new_block(&mut processor, Default::default());

// let code_id = processor
// .handle_new_code(code)
// .expect("failed to call runtime api")
// .expect("code failed verification or instrumentation");

// let amount = 10000;
// let mut programs = BTreeMap::new();
// for i in 0..amount {
// let program_id = ProgramId::from(i);

// processor
// .handle_new_program(program_id, code_id)
// .expect("failed to create new program");

// let state_hash = processor
// .handle_executable_balance_top_up(H256::zero(), 10_000_000_000)
// .expect("failed to top up balance");

// let message = create_message(&mut processor, DispatchKind::Init, b"");
// let state_hash = processor
// .handle_message_queueing(state_hash, message)
// .expect("failed to populate message queue");

// programs.insert(program_id, state_hash);
// }

// let (to_users, _) = run::run(
// threads_amount,
// processor.db.clone(),
// processor.creator.clone(),
// &mut programs,
// );
// assert_eq!(to_users.len(), amount as usize);

// for (_pid, state_hash) in programs.iter_mut() {
// let message = create_message(&mut processor, DispatchKind::Handle, b"");
// let new_state_hash = processor
// .handle_message_queueing(*state_hash, message)
// .expect("failed to populate message queue");
// *state_hash = new_state_hash;
// }

// let (to_users, _) = run::run(
// threads_amount,
// processor.db.clone(),
// processor.creator.clone(),
// &mut programs,
// );
// assert_eq!(to_users.len(), 0);

// init_new_block(
// &mut processor,
// BlockHeader {
// height: 11,
// timestamp: 11,
// ..Default::default()
// },
// );

// let (to_users, _) = run::run(
// threads_amount,
// processor.db.clone(),
// processor.creator.clone(),
// &mut programs,
// );

// assert_eq!(to_users.len(), amount as usize);

// for message in to_users {
// assert_eq!(message.payload_bytes(), b"Hello, world!");
// }
// }

mod utils {
use super::*;
Expand Down

0 comments on commit 35f7da8

Please sign in to comment.