Exemplo n.º 1
0
 public CliApiBuilder(Engine engine, IJsonSerializer jsonSerializer, IJsonRpcClient client, ILogManager logManager)
 {
     _engine     = engine;
     _serializer = jsonSerializer;
     _client     = client;
     _logManager = logManager;
 }
Exemplo n.º 2
0
        public NdmContext MakeDeposit(Func <MakeDepositDto> deposit, string name = "Make deposit",
                                      Func <string, bool> validator = null, Action <NdmState, JsonRpcResponse <string> > stateUpdater = null)
        {
            IJsonRpcClient client = TestBuilder.CurrentNode.JsonRpcClient;

            return(AddJsonRpc(name, "npm_makeDeposit", () => client.PostAsync <string>(nameof(MakeDeposit), new object[] { deposit() }), validator, stateUpdater));
        }
Exemplo n.º 3
0
        public NdmContext SendData(Func <DataAssetDataDto> data, string name = "Send data",
                                   Func <string, bool> validator             = null, Action <NdmState, JsonRpcResponse <string> > stateUpdater = null)
        {
            IJsonRpcClient client = TestBuilder.CurrentNode.JsonRpcClient;

            return(AddJsonRpc(name, "npm_sendData", () => client.PostAsync <string>(nameof(SendData), new object[] { data() }), validator, stateUpdater));
        }
Exemplo n.º 4
0
        public static async Task <(JsonRpcError Error, Hash TransactionHash)> TryDeploy(
            bool expectException,
            SolidityContractAttribute contractAttribute,
            IJsonRpcClient rpcClient,
            byte[] bytecode,
            TransactionParams sendParams,
            ReadOnlyMemory <byte> abiEncodedConstructorArgs = default)
        {
            // If we have no code, we shouldn't append our constructor arguments, so we blank ours out.
            if (bytecode == null || bytecode.Length == 0)
            {
                abiEncodedConstructorArgs = default;
            }

            // If constructor args are provided, append to contract bytecode.
            if (!abiEncodedConstructorArgs.IsEmpty)
            {
                sendParams.Data = new byte[bytecode.Length + abiEncodedConstructorArgs.Length];
                Memory <byte> deploymentMem = new Memory <byte>(sendParams.Data);
                bytecode.CopyTo(deploymentMem);
                abiEncodedConstructorArgs.CopyTo(deploymentMem.Slice(bytecode.Length));
            }
            else
            {
                sendParams.Data = bytecode;
            }

            return(await rpcClient.TrySendTransaction(sendParams, expectException));
        }
Exemplo n.º 5
0
        public CliqueContext Propose(Address address, bool vote)
        {
            IJsonRpcClient client = TestBuilder.CurrentNode.JsonRpcClient;

            return(AddJsonRpc($"vote {vote} for {address}", "clique_propose",
                              () => client.PostAsync <string>("clique_propose", new object[] { address, vote })));
        }
Exemplo n.º 6
0
        public CliqueContext Discard(Address address)
        {
            IJsonRpcClient client = TestBuilder.CurrentNode.JsonRpcClient;

            return(AddJsonRpc($"discard vote for {address}", "clique_discard",
                              () => client.PostAsync <string>("clique_discard", new object[] { address })));
        }
Exemplo n.º 7
0
 public void SetUp()
 {
     _jsonSerializer = Substitute.For <IJsonSerializer>();
     _jsonRpcClient  = Substitute.For <IJsonRpcClient>();
     _recordDb       = Substitute.For <IDb>();
     _rpcDb          = new RpcDb("Name", _jsonSerializer, _jsonRpcClient, LimboLogs.Instance, _recordDb);
 }
Exemplo n.º 8
0
        public void ValidateDbs()
        {
            void ValidateDb <T>(params IDb[] dbs) where T : IDb
            {
                foreach (IDb db in dbs)
                {
                    db.Should().BeAssignableTo <T>(db.Name);
                    db.Innermost.Should().BeAssignableTo <RpcDb>(db.Name);
                }
            }

            IJsonSerializer jsonSerializer = Substitute.For <IJsonSerializer>();
            IJsonRpcClient  jsonRpcClient  = Substitute.For <IJsonRpcClient>();
            IMemDbFactory   rpcDbFactory   = new RpcDbFactory(new MemDbFactory(), null, jsonSerializer, jsonRpcClient, LimboLogs.Instance);

            IDbProvider           memDbProvider         = new DbProvider(DbModeHint.Mem);
            StandardDbInitializer standardDbInitializer = new(memDbProvider, null, rpcDbFactory);

            standardDbInitializer.InitStandardDbs(true);

            ValidateDb <ReadOnlyDb>(
                memDbProvider.BlocksDb,
                memDbProvider.BloomDb,
                memDbProvider.HeadersDb,
                memDbProvider.ReceiptsDb,
                memDbProvider.BlockInfosDb,
                memDbProvider.PendingTxsDb);

            ValidateDb <ReadOnlyDb>(
                memDbProvider.StateDb,
                memDbProvider.CodeDb);
        }
