Skip to content

Commit

Permalink
remove transactions in test
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeanmichel7 committed Aug 3, 2024
1 parent 5e75469 commit ff242e5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
14 changes: 7 additions & 7 deletions src/state.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub struct ChainState {
pub epoch_start_time: u32,
/// Previous timestamps.
pub prev_timestamps: Span<u32>,
// TODO: utreexo_roots?
// TODO: utreexo_roots?
}

/// Represents a block in the blockchain.
Expand Down Expand Up @@ -65,22 +65,22 @@ pub struct Transaction {
#[derive(Drop, Copy)]
pub struct TxOut {
/// The value of the output.
pub value: i64,
value: i64,
/// The public key script of the output.
pub pk_script: @ByteArray,
pk_script: @ByteArray,
}

/// Input of a transaction.
/// https://developer.bitcoin.org/reference/transactions.html#txin-a-transaction-input-non-coinbase
#[derive(Drop, Copy)]
pub struct TxIn {
/// The transaction ID of the input.
pub txid: u256,
txid: u256,
/// The index of the input.
pub index: u32,
index: u32,
/// The script of the input.
pub script: @ByteArray,
script: @ByteArray,
/// The sequence of the input.
pub sequence: u32,
sequence: u32,
}

16 changes: 7 additions & 9 deletions src/validation.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ fn validate_merkle_root(self: @ChainState, block: @Block) -> Result<(), ByteArra
mod tests {
use core::result::ResultTrait;
use super::validate_target;
use super::{Block, ChainState,};
use super::{Block, ChainState};
use super::super::state::{Header, Transaction, TxIn, TxOut};
use core::array::{Span};

Expand All @@ -85,15 +85,13 @@ mod tests {
epoch_start_time: 1,
prev_timestamps: array![1, 2, 3, 4, 5].span(),
};
let txIn = TxIn { txid: 1, index: 1, script: @"1", sequence: 1, };
let txOut = TxOut { value: 1, pk_script: @"1", };
let transaction = Transaction {
version: 1, inputs: array![txIn].span(), outputs: array![txOut].span(), lock_time: 1,
let mut block = Block {
header: Header {
version: 1, prev_block_hash: 1, merkle_root_hash: 1, time: 1, bits: 1, nonce: 1,
},
txs: ArrayTrait::new().span(),
};
let header = Header {
version: 1, prev_block_hash: 1, merkle_root_hash: 1, time: 1, bits: 1, nonce: 1,
};
let mut block = Block { header: header, txs: array![transaction].span() };

let result = validate_target(@chain_state, @block);
assert(result.is_ok(), 'Expected target to be valid');

Expand Down

0 comments on commit ff242e5

Please sign in to comment.