mirror of
https://github.com/logos-blockchain/lssa.git
synced 2026-01-05 23:03:06 +00:00
fix test
This commit is contained in:
parent
00773d7457
commit
7d23983309
@ -15,6 +15,7 @@ pub use nssa_core::program::Program;
|
||||
pub use public_transaction::PublicTransaction;
|
||||
pub use signature::PrivateKey;
|
||||
pub use signature::PublicKey;
|
||||
pub use signature::Signature;
|
||||
pub use state::V01State;
|
||||
|
||||
pub const AUTHENTICATED_TRANSFER_PROGRAM: Program = Program {
|
||||
|
||||
@ -42,7 +42,7 @@ impl Message {
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
|
||||
pub struct WitnessSet {
|
||||
pub(crate) signatures_and_public_keys: Vec<(Signature, PublicKey)>,
|
||||
pub signatures_and_public_keys: Vec<(Signature, PublicKey)>,
|
||||
}
|
||||
|
||||
impl WitnessSet {
|
||||
|
||||
@ -3,10 +3,11 @@ use serde::{Deserialize, Serialize};
|
||||
use crate::public_transaction::Message;
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
|
||||
pub(crate) struct Signature;
|
||||
pub struct Signature(pub(crate) u8);
|
||||
|
||||
// TODO: Dummy impl. Replace by actual private key.
|
||||
// TODO: Remove Debug, Clone, Serialize, Deserialize, PartialEq and Eq for security reasons
|
||||
// TODO: Implement Zeroize
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
|
||||
pub struct PrivateKey(pub(crate) u8);
|
||||
|
||||
@ -28,12 +29,12 @@ impl PublicKey {
|
||||
}
|
||||
|
||||
impl Signature {
|
||||
pub(crate) fn new(_key: &PrivateKey, message: &[u8]) -> Self {
|
||||
Self
|
||||
pub(crate) fn new(key: &PrivateKey, message: &[u8]) -> Self {
|
||||
Signature(key.0)
|
||||
}
|
||||
|
||||
pub(crate) fn is_valid_for(&self, _message: &Message, _public_key: &PublicKey) -> bool {
|
||||
pub fn is_valid_for(&self, _message: &Message, public_key: &PublicKey) -> bool {
|
||||
// TODO: implement
|
||||
true
|
||||
self.0 == public_key.0
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,10 +1,7 @@
|
||||
use std::fmt::Display;
|
||||
|
||||
use anyhow::Result;
|
||||
use common::{
|
||||
block::HashableBlockData,
|
||||
merkle_tree_public::TreeHashType,
|
||||
};
|
||||
use common::{block::HashableBlockData, merkle_tree_public::TreeHashType};
|
||||
use config::SequencerConfig;
|
||||
use mempool::MemPool;
|
||||
use sequencer_store::SequecerChainStore;
|
||||
@ -63,10 +60,18 @@ impl SequencerCore {
|
||||
pub fn transaction_pre_check(
|
||||
&mut self,
|
||||
tx: nssa::PublicTransaction,
|
||||
// tx_roots: [[u8; 32]; 2],
|
||||
) -> Result<nssa::PublicTransaction, TransactionMalformationErrorKind> {
|
||||
// TODO: Stateless checks here
|
||||
Ok(tx)
|
||||
// Stateless checks here
|
||||
if tx
|
||||
.witness_set()
|
||||
.signatures_and_public_keys
|
||||
.iter()
|
||||
.all(|(signature, public_key)| signature.is_valid_for(tx.message(), public_key))
|
||||
{
|
||||
Ok(tx)
|
||||
} else {
|
||||
Err(TransactionMalformationErrorKind::InvalidSignature)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn push_tx_into_mempool_pre_check(
|
||||
@ -92,8 +97,6 @@ impl SequencerCore {
|
||||
) -> Result<nssa::PublicTransaction, ()> {
|
||||
self.store.state.transition_from_public_transaction(&tx)?;
|
||||
|
||||
// self.store.pub_tx_store.add_tx(mempool_tx.auth_tx);
|
||||
|
||||
Ok(tx)
|
||||
}
|
||||
|
||||
@ -139,7 +142,6 @@ mod tests {
|
||||
use crate::config::AccountInitialData;
|
||||
|
||||
use super::*;
|
||||
|
||||
|
||||
fn setup_sequencer_config_variable_initial_accounts(
|
||||
initial_accounts: Vec<AccountInitialData>,
|
||||
@ -396,12 +398,14 @@ mod tests {
|
||||
let tx = common::test_utils::create_dummy_transaction_native_token_transfer(
|
||||
acc1, 0, acc2, 10, sign_key2,
|
||||
);
|
||||
// let tx_roots = sequencer.get_tree_roots();
|
||||
|
||||
// Signature is valid, stateless check pass
|
||||
let tx = sequencer.transaction_pre_check(tx).unwrap();
|
||||
|
||||
// Signature is not from sender. Execution fails
|
||||
let result = sequencer.execute_check_transaction_on_state(tx);
|
||||
|
||||
assert_eq!(result.err().unwrap(), ());
|
||||
assert!(matches!(result, Err(())));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user