use of org.ethereum.vm.DataWord in project rskj by rsksmart.
the class SamplePrecompiledContractTest method GetResult.
private int GetResult(Repository repository) {
DataWord addr = new DataWord(PrecompiledContracts.SAMPLE_ADDR.getBytes());
SamplePrecompiledContract contract = (SamplePrecompiledContract) precompiledContracts.getContractForAddress(addr);
String funcJson = "{\n" + " 'constant':false, \n" + " 'inputs':[], \n" + " 'name':'GetResult', \n" + " 'outputs':[{'name':'result','type':'int'}], \n" + " 'type':'function' \n" + "}\n";
funcJson = funcJson.replaceAll("'", "\"");
CallTransaction.Function function = CallTransaction.Function.fromJsonInterface(funcJson);
byte[] data = function.encode();
contract.init(null, null, repository, null, null, new ArrayList<LogInfo>());
byte[] result = contract.execute(data);
Object[] results = function.decodeResult(result);
return ((BigInteger) results[0]).intValue();
}
use of org.ethereum.vm.DataWord in project rskj by rsksmart.
the class SamplePrecompiledContractTest method samplePrecompiledContractIncrementResultOk.
@Test
public void samplePrecompiledContractIncrementResultOk() {
DataWord addr = new DataWord(PrecompiledContracts.SAMPLE_ADDR.getBytes());
SamplePrecompiledContract contract = (SamplePrecompiledContract) precompiledContracts.getContractForAddress(addr);
String funcJson = "{\n" + " 'constant':false, \n" + " 'inputs':[], \n" + " 'name':'IncrementResult', \n" + " 'outputs':[], \n" + " 'type':'function' \n" + "}\n";
funcJson = funcJson.replaceAll("'", "\"");
CallTransaction.Function function = CallTransaction.Function.fromJsonInterface(funcJson);
byte[] data = function.encode();
Repository repository = new RepositoryImpl(config);
Repository track = repository.startTracking();
contract.init(null, null, track, null, null, new ArrayList<LogInfo>());
contract.execute(data);
track.commit();
int result = this.GetResult(repository);
assertEquals(1, result);
}
use of org.ethereum.vm.DataWord in project rskj by rsksmart.
the class SamplePrecompiledContractTest method samplePrecompiledContractMethodDoesNotExist.
@Test
public void samplePrecompiledContractMethodDoesNotExist() {
DataWord addr = new DataWord(PrecompiledContracts.SAMPLE_ADDR.getBytes());
SamplePrecompiledContract contract = (SamplePrecompiledContract) precompiledContracts.getContractForAddress(addr);
String funcJson = "{\n" + " 'constant':false, \n" + " 'inputs':[{'name':'param0','type':'int'}, \n" + " {'name':'param1','type':'bytes'}, \n" + " {'name':'param2','type':'int'}], \n" + " 'name':'UnexistentMethod', \n" + " 'outputs':[{'name':'output0','type':'int'}], \n" + " 'type':'function' \n" + "}\n";
funcJson = funcJson.replaceAll("'", "\"");
CallTransaction.Function function = CallTransaction.Function.fromJsonInterface(funcJson);
byte[] bytes = new byte[] { (byte) 0xab, (byte) 0xcd, (byte) 0xef };
byte[] data = function.encode(111, bytes, 222);
contract.init(null, null, new RepositoryImpl(config), null, null, new ArrayList<LogInfo>());
byte[] result = contract.execute(data);
assertNull(result);
}
use of org.ethereum.vm.DataWord in project rskj by rsksmart.
the class Logs method compareToReal.
public List<String> compareToReal(List<LogInfo> logs) {
List<String> results = new ArrayList<>();
int i = 0;
for (LogInfo postLog : this.logs) {
LogInfo realLog = logs.get(i);
String postAddress = Hex.toHexString(postLog.getAddress());
String realAddress = Hex.toHexString(realLog.getAddress());
if (!postAddress.equals(realAddress)) {
String formattedString = String.format("Log: %s: has unexpected address, expected address: %s found address: %s", i, postAddress, realAddress);
results.add(formattedString);
}
String postData = Hex.toHexString(postLog.getData());
String realData = Hex.toHexString(realLog.getData());
if (!postData.equals(realData)) {
String formattedString = String.format("Log: %s: has unexpected data, expected data: %s found data: %s", i, postData, realData);
results.add(formattedString);
}
String postBloom = Hex.toHexString(postLog.getBloom().getData());
String realBloom = Hex.toHexString(realLog.getBloom().getData());
if (!postData.equals(realData)) {
String formattedString = String.format("Log: %s: has unexpected bloom, expected bloom: %s found bloom: %s", i, postBloom, realBloom);
results.add(formattedString);
}
List<DataWord> postTopics = postLog.getTopics();
List<DataWord> realTopics = realLog.getTopics();
int j = 0;
for (DataWord postTopic : postTopics) {
DataWord realTopic = realTopics.get(j);
if (!postTopic.equals(realTopic)) {
String formattedString = String.format("Log: %s: has unexpected topic: %s, expected topic: %s found topic: %s", i, j, postTopic, realTopic);
results.add(formattedString);
}
++j;
}
++i;
}
return results;
}
use of org.ethereum.vm.DataWord in project rskj by rsksmart.
the class TestRunner method loadRepository.
public Repository loadRepository(Repository track, Map<RskAddress, AccountState> pre) {
/* 1. Store pre-exist accounts - Pre */
for (RskAddress addr : pre.keySet()) {
AccountState accountState = pre.get(addr);
track.addBalance(addr, accountState.getBalance());
((RepositoryTrack) track).setNonce(addr, new BigInteger(1, accountState.getNonce()));
track.saveCode(addr, accountState.getCode());
for (DataWord storageKey : accountState.getStorage().keySet()) {
track.addStorageRow(addr, storageKey, accountState.getStorage().get(storageKey));
}
}
return track;
}
Aggregations