synchronization_chain.rs 37.8 KiB
Newer Older
		let storage = Arc::new(db::Storage::new(path.as_path()).unwrap());
		storage.insert_block(&b0).expect("no db error");

		let mut chain = Chain::new(storage);
		chain.verify_transaction(tx1_hash.clone(), tx1);
		chain.insert_verified_transaction(tx2);

		// no reorg
		let result = chain.insert_best_block(b1.hash(), &b1).expect("no error");
		assert_eq!(result.transactions_to_reverify.len(), 0);

		// no reorg
		let result = chain.insert_best_block(b2.hash(), &b2).expect("no error");
		assert_eq!(result.transactions_to_reverify.len(), 0);

		// reorg
		let result = chain.insert_best_block(b3.hash(), &b3).expect("no error");
		assert_eq!(result.transactions_to_reverify.len(), 2);
		assert!(result.transactions_to_reverify.iter().any(|&(ref h, _)| h == &tx1_hash));
		assert!(result.transactions_to_reverify.iter().any(|&(ref h, _)| h == &tx2_hash));
	}