Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix test configs #3174

Merged
merged 9 commits into from Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
116 changes: 58 additions & 58 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Expand Up @@ -46,7 +46,7 @@ default-features = false

[workspace.dependencies.snarkvm]
git = "https://github.com/AleoHQ/snarkVM.git"
rev = "01c8b09"
rev = "eefd27d"
#version = "=0.16.18"
features = [ "circuit", "console", "rocks" ]

Expand Down
5 changes: 4 additions & 1 deletion node/bft/src/worker.rs
Expand Up @@ -554,9 +554,12 @@ mod tests {

#[tokio::test]
async fn test_max_redundant_requests() {
const NUM_NODES: u16 = Committee::<CurrentNetwork>::MAX_COMMITTEE_SIZE;

let rng = &mut TestRng::default();
// Sample a committee.
let committee = snarkvm::ledger::committee::test_helpers::sample_committee_for_round_and_size(0, 100, rng);
let committee =
snarkvm::ledger::committee::test_helpers::sample_committee_for_round_and_size(0, NUM_NODES, rng);
let committee_clone = committee.clone();
// Setup the mock ledger.
let mut mock_ledger = MockLedger::default();
Expand Down
6 changes: 4 additions & 2 deletions node/bft/tests/common/primary.rs
Expand Up @@ -29,6 +29,7 @@ use snarkvm::{
console::{
account::{Address, PrivateKey},
algorithms::{Hash, BHP256},
network::Network,
},
ledger::{
block::Block,
Expand Down Expand Up @@ -137,8 +138,9 @@ impl TestNetwork {
.map(|(address, (amount, _))| (*address, (*address, *address, *amount)))
.collect();
let gen_key = *accounts[0].private_key();
let public_balance_per_validator =
(1_500_000_000_000_000 - (config.num_nodes as u64) * 1_000_000_000_000) / (config.num_nodes as u64);
let public_balance_per_validator = (CurrentNetwork::STARTING_SUPPLY
- (config.num_nodes as u64) * MIN_VALIDATOR_STAKE)
/ (config.num_nodes as u64);
let mut balances = IndexMap::<Address<CurrentNetwork>, u64>::new();
for account in accounts.iter() {
balances.insert(account.address(), public_balance_per_validator);
Expand Down
4 changes: 2 additions & 2 deletions node/bft/tests/components/mod.rs
Expand Up @@ -22,7 +22,7 @@ use snarkos_node_bft_ledger_service::LedgerService;
use snarkos_node_bft_storage_service::BFTMemoryService;
use snarkvm::{
console::{account::Address, network::Network},
ledger::{narwhal::BatchHeader, store::helpers::memory::ConsensusMemory},
ledger::{committee::MIN_VALIDATOR_STAKE, narwhal::BatchHeader, store::helpers::memory::ConsensusMemory},
prelude::TestRng,
};

Expand All @@ -42,7 +42,7 @@ pub fn sample_ledger(
committee.members().iter().map(|(address, (amount, _))| (*address, (*address, *address, *amount))).collect();
let gen_key = *accounts[0].private_key();
let public_balance_per_validator =
(1_500_000_000_000_000 - (num_nodes as u64) * 1_000_000_000_000) / (num_nodes as u64);
(CurrentNetwork::STARTING_SUPPLY - (num_nodes as u64) * MIN_VALIDATOR_STAKE) / (num_nodes as u64);
let mut balances = IndexMap::<Address<CurrentNetwork>, u64>::new();
for account in accounts.iter() {
balances.insert(account.address(), public_balance_per_validator);
Expand Down
6 changes: 3 additions & 3 deletions node/bft/tests/components/pending.rs
Expand Up @@ -12,13 +12,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use crate::components::sample_ledger;
use crate::{common::CurrentNetwork, components::sample_ledger};
use snarkos_node_bft::helpers::max_redundant_requests;
use snarkvm::prelude::TestRng;
use snarkvm::{ledger::committee::Committee, prelude::TestRng};

#[test]
fn test_max_redundant_requests() {
const NUM_NODES: u16 = 100;
const NUM_NODES: u16 = Committee::<CurrentNetwork>::MAX_COMMITTEE_SIZE;

// Initialize the RNG.
let rng = &mut TestRng::default();
Expand Down
12 changes: 8 additions & 4 deletions node/bft/tests/components/worker.rs
Expand Up @@ -18,7 +18,7 @@ use crate::{
};
use snarkos_node_bft::helpers::max_redundant_requests;
use snarkvm::{
ledger::narwhal::TransmissionID,
ledger::{committee::Committee, narwhal::TransmissionID},
prelude::{Network, TestRng},
};

Expand All @@ -27,7 +27,7 @@ use std::net::SocketAddr;
#[tokio::test]
#[rustfmt::skip]
async fn test_resend_transmission_request() {
const NUM_NODES: u16 = 100;
const NUM_NODES: u16 = Committee::<CurrentNetwork>::MAX_COMMITTEE_SIZE;

// Initialize the RNG.
let rng = &mut TestRng::default();
Expand All @@ -36,6 +36,10 @@ async fn test_resend_transmission_request() {
// Sample a worker.
let worker = sample_worker(0, ledger.clone());

// Determine the maximum number of redundant requests.
let max_redundancy = max_redundant_requests(ledger.clone(), 0);
assert_eq!(max_redundancy, 34, "Update me if the formula changes");
raychu86 marked this conversation as resolved.
Show resolved Hide resolved

// Prepare a dummy transmission ID.
let peer_ip = SocketAddr::from(([127, 0, 0, 1], 1234));
let transmission_id = TransmissionID::Transaction(<CurrentNetwork as Network>::TransactionID::default());
Expand Down Expand Up @@ -75,14 +79,14 @@ async fn test_resend_transmission_request() {
// Ensure the number of callbacks is correct.
assert_eq!(pending.num_callbacks(transmission_id), 1 + i, "Incorrect number of callbacks for transmission");
// Ensure the number of sent requests is correct.
assert_eq!(pending.num_sent_requests(transmission_id), 1 + i, "Incorrect number of sent requests for transmission");
assert_eq!(pending.num_sent_requests(transmission_id), (1 + i).min(max_redundancy), "Incorrect number of sent requests for transmission");
}
}

#[tokio::test]
#[rustfmt::skip]
async fn test_flood_transmission_requests() {
const NUM_NODES: u16 = 100;
const NUM_NODES: u16 = Committee::<CurrentNetwork>::MAX_COMMITTEE_SIZE;

// Initialize the RNG.
let rng = &mut TestRng::default();
Expand Down