mirror of
https://github.com/logos-blockchain/logos-execution-zone.git
synced 2026-06-26 00:49:27 +00:00
fix(tests): fix tests
This commit is contained in:
parent
c74b03582b
commit
96b28827f6
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -9459,7 +9459,9 @@ dependencies = [
|
||||
"borsh",
|
||||
"common",
|
||||
"lee",
|
||||
"programs",
|
||||
"rocksdb",
|
||||
"system_accounts",
|
||||
"tempfile",
|
||||
"thiserror 2.0.18",
|
||||
]
|
||||
|
||||
@ -10,7 +10,7 @@ use log::info;
|
||||
pub use test_fixtures::*;
|
||||
|
||||
/// Maximum time to wait for the indexer to catch up to the sequencer.
|
||||
pub const L2_TO_L1_TIMEOUT: Duration = Duration::from_mins(6);
|
||||
pub const L2_TO_L1_TIMEOUT: Duration = Duration::from_mins(7);
|
||||
|
||||
/// Poll the indexer until its last finalized block id reaches the sequencer's
|
||||
/// current last block id or until [`L2_TO_L1_TIMEOUT`] elapses.
|
||||
|
||||
@ -68,9 +68,10 @@ async fn deploy_and_execute_program() -> Result<()> {
|
||||
|
||||
let post_state_account = ctx.sequencer_client().get_account(account_id).await?;
|
||||
|
||||
let expected_data: &[u8] = &[];
|
||||
assert_eq!(post_state_account.program_owner, claimer.id());
|
||||
assert_eq!(post_state_account.balance, 0);
|
||||
assert_eq!(post_state_account.data.as_ref(), &[0]);
|
||||
assert_eq!(post_state_account.data.as_ref(), expected_data);
|
||||
assert_eq!(post_state_account.nonce.0, 1);
|
||||
|
||||
info!("Successfully deployed and executed program");
|
||||
|
||||
@ -1585,8 +1585,7 @@ fn test_wallet_ffi_transfer_generic_public() -> Result<()> {
|
||||
let instruction_words_size = instruction_data.len();
|
||||
let instruction_words = Box::into_raw(instruction_data.into_boxed_slice()) as *const u32;
|
||||
|
||||
let program: ProgramWithDependencies = programs::authenticated_transfer().into();
|
||||
let program_with_dependencies: FfiProgramWithDependencies = program.into();
|
||||
let program_id = programs::authenticated_transfer().id();
|
||||
|
||||
unsafe {
|
||||
wallet_ffi_send_generic_public_transaction(
|
||||
|
||||
@ -667,7 +667,7 @@ mod tests {
|
||||
/// to `PrivateAccountKind::Regular` carrying the correct identifier.
|
||||
#[test]
|
||||
fn private_authorized_init_encrypts_regular_kind_with_identifier() {
|
||||
let program = crate::test_methods::simple_balance_transfer();
|
||||
let program = crate::test_methods::claimer();
|
||||
let keys = test_private_account_keys_1();
|
||||
let identifier: u128 = 99;
|
||||
let ssk = SharedSecretKey::encapsulate_deterministic(&keys.vpk(), &[0_u8; 32], 0).0;
|
||||
@ -676,7 +676,7 @@ mod tests {
|
||||
|
||||
let (output, _) = execute_and_prove(
|
||||
vec![pre],
|
||||
Program::serialize_instruction(0).unwrap(),
|
||||
Program::serialize_instruction(()).unwrap(),
|
||||
vec![InputAccountIdentity::PrivateAuthorizedInit {
|
||||
epk: EphemeralPublicKey(Vec::new()),
|
||||
view_tag: EncryptedAccountData::compute_view_tag(&keys.npk(), &keys.vpk()),
|
||||
@ -698,36 +698,23 @@ mod tests {
|
||||
/// to `PrivateAccountKind::Regular` carrying the correct identifier.
|
||||
#[test]
|
||||
fn private_unauthorized_init_encrypts_regular_kind_with_identifier() {
|
||||
let program = crate::test_methods::simple_balance_transfer();
|
||||
let program = crate::test_methods::claimer();
|
||||
let keys = test_private_account_keys_1();
|
||||
let identifier: u128 = 99;
|
||||
let ssk = SharedSecretKey::encapsulate_deterministic(&keys.vpk(), &[0_u8; 32], 0).0;
|
||||
|
||||
let sender = AccountWithMetadata::new(
|
||||
Account {
|
||||
program_owner: program.id(),
|
||||
balance: 1,
|
||||
..Account::default()
|
||||
},
|
||||
true,
|
||||
AccountId::new([0; 32]),
|
||||
);
|
||||
let recipient_id = AccountId::for_regular_private_account(&keys.npk(), identifier);
|
||||
let recipient = AccountWithMetadata::new(Account::default(), false, recipient_id);
|
||||
|
||||
let (output, _) = execute_and_prove(
|
||||
vec![sender, recipient],
|
||||
Program::serialize_instruction(1).unwrap(),
|
||||
vec![
|
||||
InputAccountIdentity::Public,
|
||||
InputAccountIdentity::PrivateUnauthorized {
|
||||
epk: EphemeralPublicKey(Vec::new()),
|
||||
view_tag: EncryptedAccountData::compute_view_tag(&keys.npk(), &keys.vpk()),
|
||||
npk: keys.npk(),
|
||||
ssk,
|
||||
identifier,
|
||||
},
|
||||
],
|
||||
vec![recipient],
|
||||
Program::serialize_instruction(()).unwrap(),
|
||||
vec![InputAccountIdentity::PrivateUnauthorized {
|
||||
epk: EphemeralPublicKey(Vec::new()),
|
||||
view_tag: EncryptedAccountData::compute_view_tag(&keys.npk(), &keys.vpk()),
|
||||
npk: keys.npk(),
|
||||
ssk,
|
||||
identifier,
|
||||
}],
|
||||
&program.into(),
|
||||
)
|
||||
.unwrap();
|
||||
@ -742,7 +729,7 @@ mod tests {
|
||||
/// to `PrivateAccountKind::Regular` carrying the correct identifier.
|
||||
#[test]
|
||||
fn private_authorized_update_encrypts_regular_kind_with_identifier() {
|
||||
let program = crate::test_methods::simple_balance_transfer();
|
||||
let program = crate::test_methods::noop();
|
||||
let keys = test_private_account_keys_1();
|
||||
let identifier: u128 = 99;
|
||||
let ssk = SharedSecretKey::encapsulate_deterministic(&keys.vpk(), &[0_u8; 32], 0).0;
|
||||
@ -757,22 +744,18 @@ mod tests {
|
||||
commitment_set.extend(std::slice::from_ref(&commitment));
|
||||
|
||||
let sender = AccountWithMetadata::new(account, true, account_id);
|
||||
let recipient = AccountWithMetadata::new(Account::default(), true, AccountId::new([0; 32]));
|
||||
|
||||
let (output, _) = execute_and_prove(
|
||||
vec![sender, recipient],
|
||||
Program::serialize_instruction(1).unwrap(),
|
||||
vec![
|
||||
InputAccountIdentity::PrivateAuthorizedUpdate {
|
||||
epk: EphemeralPublicKey(Vec::new()),
|
||||
view_tag: EncryptedAccountData::compute_view_tag(&keys.npk(), &keys.vpk()),
|
||||
ssk,
|
||||
nsk: keys.nsk,
|
||||
membership_proof: commitment_set.get_proof_for(&commitment).unwrap(),
|
||||
identifier,
|
||||
},
|
||||
InputAccountIdentity::Public,
|
||||
],
|
||||
vec![sender],
|
||||
Program::serialize_instruction(()).unwrap(),
|
||||
vec![InputAccountIdentity::PrivateAuthorizedUpdate {
|
||||
epk: EphemeralPublicKey(Vec::new()),
|
||||
view_tag: EncryptedAccountData::compute_view_tag(&keys.npk(), &keys.vpk()),
|
||||
ssk,
|
||||
nsk: keys.nsk,
|
||||
membership_proof: commitment_set.get_proof_for(&commitment).unwrap(),
|
||||
identifier,
|
||||
}],
|
||||
&program.into(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
@ -364,6 +364,27 @@ pub mod tests {
|
||||
self.insert_program(crate::test_methods::data_changer());
|
||||
self.insert_program(crate::test_methods::minter());
|
||||
self.insert_program(crate::test_methods::burner());
|
||||
self.insert_program(crate::test_methods::auth_asserting_noop());
|
||||
self.insert_program(crate::test_methods::private_pda_delegator());
|
||||
self.insert_program(crate::test_methods::pda_claimer());
|
||||
self.insert_program(crate::test_methods::two_pda_claimer());
|
||||
self.insert_program(crate::test_methods::noop());
|
||||
self.insert_program(crate::test_methods::chain_caller());
|
||||
self.insert_program(crate::test_methods::modified_transfer_program());
|
||||
self.insert_program(crate::test_methods::malicious_authorization_changer());
|
||||
self.insert_program(crate::test_methods::validity_window());
|
||||
self.insert_program(crate::test_methods::flash_swap_initiator());
|
||||
self.insert_program(crate::test_methods::flash_swap_callback());
|
||||
self.insert_program(crate::test_methods::malicious_self_program_id());
|
||||
self.insert_program(crate::test_methods::malicious_caller_program_id());
|
||||
self.insert_program(crate::test_methods::pda_spend_proxy());
|
||||
self.insert_program(crate::test_methods::claimer());
|
||||
self.insert_program(crate::test_methods::changer_claimer());
|
||||
self.insert_program(crate::test_methods::validity_window_chain_caller());
|
||||
self.insert_program(crate::test_methods::simple_transfer_proxy());
|
||||
self.insert_program(crate::test_methods::malicious_injector());
|
||||
self.insert_program(crate::test_methods::malicious_launderer());
|
||||
self.insert_program(crate::test_methods::modified_transfer_program());
|
||||
self
|
||||
}
|
||||
|
||||
@ -474,6 +495,7 @@ pub mod tests {
|
||||
(
|
||||
account_id,
|
||||
Account {
|
||||
program_owner: crate::test_methods::simple_balance_transfer().id(),
|
||||
balance,
|
||||
..Account::default()
|
||||
},
|
||||
@ -599,6 +621,7 @@ pub mod tests {
|
||||
let initial_data = [(
|
||||
account_id,
|
||||
Account {
|
||||
program_owner: crate::test_methods::simple_balance_transfer().id(),
|
||||
balance: 100,
|
||||
..Account::default()
|
||||
},
|
||||
@ -638,6 +661,7 @@ pub mod tests {
|
||||
let initial_data = [(
|
||||
account_id,
|
||||
Account {
|
||||
program_owner: crate::test_methods::simple_balance_transfer().id(),
|
||||
balance: 100,
|
||||
..Account::default()
|
||||
},
|
||||
@ -694,6 +718,7 @@ pub mod tests {
|
||||
(
|
||||
account_id1,
|
||||
Account {
|
||||
program_owner: crate::test_methods::simple_balance_transfer().id(),
|
||||
balance: 100,
|
||||
..Account::default()
|
||||
},
|
||||
@ -701,6 +726,7 @@ pub mod tests {
|
||||
(
|
||||
account_id2,
|
||||
Account {
|
||||
program_owner: crate::test_methods::simple_balance_transfer().id(),
|
||||
balance: 200,
|
||||
..Account::default()
|
||||
},
|
||||
@ -734,6 +760,7 @@ pub mod tests {
|
||||
let initial_data = [(
|
||||
account_id1,
|
||||
Account {
|
||||
program_owner: crate::test_methods::simple_balance_transfer().id(),
|
||||
balance: 100,
|
||||
..Account::default()
|
||||
},
|
||||
@ -1504,6 +1531,7 @@ pub mod tests {
|
||||
.with_public_accounts([(
|
||||
recipient_keys.account_id(),
|
||||
Account {
|
||||
program_owner: crate::test_methods::simple_balance_transfer().id(),
|
||||
balance: recipient_initial_balance,
|
||||
..Account::default()
|
||||
},
|
||||
@ -2667,7 +2695,7 @@ pub mod tests {
|
||||
assert_eq!(state.get_account_by_id(account_id), Account::default());
|
||||
|
||||
let message =
|
||||
public_transaction::Message::try_new(program.id(), vec![account_id], vec![], 0)
|
||||
public_transaction::Message::try_new(program.id(), vec![account_id], vec![], 0_u128)
|
||||
.unwrap();
|
||||
let witness_set = public_transaction::WitnessSet::for_message(&message, &[]);
|
||||
let tx = PublicTransaction::new(message, witness_set);
|
||||
@ -2687,9 +2715,13 @@ pub mod tests {
|
||||
|
||||
assert_eq!(state.get_account_by_id(account_id), Account::default());
|
||||
|
||||
let message =
|
||||
public_transaction::Message::try_new(program.id(), vec![account_id], vec![Nonce(0)], 0)
|
||||
.unwrap();
|
||||
let message = public_transaction::Message::try_new(
|
||||
program.id(),
|
||||
vec![account_id],
|
||||
vec![Nonce(0)],
|
||||
0_u128,
|
||||
)
|
||||
.unwrap();
|
||||
let witness_set = public_transaction::WitnessSet::for_message(&message, &[&account_key]);
|
||||
let tx = PublicTransaction::new(message, witness_set);
|
||||
|
||||
@ -2899,7 +2931,7 @@ pub mod tests {
|
||||
|
||||
let result = execute_and_prove(
|
||||
vec![public_account],
|
||||
Program::serialize_instruction(0).unwrap(),
|
||||
Program::serialize_instruction(0_u128).unwrap(),
|
||||
vec![InputAccountIdentity::Public],
|
||||
&program.into(),
|
||||
);
|
||||
@ -3190,7 +3222,7 @@ pub mod tests {
|
||||
AccountWithMetadata::new(state.get_account_by_id(recipient_id), false, sender_id);
|
||||
|
||||
let message = public_transaction::Message::try_new(
|
||||
crate::test_methods::modified_transfer_program().id(),
|
||||
modified_transfer_id,
|
||||
vec![sender_id, recipient_id],
|
||||
vec![sender_nonce],
|
||||
balance_to_move,
|
||||
@ -3255,7 +3287,7 @@ pub mod tests {
|
||||
let (shared_secret, epk) =
|
||||
SharedSecretKey::encapsulate_deterministic(&private_keys.vpk(), &[0_u8; 32], 0);
|
||||
|
||||
let instruction = 0;
|
||||
let instruction: u128 = 0;
|
||||
|
||||
// Execute and prove the circuit with the authorized account but no commitment proof
|
||||
let (output, proof) = execute_and_prove(
|
||||
@ -3307,7 +3339,7 @@ pub mod tests {
|
||||
|
||||
let (output, proof) = execute_and_prove(
|
||||
vec![unauthorized_account],
|
||||
Program::serialize_instruction(0_u128).unwrap(),
|
||||
Program::serialize_instruction(()).unwrap(),
|
||||
vec![InputAccountIdentity::PrivateUnauthorized {
|
||||
epk,
|
||||
view_tag: EncryptedAccountData::compute_view_tag(
|
||||
@ -3353,7 +3385,7 @@ pub mod tests {
|
||||
let (shared_secret, epk) =
|
||||
SharedSecretKey::encapsulate_deterministic(&private_keys.vpk(), &[0_u8; 32], 0);
|
||||
|
||||
let instruction = 0;
|
||||
let instruction = ();
|
||||
|
||||
// Step 2: Execute claimer program to claim the account with authentication
|
||||
let (output, proof) = execute_and_prove(
|
||||
|
||||
@ -533,6 +533,7 @@ mod tests {
|
||||
(
|
||||
account_id,
|
||||
Account {
|
||||
program_owner: crate::test_methods::simple_balance_transfer().id(),
|
||||
balance,
|
||||
..Account::default()
|
||||
},
|
||||
@ -558,7 +559,7 @@ mod tests {
|
||||
));
|
||||
let program_id = crate::test_methods::simple_balance_transfer().id();
|
||||
let message =
|
||||
Message::try_new(program_id, vec![from, to], vec![Nonce(0), Nonce(0)], 5).unwrap();
|
||||
Message::try_new(program_id, vec![from, to], vec![Nonce(0), Nonce(0)], 5_u128).unwrap();
|
||||
let witness_set = WitnessSet::for_message(&message, &[&from_key, &to_key]);
|
||||
let tx = crate::PublicTransaction::new(message, witness_set);
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
use lee_core::program::{AccountPostState, ProgramInput, ProgramOutput, read_lee_inputs};
|
||||
use lee_core::program::{AccountPostState, Claim, ProgramInput, ProgramOutput, read_lee_inputs};
|
||||
|
||||
type Instruction = u128;
|
||||
|
||||
@ -13,6 +13,21 @@ fn main() {
|
||||
instruction_words,
|
||||
) = read_lee_inputs::<Instruction>();
|
||||
|
||||
if let Ok([account_pre]) = <[_; 1]>::try_from(pre_states.clone()) {
|
||||
let account_post =
|
||||
AccountPostState::new_claimed_if_default(account_pre.account, Claim::Authorized);
|
||||
|
||||
ProgramOutput::new(
|
||||
self_program_id,
|
||||
caller_program_id,
|
||||
instruction_words,
|
||||
pre_states,
|
||||
vec![account_post],
|
||||
)
|
||||
.write();
|
||||
return;
|
||||
}
|
||||
|
||||
let Ok([sender_pre, receiver_pre]) = <[_; 2]>::try_from(pre_states) else {
|
||||
return;
|
||||
};
|
||||
@ -34,8 +49,8 @@ fn main() {
|
||||
instruction_words,
|
||||
vec![sender_pre, receiver_pre],
|
||||
vec![
|
||||
AccountPostState::new(sender_post),
|
||||
AccountPostState::new(receiver_post),
|
||||
AccountPostState::new_claimed_if_default(sender_post, Claim::Authorized),
|
||||
AccountPostState::new_claimed_if_default(receiver_post, Claim::Authorized),
|
||||
],
|
||||
)
|
||||
.write();
|
||||
|
||||
@ -1609,6 +1609,7 @@ mod tests {
|
||||
nonce: Nonce(0xdead_beef),
|
||||
data: Data::default(),
|
||||
};
|
||||
let bridge_account_id = system_accounts::bridge_account_id();
|
||||
|
||||
let mut state = V03State::new()
|
||||
.with_public_accounts([(bridge_account_id, system_accounts::bridge_account())])
|
||||
@ -1618,7 +1619,6 @@ mod tests {
|
||||
)]);
|
||||
|
||||
let sender_commitment = Commitment::new(&sender_account_id, &sender_private_account);
|
||||
let bridge_account_id = system_accounts::bridge_account_id();
|
||||
|
||||
let sender_pre = AccountWithMetadata::new(
|
||||
sender_private_account,
|
||||
|
||||
@ -15,3 +15,7 @@ thiserror.workspace = true
|
||||
borsh.workspace = true
|
||||
rocksdb.workspace = true
|
||||
tempfile.workspace = true
|
||||
|
||||
[dev-dependencies]
|
||||
programs.workspace = true
|
||||
system_accounts.workspace = true
|
||||
|
||||
@ -295,6 +295,7 @@ mod tests {
|
||||
(
|
||||
id,
|
||||
Account {
|
||||
program_owner: programs::authenticated_transfer().id(),
|
||||
balance,
|
||||
..Account::default()
|
||||
},
|
||||
|
||||
@ -233,6 +233,7 @@ fn initial_public_accounts() -> HashMap<AccountId, Account> {
|
||||
(
|
||||
acc_data.account_id,
|
||||
Account {
|
||||
program_owner: programs::authenticated_transfer().id(),
|
||||
balance: acc_data.balance,
|
||||
..Default::default()
|
||||
},
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user