public void Trace_block_null()
        {
            IBlockchainBridge blockchainBridge = Substitute.For <IBlockchainBridge>();
            ITracer           tracer           = Substitute.For <ITracer>();

            ITraceModule module = new TraceModule(blockchainBridge, NullLogManager.Instance, tracer);

            string serialized = RpcTest.TestSerializedRequest(TraceModuleFactory.Converters, module, "trace_block", "earliest");

            Assert.AreEqual("{\"id\":67,\"jsonrpc\":\"2.0\",\"result\":null}", serialized);
        }
Beispiel #2
0
 public NdmBlockchainBridge(
     IBlockchainBridge blockchainBridge,
     IBlockFinder blockTree,
     IStateReader stateReader,
     ITxSender txSender)
 {
     _blockchainBridge = blockchainBridge ?? throw new ArgumentNullException(nameof(blockchainBridge));
     _txSender         = txSender ?? throw new ArgumentNullException(nameof(txSender));
     _blockTree        = blockTree ?? throw new ArgumentNullException(nameof(blockTree));
     _stateReader      = stateReader ?? throw new ArgumentNullException(nameof(stateReader));
 }
 public DepositConfirmationService(IBlockchainBridge blockchainBridge, IConsumerNotifier consumerNotifier,
                                   IDepositDetailsRepository depositRepository, IDepositService depositService, ILogManager logManager,
                                   uint requiredBlockConfirmations)
 {
     _blockchainBridge           = blockchainBridge;
     _consumerNotifier           = consumerNotifier;
     _depositRepository          = depositRepository;
     _depositService             = depositService;
     _logger                     = logManager.GetClassLogger();
     _requiredBlockConfirmations = requiredBlockConfirmations;
 }
        public async Task Ok_when_code_is_valid()
        {
            IBlockchainBridge bridge = Substitute.For <IBlockchainBridge>();

            _ndmBridge = new NdmBlockchainBridge(bridge, _txPool);
            DepositService depositService  = new DepositService(_ndmBridge, _txPool, _abiEncoder, _wallet, _contractAddress, LimboLogs.Instance);
            Address        contractAddress = new Address(_ndmConfig.ContractAddress);

            bridge.GetCode(contractAddress).Returns(Bytes.FromHexString(ContractData.DeployedCode));
            await depositService.ValidateContractAddressAsync(contractAddress);
        }
        public void Throws_when_unexpected_code()
        {
            IBlockchainBridge bridge = Substitute.For <IBlockchainBridge>();

            _ndmBridge = new NdmBlockchainBridge(bridge, _txPool);
            DepositService depositService  = new DepositService(_ndmBridge, _txPool, _abiEncoder, _wallet, _contractAddress, LimboLogs.Instance);
            Address        contractAddress = new Address(_ndmConfig.ContractAddress);

            bridge.GetCode(contractAddress).Returns(Bytes.FromHexString("0xa234"));
            Assert.ThrowsAsync <InvalidDataException>(async() => await depositService.ValidateContractAddressAsync(contractAddress));
        }
        public void Eth_get_block_by_hash()
        {
            IBlockchainBridge bridge = Substitute.For <IBlockchainBridge>();

            bridge.FindBlock(Arg.Any <Keccak>(), Arg.Any <bool>()).Returns(Build.A.Block.WithTotalDifficulty(0).WithTransactions(Build.A.Transaction.TestObject).TestObject);

            IEthModule module = new EthModule(NullLogManager.Instance, bridge);

            string serialized = RpcTest.TestSerializedRequest(module, "eth_getBlockByHash", TestItem.KeccakA.ToString(), "true");

            Assert.AreEqual("{\"id\":\"0x43\",\"jsonrpc\":\"2.0\",\"result\":{\"number\":\"0x0\",\"hash\":\"0xa2a9f03b9493046696099d27b2612b99497aa1f392ec966716ab393c715a5bb6\",\"parentHash\":\"0xff483e972a04a9a62bb4b7d04ae403c615604e4090521ecc5bb7af67f71be09c\",\"nonce\":\"0x3e8\",\"mixHash\":\"0x2ba5557a4c62a513c7e56d1bf13373e0da6bec016755483e91589fe1c6d212e2\",\"sha3Uncles\":\"0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347\",\"logsBloom\":\"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\",\"transactionsRoot\":\"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421\",\"stateRoot\":\"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421\",\"receiptsRoot\":\"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421\",\"miner\":\"0x0000000000000000000000000000000000000000\",\"difficulty\":\"0xf4240\",\"totalDifficulty\":\"0x0\",\"extraData\":\"0x010203\",\"size\":\"0x0\",\"gasLimit\":\"0x3d0900\",\"gasUsed\":\"0x0\",\"timestamp\":\"0xf4240\",\"transactions\":[{\"hash\":null,\"nonce\":\"0x0\",\"blockHash\":\"0xa2a9f03b9493046696099d27b2612b99497aa1f392ec966716ab393c715a5bb6\",\"blockNumber\":\"0x0\",\"transactionIndex\":\"0x0\",\"from\":null,\"to\":\"0x0000000000000000000000000000000000000000\",\"value\":\"0x1\",\"gasPrice\":\"0x1\",\"gas\":\"0x5208\",\"data\":\"0x\"}],\"transactionHashes\":null,\"uncles\":[]}}", serialized);
        }
