Fix VMTests/vmSystemOperationsTest

+ [DONE] CallToNameRegistratorNotMuchMemory0
 + [DONE] ABAcallsSuicide0
 + [DONE] CallToNameRegistratorNotMuchMemory1
 + [DONE] CallToNameRegistratorOutOfGas
 + [DONE] callcodeToReturn1
 + [DONE] ABAcallsSuicide1
 + [DONE] ABAcalls1
 + [DONE] ABAcalls2
 + [DONE] ABAcalls3
 + [DONE] CallToNameRegistrator0
 + [DONE] ABAcalls0
 + [DONE] CallRecursiveBomb3
 + [DONE] CallRecursiveBomb2
 + [DONE] CallRecursiveBomb1
 + [DONE] CallRecursiveBomb0
 + [DONE] CallToReturn1
 + [DONE] callcodeToNameRegistrator0
This commit is contained in:
Roman Mandeleil 2015-02-08 22:01:32 +02:00
parent e032b2248f
commit 87c97652b6
10 changed files with 57 additions and 33 deletions

View File

@ -34,7 +34,7 @@ public class TestProgramInvokeFactory implements ProgramInvokeFactory {
@Override @Override
public ProgramInvoke createProgramInvoke(Program program, DataWord toAddress, DataWord inValue, DataWord inGas, public ProgramInvoke createProgramInvoke(Program program, DataWord toAddress, DataWord inValue, DataWord inGas,
BigInteger balanceInt, byte[] dataIn, BigInteger balanceInt, byte[] dataIn,
Repository repository, BlockStore blockStore) { Repository repository, BlockStore blockStore, boolean byTestingSuite) {
return null; return null;
} }

View File

@ -171,7 +171,7 @@ public class TestRunner {
byte[] lastHash = env.getPreviousHash(); byte[] lastHash = env.getPreviousHash();
byte[] coinbase = env.getCurrentCoinbase(); byte[] coinbase = env.getCurrentCoinbase();
long timestamp = new BigInteger(env.getCurrentTimestamp()).longValue(); long timestamp = new BigInteger(env.getCurrentTimestamp()).longValue();
long number = new BigInteger(env.getCurrentNumber()).longValue(); long number = ByteUtil.byteArrayToLong(env.getCurrentNumber());
byte[] difficulty = env.getCurrentDifficulty(); byte[] difficulty = env.getCurrentDifficulty();
long gaslimit = new BigInteger(env.getCurrentGasLimit()).longValue(); long gaslimit = new BigInteger(env.getCurrentGasLimit()).longValue();

View File

@ -269,7 +269,7 @@ public class ByteUtil {
final int firstNonZero = firstNonZeroByte(data); final int firstNonZero = firstNonZeroByte(data);
switch (firstNonZero) { switch (firstNonZero) {
case -1: case -1:
return EMPTY_BYTE_ARRAY; return ZERO_BYTE_ARRAY;
case 0: case 0:
return data; return data;

View File

@ -223,6 +223,9 @@ public class Program {
public void memoryExpand(DataWord outDataOffs, DataWord outDataSize) { public void memoryExpand(DataWord outDataOffs, DataWord outDataSize) {
if (outDataSize.isZero())
return ;
int maxAddress = outDataOffs.intValue() + outDataSize.intValue(); int maxAddress = outDataOffs.intValue() + outDataSize.intValue();
if (getMemSize() < maxAddress) { if (getMemSize() < maxAddress) {
memorySave(maxAddress, new byte[]{0}); memorySave(maxAddress, new byte[]{0});
@ -365,7 +368,7 @@ public class Program {
// [5] COOK THE INVOKE AND EXECUTE // [5] COOK THE INVOKE AND EXECUTE
ProgramInvoke programInvoke = programInvokeFactory.createProgramInvoke( ProgramInvoke programInvoke = programInvokeFactory.createProgramInvoke(
this, new DataWord(newAddress), DataWord.ZERO, gasLimit, this, new DataWord(newAddress), DataWord.ZERO, gasLimit,
newBalance, null, track, this.invokeData.getBlockStore()); newBalance, null, track, this.invokeData.getBlockStore(), invokeData.byTestingSuite());
ProgramResult result = null; ProgramResult result = null;
@ -392,7 +395,7 @@ public class Program {
if (programCode.length == 0) { if (programCode.length == 0) {
result = new ProgramResult(); result = new ProgramResult();
result.setHReturn(new byte[] {}); result.setHReturn(new byte[] {});
} }
// 4. CREATE THE CONTRACT OUT OF RETURN // 4. CREATE THE CONTRACT OUT OF RETURN
@ -470,8 +473,13 @@ public class Program {
stackPushZero(); stackPushZero();
return; return;
} }
result.getRepository().addBalance(senderAddress, endowment.negate()); result.getRepository().addBalance(senderAddress, endowment.negate());
BigInteger contextBalance = result.getRepository().addBalance(contextAddress, endowment);
BigInteger contextBalance = BigInteger.ZERO;
if (!invokeData.byTestingSuite()) {
contextBalance = result.getRepository().addBalance(contextAddress, endowment);
}
if (invokeData.byTestingSuite()) { if (invokeData.byTestingSuite()) {
// This keeps track of the calls created for a test // This keeps track of the calls created for a test
@ -486,7 +494,7 @@ public class Program {
Repository trackRepository = result.getRepository().startTracking(); Repository trackRepository = result.getRepository().startTracking();
ProgramInvoke programInvoke = programInvokeFactory.createProgramInvoke( ProgramInvoke programInvoke = programInvokeFactory.createProgramInvoke(
this, new DataWord(contextAddress), msg.getEndowment(), this, new DataWord(contextAddress), msg.getEndowment(),
msg.getGas(), contextBalance, data, trackRepository, this.invokeData.getBlockStore()); msg.getGas(), contextBalance, data, trackRepository, this.invokeData.getBlockStore(), invokeData.byTestingSuite());
ProgramResult result = null; ProgramResult result = null;
@ -922,8 +930,20 @@ public class Program {
public void callToPrecompiledAddress(MessageCall msg, PrecompiledContract contract) { public void callToPrecompiledAddress(MessageCall msg, PrecompiledContract contract) {
byte[] data = this.memoryChunk(msg.getInDataOffs(), msg.getInDataSize()).array(); byte[] data = this.memoryChunk(msg.getInDataOffs(), msg.getInDataSize()).array();
this.result.getRepository().addBalance(this.getOwnerAddress().getLast20Bytes(), msg.getEndowment().value().negate()); this.result.getRepository().addBalance(this.getOwnerAddress().getLast20Bytes(), msg.getEndowment().value().negate());
if (invokeData.byTestingSuite()) {
// This keeps track of the calls created for a test
this.getResult().addCallCreate(data,
msg.getCodeAddress().getLast20Bytes(),
msg.getGas().getNoLeadZeroesData(),
msg.getEndowment().getNoLeadZeroesData());
stackPushOne();
return;
}
this.result.getRepository().addBalance(msg.getCodeAddress().getLast20Bytes(), msg.getEndowment().value()); this.result.getRepository().addBalance(msg.getCodeAddress().getLast20Bytes(), msg.getEndowment().value());
long requiredGas = contract.getGasForData(data); long requiredGas = contract.getGasForData(data);

View File

@ -19,7 +19,7 @@ public interface ProgramInvokeFactory {
public ProgramInvoke createProgramInvoke(Program program, DataWord toAddress, public ProgramInvoke createProgramInvoke(Program program, DataWord toAddress,
DataWord inValue, DataWord inGas, DataWord inValue, DataWord inGas,
BigInteger balanceInt, byte[] dataIn, BigInteger balanceInt, byte[] dataIn,
Repository repository, BlockStore blockStore); Repository repository, BlockStore blockStore, boolean byTestingSuite);
} }

View File

@ -130,7 +130,7 @@ public class ProgramInvokeFactoryImpl implements ProgramInvokeFactory {
public ProgramInvoke createProgramInvoke(Program program, DataWord toAddress, public ProgramInvoke createProgramInvoke(Program program, DataWord toAddress,
DataWord inValue, DataWord inGas, DataWord inValue, DataWord inGas,
BigInteger balanceInt, byte[] dataIn, BigInteger balanceInt, byte[] dataIn,
Repository repository, BlockStore blockStore) { Repository repository, BlockStore blockStore, boolean byTestingSuite) {
DataWord address = toAddress; DataWord address = toAddress;
DataWord origin = program.getOriginAddress(); DataWord origin = program.getOriginAddress();
@ -183,6 +183,6 @@ public class ProgramInvokeFactoryImpl implements ProgramInvokeFactory {
return new ProgramInvokeImpl(address, origin, caller, balance, gasPrice, gas, callValue, return new ProgramInvokeImpl(address, origin, caller, balance, gasPrice, gas, callValue,
data, lastHash, coinbase, timestamp, number, difficulty, gasLimit, data, lastHash, coinbase, timestamp, number, difficulty, gasLimit,
repository, program.invokeData.getCallDeep() + 1, blockStore); repository, program.invokeData.getCallDeep() + 1, blockStore, byTestingSuite);
} }
} }

View File

@ -41,7 +41,7 @@ public class ProgramInvokeImpl implements ProgramInvoke {
DataWord gasPrice, DataWord gas, DataWord callValue, byte[] msgData, DataWord gasPrice, DataWord gas, DataWord callValue, byte[] msgData,
DataWord lastHash, DataWord coinbase, DataWord timestamp, DataWord number, DataWord DataWord lastHash, DataWord coinbase, DataWord timestamp, DataWord number, DataWord
difficulty, difficulty,
DataWord gaslimit, Repository repository, int callDeep, BlockStore blockStore) { DataWord gaslimit, Repository repository, int callDeep, BlockStore blockStore, boolean byTestingSuite) {
// Transaction env // Transaction env
this.address = address; this.address = address;
@ -65,6 +65,7 @@ public class ProgramInvokeImpl implements ProgramInvoke {
this.byTransaction = false; this.byTransaction = false;
this.callDeep = callDeep; this.callDeep = callDeep;
this.blockStore = blockStore; this.blockStore = blockStore;
this.byTestingSuite = byTestingSuite;
} }
public ProgramInvokeImpl(byte[] address, byte[] origin, byte[] caller, byte[] balance, public ProgramInvokeImpl(byte[] address, byte[] origin, byte[] caller, byte[] balance,

View File

@ -1126,6 +1126,8 @@ public class VM {
program.spendGas(GasCost.TX_ZERO_DATA * zeroVals, "DATA"); program.spendGas(GasCost.TX_ZERO_DATA * zeroVals, "DATA");
} }
if (program.invokeData.byTestingSuite()) return;
while (!program.isStopped()) while (!program.isStopped())
this.step(program); this.step(program);

View File

@ -17,11 +17,12 @@ import java.util.Set;
public class GitHubVMTest { public class GitHubVMTest {
@Ignore
@Test @Test
public void runSingle() throws ParseException { public void runSingle() throws ParseException {
String json = JSONReader.loadJSON("VMTests/vmArithmeticTest.json"); String json = JSONReader.loadJSON("VMTests/vmSystemOperationsTest.json");
GitHubJSONTestSuite.runGitHubJsonVMTest(json, ""); GitHubJSONTestSuite.runGitHubJsonVMTest(json, "CallToPrecompiledContract");
} }
@ -126,25 +127,25 @@ public class GitHubVMTest {
public void testvmSystemOperationsTestGitHub() throws ParseException { public void testvmSystemOperationsTestGitHub() throws ParseException {
Set<String> excluded = new HashSet<>(); Set<String> excluded = new HashSet<>();
excluded.add("CallToNameRegistratorNotMuchMemory0"); // excluded.add("CallToNameRegistratorNotMuchMemory0");
excluded.add("ABAcallsSuicide0"); // excluded.add("ABAcallsSuicide0");
excluded.add("CallToNameRegistratorNotMuchMemory1"); // excluded.add("CallToNameRegistratorNotMuchMemory1");
excluded.add("CallToNameRegistratorOutOfGas"); // excluded.add("CallToNameRegistratorOutOfGas");
excluded.add("callcodeToReturn1"); // excluded.add("callcodeToReturn1");
excluded.add("createNameRegistrator"); excluded.add("createNameRegistrator");
excluded.add("ABAcallsSuicide1"); // excluded.add("ABAcallsSuicide1");
excluded.add("CallToPrecompiledContract"); excluded.add("CallToPrecompiledContract");
excluded.add("ABAcalls1"); // excluded.add("ABAcalls1");
excluded.add("ABAcalls2"); // excluded.add("ABAcalls2");
excluded.add("ABAcalls3"); // excluded.add("ABAcalls3");
excluded.add("CallToNameRegistrator0"); // excluded.add("CallToNameRegistrator0");
excluded.add("ABAcalls0"); // excluded.add("ABAcalls0");
excluded.add("CallRecursiveBomb3"); // excluded.add("CallRecursiveBomb3");
excluded.add("CallRecursiveBomb2"); // excluded.add("CallRecursiveBomb2");
excluded.add("CallRecursiveBomb1"); // excluded.add("CallRecursiveBomb1");
excluded.add("CallRecursiveBomb0"); // excluded.add("CallRecursiveBomb0");
excluded.add("CallToReturn1"); // excluded.add("CallToReturn1");
excluded.add("callcodeToNameRegistrator0"); // excluded.add("callcodeToNameRegistrator0");
String json = JSONReader.loadJSON("VMTests/vmSystemOperationsTest.json"); String json = JSONReader.loadJSON("VMTests/vmSystemOperationsTest.json");

View File

@ -106,8 +106,8 @@ public class ByteUtilTest {
byte[] test4 = new byte[]{0x00, 0x01}; byte[] test4 = new byte[]{0x00, 0x01};
byte[] test5 = new byte[]{0x00, 0x00, 0x01}; byte[] test5 = new byte[]{0x00, 0x00, 0x01};
byte[] expected1 = null; byte[] expected1 = null;
byte[] expected2 = new byte[]{}; byte[] expected2 = new byte[]{0};
byte[] expected3 = new byte[]{}; byte[] expected3 = new byte[]{0};
byte[] expected4 = new byte[]{0x01}; byte[] expected4 = new byte[]{0x01};
byte[] expected5 = new byte[]{0x01}; byte[] expected5 = new byte[]{0x01};
assertArrayEquals(expected1, ByteUtil.stripLeadingZeroes(test1)); assertArrayEquals(expected1, ByteUtil.stripLeadingZeroes(test1));