-
Notifications
You must be signed in to change notification settings - Fork 514
/
Copy pathVmCodeDepositTests.cs
107 lines (87 loc) · 4.09 KB
/
VmCodeDepositTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// SPDX-FileCopyrightText: 2022 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only
using Nethermind.Core;
using Nethermind.Core.Extensions;
using Nethermind.Specs;
using Nethermind.State;
using Nethermind.Core.Test.Builders;
using NUnit.Framework;
namespace Nethermind.Evm.Test
{
[TestFixture]
[Parallelizable(ParallelScope.Self)]
public class VmCodeDepositTests : VirtualMachineTestsBase
{
private long _blockNumber = MainnetSpecProvider.ByzantiumBlockNumber;
protected override long BlockNumber => _blockNumber;
[SetUp]
public override void Setup()
{
base.Setup();
_blockNumber = MainnetSpecProvider.ByzantiumBlockNumber;
}
[Test(Description = "Refunds should not be given when the call fails due to lack of gas for code deposit payment")]
public void Regression_mainnet_6108276()
{
Address deployed = ContractAddress.From(TestItem.AddressC, 0);
StorageCell storageCell = new(deployed, 1);
byte[] deployedCode = new byte[100]; // cost is * 200
byte[] initCode = Prepare.EvmCode
.PushData(1)
.PushData(1)
.Op(Instruction.SSTORE)
.PushData(0)
.PushData(1)
.Op(Instruction.SSTORE) // here we reset storage so we would get refund of 15000 gas
.ForInitOf(deployedCode).Done;
byte[] createCode = Prepare.EvmCode
.Create(initCode, 0)
.PushData(0)
.Op(Instruction.SSTORE)
.Done;
TestState.CreateAccount(TestItem.AddressC, 1.Ether());
TestState.InsertCode(TestItem.AddressC, createCode, Spec);
byte[] code = Prepare.EvmCode
.Call(TestItem.AddressC, 32000 + 20003 + 20000 + 5000 + 500 + 0) // not enough
.Done;
TestAllTracerWithOutput receipt = Execute(code);
byte[] result = TestState.Get(storageCell).BytesWithNoLeadingZeroes.ToArray();
Assert.That(result, Is.EqualTo(new byte[] { 0 }), "storage reverted");
Assert.That(receipt.GasSpent, Is.EqualTo(98777), "no refund");
byte[] returnData = TestState.Get(new StorageCell(TestItem.AddressC, 0)).BytesWithNoLeadingZeroes.ToArray();
Assert.That(returnData, Is.EqualTo(new byte[1]), "address returned");
}
[Test(Description = "Deposit OutOfGas before EIP-2")]
public void Regression_mainnet_226522()
{
_blockNumber = 1;
Address deployed = ContractAddress.From(TestItem.AddressC, 0);
StorageCell storageCell = new(deployed, 1);
byte[] deployedCode = new byte[106]; // cost is * 200
byte[] initCode = Prepare.EvmCode
.PushData(1)
.PushData(1)
.Op(Instruction.SSTORE)
.PushData(0)
.PushData(1)
.Op(Instruction.SSTORE) // here we reset storage so we would get refund of 15000 gas
.ForInitOf(deployedCode).Done;
byte[] createCode = Prepare.EvmCode
.Create(initCode, 0)
.PushData(0)
.Op(Instruction.SSTORE)
.Done;
TestState.CreateAccount(TestItem.AddressC, 1.Ether());
TestState.InsertCode(TestItem.AddressC, createCode, Spec);
byte[] code = Prepare.EvmCode
.Call(TestItem.AddressC, 32000 + 20003 + 20000 + 5000 + 500 + 0) // not enough
.Done;
TestAllTracerWithOutput receipt = Execute(code);
byte[] result = TestState.Get(storageCell).BytesWithNoLeadingZeroes.ToArray();
Assert.That(result, Is.EqualTo(new byte[] { 0 }), "storage reverted");
Assert.That(receipt.GasSpent, Is.EqualTo(83199), "with refund");
byte[] returnData = TestState.Get(new StorageCell(TestItem.AddressC, 0)).BytesWithNoLeadingZeroes.ToArray();
Assert.That(returnData, Is.EqualTo(deployed.Bytes), "address returned");
}
}
}