示例#1
0
        public void Action_result_output_is_set()
        {
            byte[] code = Prepare.EvmCode
                          .StoreDataInMemory(0, SampleHexData1.PadLeft(64, '0'))
                          .PushData("0x20")
                          .PushData("0x0")
                          .Op(Instruction.RETURN)
                          .Done;

            (ParityLikeTxTrace trace, Block block, Transaction tx) = ExecuteAndTraceParityCall(code);
            Assert.AreEqual(Bytes.FromHexString(SampleHexData1.PadLeft(64, '0')), trace.Action.Result.Output);
        }
        public void Memory_is_cleared_and_restored_when_moving_between_call_levels()
        {
            byte[] deployedCode = new byte[3];

            byte[] initCode = Prepare.EvmCode
                              .ForInitOf(deployedCode)
                              .Done;

            byte[] createCode = Prepare.EvmCode
                                .StoreDataInMemory(32, SampleHexData1.PadLeft(64, '0')) // just to test if memory is restored
                                .Create(initCode, 0)
                                .Op(Instruction.STOP)
                                .Done;

            TestState.CreateAccount(TestItem.AddressC, 1.Ether());
            Keccak createCodeHash = TestState.UpdateCode(createCode);

            TestState.UpdateCodeHash(TestItem.AddressC, createCodeHash, Spec);

            byte[] code = Prepare.EvmCode
                          .StoreDataInMemory(64, SampleHexData2.PadLeft(64, '0')) // just to test if memory is restored
                          .Call(TestItem.AddressC, 50000)
                          .Op(Instruction.STOP)
                          .Done;

            GethLikeTxTrace trace = ExecuteAndTrace(code);

            /* depths
             * {
             *  1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 // MEMORY + STACK FOR CALL [0..10]
             *  2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 // MEMORY + CALL [11..23]
             *  3, 3, 3, 3, 3, 3, // CREATE [24..29]
             *  2, // STOP [30]
             *  1, // STOP [21]
             * }; */

            Assert.AreEqual(0, trace.Entries[0].Memory.Count, "BEGIN 1");
            Assert.AreEqual(3, trace.Entries[10].Memory.Count, "CALL FROM 1");
            Assert.AreEqual(0, trace.Entries[11].Memory.Count, "BEGIN 2");
            Assert.AreEqual(2, trace.Entries[23].Memory.Count, "CREATE FROM 2");
            Assert.AreEqual(0, trace.Entries[24].Memory.Count, "BEGIN 3");
            Assert.AreEqual(1, trace.Entries[29].Memory.Count, "END 3");
            Assert.AreEqual(2, trace.Entries[30].Memory.Count, "END 2");
            Assert.AreEqual(3, trace.Entries[31].Memory.Count, "END 1");
        }
        public void Can_trace_stack()
        {
            byte[] code = Prepare.EvmCode
                          .PushData(SampleHexData1)
                          .PushData(HexZero)
                          .Op(Instruction.POP)
                          .Op(Instruction.STOP)
                          .Done;

            GethLikeTxTrace trace = ExecuteAndTrace(code);

            Assert.AreEqual(0, trace.Entries[0].Stack.Count, "entry[0] length");

            Assert.AreEqual(1, trace.Entries[1].Stack.Count, "entry[1] length");
            Assert.AreEqual(SampleHexData1.PadLeft(64, '0'), trace.Entries[1].Stack[0], "entry[1][0]");

            Assert.AreEqual(2, trace.Entries[2].Stack.Count, "entry[2] length");
            Assert.AreEqual(SampleHexData1.PadLeft(64, '0'), trace.Entries[2].Stack[0], "entry[2][0]");
            Assert.AreEqual(HexZero.PadLeft(64, '0'), trace.Entries[2].Stack[1], "entry[2][1]");

            Assert.AreEqual(1, trace.Entries[3].Stack.Count, "entry[3] length");
            Assert.AreEqual(SampleHexData1.PadLeft(64, '0'), trace.Entries[3].Stack[0], "entry[3][0]");
        }
        public void Can_trace_memory()
        {
            byte[] code = Prepare.EvmCode
                          .PushData(SampleHexData1.PadLeft(64, '0'))
                          .PushData(0)
                          .Op(Instruction.MSTORE)
                          .PushData(SampleHexData2.PadLeft(64, '0'))
                          .PushData(32)
                          .Op(Instruction.MSTORE)
                          .Op(Instruction.STOP)
                          .Done;

            GethLikeTxTrace trace = ExecuteAndTrace(code);

            /* note the curious Geth trace behaviour where memory grows now but is populated from the next trace entry */

            Assert.AreEqual(0, trace.Entries[0].Memory.Count, "entry[0] length");

            Assert.AreEqual(0, trace.Entries[1].Memory.Count, "entry[1] length");

            Assert.AreEqual(1, trace.Entries[2].Memory.Count, "entry[2] length");
            Assert.AreEqual(HexZero.PadLeft(64, '0'), trace.Entries[2].Memory[0], "entry[2][0]");

            Assert.AreEqual(1, trace.Entries[3].Memory.Count, "entry[3] length");
            Assert.AreEqual(SampleHexData1.PadLeft(64, '0'), trace.Entries[3].Memory[0], "entry[3][0]");

            Assert.AreEqual(1, trace.Entries[4].Memory.Count, "entry[4] length");
            Assert.AreEqual(SampleHexData1.PadLeft(64, '0'), trace.Entries[4].Memory[0], "entry[4][0]");

            Assert.AreEqual(2, trace.Entries[5].Memory.Count, "entry[5] length");
            Assert.AreEqual(SampleHexData1.PadLeft(64, '0'), trace.Entries[5].Memory[0], "entry[5][0]");
            Assert.AreEqual(HexZero.PadLeft(64, '0'), trace.Entries[5].Memory[1], "entry[5][1]");

            Assert.AreEqual(2, trace.Entries[6].Memory.Count, "entry[2] length");
            Assert.AreEqual(SampleHexData1.PadLeft(64, '0'), trace.Entries[6].Memory[0], "entry[6][0]");
            Assert.AreEqual(SampleHexData2.PadLeft(64, '0'), trace.Entries[6].Memory[1], "entry[6][1]");
        }