public void Test_Block_Emulation() { _blockManager.TryBuildGenesisBlock(); var block = BuildNextBlock(); Assert.AreEqual(OperatingError.Ok, EmulateBlock(block)); }
public void Test_StakeWithdraw() { _blockManager.TryBuildGenesisBlock(); GenerateBlocks(1, 1); _validatorStatusManager.Start(false); Assert.IsTrue(_validatorStatusManager.IsStarted()); Assert.IsFalse(_validatorStatusManager.IsWithdrawTriggered()); int blockNum = (int)_blockManager.GetHeight(); Assert.IsFalse(HardforkHeights.IsHardfork_9Active((ulong)blockNum)); while (!HardforkHeights.IsHardfork_9Active((ulong)blockNum)) { blockNum++; GenerateBlocks(blockNum, blockNum); } var systemContractReader = _container?.Resolve <ISystemContractReader>() ?? throw new Exception("Container is not loaded"); var stake = new Money(systemContractReader.GetStake()); Console.WriteLine($"Current stake is {stake}"); Assert.That(stake > Money.Zero, "Stake is zero"); _validatorStatusManager.WithdrawStakeAndStop(); Assert.IsTrue(_validatorStatusManager.IsStarted()); Assert.IsTrue(_validatorStatusManager.IsWithdrawTriggered()); // Test node is the only validator, so it is a next validator always // and it can't withdraw its stake. TODO: test to check withdraw is working //GenerateBlocks(50); //Assert.IsFalse(_validatorStatusManager.IsStarted()); }
public void Test_Tx_Pool_Adding() { TestTxPoolAdding(); _blockManager.TryBuildGenesisBlock(); Assert.IsFalse(HardforkHeights.IsHardfork_9Active(_blockManager.GetHeight())); while (!HardforkHeights.IsHardfork_9Active(_blockManager.GetHeight())) { var block = BuildNextBlock(); var result = ExecuteBlock(block); Assert.AreEqual(OperatingError.Ok, result); } TestTxPoolAdding(); }
public void Setup() { TestUtils.DeleteTestChainData(); var containerBuilder = new SimpleInjectorContainerBuilder(new ConfigManager( Path.Join(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "config.json"), new RunOptions() )); containerBuilder.RegisterModule <BlockchainModule>(); containerBuilder.RegisterModule <ConfigModule>(); containerBuilder.RegisterModule <StorageModule>(); _container = containerBuilder.Build(); _blockManager = _container.Resolve <IBlockManager>(); _transactionBuilder = _container.Resolve <ITransactionBuilder>(); _stateManager = _container.Resolve <IStateManager>(); _wallet = _container.Resolve <IPrivateWallet>(); _transactionPool = _container.Resolve <ITransactionPool>(); _configManager = _container.Resolve <IConfigManager>(); // set chainId from config if (TransactionUtils.ChainId(false) == 0) { var chainId = _configManager.GetConfig <NetworkConfig>("network")?.ChainId; var newChainId = _configManager.GetConfig <NetworkConfig>("network")?.NewChainId; TransactionUtils.SetChainId((int)chainId !, (int)newChainId !); HardforkHeights.SetHardforkHeights(_configManager.GetConfig <HardforkConfig>("hardfork") ?? throw new InvalidOperationException()); } _blockManager.TryBuildGenesisBlock(); }
// changed from private to public: GetStateHashFromTrieRootsRange() , GetStateHashFromTrieRoots() public void Test_Web3StateHashFromTrieRoots() { _blockManager.TryBuildGenesisBlock(); ulong total = 5; GenerateBlocks(total, 1); ulong startBlock = 0, endBlock = total; var stateHash = _apiService.GetStateHashFromTrieRootsRange(startBlock.ToHex(), endBlock.ToHex()); Assert.AreEqual(stateHash ![startBlock.ToHex(false)], stateHash[endBlock.ToHex(false)]);
public void Test_EventFormat() { _blockManager.TryBuildGenesisBlock(); TestEventFormat(); Assert.IsFalse(HardforkHeights.IsHardfork_9Active(_blockManager.GetHeight())); while (!HardforkHeights.IsHardfork_9Active(_blockManager.GetHeight())) { GenerateBlocks(1); } TestEventFormat(); }
// Changed GetTransactionCount to public public void Test_GetTransactionCount_latest() { _blockManager.TryBuildGenesisBlock(); var tx = TestUtils.GetRandomTransaction(HardforkHeights.IsHardfork_9Active(1)); // adding balance so that it's transaction is added to the pool _stateManager.LastApprovedSnapshot.Balances.AddBalance(tx.Transaction.From, Money.Parse("1000")); var txCountBefore = _apiService !.GetTransactionCount(tx.Transaction.From.ToHex(), "latest").HexToUlong(); Assert.AreEqual(txCountBefore, 0); var result = _transactionPool.Add(tx); Assert.AreEqual(OperatingError.Ok, result); GenerateBlocks(1); var txCountAfter = _apiService !.GetTransactionCount(tx.Transaction.From.ToHex(), "latest").HexToUlong(); Assert.AreEqual(txCountAfter, 1); }
//changed GetTransactionReceipt from private to public public void Test_GetTransactionReceipt() { _blockManager.TryBuildGenesisBlock(); var tx = TestUtils.GetRandomTransaction(HardforkHeights.IsHardfork_9Active(1)); _stateManager.LastApprovedSnapshot.Balances.AddBalance(tx.Transaction.From, Money.Parse("1000")); var result = _transactionPool.Add(tx); Assert.AreEqual(OperatingError.Ok, result); GenerateBlocks(1, 1); var txHashSent = tx.Hash.ToHex(); var txReceipt = _apiService.GetTransactionReceipt(txHashSent); var txHashReceived = txReceipt !["transactionHash"] !.ToString();
public void Setup() { _container?.Dispose(); TestUtils.DeleteTestChainData(); var containerBuilder = new SimpleInjectorContainerBuilder(new ConfigManager( Path.Join(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "config2.json"), new RunOptions() )); containerBuilder.RegisterModule <BlockchainModule>(); containerBuilder.RegisterModule <ConfigModule>(); containerBuilder.RegisterModule <StorageModule>(); _container = containerBuilder.Build(); _configManager = _container.Resolve <IConfigManager>(); _stateManager = _container.Resolve <IStateManager>(); _contractRegisterer = _container.Resolve <IContractRegisterer>(); _privateWallet = _container.Resolve <IPrivateWallet>(); _snapshotIndexer = _container.Resolve <ISnapshotIndexRepository>(); _systemContractReader = _container.Resolve <ISystemContractReader>(); _transactionManager = _container.Resolve <ITransactionManager>(); _transactionBuilder = _container.Resolve <ITransactionBuilder>(); _transactionSigner = _container.Resolve <ITransactionSigner>(); _transactionPool = _container.Resolve <ITransactionPool>(); _blockManager = _container.Resolve <IBlockManager>(); // set chainId from config if (TransactionUtils.ChainId(false) == 0) { var chainId = _configManager.GetConfig <NetworkConfig>("network")?.ChainId; var newChainId = _configManager.GetConfig <NetworkConfig>("network")?.ChainId; TransactionUtils.SetChainId((int)chainId !, (int)newChainId !); HardforkHeights.SetHardforkHeights(_configManager.GetConfig <HardforkConfig>("hardfork") ?? throw new InvalidOperationException()); } ServiceBinder.BindService <GenericParameterAttributes>(); _apiService = new AccountServiceWeb3(_stateManager, _snapshotIndexer, _contractRegisterer, _systemContractReader, _transactionPool); _transactionApiService = new TransactionServiceWeb3(_stateManager, _transactionManager, _transactionBuilder, _transactionSigner, _transactionPool, _contractRegisterer, _privateWallet); _blockManager.TryBuildGenesisBlock(); }
public void Start(RunOptions options) { _blockManager = _container.Resolve <IBlockManager>(); _configManager = _container.Resolve <IConfigManager>(); _stateManager = _container.Resolve <IStateManager>(); _transactionBuilder = _container.Resolve <ITransactionBuilder>(); _transactionPool = _container.Resolve <ITransactionPool>(); _transactionSigner = _container.Resolve <ITransactionSigner>(); _wallet = _container.Resolve <IPrivateWallet>(); var keyPair = _wallet.EcdsaKeyPair; Console.WriteLine("-------------------------------"); Console.WriteLine("Private Key: " + keyPair.PrivateKey.Encode().ToHex()); Console.WriteLine("Public Key: " + keyPair.PublicKey.EncodeCompressed().ToHex()); Console.WriteLine("Address: " + Crypto.ComputeAddress(keyPair.PublicKey.EncodeCompressed()).ToHex()); Console.WriteLine("-------------------------------"); if (_blockManager.TryBuildGenesisBlock()) { Console.WriteLine("Generated genesis block"); } var genesisBlock = _stateManager.LastApprovedSnapshot.Blocks.GetBlockByHeight(0); Console.WriteLine("Genesis Block: " + genesisBlock !.Hash.ToHex()); Console.WriteLine($" + prevBlockHash: {genesisBlock.Header.PrevBlockHash.ToHex()}"); Console.WriteLine($" + merkleRoot: {genesisBlock.Header.MerkleRoot.ToHex()}"); Console.WriteLine($" + nonce: {genesisBlock.Header.Nonce}"); Console.WriteLine($" + transactionHashes: {genesisBlock.TransactionHashes.Count}"); foreach (var s in genesisBlock.TransactionHashes) { Console.WriteLine($" + - {s.ToHex()}"); } Console.WriteLine($" + hash: {genesisBlock.Hash.ToHex()}"); var address1 = "0xe3c7a20ee19c0107b9121087bcba18eb4dcb8576".HexToUInt160(); var address2 = "0x6bc32575acb8754886dc283c2c8ac54b1bd93195".HexToUInt160(); Console.WriteLine("-------------------------------"); // Console.WriteLine("Current block header height: " + blockchainContext.CurrentBlockHeight); Console.WriteLine("-------------------------------"); Console.WriteLine("Balance of LA 0x3e: " + _stateManager.LastApprovedSnapshot.Balances.GetBalance(address1)); Console.WriteLine("Balance of LA 0x6b: " + _stateManager.LastApprovedSnapshot.Balances.GetBalance(address2)); Console.WriteLine("-------------------------------"); Logger.LogInformation($"Setting chainId"); var chainId = _configManager.GetConfig <NetworkConfig>("network")?.ChainId ?? 42; var newChainId = _configManager.GetConfig <NetworkConfig>("network")?.NewChainId ?? chainId; TransactionUtils.SetChainId((int)chainId, newChainId); // _BenchTxProcessing(_transactionBuilder, _transactionSigner, keyPair); // _BenchOneTxInBlock(_transactionBuilder, _transactionSigner, keyPair); Console.WriteLine("---------------START - TX POOL BENCHMARK----------------"); _Bench_Tx_Pool(_transactionBuilder, _transactionSigner, keyPair); Console.WriteLine("---------------END - TX POOL BENCHMARK----------------"); Console.WriteLine("---------------START - BLOCK EMULATE BENCHMARK----------------"); _Bench_Emulate_Block(_transactionBuilder, _transactionSigner, keyPair); Console.WriteLine("---------------END - BLOCK EMULATE BENCHMARK----------------"); Console.WriteLine("---------------START - BLOCK EMULATE + EXECUTE BENCHMARK----------------"); _Bench_Emulate_Execute_Tx(_transactionBuilder, _transactionSigner, keyPair); Console.WriteLine("---------------END - BLOCK EMULATE + EXECUTE BENCHMARK----------------"); Console.WriteLine("---------------START - MULTIPLE BLOCKS EMULATE + EXECUTE BENCHMARK----------------"); _Bench_Execute_Blocks(_transactionBuilder, _transactionSigner, keyPair); Console.WriteLine("---------------END - MULTIPLE BLOCKS EMULATE + EXECUTE BENCHMARK----------------"); Environment.Exit(0); }