mirror of
https://github.com/alexgo-io/stacks-puppet-node.git
synced 2026-05-13 09:08:02 +08:00
fix nonce tests
This commit is contained in:
@@ -811,7 +811,7 @@ pub mod test {
|
||||
conn.connection().as_transaction(
|
||||
|tx| StacksChainState::account_credit(tx, &addr.to_account_principal(), 223));
|
||||
|
||||
let (fee, _) = StacksChainState::process_transaction(&mut conn, &signed_tx, true).unwrap();
|
||||
let (fee, _) = StacksChainState::process_transaction(&mut conn, &signed_tx, false).unwrap();
|
||||
|
||||
let account_after = StacksChainState::get_account(&mut conn, &addr.to_account_principal());
|
||||
assert_eq!(account_after.nonce, 1);
|
||||
@@ -848,7 +848,7 @@ pub mod test {
|
||||
assert_eq!(recv_account.stx_balance, 0);
|
||||
assert_eq!(recv_account.nonce, 0);
|
||||
|
||||
let (fee, _) = StacksChainState::process_transaction(&mut conn, &signed_tx, true).unwrap();
|
||||
let (fee, _) = StacksChainState::process_transaction(&mut conn, &signed_tx, false).unwrap();
|
||||
|
||||
let account_after = StacksChainState::get_account(&mut conn, &addr.to_account_principal());
|
||||
assert_eq!(account_after.nonce, 2);
|
||||
@@ -961,7 +961,7 @@ pub mod test {
|
||||
assert_eq!(account.stx_balance, 123);
|
||||
assert_eq!(account.nonce, 0);
|
||||
|
||||
let res = StacksChainState::process_transaction(&mut conn, &signed_tx, true);
|
||||
let res = StacksChainState::process_transaction(&mut conn, &signed_tx, false);
|
||||
assert!(res.is_err());
|
||||
|
||||
match res {
|
||||
@@ -1028,7 +1028,7 @@ pub mod test {
|
||||
conn.connection().as_transaction(
|
||||
|tx| StacksChainState::account_credit(tx, &addr.to_account_principal(), 123));
|
||||
|
||||
let (fee, _) = StacksChainState::process_transaction(&mut conn, &signed_tx, true).unwrap();
|
||||
let (fee, _) = StacksChainState::process_transaction(&mut conn, &signed_tx, false).unwrap();
|
||||
|
||||
let account_after = StacksChainState::get_account(&mut conn, &addr.to_account_principal());
|
||||
assert_eq!(account_after.nonce, 1);
|
||||
@@ -1082,7 +1082,7 @@ pub mod test {
|
||||
let account = StacksChainState::get_account(&mut conn, &addr.to_account_principal());
|
||||
assert_eq!(account.nonce, 0);
|
||||
|
||||
let (fee, _) = StacksChainState::process_transaction(&mut conn, &signed_tx, true).unwrap();
|
||||
let (fee, _) = StacksChainState::process_transaction(&mut conn, &signed_tx, false).unwrap();
|
||||
|
||||
let account = StacksChainState::get_account(&mut conn, &addr.to_account_principal());
|
||||
assert_eq!(account.nonce, 1);
|
||||
@@ -1160,7 +1160,7 @@ pub mod test {
|
||||
let account = StacksChainState::get_account(&mut conn, &addr.to_account_principal());
|
||||
assert_eq!(account.nonce, next_nonce);
|
||||
|
||||
let res = StacksChainState::process_transaction(&mut conn, &signed_tx, true);
|
||||
let res = StacksChainState::process_transaction(&mut conn, &signed_tx, false);
|
||||
if expected_behavior[i] {
|
||||
assert!(res.is_ok());
|
||||
|
||||
@@ -1247,7 +1247,7 @@ pub mod test {
|
||||
assert_eq!(account.nonce, i as u64);
|
||||
|
||||
// runtime error should be handled
|
||||
let (_fee, _) = StacksChainState::process_transaction(&mut conn, &signed_tx, true).unwrap();
|
||||
let (_fee, _) = StacksChainState::process_transaction(&mut conn, &signed_tx, false).unwrap();
|
||||
|
||||
// account nonce should increment
|
||||
let account = StacksChainState::get_account(&mut conn, &addr.to_account_principal());
|
||||
@@ -1307,7 +1307,7 @@ pub mod test {
|
||||
let _account_sponsor = StacksChainState::get_account(&mut conn, &addr_sponsor.to_account_principal());
|
||||
assert_eq!(account.nonce, 0);
|
||||
|
||||
let (fee, _) = StacksChainState::process_transaction(&mut conn, &signed_tx, true).unwrap();
|
||||
let (fee, _) = StacksChainState::process_transaction(&mut conn, &signed_tx, false).unwrap();
|
||||
|
||||
let account = StacksChainState::get_account(&mut conn, &addr.to_account_principal());
|
||||
assert_eq!(account.nonce, 1);
|
||||
@@ -1383,12 +1383,12 @@ pub mod test {
|
||||
let var_before_res = StacksChainState::get_data_var(&mut conn, &contract_id, "bar").unwrap();
|
||||
assert!(var_before_res.is_none());
|
||||
|
||||
let (fee, _) = StacksChainState::process_transaction(&mut conn, &signed_tx, true).unwrap();
|
||||
let (fee, _) = StacksChainState::process_transaction(&mut conn, &signed_tx, false).unwrap();
|
||||
|
||||
let var_before_set_res = StacksChainState::get_data_var(&mut conn, &contract_id, "bar").unwrap();
|
||||
assert_eq!(var_before_set_res, Some(Value::Int(0)));
|
||||
|
||||
let (fee_2, _) = StacksChainState::process_transaction(&mut conn, &signed_tx_2, true).unwrap();
|
||||
let (fee_2, _) = StacksChainState::process_transaction(&mut conn, &signed_tx_2, false).unwrap();
|
||||
|
||||
let account = StacksChainState::get_account(&mut conn, &addr.to_account_principal());
|
||||
assert_eq!(account.nonce, 1);
|
||||
@@ -1439,7 +1439,7 @@ pub mod test {
|
||||
let mut conn = chainstate.block_begin(&FIRST_BURNCHAIN_BLOCK_HASH, &FIRST_STACKS_BLOCK_HASH, &BurnchainHeaderHash([1u8; 32]), &BlockHeaderHash([1u8; 32]));
|
||||
|
||||
let contract_id = QualifiedContractIdentifier::new(StandardPrincipalData::from(addr.clone()), ContractName::from("hello-world"));
|
||||
let (_fee, _) = StacksChainState::process_transaction(&mut conn, &signed_tx, true).unwrap();
|
||||
let (_fee, _) = StacksChainState::process_transaction(&mut conn, &signed_tx, false).unwrap();
|
||||
|
||||
// contract-calls that don't commit
|
||||
let contract_calls = vec![
|
||||
@@ -1472,7 +1472,7 @@ pub mod test {
|
||||
let account_2 = StacksChainState::get_account(&mut conn, &addr_2.to_account_principal());
|
||||
assert_eq!(account_2.nonce, next_nonce);
|
||||
|
||||
let (_fee, _) = StacksChainState::process_transaction(&mut conn, &signed_tx_2, true).unwrap();
|
||||
let (_fee, _) = StacksChainState::process_transaction(&mut conn, &signed_tx_2, false).unwrap();
|
||||
|
||||
// nonce should have incremented
|
||||
next_nonce += 1;
|
||||
@@ -1521,7 +1521,7 @@ pub mod test {
|
||||
let signed_tx = signer.get_tx().unwrap();
|
||||
|
||||
let mut conn = chainstate.block_begin(&FIRST_BURNCHAIN_BLOCK_HASH, &FIRST_STACKS_BLOCK_HASH, &BurnchainHeaderHash([1u8; 32]), &BlockHeaderHash([1u8; 32]));
|
||||
let (_fee, _) = StacksChainState::process_transaction(&mut conn, &signed_tx, true).unwrap();
|
||||
let (_fee, _) = StacksChainState::process_transaction(&mut conn, &signed_tx, false).unwrap();
|
||||
|
||||
// invalid contract-calls
|
||||
let contract_calls = vec![
|
||||
@@ -1554,7 +1554,7 @@ pub mod test {
|
||||
assert_eq!(account_2.nonce, next_nonce);
|
||||
|
||||
// transaction is invalid, and won't be mined
|
||||
let res = StacksChainState::process_transaction(&mut conn, &signed_tx_2, true);
|
||||
let res = StacksChainState::process_transaction(&mut conn, &signed_tx_2, false);
|
||||
assert!(res.is_err());
|
||||
|
||||
// nonce should NOT have incremented
|
||||
@@ -1640,7 +1640,7 @@ pub mod test {
|
||||
let var_before_res = StacksChainState::get_data_var(&mut conn, &contract_id, "bar").unwrap();
|
||||
assert!(var_before_res.is_none());
|
||||
|
||||
let (fee, _) = StacksChainState::process_transaction(&mut conn, &signed_tx, true).unwrap();
|
||||
let (fee, _) = StacksChainState::process_transaction(&mut conn, &signed_tx, false).unwrap();
|
||||
|
||||
let account_publisher = StacksChainState::get_account(&mut conn, &addr_publisher.to_account_principal());
|
||||
assert_eq!(account_publisher.nonce, 1);
|
||||
@@ -1648,7 +1648,7 @@ pub mod test {
|
||||
let var_before_set_res = StacksChainState::get_data_var(&mut conn, &contract_id, "bar").unwrap();
|
||||
assert_eq!(var_before_set_res, Some(Value::Int(0)));
|
||||
|
||||
let (fee_2, _) = StacksChainState::process_transaction(&mut conn, &signed_tx_2, true).unwrap();
|
||||
let (fee_2, _) = StacksChainState::process_transaction(&mut conn, &signed_tx_2, false).unwrap();
|
||||
|
||||
let account_origin = StacksChainState::get_account(&mut conn, &addr_origin.to_account_principal());
|
||||
assert_eq!(account_origin.nonce, 1);
|
||||
@@ -2002,7 +2002,7 @@ pub mod test {
|
||||
let _ = StacksChainState::get_account_ft(&mut conn, &contract_id, "stackaroos", &recv_principal).unwrap_err();
|
||||
|
||||
// publish contract
|
||||
let _ = StacksChainState::process_transaction(&mut conn, &signed_contract_tx, true).unwrap();
|
||||
let _ = StacksChainState::process_transaction(&mut conn, &signed_contract_tx, false).unwrap();
|
||||
|
||||
// no initial stackaroos balance
|
||||
let account_stackaroos_balance = StacksChainState::get_account_ft(&mut conn, &contract_id, "stackaroos", &recv_principal).unwrap();
|
||||
@@ -2015,7 +2015,7 @@ pub mod test {
|
||||
let mut expected_next_name : u64 = 0;
|
||||
|
||||
for tx_pass in post_conditions_pass.iter() {
|
||||
let (_fee, _) = StacksChainState::process_transaction(&mut conn, &tx_pass, true).unwrap();
|
||||
let (_fee, _) = StacksChainState::process_transaction(&mut conn, &tx_pass, false).unwrap();
|
||||
expected_stackaroos_balance += 100;
|
||||
expected_nonce += 1;
|
||||
|
||||
@@ -2027,7 +2027,7 @@ pub mod test {
|
||||
}
|
||||
|
||||
for tx_pass in post_conditions_pass_payback.iter() {
|
||||
let (_fee, _) = StacksChainState::process_transaction(&mut conn, &tx_pass, true).unwrap();
|
||||
let (_fee, _) = StacksChainState::process_transaction(&mut conn, &tx_pass, false).unwrap();
|
||||
expected_stackaroos_balance -= 100;
|
||||
expected_payback_stackaroos_balance += 100;
|
||||
expected_recv_nonce += 1;
|
||||
@@ -2046,7 +2046,7 @@ pub mod test {
|
||||
}
|
||||
|
||||
for (_i, tx_pass) in post_conditions_pass_nft.iter().enumerate() {
|
||||
let (_fee, _) = StacksChainState::process_transaction(&mut conn, &tx_pass, true).unwrap();
|
||||
let (_fee, _) = StacksChainState::process_transaction(&mut conn, &tx_pass, false).unwrap();
|
||||
expected_nonce += 1;
|
||||
|
||||
let expected_value = Value::buff_from(expected_next_name.to_be_bytes().to_vec()).unwrap();
|
||||
@@ -2060,7 +2060,7 @@ pub mod test {
|
||||
}
|
||||
|
||||
for tx_fail in post_conditions_fail.iter() {
|
||||
let (_fee, _) = StacksChainState::process_transaction(&mut conn, &tx_fail, true).unwrap();
|
||||
let (_fee, _) = StacksChainState::process_transaction(&mut conn, &tx_fail, false).unwrap();
|
||||
expected_nonce += 1;
|
||||
|
||||
// no change in balance
|
||||
@@ -2076,7 +2076,7 @@ pub mod test {
|
||||
}
|
||||
|
||||
for tx_fail in post_conditions_fail_payback.iter() {
|
||||
let (_fee, _) = StacksChainState::process_transaction(&mut conn, &tx_fail, true).unwrap();
|
||||
let (_fee, _) = StacksChainState::process_transaction(&mut conn, &tx_fail, false).unwrap();
|
||||
expected_recv_nonce += 1;
|
||||
|
||||
// no change in balance
|
||||
@@ -2096,7 +2096,7 @@ pub mod test {
|
||||
}
|
||||
|
||||
for (_i, tx_fail) in post_conditions_fail_nft.iter().enumerate() {
|
||||
let (_fee, _) = StacksChainState::process_transaction(&mut conn, &tx_fail, true).unwrap();
|
||||
let (_fee, _) = StacksChainState::process_transaction(&mut conn, &tx_fail, false).unwrap();
|
||||
expected_nonce += 1;
|
||||
|
||||
// nft shouldn't exist -- the nft-mint! should have been rolled back
|
||||
@@ -2404,7 +2404,7 @@ pub mod test {
|
||||
let _ = StacksChainState::get_account_ft(&mut conn, &contract_id, "stackaroos", &recv_principal).unwrap_err();
|
||||
|
||||
// publish contract
|
||||
let _ = StacksChainState::process_transaction(&mut conn, &signed_contract_tx, true).unwrap();
|
||||
let _ = StacksChainState::process_transaction(&mut conn, &signed_contract_tx, false).unwrap();
|
||||
|
||||
// no initial stackaroos balance
|
||||
let account_stackaroos_balance = StacksChainState::get_account_ft(&mut conn, &contract_id, "stackaroos", &recv_principal).unwrap();
|
||||
@@ -2416,7 +2416,7 @@ pub mod test {
|
||||
let mut expected_payback_stackaroos_balance = 0;
|
||||
|
||||
for (_i, tx_pass) in post_conditions_pass.iter().enumerate() {
|
||||
let (_fee, _) = StacksChainState::process_transaction(&mut conn, &tx_pass, true).unwrap();
|
||||
let (_fee, _) = StacksChainState::process_transaction(&mut conn, &tx_pass, false).unwrap();
|
||||
expected_stackaroos_balance += 100;
|
||||
expected_nonce += 1;
|
||||
|
||||
@@ -2439,7 +2439,7 @@ pub mod test {
|
||||
}
|
||||
|
||||
for (_i, tx_pass) in post_conditions_pass_payback.iter().enumerate() {
|
||||
let (_fee, _) = StacksChainState::process_transaction(&mut conn, &tx_pass, true).unwrap();
|
||||
let (_fee, _) = StacksChainState::process_transaction(&mut conn, &tx_pass, false).unwrap();
|
||||
expected_stackaroos_balance -= 100;
|
||||
expected_payback_stackaroos_balance += 100;
|
||||
expected_recv_nonce += 1;
|
||||
@@ -2471,7 +2471,7 @@ pub mod test {
|
||||
}
|
||||
|
||||
for (_i, tx_fail) in post_conditions_fail.iter().enumerate() {
|
||||
let (_fee, _) = StacksChainState::process_transaction(&mut conn, &tx_fail, true).unwrap();
|
||||
let (_fee, _) = StacksChainState::process_transaction(&mut conn, &tx_fail, false).unwrap();
|
||||
expected_nonce += 1;
|
||||
|
||||
// no change in balance
|
||||
@@ -2497,7 +2497,7 @@ pub mod test {
|
||||
|
||||
for (_i, tx_fail) in post_conditions_fail_payback.iter().enumerate() {
|
||||
eprintln!("tx fail {:?}", &tx_fail);
|
||||
let (_fee, _) = StacksChainState::process_transaction(&mut conn, &tx_fail, true).unwrap();
|
||||
let (_fee, _) = StacksChainState::process_transaction(&mut conn, &tx_fail, false).unwrap();
|
||||
expected_recv_nonce += 1;
|
||||
|
||||
// no change in balance
|
||||
@@ -3291,8 +3291,8 @@ pub mod test {
|
||||
let signed_contract_call_tx = signer.get_tx().unwrap();
|
||||
|
||||
let mut conn = chainstate.block_begin(&FIRST_BURNCHAIN_BLOCK_HASH, &FIRST_STACKS_BLOCK_HASH, &BurnchainHeaderHash([1u8; 32]), &BlockHeaderHash([1u8; 32]));
|
||||
let (fee, _) = StacksChainState::process_transaction(&mut conn, &signed_contract_tx, true).unwrap();
|
||||
let err = StacksChainState::process_transaction(&mut conn, &signed_contract_call_tx, true).unwrap_err();
|
||||
let (fee, _) = StacksChainState::process_transaction(&mut conn, &signed_contract_tx, false).unwrap();
|
||||
let err = StacksChainState::process_transaction(&mut conn, &signed_contract_call_tx, false).unwrap_err();
|
||||
conn.commit_block();
|
||||
|
||||
eprintln!("{:?}", &err);
|
||||
|
||||
Reference in New Issue
Block a user