Exemplo n.º 9
0
 public NethermindProcessWrapper(string name, Process process, string enode, IJsonRpcClient jsonRpcClient)
 {
     Enode         = enode;
     JsonRpcClient = jsonRpcClient;
     Name          = name;
     Process       = process;
 }
Exemplo n.º 10
0
        public CliqueContext SendTransaction(TransactionForRpc tx)
        {
            IJsonRpcClient client = TestBuilder.CurrentNode.JsonRpcClient;

            return(AddJsonRpc($"send tx to {TestBuilder.CurrentNode.HttpPort}", "eth_sendTransaction",
                              () => client.PostAsync <string>("eth_SendTransaction", new object[] { tx })));
        }
Exemplo n.º 11
0
        public AuRaContext ReadBlockNumber()
        {
            IJsonRpcClient client = TestBuilder.CurrentNode.JsonRpcClient;

            return(AddJsonRpc("Read block number", "eth_blockNumber",
                              () => client.PostAsync <long>("eth_blockNumber"), stateUpdater: (s, r) => s.BlocksCount = r.Result
                              ));
        }
Exemplo n.º 12
0
        public RpcServerProxy(Uri targetHost, int?proxyServerPort = null, IPAddress address = null)
        {
            _proxyClient = JsonRpcClient.Create(targetHost, ArbitraryDefaults.DEFAULT_GAS_LIMIT, ArbitraryDefaults.DEFAULT_GAS_PRICE);
            _httpServer  = new JsonRpcHttpServer(_proxyClient, ConfigureWebHost, proxyServerPort, address);

            //var undefinedRpcMethods = this.GetUndefinedRpcMethods();
            //Console.WriteLine("Warning: following RPC methods are not defined: \n" + string.Join(", ", undefinedRpcMethods.Select(r => r.Value())));
        }
Exemplo n.º 13
0
        public NdmContext AddDataHeader(Func <DataHeaderDto> dataHeader, string name = "Add data header",
                                        Func <string, bool> validator = null, Action <NdmState, JsonRpcResponse <string> > stateUpdater = null)
        {
            IJsonRpcClient client = TestBuilder.CurrentNode.JsonRpcClient;

            return(AddJsonRpc(name, "npm_addDataHeader",
                              () => client.PostAsync <string>(nameof(AddDataHeader), new object[] { dataHeader() }), validator, stateUpdater));
        }
Exemplo n.º 14
0
        public NdmContext PullData(Func <string> depositId, string name = "Pull data",
                                   Func <string, bool> validator        = null, Action <NdmState, JsonRpcResponse <string> > stateUpdater = null)
        {
            IJsonRpcClient client = TestBuilder.CurrentNode.JsonRpcClient;

            return(AddJsonRpc(name, "npm_pullData",
                              () => client.PostAsync <string>(nameof(PullData), new object[] { depositId() }), validator, stateUpdater));
        }
Exemplo n.º 15
0
 public RpcDb(string dbName, IJsonSerializer jsonSerializer, IJsonRpcClient rpcClient, ILogManager logManager, IDb recordDb)
 {
     _dbName         = dbName;
     _rpcClient      = rpcClient ?? throw new ArgumentNullException(nameof(rpcClient));
     _jsonSerializer = jsonSerializer ?? throw new ArgumentNullException(nameof(jsonSerializer));
     _logger         = logManager?.GetClassLogger() ?? throw new ArgumentNullException(nameof(logManager));
     _recordDb       = recordDb;
 }
Exemplo n.º 16
0
 public CashOutQueueTrigger(string component, IJsonRpcClient rpcClient, INoSQLTableStorage <ExistingCashOutEntity> existingTxes, ILog log, ISlackNotifier slackNotifier)
 {
     _component     = component + ".QueueTrigger";
     _rpcClient     = rpcClient;
     _existingTxes  = existingTxes;
     _log           = log;
     _slackNotifier = slackNotifier;
 }
Exemplo n.º 17
0
        public NdmContext GetDeposits(string name = "Get deposits",
                                      Func <DepositDetailsDto[], bool> validator = null,
                                      Action <NdmState, JsonRpcResponse <DepositDetailsDto[]> > stateUpdater = null)
        {
            IJsonRpcClient client = TestBuilder.CurrentNode.JsonRpcClient;

            return(AddJsonRpc(name, "npm_getDeposits",
                              () => client.PostAsync <DepositDetailsDto[]>(nameof(GetDeposits)), validator, stateUpdater));
        }
