+ RETURN new cost
This commit is contained in:
romanman 2014-12-14 12:53:55 +01:00
parent a216aba714
commit e8eaa4f6f9
3 changed files with 58 additions and 2 deletions

View File

@ -88,6 +88,10 @@ public class ProgramInvokeMockImpl implements ProgramInvoke {
return new DataWord(gasLimit);
}
public void setGas(long gasLimit){
this.gasLimit = gasLimit;
}
/* CALLVALUE op */
public DataWord getCallValue() {
byte[] balance = Hex.decode("0DE0B6B3A7640000");

View File

@ -955,7 +955,12 @@ public class VM {
DataWord size = program.stackPop();
ByteBuffer hReturn = program.memoryChunk(offset, size);
program.setHReturn(hReturn);
if (hReturn.array().length * 5 <= program.getGas().longValue()){
program.spendGas(hReturn.array().length * 5, op.name());
program.setHReturn(hReturn);
} else {
program.setHReturn(ByteBuffer.wrap(new byte[]{}));
}
if (logger.isInfoEnabled())
hint = "data: " + Hex.toHexString(hReturn.array())

View File

@ -25,7 +25,7 @@ import static org.junit.Assert.*;
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class VMTest {
private ProgramInvoke invoke;
private ProgramInvokeMockImpl invoke;
private Program program;
@Before
@ -2482,6 +2482,53 @@ public class VMTest {
assertTrue(program.isStopped());
}
@Test // RETURN OP
public void testRETURN_5() {
invoke.setGas(300);
VM vm = new VM();
program =
new Program(Hex.decode("7FA0B0C0D0E0F0A1B1C1D1E1F1A2B2C2D2E2F2A3B3C3D3E3F3A4B4C4D4E4F4A1B160005260206010F3"),
invoke);
String s_expected_1 = "E2F2A3B3C3D3E3F3A4B4C4D4E4F4A1B100000000000000000000000000000000";
vm.step(program);
vm.step(program);
vm.step(program);
vm.step(program);
vm.step(program);
vm.step(program);
assertEquals(s_expected_1, Hex.toHexString(program.getResult().getHReturn().array()).toUpperCase());
assertEquals(132, program.getGas().longValue());
assertTrue(program.isStopped());
}
@Test // RETURN OP
public void testRETURN_6() {
invoke.setGas(100);
VM vm = new VM();
program =
new Program(Hex.decode("7FA0B0C0D0E0F0A1B1C1D1E1F1A2B2C2D2E2F2A3B3C3D3E3F3A4B4C4D4E4F4A1B160005260206010F3"),
invoke);
vm.step(program);
vm.step(program);
vm.step(program);
vm.step(program);
vm.step(program);
vm.step(program);
assertArrayEquals("".getBytes(), program.getResult().getHReturn().array());
assertEquals(92, program.getGas().longValue());
assertTrue(program.isStopped());
}
@Test // CODECOPY OP
public void testCODECOPY_1() {