node.rs
1 // Copyright (c) 2025 ADnet Contributors 2 // This file is part of the AlphaOS library. 3 4 // Licensed under the Apache License, Version 2.0 (the "License"); 5 // you may not use this file except in compliance with the License. 6 // You may obtain a copy of the License at: 7 8 // http://www.apache.org/licenses/LICENSE-2.0 9 10 // Unless required by applicable law or agreed to in writing, software 11 // distributed under the License is distributed on an "AS IS" BASIS, 12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 // See the License for the specific language governing permissions and 14 // limitations under the License. 15 16 use crate::common::test_peer::sample_genesis_block; 17 18 use alphaos_account::Account; 19 use alphaos_node::{Client, Prover, Validator}; 20 use alphaos_utilities::SignalHandler; 21 22 use alphavm::prelude::{MainnetV0 as CurrentNetwork, store::helpers::memory::ConsensusMemory}; 23 24 use alpha_std::StorageMode; 25 use std::str::FromStr; 26 27 pub async fn client() -> Client<CurrentNetwork, ConsensusMemory<CurrentNetwork>> { 28 Client::new( 29 "127.0.0.1:0".parse().unwrap(), 30 None, 31 10, 32 Account::<CurrentNetwork>::from_str("APrivateKey1zkp2oVPTci9kKcUprnbzMwq95Di1MQERpYBhEeqvkrDirK1").unwrap(), 33 &[], 34 sample_genesis_block(), 35 None, // No CDN. 36 StorageMode::new_test(None), 37 false, // Connect to untrusted peers. 38 None, 39 SignalHandler::new(), 40 ) 41 .await 42 .expect("couldn't create client instance") 43 } 44 45 pub async fn prover() -> Prover<CurrentNetwork, ConsensusMemory<CurrentNetwork>> { 46 Prover::new( 47 "127.0.0.1:0".parse().unwrap(), 48 Account::<CurrentNetwork>::from_str("APrivateKey1zkp2oVPTci9kKcUprnbzMwq95Di1MQERpYBhEeqvkrDirK1").unwrap(), 49 &[], 50 sample_genesis_block(), 51 StorageMode::new_test(None), 52 false, 53 None, 54 SignalHandler::new(), 55 ) 56 .await 57 .expect("couldn't create prover instance") 58 } 59 60 pub async fn validator() -> Validator<CurrentNetwork, ConsensusMemory<CurrentNetwork>> { 61 Validator::new( 62 "127.0.0.1:0".parse().unwrap(), 63 None, 64 None, 65 10, 66 Account::<CurrentNetwork>::from_str("APrivateKey1zkp2oVPTci9kKcUprnbzMwq95Di1MQERpYBhEeqvkrDirK1").unwrap(), 67 &[], 68 &[], 69 sample_genesis_block(), // Should load the current network's genesis block. 70 None, // No CDN. 71 StorageMode::new_test(None), 72 false, // This test requires validators to connect to peers. 73 false, // No dev traffic in production mode. 74 None, 75 SignalHandler::new(), 76 ) 77 .await 78 .expect("couldn't create validator instance") 79 }