public async Task deploy_deploys_the_contract() { var spec = new SingleReleaseSpecProvider(ConstantinopleFix.Instance, 1); TestRpcBlockchain testRpc = await TestRpcBlockchain.ForTest(SealEngineType.NethDev).Build(spec); testRpc.TestWallet.UnlockAccount(TestItem.Addresses[0], new SecureString()); await testRpc.AddFunds(TestItem.Addresses[0], 1.Ether()); DepositModule depositModule = new DepositModule( testRpc.TxPoolBridge, testRpc.LogFinder, new DepositConfig() { DepositContractAddress = TestItem.AddressA.ToString() }, LimboLogs.Instance); var result = await depositModule.deposit_deploy(TestItem.Addresses[0]); result.Data.Should().NotBe(null); result.ErrorCode.Should().Be(0); result.Result.Error.Should().BeNull(); result.Result.ResultType.Should().Be(ResultType.Success); await testRpc.AddBlock(); testRpc.BlockTree.Head.Number.Should().Be(5); testRpc.BlockTree.Head.Transactions.Should().Contain(tx => tx.IsContractCreation); var code = testRpc.StateReader .GetCode(testRpc.BlockTree.Head.StateRoot, ContractAddress.From(TestItem.Addresses[0], 0)); code.Should().NotBeEmpty(); }
public async Task can_deposit_32eth() { var spec = new SingleReleaseSpecProvider(ConstantinopleFix.Instance, 1); TestRpcBlockchain testRpc = await TestRpcBlockchain.ForTest(SealEngineType.NethDev).Build(spec); testRpc.TestWallet.UnlockAccount(TestItem.Addresses[0], new SecureString()); await testRpc.AddFunds(TestItem.Addresses[0], 33.Ether()); DepositModule depositModule = new DepositModule( testRpc.TxPoolBridge, testRpc.LogFinder, new DepositConfig(), LimboLogs.Instance); await depositModule.deposit_deploy(TestItem.Addresses[0]); await testRpc.AddBlock(); var contractAddress = ContractAddress.From(TestItem.Addresses[0], 0); await depositModule.deposit_setContractAddress(contractAddress); var result = await depositModule.deposit_make( TestItem.Addresses[0], new byte[48], new byte[32], new byte[96]); result.Data.Should().NotBe(null); result.ErrorCode.Should().Be(0); result.Result.Error.Should().BeNull(); result.Result.ResultType.Should().Be(ResultType.Success); await testRpc.AddBlock(); testRpc.BlockTree.Head.Transactions.Should().Contain(tx => !tx.IsContractCreation); /* if status is 1 then it means that no revert has been made */ testRpc.ReceiptStorage.Get(testRpc.BlockTree.Head)[0].StatusCode.Should().Be(1); }
public async Task can_getLogs() { var spec = new SingleReleaseSpecProvider(ConstantinopleFix.Instance, 1); TestRpcBlockchain testRpc = await TestRpcBlockchain.ForTest(SealEngineType.NethDev).Build(spec); testRpc.TestWallet.UnlockAccount(TestItem.Addresses[0], new SecureString()); await testRpc.AddFunds(TestItem.Addresses[0], 33.Ether()); DepositModule depositModule = new DepositModule( testRpc.TxPoolBridge, testRpc.LogFinder, new DepositConfig() { DepositContractAddress = TestItem.AddressA.ToString() }, LimboLogs.Instance); await depositModule.deposit_deploy(TestItem.Addresses[0]); await testRpc.AddBlock(); var contractAddress = ContractAddress.From(TestItem.Addresses[0], 0); await depositModule.deposit_setContractAddress(contractAddress); await depositModule.deposit_make( TestItem.Addresses[0], GetNonZeroBytes(48), GetNonZeroBytes(32), GetNonZeroBytes(96)); await testRpc.AddBlock(); var all = depositModule.deposit_getAll(); all.Result.Data.Length.Should().Be(1); ulong amount = BinaryPrimitives.ReadUInt64LittleEndian(all.Result.Data[0].Amount); ((BigInteger)amount).Should().Be((BigInteger)32.Ether() / (BigInteger)1.GWei()); }
public virtual Task Execute(CancellationToken cancellationToken) { if (_context.RpcModuleProvider == null) { throw new StepDependencyException(nameof(_context.RpcModuleProvider)); } if (_context.TxPool == null) { throw new StepDependencyException(nameof(_context.TxPool)); } if (_context.BlockTree == null) { throw new StepDependencyException(nameof(_context.BlockTree)); } if (_context.Wallet == null) { throw new StepDependencyException(nameof(_context.Wallet)); } if (_context.SpecProvider == null) { throw new StepDependencyException(nameof(_context.SpecProvider)); } ILogger logger = _context.LogManager.GetClassLogger(); IJsonRpcConfig jsonRpcConfig = _context.Config <IJsonRpcConfig>(); if (!jsonRpcConfig.Enabled) { return(Task.CompletedTask); } // the following line needs to be called in order to make sure that the CLI library is referenced from runner and built alongside if (logger.IsDebug) { logger.Debug($"Resolving CLI ({nameof(CliModuleLoader)})"); } IInitConfig initConfig = _context.Config <IInitConfig>(); INdmConfig ndmConfig = _context.Config <INdmConfig>(); IJsonRpcConfig rpcConfig = _context.Config <IJsonRpcConfig>(); IBaselineConfig baselineConfig = _context.Config <IBaselineConfig>(); INetworkConfig networkConfig = _context.Config <INetworkConfig>(); if (ndmConfig.Enabled && !(_context.NdmInitializer is null) && ndmConfig.ProxyEnabled) { EthModuleProxyFactory proxyFactory = new EthModuleProxyFactory(_context.EthJsonRpcClientProxy, _context.Wallet); _context.RpcModuleProvider.Register(new SingletonModulePool <IEthModule>(proxyFactory, true)); if (logger.IsInfo) { logger.Info("Enabled JSON RPC Proxy for NDM."); } } else { EthModuleFactory ethModuleFactory = new EthModuleFactory(_context.DbProvider, _context.TxPool, _context.Wallet, _context.BlockTree, _context.EthereumEcdsa, _context.MainBlockProcessor, _context.ReceiptFinder, _context.SpecProvider, rpcConfig, _context.BloomStorage, _context.LogManager, initConfig.IsMining); _context.RpcModuleProvider.Register(new BoundedModulePool <IEthModule>(8, ethModuleFactory)); } ProofModuleFactory proofModuleFactory = new ProofModuleFactory(_context.DbProvider, _context.BlockTree, _context.RecoveryStep, _context.ReceiptFinder, _context.SpecProvider, _context.LogManager); _context.RpcModuleProvider.Register(new BoundedModulePool <IProofModule>(2, proofModuleFactory)); DebugModuleFactory debugModuleFactory = new DebugModuleFactory(_context.DbProvider, _context.BlockTree, _context.BlockValidator, _context.RecoveryStep, _context.RewardCalculatorSource, _context.ReceiptStorage, _context.ConfigProvider, _context.SpecProvider, _context.LogManager); _context.RpcModuleProvider.Register(new BoundedModulePool <IDebugModule>(8, debugModuleFactory)); TraceModuleFactory traceModuleFactory = new TraceModuleFactory(_context.DbProvider, _context.BlockTree, _context.RecoveryStep, _context.RewardCalculatorSource, _context.ReceiptStorage, _context.SpecProvider, _context.LogManager); _context.RpcModuleProvider.Register(new BoundedModulePool <ITraceModule>(8, traceModuleFactory)); if (initConfig.EnableUnsecuredDevWallet) { PersonalBridge personalBridge = new PersonalBridge(_context.EthereumEcdsa, _context.Wallet); PersonalModule personalModule = new PersonalModule(personalBridge, _context.LogManager); _context.RpcModuleProvider.Register(new SingletonModulePool <IPersonalModule>(personalModule, true)); } AdminModule adminModule = new AdminModule(_context.BlockTree, networkConfig, _context.PeerManager, _context.StaticNodesManager, _context.Enode, initConfig.BaseDbPath); _context.RpcModuleProvider.Register(new SingletonModulePool <IAdminModule>(adminModule, true)); LogFinder logFinder = new LogFinder( _context.BlockTree, _context.ReceiptFinder, _context.BloomStorage, _context.LogManager, new ReceiptsRecovery(), 1024); if (baselineConfig.Enabled) { BaselineModuleFactory baselineModuleFactory = new BaselineModuleFactory( _context.TxPool, logFinder, _context.BlockTree, _context.AbiEncoder, _context.Wallet, _context.SpecProvider, _context.FileSystem, _context.LogManager); _context.RpcModuleProvider.Register(new SingletonModulePool <IBaselineModule>(baselineModuleFactory, true)); if (logger?.IsInfo ?? false) { logger !.Info($"Baseline RPC Module has been enabled"); } } IDepositConfig depositConfig = _context.Config <IDepositConfig>(); if (depositConfig.DepositContractAddress != null) { TxPoolBridge txPoolBridge = new TxPoolBridge( _context.TxPool, new WalletTxSigner(_context.Wallet, _context.SpecProvider.ChainId), _context.Timestamper); DepositModule depositModule = new DepositModule(txPoolBridge, logFinder, depositConfig, _context.LogManager); _context.RpcModuleProvider.Register(new SingletonModulePool <IDepositModule>(depositModule, true)); } TxPoolModule txPoolModule = new TxPoolModule(_context.BlockTree, _context.TxPoolInfoProvider, _context.LogManager); _context.RpcModuleProvider.Register(new SingletonModulePool <ITxPoolModule>(txPoolModule, true)); NetModule netModule = new NetModule(_context.LogManager, new NetBridge(_context.Enode, _context.SyncServer)); _context.RpcModuleProvider.Register(new SingletonModulePool <INetModule>(netModule, true)); ParityModule parityModule = new ParityModule(_context.EthereumEcdsa, _context.TxPool, _context.BlockTree, _context.ReceiptFinder, _context.LogManager); _context.RpcModuleProvider.Register(new SingletonModulePool <IParityModule>(parityModule, true)); SubsystemStateChanged?.Invoke(this, new SubsystemStateEventArgs(EthereumSubsystemState.Running)); return(Task.CompletedTask); }