Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
hansieodendaal committed Jan 14, 2024
1 parent 8e43eec commit e391021
Showing 1 changed file with 29 additions and 5 deletions.
34 changes: 29 additions & 5 deletions base_layer/core/tests/tests/horizon_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

use tari_core::{base_node::state_machine_service::states::StateEvent, chain_storage::BlockchainDatabaseConfig};
use std::sync::Arc;
use tari_core::{base_node::state_machine_service::states::StateEvent, chain_storage::BlockchainDatabaseConfig, txn_schema};
use tari_core::transactions::tari_amount::T;
use tari_core::transactions::test_helpers::schema_to_transaction;

use crate::helpers::{sync, sync::WhatToDelete};

Expand Down Expand Up @@ -59,19 +62,40 @@ async fn test_horizon_sync_to_archival_node_happy_path() {
);

// Create a blockchain with many blocks
let (blocks, _coinbases) = sync::create_and_add_some_blocks(
let (blocks_a, coinbases_a) = sync::create_and_add_some_blocks(
&bob_node,
&initial_block,
&initial_coinbase,
40,
20,
&consensus_manager,
&key_manager,
&[3; 40],
&[3; 20],
&None,
)
.await;
// Create a transaction to spend some coinbase outputs
let schema = txn_schema!(
from: vec![coinbases_a[0].clone(), coinbases_a[1].clone(), coinbases_a[2].clone(), coinbases_a[3].clone(), coinbases_a[4].clone()],
to: vec![1000 * T; 20]
);
let (txns, _outputs) = schema_to_transaction(&[schema], &key_manager).await;
let txns = txns.into_iter().map(|t| Arc::try_unwrap(t).unwrap()).collect::<Vec<_>>();
// Expand the blockchain with the spend transaction
let (blocks_b, _coinbases) = sync::create_and_add_some_blocks(
&bob_node,
&blocks_a[20],
&coinbases_a[20],
20,
&consensus_manager,
&key_manager,
&[3; 20],
&Some(vec![txns]),
)
.await;
assert_eq!(bob_node.blockchain_db.get_height().unwrap(), 40);
assert_eq!(bob_node.blockchain_db.fetch_last_header().unwrap().height, 40);
let blocks = [&blocks_a[..], &blocks_b[1..]].concat();

// Now rewind Bob's chain to height 10
sync::delete_some_blocks_and_headers(&blocks[10..=40], WhatToDelete::BlocksAndHeaders, &bob_node);
assert_eq!(bob_node.blockchain_db.get_height().unwrap(), 10);
Expand Down Expand Up @@ -175,7 +199,7 @@ async fn test_horizon_sync_to_archival_node_happy_path() {
// Bob will not be banned
assert!(!sync::wait_for_is_peer_banned(&alice_node, bob_node.node_identity.node_id(), 1).await);

// Give Bob some more blocks
// Give Bob some more blocks (containing the block with the spend transaction at height 21)
sync::add_some_existing_blocks(&blocks[21..=40], &bob_node);
assert_eq!(bob_node.blockchain_db.get_height().unwrap(), 40);
assert_eq!(bob_node.blockchain_db.fetch_last_header().unwrap().height, 40);
Expand Down

0 comments on commit e391021

Please sign in to comment.