public void Test_out_of_gas_non_existing_account()
        {
            byte[] salt         = { 4, 5, 6 };
            byte[] deployedCode = { 1, 2, 3 };

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

            byte[] createCode = Prepare.EvmCode
                                .Create2(initCode, salt, 0).Done;

            Address expectedAddress = ContractAddress.From(TestItem.AddressC, salt.PadLeft(32).AsSpan(), initCode.AsSpan());

            // TestState.CreateAccount(expectedAddress, 1.Ether()); <-- non-existing
            TestState.CreateAccount(TestItem.AddressC, 1.Ether());

            Keccak createCodeHash = TestState.UpdateCode(createCode);

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

            byte[] code = Prepare.EvmCode
                          .Call(TestItem.AddressC, 32100)
                          .Done;

            Execute(code);

            TestState.AccountExists(expectedAddress).Should().BeFalse();
        }
 protected void AssertStorage(StorageCell storageCell, UInt256 expectedValue)
 {
     _callIndex++;
     if (!TestState.AccountExists(storageCell.Address))
     {
         Assert.AreEqual(expectedValue.ToBigEndian().WithoutLeadingZeros().ToArray(), new byte[] { 0 }, $"storage {storageCell}, call {_callIndex}");
     }
     else
     {
         byte[] actualValue = Storage.Get(storageCell);
         Assert.AreEqual(expectedValue.ToBigEndian().WithoutLeadingZeros().ToArray(), actualValue, $"storage {storageCell}, call {_callIndex}");
     }
 }
 protected void AssertStorage(StorageCell storageCell, BigInteger expectedValue)
 {
     _callIndex++;
     if (!TestState.AccountExists(storageCell.Address))
     {
         Assert.AreEqual(expectedValue.ToBigEndianByteArray(), new byte[1] {
             0
         }, $"storage {storageCell}, call {_callIndex}");
     }
     else
     {
         byte[] actualValue = Storage.Get(storageCell);
         Assert.AreEqual(expectedValue.ToBigEndianByteArray(), actualValue, $"storage {storageCell}, call {_callIndex}");
     }
 }
Exemple #4
0
        public void Newly_created_empty_account_returns_empty_data_hash()
        {
            byte[] code = Prepare.EvmCode
                          .Create(Bytes.Empty, 0)
                          .PushData(Address.OfContract(Recipient, 0))
                          .Op(Instruction.EXTCODEHASH)
                          .PushData(0)
                          .Op(Instruction.SSTORE)
                          .Done;

            Execute(code);

            // todo: so far EIP does not define whether it should be zero or empty data
            AssertStorage(0, Keccak.OfAnEmptyString);
            Assert.True(TestState.AccountExists(Address.OfContract(Recipient, 0)),
                        "did not test the right thing - it was not a newly created empty account scenario");
        }
Exemple #5
0
        public void Empty_account_that_would_be_cleared_returns_zero()
        {
            TestState.CreateAccount(TestItem.AddressC, 0.Ether());

            byte[] code = Prepare.EvmCode
                          .Call(TestItem.AddressC, 0)
                          .PushData(TestItem.AddressC)
                          .Op(Instruction.EXTCODEHASH)
                          .PushData(0)
                          .Op(Instruction.SSTORE)
                          .Done;

            Execute(code);

            AssertStorage(0, 0);
            Assert.False(TestState.AccountExists(TestItem.AddressC), "did not test the right thing - it was not an empty account + touch scenario");
        }
Exemple #6
0
        public void Empty_account_that_would_be_cleared_returns_zero()
        {
            TestState.CreateAccount(TestObject.AddressC, 0.Ether());

            byte[] code = Prepare.EvmCode
                          .Call(TestObject.AddressC, 0)
                          .PushData(TestObject.AddressC)
                          .Op(Instruction.EXTCODEHASH)
                          .PushData(0)
                          .Op(Instruction.SSTORE)
                          .Done;

            Execute(code);

            // todo: so far EIP does not define whether it should be zero or empty data
            AssertStorage(0, Keccak.OfAnEmptyString);
            Assert.False(TestState.AccountExists(TestObject.AddressC),
                         "did not test the right thing - it was not an empty account + touch scenario");
        }