Beispiel #7
0
        public void Eth_get_transaction_receipt_returns_null_on_missing_receipt()
        {
            IBlockchainBridge bridge = Substitute.For <IBlockchainBridge>();

            bridge.GetReceipt(Arg.Any <Keccak>()).Returns((TxReceipt)null);

            IEthModule module = new EthModule(NullLogManager.Instance, bridge);

            string serialized = RpcTest.TestSerializedRequest(EthModuleFactory.Converters, module, "eth_getTransactionReceipt", TestItem.KeccakA.ToString());

            Assert.AreEqual("{\"id\":67,\"jsonrpc\":\"2.0\",\"result\":null}", serialized);
        }
        public void Eth_get_transaction_receipt_returns_null_on_missing_receipt()
        {
            IBlockchainBridge bridge = Substitute.For <IBlockchainBridge>();

            bridge.GetTransactionReceipt(Arg.Any <Keccak>()).Returns((TransactionReceipt)null);

            IEthModule module = new EthModule(new UnforgivingJsonSerializer(), Substitute.For <IConfigProvider>(), NullLogManager.Instance, bridge);

            string serialized = RpcTest.TestSerializedRequest(module, "eth_getTransactionReceipt", TestObject.KeccakA.ToString());

            Assert.AreEqual("{\"id\":67,\"jsonrpc\":\"2.0\",\"result\":null}", serialized);
        }
Beispiel #9
0
        public void Eth_get_balance_internal_error()
        {
            IBlockchainBridge bridge = Substitute.For <IBlockchainBridge>();

            bridge.Head.Returns((BlockHeader)null);

            IEthModule module = new EthModule(NullLogManager.Instance, bridge);

            string serialized = RpcTest.TestSerializedRequest(EthModuleFactory.Converters, module, "eth_getBalance", TestItem.AddressA.Bytes.ToHexString(true), "0x01");

            Assert.AreEqual("{\"id\":67,\"jsonrpc\":\"2.0\",\"error\":{\"code\":-32603,\"message\":\"Incorrect head block\",\"data\":null}}", serialized);
        }
        public void Eth_get_balance_incorrect_parameters()
        {
            IBlockchainBridge bridge = Substitute.For <IBlockchainBridge>();

            bridge.Head.Returns((BlockHeader)null);

            IEthModule module = new EthModule(new UnforgivingJsonSerializer(), Substitute.For <IConfigProvider>(), NullLogManager.Instance, bridge);

            string serialized = RpcTest.TestSerializedRequest(module, "eth_getBalance", TestObject.KeccakA.Bytes.ToHexString(true), "0x01");

            Assert.AreEqual("{\"id\":67,\"jsonrpc\":\"2.0\",\"result\":\"0x\",\"error\":{\"code\":-32602,\"message\":\"Incorrect parameters\",\"data\":null}}", serialized);
        }
        public void Eth_get_block_number()
        {
            IBlockchainBridge bridge = Substitute.For <IBlockchainBridge>();

            bridge.Head.Returns(Build.A.BlockHeader.WithNumber(310000).TestObject);

            IEthModule module = new EthModule(NullLogManager.Instance, bridge);

            string serialized = RpcTest.TestSerializedRequest(module, "eth_blockNumber");

            Assert.AreEqual($"{{\"id\":\"0x43\",\"jsonrpc\":\"2.0\",\"result\":\"0x4baf0\"}}", serialized);
        }
        public void Eth_get_balance_incorrect_number_of_params()
        {
            IBlockchainBridge bridge = Substitute.For <IBlockchainBridge>();

            bridge.Head.Returns((BlockHeader)null);

            IEthModule module = new EthModule(NullLogManager.Instance, bridge);

            string serialized = RpcTest.TestSerializedRequest(module, "eth_getBalance", TestItem.AddressA.Bytes.ToHexString(true));

            Assert.AreEqual("{\"id\":\"0x43\",\"jsonrpc\":\"2.0\",\"result\":null,\"error\":{\"code\":-32602,\"message\":\"Incorrect parameters count, expected: 2, actual: 1\",\"data\":null}}", serialized);
        }
