Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit 9ffccbb

Browse files
Alex6323grtlr
andauthored
feat(test): add more db query tests (#699)
* Test 'get_block_children' * Test 'get_spending_transaction' * Add test 'test_ledger_updates_by_address' * Add test 'test_ledger_updates_by_milestone' * Add test 'test_spent_unspent_ledger_updates' * Use 'count_documents' * Prep milestone tests * Add 'len' to 'MongoDbCollectionExt' trait with enabled 'rand' feature * Use 'MongoDbCollectionExt' count * Clippy * Fmt * Go away now * Rename claiming test module * Make MongoDbCollection trait async * Fix merge * Simplify collection creation in launch code * Format * Slight refactor * Use generic setup helper * Improve spending transaction test * Temporarily create only 1 unspent output for the spending tx * Ensure all inputs fetch the spending block * Format * Fix docs * PR comments 1 * Simplify * Cleanup * PR comments 2 * Format * Add protocol parameters test * Format and clean up * PR comments 3 * Fix Co-authored-by: Jochen Görtler <[email protected]>
1 parent 85cf674 commit 9ffccbb

19 files changed

+588
-74
lines changed

src/db/collections/block.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ impl BlockCollection {
181181
doc! { "$skip": (page_size * page) as i64 },
182182
doc! { "$sort": {"metadata.referenced_by_milestone_index": -1} },
183183
doc! { "$limit": page_size as i64 },
184-
doc! { "$replaceWith": { "block_id": "$metadata.block_id" } },
184+
doc! { "$replaceWith": { "block_id": "$_id" } },
185185
],
186186
None,
187187
)

src/db/collections/protocol_update.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::{
1313
};
1414

1515
/// A milestone's metadata.
16-
#[derive(Clone, Debug, Serialize, Deserialize)]
16+
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
1717
pub struct ProtocolUpdateDocument {
1818
#[serde(rename = "_id")]
1919
pub tangle_index: MilestoneIndex,

src/types/stardust/block/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,16 @@ mod rand {
146146
nonce: rand_number(),
147147
}
148148
}
149+
150+
/// Generates a random [`Block`] with given parents.
151+
pub fn rand_no_payload_with_parents(parents: Box<[BlockId]>) -> Self {
152+
Self {
153+
protocol_version: rand_number(),
154+
parents,
155+
payload: None,
156+
nonce: rand_number(),
157+
}
158+
}
149159
}
150160
}
151161

src/types/stardust/block/output/mod.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ pub use self::{
2828
native_token::{NativeToken, NativeTokenAmount, TokenScheme},
2929
nft::{NftId, NftOutput},
3030
treasury::TreasuryOutput,
31+
unlock_condition::{
32+
AddressUnlockCondition, ExpirationUnlockCondition, GovernorAddressUnlockCondition,
33+
ImmutableAliasAddressUnlockCondition, StateControllerAddressUnlockCondition,
34+
StorageDepositReturnUnlockCondition, TimelockUnlockCondition,
35+
},
3136
};
3237
use super::Address;
3338
use crate::types::{
@@ -45,7 +50,7 @@ pub type OutputIndex = u16;
4550

4651
/// An id which uniquely identifies an output. It is computed from the corresponding [`TransactionId`], as well as the
4752
/// [`OutputIndex`].
48-
#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
53+
#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Hash)]
4954
pub struct OutputId {
5055
/// The transaction id part of the [`OutputId`].
5156
pub transaction_id: TransactionId,
@@ -244,7 +249,7 @@ mod rand {
244249
impl Output {
245250
/// Generates a random [`Output`].
246251
pub fn rand(ctx: &bee_block_stardust::protocol::ProtocolParameters) -> Self {
247-
match rand_number_range(0..5) {
252+
match rand_number_range(0..4) {
248253
0 => Self::rand_basic(ctx),
249254
1 => Self::rand_alias(ctx),
250255
2 => Self::rand_foundry(ctx),

src/types/stardust/block/output/unlock_condition/address.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ use serde::{Deserialize, Serialize};
88

99
use crate::types::stardust::block::Address;
1010

11+
/// Defines the Address that owns an output.
1112
#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
1213
pub struct AddressUnlockCondition {
14+
/// The associated address of this [`AddressUnlockCondition`].
1315
pub address: Address,
1416
}
1517

src/types/stardust/block/output/unlock_condition/expiration.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ use serde::{Deserialize, Serialize};
88

99
use crate::types::stardust::{block::Address, milestone::MilestoneTimestamp};
1010

11+
/// Defines a unix time until which only Address, defined in Address Unlock Condition, is allowed to unlock the output.
12+
/// After or at the unix time, only Return Address can unlock it.
1113
#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
1214
pub struct ExpirationUnlockCondition {
1315
return_address: Address,

src/types/stardust/block/output/unlock_condition/governor_address.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ use serde::{Deserialize, Serialize};
88

99
use crate::types::stardust::block::Address;
1010

11+
/// Defines the Governor Address that owns this output, that is, it can unlock it with the proper Unlock in a
12+
/// transaction that governance transitions the alias output.
1113
#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
1214
pub struct GovernorAddressUnlockCondition {
15+
/// The associated address of this [`GovernorAddressUnlockCondition`].
1316
pub address: Address,
1417
}
1518

src/types/stardust/block/output/unlock_condition/immutable_alias_address.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ use serde::{Deserialize, Serialize};
88

99
use crate::types::stardust::block::Address;
1010

11+
/// Defines the permanent alias address that owns this output.
1112
#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
1213
pub struct ImmutableAliasAddressUnlockCondition {
14+
/// The associated address of this [`ImmutableAliasAddressUnlockCondition`].
1315
pub address: Address,
1416
}
1517

src/types/stardust/block/output/unlock_condition/state_controller_address.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ use serde::{Deserialize, Serialize};
88

99
use crate::types::stardust::block::Address;
1010

11+
/// Defines the State Controller Address that owns this output, that is, it can unlock it with the proper Unlock in a
12+
/// transaction that state transitions the alias output.
1113
#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
1214
pub struct StateControllerAddressUnlockCondition {
15+
/// The associated address of this [`StateControllerAddressUnlockCondition`].
1316
pub address: Address,
1417
}
1518

src/types/stardust/block/output/unlock_condition/storage_deposit_return.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use serde::{Deserialize, Serialize};
99
use super::OutputAmount;
1010
use crate::types::{context::TryFromWithContext, stardust::block::Address};
1111

12+
/// Defines the amount of tokens used as storage deposit that have to be returned to the return address.
1213
#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
1314
pub struct StorageDepositReturnUnlockCondition {
1415
return_address: Address,

src/types/stardust/block/output/unlock_condition/timelock.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use serde::{Deserialize, Serialize};
88

99
use crate::types::stardust::milestone::MilestoneTimestamp;
1010

11+
/// Defines a unix timestamp until which the output can not be unlocked.
1112
#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
1213
pub struct TimelockUnlockCondition {
1314
timestamp: MilestoneTimestamp,

src/types/stardust/block/payload/transaction.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use crate::types::{
1616
};
1717

1818
/// Uniquely identifies a transaction.
19-
#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
19+
#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Hash)]
2020
#[serde(transparent)]
2121
pub struct TransactionId(#[serde(with = "bytify")] pub [u8; Self::LENGTH]);
2222

0 commit comments

Comments
 (0)