Exemplo n.º 18
0
 public NethermindProcessWrapper(string name, Process process, int httpPort, Address address, string enode, IJsonRpcClient jsonRpcClient)
 {
     HttpPort      = httpPort;
     Address       = address;
     Enode         = enode;
     JsonRpcClient = jsonRpcClient;
     Name          = name;
     Process       = process;
 }
Exemplo n.º 19
0
        public NdmContext GetDiscoveredDataHeaders(string name = "Get discovered data headers",
                                                   Func <DataHeaderDto[], bool> validator = null,
                                                   Action <NdmState, JsonRpcResponse <DataHeaderDto[]> > stateUpdater = null)
        {
            IJsonRpcClient client = TestBuilder.CurrentNode.JsonRpcClient;

            return(AddJsonRpc(name, "npm_getDiscoveredDataHeaders",
                              () => client.PostAsync <DataHeaderDto[]>(nameof(GetDiscoveredDataHeaders)), validator, stateUpdater));
        }
Exemplo n.º 20
0
        public NdmContext EnableDataStream(Func <string> depositId, string[] args,
                                           string name = "Enable data stream", Func <string, bool> validator = null,
                                           Action <NdmState, JsonRpcResponse <string> > stateUpdater = null)
        {
            IJsonRpcClient client = TestBuilder.CurrentNode.JsonRpcClient;

            return(AddJsonRpc(name, "npm_enableDataStream",
                              () => client.PostAsync <string>(nameof(EnableDataStream), new object[] { depositId(), args }), validator, stateUpdater));
        }
Exemplo n.º 21
0
        public RpcApp()
        {
            Server = new MockServerApp();
            Server.RpcServer.WebHost.Start();
            var port = Server.RpcServer.ServerPort;

            HttpClient      = JsonRpcClient.Create(new Uri($"http://{IPAddress.Loopback}:{port}"), ArbitraryDefaults.DEFAULT_GAS_LIMIT, ArbitraryDefaults.DEFAULT_GAS_PRICE);
            WebSocketClient = JsonRpcClient.Create(new Uri($"ws://{IPAddress.Loopback}:{port}"), ArbitraryDefaults.DEFAULT_GAS_LIMIT, ArbitraryDefaults.DEFAULT_GAS_PRICE);
        }
Exemplo n.º 22
0
        /// <summary>
        /// The default constructor, creates a test chain for tests to share.
        /// </summary>
        public TestChainFixture()
        {
            // Create a test node on this port.
            Server = new Meadow.TestNode.TestNodeServer();
            Server.RpcServer.Start();
            int port = Server.RpcServer.ServerPort;

            // Create our client and grab our account list.
            Client = JsonRpcClient.Create(new Uri($"http://{IPAddress.Loopback}:{port}"), ArbitraryDefaults.DEFAULT_GAS_LIMIT, ArbitraryDefaults.DEFAULT_GAS_PRICE);
        }
Exemplo n.º 23
0
        public void SwitchUri(Uri uri)
        {
            CurrentUri = uri.ToString();
            if (!_clients.ContainsKey(uri))
            {
                _clients[uri] = new BasicJsonRpcClient(uri, _serializer, _logManager);
            }

            _currentClient = _clients[uri];
        }
Exemplo n.º 24
0
        private AuRaContext ReadBlockAuthor(long blockNumber)
        {
            IJsonRpcClient client = TestBuilder.CurrentNode.JsonRpcClient;

            return(AddJsonRpc("Read block", "eth_getBlockByNumber",
                              () => client.PostAsync <JObject>("eth_getBlockByNumber", new object[] { blockNumber, false }),
                              stateUpdater: (s, r) => s.Blocks.Add(
                                  Convert.ToInt64(r.Result["number"].Value <string>(), 16),
                                  (r.Result["miner"].Value <string>(), Convert.ToInt64(r.Result["step"].Value <string>(), 16)))));
        }