Beispiel #13
0
        public void Eth_chain_id()
        {
            IBlockchainBridge bridge = Substitute.For <IBlockchainBridge>();

            bridge.GetChainId().Returns(1);

            IEthModule module = new EthModule(NullLogManager.Instance, bridge);

            string serialized = RpcTest.TestSerializedRequest(EthModuleFactory.Converters, module, "eth_chainid");

            Assert.AreEqual("{\"id\":67,\"jsonrpc\":\"2.0\",\"result\":\"0x1\"}", serialized);
        }
        public void Eth_syncing()
        {
            IBlockchainBridge bridge = Substitute.For <IBlockchainBridge>();

            bridge.BestKnown.Returns((UInt256)6178000);
            bridge.Head.Returns(Build.A.BlockHeader.WithNumber((UInt256)6170000).TestObject);

            IEthModule module = new EthModule(new UnforgivingJsonSerializer(), Substitute.For <IConfigProvider>(), NullLogManager.Instance, bridge);

            string serialized = RpcTest.TestSerializedRequest(module, "eth_syncing");

            Assert.AreEqual("{\"id\":67,\"jsonrpc\":\"2.0\",\"result\":{\"startingBlock\":\"0x0\",\"currentBlock\":\"0x5e2590\",\"highestBlock\":\"0x5e44d0\"}}", serialized);
        }
