use of org.ethereum.vm.DataWord in project rskj by rsksmart.
the class AccountValidator method valid.
public static List<String> valid(RskAddress addr, AccountState expectedState, ContractDetails expectedDetails, AccountState currentState, ContractDetails currentDetails) {
List<String> results = new ArrayList<>();
if (currentState == null || currentDetails == null) {
String formattedString = String.format("Account: %s: expected but doesn't exist", addr);
results.add(formattedString);
return results;
}
if (expectedState == null || expectedDetails == null) {
String formattedString = String.format("Account: %s: unexpected account in the repository", addr);
results.add(formattedString);
return results;
}
Coin expectedBalance = expectedState.getBalance();
if (!currentState.getBalance().equals(expectedBalance)) {
String formattedString = String.format("Account: %s: has unexpected balance, expected balance: %s found balance: %s", addr, expectedBalance.toString(), currentState.getBalance().toString());
results.add(formattedString);
}
BigInteger expectedNonce = expectedState.getNonce();
if (currentState.getNonce().compareTo(expectedNonce) != 0) {
String formattedString = String.format("Account: %s: has unexpected nonce, expected nonce: %s found nonce: %s", addr, expectedNonce.toString(), currentState.getNonce().toString());
results.add(formattedString);
}
byte[] code = Arrays.equals(currentState.getCodeHash(), EMPTY_DATA_HASH) ? new byte[0] : currentDetails.getCode();
if (!Arrays.equals(expectedDetails.getCode(), code)) {
String formattedString = String.format("Account: %s: has unexpected code, expected code: %s found code: %s", addr, Hex.toHexString(expectedDetails.getCode()), Hex.toHexString(currentDetails.getCode()));
results.add(formattedString);
}
// compare storage
Set<DataWord> currentKeys = currentDetails.getStorage().keySet();
Set<DataWord> expectedKeys = expectedDetails.getStorage().keySet();
Set<DataWord> checked = new HashSet<>();
for (DataWord key : currentKeys) {
DataWord currentValue = currentDetails.getStorage().get(key);
DataWord expectedValue = expectedDetails.getStorage().get(key);
if (expectedValue == null) {
String formattedString = String.format("Account: %s: has unexpected storage data: %s = %s", addr, key, currentValue);
results.add(formattedString);
continue;
}
if (!expectedValue.equals(currentValue)) {
String formattedString = String.format("Account: %s: has unexpected value, for key: %s , expectedValue: %s real value: %s", addr, key.toString(), expectedValue.toString(), currentValue.toString());
results.add(formattedString);
continue;
}
checked.add(key);
}
for (DataWord key : expectedKeys) {
if (!checked.contains(key)) {
String formattedString = String.format("Account: %s: doesn't exist expected storage key: %s", addr, key.toString());
results.add(formattedString);
}
}
return results;
}
use of org.ethereum.vm.DataWord in project rskj by rsksmart.
the class LogsValidator method valid.
public static List<String> valid(List<LogInfo> origLogs, List<LogInfo> postLogs) {
List<String> results = new ArrayList<>();
int i = 0;
for (LogInfo postLog : postLogs) {
if (origLogs == null || origLogs.size() - 1 < i) {
String formattedString = String.format("Log: %s: was expected but doesn't exist: address: %s", i, Hex.toHexString(postLog.getAddress()));
results.add(formattedString);
continue;
}
LogInfo realLog = origLogs.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 GasLimitRuleTests method getBlock.
private static Block getBlock(long gasLimitValue) {
byte[] gasLimit = new DataWord(gasLimitValue).getData();
BlockHeader header = new BlockHeader(null, null, RskAddress.nullAddress().getBytes(), null, BlockDifficulty.ZERO.getBytes(), 0, gasLimit, 0, 0, null, null, 0);
return new Block(header);
}
use of org.ethereum.vm.DataWord in project rskj by rsksmart.
the class VMExecutionTest method swapnSecondItem.
@Test
public void swapnSecondItem() {
Program program = executeCode("PUSH1 0x01 PUSH1 0x02 PUSH1 0x00 SWAPN", 4);
Stack stack = program.getStack();
Assert.assertEquals(2, stack.size());
Assert.assertEquals(new DataWord(1), stack.peek());
Assert.assertEquals(new DataWord(2), stack.get(0));
}
use of org.ethereum.vm.DataWord in project rskj by rsksmart.
the class VMExecutionTest method testMul.
@Test
public void testMul() {
Program program = executeCode("PUSH1 3 PUSH1 2 MUL", 3);
Stack stack = program.getStack();
Assert.assertEquals(1, stack.size());
Assert.assertEquals(new DataWord(6), stack.peek());
}
Aggregations