parent
a216aba714
commit
e8eaa4f6f9
|
@ -88,6 +88,10 @@ public class ProgramInvokeMockImpl implements ProgramInvoke {
|
||||||
return new DataWord(gasLimit);
|
return new DataWord(gasLimit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setGas(long gasLimit){
|
||||||
|
this.gasLimit = gasLimit;
|
||||||
|
}
|
||||||
|
|
||||||
/* CALLVALUE op */
|
/* CALLVALUE op */
|
||||||
public DataWord getCallValue() {
|
public DataWord getCallValue() {
|
||||||
byte[] balance = Hex.decode("0DE0B6B3A7640000");
|
byte[] balance = Hex.decode("0DE0B6B3A7640000");
|
||||||
|
|
|
@ -955,7 +955,12 @@ public class VM {
|
||||||
DataWord size = program.stackPop();
|
DataWord size = program.stackPop();
|
||||||
|
|
||||||
ByteBuffer hReturn = program.memoryChunk(offset, size);
|
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())
|
if (logger.isInfoEnabled())
|
||||||
hint = "data: " + Hex.toHexString(hReturn.array())
|
hint = "data: " + Hex.toHexString(hReturn.array())
|
||||||
|
|
|
@ -25,7 +25,7 @@ import static org.junit.Assert.*;
|
||||||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||||
public class VMTest {
|
public class VMTest {
|
||||||
|
|
||||||
private ProgramInvoke invoke;
|
private ProgramInvokeMockImpl invoke;
|
||||||
private Program program;
|
private Program program;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
|
@ -2482,6 +2482,53 @@ public class VMTest {
|
||||||
assertTrue(program.isStopped());
|
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
|
@Test // CODECOPY OP
|
||||||
public void testCODECOPY_1() {
|
public void testCODECOPY_1() {
|
||||||
|
|
Loading…
Reference in New Issue