Beispiel #15
0
        public void Eth_get_logs(string parameter)
        {
            IBlockchainBridge bridge = Substitute.For <IBlockchainBridge>();

            bridge.GetLogs(Arg.Any <FilterBlock>(), Arg.Any <FilterBlock>(), Arg.Any <object>(), Arg.Any <IEnumerable <object> >()).Returns(new[] { new FilterLog(1, 0, 1, TestItem.KeccakA, 1, TestItem.KeccakB, TestItem.AddressA, new byte[] { 1, 2, 3 }, new[] { TestItem.KeccakC, TestItem.KeccakD }) });
            bridge.FilterExists(1).Returns(true);

            IEthModule module = new EthModule(NullLogManager.Instance, bridge);

            string serialized = RpcTest.TestSerializedRequest(EthModuleFactory.Converters, module, "eth_getLogs", parameter);

            Assert.AreEqual("{\"id\":67,\"jsonrpc\":\"2.0\",\"result\":[{\"address\":\"0xb7705ae4c6f81b66cdb323c65f4e8133690fc099\",\"blockHash\":\"0x03783fac2efed8fbc9ad443e592ee30e61d65f471140c10ca155e937b435b760\",\"blockNumber\":\"0x1\",\"data\":\"0x010203\",\"logIndex\":\"0x1\",\"removed\":false,\"topics\":[\"0x017e667f4b8c174291d1543c466717566e206df1bfd6f30271055ddafdb18f72\",\"0x6c3fd336b49dcb1c57dd4fbeaf5f898320b0da06a5ef64e798c6497600bb79f2\"],\"transactionHash\":\"0x1f675bff07515f5df96737194ea945c36c41e7b4fcef307b7cd4d0e602a69111\",\"transactionIndex\":\"0x1\",\"transactionLogIndex\":\"0x0\"}]}", serialized);
        }
        public static Block GetBlock(this IBlockchainBridge blockchainBridge, BlockParameter blockParameter, bool allowNulls = false, bool recoverTxSenders = false)
        {
            Block block;

            switch (blockParameter.Type)
            {
            case BlockParameterType.Pending:
            {
                block = blockchainBridge.FindPendingBlock();
                break;
            }

            case BlockParameterType.Latest:
            {
                block = blockchainBridge.FindLatestBlock();
                break;
            }

            case BlockParameterType.Earliest:
            {
                block = blockchainBridge.FindEarliestBlock();
                break;
            }

            case BlockParameterType.BlockId:
            {
                if (blockParameter.BlockId == null)
                {
                    throw new JsonRpcException(ErrorType.InvalidParams, $"Block number is required for {BlockParameterType.BlockId}");
                }

                block = blockchainBridge.FindBlock(blockParameter.BlockId.Value);
                break;
            }

            default:
                throw new Exception($"{nameof(BlockParameterType)} not supported: {blockParameter.Type}");
            }

            if (block == null && !allowNulls)
            {
                throw new JsonRpcException(ErrorType.NotFound, $"Cannot find block {blockParameter}");
            }

            if (block != null && recoverTxSenders)
            {
                blockchainBridge.RecoverTxSenders(block);
            }

            return(block);
        }
        public void Eth_syncing_false()
        {
            IBlockchainBridge bridge = Substitute.For <IBlockchainBridge>();

            bridge.IsSyncing.Returns(true);
            bridge.Head.Returns(Build.A.BlockHeader.WithNumber(900).TestObject);
            bridge.BestKnown.Returns((UInt256)1000);

            IEthModule module = new EthModule(new UnforgivingJsonSerializer(), Substitute.For <IConfigProvider>(), NullLogManager.Instance, bridge);

            string serialized = RpcTest.TestSerializedRequest(module, "eth_syncing");

            Assert.AreEqual("{\"id\":67,\"jsonrpc\":\"2.0\",\"result\":false}", serialized);
        }
        public void Eth_get_block_by_number_with_number_bad_number()
        {
            IBlockchainBridge bridge = Substitute.For <IBlockchainBridge>();

            bridge.FindBlock(Arg.Any <UInt256>()).Returns(Build.A.Block.WithTotalDifficulty(0).WithTransactions(Build.A.Transaction.TestObject).TestObject);
            bridge.RetrieveHeadBlock().Returns(Build.A.Block.WithTotalDifficulty(0).WithTransactions(Build.A.Transaction.TestObject).TestObject);
            bridge.Head.Returns(Build.A.BlockHeader.TestObject);

            IEthModule module = new EthModule(new EthereumJsonSerializer(), Substitute.For <IConfigProvider>(), NullLogManager.Instance, bridge);

            string serialized = RpcTest.TestSerializedRequest(module, "eth_getBlockByNumber", "'0x1234567890123456789012345678901234567890123456789012345678901234567890'", "true");

            Assert.AreEqual("{\"id\":67,\"jsonrpc\":\"2.0\",\"result\":null}", serialized);
        }
        public void Eth_get_block_by_number_empty_param()
        {
            IBlockchainBridge bridge = Substitute.For <IBlockchainBridge>();

            bridge.FindBlock(Arg.Any <Keccak>(), Arg.Any <bool>()).Returns(Build.A.Block.WithTotalDifficulty(0).WithTransactions(Build.A.Transaction.TestObject).TestObject);
            bridge.RetrieveHeadBlock().Returns(Build.A.Block.WithTotalDifficulty(0).WithTransactions(Build.A.Transaction.TestObject).TestObject);
            bridge.Head.Returns(Build.A.BlockHeader.TestObject);

            IEthModule module = new EthModule(NullLogManager.Instance, bridge);

            string serialized = RpcTest.TestSerializedRequest(module, "eth_getBlockByNumber", "", "true");

            Assert.AreEqual("{\"id\":\"0x43\",\"jsonrpc\":\"2.0\",\"result\":null,\"error\":{\"code\":-32602,\"message\":\"Incorrect parameters count, expected: 2, actual: 1\",\"data\":null}}", serialized);
        }
