Exemplo n.º 1
0
        public void Trace_replay_transaction(string types)
        {
            ParityTraceAction subtrace = new ParityTraceAction();

            subtrace.Value        = 67890;
            subtrace.CallType     = "call";
            subtrace.From         = TestObject.AddressC;
            subtrace.To           = TestObject.AddressD;
            subtrace.Input        = Bytes.Empty;
            subtrace.Gas          = 10000;
            subtrace.TraceAddress = new int[] { 0, 0 };

            ParityLikeTxTrace result = new ParityLikeTxTrace();

            result.Action              = new ParityTraceAction();
            result.Action.Value        = 12345;
            result.Action.CallType     = "init";
            result.Action.From         = TestObject.AddressA;
            result.Action.To           = TestObject.AddressB;
            result.Action.Input        = new byte[] { 1, 2, 3, 4, 5, 6 };
            result.Action.Gas          = 40000;
            result.Action.TraceAddress = new int[] { 0 };
            result.Action.Subtraces.Add(subtrace);

            result.BlockHash           = TestObject.KeccakB;
            result.BlockNumber         = 123456;
            result.TransactionHash     = TestObject.KeccakC;
            result.TransactionPosition = 5;
            result.Action.TraceAddress = new int[] { 1, 2, 3 };

            ParityAccountStateChange stateChange = new ParityAccountStateChange();

            stateChange.Balance    = new ParityStateChange <UInt256>(1, 2);
            stateChange.Nonce      = new ParityStateChange <UInt256>(0, 1);
            stateChange.Storage    = new Dictionary <UInt256, ParityStateChange <byte[]> >();
            stateChange.Storage[1] = new ParityStateChange <byte[]>(new byte[] { 1 }, new byte[] { 2 });

            result.StateChanges = new Dictionary <Address, ParityAccountStateChange>();
            result.StateChanges.Add(TestObject.AddressC, stateChange);

            ITracer tracer = Substitute.For <ITracer>();

            tracer.ParityTrace(TestObject.KeccakC, Arg.Any <ParityTraceTypes>()).Returns(result);

            ITraceModule module = new TraceModule(Substitute.For <IConfigProvider>(), NullLogManager.Instance, new UnforgivingJsonSerializer(), tracer);

            JsonRpcResponse response = RpcTest.TestRequest(module, "trace_replayTransaction", TestObject.KeccakC.ToString(true), types);

            Assert.IsNull(response.Error, "error");
            Assert.NotNull(response.Result, "result");
//            Assert.False(response.Result is string s && s.Contains("\""));
        }
Exemplo n.º 2
0
        public void Get_from_db_null_value()
        {
            IDebugBridge debugBridge = Substitute.For <IDebugBridge>();

            byte[] key = new byte[] { 1, 2, 3 };
            debugBridge.GetDbValue(Arg.Any <string>(), Arg.Any <byte[]>()).Returns((byte[])null);

            IConfigProvider     configProvider = Substitute.For <IConfigProvider>();
            IJsonRpcModelMapper modelMapper    = new JsonRpcModelMapper();
            DebugModule         module         = new DebugModule(configProvider, NullLogManager.Instance, debugBridge, modelMapper, new UnforgivingJsonSerializer());
            JsonRpcResponse     response       = RpcTest.TestRequest <IDebugModule>(module, "debug_getFromDb", "STATE", key.ToHexString());

            Assert.IsNull(response.Error, "error");
            Assert.IsNull(response.Result, "result");
        }
Exemplo n.º 3
0
        public void Get_from_db()
        {
            IDebugBridge debugBridge = Substitute.For <IDebugBridge>();

            byte[] key   = new byte[] { 1, 2, 3 };
            byte[] value = new byte[] { 4, 5, 6 };
            debugBridge.GetDbValue(Arg.Any <string>(), Arg.Any <byte[]>()).Returns(value);

            IConfigProvider     configProvider = Substitute.For <IConfigProvider>();
            IJsonRpcModelMapper modelMapper    = new JsonRpcModelMapper();
            DebugModule         module         = new DebugModule(configProvider, NullLogManager.Instance, debugBridge, modelMapper, new UnforgivingJsonSerializer());
            JsonRpcResponse     response       = RpcTest.TestRequest <IDebugModule>(module, "debug_getFromDb", "STATE", key.ToHexString());

            byte[] result = Bytes.FromHexString((string)response.Result);
            Assert.AreEqual(value, result);
        }