Exemplo n.º 25
0
 public RpcDbProvider(IJsonSerializer serializer, IJsonRpcClient client, ILogManager logManager, IDbProvider recordDbProvider)
 {
     _recordDbProvider = recordDbProvider;
     StateDb           = new StateDb(new ReadOnlyDb(new RpcDb(DbNames.State, serializer, client, logManager, recordDbProvider?.StateDb), true));
     CodeDb            = new StateDb(new ReadOnlyDb(new RpcDb(DbNames.Code, serializer, client, logManager, recordDbProvider?.CodeDb), true));
     ReceiptsDb        = new ReadOnlyDb(new RpcDb(DbNames.Receipts, serializer, client, logManager, recordDbProvider?.ReceiptsDb), true);
     BlocksDb          = new ReadOnlyDb(new RpcDb(DbNames.Blocks, serializer, client, logManager, recordDbProvider?.BlocksDb), true);
     BlockInfosDb      = new ReadOnlyDb(new RpcDb(DbNames.BlockInfos, serializer, client, logManager, recordDbProvider?.BlockInfosDb), true);
     PendingTxsDb      = new ReadOnlyDb(new RpcDb(DbNames.PendingTxs, serializer, client, logManager, recordDbProvider?.ReceiptsDb), true);
     TraceDb           = new ReadOnlyDb(new RpcDb(DbNames.Trace, serializer, client, logManager, recordDbProvider?.ReceiptsDb), true);
 }
Exemplo n.º 26
0
        public async Task RpcExecutionCallback(IJsonRpcClient client, bool expectingException)
        {
            // Obtain an execution trace from our client.
            var executionTrace = await client.GetExecutionTrace();

            var executionTraceAnalysis = new ExecutionTraceAnalysis(executionTrace);

            // Process our execution trace in the debug adapter.
            await DebugAdapter.ProcessExecutionTraceAnalysis(client, executionTraceAnalysis, expectingException);

            await Task.CompletedTask;
        }
Exemplo n.º 27
0
        public ContractInstance(
            string contractSolFilePath, string contractName,
            IJsonRpcClient rpcClient, Address contractAddress, Address defaultFromAccount)
            : base(rpcClient, contractAddress, defaultFromAccount)
        {
            ContractAddress    = contractAddress;
            DefaultFromAccount = defaultFromAccount;
            JsonRpcClient      = rpcClient;

            ContractSolFilePath = contractSolFilePath;
            ContractName        = contractName;
        }
 public CashInHandlerQueueTrigger(string component, INoSQLTableStorage <WalletStorageEntity> generatedWallets, ILog log, IQueueExt txesQueue,
                                  IJsonRpcClient rpcClient, ISlackNotifier slackNotifier, string hotWalletAddress, decimal txFee, decimal minTxAmount)
 {
     _component        = component + ".QueueTrigger";
     _generatedWallets = generatedWallets;
     _log              = log;
     _txesQueue        = txesQueue;
     _rpcClient        = rpcClient;
     _hotWalletAddress = hotWalletAddress;
     _txFee            = txFee;
     _minTxAmount      = minTxAmount;
     _slackNotifier    = slackNotifier;
 }
Exemplo n.º 29
0
 public RpcDbFactory(
     IMemDbFactory wrappedMemDbFactory,
     IRocksDbFactory wrappedRocksDbFactory,
     IJsonSerializer jsonSerializer,
     IJsonRpcClient jsonRpcClient,
     ILogManager logManager)
 {
     _wrappedMemDbFactory   = wrappedMemDbFactory;
     _wrappedRocksDbFactory = wrappedRocksDbFactory;
     _jsonSerializer        = jsonSerializer;
     _jsonRpcClient         = jsonRpcClient;
     _logManager            = logManager;
 }
Exemplo n.º 30
0
        public void Setup()
        {
            _serializer    = new EthereumJsonSerializer();
            _jsonRpcClient = Substitute.For <IJsonRpcClient>();
            _engine        = new CliEngine(_cliConsole);
            NodeManager nodeManager = new NodeManager(_engine, _serializer, _cliConsole, LimboLogs.Instance);

            nodeManager.SwitchClient(_jsonRpcClient);
            ICliConsole     cliConsole   = Substitute.For <ICliConsole>();
            CliModuleLoader moduleLoader = new CliModuleLoader(_engine, nodeManager, cliConsole);

            moduleLoader.LoadModule(typeof(ProofCliModule));
        }
Exemplo n.º 31
0
        public PluginsModule(IPluginEngine pluginEngine, IJsonRpcClient rpcClient)
            : base("plugins")
        {
            Get["/{id}/{path*}"] = _ =>
            {
                string id = _.id;
                string path = _.path;

                var plugin = pluginEngine.Get(id);
                if (plugin == null)
                {
                    return 404;
                }

                var data = rpcClient.Call<byte[]>(string.Format("{0}.resource.get", id), new[] {path});
                if (data == null)
                {
                    return 404;
                }

                var contentType = MimeTypes.GetMimeType(path);
                return Response.FromStream(() => new MemoryStream(data), contentType);
            };
        }
Exemplo n.º 32
0
 public EventsService(ILogger logger, IPluginEngine pluginEngine, IJsonRpcClient rpcClient)
 {
     _logger = logger;
     _pluginEngine = pluginEngine;
     _rpcClient = rpcClient;
 }