Beispiel #20
0
 public CreatedServices(Address consumerAddress,
                        IAbiEncoder abiEncoder, IRlpDecoder <DataHeader> dataHeaderRlpDecoder, IDepositService depositService,
                        INdmDataPublisher ndmDataPublisher, IJsonRpcNdmConsumerChannel jsonRpcNdmConsumerChannel,
                        INdmConsumerChannelManager ndmConsumerChannelManager, IBlockchainBridge blockchainBridge)
 {
     ConsumerAddress           = consumerAddress;
     AbiEncoder                = abiEncoder;
     DataHeaderRlpDecoder      = dataHeaderRlpDecoder;
     DepositService            = depositService;
     NdmDataPublisher          = ndmDataPublisher;
     JsonRpcNdmConsumerChannel = jsonRpcNdmConsumerChannel;
     NdmConsumerChannelManager = ndmConsumerChannelManager;
     BlockchainBridge          = blockchainBridge;
 }
        public void Eth_get_balance()
        {
            IBlockchainBridge bridge = Substitute.For <IBlockchainBridge>();

            bridge.FindBlock(Arg.Any <long>()).Returns(Build.A.Block.TestObject);
            bridge.GetAccount(Arg.Any <Address>(), Arg.Any <Keccak>()).Returns(Build.A.Account.WithBalance(1.Ether()).TestObject);
            bridge.Head.Returns(Build.A.BlockHeader.TestObject);

            IEthModule module = new EthModule(NullLogManager.Instance, bridge);

            string serialized = RpcTest.TestSerializedRequest(module, "eth_getBalance", TestItem.AddressA.Bytes.ToHexString(true), "0x01");

            Assert.AreEqual("{\"id\":\"0x43\",\"jsonrpc\":\"2.0\",\"result\":\"0xde0b6b3a7640000\"}", serialized);
        }
Beispiel #22
0
        public void Eth_syncing()
        {
            IBlockchainBridge bridge = Substitute.For <IBlockchainBridge>();

            bridge.IsSyncing.Returns(true);
            bridge.BestKnown.Returns(6178000L);
            bridge.Head.Returns(Build.A.BlockHeader.WithNumber(6170000L).TestObject);

            IEthModule module = new EthModule(NullLogManager.Instance, bridge);

            string serialized = RpcTest.TestSerializedRequest(EthModuleFactory.Converters, module, "eth_syncing");

            Assert.AreEqual("{\"id\":67,\"jsonrpc\":\"2.0\",\"result\":{\"startingBlock\":\"0x0\",\"currentBlock\":\"0x5e2590\",\"highestBlock\":\"0x5e44d0\"}}", serialized);
        }
Beispiel #23
0
        public void Eth_syncing_false()
        {
            IBlockchainBridge bridge = Substitute.For <IBlockchainBridge>();

            bridge.IsSyncing.Returns(false);
            bridge.Head.Returns(Build.A.BlockHeader.WithNumber(900).TestObject);
            bridge.BestKnown.Returns(1000L);

            IEthModule module = new EthModule(NullLogManager.Instance, bridge);

            string serialized = RpcTest.TestSerializedRequest(EthModuleFactory.Converters, module, "eth_syncing");

            Assert.AreEqual("{\"id\":67,\"jsonrpc\":\"2.0\",\"result\":false}", serialized);
        }
        public void Eth_syncing_true()
        {
            IBlockchainBridge bridge = Substitute.For <IBlockchainBridge>();

            bridge.IsSyncing.Returns(false);
            bridge.Head.Returns(Build.A.BlockHeader.WithNumber(900).TestObject);
            bridge.BestKnown.Returns(1000L);
            bridge.IsSyncing.Returns(true);

            IEthModule module = new EthModule(NullLogManager.Instance, bridge);

            string serialized = RpcTest.TestSerializedRequest(module, "eth_syncing");

            Assert.AreEqual("{\"id\":\"0x43\",\"jsonrpc\":\"2.0\",\"result\":{\"startingBlock\":\"0x0\",\"currentBlock\":\"0x384\",\"highestBlock\":\"0x3e8\"}}", serialized);
        }
Beispiel #25
0
        public void Eth_get_transaction_receipt()
        {
            IBlockchainBridge bridge = Substitute.For <IBlockchainBridge>();
            var entries = new[]
            {
                Build.A.LogEntry.TestObject,
                Build.A.LogEntry.TestObject
            };

            bridge.GetReceipt(Arg.Any <Keccak>()).Returns(Build.A.Receipt.WithBloom(new Bloom(entries, new Bloom())).WithAllFieldsFilled.WithLogs(entries).TestObject);

            IEthModule module = new EthModule(NullLogManager.Instance, bridge);

            string serialized = RpcTest.TestSerializedRequest(EthModuleFactory.Converters, module, "eth_getTransactionReceipt", TestItem.KeccakA.ToString());

            Assert.AreEqual("{\"id\":67,\"jsonrpc\":\"2.0\",\"result\":{\"transactionHash\":\"0x03783fac2efed8fbc9ad443e592ee30e61d65f471140c10ca155e937b435b760\",\"transactionIndex\":\"0x2\",\"blockHash\":\"0x017e667f4b8c174291d1543c466717566e206df1bfd6f30271055ddafdb18f72\",\"blockNumber\":\"0x2\",\"cumulativeGasUsed\":\"0x3e8\",\"gasUsed\":\"0x64\",\"from\":\"0xb7705ae4c6f81b66cdb323c65f4e8133690fc099\",\"to\":\"0x942921b14f1b1c385cd7e0cc2ef7abe5598c8358\",\"contractAddress\":\"0x76e68a8696537e4141926f3e528733af9e237d69\",\"logs\":[{\"removed\":false,\"logIndex\":\"0x0\",\"transactionIndex\":\"0x2\",\"transactionHash\":\"0x03783fac2efed8fbc9ad443e592ee30e61d65f471140c10ca155e937b435b760\",\"blockHash\":\"0x017e667f4b8c174291d1543c466717566e206df1bfd6f30271055ddafdb18f72\",\"blockNumber\":\"0x2\",\"address\":\"0x0000000000000000000000000000000000000000\",\"data\":\"0x\",\"topics\":[\"0x0000000000000000000000000000000000000000000000000000000000000000\"]},{\"removed\":false,\"logIndex\":\"0x1\",\"transactionIndex\":\"0x2\",\"transactionHash\":\"0x03783fac2efed8fbc9ad443e592ee30e61d65f471140c10ca155e937b435b760\",\"blockHash\":\"0x017e667f4b8c174291d1543c466717566e206df1bfd6f30271055ddafdb18f72\",\"blockNumber\":\"0x2\",\"address\":\"0x0000000000000000000000000000000000000000\",\"data\":\"0x\",\"topics\":[\"0x0000000000000000000000000000000000000000000000000000000000000000\"]}],\"logsBloom\":\"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\",\"root\":\"0x1f675bff07515f5df96737194ea945c36c41e7b4fcef307b7cd4d0e602a69111\",\"status\":\"0x1\",\"error\":\"error\"}}", serialized);
        }
Beispiel #26
0
 public void Setup()
 {
     _blockchainBridge = Substitute.For <IBlockchainBridge>();
     _repository       = Substitute.For <IEthRequestRepository>();
     _faucetAddress    = Address.FromNumber(1);
     _maxValue         = 1.GWei();
     _enabled          = true;
     _timestamp        = new Timestamp();
     _logManager       = NullLogManager.Instance;
     _host             = "127.0.0.1";
     _address          = Address.FromNumber(2);
     _value            = 1.GWei();
     _faucetAccount    = Account.TotallyEmpty;
     _transactionHash  = Keccak.Zero;
     _blockchainBridge.GetAccount(_faucetAddress).Returns(_faucetAccount);
     _blockchainBridge.SendTransaction(Arg.Any <Transaction>()).Returns(_transactionHash);
 }
Beispiel #27
0
 public NdmFaucet(IBlockchainBridge blockchainBridge, IEthRequestRepository requestRepository,
                  Address faucetAddress, UInt256 maxValue, bool enabled, ITimestamp timestamp, ILogManager logManager)
 {
     _blockchainBridge  = blockchainBridge;
     _requestRepository = requestRepository;
     _faucetAddress     = faucetAddress;
     _maxValue          = maxValue;
     _enabled           = enabled;
     _timestamp         = timestamp;
     _logger            = logManager.GetClassLogger();
     if (_enabled && !(_faucetAddress is null))
     {
         if (_logger.IsInfo)
         {
             _logger.Info($"NDM Faucet was enabled for this host, account: {faucetAddress}, ETH request max value: {maxValue} wei");
         }
     }
 }
Beispiel #28
0
        public DepositService(IBlockchainBridge blockchainBridge, IAbiEncoder abiEncoder, IWallet wallet,
                              INdmConfig ndmConfig, ILogManager logManager)
        {
            _blockchainBridge = blockchainBridge ?? throw new ArgumentNullException(nameof(blockchainBridge));
            _abiEncoder       = abiEncoder ?? throw new ArgumentNullException(nameof(abiEncoder));
            _wallet           = wallet ?? throw new ArgumentNullException(nameof(wallet));
            if (ndmConfig is null)
            {
                throw new ArgumentNullException(nameof(ndmConfig));
            }

            _logger          = logManager?.GetClassLogger() ?? throw new ArgumentNullException(nameof(logManager));
            _consumerAddress = string.IsNullOrWhiteSpace(ndmConfig.ConsumerAddress)
                ? Address.Zero
                : new Address(ndmConfig.ConsumerAddress);
            _contractAddress = string.IsNullOrWhiteSpace(ndmConfig.ContractAddress)
                ? Address.Zero
                : new Address(ndmConfig.ContractAddress);
        }
Beispiel #29
0
 public void Setup()
 {
     _blockchainBridge = Substitute.For <IBlockchainBridge>();
     _repository       = Substitute.For <IEthRequestRepository>();
     _repository.SumDailyRequestsTotalValueAsync(Arg.Any <DateTime>()).ReturnsForAnyArgs(UInt256.Zero);
     _faucetAddress = Address.FromNumber(1);
     _maxValue      = 1.Ether();
     _dailyRequestsTotalValueEth = 500;
     _enabled         = true;
     _timestamper     = new Timestamper();
     _logManager      = LimboLogs.Instance;
     _host            = "127.0.0.1";
     _address         = Address.FromNumber(2);
     _value           = 1.Ether();
     _faucetAccount   = Account.TotallyEmpty;
     _transactionHash = Keccak.Zero;
     _blockchainBridge.GetAccount(_faucetAddress).Returns(_faucetAccount);
     _blockchainBridge.SendTransaction(Arg.Any <Transaction>(), true).Returns(_transactionHash);
 }
Beispiel #30
0
 public EthModule(
     IJsonRpcConfig rpcConfig,
     IBlockchainBridge blockchainBridge,
     IBlockFinder blockFinder,
     IStateReader stateReader,
     ITxPool _txPool,
     ITxSender txSender,
     IWallet wallet,
     ILogManager logManager)
 {
     _logger           = logManager.GetClassLogger();
     _rpcConfig        = rpcConfig ?? throw new ArgumentNullException(nameof(rpcConfig));
     _blockchainBridge = blockchainBridge ?? throw new ArgumentNullException(nameof(blockchainBridge));
     _blockFinder      = blockFinder ?? throw new ArgumentNullException(nameof(blockFinder));
     _stateReader      = stateReader ?? throw new ArgumentNullException(nameof(stateReader));
     _txPoolBridge     = _txPool ?? throw new ArgumentNullException(nameof(_txPool));
     _txSender         = txSender ?? throw new ArgumentNullException(nameof(txSender));
     _wallet           = wallet ?? throw new ArgumentNullException(nameof(wallet));
 }