repo
stringlengths 1
191
⌀ | file
stringlengths 23
351
| code
stringlengths 0
5.32M
| file_length
int64 0
5.32M
| avg_line_length
float64 0
2.9k
| max_line_length
int64 0
288k
| extension_type
stringclasses 1
value |
|---|---|---|---|---|---|---|
heldroid
|
heldroid-master/src/java/it/polimi/elet/necst/heldroid/goodware/ripper/FeatureRipper.java
|
package it.polimi.elet.necst.heldroid.goodware.ripper;
import it.polimi.elet.necst.heldroid.pipeline.ApplicationData;
import it.polimi.elet.necst.heldroid.smali.SmaliConstantFinder;
import it.polimi.elet.necst.heldroid.smali.SmaliLoader;
import it.polimi.elet.necst.heldroid.smali.core.SmaliClass;
import it.polimi.elet.necst.heldroid.smali.core.SmaliMethod;
import it.polimi.elet.necst.heldroid.smali.names.SmaliClassName;
import it.polimi.elet.necst.heldroid.smali.names.SmaliMemberName;
import it.polimi.elet.necst.heldroid.smali.statements.SmaliInvocationStatement;
import it.polimi.elet.necst.heldroid.smali.statements.SmaliStatement;
import it.polimi.elet.necst.heldroid.utils.Literal;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
public class FeatureRipper {
private BufferedWriter writer;
private ApplicationData currentData;
private Collection<String> permissions, intentFilters, usedFeatures;
private Collection<String> androidApis, otherApis, packageNames;
private Collection<String> hosts, phoneNumbers, osPrimitives, contents;
private Collection<String> activities, services, receivers, providers;
public FeatureRipper(File outputFile) throws IOException {
this.writer = new BufferedWriter(new FileWriter(outputFile));
}
public void rip(ApplicationData applicationData) {
this.currentData = applicationData;
ExecutorService executor = Executors.newFixedThreadPool(8);
executor.execute(new Runnable() {
@Override
public void run() {
ripPermissions();
}
});
executor.execute(new Runnable() {
@Override
public void run() {
ripIntentFilters();
}
});
executor.execute(new Runnable() {
@Override
public void run() {
ripUsedFeatures();
}
});
executor.execute(new Runnable() {
@Override
public void run() {
ripApisAndPackageNames();
}
});
executor.execute(new Runnable() {
@Override
public void run() {
ripHostsAndContents();
}
});
executor.execute(new Runnable() {
@Override
public void run() {
ripPhoneNumbers();
}
});
executor.execute(new Runnable() {
@Override
public void run() {
ripOsPrimitives();
}
});
executor.execute(new Runnable() {
@Override
public void run() {
ripClasses();
}
});
try {
executor.shutdown();
if (!executor.awaitTermination(10, TimeUnit.SECONDS))
executor.shutdownNow();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
public void writeout(Double detectionRatio, boolean adware) {
try {
writer.write("APK:");
writer.write(currentData.getDecodedPackage().getOriginalApk().getAbsolutePath());
writer.newLine();
writer.write("PERMISSIONS:");
writer.write(makeStringList(permissions));
writer.newLine();
writer.write("INTENT_FILTERS:");
writer.write(makeStringList(intentFilters));
writer.newLine();
writer.write("USED_FEATURES:");
writer.write(makeStringList(usedFeatures));
writer.newLine();
writer.write("ANDROID_APIS:");
writer.write(makeStringList(androidApis));
writer.newLine();
writer.write("OTHER_APIS:");
writer.write(makeStringList(otherApis));
writer.newLine();
writer.write("PACKAGE_NAMES:");
writer.write(makeStringList(packageNames));
writer.newLine();
writer.write("HOSTS:");
writer.write(makeStringList(hosts));
writer.newLine();
writer.write("PHONE_NUMBERS:");
writer.write(makeStringList(phoneNumbers));
writer.newLine();
writer.write("OS_PRIMITIVES:");
writer.write(makeStringList(osPrimitives));
writer.newLine();
writer.write("CONTENTS:");
writer.write(makeStringList(contents));
writer.newLine();
writer.write("ACTIVITIES:");
writer.write(makeStringList(activities));
writer.newLine();
writer.write("SERVICES:");
writer.write(makeStringList(services));
writer.newLine();
writer.write("RECEIVERS:");
writer.write(makeStringList(receivers));
writer.newLine();
writer.write("PROVIDERS:");
writer.write(makeStringList(providers));
writer.newLine();
writer.write("DETECTION_RATIO:");
writer.write(detectionRatio == null ? "?" : String.valueOf(detectionRatio));
writer.newLine();
writer.write("ADWARE:");
writer.write(String.valueOf(adware));
writer.newLine();
writer.flush();
} catch (IOException e) {
e.printStackTrace();
}
}
private void ripPermissions() {
permissions = currentData.getManifestReport().getPermissions();
}
private void ripIntentFilters() {
intentFilters = new ArrayList<String>(currentData.getManifestReport().getIntentFilters());
SmaliLoader loader = currentData.getSmaliLoader();
SmaliConstantFinder constantFinder = loader.generateConstantFinder();
constantFinder.setHandler(new SmaliConstantFinder.ConstantHandler() {
@Override
public boolean constantFound(String intentName) {
if (Literal.isString(intentName))
intentFilters.add(Literal.getStringValue(intentName));
return false;
}
});
constantFinder.searchParameters(new SmaliMemberName("Landroid/content/IntentFilter->addAction"), 0);
constantFinder.searchParameters(new SmaliMemberName("Landroid/content/IntentFilter;-><init>"), 0);
}
private void ripUsedFeatures() {
this.usedFeatures = currentData.getManifestReport().getUsedFeatures();
}
private void ripApisAndPackageNames() {
androidApis = new HashSet<String>();
otherApis = new HashSet<String>();
packageNames = new HashSet<String>();
SmaliLoader loader = currentData.getSmaliLoader();
for (SmaliClass klass : loader.getClasses()) {
packageNames.add(klass.getName().getPackageName());
for (SmaliMethod method : klass.getMethods())
for (SmaliStatement statement : method.getInterestingStatements()) {
if (!statement.is(SmaliInvocationStatement.class))
continue;
SmaliInvocationStatement invocation = (SmaliInvocationStatement) statement;
SmaliMemberName invokedName = invocation.getMethodName();
if (invokedName.getCompleteName().startsWith("Landroid"))
androidApis.add(invokedName.getCompleteName());
else if ((otherApis.size() < OTHER_APIS.size()) && OTHER_APIS.contains(invokedName.getCompleteName()))
otherApis.add(invokedName.getCompleteName());
}
}
}
private void ripHostsAndContents() {
hosts = new HashSet<String>();
contents = new HashSet<String>();
SmaliLoader loader = currentData.getSmaliLoader();
SmaliConstantFinder constantFinder = loader.generateConstantFinder();
constantFinder.setHandler(new SmaliConstantFinder.ConstantHandler() {
@Override
public boolean constantFound(String value) {
if (!Literal.isString(value))
return false;
String literal = Literal.getStringValue(value);
if (literal.startsWith("content://")) {
contents.add(literal);
return false;
}
try {
URL url = new URL(literal);
String host = url.getHost();
hosts.add(host);
} catch (MalformedURLException e) { }
return false;
}
});
constantFinder.searchAllLiterals();
}
private void ripPhoneNumbers() {
phoneNumbers = new HashSet<String>();
SmaliLoader loader = currentData.getSmaliLoader();
SmaliConstantFinder constantFinder = loader.generateConstantFinder();
constantFinder.setHandler(new SmaliConstantFinder.ConstantHandler() {
@Override
public boolean constantFound(String value) {
if (!Literal.isString(value))
return false;
String literal = Literal.getStringValue(value);
if (!isPhoneNumber(literal))
return false;
if (isSuspiciousNumber(literal))
phoneNumbers.add(literal);
return false;
}
});
constantFinder.searchParameters(new SmaliMemberName("Landroid/telephony/SmsManager;->sendTextMessage"), 0);
}
private void ripOsPrimitives() {
osPrimitives = new HashSet<String>();
SmaliLoader loader = currentData.getSmaliLoader();
SmaliConstantFinder constantFinder = loader.generateConstantFinder();
constantFinder.setHandler(new SmaliConstantFinder.ConstantHandler() {
@Override
public boolean constantFound(String value) {
if (!Literal.isString(value))
return false;
String literal = Literal.getStringValue(value);
osPrimitives.add(literal);
return false;
}
});
constantFinder.searchParameters(new SmaliMemberName("Ljava/lang/Runtime;->exec"), 0);
}
private void ripClasses() {
activities = new ArrayList<String>();
services = new ArrayList<String>();
receivers = new ArrayList<String>();
providers = new ArrayList<String>();
SmaliLoader loader = currentData.getSmaliLoader();
for (SmaliClass klass : loader.getClasses()) {
if (klass.isSubclassOf(ACTIVITY))
activities.add(klass.getName().getSimpleName());
else if (klass.isSubclassOf(SERVICE))
services.add(klass.getName().getSimpleName());
else if (klass.isSubclassOf(RECEIVER))
receivers.add(klass.getName().getSimpleName());
else if (klass.isSubclassOf(PROVIDER))
providers.add(klass.getName().getSimpleName());
}
}
private boolean isPhoneNumber(String literal) {
boolean prefix = true;
boolean isNumber = true;
for (Character c : literal.toCharArray()) {
if (!Character.isDigit(c)) {
if (prefix && c.equals(ALLOWED_NUMBER_PREFIXE))
continue;
isNumber = false;
break;
}
prefix = false;
}
return isNumber;
}
private boolean isSuspiciousNumber(String number) {
boolean isCarrierServiceNumber = false;
for (String prefix : CARRIER_NUMBERS_PREFIXES)
if (number.startsWith(prefix)) {
isCarrierServiceNumber = true;
break;
}
return !isCarrierServiceNumber;
}
private String makeStringList(Collection<String> strings) {
StringBuilder builder = new StringBuilder();
int i = 0;
for (String str : strings) {
if (i++ > 0) builder.append(",");
builder.append(str);
}
return builder.toString();
}
private static final String[] CARRIER_NUMBERS_PREFIXES = { "#", "*" };
private static final Character ALLOWED_NUMBER_PREFIXE = '+';
private static final SmaliClassName ACTIVITY = new SmaliClassName("Landroid/app/Activity;");
private static final SmaliClassName SERVICE = new SmaliClassName("Landroid/app/Service;");
private static final SmaliClassName RECEIVER = new SmaliClassName("Landroid/content/BroadcastReceiver;");
private static final SmaliClassName PROVIDER = new SmaliClassName("Landroid/content/ContentProvider;");
private static List<String> OTHER_APIS = Arrays.asList(
"Ljava/lang/System;->loadLibrary",
"Ljavax/crypto/Cipher;->getInstance",
"Ljava/lang/Runtime;->exec"
);
}
| 13,165
| 32.758974
| 122
|
java
|
heldroid
|
heldroid-master/src/java/it/polimi/elet/necst/heldroid/utils/Logging.java
|
package it.polimi.elet.necst.heldroid.utils;
import java.io.OutputStream;
import java.io.PrintStream;
public class Logging {
private static PrintStream originalOut, originalErr;
public static void suppressOut() {
originalOut = System.out;
PrintStream dummyStream = new PrintStream(new OutputStream(){
public void write(int b) { }
});
System.setOut(dummyStream);
}
public static void restoreOut() {
System.setOut(originalOut);
originalOut = null;
}
public static void suppressErr() {
originalErr = System.err;
PrintStream dummyStream = new PrintStream(new OutputStream(){
public void write(int b) { }
});
System.setErr(dummyStream);
}
public static void restoreErr() {
System.setErr(originalErr);
originalErr = null;
}
public static void suppressAll() {
suppressOut();
suppressErr();
}
public static void restoreAll() {
restoreErr();
restoreOut();
}
}
| 1,067
| 20.795918
| 69
|
java
|
heldroid
|
heldroid-master/src/java/it/polimi/elet/necst/heldroid/utils/MultiMap.java
|
package it.polimi.elet.necst.heldroid.utils;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
public class MultiMap<K, V> {
private Map<K, Collection<V>> map;
public MultiMap() {
map = new HashMap<K, Collection<V>>();
}
public void put(K name, V value) {
Collection<V> existingCollection = map.get(name);
if (existingCollection != null) {
existingCollection.add(value);
} else {
Collection<V> newCollection = new ArrayList<V>();
newCollection.add(value);
map.put(name, newCollection);
}
}
public void putAll(K name, Collection<V> values) {
Collection<V> existingCollection = map.get(name);
if (existingCollection != null) {
existingCollection.addAll(values);
} else {
Collection<V> newCollection = new ArrayList<V>();
newCollection.addAll(values);
map.put(name, newCollection);
}
}
public void replaceAll(K name, Collection<V> values) {
Collection<V> existingColletion = map.get(name);
if (existingColletion != null) {
existingColletion.clear();
existingColletion.addAll(values);
} else {
Collection<V> newCollection = new ArrayList<V>();
newCollection.addAll(values);
map.put(name, newCollection);
}
}
public void empty(K name) {
Collection<V> existingColletion = map.get(name);
if (existingColletion != null)
existingColletion.clear();
}
public Collection<V> get(K name) {
if (map.containsKey(name))
return map.get(name);
return map.put(name, new ArrayList<V>());
}
public boolean containsKey(K name) {
return map.containsKey(name);
}
}
| 1,893
| 26.057143
| 61
|
java
|
heldroid
|
heldroid-master/src/java/it/polimi/elet/necst/heldroid/utils/Wrapper.java
|
package it.polimi.elet.necst.heldroid.utils;
public class Wrapper<T> {
public T value;
public Wrapper() { }
public Wrapper(T value) {
this.value = value;
}
}
| 185
| 14.5
| 44
|
java
|
heldroid
|
heldroid-master/src/java/it/polimi/elet/necst/heldroid/utils/Literal.java
|
package it.polimi.elet.necst.heldroid.utils;
public class Literal {
public static boolean isString(String liteal) {
return liteal.startsWith("\"");
}
public static String getStringValue(String literal) {
return literal.replace("\"", "");
}
}
| 276
| 22.083333
| 57
|
java
|
heldroid
|
heldroid-master/src/java/it/polimi/elet/necst/heldroid/utils/MixedInputStream.java
|
package it.polimi.elet.necst.heldroid.utils;
import java.io.IOException;
import java.io.InputStream;
public class MixedInputStream extends InputStream {
private static final int PARTIAL_BUFFER_MAX_SIZE = 4096;
private InputStream stream;
private byte[] partialBuffer;
private int partialBufferIndex;
public MixedInputStream(InputStream stream) {
this.stream = stream;
this.partialBuffer = null;
this.partialBufferIndex = -1;
}
@Override
public int read() throws IOException {
return stream.read();
}
@Override
public int read(byte[] buffer, int offset, int length) throws IOException {
if (partialBuffer == null)
return stream.read(buffer, offset, length);
int remainingBufferSize = partialBuffer.length - partialBufferIndex;
if (remainingBufferSize >= length) {
System.arraycopy(partialBuffer, partialBufferIndex, buffer, offset, length);
partialBufferIndex += length;
if (partialBufferIndex == partialBuffer.length) {
partialBuffer = null;
partialBufferIndex = -1;
}
return length;
}
System.arraycopy(partialBuffer, partialBufferIndex, buffer, offset, remainingBufferSize);
partialBuffer = null;
partialBufferIndex = -1;
int readBytes = stream.read(buffer, offset + remainingBufferSize, length - remainingBufferSize);
return remainingBufferSize + readBytes;
}
public String readLine() throws IOException {
if (partialBuffer == null)
this.refillPartialBuffer();
StringBuilder builder = new StringBuilder();
boolean nrFound = false;
int i;
do {
for (i = partialBufferIndex ; i < partialBuffer.length; i++) {
if (partialBuffer[i] != 13)
builder.append((char)partialBuffer[i]);
else {
if ((i + 1 < partialBuffer.length) && (partialBuffer[i + 1] == 10))
i++;
nrFound = true;
break;
}
}
if (!nrFound && (i >= partialBuffer.length))
this.refillPartialBuffer();
} while (!nrFound);
partialBufferIndex = i + 1;
if (partialBufferIndex >= partialBuffer.length) {
partialBuffer = null;
partialBufferIndex = -1;
}
return builder.toString();
}
public void skipEmptyLines() throws IOException {
if (partialBuffer == null)
this.refillPartialBuffer();
boolean cFound = false;
int i;
do {
for (i = partialBufferIndex; i < partialBuffer.length; i++)
if (partialBuffer[i] == 13) {
if ((i + 1 < partialBuffer.length) && (partialBuffer[i + 1] == 10))
i++;
} else {
cFound = true;
break;
}
if (!cFound && (i >= partialBuffer.length))
this.refillPartialBuffer();
} while (!cFound);
partialBufferIndex = i;
}
private void refillPartialBuffer() throws IOException {
byte[] tempBuffer = new byte[PARTIAL_BUFFER_MAX_SIZE];
int actualLength = stream.read(tempBuffer, 0, tempBuffer.length);
partialBuffer = new byte[actualLength];
partialBufferIndex = 0;
System.arraycopy(tempBuffer, 0, partialBuffer, 0, actualLength);
}
}
| 3,598
| 28.5
| 104
|
java
|
heldroid
|
heldroid-master/src/java/it/polimi/elet/necst/heldroid/utils/Stopwatch.java
|
package it.polimi.elet.necst.heldroid.utils;
public class Stopwatch {
public static double time(Runnable runnable) {
Long startTime, endTime;
startTime = System.currentTimeMillis();
runnable.run();
endTime = System.currentTimeMillis();
return (double)(endTime - startTime) / 1000.0;
}
}
| 338
| 23.214286
| 54
|
java
|
heldroid
|
heldroid-master/src/java/it/polimi/elet/necst/heldroid/utils/CollectionToJsonConverter.java
|
package it.polimi.elet.necst.heldroid.utils;
import java.util.Collection;
import org.json.JSONArray;
public class CollectionToJsonConverter {
/**
* This method will create a JSONArray from a {@link Collection}. For each
* object inside the collection, the {@link Object#toString()} method is
* called and added to the JSONArray.
*
* @param collection
* The collection to transform to a JSONArray.
* @return An empty JSONArray if the collection is either {@code null} or
* empty, otherwise a JSONArray containing the
* {@link Object#toString()} representation of each object inside
* the collection.
*/
public static JSONArray convert(Collection<?> collection) {
JSONArray result = new JSONArray();
if (collection != null && collection.size() > 0) {
for (Object element : collection) {
result.put(element.toString());
}
}
return result;
}
}
| 925
| 27.060606
| 75
|
java
|
heldroid
|
heldroid-master/src/java/it/polimi/elet/necst/heldroid/utils/CFGUtils.java
|
/**
*
*/
package it.polimi.elet.necst.heldroid.utils;
import java.io.File;
import java.util.Collections;
import it.polimi.elet.necst.heldroid.apk.DecodedPackage;
import it.polimi.elet.necst.heldroid.ransomware.Globals;
import soot.PackManager;
import soot.Scene;
import soot.SootMethod;
import soot.jimple.infoflow.InfoflowConfiguration.CallgraphAlgorithm;
import soot.jimple.infoflow.android.SetupApplication;
import soot.jimple.infoflow.cfg.DefaultBiDiICFGFactory;
import soot.jimple.infoflow.solver.cfg.IInfoflowCFG;
import soot.options.Options;
/**
* @author Nicola Dellarocca
*
*/
public class CFGUtils {
/**
* Creates the CFG associated to the APK referenced by target
*
* @param target
* The decoded APK container
* @return The CFG or <code>null</code> if some error occurred
*
* @throws IllegalArgumentException
* If target is <code>null</code>
*/
public static IInfoflowCFG createCfg(DecodedPackage target)
throws IllegalArgumentException {
if (target == null)
throw new IllegalArgumentException("You must provide a valid APK target");
/*
* We will generate the CFG using the latest android version available
* on the platform.
*/
File libPath = Globals.getLatestAndroidVersion();
if (libPath == null)
libPath = Globals.ANDROID_PLATFORMS_DIRECTORY;
// A new setup application is required to create the CFG
SetupApplication app = new SetupApplication(libPath.getAbsolutePath(),
target .getOriginalApk()
.getAbsolutePath());
app .getConfig()
.setIgnoreFlowsInSystemPackages(false);
try {
app.calculateSourcesSinksEntrypoints("SourcesAndSinks.txt");
// Configure Soot
soot.G.reset();
Options .v()
.set_src_prec(Options.src_prec_apk);
Options .v()
.set_process_dir(
Collections.singletonList(target.getOriginalApk()
.getAbsolutePath()));
Options .v()
.set_force_android_jar(libPath.getAbsolutePath());
Options .v()
.set_whole_program(true);
Options .v()
.set_allow_phantom_refs(true);
Options .v()
.set_output_format(Options.output_format_jimple);
Options .v()
.setPhaseOption("cg.spark", "on");
Scene .v()
.loadNecessaryClasses();
SootMethod dummyMain = app .getEntryPointCreator()
.createDummyMain();
// The dummy main is the starting point
Options .v()
.set_main_class(dummyMain.getSignature());
// Share the dummy main
Scene .v()
.setEntryPoints(Collections.singletonList(dummyMain));
System.out.println(dummyMain.getActiveBody());
PackManager .v()
.runPacks();
DefaultBiDiICFGFactory factory = new DefaultBiDiICFGFactory();
IInfoflowCFG cfg = factory.buildBiDirICFG(
CallgraphAlgorithm.OnDemand, false);
return cfg;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}
| 2,873
| 25.366972
| 77
|
java
|
heldroid
|
heldroid-master/src/java/it/polimi/elet/necst/heldroid/utils/TextFileWriter.java
|
package it.polimi.elet.necst.heldroid.utils;
import java.io.*;
public class TextFileWriter extends FileWriter {
private boolean printOut = false;
private boolean fileOut = true;
public void setPrintOut(boolean printOut) {
this.printOut = printOut;
}
public void setFileOut(boolean fileOut) {
this.fileOut = fileOut;
}
public TextFileWriter(File file) throws IOException {
super(file);
}
public void writef(String formatString, Object... args) throws IOException {
this.write(String.format(formatString, args));
}
public void writeln(String text) throws IOException {
this.write(text);
this.write("\n");
}
public void writeln() throws IOException {
this.write("\n");
}
public void writefln(String formatString, Object... args) throws IOException {
this.writef(formatString, args);
this.writeln();
}
@Override
public void write(String s) throws IOException {
if (this.fileOut)
super.write(s);
if (this.printOut)
System.out.print(s);
}
}
| 1,134
| 22.645833
| 82
|
java
|
heldroid
|
heldroid-master/src/java/it/polimi/elet/necst/heldroid/utils/Options.java
|
package it.polimi.elet.necst.heldroid.utils;
public class Options {
private String args[];
public Options(String args[]) {
this.args = args;
}
public boolean contains(String option) {
for (int i = 0; i < args.length; i++)
if (args[i].equals(option))
return true;
return false;
}
public String getParameter(String option) {
for (int i = 0; i < args.length; i++)
if (args[i].equals(option))
return args[i + 1];
return null;
}
public String[] getParameters(String option, int count) {
for (int i = 0; i < args.length; i++)
if (args[i].equals(option)) {
String[] params = new String[count];
for (int j = 0; j < count; j++)
params[j] = args[i + 1 + j];
return params;
}
return null;
}
}
| 932
| 22.325
| 61
|
java
|
heldroid
|
heldroid-master/src/java/it/polimi/elet/necst/heldroid/utils/FileSystem.java
|
package it.polimi.elet.necst.heldroid.utils;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.FilenameFilter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.security.DigestInputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
public class FileSystem {
public static boolean deleteDirectory(File directory) {
if (isUnix()) {
try {
Process p = Runtime.getRuntime().exec(new String[]{"rm", "-rf", directory.getAbsolutePath()});
exhaustStreamAsync(p.getInputStream());
exhaustStreamAsync(p.getErrorStream());
p.waitFor();
} catch (Exception e) {
return false;
}
} else {
for (File file : directory.listFiles()) {
if (file.isDirectory())
deleteDirectory(file);
else
file.delete();
}
return (directory.delete());
}
return true;
}
private static void exhaustStream(InputStream inputStream) {
InputStreamReader reader = new InputStreamReader(inputStream);
BufferedReader bufferedReader = new BufferedReader(reader);
try {
while (bufferedReader.readLine() != null)
;
inputStream.close();
} catch (IOException e) { }
}
private static void exhaustStreamAsync(final InputStream inputStream) {
new Thread(new Runnable() {
@Override
public void run() {
exhaustStream(inputStream);
}
}).start();
}
private static boolean isUnix() {
return (File.separatorChar == '/');
}
public static String readFileAsString(File file) throws IOException {
BufferedReader reader = new BufferedReader(new FileReader(file));
StringBuilder stringBuilder = new StringBuilder();
String line = null;
while((line = reader.readLine()) != null) {
stringBuilder.append(line);
stringBuilder.append("\n");
}
return stringBuilder.toString();
}
public static String hashOf(File file) throws IOException {
MessageDigest md = null;
try {
md = MessageDigest.getInstance("MD5");
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
InputStream stream = new FileInputStream(file);
DigestInputStream digestStream = new DigestInputStream(stream, md);
byte[] buffer = new byte[4096];
int rb = 0;
while ((rb = digestStream.read(buffer, 0, buffer.length)) > 0)
;
digestStream.close();
return hex(md.digest());
}
private static String hex(byte[] bytes) {
StringBuilder builder = new StringBuilder();
for (byte b : bytes)
builder.append(String.format("%02x", b));
return builder.toString();
}
public static List<File> listFiles(File directory, final String suffix) {
List<File> files = new ArrayList<File>();
File[] array = directory.listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return name.endsWith(suffix);
}
});
if (array == null)
return files;
for (File file : array)
files.add(file);
return files;
}
/**
* Lists all files contained inside {@code directory} or
* its subfolders.
* @param directory
* @return
*/
public static List<File> listFilesRecursively(File directory) {
return FileSystem.listFilesRecursively(directory, "");
}
public static List<File> listFilesRecursively(File directory, FilenameFilter filter) {
List<File> files = new ArrayList<File>();
File[] array = directory.listFiles();
if (array == null) {
return files;
}
for (File file : array) {
if (file.isDirectory()) {
files.addAll(listFilesRecursively(file, filter));
} else if (filter.accept(file.getParentFile(), file.getName())) {
files.add(file);
}
}
return files;
}
public static List<File> listFilesRecursively(File directory, final String suffix) {
List<File> files = new ArrayList<File>();
File[] array = directory.listFiles();
if (array == null)
return files;
for (File file : array)
if (file.isDirectory())
files.addAll(listFilesRecursively(file, suffix));
else if (file.getName().endsWith(suffix))
files.add(file);
return files;
}
/**
* Searches recursively in all files contained inside {@code directory}
* (or its subfolders) for the regular expression {@code regex}.
* @param directory The parent directory in which perform the search
* @param regex The regex to search for
* @return {@code true} if at least one file contains a string that matches
* the {@code regex}, {@code false} otherwise.
*/
public static boolean searchRecursively(File directory, String regex) {
if (directory == null) {
throw new IllegalArgumentException("Directory cannot be null");
}
if (regex == null) {
throw new IllegalArgumentException("You must provide a valid pattern");
}
List<File> files = FileSystem.listFilesRecursively(directory, "smali");
for (File f : files) {
try (BufferedReader reader = new BufferedReader(new FileReader(f))) {
String line;
while ((line = reader.readLine()) != null) {
if (line.matches(regex))
return true;
}
} catch (IOException e) {
e.printStackTrace();
}
}
return false;
}
}
| 6,148
| 28.14218
| 110
|
java
|
heldroid
|
heldroid-master/src/java/it/polimi/elet/necst/heldroid/utils/Xml.java
|
package it.polimi.elet.necst.heldroid.utils;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
public class Xml {
public static Element getChildElement(Element parent, String name) {
NodeList nodes = parent.getElementsByTagName(name);
if (nodes.getLength() == 0)
return null;
Node node = nodes.item(0);
if (node.getNodeType() != Node.ELEMENT_NODE)
return null;
return (Element) node;
}
public static List<Element> getChildElements(Element parent) {
List<Element> result = new ArrayList<Element>();
NodeList nodes = parent.getChildNodes();
for (int i = 0; i < nodes.getLength(); i++) {
Node node = nodes.item(i);
if (node.getNodeType() == Node.ELEMENT_NODE)
result.add((Element)node);
}
return result;
}
public static Collection<Element> getElementsByTagName(Element parent, String tagName) {
NodeList backtrackNodes = parent.getElementsByTagName(tagName);
List<Element> results = new ArrayList<Element>();
for (int i = 0; i < backtrackNodes.getLength(); i++) {
Node node = backtrackNodes.item(i);
if (node.getNodeType() != Node.ELEMENT_NODE)
continue;
Element element = (Element) node;
results.add(element);
}
return results;
}
}
| 1,531
| 25.413793
| 92
|
java
|
heldroid
|
heldroid-master/src/java/it/polimi/elet/necst/heldroid/utils/PersistentFileList.java
|
package it.polimi.elet.necst.heldroid.utils;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
public class PersistentFileList {
private List<String> innerList;
private BufferedWriter writer;
public PersistentFileList(File repo) throws IOException {
innerList = new ArrayList<String>();
if (repo.exists()) {
BufferedReader reader = new BufferedReader(new FileReader(repo));
String line;
while ((line = reader.readLine()) != null)
innerList.add(line);
reader.close();
}
writer = new BufferedWriter(new FileWriter(repo, true)); // append to repo, if it exists
}
public synchronized void add(File file) {
innerList.add(file.getAbsolutePath());
try {
writer.write(file.getAbsolutePath());
writer.newLine();
writer.flush();
} catch (IOException e) {
e.printStackTrace();
}
}
public synchronized boolean contains(File file) {
return innerList.contains(file.getAbsolutePath());
}
public synchronized void dispose() {
try {
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
| 1,287
| 24.254902
| 96
|
java
|
heldroid
|
heldroid-master/src/java/it/polimi/elet/necst/heldroid/smali/SmaliLoader.java
|
package it.polimi.elet.necst.heldroid.smali;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import it.polimi.elet.necst.heldroid.pipeline.ThreadedCollectionExecutor;
import it.polimi.elet.necst.heldroid.smali.collections.QueryableSmaliClassCollection;
import it.polimi.elet.necst.heldroid.smali.core.SmaliClass;
import it.polimi.elet.necst.heldroid.smali.core.SmaliField;
import it.polimi.elet.necst.heldroid.smali.core.SmaliMethod;
import it.polimi.elet.necst.heldroid.smali.names.SmaliClassName;
import it.polimi.elet.necst.heldroid.smali.names.SmaliMemberName;
import it.polimi.elet.necst.heldroid.smali.statements.SmaliPutStatement;
import it.polimi.elet.necst.heldroid.smali.statements.SmaliStatement;
import it.polimi.elet.necst.heldroid.utils.MultiMap;
public class SmaliLoader {
private static final int FILES_PER_THREAD = 10;
private static final int MAX_THREADS_COUNT = 4;
private static final int INVOCATION_FLOW_STACK_LIMIT = 10;
private Map<String, SmaliClass> quickClassesMap;
private QueryableSmaliClassCollection classes;
private MultiMap<String, String> initializedFieldValues;
private SmaliInspector inspector;
public int getClassesCount() {
return classes.size();
}
public long getTotalClassesSize() {
long sum = 0;
for (SmaliClass klass : classes)
sum += klass.getSize();
return sum;
}
public Collection<SmaliClass> getClasses() {
return classes;
}
public Collection<SmaliClass> getSubclassesOf(SmaliClassName baseClassName) {
Collection<SmaliClass> result = new ArrayList<SmaliClass>();
for (SmaliClass klass : classes)
if (klass.isSubclassOf(baseClassName))
result.add(klass);
return result;
}
public SmaliClass getClassByName(SmaliClassName className) {
return classes.getClassByName(className);
}
public SmaliLoader(Collection<SmaliClass> classes) {
this.classes = new QueryableSmaliClassCollection(classes);
for (SmaliClass klass : this.classes)
klass.setAssociatedCollection(this.classes);
this.selectInitializedFields();
}
private SmaliLoader() {
this.classes = new QueryableSmaliClassCollection();
}
public static SmaliLoader onSources(Collection<File> classFiles) {
final SmaliLoader result = new SmaliLoader();
ThreadedCollectionExecutor<File> texecutor = new ThreadedCollectionExecutor<File>(MAX_THREADS_COUNT, FILES_PER_THREAD);
texecutor.setTimeout(10, TimeUnit.SECONDS);
texecutor.execute(classFiles, new ThreadedCollectionExecutor.ParameterizedRunnable<File>() {
@Override
public void run(File file) {
SmaliClass klass = null;
try {
klass = SmaliClass.parse(file);
} catch (Exception e) { }
if (klass == null)
return;
if (Thread.currentThread().isInterrupted())
return;
synchronized (result.classes) {
klass.setAssociatedCollection(result.classes);
result.classes.add(klass);
}
}
});
result.selectInitializedFields();
return result;
}
public static SmaliLoader onSource(File smaliSource) throws IOException, SmaliFormatException {
SmaliLoader result = new SmaliLoader();
SmaliClass klass = SmaliClass.parse(smaliSource);
if (klass == null)
throw new IllegalArgumentException("Not a valid smali source.");
klass.setAssociatedCollection(result.classes);
result.classes.add(klass);
result.selectInitializedFields();
return result;
}
/**
* Scans all the smali classes collected into this inspector and finds all the values that fields have been assigned
* either in their declaration (in-line initialization) or in other methods' body (typically in the constructor).
*/
private void selectInitializedFields() {
if (initializedFieldValues == null)
initializedFieldValues = new MultiMap<String, String>();
synchronized (classes) {
for (SmaliClass klass : classes) {
for (SmaliField field : klass.getFields())
if (field.getLiteralValue() != null) {
SmaliMemberName fieldName = new SmaliMemberName(klass.getName(), field.getName());
initializedFieldValues.put(fieldName.getCompleteName(), field.getLiteralValue());
}
for (SmaliMethod method : klass.getMethods()) {
final SmaliSimulator simulator = SmaliSimulator.on(method);
simulator.addHandler(SmaliPutStatement.class, new SmaliSimulator.StatementHandler() {
@Override
public boolean statementReached(SmaliStatement statement) {
SmaliPutStatement putter = (SmaliPutStatement) statement;
SmaliMemberName fieldName = putter.getFieldName();
initializedFieldValues.putAll(
fieldName.getCompleteName(),
simulator.getPossibleValues(putter.getRegister()));
return false;
}
});
simulator.simulate();
}
}
}
}
public SmaliConstantFinder generateConstantFinder() {
return new SmaliConstantFinder(classes, initializedFieldValues);
}
public SmaliConstantFinder generateConstantFinder(Collection<SmaliClass> classesSubset) {
return new SmaliConstantFinder(classesSubset, initializedFieldValues);
}
public SmaliConstantFinder generateConstantFinder(SmaliClass klass) {
List<SmaliClass> singleton = new ArrayList<SmaliClass>();
singleton.add(klass);
return this.generateConstantFinder(singleton);
}
public SmaliInspector generateInspector() {
if (inspector != null)
return inspector;
return (inspector = new SmaliInspector(classes));
}
}
| 6,466
| 33.956757
| 127
|
java
|
heldroid
|
heldroid-master/src/java/it/polimi/elet/necst/heldroid/smali/SmaliSimulator.java
|
package it.polimi.elet.necst.heldroid.smali;
import it.polimi.elet.necst.heldroid.smali.core.SmaliMethod;
import it.polimi.elet.necst.heldroid.smali.names.SmaliMemberName;
import it.polimi.elet.necst.heldroid.smali.statements.*;
import it.polimi.elet.necst.heldroid.utils.MultiMap;
import java.util.*;
public class SmaliSimulator {
public interface StatementHandler {
/**
* Callback method invoked when a given statement type is reached.
* @param statement The reached statement. May need casting to an appropriate subclass.
* @return Returns true if you want to terminate the method simulation. Except in the case statement is a
* SmaliIfStatement: in that case, true means to take the true branch and false to take the false branch.
*/
boolean statementReached(SmaliStatement statement);
}
private SmaliMethod target;
private int statementIndex;
private Map<Class, StatementHandler> handlers;
private MultiMap<String, String> initializedFieldValues;
private MultiMap<String, String> fieldDerivedRegisterValues;
private Map<String, String> currentConstants;
private SmaliSimulator(SmaliMethod target) {
this.target = target;
this.handlers = new HashMap<Class, StatementHandler>();
this.reset();
}
public static SmaliSimulator on(SmaliMethod target) {
return new SmaliSimulator(target);
}
public void setInitializedFieldValues(MultiMap<String, String> obj) {
this.initializedFieldValues = obj;
}
public void addHandler(Class statementClass, StatementHandler handler) {
handlers.put(statementClass, handler);
}
public void removeHandler(Class statementClass) {
handlers.remove(statementClass);
}
public Collection<String> getPossibleValues(String registerName) {
Collection<String> result = new ArrayList<String>();
if (currentConstants.containsKey(registerName))
result.add(currentConstants.get(registerName));
if (fieldDerivedRegisterValues.containsKey(registerName))
result.addAll(fieldDerivedRegisterValues.get(registerName));
return result;
}
public void reset() {
this.statementIndex = 0;
this.fieldDerivedRegisterValues = new MultiMap<String, String>();
this.currentConstants = new HashMap<String, String>();
}
public void simulate() {
this.reset();
while (this.step())
;
}
private boolean step() {
// A register/parameter can hold only one value at a time. We consider only registers that are assigned literal
// values. Among those, the value is either a literal constant defined with a const statement or the content
// of a class field which has been initialized somewhere with a literal value itself. In the second case, more than
// one value is possible: since this analysis is aimed to be simple and quick, no complex flow mechanism is
// adopted and as such we do not know which execution path contains the true value used. We can at most obtain a
// false negative in detection, which is of no importance.
// At any given time, the set of keys of fieldDerivedRegisterValues and currentConstants are strictly disjoint.
if (statementIndex >= target.getInterestingStatements().size())
return false;
SmaliStatement statement = target.getInterestingStatements().get(statementIndex);
// A constant is being declared: memorize its value in the constants mapping
if (statement.is(SmaliConstantStatement.class))
this.defineConstant((SmaliConstantStatement) statement);
// A value is being moved: move it also in the current mappings
else if (statement.is(SmaliMoveStatement.class))
this.executeMove((SmaliMoveStatement) statement);
// A field is being read: if it has a constant value, put it in the current mapping
else if (statement.is(SmaliGetStatement.class))
this.readField((SmaliGetStatement)statement);
// An if statement is encountered: the client decides which branch he wants to follow. Otheriwse
// the flow will simply fall through
else if (statement.is(SmaliIfStatement.class)) {
boolean takeBranch = callHandler(statement);
if (takeBranch) {
SmaliIfStatement ifStatement = (SmaliIfStatement)statement;
Integer jumpIndex = target.getTargetStatementIndex(ifStatement.getLabel());
if (jumpIndex >= 0)
statementIndex = jumpIndex - 1;
}
statementIndex++;
return true;
}
statementIndex++;
// Then, call an appropriate handler, if it exists
// callHandler returns true iif the called handler returns true as well, which means that it is
// no longer needed to proceed in the simulation; therefore, in that case, step returns false, which
// halts the simulation cycle in simulate()
if (callHandler(statement))
return false;
return true;
}
private boolean callHandler(SmaliStatement statement) {
StatementHandler handler = handlers.get(statement.getClass());
if (handler != null)
return handler.statementReached(statement);
return false;
}
private void defineConstant(SmaliConstantStatement konst) {
currentConstants.put(konst.getRegister(), konst.getValue());
fieldDerivedRegisterValues.empty(konst.getRegister());
}
private void executeMove(SmaliMoveStatement move) {
String source = move.getSource();
String destination = move.getDestination();
// Moves value from source to destination in currentConstants mapping
if (currentConstants.containsKey(source)) {
String value = currentConstants.get(source);
currentConstants.remove(source);
currentConstants.put(destination, value);
fieldDerivedRegisterValues.empty(destination);
}
// Does the same for fieldDerivedRegisterValues mapping, only considering more potential values at once
else if (fieldDerivedRegisterValues.containsKey(source)) {
Collection<String> values = fieldDerivedRegisterValues.get(source);
fieldDerivedRegisterValues.empty(source);
fieldDerivedRegisterValues.putAll(destination, values);
currentConstants.remove(destination);
}
}
private void readField(SmaliGetStatement getter) {
if (initializedFieldValues == null)
return;
SmaliMemberName fieldName = getter.getFieldName();
String fieldCompleteName = fieldName.getCompleteName();
if (initializedFieldValues.containsKey(fieldCompleteName)) {
fieldDerivedRegisterValues.replaceAll(getter.getRegister(), initializedFieldValues.get(fieldCompleteName));
currentConstants.remove(getter.getRegister());
}
}
}
| 7,128
| 38.826816
| 123
|
java
|
heldroid
|
heldroid-master/src/java/it/polimi/elet/necst/heldroid/smali/SmaliConstantFinder.java
|
package it.polimi.elet.necst.heldroid.smali;
import it.polimi.elet.necst.heldroid.smali.core.SmaliClass;
import it.polimi.elet.necst.heldroid.smali.core.SmaliField;
import it.polimi.elet.necst.heldroid.smali.core.SmaliMethod;
import it.polimi.elet.necst.heldroid.smali.names.SmaliMemberName;
import it.polimi.elet.necst.heldroid.smali.statements.SmaliConstantStatement;
import it.polimi.elet.necst.heldroid.smali.statements.SmaliInvocationStatement;
import it.polimi.elet.necst.heldroid.smali.statements.SmaliStatement;
import it.polimi.elet.necst.heldroid.utils.Literal;
import it.polimi.elet.necst.heldroid.utils.MultiMap;
import it.polimi.elet.necst.heldroid.utils.Wrapper;
import java.util.Collection;
public class SmaliConstantFinder {
public interface ConstantHandler {
/**
* Callback method invoked when a constant value is found.
* @param value The constant value as string. Notice that constants that are string-typed in smali code
* are enclosed by double quotes.
* @return Returns true if you want to terminate the search.
*/
public boolean constantFound(String value);
}
private MultiMap<String, String> initializedFieldValues;
private Collection<SmaliClass> classes;
private ConstantHandler handler;
SmaliConstantFinder(Collection<SmaliClass> classes, MultiMap<String, String> initializedFieldValues) {
this.classes = classes;
this.initializedFieldValues = initializedFieldValues;
}
public void setHandler(ConstantHandler handler) {
this.handler = handler;
}
public void searchAllLiterals() {
for (SmaliClass klass : classes)
this.searchAllLiterals(klass);
}
public void searchAllLiterals(SmaliClass klass) {
for (SmaliField field : klass.getFields())
if (field.getLiteralValue() != null)
if ((handler != null) && handler.constantFound(field.getLiteralValue()))
return;
for(SmaliMethod method : klass.getMethods()) {
for (SmaliStatement statement : method.getInterestingStatements())
if (statement.is(SmaliConstantStatement.class)) {
String value = ((SmaliConstantStatement)statement).getValue();
if ((handler != null) && handler.constantFound(value))
return;
}
}
}
public void searchParameters(SmaliMemberName methodName, int parameterIndex) {
for (SmaliClass klass : classes)
for (SmaliMethod method : klass.getMethods()) {
boolean aborted = this.searchParameters(methodName, parameterIndex, method);
if (aborted)
return;
}
}
public boolean testInvocationParameter(SmaliMemberName methodName, int paramIndex, final String paramValue) {
final Wrapper<Boolean> found = new Wrapper<Boolean>(false);
this.setHandler(new ConstantHandler() {
@Override
public boolean constantFound(String value) {
String escaped = Literal.getStringValue(value);
if (escaped.equals(paramValue)) {
found.value = true;
return true;
}
return false;
}
});
this.searchParameters(methodName, paramIndex);
return found.value;
}
private boolean searchParameters(final SmaliMemberName methodName, final int parameterIndex, SmaliMethod analyzedMethod) {
final SmaliSimulator simulator = SmaliSimulator.on(analyzedMethod);
final ConstantHandler constantHandler = this.handler;
final Wrapper<Boolean> aborted = new Wrapper<Boolean>();
aborted.value = false;
simulator.setInitializedFieldValues(initializedFieldValues);
simulator.addHandler(SmaliInvocationStatement.class, new SmaliSimulator.StatementHandler() {
@Override
public boolean statementReached(SmaliStatement statement) {
SmaliInvocationStatement invocation = (SmaliInvocationStatement)statement;
SmaliMemberName invokeName = invocation.getMethodName();
if (!invokeName.equals(methodName))
return false;
if (invocation.getParameterTypes().size() > parameterIndex) {
// invoke requires object to invoke on as first parameter, except for invoke-static
int paramOffset = (invocation.getParameters().size() > invocation.getParameterTypes().size()) ? 1 : 0;
String parameter = invocation.getParameters().get(parameterIndex + paramOffset);
Collection<String> possibleValues = simulator.getPossibleValues(parameter);
for (String value : possibleValues)
if (constantHandler.constantFound(value)) {
aborted.value = true;
return true;
}
}
return false;
}
});
simulator.simulate();
return aborted.value;
}
}
| 5,219
| 38.545455
| 126
|
java
|
heldroid
|
heldroid-master/src/java/it/polimi/elet/necst/heldroid/smali/SmaliInspector.java
|
package it.polimi.elet.necst.heldroid.smali;
import it.polimi.elet.necst.heldroid.smali.collections.QueryableSmaliClassCollection;
import it.polimi.elet.necst.heldroid.smali.core.SmaliClass;
import it.polimi.elet.necst.heldroid.smali.core.SmaliMethod;
import it.polimi.elet.necst.heldroid.smali.names.SmaliClassName;
import it.polimi.elet.necst.heldroid.smali.names.SmaliMemberName;
import it.polimi.elet.necst.heldroid.smali.statements.SmaliInvocationStatement;
import it.polimi.elet.necst.heldroid.smali.statements.SmaliStatement;
import java.util.*;
public class SmaliInspector {
private static final int INVOCATION_FLOW_STACK_LIMIT = 3;
private QueryableSmaliClassCollection classCollection;
SmaliInspector(QueryableSmaliClassCollection classes) {
this.classCollection = classes;
}
public boolean[] invocationsExist(List<SmaliMemberName> methodNames) {
boolean[] methodsFound = new boolean[methodNames.size()];
for (SmaliClass klass : classCollection)
for (SmaliMethod method : klass.getMethods())
for (SmaliStatement statement : method.getInterestingStatements())
if (statement.is(SmaliInvocationStatement.class)) {
SmaliInvocationStatement invoke = (SmaliInvocationStatement) statement;
SmaliMemberName invokeName = invoke.getMethodName();
for (int i = 0; i < methodNames.size(); i++)
if (invokeName.equals(methodNames.get(i)))
methodsFound[i] = true;
}
return methodsFound;
}
public class Inspection {
private Collection<String> exitPoints;
private boolean onlyCheckClass;
private Inspection(boolean onlyCheckClass) {
this.exitPoints = new ArrayList<String>();
this.onlyCheckClass = onlyCheckClass;
}
void addMethodNames(Collection<SmaliMemberName> exitPoints) {
for (SmaliMemberName memberName : exitPoints)
this.exitPoints.add(memberName.getCompleteName());
}
void addMethodName(SmaliMemberName exitPoint) {
this.exitPoints.add(exitPoint.getCompleteName());
}
void addClasseNames(Collection<SmaliClassName> exitPoints) {
for (SmaliClassName className : exitPoints)
this.exitPoints.add(className.getCompleteName());
}
void addClassName(SmaliClassName exitPoint) {
this.exitPoints.add(exitPoint.getCompleteName());
}
public boolean reachableFrom(SmaliMethod entryPoint) {
return SmaliInspector.this.flowExists(entryPoint, exitPoints, entryPoint, 0, onlyCheckClass);
}
public boolean reachableFromAny(SmaliMemberName virtualMethodName) {
return reachableFromAny(classCollection, virtualMethodName);
}
public boolean reachableFromAny(Collection<SmaliClass> providedClasses, SmaliMemberName virtualMethodName) {
SmaliClassName baseClassName = virtualMethodName.getClassName();
for (SmaliClass klass : providedClasses) {
if (!klass.isSubclassOf(baseClassName))
continue;
SmaliMethod method = klass.getMethodByName(virtualMethodName);
if (method == null)
continue;
if (this.reachableFrom(method))
return true;
}
return false;
}
}
public Inspection is(SmaliMemberName methodName) {
Inspection methodInspection = new Inspection(false);
methodInspection.addMethodName(methodName);
return methodInspection;
}
public Inspection isAny(Collection<SmaliMemberName> methodNames) {
Inspection methodInspection = new Inspection(false);
methodInspection.addMethodNames(methodNames);
return methodInspection;
}
public Inspection isClass(SmaliClassName className) {
Inspection classInspection = new Inspection(true);
classInspection.addClassName(className);
return classInspection;
}
public Inspection isAnyClass(Collection<SmaliClassName> classNames) {
Inspection classInspection = new Inspection(true);
classInspection.addClasseNames(classNames);
return classInspection;
}
private boolean flowExists(SmaliMethod entryPoint, Collection<String> methodOrClassExitPoints, SmaliMethod originalEntryPoint, int stackLimit, boolean onlyCheckClass) {
// Avoid circular references
if (stackLimit > 0 && entryPoint.equals(originalEntryPoint))
return false;
// We have to go deeper! Or not...
if (stackLimit > INVOCATION_FLOW_STACK_LIMIT)
return false;
// Contains a collection of methods for further inspections
Collection<SmaliMethod> invokedMethods = new ArrayList<SmaliMethod>();
// Contains a mapping from a register name to its class type (only for classes defined in smali files)
Map<String, SmaliClass> registerLocalTypes = new HashMap<String, SmaliClass>();
for (SmaliStatement statement : entryPoint.getInterestingStatements()) {
if (!statement.is(SmaliInvocationStatement.class))
continue;
SmaliInvocationStatement invocationStatement = (SmaliInvocationStatement) statement;
SmaliMemberName invokedMethodName = invocationStatement.getMethodName();
String searchTarget;
// If we only care about which class a method is invoked from
if (onlyCheckClass)
searchTarget = invokedMethodName.getClassName().getCompleteName();
else
searchTarget = invokedMethodName.getCompleteName();
// If this method invocation is within our blacklist, the search ends in success
if (methodOrClassExitPoints.contains(searchTarget))
return true;
// A new thread has been created. We can look into its Runnable target for further inspections
if (invokedMethodName.equals(THREAD_CONSTRUCTOR) && invocationStatement.getParameters().size() > 1) {
List<String> parameterTypes = invocationStatement.getParameterTypes();
String registerArgument = null;
// Since Thread has multiple overloaded constructors, check for the parameter index associated to
// the correct parameter (i.e. a Runnable instance). Luckily, smali invocations report exact signatures
for (int i = 0; i < parameterTypes.size(); i++)
if (parameterTypes.get(i).equals(RUNNABLE))
registerArgument = invocationStatement.getParameters().get(i + 1);
// If a runnable is passed to the constructor and we have previously seen that register associated
// with a specific class, then the run method of that class is reachable through this code
if ((registerArgument != null) && registerLocalTypes.containsKey(registerArgument)) {
SmaliClass runnableClass = registerLocalTypes.get(registerArgument);
SmaliMethod runMethod = runnableClass.getMethodByName(RUNNABLE_RUN);
if (runMethod != null)
invokedMethods.add(runMethod);
}
}
// Otherwise, if the invoked method is coded within another smali file, keep looking at its
// content recursively
SmaliClass targetClass = classCollection.getClassByName(invokedMethodName.getClassName());
if (targetClass != null) {
// A constructor method is being called
if (invokedMethodName.getMemberName().equals(CONSTRUCTOR)) {
// This register contains an instance of the class type on which the constructor is being invoked
String register = invocationStatement.getParameters().get(0);
registerLocalTypes.put(register, targetClass);
}
SmaliMethod invokedMethod = targetClass.getMethodByName(invokedMethodName);
if ((invokedMethod == null) || (stackLimit == INVOCATION_FLOW_STACK_LIMIT))
continue;
// Add the method for later inspection. This is a semi-breadth-first semi-depth-first analysis
invokedMethods.add(invokedMethod);
}
}
registerLocalTypes.clear();
registerLocalTypes = null;
// Checks if any of our callees is reachable through a further method invocation
for (SmaliMethod invokedMethod : invokedMethods) {
if (flowExists(invokedMethod, methodOrClassExitPoints, originalEntryPoint, stackLimit + 1, onlyCheckClass))
return true;
}
// If anything else fails, return false
return false;
}
private static final String CONSTRUCTOR = "<init>";
private static final String RUNNABLE = "Ljava/lang/Runnable;";
private static final SmaliMemberName RUNNABLE_RUN = new SmaliMemberName("Ljava/lang/Runnable;->run");
private static final SmaliMemberName THREAD_CONSTRUCTOR = new SmaliMemberName("Ljava/lang/Thread;-><init>");
}
| 9,404
| 42.948598
| 172
|
java
|
heldroid
|
heldroid-master/src/java/it/polimi/elet/necst/heldroid/smali/SmaliHelper.java
|
package it.polimi.elet.necst.heldroid.smali;
import java.util.ArrayList;
import java.util.List;
public class SmaliHelper {
public static final String SMALI_EXTENSION = ".smali";
// Type examples: "I", "[S", "Ljava/lang/Object;"
public static final String TYPE_REGEX = "[\\w\\d\\$\\/\\[;_]+";
// Access modifier examples: "public", "static", "declared-synchronized"
public static final String ACCESS_MODIFIER_REGEX = "[\\-\\w]+";
// Identifier examples: "<init>", "onCreate", "my_method", "open$3"
public static final String IDENTIFIER_REGEX = "[\\w\\d\\$\\<\\>_]+";
// Parameters examples: "v0", "p1, p3, v5", "v1 .. v2", ""
public static final String PARAMETERS_REGEX = "[pv\\.\\d\\s,]*";
// Qualifier examples: "/16", "-wide", "-static/range", "/high16", ""
public static final String QUALIFIER_REGEX = "[\\/\\-\\w\\d]*";
public static List<String> parseParameterTypesList(String parameterTypesList) {
List<String> result = new ArrayList<String>();
StringBuilder builder = new StringBuilder();
boolean complexTypeOpen = false;
for (Character c : parameterTypesList.toCharArray()) {
builder.append(c);
switch (c) {
case 'L':
complexTypeOpen = true;
break;
case 'Z': // boolean
case 'B': // byte
case 'S': // string
case 'C': // char
case 'I': // int
case 'J': // long
case 'F': // float
case 'D': // double
if (!complexTypeOpen) {
result.add(builder.toString());
builder.setLength(0);
}
break;
case ';':
result.add(builder.toString());
builder.setLength(0);
complexTypeOpen = false;
break;
}
}
return result;
}
}
| 2,047
| 34.310345
| 83
|
java
|
heldroid
|
heldroid-master/src/java/it/polimi/elet/necst/heldroid/smali/SmaliSyntaxException.java
|
package it.polimi.elet.necst.heldroid.smali;
public class SmaliSyntaxException extends Exception {
public SmaliSyntaxException(String message) {
super(message);
}
}
| 182
| 21.875
| 53
|
java
|
heldroid
|
heldroid-master/src/java/it/polimi/elet/necst/heldroid/smali/SmaliFormatException.java
|
package it.polimi.elet.necst.heldroid.smali;
public class SmaliFormatException extends Exception {
public SmaliFormatException(String message) {
super(message);
}
}
| 182
| 21.875
| 53
|
java
|
heldroid
|
heldroid-master/src/java/it/polimi/elet/necst/heldroid/smali/core/SmaliField.java
|
package it.polimi.elet.necst.heldroid.smali.core;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class SmaliField {
private static final String DECLARATION_PREFIX = ".field";
private static final Pattern DECLARATION_PATTERN = Pattern.compile("\\.field\\s+([\\-\\w]+\\s+)*?([\\w\\d\\$]+):([\\w\\d\\$\\/\\[]+;?)(\\s+\\=\\s+(.+))?");
private static final int NAME_GROUP = 2;
private static final int TYPE_GROUP = 3;
private static final int LITERAL_VALUE_GROUP = 5;
private String name;
private String type;
private String literalValue;
private SmaliField() { }
public static boolean isDeclaredIn(String codeLine) {
return codeLine.trim().startsWith(DECLARATION_PREFIX);
}
public static SmaliField parse(String codeLine) {
Matcher matcher = DECLARATION_PATTERN.matcher(codeLine);
if (!matcher.find())
return null;
SmaliField result = new SmaliField();
result.name = matcher.group(NAME_GROUP);
result.type = matcher.group(TYPE_GROUP);
result.literalValue = matcher.group(LITERAL_VALUE_GROUP);
return result;
}
public String getName() {
return name;
}
public String getType() {
return type;
}
public String getLiteralValue() {
return literalValue;
}
}
| 1,361
| 25.705882
| 159
|
java
|
heldroid
|
heldroid-master/src/java/it/polimi/elet/necst/heldroid/smali/core/SmaliClass.java
|
package it.polimi.elet.necst.heldroid.smali.core;
import it.polimi.elet.necst.heldroid.smali.SmaliFormatException;
import it.polimi.elet.necst.heldroid.smali.SmaliHelper;
import it.polimi.elet.necst.heldroid.smali.collections.QueryableSmaliClassCollection;
import it.polimi.elet.necst.heldroid.smali.names.SmaliClassName;
import it.polimi.elet.necst.heldroid.smali.names.SmaliMemberName;
import java.io.*;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class SmaliClass {
private static final Pattern DECLARATION_PATTERN = Pattern.compile("\\.class\\s+([\\-\\w]+\\s+)*L([\\w\\d\\$\\/_]+);");
private static final Pattern SUPER_PATTERN = Pattern.compile("\\.super\\s+([\\w\\d\\$\\/_]+);");
private static final Pattern COMMENT_PATTERN = Pattern.compile("\\s*#.*");
private static final int NAME_GROUP = 2;
private static final int SUPER_GROUP = 1;
private long size;
private SmaliClassName name, superClassName;
private Map<String, SmaliMethod> quickMethodsMap;
private Collection<SmaliField> fields;
private Collection<SmaliMethod> methods;
private QueryableSmaliClassCollection associatedCollection;
public void setAssociatedCollection(QueryableSmaliClassCollection collection) {
this.associatedCollection = collection;
}
public long getSize() {
return size;
}
public SmaliClassName getSuperClassName() {
return superClassName;
}
public SmaliClassName getName() {
return name;
}
private SmaliClass() {
this.fields = new ArrayList<SmaliField>();
this.methods = new ArrayList<SmaliMethod>();
}
public static SmaliClass parse(File file) throws IOException, SmaliFormatException {
if (!file.getName().toLowerCase().endsWith(SmaliHelper.SMALI_EXTENSION))
throw new SmaliFormatException("Invalid file type.");
BufferedReader reader = new BufferedReader(new FileReader(file));
boolean headerFound = false;
String line, completeName;
completeName = null;
while ((line = reader.readLine()) != null) {
Matcher classHeaderMatcher = DECLARATION_PATTERN.matcher(line);
if (classHeaderMatcher.find()) {
completeName = classHeaderMatcher.group(NAME_GROUP);
headerFound = true;
break;
}
}
if (!headerFound) {
reader.close();
throw new SmaliFormatException("No class header found.");
}
SmaliClass result = new SmaliClass();
SmaliMethod.Builder methodBuilder = null;
result.name = new SmaliClassName("L" + completeName + ";");
while ((line = reader.readLine()) != null) {
Matcher matcher = SUPER_PATTERN.matcher(line);
if (matcher.find()) {
result.superClassName = new SmaliClassName(matcher.group(SUPER_GROUP) + ";"); // same as above
continue;
}
if (SmaliField.isDeclaredIn(line)) {
SmaliField field = SmaliField.parse(line);
if (field != null)
result.fields.add(field);
} else {
if (SmaliMethod.startsHere(line))
methodBuilder = new SmaliMethod.Builder();
if (methodBuilder != null)
methodBuilder.append(line);
if (SmaliMethod.endsHere(line)) {
SmaliMethod method = methodBuilder.build();
result.methods.add(method);
methodBuilder = null;
}
}
}
reader.close();
result.size = file.length();
return result;
}
public boolean matchesType(SmaliClassName typeName) {
return this.getName().equals(typeName) || typeName.equals(this.getSuperClassName());
}
public Collection<SmaliField> getFields() {
return fields;
}
public Collection<SmaliMethod> getMethods() {
return methods;
}
public SmaliMethod getMethodByName(SmaliMemberName name) {
String methodName = name.getMemberName();
if (quickMethodsMap != null)
return quickMethodsMap.get(methodName);
SmaliMethod result = null;
quickMethodsMap = new HashMap<String, SmaliMethod>();
for (SmaliMethod method : methods) {
quickMethodsMap.put(method.getName(), method);
if (method.getName().equals(methodName))
result = method;
}
return result;
}
public SmaliMethod getMethodBySignature(SmaliMemberName name, List<String> parameterTypes) {
String methodName = name.getMemberName();
for (SmaliMethod method : methods) {
if (method.getName().equals(methodName)) {
if (method.getParameterTypes().size() != parameterTypes.size())
continue;
for (int i = 0; i < parameterTypes.size(); i++)
if (!method.getParameterTypes().get(i).equals(parameterTypes.get(i)))
continue;
return method;
}
}
return null;
}
public boolean isSubclassOf(SmaliClassName className) {
return associatedCollection.classExtends(this, className);
}
public String toString() {
return this.getName().toString();
}
}
| 5,483
| 29.983051
| 123
|
java
|
heldroid
|
heldroid-master/src/java/it/polimi/elet/necst/heldroid/smali/core/SmaliMethod.java
|
package it.polimi.elet.necst.heldroid.smali.core;
import it.polimi.elet.necst.heldroid.smali.SmaliFormatException;
import it.polimi.elet.necst.heldroid.smali.SmaliHelper;
import it.polimi.elet.necst.heldroid.smali.statements.SmaliLabelDeclaration;
import it.polimi.elet.necst.heldroid.smali.statements.SmaliStatement;
import it.polimi.elet.necst.heldroid.smali.SmaliSyntaxException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class SmaliMethod {
static class Builder {
List<String> codeLines;
public Builder() {
this.codeLines = new ArrayList<String>();
}
public void append(String codeLine) {
codeLines.add(codeLine);
}
public SmaliMethod build() throws SmaliFormatException {
return SmaliMethod.parse(this.codeLines);
}
}
private static final String DECLARATION_START_PREFIX = ".method";
private static final String DECLARATION_END_PREFIX = ".end method";
private static final Pattern SIGNATURE_PATTERN = Pattern.compile("\\.method\\s+([\\-\\w]+\\s+)*([\\w\\d\\$\\<\\>]+)\\s*\\(([\\s\\w\\d\\$\\/\\[;]*)\\)([\\w\\d\\$\\/\\[;]+)");
private static final int NAME_GROUP = 2;
private static final int PARAMETER_TYPES_LIST_GROUP = 3;
private static final int RETURN_TYPE_GROUP = 4;
private String name;
private String returnType;
private List<String> parameterTypes;
private List<String> codeLines;
private List<SmaliStatement> interestingStatements;
private Map<String, Integer> labelOffsets;
private SmaliMethod() {
this.codeLines = new ArrayList<String>();
this.parameterTypes = new ArrayList<String>();
this.labelOffsets = new HashMap<String, Integer>();
}
public static boolean startsHere(String codeLine) {
return codeLine.trim().startsWith(DECLARATION_START_PREFIX);
}
public static boolean endsHere(String codeLine) {
return codeLine.trim().startsWith(DECLARATION_END_PREFIX);
}
public static SmaliMethod parse(List<String> codeLines) throws SmaliFormatException {
String signatureLine = codeLines.get(0);
Matcher signatureMatcher = SIGNATURE_PATTERN.matcher(signatureLine);
if (!signatureMatcher.find())
throw new SmaliFormatException("No valid method header found in: " + signatureLine);
SmaliMethod result = new SmaliMethod();
result.name = signatureMatcher.group(NAME_GROUP);
result.returnType = signatureMatcher.group(RETURN_TYPE_GROUP);
result.parameterTypes = SmaliHelper.parseParameterTypesList(signatureMatcher.group(PARAMETER_TYPES_LIST_GROUP));
codeLines.remove(0); // removes .method ... (start line)
codeLines.remove(codeLines.size() - 1); // removes .end method (end line)
result.codeLines.addAll(codeLines);
result.parseCodeLines();
return result;
}
private void parseCodeLines() {
if (interestingStatements == null)
interestingStatements = new ArrayList<SmaliStatement>();
for (String codeLine : codeLines) {
try {
SmaliStatement statement = SmaliStatement.parse(codeLine);
if (statement != null) {
interestingStatements.add(statement);
if (statement.is(SmaliLabelDeclaration.class)) {
SmaliLabelDeclaration declaration = (SmaliLabelDeclaration)statement;
labelOffsets.put(declaration.getLabel(), interestingStatements.size());
}
}
} catch (SmaliSyntaxException ssex) {
// ssex.printStackTrace();
}
}
}
public String getName() {
return name;
}
public String getReturnType() {
return returnType;
}
public List<String> getParameterTypes() {
return parameterTypes;
}
public List<SmaliStatement> getInterestingStatements() {
return interestingStatements;
}
public Integer getTargetStatementIndex(String label) {
Integer index = labelOffsets.get(label);
if ((index == null) || (index >= interestingStatements.size()))
return -1;
return index;
}
public SmaliStatement getTargetStatement(String label) {
Integer index = this.getTargetStatementIndex(label);
if (index >= 0)
return interestingStatements.get(index);
return null;
}
public String toString() {
return this.getName();
}
}
| 4,725
| 31.593103
| 177
|
java
|
heldroid
|
heldroid-master/src/java/it/polimi/elet/necst/heldroid/smali/collections/QueryableSmaliClassCollection.java
|
package it.polimi.elet.necst.heldroid.smali.collections;
import it.polimi.elet.necst.heldroid.smali.core.SmaliClass;
import it.polimi.elet.necst.heldroid.smali.names.SmaliClassName;
import java.util.*;
public class QueryableSmaliClassCollection implements Collection<SmaliClass> {
private Collection<SmaliClass> innerCollection;
private Map<String, SmaliClass> quickClassesMap;
public QueryableSmaliClassCollection() {
this.innerCollection = new ArrayList<SmaliClass>();
}
public QueryableSmaliClassCollection(Collection<SmaliClass> classCollection) {
this.innerCollection = classCollection;
}
public SmaliClass getClassByName(SmaliClassName className) {
String completeClassName = className.getCompleteName();
if (quickClassesMap != null)
return quickClassesMap.get(completeClassName);
SmaliClass result = null;
quickClassesMap = new HashMap<String, SmaliClass>();
for (SmaliClass klass : innerCollection) {
quickClassesMap.put(klass.getName().getCompleteName(), klass);
if (klass.getName().getCompleteName().equals(completeClassName))
result = klass;
}
return result;
}
/***
* Checks whether a class extends another known class (usually from android api).
* @param klass Instance of SmaliClass to check.
* @param baseClassName Complete smali name of the base class.
* @return Returns true iif klass is a subclass of the class determined by baseClassCompleteName, even directly
* or indirectly (through any other class defined in the inspector files).
*/
public boolean classExtends(SmaliClass klass, SmaliClassName baseClassName) {
SmaliClassName superClassName = klass.getSuperClassName();
if (superClassName == null)
return false;
if (superClassName.equals(baseClassName))
return true;
SmaliClass base = this.getClassByName(klass.getSuperClassName());
if (base != null)
return this.classExtends(base, baseClassName);
return false;
}
@Override
public int size() {
return innerCollection.size();
}
@Override
public boolean isEmpty() {
return innerCollection.isEmpty();
}
@Override
public boolean contains(Object o) {
return innerCollection.contains(o);
}
@Override
public Iterator<SmaliClass> iterator() {
return innerCollection.iterator();
}
@Override
public Object[] toArray() {
return innerCollection.toArray();
}
@Override
public <T> T[] toArray(T[] ts) {
return innerCollection.toArray(ts);
}
@Override
public boolean add(SmaliClass smaliClass) {
if (quickClassesMap != null)
quickClassesMap.put(smaliClass.getName().getCompleteName(), smaliClass);
return innerCollection.add(smaliClass);
}
@Override
public boolean remove(Object o) {
if (o.getClass().equals(SmaliClass.class) && (quickClassesMap != null))
quickClassesMap.remove(((SmaliClass)o).getName().getCompleteName());
return innerCollection.remove(o);
}
@Override
public boolean containsAll(Collection<?> objects) {
return innerCollection.containsAll(objects);
}
@Override
public boolean addAll(Collection<? extends SmaliClass> smaliClasses) {
return innerCollection.addAll(smaliClasses);
}
@Override
public boolean removeAll(Collection<?> objects) {
return innerCollection.removeAll(objects);
}
@Override
public boolean retainAll(Collection<?> objects) {
return innerCollection.retainAll(objects);
}
@Override
public void clear() {
innerCollection.clear();
}
@Override
public boolean equals(Object o) {
return innerCollection.equals(o);
}
@Override
public int hashCode() {
return innerCollection.hashCode();
}
}
| 4,039
| 26.862069
| 115
|
java
|
heldroid
|
heldroid-master/src/java/it/polimi/elet/necst/heldroid/smali/names/SmaliMemberName.java
|
package it.polimi.elet.necst.heldroid.smali.names;
import java.util.ArrayList;
import java.util.List;
public class SmaliMemberName {
private SmaliClassName className;
private String memberName;
private String completeName;
public SmaliMemberName(String completeName) {
String[] parts = completeName.split("\\-\\>");
if (parts.length != 2)
throw new IllegalArgumentException("The name must be in the form Lpackage/class;->memberName");
this.className = new SmaliClassName(parts[0]);
this.memberName = parts[1];
this.completeName = completeName;
}
public SmaliMemberName(SmaliClassName className, String memberName) {
this.className = className;
this.memberName = memberName;
this.completeName = className.getCompleteName() + "->" + memberName;
}
public SmaliMemberName(String className, String memberName) {
this(new SmaliClassName(className), memberName);
}
public SmaliClassName getClassName() {
return className;
}
public String getMemberName() {
return memberName;
}
public String getCompleteName() {
return completeName;
}
public boolean equals(SmaliMemberName other) {
return this.completeName.equals(other.completeName);
}
public String toString() {
return this.completeName;
}
public static List<SmaliMemberName> newList(String... completeNames) {
List<SmaliMemberName> result = new ArrayList<SmaliMemberName>(completeNames.length);
for (int i = 0; i < completeNames.length; i++)
result.add(new SmaliMemberName(completeNames[i]));
return result;
}
}
| 1,717
| 26.709677
| 107
|
java
|
heldroid
|
heldroid-master/src/java/it/polimi/elet/necst/heldroid/smali/names/SmaliClassName.java
|
package it.polimi.elet.necst.heldroid.smali.names;
public class SmaliClassName {
private String packageName;
private String simpleName;
private String completeName;
public SmaliClassName(String completeName) {
this.completeName = completeName;
if (completeName.indexOf('/') >= 0) {
this.packageName = completeName.substring(0, completeName.lastIndexOf("/"));
this.simpleName = completeName.substring(this.getPackageName().length() + 1);
} else {
this.packageName = "";
this.simpleName = completeName;
}
if (this.packageName.startsWith("L"))
this.packageName = this.packageName.substring(1);
if (this.simpleName.endsWith(";"))
this.simpleName = this.simpleName.substring(0, this.simpleName.length() - 1);
}
public String getPackageName() {
return packageName;
}
public String getSimpleName() {
return simpleName;
}
public String getCompleteName() {
return completeName;
}
public boolean equals(SmaliClassName other) {
return this.completeName.equals(other.completeName);
}
public String toString() {
return this.completeName;
}
}
| 1,259
| 26.391304
| 89
|
java
|
heldroid
|
heldroid-master/src/java/it/polimi/elet/necst/heldroid/smali/statements/SmaliNewInstanceStatement.java
|
package it.polimi.elet.necst.heldroid.smali.statements;
import it.polimi.elet.necst.heldroid.smali.SmaliSyntaxException;
import it.polimi.elet.necst.heldroid.smali.names.SmaliClassName;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class SmaliNewInstanceStatement extends SmaliStatement {
private static final String CALL_PREFIX = "new-instance";
private static final Pattern CALL_PATTERN = Pattern.compile("new\\-instance\\s+([v]\\d+)\\s*,\\s*([\\w\\d\\/\\$\\[;]+)");
private static final int REGISTER_GROUP = 1;
private static final int TYPE_GROUP = 2;
private String register;
private SmaliClassName instanceType;
private SmaliNewInstanceStatement() { }
public static boolean isCalledIn(String codeLine) {
return codeLine.trim().startsWith(CALL_PREFIX);
}
public static SmaliNewInstanceStatement parse(String codeLine) throws SmaliSyntaxException {
Matcher matcher = CALL_PATTERN.matcher(codeLine);
if (!matcher.find())
throw new SmaliSyntaxException("Cannot parse new-instance statement: " + codeLine);
SmaliNewInstanceStatement result = new SmaliNewInstanceStatement();
result.register = matcher.group(REGISTER_GROUP);
result.instanceType = new SmaliClassName(matcher.group(TYPE_GROUP));
return result;
}
public String getRegister() {
return register;
}
public SmaliClassName getInstanceType() {
return instanceType;
}
}
| 1,509
| 31.12766
| 125
|
java
|
heldroid
|
heldroid-master/src/java/it/polimi/elet/necst/heldroid/smali/statements/SmaliMoveStatement.java
|
package it.polimi.elet.necst.heldroid.smali.statements;
import it.polimi.elet.necst.heldroid.smali.SmaliSyntaxException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class SmaliMoveStatement extends SmaliStatement {
private static final String CALL_PREFIX = "move";
private static final Pattern CALL_PATTERN = Pattern.compile("move([\\/\\-\\w\\d]*)\\s+([pv]\\d+)\\s*,\\s*([pv]\\d+)");
private static final int QUALIFIER_GROUP = 1;
private static final int DESTINATION_GROUP = 2;
private static final int SOURCE_GROUP = 3;
private String qualifier;
private String destination;
private String source;
private SmaliMoveStatement() { }
public static boolean isCalledIn(String codeLine) {
return codeLine.trim().startsWith(CALL_PREFIX);
}
public static SmaliMoveStatement parse(String codeLine) throws SmaliSyntaxException {
Matcher matcher = CALL_PATTERN.matcher(codeLine);
if (!matcher.find())
throw new SmaliSyntaxException("Cannot parse move statement: " + codeLine);
SmaliMoveStatement result = new SmaliMoveStatement();
result.qualifier = matcher.group(QUALIFIER_GROUP);
result.destination = matcher.group(DESTINATION_GROUP);
result.source = matcher.group(SOURCE_GROUP);
return result;
}
public String getQualifier() {
return qualifier;
}
public String getDestination() {
return destination;
}
public String getSource() {
return source;
}
}
| 1,559
| 28.433962
| 122
|
java
|
heldroid
|
heldroid-master/src/java/it/polimi/elet/necst/heldroid/smali/statements/SmaliArrayGetStatement.java
|
package it.polimi.elet.necst.heldroid.smali.statements;
public class SmaliArrayGetStatement extends SmaliArrayAccessStatement {
}
| 131
| 25.4
| 71
|
java
|
heldroid
|
heldroid-master/src/java/it/polimi/elet/necst/heldroid/smali/statements/SmaliArrayAccessStatement.java
|
package it.polimi.elet.necst.heldroid.smali.statements;
import it.polimi.elet.necst.heldroid.smali.SmaliSyntaxException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class SmaliArrayAccessStatement extends SmaliStatement {
private static final String[] CALL_PREFIXES = {"aget", "aput" };
private static final String ACTION_GET = "get";
private static final String ACTION_PUT = "put";
private static final Pattern CALL_PATTERN = Pattern.compile("a(get|put)(\\-\\w+)?\\s+([pv]\\d+)\\s*,\\s*([pv]\\d+)\\s*,\\s*([pv]\\d+)");
protected String qualifier;
protected String targetRegister;
protected String arrayRegister;
protected String indexRegister;
public static boolean isCalledIn(String codeLine) {
String trimmedLine = codeLine.trim();
for (String prefix : CALL_PREFIXES)
if (trimmedLine.startsWith(prefix))
return true;
return false;
}
public static SmaliArrayAccessStatement parse(String codeLine) throws SmaliSyntaxException {
Matcher matcher = CALL_PATTERN.matcher(codeLine);
if (!matcher.find())
throw new SmaliSyntaxException("Cannot parse aget/aput statement: " + codeLine);
String action = matcher.group(ACTION_GROUP);
SmaliArrayAccessStatement result;
if (action.equals(ACTION_GET))
result = new SmaliArrayGetStatement();
else
result = new SmaliArrayPutStatement();
result.qualifier = matcher.group(QUALIFIER_GROUP);
result.targetRegister = matcher.group(TARGET_GROUP);
result.arrayRegister = matcher.group(ARRAY_GROUP);
result.indexRegister = matcher.group(INDEX_GROUP);
return result;
}
public String getQualifier() {
return qualifier;
}
public String getTargetRegister() {
return targetRegister;
}
public String getArrayRegister() {
return arrayRegister;
}
public String getIndexRegister() {
return indexRegister;
}
private static final int ACTION_GROUP = 1;
private static final int QUALIFIER_GROUP = 2;
private static final int TARGET_GROUP = 3;
private static final int ARRAY_GROUP = 4;
private static final int INDEX_GROUP = 5;
}
| 2,299
| 30.081081
| 140
|
java
|
heldroid
|
heldroid-master/src/java/it/polimi/elet/necst/heldroid/smali/statements/SmaliGetStatement.java
|
package it.polimi.elet.necst.heldroid.smali.statements;
public class SmaliGetStatement extends SmaliAccessStatement {
}
| 121
| 23.4
| 61
|
java
|
heldroid
|
heldroid-master/src/java/it/polimi/elet/necst/heldroid/smali/statements/SmaliMoveResultStatement.java
|
package it.polimi.elet.necst.heldroid.smali.statements;
import it.polimi.elet.necst.heldroid.smali.SmaliSyntaxException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class SmaliMoveResultStatement extends SmaliStatement {
private static final String CALL_PREFIX = "move-result";
private static final Pattern CALL_PATTERN = Pattern.compile("move\\-result(\\-\\w+)?\\s+([pv]\\d+)");
private static final int QUALIFIER_GROUP = 1;
private static final int DESTINATION_GROUP = 2;
private String qualifier;
private String destination;
private SmaliMoveResultStatement() { }
public static boolean isCalledIn(String codeLine) {
return codeLine.trim().startsWith(CALL_PREFIX);
}
public static SmaliMoveResultStatement parse(String codeLine) throws SmaliSyntaxException {
Matcher matcher = CALL_PATTERN.matcher(codeLine);
if (!matcher.find())
throw new SmaliSyntaxException("Cannot parse move-result statement: " + codeLine);
SmaliMoveResultStatement result = new SmaliMoveResultStatement();
result.qualifier = matcher.group(QUALIFIER_GROUP);
result.destination = matcher.group(DESTINATION_GROUP);
return result;
}
public String getQualifier() {
return qualifier;
}
public String getDestination() {
return destination;
}
}
| 1,397
| 29.391304
| 105
|
java
|
heldroid
|
heldroid-master/src/java/it/polimi/elet/necst/heldroid/smali/statements/SmaliConstantStatement.java
|
package it.polimi.elet.necst.heldroid.smali.statements;
import it.polimi.elet.necst.heldroid.smali.SmaliSyntaxException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class SmaliConstantStatement extends SmaliStatement {
private static final String CALL_PREFIX = "const";
private static final Pattern CALL_PATTERN = Pattern.compile("const([\\/\\-\\w\\d]*)\\s+([pv]\\d+)\\s*,\\s*(.+)");
private static final int QUALIFIER_GROUP = 1;
private static final int REGISTER_GROUP = 2;
private static final int VALUE_GROUP = 3;
private String qualifier;
private String register;
private String value;
private SmaliConstantStatement() { }
public static boolean isCalledIn(String codeLine) {
return codeLine.trim().startsWith(CALL_PREFIX);
}
public static SmaliConstantStatement parse(String codeLine) throws SmaliSyntaxException {
Matcher matcher = CALL_PATTERN.matcher(codeLine);
if (!matcher.find())
throw new SmaliSyntaxException("Cannot parse const statement: " + codeLine);
SmaliConstantStatement result = new SmaliConstantStatement();
result.qualifier = matcher.group(QUALIFIER_GROUP);
result.register = matcher.group(REGISTER_GROUP);
result.value = matcher.group(VALUE_GROUP);
return result;
}
public String getQualifier() {
return qualifier;
}
public String getRegister() {
return register;
}
public String getValue() {
return value;
}
}
| 1,552
| 28.301887
| 117
|
java
|
heldroid
|
heldroid-master/src/java/it/polimi/elet/necst/heldroid/smali/statements/SmaliReturnStatement.java
|
package it.polimi.elet.necst.heldroid.smali.statements;
import it.polimi.elet.necst.heldroid.smali.SmaliSyntaxException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class SmaliReturnStatement extends SmaliStatement {
private static final String CALL_PREFIX = "return";
private static final Pattern CALL_PATTERN = Pattern.compile("(return\\-void|return(\\-(\\w+))?\\s+([pv]\\d+))");
private static final int WHOLE_GROUP = 0;
private static final int QUALIFIER_GROUP = 3;
private static final int REGISTER_GROUP = 4;
private String qualifier;
private String register;
public static boolean isCalledIn(String codeLine) {
return codeLine.trim().startsWith(CALL_PREFIX);
}
public static SmaliReturnStatement parse(String codeLine) throws SmaliSyntaxException {
Matcher matcher = CALL_PATTERN.matcher(codeLine);
if (!matcher.find())
throw new SmaliSyntaxException("Cannot parse return statement: " + codeLine);
SmaliReturnStatement result = new SmaliReturnStatement();
String whole = matcher.group(WHOLE_GROUP);
if (whole.equals("return-void")) {
result.qualifier = "void";
result.register = null;
} else {
result.qualifier = matcher.group(QUALIFIER_GROUP);
result.register = matcher.group(REGISTER_GROUP);
}
return result;
}
public String getQualifier() {
return qualifier;
}
public String getRegister() {
return register;
}
}
| 1,570
| 29.803922
| 116
|
java
|
heldroid
|
heldroid-master/src/java/it/polimi/elet/necst/heldroid/smali/statements/SmaliIfStatement.java
|
package it.polimi.elet.necst.heldroid.smali.statements;
import it.polimi.elet.necst.heldroid.smali.SmaliSyntaxException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class SmaliIfStatement extends SmaliStatement {
private static final String CALL_PREFIX = "if-";
private static final Pattern CALL_PATTERN = Pattern.compile("if\\-([neltzgq]+)\\s+([pv]\\d+)\\s*,\\s*([pv]\\d+|:[\\w\\_]+)(\\s*,\\s*)?(:[\\w\\_]+)?");
private static final int QUALIFIER_GROUP = 1;
private static final int ZERO_REGISTER_GROUP = 2;
private static final int ZERO_LABEL_GROUP = 3;
private static final int EQUALS_REGISTER1_GROUP = 2;
private static final int EQUALS_REGISTER2_GROUP = 3;
private static final int EQUALS_LABEL_GROUP = 5;
private String qualifier;
private String register1, register2;
private String label;
public static boolean isCalledIn(String codeLine) {
return codeLine.trim().startsWith(CALL_PREFIX);
}
public static SmaliIfStatement parse(String codeLine) throws SmaliSyntaxException {
Matcher matcher = CALL_PATTERN.matcher(codeLine);
if (!matcher.find())
throw new SmaliSyntaxException("Cannot parse if statement: " + codeLine);
SmaliIfStatement result = new SmaliIfStatement();
result.qualifier = matcher.group(QUALIFIER_GROUP);
if (result.qualifier.endsWith("z")) {
result.register1 = matcher.group(ZERO_REGISTER_GROUP);
result.label = matcher.group(ZERO_LABEL_GROUP);
} else {
result.register1 = matcher.group(EQUALS_REGISTER1_GROUP);
result.register2 = matcher.group(EQUALS_REGISTER2_GROUP);
result.label = matcher.group(EQUALS_LABEL_GROUP);
}
return result;
}
public String getQualifier() {
return qualifier;
}
public String getRegister1() {
return register1;
}
public String getRegister2() {
return register2;
}
public String getRegister() {
return register1;
}
public String getLabel() {
return label;
}
}
| 2,139
| 30.014493
| 154
|
java
|
heldroid
|
heldroid-master/src/java/it/polimi/elet/necst/heldroid/smali/statements/SmaliLabelDeclaration.java
|
package it.polimi.elet.necst.heldroid.smali.statements;
import it.polimi.elet.necst.heldroid.smali.SmaliSyntaxException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class SmaliLabelDeclaration extends SmaliStatement {
private static final String CALL_PREFIX = ":";
private static final Pattern CALL_PATTERN = Pattern.compile(":[\\w\\_]+");
private String label;
public static boolean isCalledIn(String codeLine) {
return codeLine.trim().startsWith(CALL_PREFIX);
}
public static SmaliLabelDeclaration parse(String codeLine) throws SmaliSyntaxException {
Matcher matcher = CALL_PATTERN.matcher(codeLine);
if (!matcher.find())
throw new SmaliSyntaxException("Cannot parse label statement: " + codeLine);
SmaliLabelDeclaration result = new SmaliLabelDeclaration();
result.label = matcher.group(0);
return result;
}
public String getLabel() {
return label;
}
}
| 998
| 27.542857
| 92
|
java
|
heldroid
|
heldroid-master/src/java/it/polimi/elet/necst/heldroid/smali/statements/SmaliInvocationStatement.java
|
package it.polimi.elet.necst.heldroid.smali.statements;
import it.polimi.elet.necst.heldroid.smali.SmaliHelper;
import it.polimi.elet.necst.heldroid.smali.SmaliSyntaxException;
import it.polimi.elet.necst.heldroid.smali.names.SmaliClassName;
import it.polimi.elet.necst.heldroid.smali.names.SmaliMemberName;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class SmaliInvocationStatement extends SmaliStatement {
private static final String CALL_PREFIX = "invoke";
private static final Pattern CALL_PATTERN = Pattern.compile("invoke([\\/\\-\\w\\d]*)\\s+\\{([pv\\.\\d\\s,]*)\\}\\s*,\\s*([\\w\\d\\/\\$\\[;]+)\\-\\>([\\w\\d\\<\\>\\$]+)\\(([\\s\\w\\d\\$\\/\\[;]*)\\)([\\w\\d\\$\\/\\[;]+)");
private static final Pattern SINGLE_PARAMETER_PATTERN = Pattern.compile("(p|v)(\\d+)");
private static final Pattern RANGE_PARAMETERS_PATTERN = Pattern.compile("(p|v)(\\d+)\\s*\\.\\.\\s*(p|v)(\\d+)");
private String qualifier;
private String returnType;
private List<String> parameters;
private List<String> parameterTypes;
private SmaliMemberName methodName;
private SmaliInvocationStatement() { }
public static boolean isCalledIn(String codeLine) {
return codeLine.trim().startsWith(CALL_PREFIX);
}
public static SmaliInvocationStatement parse(String codeLine) throws SmaliSyntaxException {
Matcher matcher = CALL_PATTERN.matcher(codeLine);
if (!matcher.find())
throw new SmaliSyntaxException("Cannot parse invoke statement: " + codeLine);
SmaliInvocationStatement result = new SmaliInvocationStatement();
result.qualifier = matcher.group(QUALIFIER_GROUP);
result.returnType = matcher.group(RETURN_TYPE_GROUP);
String completeClassName = matcher.group(CLASS_GROUP);
String simpleMethodName = matcher.group(METHOD_GROUP);
result.methodName = new SmaliMemberName(new SmaliClassName(completeClassName), simpleMethodName);
result.parameterTypes = SmaliHelper.parseParameterTypesList(matcher.group(PARAMETER_TYPES_LIST_GROUP));
result.parameters = parseParametersList(matcher.group(PARAMETERS_LIST_GROUP));
return result;
}
private static List<String> parseParametersList(String parametersList) {
String[] chunks = parametersList.split(",");
List<String> result = new ArrayList<String>();
for (String chunk : chunks) {
Matcher rangeMatcher = RANGE_PARAMETERS_PATTERN.matcher(chunk);
if (rangeMatcher.find()) {
String kind = rangeMatcher.group(PARAMETER_KIND_GROUP);
Integer firstRegister = Integer.parseInt(rangeMatcher.group(FIRST_PARAMETER_GROUP));
Integer lastRegister = Integer.parseInt(rangeMatcher.group(LAST_PARAMETER_GROUP));
for (Integer reg = firstRegister; reg <= lastRegister; reg++)
result.add(kind + reg);
} else {
Matcher singleMatcher = SINGLE_PARAMETER_PATTERN.matcher(chunk);
if (singleMatcher.find())
result.add(singleMatcher.group(0)); // all match
}
}
return result;
}
public String getQualifier() {
return qualifier;
}
public SmaliMemberName getMethodName() {
return methodName;
}
public String getReturnType() {
return returnType;
}
public List<String> getParameters() {
return parameters;
}
public List<String> getParameterTypes() {
return parameterTypes;
}
private static final int QUALIFIER_GROUP = 1;
private static final int PARAMETERS_LIST_GROUP = 2;
private static final int CLASS_GROUP = 3;
private static final int METHOD_GROUP = 4;
private static final int PARAMETER_TYPES_LIST_GROUP = 5;
private static final int RETURN_TYPE_GROUP = 6;
private static final int PARAMETER_KIND_GROUP = 1;
private static final int FIRST_PARAMETER_GROUP = 2;
private static final int LAST_PARAMETER_GROUP = 4;
}
| 4,123
| 36.490909
| 225
|
java
|
heldroid
|
heldroid-master/src/java/it/polimi/elet/necst/heldroid/smali/statements/SmaliArrayPutStatement.java
|
package it.polimi.elet.necst.heldroid.smali.statements;
public class SmaliArrayPutStatement extends SmaliArrayAccessStatement {
}
| 131
| 25.4
| 71
|
java
|
heldroid
|
heldroid-master/src/java/it/polimi/elet/necst/heldroid/smali/statements/SmaliAccessStatement.java
|
package it.polimi.elet.necst.heldroid.smali.statements;
import it.polimi.elet.necst.heldroid.smali.SmaliSyntaxException;
import it.polimi.elet.necst.heldroid.smali.names.SmaliClassName;
import it.polimi.elet.necst.heldroid.smali.names.SmaliMemberName;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public abstract class SmaliAccessStatement extends SmaliStatement {
private static final String[] CALL_PREFIXES = {"sget", "iget", "sput", "iput" };
private static final String ACTION_GET = "get";
private static final String ACTION_PUT = "put";
private static final Pattern CALL_PATTERN = Pattern.compile("(s|i)(get|put)([\\/\\-\\w\\d]*)\\s+([pv]\\d+)\\s*,(\\s*[pv]\\d+\\s*,)?\\s*([\\w\\d\\$\\/\\[;_]+)\\-\\>([\\w\\d\\$\\<\\>_]+):([\\w\\d\\$\\/\\[;_]+)");
protected String qualifier;
protected String register;
protected String returnType;
protected SmaliMemberName fieldName;
public static boolean isCalledIn(String codeLine) {
String trimmedLine = codeLine.trim();
for (String prefix : CALL_PREFIXES)
if (trimmedLine.startsWith(prefix))
return true;
return false;
}
public static SmaliAccessStatement parse(String codeLine) throws SmaliSyntaxException {
Matcher matcher = CALL_PATTERN.matcher(codeLine);
if (!matcher.find())
throw new SmaliSyntaxException("Cannot parse get statement: " + codeLine);
String action = matcher.group(ACTION_GROUP);
SmaliAccessStatement result;
if (action.equals(ACTION_GET))
result = new SmaliGetStatement();
else
result = new SmaliPutStatement();
result.qualifier = matcher.group(QUALIFIER_GROUP);
result.register = matcher.group(REGISTER_GROUP);
result.returnType = matcher.group(RETURN_TYPE_GROUP);
String completeClassName = matcher.group(CLASS_GROUP);
String simpleMemberName = matcher.group(FIELD_GROUP);
result.fieldName = new SmaliMemberName(new SmaliClassName(completeClassName), simpleMemberName);
return result;
}
public String getQualifier() {
return qualifier;
}
public String getRegister() {
return register;
}
public SmaliMemberName getFieldName() {
return fieldName;
}
public String getReturnType() {
return returnType;
}
private static final int SCOPE_GROUP = 1;
private static final int ACTION_GROUP = 2;
private static final int QUALIFIER_GROUP = 3;
private static final int REGISTER_GROUP = 4;
private static final int CLASS_GROUP = 6;
private static final int FIELD_GROUP = 7;
private static final int RETURN_TYPE_GROUP = 8;
}
| 2,750
| 32.144578
| 214
|
java
|
heldroid
|
heldroid-master/src/java/it/polimi/elet/necst/heldroid/smali/statements/SmaliStatement.java
|
package it.polimi.elet.necst.heldroid.smali.statements;
import it.polimi.elet.necst.heldroid.smali.SmaliSyntaxException;
public abstract class SmaliStatement {
private String codeLine;
public boolean is(Class type) {
return this.getClass().getName().equals(type.getName());
}
public static SmaliStatement parse(String codeLine) throws SmaliSyntaxException {
SmaliStatement result = null;
if (SmaliConstantStatement.isCalledIn(codeLine))
result = SmaliConstantStatement.parse(codeLine);
else if (SmaliInvocationStatement.isCalledIn(codeLine))
result = SmaliInvocationStatement.parse(codeLine);
else if (SmaliAccessStatement.isCalledIn(codeLine))
result = SmaliAccessStatement.parse(codeLine);
else if (SmaliMoveResultStatement.isCalledIn(codeLine))
result = SmaliMoveResultStatement.parse(codeLine);
else if (SmaliMoveStatement.isCalledIn(codeLine))
result = SmaliMoveStatement.parse(codeLine);
else if (SmaliIfStatement.isCalledIn(codeLine))
result = SmaliIfStatement.parse(codeLine);
else if (SmaliGotoStatement.isCalledIn(codeLine))
result = SmaliGotoStatement.parse(codeLine);
else if (SmaliReturnStatement.isCalledIn(codeLine))
result = SmaliReturnStatement.parse(codeLine);
else if (SmaliLabelDeclaration.isCalledIn(codeLine))
result = SmaliLabelDeclaration.parse(codeLine);
else if (SmaliArrayAccessStatement.isCalledIn(codeLine))
result = SmaliArrayAccessStatement.parse(codeLine);
else if (SmaliNewInstanceStatement.isCalledIn(codeLine))
result = SmaliNewInstanceStatement.parse(codeLine);
if (result != null)
result.codeLine = codeLine;
return result;
}
public String toString() {
return codeLine;
}
}
| 1,929
| 32.275862
| 85
|
java
|
heldroid
|
heldroid-master/src/java/it/polimi/elet/necst/heldroid/smali/statements/SmaliPutStatement.java
|
package it.polimi.elet.necst.heldroid.smali.statements;
public class SmaliPutStatement extends SmaliAccessStatement {
}
| 121
| 23.4
| 61
|
java
|
heldroid
|
heldroid-master/src/java/it/polimi/elet/necst/heldroid/smali/statements/SmaliGotoStatement.java
|
package it.polimi.elet.necst.heldroid.smali.statements;
import it.polimi.elet.necst.heldroid.smali.SmaliSyntaxException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class SmaliGotoStatement extends SmaliStatement {
private static final String CALL_PREFIX = "goto";
private static final Pattern CALL_PATTERN = Pattern.compile("goto(\\/(16|32))?\\s+(:[\\w\\_]+)");
private static final int QUALIFIER_GROUP = 2;
private static final int LABEL_GROUP = 3;
private String qualifier;
private String label;
public static boolean isCalledIn(String codeLine) {
return codeLine.trim().startsWith(CALL_PREFIX);
}
public static SmaliGotoStatement parse(String codeLine) throws SmaliSyntaxException {
Matcher matcher = CALL_PATTERN.matcher(codeLine);
if (!matcher.find())
throw new SmaliSyntaxException("Cannot parse goto statement: " + codeLine);
SmaliGotoStatement result = new SmaliGotoStatement();
result.qualifier = matcher.group(QUALIFIER_GROUP);
result.label = matcher.group(LABEL_GROUP);
return result;
}
public String getQualifier() {
return qualifier;
}
public String getLabel() {
return label;
}
}
| 1,276
| 27.377778
| 101
|
java
|
ethereumj
|
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/TestUtils.java
|
/*
* Copyright (c) [2016] [ <ether.camp> ]
* This file is part of the ethereumJ library.
*
* The ethereumJ library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The ethereumJ library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the ethereumJ library. If not, see <http://www.gnu.org/licenses/>.
*/
package org.ethereum;
import org.ethereum.core.Block;
import org.ethereum.vm.DataWord;
import org.spongycastle.util.BigIntegers;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import static org.ethereum.crypto.HashUtil.EMPTY_TRIE_HASH;
import static org.ethereum.crypto.HashUtil.randomHash;
public final class TestUtils {
private TestUtils() {
}
public static byte[] randomBytes(int length) {
byte[] result = new byte[length];
new Random().nextBytes(result);
return result;
}
public static DataWord randomDataWord() {
return DataWord.of(randomBytes(32));
}
public static byte[] randomAddress() {
return randomBytes(20);
}
public static List<Block> getRandomChain(byte[] startParentHash, long startNumber, long length){
List<Block> result = new ArrayList<>();
byte[] lastHash = startParentHash;
long lastIndex = startNumber;
for (int i = 0; i < length; ++i){
byte[] difficulty = BigIntegers.asUnsignedByteArray(new BigInteger(8, new Random()));
byte[] newHash = randomHash();
Block block = new Block(lastHash, newHash, null, null, difficulty, lastIndex, new byte[] {0}, 0, 0, null, null,
null, null, EMPTY_TRIE_HASH, randomHash(), null, null);
++lastIndex;
lastHash = block.getHash();
result.add(block);
}
return result;
}
// Generates chain with alternative sub-chains, maxHeight blocks on each level
public static List<Block> getRandomAltChain(byte[] startParentHash, long startNumber, long length, int maxHeight){
List<Block> result = new ArrayList<>();
List<byte[]> lastHashes = new ArrayList<>();
lastHashes.add(startParentHash);
long lastIndex = startNumber;
Random rnd = new Random();
for (int i = 0; i < length; ++i){
List<byte[]> currentHashes = new ArrayList<>();
int curMaxHeight = maxHeight;
if (i == 0) curMaxHeight = 1;
for (int j = 0; j < curMaxHeight; ++j){
byte[] parentHash = lastHashes.get(rnd.nextInt(lastHashes.size()));
byte[] difficulty = BigIntegers.asUnsignedByteArray(new BigInteger(8, new Random()));
byte[] newHash = randomHash();
Block block = new Block(parentHash, newHash, null, null, difficulty, lastIndex, new byte[]{0}, 0, 0, null, null,
null, null, EMPTY_TRIE_HASH, randomHash(), null, null);
currentHashes.add(block.getHash());
result.add(block);
}
++lastIndex;
lastHashes.clear();
lastHashes.addAll(currentHashes);
}
return result;
}
}
| 3,658
| 32.568807
| 128
|
java
|
ethereumj
|
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/crypto/ECIESTest.java
|
/*
* Copyright (c) [2016] [ <ether.camp> ]
* This file is part of the ethereumJ library.
*
* The ethereumJ library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The ethereumJ library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the ethereumJ library. If not, see <http://www.gnu.org/licenses/>.
*/
package org.ethereum.crypto;
import org.ethereum.ConcatKDFBytesGenerator;
import org.junit.BeforeClass;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.spongycastle.asn1.sec.SECNamedCurves;
import org.spongycastle.asn1.x9.X9ECParameters;
import org.spongycastle.crypto.*;
import org.spongycastle.crypto.agreement.ECDHBasicAgreement;
import org.spongycastle.crypto.digests.SHA256Digest;
import org.spongycastle.crypto.engines.AESEngine;
import org.spongycastle.crypto.generators.ECKeyPairGenerator;
import org.spongycastle.crypto.macs.HMac;
import org.spongycastle.crypto.modes.SICBlockCipher;
import org.spongycastle.crypto.params.*;
import org.spongycastle.math.ec.ECPoint;
import org.spongycastle.util.encoders.Hex;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.math.BigInteger;
import java.security.SecureRandom;
import java.security.Security;
import static org.junit.Assert.assertArrayEquals;
public class ECIESTest {
public static final int KEY_SIZE = 128;
static Logger log = LoggerFactory.getLogger("test");
private static ECDomainParameters curve;
private static final String CIPHERTEXT1 = "042a851331790adacf6e64fcb19d0872fcdf1285a899a12cdc897da941816b0ea6485402aaf6c2e0a5d98ae3af1b05c68b307d1e0eb7a426a46f1617ba5b94f90b606eee3b5e9d2b527a9ee52cfa377bcd118b9390ed27ffe7d48e8155004375cae209012c3e057bb13a478a64a201d79ad4ae83";
private static final X9ECParameters IES_CURVE_PARAM = SECNamedCurves.getByName("secp256r1");
private static final BigInteger PRIVATE_KEY1 = new BigInteger("51134539186617376248226283012294527978458758538121566045626095875284492680246");
private static ECPoint pub(BigInteger d) {
return curve.getG().multiply(d);
}
@BeforeClass
public static void beforeAll() {
curve = new ECDomainParameters(IES_CURVE_PARAM.getCurve(), IES_CURVE_PARAM.getG(), IES_CURVE_PARAM.getN(), IES_CURVE_PARAM.getH());
}
@Test
public void testKDF() {
ConcatKDFBytesGenerator kdf = new ConcatKDFBytesGenerator(new SHA256Digest());
kdf.init(new KDFParameters("Hello".getBytes(), new byte[0]));
byte[] bytes = new byte[2];
kdf.generateBytes(bytes, 0, bytes.length);
assertArrayEquals(new byte[]{-66, -89}, bytes);
}
@Test
public void testDecryptTestVector() throws IOException, InvalidCipherTextException {
ECPoint pub1 = pub(PRIVATE_KEY1);
byte[] ciphertext = Hex.decode(CIPHERTEXT1);
byte[] plaintext = decrypt(PRIVATE_KEY1, ciphertext);
assertArrayEquals(new byte[]{1,1,1}, plaintext);
}
@Test
public void testRoundTrip() throws InvalidCipherTextException, IOException {
ECPoint pub1 = pub(PRIVATE_KEY1);
byte[] plaintext = "Hello world".getBytes();
byte[] ciphertext = encrypt(pub1, plaintext);
byte[] plaintext1 = decrypt(PRIVATE_KEY1, ciphertext);
assertArrayEquals(plaintext, plaintext1);
}
public static byte[] decrypt(BigInteger prv, byte[] cipher) throws InvalidCipherTextException, IOException {
ByteArrayInputStream is = new ByteArrayInputStream(cipher);
byte[] ephemBytes = new byte[2*((curve.getCurve().getFieldSize()+7)/8) + 1];
is.read(ephemBytes);
ECPoint ephem = curve.getCurve().decodePoint(ephemBytes);
byte[] IV = new byte[KEY_SIZE /8];
is.read(IV);
byte[] cipherBody = new byte[is.available()];
is.read(cipherBody);
EthereumIESEngine iesEngine = makeIESEngine(false, ephem, prv, IV);
byte[] message = iesEngine.processBlock(cipherBody, 0, cipherBody.length);
return message;
}
public static byte[] encrypt(ECPoint toPub, byte[] plaintext) throws InvalidCipherTextException, IOException {
ECKeyPairGenerator eGen = new ECKeyPairGenerator();
SecureRandom random = new SecureRandom();
KeyGenerationParameters gParam = new ECKeyGenerationParameters(curve, random);
eGen.init(gParam);
byte[] IV = new byte[KEY_SIZE/8];
new SecureRandom().nextBytes(IV);
AsymmetricCipherKeyPair ephemPair = eGen.generateKeyPair();
BigInteger prv = ((ECPrivateKeyParameters)ephemPair.getPrivate()).getD();
ECPoint pub = ((ECPublicKeyParameters)ephemPair.getPublic()).getQ();
EthereumIESEngine iesEngine = makeIESEngine(true, toPub, prv, IV);
ECKeyGenerationParameters keygenParams = new ECKeyGenerationParameters(curve, random);
ECKeyPairGenerator generator = new ECKeyPairGenerator();
generator.init(keygenParams);
ECKeyPairGenerator gen = new ECKeyPairGenerator();
gen.init(new ECKeyGenerationParameters(ECKey.CURVE, random));
byte[] cipher = iesEngine.processBlock(plaintext, 0, plaintext.length);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bos.write(pub.getEncoded(false));
bos.write(IV);
bos.write(cipher);
return bos.toByteArray();
}
private static EthereumIESEngine makeIESEngine(boolean isEncrypt, ECPoint pub, BigInteger prv, byte[] IV) {
AESEngine aesFastEngine = new AESEngine();
EthereumIESEngine iesEngine = new EthereumIESEngine(
new ECDHBasicAgreement(),
new ConcatKDFBytesGenerator(new SHA256Digest()),
new HMac(new SHA256Digest()),
new SHA256Digest(),
new BufferedBlockCipher(new SICBlockCipher(aesFastEngine)));
byte[] d = new byte[] {};
byte[] e = new byte[] {};
IESParameters p = new IESWithCipherParameters(d, e, KEY_SIZE, KEY_SIZE);
ParametersWithIV parametersWithIV = new ParametersWithIV(p, IV);
iesEngine.init(isEncrypt, new ECPrivateKeyParameters(prv, curve), new ECPublicKeyParameters(pub, curve), parametersWithIV);
return iesEngine;
}
}
| 6,761
| 41.2625
| 281
|
java
|
ethereumj
|
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/crypto/CryptoTest.java
|
/*
* Copyright (c) [2016] [ <ether.camp> ]
* This file is part of the ethereumJ library.
*
* The ethereumJ library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The ethereumJ library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the ethereumJ library. If not, see <http://www.gnu.org/licenses/>.
*/
package org.ethereum.crypto;
import org.ethereum.util.Utils;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.spongycastle.crypto.AsymmetricCipherKeyPair;
import org.spongycastle.crypto.BufferedBlockCipher;
import org.spongycastle.crypto.KeyEncoder;
import org.spongycastle.crypto.KeyGenerationParameters;
import org.spongycastle.crypto.agreement.ECDHBasicAgreement;
import org.spongycastle.crypto.digests.SHA256Digest;
import org.spongycastle.crypto.engines.AESEngine;
import org.spongycastle.crypto.engines.IESEngine;
import org.spongycastle.crypto.generators.ECKeyPairGenerator;
import org.spongycastle.crypto.generators.EphemeralKeyPairGenerator;
import org.spongycastle.crypto.generators.KDF2BytesGenerator;
import org.spongycastle.crypto.macs.HMac;
import org.spongycastle.crypto.modes.SICBlockCipher;
import org.spongycastle.crypto.params.*;
import org.spongycastle.crypto.parsers.ECIESPublicKeyParser;
import org.spongycastle.math.ec.ECPoint;
import org.spongycastle.util.encoders.Hex;
import java.math.BigInteger;
import java.security.SecureRandom;
import static org.ethereum.crypto.HashUtil.sha3;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
public class CryptoTest {
private static final Logger log = LoggerFactory.getLogger("test");
@Test
public void test1() {
byte[] result = HashUtil.sha3("horse".getBytes());
assertEquals("c87f65ff3f271bf5dc8643484f66b200109caffe4bf98c4cb393dc35740b28c0",
Hex.toHexString(result));
result = HashUtil.sha3("cow".getBytes());
assertEquals("c85ef7d79691fe79573b1a7064c19c1a9819ebdbd1faaab1a8ec92344438aaf4",
Hex.toHexString(result));
}
@Test
public void test3() {
BigInteger privKey = new BigInteger("cd244b3015703ddf545595da06ada5516628c5feadbf49dc66049c4b370cc5d8", 16);
byte[] addr = ECKey.fromPrivate(privKey).getAddress();
assertEquals("89b44e4d3c81ede05d0f5de8d1a68f754d73d997", Hex.toHexString(addr));
}
@Test
public void test4() {
byte[] cowBytes = HashUtil.sha3("cow".getBytes());
byte[] addr = ECKey.fromPrivate(cowBytes).getAddress();
assertEquals("CD2A3D9F938E13CD947EC05ABC7FE734DF8DD826", Hex.toHexString(addr).toUpperCase());
}
@Test
public void test5() {
byte[] horseBytes = HashUtil.sha3("horse".getBytes());
byte[] addr = ECKey.fromPrivate(horseBytes).getAddress();
assertEquals("13978AEE95F38490E9769C39B2773ED763D9CD5F", Hex.toHexString(addr).toUpperCase());
}
@Test /* performance test */
public void test6() {
long firstTime = System.currentTimeMillis();
System.out.println(firstTime);
for (int i = 0; i < 1000; ++i) {
byte[] horseBytes = HashUtil.sha3("horse".getBytes());
byte[] addr = ECKey.fromPrivate(horseBytes).getAddress();
assertEquals("13978AEE95F38490E9769C39B2773ED763D9CD5F", Hex.toHexString(addr).toUpperCase());
}
long secondTime = System.currentTimeMillis();
System.out.println(secondTime);
System.out.println(secondTime - firstTime + " millisec");
// 1) result: ~52 address calculation every second
}
@Test /* real tx hash calc */
public void test7() {
String txRaw = "F89D80809400000000000000000000000000000000000000008609184E72A000822710B3606956330C0D630000003359366000530A0D630000003359602060005301356000533557604060005301600054630000000C5884336069571CA07F6EB94576346488C6253197BDE6A7E59DDC36F2773672C849402AA9C402C3C4A06D254E662BF7450DD8D835160CBB053463FED0B53F2CDD7F3EA8731919C8E8CC";
byte[] txHashB = HashUtil.sha3(Hex.decode(txRaw));
String txHash = Hex.toHexString(txHashB);
assertEquals("4b7d9670a92bf120d5b43400543b69304a14d767cf836a7f6abff4edde092895", txHash);
}
@Test /* real block hash calc */
public void test8() {
String blockRaw = "F885F8818080A01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D49347940000000000000000000000000000000000000000A0BCDDD284BF396739C224DBA0411566C891C32115FEB998A3E2B4E61F3F35582AA01DCC4DE8DEC75D7AAB85B567B6CCD41AD312451B948A7413F0A142FD40D4934783800000808080C0C0";
byte[] blockHashB = HashUtil.sha3(Hex.decode(blockRaw));
String blockHash = Hex.toHexString(blockHashB);
System.out.println(blockHash);
}
@Test
public void test9() {
// TODO: https://tools.ietf.org/html/rfc6979#section-2.2
// TODO: https://github.com/bcgit/bc-java/blob/master/core/src/main/java/org/bouncycastle/crypto/signers/ECDSASigner.java
System.out.println(new BigInteger(Hex.decode("3913517ebd3c0c65000000")));
System.out.println(Utils.getValueShortString(new BigInteger("69000000000000000000000000")));
}
@Test
public void test10() {
BigInteger privKey = new BigInteger("74ef8a796480dda87b4bc550b94c408ad386af0f65926a392136286784d63858", 16);
byte[] addr = ECKey.fromPrivate(privKey).getAddress();
assertEquals("ba73facb4f8291f09f27f90fe1213537b910065e", Hex.toHexString(addr));
}
@Test // basic encryption/decryption
public void test11() throws Throwable {
byte[] keyBytes = sha3("...".getBytes());
log.info("key: {}", Hex.toHexString(keyBytes));
byte[] ivBytes = new byte[16];
byte[] payload = Hex.decode("22400891000000000000000000000000");
KeyParameter key = new KeyParameter(keyBytes);
ParametersWithIV params = new ParametersWithIV(key, new byte[16]);
AESEngine engine = new AESEngine();
SICBlockCipher ctrEngine = new SICBlockCipher(engine);
ctrEngine.init(true, params);
byte[] cipher = new byte[16];
ctrEngine.processBlock(payload, 0, cipher, 0);
log.info("cipher: {}", Hex.toHexString(cipher));
byte[] output = new byte[cipher.length];
ctrEngine.init(false, params);
ctrEngine.processBlock(cipher, 0, output, 0);
assertEquals(Hex.toHexString(output), Hex.toHexString(payload));
log.info("original: {}", Hex.toHexString(payload));
}
@Test // big packet encryption
public void test12() throws Throwable {
AESEngine engine = new AESEngine();
SICBlockCipher ctrEngine = new SICBlockCipher(engine);
byte[] keyBytes = Hex.decode("a4627abc2a3c25315bff732cb22bc128f203912dd2a840f31e66efb27a47d2b1");
byte[] ivBytes = new byte[16];
byte[] payload = Hex.decode("0109efc76519b683d543db9d0991bcde99cc9a3d14b1d0ecb8e9f1f66f31558593d746eaa112891b04ef7126e1dce17c9ac92ebf39e010f0028b8ec699f56f5d0c0d00");
byte[] cipherText = Hex.decode("f9fab4e9dd9fc3e5d0d0d16da254a2ac24df81c076e3214e2c57da80a46e6ae4752f4b547889fa692b0997d74f36bb7c047100ba71045cb72cfafcc7f9a251762cdf8f");
KeyParameter key = new KeyParameter(keyBytes);
ParametersWithIV params = new ParametersWithIV(key, ivBytes);
ctrEngine.init(true, params);
byte[] in = payload;
byte[] out = new byte[in.length];
int i = 0;
while(i < in.length){
ctrEngine.processBlock(in, i, out, i);
i += engine.getBlockSize();
if (in.length - i < engine.getBlockSize())
break;
}
// process left bytes
if (in.length - i > 0){
byte[] tmpBlock = new byte[16];
System.arraycopy(in, i, tmpBlock, 0, in.length - i);
ctrEngine.processBlock(tmpBlock, 0, tmpBlock, 0);
System.arraycopy(tmpBlock, 0, out, i, in.length - i);
}
log.info("cipher: {}", Hex.toHexString(out));
assertEquals(Hex.toHexString(cipherText), Hex.toHexString(out));
}
@Test // cpp keys demystified
public void test13() throws Throwable {
// us.secret() a4627abc2a3c25315bff732cb22bc128f203912dd2a840f31e66efb27a47d2b1
// us.public() caa3d5086b31529bb00207eabf244a0a6c54d807d2ac0ec1f3b1bdde0dbf8130c115b1eaf62ce0f8062bcf70c0fefbc97cec79e7faffcc844a149a17fcd7bada
// us.address() 47d8cb63a7965d98b547b9f0333a654b60ffa190
ECKey key = ECKey.fromPrivate(Hex.decode("a4627abc2a3c25315bff732cb22bc128f203912dd2a840f31e66efb27a47d2b1"));
String address = Hex.toHexString(key.getAddress());
String pubkey = Hex.toHexString(key.getPubKeyPoint().getEncoded(/* uncompressed form */ false));
log.info("address: " + address);
log.info("pubkey: " + pubkey);
assertEquals("47d8cb63a7965d98b547b9f0333a654b60ffa190", address);
assertEquals("04caa3d5086b31529bb00207eabf244a0a6c54d807d2ac0ec1f3b1bdde0dbf8130c115b1eaf62ce0f8062bcf70c0fefbc97cec79e7faffcc844a149a17fcd7bada", pubkey);
}
@Test // ECIES_AES128_SHA256 + No Ephemeral Key + IV(all zeroes)
public void test14() throws Throwable{
AESEngine aesFastEngine = new AESEngine();
IESEngine iesEngine = new IESEngine(
new ECDHBasicAgreement(),
new KDF2BytesGenerator(new SHA256Digest()),
new HMac(new SHA256Digest()),
new BufferedBlockCipher(new SICBlockCipher(aesFastEngine)));
byte[] d = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 };
byte[] e = new byte[] { 8, 7, 6, 5, 4, 3, 2, 1 };
IESParameters p = new IESWithCipherParameters(d, e, 64, 128);
ParametersWithIV parametersWithIV = new ParametersWithIV(p, new byte[16]);
ECKeyPairGenerator eGen = new ECKeyPairGenerator();
KeyGenerationParameters gParam = new ECKeyGenerationParameters(ECKey.CURVE, new SecureRandom());
eGen.init(gParam);
AsymmetricCipherKeyPair p1 = eGen.generateKeyPair();
AsymmetricCipherKeyPair p2 = eGen.generateKeyPair();
ECKeyGenerationParameters keygenParams = new ECKeyGenerationParameters(ECKey.CURVE, new SecureRandom());
ECKeyPairGenerator generator = new ECKeyPairGenerator();
generator.init(keygenParams);
ECKeyPairGenerator gen = new ECKeyPairGenerator();
gen.init(new ECKeyGenerationParameters(ECKey.CURVE, new SecureRandom()));
iesEngine.init(true, p1.getPrivate(), p2.getPublic(), parametersWithIV);
byte[] message = Hex.decode("010101");
log.info("payload: {}", Hex.toHexString(message));
byte[] cipher = iesEngine.processBlock(message, 0, message.length);
log.info("cipher: {}", Hex.toHexString(cipher));
IESEngine decryptorIES_Engine = new IESEngine(
new ECDHBasicAgreement(),
new KDF2BytesGenerator (new SHA256Digest()),
new HMac(new SHA256Digest()),
new BufferedBlockCipher(new SICBlockCipher(aesFastEngine)));
decryptorIES_Engine.init(false, p2.getPrivate(), p1.getPublic(), parametersWithIV);
byte[] orig = decryptorIES_Engine.processBlock(cipher, 0, cipher.length);
log.info("orig: " + Hex.toHexString(orig));
}
@Test // ECIES_AES128_SHA256 + Ephemeral Key + IV(all zeroes)
public void test15() throws Throwable{
byte[] privKey = Hex.decode("a4627abc2a3c25315bff732cb22bc128f203912dd2a840f31e66efb27a47d2b1");
ECKey ecKey = ECKey.fromPrivate(privKey);
ECPrivateKeyParameters ecPrivKey = new ECPrivateKeyParameters(ecKey.getPrivKey(), ECKey.CURVE);
ECPublicKeyParameters ecPubKey = new ECPublicKeyParameters(ecKey.getPubKeyPoint(), ECKey.CURVE);
AsymmetricCipherKeyPair myKey = new AsymmetricCipherKeyPair(ecPubKey, ecPrivKey);
AESEngine aesFastEngine = new AESEngine();
IESEngine iesEngine = new IESEngine(
new ECDHBasicAgreement(),
new KDF2BytesGenerator(new SHA256Digest()),
new HMac(new SHA256Digest()),
new BufferedBlockCipher(new SICBlockCipher(aesFastEngine)));
byte[] d = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 };
byte[] e = new byte[] { 8, 7, 6, 5, 4, 3, 2, 1 };
IESParameters p = new IESWithCipherParameters(d, e, 64, 128);
ParametersWithIV parametersWithIV = new ParametersWithIV(p, new byte[16]);
ECKeyPairGenerator eGen = new ECKeyPairGenerator();
KeyGenerationParameters gParam = new ECKeyGenerationParameters(ECKey.CURVE, new SecureRandom());
eGen.init(gParam);
ECKeyGenerationParameters keygenParams = new ECKeyGenerationParameters(ECKey.CURVE, new SecureRandom());
ECKeyPairGenerator generator = new ECKeyPairGenerator();
generator.init(keygenParams);
EphemeralKeyPairGenerator kGen = new EphemeralKeyPairGenerator(generator, new KeyEncoder()
{
public byte[] getEncoded(AsymmetricKeyParameter keyParameter)
{
return ((ECPublicKeyParameters)keyParameter).getQ().getEncoded();
}
});
ECKeyPairGenerator gen = new ECKeyPairGenerator();
gen.init(new ECKeyGenerationParameters(ECKey.CURVE, new SecureRandom()));
iesEngine.init(myKey.getPublic(), parametersWithIV, kGen);
byte[] message = Hex.decode("010101");
log.info("payload: {}", Hex.toHexString(message));
byte[] cipher = iesEngine.processBlock(message, 0, message.length);
log.info("cipher: {}", Hex.toHexString(cipher));
IESEngine decryptorIES_Engine = new IESEngine(
new ECDHBasicAgreement(),
new KDF2BytesGenerator (new SHA256Digest()),
new HMac(new SHA256Digest()),
new BufferedBlockCipher(new SICBlockCipher(aesFastEngine)));
decryptorIES_Engine.init(myKey.getPrivate(), parametersWithIV, new ECIESPublicKeyParser(ECKey.CURVE));
byte[] orig = decryptorIES_Engine.processBlock(cipher, 0, cipher.length);
log.info("orig: " + Hex.toHexString(orig));
}
@Test
public void calcSaltAddrTest() {
byte[] from = Hex.decode("0123456789012345678901234567890123456789");
byte[] salt = Hex.decode("0000000000000000000000000000000000000000000000000000000000000314");
// contract Demo{}
byte[] code = Hex.decode("6080604052348015600f57600080fd5b50603580601d6000396000f3006080604052600080fd00a165627a7a72305820a63607f79a5e21cdaf424583b9686f2aa44059d70183eb9846ccfa086405716e0029");
assertArrayEquals(Hex.decode("d26e42c8a0511c19757f783402231cf82b2bdf59"), HashUtil.calcSaltAddr(from, code, salt));
}
}
| 15,330
| 39.238845
| 344
|
java
|
ethereumj
|
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/crypto/ECIESCoderTest.java
|
/*
* Copyright (c) [2016] [ <ether.camp> ]
* This file is part of the ethereumJ library.
*
* The ethereumJ library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The ethereumJ library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the ethereumJ library. If not, see <http://www.gnu.org/licenses/>.
*/
package org.ethereum.crypto;
import org.junit.Assert;
import org.junit.Test;
import org.spongycastle.math.ec.ECPoint;
import org.spongycastle.util.encoders.Hex;
import java.math.BigInteger;
public class ECIESCoderTest {
@Test // decrypt cpp data
public void test1(){
BigInteger privKey = new BigInteger("5e173f6ac3c669587538e7727cf19b782a4f2fda07c1eaa662c593e5e85e3051", 16);
byte[] cipher = Hex.decode("049934a7b2d7f9af8fd9db941d9da281ac9381b5740e1f64f7092f3588d4f87f5ce55191a6653e5e80c1c5dd538169aa123e70dc6ffc5af1827e546c0e958e42dad355bcc1fcb9cdf2cf47ff524d2ad98cbf275e661bf4cf00960e74b5956b799771334f426df007350b46049adb21a6e78ab1408d5e6ccde6fb5e69f0f4c92bb9c725c02f99fa72b9cdc8dd53cff089e0e73317f61cc5abf6152513cb7d833f09d2851603919bf0fbe44d79a09245c6e8338eb502083dc84b846f2fee1cc310d2cc8b1b9334728f97220bb799376233e113");
byte[] payload = new byte[0];
try {
payload = ECIESCoder.decrypt(privKey, cipher);
} catch (Throwable e) {e.printStackTrace();}
Assert.assertEquals("802b052f8b066640bba94a4fc39d63815c377fced6fcb84d27f791c9921ddf3e9bf0108e298f490812847109cbd778fae393e80323fd643209841a3b7f110397f37ec61d84cea03dcc5e8385db93248584e8af4b4d1c832d8c7453c0089687a700",
Hex.toHexString(payload));
}
@Test // encrypt decrypt round trip
public void test2(){
BigInteger privKey = new BigInteger("5e173f6ac3c669587538e7727cf19b782a4f2fda07c1eaa662c593e5e85e3051", 16);
byte[] payload = Hex.decode("1122334455");
ECKey ecKey = ECKey.fromPrivate(privKey);
ECPoint pubKeyPoint = ecKey.getPubKeyPoint();
byte[] cipher = new byte[0];
try {
cipher = ECIESCoder.encrypt(pubKeyPoint, payload);
} catch (Throwable e) {e.printStackTrace();}
System.out.println(Hex.toHexString(cipher));
byte[] decrypted_payload = new byte[0];
try {
decrypted_payload = ECIESCoder.decrypt(privKey, cipher);
} catch (Throwable e) {e.printStackTrace();}
System.out.println(Hex.toHexString(decrypted_payload));
}
}
| 2,913
| 40.042254
| 459
|
java
|
ethereumj
|
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/crypto/ECKeyTest.java
|
/*
* Copyright (c) [2016] [ <ether.camp> ]
* This file is part of the ethereumJ library.
*
* The ethereumJ library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The ethereumJ library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the ethereumJ library. If not, see <http://www.gnu.org/licenses/>.
*/
package org.ethereum.crypto;
import com.google.common.collect.Lists;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.common.util.concurrent.MoreExecutors;
import org.ethereum.core.Transaction;
import org.ethereum.crypto.ECKey.ECDSASignature;
import org.ethereum.crypto.jce.SpongyCastleProvider;
import org.junit.Assert;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.spongycastle.util.encoders.Hex;
import java.io.IOException;
import java.math.BigInteger;
import java.security.KeyPairGenerator;
import java.security.Provider;
import java.security.SecureRandom;
import java.security.Security;
import java.security.SignatureException;
import java.util.List;
import java.util.concurrent.Executors;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
public class ECKeyTest {
private static final Logger log = LoggerFactory.getLogger(ECKeyTest.class);
private static final SecureRandom secureRandom = new SecureRandom();
private String privString = "c85ef7d79691fe79573b1a7064c19c1a9819ebdbd1faaab1a8ec92344438aaf4";
private BigInteger privateKey = new BigInteger(privString, 16);
private String pubString = "040947751e3022ecf3016be03ec77ab0ce3c2662b4843898cb068d74f698ccc8ad75aa17564ae80a20bb044ee7a6d903e8e8df624b089c95d66a0570f051e5a05b";
private String compressedPubString = "030947751e3022ecf3016be03ec77ab0ce3c2662b4843898cb068d74f698ccc8ad";
private byte[] pubKey = Hex.decode(pubString);
private byte[] compressedPubKey = Hex.decode(compressedPubString);
private String address = "cd2a3d9f938e13cd947ec05abc7fe734df8dd826";
private String exampleMessage = "This is an example of a signed message.";
private String sigBase64 = "HNLOSI9Nop5o8iywXKwbGbdd8XChK0rRvdRTG46RFcb7dcH+UKlejM/8u1SCoeQvu91jJBMd/nXDs7f5p8ch7Ms=";
private String signatureHex = "d2ce488f4da29e68f22cb05cac1b19b75df170a12b4ad1bdd4531b8e9115c6fb75c1fe50a95e8ccffcbb5482a1e42fbbdd6324131dfe75c3b3b7f9a7c721eccb01";
@Test
public void testHashCode() {
Assert.assertEquals(-351262686, ECKey.fromPrivate(privateKey).hashCode());
}
@Test
public void testECKey() {
ECKey key = new ECKey();
assertTrue(key.isPubKeyCanonical());
assertNotNull(key.getPubKey());
assertNotNull(key.getPrivKeyBytes());
log.debug(Hex.toHexString(key.getPrivKeyBytes()) + " :Generated privkey");
log.debug(Hex.toHexString(key.getPubKey()) + " :Generated pubkey");
}
@Test
public void testFromPrivateKey() {
ECKey key = ECKey.fromPrivate(privateKey);
assertTrue(key.isPubKeyCanonical());
assertTrue(key.hasPrivKey());
assertArrayEquals(pubKey, key.getPubKey());
}
@Test(expected = IllegalArgumentException.class)
public void testPrivatePublicKeyBytesNoArg() {
new ECKey((BigInteger) null, null);
fail("Expecting an IllegalArgumentException for using only null-parameters");
}
@Test(expected = IllegalArgumentException.class)
public void testInvalidPrivateKey() throws Exception {
new ECKey(
Security.getProvider("SunEC"),
KeyPairGenerator.getInstance("RSA").generateKeyPair().getPrivate(),
ECKey.fromPublicOnly(pubKey).getPubKeyPoint());
fail("Expecting an IllegalArgumentException for using an non EC private key");
}
@Test(expected = IllegalArgumentException.class)
public void testInvalidPrivateKey2() throws Exception {
ECKey.fromPrivate(new byte[32]);
fail("Expecting an IllegalArgumentException for using an non EC private key");
}
@Test
public void testIsPubKeyOnly() {
ECKey key = ECKey.fromPublicOnly(pubKey);
assertTrue(key.isPubKeyCanonical());
assertTrue(key.isPubKeyOnly());
assertArrayEquals(key.getPubKey(), pubKey);
}
@Test(expected = IllegalArgumentException.class)
public void testSignIncorrectInputSize() {
ECKey key = new ECKey();
String message = "The quick brown fox jumps over the lazy dog.";
ECDSASignature sig = key.doSign(message.getBytes());
fail("Expecting an IllegalArgumentException for a non 32-byte input");
}
@Test(expected = ECKey.MissingPrivateKeyException.class)
public void testSignWithPubKeyOnly() {
ECKey key = ECKey.fromPublicOnly(pubKey);
String message = "The quick brown fox jumps over the lazy dog.";
byte[] input = HashUtil.sha3(message.getBytes());
ECDSASignature sig = key.doSign(input);
fail("Expecting an MissingPrivateKeyException for a public only ECKey");
}
@Test(expected = SignatureException.class)
public void testBadBase64Sig() throws SignatureException {
byte[] messageHash = new byte[32];
ECKey.signatureToKey(messageHash, "This is not valid Base64!");
fail("Expecting a SignatureException for invalid Base64");
}
@Test(expected = SignatureException.class)
public void testInvalidSignatureLength() throws SignatureException {
byte[] messageHash = new byte[32];
ECKey.signatureToKey(messageHash, "abcdefg");
fail("Expecting a SignatureException for invalid signature length");
}
@Test
public void testPublicKeyFromPrivate() {
byte[] pubFromPriv = ECKey.publicKeyFromPrivate(privateKey, false);
assertArrayEquals(pubKey, pubFromPriv);
}
@Test
public void testPublicKeyFromPrivateCompressed() {
byte[] pubFromPriv = ECKey.publicKeyFromPrivate(privateKey, true);
assertArrayEquals(compressedPubKey, pubFromPriv);
}
@Test
public void testGetAddress() {
ECKey key = ECKey.fromPublicOnly(pubKey);
assertArrayEquals(Hex.decode(address), key.getAddress());
}
@Test
public void testToString() {
ECKey key = ECKey.fromPrivate(BigInteger.TEN); // An example private key.
assertEquals("pub:04a0434d9e47f3c86235477c7b1ae6ae5d3442d49b1943c2b752a68e2a47e247c7893aba425419bc27a3b6c7e693a24c696f794c2ed877a1593cbee53b037368d7", key.toString());
}
@Test
public void testEthereumSign() throws IOException {
ECKey key = ECKey.fromPrivate(privateKey);
System.out.println("Secret\t: " + Hex.toHexString(key.getPrivKeyBytes()));
System.out.println("Pubkey\t: " + Hex.toHexString(key.getPubKey()));
System.out.println("Data\t: " + exampleMessage);
byte[] messageHash = HashUtil.sha3(exampleMessage.getBytes());
ECDSASignature signature = key.sign(messageHash);
String output = signature.toBase64();
System.out.println("Signtr\t: " + output + " (Base64, length: " + output.length() + ")");
assertEquals(sigBase64, output);
}
/**
* Verified via https://etherchain.org/verify/signature
*/
@Test
public void testEthereumSignToHex() {
ECKey key = ECKey.fromPrivate(privateKey);
byte[] messageHash = HashUtil.sha3(exampleMessage.getBytes());
ECDSASignature signature = key.sign(messageHash);
String output = signature.toHex();
System.out.println("Signature\t: " + output + " (Hex, length: " + output.length() + ")");
assertEquals(signatureHex, output);
}
@Test
public void testVerifySignature1() {
ECKey key = ECKey.fromPublicOnly(pubKey);
BigInteger r = new BigInteger("28157690258821599598544026901946453245423343069728565040002908283498585537001");
BigInteger s = new BigInteger("30212485197630673222315826773656074299979444367665131281281249560925428307087");
ECDSASignature sig = ECDSASignature.fromComponents(r.toByteArray(), s.toByteArray(), (byte) 28);
assertFalse(key.verify(HashUtil.sha3(exampleMessage.getBytes()), sig));
}
@Test
public void testVerifySignature2() {
BigInteger r = new BigInteger("c52c114d4f5a3ba904a9b3036e5e118fe0dbb987fe3955da20f2cd8f6c21ab9c", 16);
BigInteger s = new BigInteger("6ba4c2874299a55ad947dbc98a25ee895aabf6b625c26c435e84bfd70edf2f69", 16);
ECDSASignature sig = ECDSASignature.fromComponents(r.toByteArray(), s.toByteArray(), (byte) 0x1b);
byte[] rawtx = Hex.decode("f82804881bc16d674ec8000094cd2a3d9f938e13cd947ec05abc7fe734df8dd8268609184e72a0006480");
byte[] rawHash = HashUtil.sha3(rawtx);
byte[] address = Hex.decode("cd2a3d9f938e13cd947ec05abc7fe734df8dd826");
try {
ECKey key = ECKey.signatureToKey(rawHash, sig);
System.out.println("Signature public key\t: " + Hex.toHexString(key.getPubKey()));
System.out.println("Sender is\t\t: " + Hex.toHexString(key.getAddress()));
assertEquals(key, ECKey.signatureToKey(rawHash, sig.toBase64()));
assertEquals(key, ECKey.recoverFromSignature(0, sig, rawHash));
assertArrayEquals(key.getPubKey(), ECKey.recoverPubBytesFromSignature(0, sig, rawHash));
assertArrayEquals(address, key.getAddress());
assertArrayEquals(address, ECKey.signatureToAddress(rawHash, sig));
assertArrayEquals(address, ECKey.signatureToAddress(rawHash, sig.toBase64()));
assertArrayEquals(address, ECKey.recoverAddressFromSignature(0, sig, rawHash));
assertTrue(key.verify(rawHash, sig));
} catch (SignatureException e) {
fail();
}
}
@Test
public void testVerifySignature3() throws SignatureException {
byte[] rawtx = Hex.decode("f88080893635c9adc5dea000008609184e72a00094109f3535353535353535353535353535353535359479b08ad8787060333663d19704909ee7b1903e58801ba0899b92d0c76cbf18df24394996beef19c050baa9823b4a9828cd9b260c97112ea0c9e62eb4cf0a9d95ca35c8830afac567619d6b3ebee841a3c8be61d35acd8049");
Transaction tx = new Transaction(rawtx);
ECKey key = ECKey.signatureToKey(HashUtil.sha3(rawtx), tx.getSignature());
System.out.println("Signature public key\t: " + Hex.toHexString(key.getPubKey()));
System.out.println("Sender is\t\t: " + Hex.toHexString(key.getAddress()));
// sender: CD2A3D9F938E13CD947EC05ABC7FE734DF8DD826
// todo: add test assertion when the sign/verify part actually works.
}
@Test // result is a point at infinity
public void testVerifySignature4() {
byte[] hash = Hex.decode("acb1c19ac0832320815b5e886c6b73ad7d6177853d44b026f2a7a9e11bb899fc");
byte[] r = Hex.decode("89ea49159b334f9aebbf54481b69d000d285baa341899db355a4030f6838394e");
byte[] s = Hex.decode("540e9f9fa17bef441e32d98d5f4554cfefdc6a56101352e4b92efafd0d9646e8");
byte v = (byte) 28;
ECDSASignature sig = ECKey.ECDSASignature.fromComponents(r, s, v);
try {
ECKey.signatureToKey(hash, sig);
fail("Result is a point at infinity, recovery must fail");
} catch (SignatureException e) {
}
}
@Test
public void testSValue() throws Exception {
// Check that we never generate an S value that is larger than half the curve order. This avoids a malleability
// issue that can allow someone to change a transaction [hash] without invalidating the signature.
final int ITERATIONS = 10;
ListeningExecutorService executor = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(ITERATIONS));
List<ListenableFuture<ECKey.ECDSASignature>> sigFutures = Lists.newArrayList();
final ECKey key = new ECKey();
for (byte i = 0; i < ITERATIONS; i++) {
final byte[] hash = HashUtil.sha3(new byte[]{i});
sigFutures.add(executor.submit(() -> key.doSign(hash)));
}
List<ECKey.ECDSASignature> sigs = Futures.allAsList(sigFutures).get();
for (ECKey.ECDSASignature signature : sigs) {
assertTrue(signature.s.compareTo(ECKey.HALF_CURVE_ORDER) <= 0);
}
final ECKey.ECDSASignature duplicate = new ECKey.ECDSASignature(sigs.get(0).r, sigs.get(0).s);
assertEquals(sigs.get(0), duplicate);
assertEquals(sigs.get(0).hashCode(), duplicate.hashCode());
}
@Test
public void testSignVerify() {
ECKey key = ECKey.fromPrivate(privateKey);
String message = "This is an example of a signed message.";
byte[] input = HashUtil.sha3(message.getBytes());
ECDSASignature sig = key.sign(input);
assertTrue(sig.validateComponents());
assertTrue(key.verify(input, sig));
}
private void testProviderRoundTrip(Provider provider) throws Exception {
ECKey key = new ECKey(provider, secureRandom);
String message = "The quick brown fox jumps over the lazy dog.";
byte[] input = HashUtil.sha3(message.getBytes());
ECDSASignature sig = key.sign(input);
assertTrue(sig.validateComponents());
assertTrue(key.verify(input, sig));
}
@Test
public void testSunECRoundTrip() throws Exception {
Provider provider = Security.getProvider("SunEC");
if (provider != null) {
testProviderRoundTrip(provider);
} else {
System.out.println("Skip test as provider doesn't exist. " +
"Must be OpenJDK which could be shipped without 'SunEC'");
}
}
@Test
public void testSpongyCastleRoundTrip() throws Exception {
testProviderRoundTrip(SpongyCastleProvider.getInstance());
}
@Test
public void testIsPubKeyCanonicalCorect() {
// Test correct prefix 4, right length 65
byte[] canonicalPubkey1 = new byte[65];
canonicalPubkey1[0] = 0x04;
assertTrue(ECKey.isPubKeyCanonical(canonicalPubkey1));
// Test correct prefix 2, right length 33
byte[] canonicalPubkey2 = new byte[33];
canonicalPubkey2[0] = 0x02;
assertTrue(ECKey.isPubKeyCanonical(canonicalPubkey2));
// Test correct prefix 3, right length 33
byte[] canonicalPubkey3 = new byte[33];
canonicalPubkey3[0] = 0x03;
assertTrue(ECKey.isPubKeyCanonical(canonicalPubkey3));
}
@Test
public void testIsPubKeyCanonicalWrongLength() {
// Test correct prefix 4, but wrong length !65
byte[] nonCanonicalPubkey1 = new byte[64];
nonCanonicalPubkey1[0] = 0x04;
assertFalse(ECKey.isPubKeyCanonical(nonCanonicalPubkey1));
// Test correct prefix 2, but wrong length !33
byte[] nonCanonicalPubkey2 = new byte[32];
nonCanonicalPubkey2[0] = 0x02;
assertFalse(ECKey.isPubKeyCanonical(nonCanonicalPubkey2));
// Test correct prefix 3, but wrong length !33
byte[] nonCanonicalPubkey3 = new byte[32];
nonCanonicalPubkey3[0] = 0x03;
assertFalse(ECKey.isPubKeyCanonical(nonCanonicalPubkey3));
}
@Test
public void testIsPubKeyCanonicalWrongPrefix() {
// Test wrong prefix 4, right length 65
byte[] nonCanonicalPubkey4 = new byte[65];
assertFalse(ECKey.isPubKeyCanonical(nonCanonicalPubkey4));
// Test wrong prefix 2, right length 33
byte[] nonCanonicalPubkey5 = new byte[33];
assertFalse(ECKey.isPubKeyCanonical(nonCanonicalPubkey5));
// Test wrong prefix 3, right length 33
byte[] nonCanonicalPubkey6 = new byte[33];
assertFalse(ECKey.isPubKeyCanonical(nonCanonicalPubkey6));
}
@Test
public void keyRecovery() throws Exception {
ECKey key = new ECKey();
String message = "Hello World!";
byte[] hash = HashUtil.sha256(message.getBytes());
ECKey.ECDSASignature sig = key.doSign(hash);
key = ECKey.fromPublicOnly(key.getPubKeyPoint());
boolean found = false;
for (int i = 0; i < 4; i++) {
ECKey key2 = ECKey.recoverFromSignature(i, sig, hash);
checkNotNull(key2);
if (key.equals(key2)) {
found = true;
break;
}
}
assertTrue(found);
}
@Test
public void testSignedMessageToKey() throws SignatureException {
byte[] messageHash = HashUtil.sha3(exampleMessage.getBytes());
ECKey key = ECKey.signatureToKey(messageHash, sigBase64);
assertNotNull(key);
assertArrayEquals(pubKey, key.getPubKey());
}
@Test
public void testGetPrivKeyBytes() {
ECKey key = new ECKey();
assertNotNull(key.getPrivKeyBytes());
assertEquals(32, key.getPrivKeyBytes().length);
}
@Test
public void testEqualsObject() {
ECKey key0 = new ECKey();
ECKey key1 = ECKey.fromPrivate(privateKey);
ECKey key2 = ECKey.fromPrivate(privateKey);
assertFalse(key0.equals(key1));
assertTrue(key1.equals(key1));
assertTrue(key1.equals(key2));
}
@Test
public void decryptAECSIC(){
ECKey key = ECKey.fromPrivate(Hex.decode("abb51256c1324a1350598653f46aa3ad693ac3cf5d05f36eba3f495a1f51590f"));
byte[] payload = key.decryptAES(Hex.decode("84a727bc81fa4b13947dc9728b88fd08"));
System.out.println(Hex.toHexString(payload));
}
@Test
public void testNodeId() {
ECKey key = ECKey.fromPublicOnly(pubKey);
assertEquals(key, ECKey.fromNodeId(key.getNodeId()));
}
}
| 18,454
| 41.327982
| 298
|
java
|
ethereumj
|
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/crypto/cryptohash/Keccak512Test.java
|
/*
* Copyright (c) [2016] [ <ether.camp> ]
* This file is part of the ethereumJ library.
*
* The ethereumJ library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The ethereumJ library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the ethereumJ library. If not, see <http://www.gnu.org/licenses/>.
*/
package org.ethereum.crypto.cryptohash;
import org.junit.Test;
/**
* This class is a program entry point; it includes tests for the
* implementation of the hash functions.
*
* <pre>
* ==========================(LICENSE BEGIN)============================
*
* Copyright (c) 2007-2010 Projet RNRT SAPHIR
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* ===========================(LICENSE END)=============================
* </pre>
*
* @version $Revision: 257 $
* @author Thomas Pornin <thomas.pornin@cryptolog.com>
*/
public class Keccak512Test extends AbstractCryptoTest {
@Test
public void testKeccak512() {
testKatHex(new Keccak512(),
"",
"0eab42de4c3ceb9235fc91acffe746b29c29a8c366b7c60e4e67c466f36a4304c00fa9caf9d87976ba469bcbe06713b435f091ef2769fb160cdab33d3670680e");
testKatHex(new Keccak512(),
"cc",
"8630c13cbd066ea74bbe7fe468fec1dee10edc1254fb4c1b7c5fd69b646e44160b8ce01d05a0908ca790dfb080f4b513bc3b6225ece7a810371441a5ac666eb9");
testKatHex(new Keccak512(),
"41fb",
"551da6236f8b96fce9f97f1190e901324f0b45e06dbbb5cdb8355d6ed1dc34b3f0eae7dcb68622ff232fa3cece0d4616cdeb3931f93803662a28df1cd535b731");
testKatHex(new Keccak512(),
"1f877c",
"eb7f2a98e00af37d964f7d8c44c1fb6e114d8ee21a7b976ae736539efdc1e3fe43becef5015171e6da30168cae99a82c53fa99042774ef982c01626a540f08c0");
testKatHex(new Keccak512(),
"c1ecfdfc",
"952d4c0a6f0ef5ce438c52e3edd345ea00f91cf5da8097c1168a16069e958fc05bad90a0c5fb4dd9ec28e84b226b94a847d6bb89235692ef4c9712f0c7030fae");
testKatHex(new Keccak512(),
"21f134ac57",
"2e76d93affd62b92fc4f29cb83efbe4ba21d88426aa7f075bfc20960ea258787898172e17045af43ab1fe445532be0185fbea84d9be788b05f14dbf4856a5254");
testKatHex(new Keccak512(),
"c6f50bb74e29",
"40fa8074e1e509b206448fbe757d9494b9b51e8d6e674a67f53c11ef92e96c3ea08b95ebd4172b020010cd6cf29539a34d6bfa002a2042787aa8d879a0f5b54c");
testKatHex(new Keccak512(),
"119713cc83eeef",
"d1116786a3c1ea46a8f22d82abb4c5d06dc0691b2e747ac9726d0b290e6959f7b23428519a656b237695e56403855ec4c98db0cf87f31b6ceabf2b9b8589b713");
testKatHex(new Keccak512(),
"4a4f202484512526",
"f326c7c126ddc277922760feef77c9bab6fb5d3430f652593703d7c5e30135cd0b0575257509a624184330d6ab1f508a666391b5d4690426b4e05301891df897");
testKatHex(new Keccak512(),
"1f66ab4185ed9b6375",
"1f5b8a6e8d94f5e2535d46842b9ced467c39c2db323963d3f3d937e9dda76fbc17072dda2ab4771cd7a645145a2aec1b5749bf9efe0cde006cc3ef8936438e0d");
testKatHex(new Keccak512(),
"eed7422227613b6f53c9",
"2aeee7a720c030a820cd7baa8570d72cb90b7a238c38c358676358a7ae9a5cf26635b2320d61c1284899e654f0bfdd0a3a9c343ffbd11838b57465e6c3ad3a57");
testKatHex(new Keccak512(),
"eaeed5cdffd89dece455f1",
"7b1c1bef3b4deb4b4812c81a6e7b3f2c66fa95157fa3b9d2959dc56b8add100170d3c8d1745fd230a31f89fa17889c4c58946b5d746e47b71ed0394b66d1bdb2");
testKatHex(new Keccak512(),
"5be43c90f22902e4fe8ed2d3",
"ee41401af509d6fc0944cd4a0bb29d2dce0dcc862606e669e31381e5d6cecb463143645d696d14e40169cdc71c75686d6e8732b432092626421cc6cc196f80bf");
testKatHex(new Keccak512(),
"a746273228122f381c3b46e4f1",
"9b53b410b9f5dce90a77244db407a3d0f4898d112d0044a8f66af933e26666de63ebd2a4322d8fe525ab354ce9676b6a14d0ce6b3d24e6cd5832bea0c5153cef");
testKatHex(new Keccak512(),
"3c5871cd619c69a63b540eb5a625",
"2b53fe6583fc24ee8a63801067e4d3bd6e6934ef16bc822fc3a69f4ee13a404d9a3ce2bb4a12c77382bfde4d843f87fd06ed8aecc234a3a24cedfe60bfc06933");
testKatHex(new Keccak512(),
"fa22874bcc068879e8ef11a69f0722",
"80946ca68e8c16a9667cd8339d1c5b00f1e0d401d0ecc79458754794838f3ae2949a8cc5fe5584033bca9c5be62c7c08f402ef02f727cefa43bbd374c2a67c52");
testKatHex(new Keccak512(),
"52a608ab21ccdd8a4457a57ede782176",
"4b39d3da5bcdf4d9b769015995644311c14c435bf72b1009d6dd71b01a63b97cfb596418e8e42342d117e07471a8914314ba7b0e264dadf0cea381868cbd43d1");
testKatHex(new Keccak512(),
"82e192e4043ddcd12ecf52969d0f807eed",
"c37c9dc2e20d8e2f0ae588d7d45a807ccfa000fc948ac42a8ed63bb14f318fc3d4b963f7305980e6a0fd2316b55b63142373b1a29002264855c716c5c9f17f4c");
testKatHex(new Keccak512(),
"75683dcb556140c522543bb6e9098b21a21e",
"9073c62555e6095f17df71ad02babb9100288633898489b21c906a3190875baeaccc83be80abd11466fec371ba2c4623d07f0131defaec13a8c732a9f8417163");
testKatHex(new Keccak512(),
"06e4efe45035e61faaf4287b4d8d1f12ca97e5",
"23e9352856718e1e2d68a21d56d93117ced7628e984ff04ed8c0cb9b10539e4ede284f94fa71bf4b83bbb493435fd6be26eddb09deac39680e6b05acc87b8c4e");
testKatHex(new Keccak512(),
"e26193989d06568fe688e75540aea06747d9f851",
"909d753426b1dee09fc474f18cf810d5d5aadbf8a09af495bf6c22aca0c673021bfc5d2ad94f50b24e1569e956694b21cf2cc8b4f3c7ee4cf195e4424cc415dd");
testKatHex(new Keccak512(),
"d8dc8fdefbdce9d44e4cbafe78447bae3b5436102a",
"046c6019fc4d628ae0da7092f9910f269b853d3b57052039ad1375c665405f9fd79d57579f42c4fff249bb85ae65113a9f4276cede73e9ccb0c24753935a006e");
testKatHex(new Keccak512(),
"57085fd7e14216ab102d8317b0cb338a786d5fc32d8f",
"51c909a6528949baddaf1ba0b154ea9c33fde5074359505b76d4b7ed54352dd893d40b142a5f802f378cba7b8c3782ecf2a048542be6c5936822214846a8d5e4");
testKatHex(new Keccak512(),
"a05404df5dbb57697e2c16fa29defac8ab3560d6126fa0",
"efc8917e1247742a2d4ec29afeddf1e6ece377b3d8ac6e58c9851ce9c99bd599adebfed657baacd1793fc91b04df2957bf6f1888869286002dc4ad9ac7f76793");
testKatHex(new Keccak512(),
"aecbb02759f7433d6fcb06963c74061cd83b5b3ffa6f13c6",
"fcef88bcc7ef70d8c3973429ac5139155f9ba643b431013f1817ecd2ff3ab287880f9ea54df7503cb3f73d7cf2b87d2e9bdbd203378fae74ca4bd2667a4aa706");
testKatHex(new Keccak512(),
"aafdc9243d3d4a096558a360cc27c8d862f0be73db5e88aa55",
"470bdd8d709875c8e6f88591b97d6486c5f03b54bfc905757483e013f63a6c56984d4518d45c2d2298eadb44af3a0c35a76b573d452f5747844d3ad8f84a2e85");
testKatHex(new Keccak512(),
"7bc84867f6f9e9fdc3e1046cae3a52c77ed485860ee260e30b15",
"429fd438b390ad0224028975467ec228f9adcde71e1738005e3717c58f727aa2b7c61780bf0c5f8b766cc6d34551d87d22a130b8c215614204e607aa82ff8469");
testKatHex(new Keccak512(),
"fac523575a99ec48279a7a459e98ff901918a475034327efb55843",
"790a010aeb6f13e019a1dc35574b1219e74ff5db6fbd8746733664ffdbcfe1cc6e8ab39117e3244c4fa3c0a962c9f50030aef88e193e7e0d4c4747345f30cb54");
testKatHex(new Keccak512(),
"0f8b2d8fcfd9d68cffc17ccfb117709b53d26462a3f346fb7c79b85e",
"aaf7a391600270f7b5a2a3bbc7474ac4154ebeac03a790a57fdad96cea2d043c9fa5f6916790b92f8032d668ed9a07112dc5b2373ec816aabca6f577ce60415e");
testKatHex(new Keccak512(),
"a963c3e895ff5a0be4824400518d81412f875fa50521e26e85eac90c04",
"3e2880a974e50f98bd6cc0f9d769af348ce3b7e8fa38cf0ca2da5fd704c9c0e57d5500bea3cb7477927f9c394aa3f9bbc01824350291b9a0a0cbf094bb37da55");
testKatHex(new Keccak512(),
"03a18688b10cc0edf83adf0a84808a9718383c4070c6c4f295098699ac2c",
"48e55e0340f20466881a732aa88459ad4bcdef364c3bd045ae099f953d89f15957aef204265c3915ba42fe4235196be3d0f564676227c3c0deacfbaf68f9e717");
testKatHex(new Keccak512(),
"84fb51b517df6c5accb5d022f8f28da09b10232d42320ffc32dbecc3835b29",
"9d8098d8d6edbbaa2bcfc6fb2f89c3eac67fec25cdfe75aa7bd570a648e8c8945ff2ec280f6dcf73386109155c5bbc444c707bb42eab873f5f7476657b1bc1a8");
testKatHex(new Keccak512(),
"9f2fcc7c90de090d6b87cd7e9718c1ea6cb21118fc2d5de9f97e5db6ac1e9c10",
"1eafedce7292ba73b80ae6151745f43ac95bfc9f31694d422473abca2e69d695cb6544db65506078cb20dbe0762f84aa6afd14a60ab597955be73f3f5c50f7a8");
testKatHex(new Keccak512(),
"de8f1b3faa4b7040ed4563c3b8e598253178e87e4d0df75e4ff2f2dedd5a0be046",
"9a7688e31aaf40c15575fc58c6b39267aad3722e696e518a9945cf7f7c0fea84cb3cb2e9f0384a6b5dc671ade7fb4d2b27011173f3eeeaf17cb451cf26542031");
testKatHex(new Keccak512(),
"62f154ec394d0bc757d045c798c8b87a00e0655d0481a7d2d9fb58d93aedc676b5a0",
"ada5ca5630660003c4d16149f235faeb78132f7f773a631f820cc5c654b08eab4206bb4ea1389d1cf74d3b60b86e484c90c817cdb5dd5dbf327163b4646f7213");
testKatHex(new Keccak512(),
"b2dcfe9ff19e2b23ce7da2a4207d3e5ec7c6112a8a22aec9675a886378e14e5bfbad4e",
"71a0801d32587980b09963a0f547b8b6ee3bade224671bf44f12e3da4f21778bac37fcc73ef45fee1c96688baf9020f487b1a16e3ac91b504845d6fba879134f");
testKatHex(new Keccak512(),
"47f5697ac8c31409c0868827347a613a3562041c633cf1f1f86865a576e02835ed2c2492",
"eba678b7a0e5669dc7fa5eca5d5f19fe625e113e5028da5efb138923cd444757b06078e0ba064b36c72ca2187ab9dd31dda6f24668f46c32f8ec21ac59aafa24");
testKatHex(new Keccak512(),
"512a6d292e67ecb2fe486bfe92660953a75484ff4c4f2eca2b0af0edcdd4339c6b2ee4e542",
"12df92d889d7ba0df05bcd02d9de58c97f4813126967ff78bdf759c66c4cbe9df68ab31a0256c776730bb25deecf91f0997868ac8bb86df7a0fc110cb0a4de5d");
testKatHex(new Keccak512(),
"973cf2b4dcf0bfa872b41194cb05bb4e16760a1840d8343301802576197ec19e2a1493d8f4fb",
"b8c7ce2be4cb32c140e75b75474248c1dd77d19b0cbca31a3ecc2a35c532e4fa3ed4abbcda27aa68a9dda06b245443e5903a65652a94ed3af15065d3e7736e47");
testKatHex(new Keccak512(),
"80beebcd2e3f8a9451d4499961c9731ae667cdc24ea020ce3b9aa4bbc0a7f79e30a934467da4b0",
"a0ae9dfb56831fe4a3223c501b697bd8243c471e8343acfd37a6b587feac74571c23deebc9b94a540a02f1b1e2251e01229c9d58c4279f155d5566fb18e81295");
testKatHex(new Keccak512(),
"7abaa12ec2a7347674e444140ae0fb659d08e1c66decd8d6eae925fa451d65f3c0308e29446b8ed3",
"631e7847124a70fe6eb293a44a25c50600b5e7e975ca9fab5ae64ab86c7e42c912dd6ec093f01a8debc6e1f5e487af97dc3fd6c53002765050be963ffcd4d989");
testKatHex(new Keccak512(),
"c88dee9927679b8af422abcbacf283b904ff31e1cac58c7819809f65d5807d46723b20f67ba610c2b7",
"b989263bb4e0424f95fdc9a49c83a3769fbf31dcedda7e005ab5f22f43d2718debd39085971f7eb7822c9fa0f67f776cec4e35a9a8b8c835ef4e9ebda1922e4d");
testKatHex(new Keccak512(),
"01e43fe350fcec450ec9b102053e6b5d56e09896e0ddd9074fe138e6038210270c834ce6eadc2bb86bf6",
"ff6adcb9e1546798d396db78452df1a375b65ee3d54fcc915a8ca3da693e24931999b0fc8a4eb92f6ff85e42bb4cfd9ce7d7863eee709c9ef37642b696174474");
testKatHex(new Keccak512(),
"337023370a48b62ee43546f17c4ef2bf8d7ecd1d49f90bab604b839c2e6e5bd21540d29ba27ab8e309a4b7",
"1051b7ff77274b784e7fb7823e756f0c4355047e489775bbedaa7ce5a75efac331492c016ce02eb2be8ba2fe6b735b9a1484e73ac06de573c5d0b4a58822a36a");
testKatHex(new Keccak512(),
"6892540f964c8c74bd2db02c0ad884510cb38afd4438af31fc912756f3efec6b32b58ebc38fc2a6b913596a8",
"5639a2824297ca099ecf2a81eef1753f6314cb663d860f05a39e3e801ff82060bba10628e2c0d9e0a84dd05ed637fc0b65ba03bb66e46fb256f2a5b28d3f41d2");
testKatHex(new Keccak512(),
"f5961dfd2b1ffffda4ffbf30560c165bfedab8ce0be525845deb8dc61004b7db38467205f5dcfb34a2acfe96c0",
"97f9d642507e6dd179d56f4b815e92d0d486826f273ec711b8f9cb76afc79f900816fdbc13dd3a59fbecba1f3b6953f879f27c8987b24c6ff8557a2c834076b9");
testKatHex(new Keccak512(),
"ca061a2eb6ceed8881ce2057172d869d73a1951e63d57261384b80ceb5451e77b06cf0f5a0ea15ca907ee1c27eba",
"afef2af5a01b89be190a0e6e796aa51f1f8c356772c6fc7731f08aab8bd81aee1287c70d564f4f169e37b07f28202a85f468281b4cdc1273cf61eb30e3bdcee1");
testKatHex(new Keccak512(),
"1743a77251d69242750c4f1140532cd3c33f9b5ccdf7514e8584d4a5f9fbd730bcf84d0d4726364b9bf95ab251d9bb",
"f467cca67c387ffc9f1b173a084c451095d01ad0bf3953ac103a76f0f1bc86167305a926a941a53417f1611a505aaa205bcfccbfd343465dad8a6c1e80609a9d");
testKatHex(new Keccak512(),
"d8faba1f5194c4db5f176fabfff856924ef627a37cd08cf55608bba8f1e324d7c7f157298eabc4dce7d89ce5162499f9",
"4b389a2a0df5e295ea9444f2739b5492f290c4467b0b4cdc1cc9ed2cefa7a9e527e0627cdaf0bda58f17d13f94af7d2deff6fc5d53dd9157674475527fbb4f86");
testKatHex(new Keccak512(),
"be9684be70340860373c9c482ba517e899fc81baaa12e5c6d7727975d1d41ba8bef788cdb5cf4606c9c1c7f61aed59f97d",
"6590fffb7311ab7dab370fb518ccc19baa9af7c84179adb002f8facd3c44af2830a84df1e2c2402368cc36614a6ea22903063e57d00ec511a46a9a03fe3819f7");
testKatHex(new Keccak512(),
"7e15d2b9ea74ca60f66c8dfab377d9198b7b16deb6a1ba0ea3c7ee2042f89d3786e779cf053c77785aa9e692f821f14a7f51",
"895796b2a0824c55f030d82e794925c38d8459f38cf848519f120ff6a9d5a03ebf006c3ea5021e8f3b3408ff12f01bcddf7a085ba0a9a58944fec1f554836df8");
testKatHex(new Keccak512(),
"9a219be43713bd578015e9fda66c0f2d83cac563b776ab9f38f3e4f7ef229cb443304fba401efb2bdbd7ece939102298651c86",
"e4bbd54bfb99d345471f8ab94271b4b748f5ce70c21c28ae6559e03ee7890a2c814043e624a6bd2944350756b37fa8208fc7473a67b310ceebc17d965ed688b2");
testKatHex(new Keccak512(),
"c8f2b693bd0d75ef99caebdc22adf4088a95a3542f637203e283bbc3268780e787d68d28cc3897452f6a22aa8573ccebf245972a",
"80d862ad05428a299213e65b50310463fd22c505e693dd4719e0a120eeaa35c5fc1608a08d22e2ccddeca49878bc26abe55a3c9a546347439a942ed0c1a6a23e");
testKatHex(new Keccak512(),
"ec0f99711016c6a2a07ad80d16427506ce6f441059fd269442baaa28c6ca037b22eeac49d5d894c0bf66219f2c08e9d0e8ab21de52",
"021b3b392deccb9075559f88c0c229026a2048cef8eeb2d4f94803dcf2da0a73e004d7f14e9fd662670b59229ab3883c340f4e3a8c42624ccb90bec1156f95d4");
testKatHex(new Keccak512(),
"0dc45181337ca32a8222fe7a3bf42fc9f89744259cff653504d6051fe84b1a7ffd20cb47d4696ce212a686bb9be9a8ab1c697b6d6a33",
"97bf33a5254c8aca27486428440b1034aaafac8b498ecb830c2581dc68518079b65fb0c595997693ddb8d68d9564ea98dc43cd287e2e018db7dfaaaa205c547a");
testKatHex(new Keccak512(),
"de286ba4206e8b005714f80fb1cdfaebde91d29f84603e4a3ebc04686f99a46c9e880b96c574825582e8812a26e5a857ffc6579f63742f",
"c05fd9c3fa73f80956ff1c3b89160eb520ca640e201b3fe5e6e296220e81b59d530476010d3784ca08692b8c716a3be982b37450a96d30a401d3ba3c390d9de3");
testKatHex(new Keccak512(),
"eebcc18057252cbf3f9c070f1a73213356d5d4bc19ac2a411ec8cdeee7a571e2e20eaf61fd0c33a0ffeb297ddb77a97f0a415347db66bcaf",
"b980e657c13726dbadb6570ea3a9e633869cadb798eb35c482697a04cb712f1c1e8c5d0bd67e43e52da294e82d5e80a695a74a3d27c0c672adcfe2c928859a6d");
testKatHex(new Keccak512(),
"416b5cdc9fe951bd361bd7abfc120a5054758eba88fdd68fd84e39d3b09ac25497d36b43cbe7b85a6a3cebda8db4e5549c3ee51bb6fcb6ac1e",
"6adfc561835fddd70a9feb57c513165d12aeb3283f0dd7774dd58852da9e969abdaf20dd44856fa60e11bdfa2dbb7e3347669fff7a57a8d8d37431c2b309972d");
testKatHex(new Keccak512(),
"5c5faf66f32e0f8311c32e8da8284a4ed60891a5a7e50fb2956b3cbaa79fc66ca376460e100415401fc2b8518c64502f187ea14bfc9503759705",
"0e7459bdc857b949cc59a9c649b9625268bf9a11ea81eeefa4ecdd410e2f6fd2c78289c01365f99034ff8fa8c115ddcebefa26a8d6468f5030e641745950061e");
testKatHex(new Keccak512(),
"7167e1e02be1a7ca69d788666f823ae4eef39271f3c26a5cf7cee05bca83161066dc2e217b330df821103799df6d74810eed363adc4ab99f36046a",
"2a8ce9df40879b24dadf61c9131f694e5531ade6b7ab071ca10abdd3c2e4a22c868a52986a329f880137ee76109770927d2658e63eb486d880290ac0782cf5bf");
testKatHex(new Keccak512(),
"2fda311dbba27321c5329510fae6948f03210b76d43e7448d1689a063877b6d14c4f6d0eaa96c150051371f7dd8a4119f7da5c483cc3e6723c01fb7d",
"a83ce5a6a58376d57db4c58da1b46c131ff1bf8ff2de5e8617fb37e5098398edb53f9888b8752a8aff19178f2f6bd7a33fd36c59e4a631906280907fc1c5ab07");
testKatHex(new Keccak512(),
"95d1474a5aab5d2422aca6e481187833a6212bd2d0f91451a67dd786dfc91dfed51b35f47e1deb8a8ab4b9cb67b70179cc26f553ae7b569969ce151b8d",
"9ebfcea2db1676eee6b103119543c6049debd8fb8f1e01a5ab5b348e2919e14c8cfe8e542f2ab747b0fd4a4c3eee4019bb046e24bfe2091fb9c65dca527b71ad");
testKatHex(new Keccak512(),
"c71bd7941f41df044a2927a8ff55b4b467c33d089f0988aa253d294addbdb32530c0d4208b10d9959823f0c0f0734684006df79f7099870f6bf53211a88d",
"97b08be7653e9df1b5afa459ea750a3ac9bf3577bcc7e5344fc861184880926def354e4c65b20ec66c47b7affd3e7493958bab0a90724d3d8dd9e1d561fa60c2");
testKatHex(new Keccak512(),
"f57c64006d9ea761892e145c99df1b24640883da79d9ed5262859dcda8c3c32e05b03d984f1ab4a230242ab6b78d368dc5aaa1e6d3498d53371e84b0c1d4ba",
"ef8aaf08159bbcb88efac49a33a5248b7ed0544960d8dd54d748a91c0d84c69f308bb54cb5ec97d3f81cdf76e68e0320815b93f2a00942f2168cbc18e8377708");
testKatHex(new Keccak512(),
"e926ae8b0af6e53176dbffcc2a6b88c6bd765f939d3d178a9bde9ef3aa131c61e31c1e42cdfaf4b4dcde579a37e150efbef5555b4c1cb40439d835a724e2fae7",
"c0a4d8dca967772dbf6e5508c913e7beba1b749a2b1ac963d0676e6f1dcd4ebaa3f909ef87dd849882dc8253347a5f6520b5b9f510973f443976455f923cfcb9");
testKatHex(new Keccak512(),
"16e8b3d8f988e9bb04de9c96f2627811c973ce4a5296b4772ca3eefeb80a652bdf21f50df79f32db23f9f73d393b2d57d9a0297f7a2f2e79cfda39fa393df1ac00",
"cf03c946eb7022f60fb5439462ac22684e47eaacbffe19b797760b4a24a5238be9d90e17d40ea6fe7b2885cef7dfb8bb489401caa94f2dd6e04592e33e76b9d1");
testKatHex(new Keccak512(),
"fc424eeb27c18a11c01f39c555d8b78a805b88dba1dc2a42ed5e2c0ec737ff68b2456d80eb85e11714fa3f8eabfb906d3c17964cb4f5e76b29c1765db03d91be37fc",
"2c35f1a57a17cb29403a2b40fc307bde10ba8f7fec7b94e1e42eb4eeb952aad00ec46a26646cd51db0c6b238189d7d470e21c29bf8710423cb5602cab75e29e7");
testKatHex(new Keccak512(),
"abe3472b54e72734bdba7d9158736464251c4f21b33fbbc92d7fac9a35c4e3322ff01d2380cbaa4ef8fb07d21a2128b7b9f5b6d9f34e13f39c7ffc2e72e47888599ba5",
"505e6e607c90c57bbe7ce52bb42df3d90bc32de554025730c84ed0f89a0132885d7a40fadff7a4b01de4d29735aefe0e0469f4f172b62a0daba889e152308fc4");
testKatHex(new Keccak512(),
"36f9f0a65f2ca498d739b944d6eff3da5ebba57e7d9c41598a2b0e4380f3cf4b479ec2348d015ffe6256273511154afcf3b4b4bf09d6c4744fdd0f62d75079d440706b05",
"7be2c95413c589ec5ad69f8d80bfe9f26540d5c1832c7a49a31a8f5655d9ce8b47d97c69cccd693c211904142a5403da7ad09fbdb825698fe201988fcccd2bb2");
testKatHex(new Keccak512(),
"abc87763cae1ca98bd8c5b82caba54ac83286f87e9610128ae4de68ac95df5e329c360717bd349f26b872528492ca7c94c2c1e1ef56b74dbb65c2ac351981fdb31d06c77a4",
"8aac9201d76df13424a32552f04390e499b6168711b70c875789ddaa9b115f8b8259a60d17835e2587f8901c3ca782da9afb28ba87b9fcbe05a47a42f48fcd48");
testKatHex(new Keccak512(),
"94f7ca8e1a54234c6d53cc734bb3d3150c8ba8c5f880eab8d25fed13793a9701ebe320509286fd8e422e931d99c98da4df7e70ae447bab8cffd92382d8a77760a259fc4fbd72",
"aa52587d84586317028fb7d3c20892e0288bfe2feabd76d7f89155ffe9ccbf1a09fa0ffb0553e83f79ae58bd30a35fa54892b6aba0093a012427ddab71cdf819");
testKatHex(new Keccak512(),
"13bd2811f6ed2b6f04ff3895aceed7bef8dcd45eb121791bc194a0f806206bffc3b9281c2b308b1a729ce008119dd3066e9378acdcc50a98a82e20738800b6cddbe5fe9694ad6d",
"48fc282f37a3e1fb5df4d2da1f7197ec899ae573ca08df550e61ee847eeb1d24c074ff46bcaee224ec7d8cea4256154f0c4d434e682834f6d827bfbdf75112f5");
testKatHex(new Keccak512(),
"1eed9cba179a009ec2ec5508773dd305477ca117e6d569e66b5f64c6bc64801ce25a8424ce4a26d575b8a6fb10ead3fd1992edddeec2ebe7150dc98f63adc3237ef57b91397aa8a7",
"6b4b0f126863552a6f40f45e295dc79b9ba2a88ea7c3b2f607ac1a8431a97844c2a7b664443fb23c05739df5494fe9824db80b7f3e67872142f17e2c5544e1ef");
testKatHex(new Keccak512(),
"ba5b67b5ec3a3ffae2c19dd8176a2ef75c0cd903725d45c9cb7009a900c0b0ca7a2967a95ae68269a6dbf8466c7b6844a1d608ac661f7eff00538e323db5f2c644b78b2d48de1a08aa",
"7eec7b730056b1bd4f6ffc186fb45591e50cd93cf6e4fc958889f82d3f32c5c74d03a4bcf7d2754298f134698af4559b0e29baaa365cc00db0d51d407179c56d");
testKatHex(new Keccak512(),
"0efa26ac5673167dcacab860932ed612f65ff49b80fa9ae65465e5542cb62075df1c5ae54fba4db807be25b070033efa223bdd5b1d3c94c6e1909c02b620d4b1b3a6c9fed24d70749604",
"79cb925aca072ebb3b49a9d0e59bb07dd1c223c1f26c91768b929472c51b977f85c6ceeb54bce89cf9ff6155d7fe8091540f1348ce9592a6403f92105477870e");
testKatHex(new Keccak512(),
"bbfd933d1fd7bf594ac7f435277dc17d8d5a5b8e4d13d96d2f64e771abbd51a5a8aea741beccbddb177bcea05243ebd003cfdeae877cca4da94605b67691919d8b033f77d384ca01593c1b",
"b5d1ed8f039044bcfef41e99b2f564f45991b329b503fc91fa29d2408512f8711e9db66f8ae172164650545ae9e3db32aa369ec47e81a77111276e6ca38e4d92");
testKatHex(new Keccak512(),
"90078999fd3c35b8afbf4066cbde335891365f0fc75c1286cdd88fa51fab94f9b8def7c9ac582a5dbcd95817afb7d1b48f63704e19c2baa4df347f48d4a6d603013c23f1e9611d595ebac37c",
"782c008a9ee3dda0a182267185c995a2af737ba8cb2f6179f2cdf52505f8d933e712fc4e56d10e175ec8cdd62de6529ce1f078bfa0dc7a5284f8c565182f85d9");
testKatHex(new Keccak512(),
"64105eca863515c20e7cfbaa0a0b8809046164f374d691cdbd6508aaabc1819f9ac84b52bafc1b0fe7cddbc554b608c01c8904c669d8db316a0953a4c68ece324ec5a49ffdb59a1bd6a292aa0e",
"91a0241eda8ca597cbb0f703ab7dbaaf859cff77b20401ad46230ce3b2beef6685775de37576014d8da1ba672d47aad95fb53c590b650634cebb43a175738569");
testKatHex(new Keccak512(),
"d4654be288b9f3b711c2d02015978a8cc57471d5680a092aa534f7372c71ceaab725a383c4fcf4d8deaa57fca3ce056f312961eccf9b86f14981ba5bed6ab5b4498e1f6c82c6cae6fc14845b3c8a",
"00b02dbcb7a3bc117701f2f159fc4492923c437d3369833a9bd09e78e260d48d37168d36c49777b2e68e6fe9846106a6ab8768c3971fab31fd922aacb87d1cac");
testKatHex(new Keccak512(),
"12d9394888305ac96e65f2bf0e1b18c29c90fe9d714dd59f651f52b88b3008c588435548066ea2fc4c101118c91f32556224a540de6efddbca296ef1fb00341f5b01fecfc146bdb251b3bdad556cd2",
"3dedf819b357dfab1c7092abd872a1554dd0962e9944eef9f7f8bce830f2d74f1d9ba2b748bbc6ee0b7600be8cb0ffcb79924d9f51cdb9b06bd6fd37f3050229");
testKatHex(new Keccak512(),
"871a0d7a5f36c3da1dfce57acd8ab8487c274fad336bc137ebd6ff4658b547c1dcfab65f037aa58f35ef16aff4abe77ba61f65826f7be681b5b6d5a1ea8085e2ae9cd5cf0991878a311b549a6d6af230",
"5fbe194557b0426f96ba60712176df073eafe04f2a50515455412ea3d80c116758ad952598f48031612181d82a16efe4668ffb3bcce9563a772fe416ff6db3b3");
testKatHex(new Keccak512(),
"e90b4ffef4d457bc7711ff4aa72231ca25af6b2e206f8bf859d8758b89a7cd36105db2538d06da83bad5f663ba11a5f6f61f236fd5f8d53c5e89f183a3cec615b50c7c681e773d109ff7491b5cc22296c5",
"2e8ab1619859c11473dc7c474ce8b0ae44b1c38417816fd95b9e0614f31e51ebb1dd16d1cbb584c4ebd28aa99f4a68e09dfe3ad462487f2608124b7528293045");
testKatHex(new Keccak512(),
"e728de62d75856500c4c77a428612cd804f30c3f10d36fb219c5ca0aa30726ab190e5f3f279e0733d77e7267c17be27d21650a9a4d1e32f649627638dbada9702c7ca303269ed14014b2f3cf8b894eac8554",
"db2d182bdbac6ac866537e24712332cae74dc3d36168982e4453dd6e009658345255013bc0a54fca17aeedcc4beb79bdee192cfab516d24591c8699f7c758179");
testKatHex(new Keccak512(),
"6348f229e7b1df3b770c77544e5166e081850fa1c6c88169db74c76e42eb983facb276ad6a0d1fa7b50d3e3b6fcd799ec97470920a7abed47d288ff883e24ca21c7f8016b93bb9b9e078bdb9703d2b781b616e",
"90a2c05f7001d985b587a046b488bf4ed29d75cc03a745731b5b0ce51bb86387c4ce34018a6d906eb7beb41a09afe9fedd99aacc41b4556f75229c8688c7fca2");
testKatHex(new Keccak512(),
"4b127fde5de733a1680c2790363627e63ac8a3f1b4707d982caea258655d9bf18f89afe54127482ba01e08845594b671306a025c9a5c5b6f93b0a39522dc877437be5c2436cbf300ce7ab6747934fcfc30aeaaf6",
"ea3991c4a8a5f0146402de4ae235054c78a48dca340a7d4ad8753995f82347ecfc0054d64eb4f20abc4f415c54701cbc61a7b239a7c221b833d9ea9f94b154e8");
testKatHex(new Keccak512(),
"08461f006cff4cc64b752c957287e5a0faabc05c9bff89d23fd902d324c79903b48fcb8f8f4b01f3e4ddb483593d25f000386698f5ade7faade9615fdc50d32785ea51d49894e45baa3dc707e224688c6408b68b11",
"1313023b753ed1727f13cc67a64b989a8bf6548324df9854d8d5a963ed3d860257fe6522b9c6d6cb1bcadf322c985601ba36f7e67110192094aa8f9869a458a8");
testKatHex(new Keccak512(),
"68c8f8849b120e6e0c9969a5866af591a829b92f33cd9a4a3196957a148c49138e1e2f5c7619a6d5edebe995acd81ec8bb9c7b9cfca678d081ea9e25a75d39db04e18d475920ce828b94e72241f24db72546b352a0e4",
"9bca2a1a5546a11275bf42f0b48492868359c78d94785a0ee12dc1c3d70a8e97eb462148faed1ffa4dab0e91519bd36c0c5c5fe7cfcff3e180680318e1fcf75b");
testKatHex(new Keccak512(),
"b8d56472954e31fb54e28fca743f84d8dc34891cb564c64b08f7b71636debd64ca1edbdba7fc5c3e40049ce982bba8c7e0703034e331384695e9de76b5104f2fbc4535ecbeebc33bc27f29f18f6f27e8023b0fbb6f563c",
"8492f5e621e82fdbff1976b1beecff7d137805b5736ab49216122a95396b863a0481212b6daba8b05e29e287bb0e2f588f86407c84dbfb894e6acfc6f6b2e571");
testKatHex(new Keccak512(),
"0d58ac665fa84342e60cefee31b1a4eacdb092f122dfc68309077aed1f3e528f578859ee9e4cefb4a728e946324927b675cd4f4ac84f64db3dacfe850c1dd18744c74ceccd9fe4dc214085108f404eab6d8f452b5442a47d",
"eebe4ec0fe3e0266527f4d9f57a017637eab92377d82b15856a55a22b008df67f27aa5ac04e1deeeb2c819ce41db07dbf6dcaf17a192a4371a1e92badf1e6389");
testKatHex(new Keccak512(),
"1755e2d2e5d1c1b0156456b539753ff416651d44698e87002dcf61dcfa2b4e72f264d9ad591df1fdee7b41b2eb00283c5aebb3411323b672eaa145c5125185104f20f335804b02325b6dea65603f349f4d5d8b782dd3469ccd",
"9e36e6291bc2296cb4ba71109cedcc2a3f0b4f1ae5e5406dc4b3e594551d5c70e6f814d2c9b8413103ef07535886b4ac518aaf7aed64abed7a5b0a26f7171425");
testKatHex(new Keccak512(),
"b180de1a611111ee7584ba2c4b020598cd574ac77e404e853d15a101c6f5a2e5c801d7d85dc95286a1804c870bb9f00fd4dcb03aa8328275158819dcad7253f3e3d237aeaa7979268a5db1c6ce08a9ec7c2579783c8afc1f91a7",
"f1089483a00b2601be9c16469a090efc49fcb70e62ac0ffea2d1e508083cd5d41dcf2daae1e0eac217859e5feaddcb782ac471c01d7266136185d37b568e9606");
testKatHex(new Keccak512(),
"cf3583cbdfd4cbc17063b1e7d90b02f0e6e2ee05f99d77e24e560392535e47e05077157f96813544a17046914f9efb64762a23cf7a49fe52a0a4c01c630cfe8727b81fb99a89ff7cc11dca5173057e0417b8fe7a9efba6d95c555f",
"d063ea794cfd2ed9248665a6084a7b99051c1051e41b7d9dcb1537a1c79cba6deb4d844c6a618e43c7ca020d16976999684feb084616f707209f75c4bd584d86");
testKatHex(new Keccak512(),
"072fc02340ef99115bad72f92c01e4c093b9599f6cfc45cb380ee686cb5eb019e806ab9bd55e634ab10aa62a9510cc0672cd3eddb589c7df2b67fcd3329f61b1a4441eca87a33c8f55da4fbbad5cf2b2527b8e983bb31a2fadec7523",
"424a86d746c87c85dabd1dae298a488e4ca2183de692d1d01c4b7994ee5124f9004bea84933c311cc38ea6f604a7769ee178e1ec160a9891c42c462a13a62286");
testKatHex(new Keccak512(),
"76eecf956a52649f877528146de33df249cd800e21830f65e90f0f25ca9d6540fde40603230eca6760f1139c7f268deba2060631eea92b1fff05f93fd5572fbe29579ecd48bc3a8d6c2eb4a6b26e38d6c5fbf2c08044aeea470a8f2f26",
"a9403c26a96de2c3d359ee29f3fd1c581154852d19ad12884b79e7082d2da22ec83553baba2bdff2a2fa15947a8e6acd5f5d113ec091bfd1962a0a10401d2c98");
testKatHex(new Keccak512(),
"7adc0b6693e61c269f278e6944a5a2d8300981e40022f839ac644387bfac9086650085c2cdc585fea47b9d2e52d65a2b29a7dc370401ef5d60dd0d21f9e2b90fae919319b14b8c5565b0423cefb827d5f1203302a9d01523498a4db10374",
"3d23632ee4c2d4f4118a02a677b5a32427c72ba54899ba2e6ccd22ec3defe0fcb052e3f83d35786cea2080eed148a0a94628e735202e6b2809994c5f5bdafdd6");
testKatHex(new Keccak512(),
"e1fffa9826cce8b86bccefb8794e48c46cdf372013f782eced1e378269b7be2b7bf51374092261ae120e822be685f2e7a83664bcfbe38fe8633f24e633ffe1988e1bc5acf59a587079a57a910bda60060e85b5f5b6f776f0529639d9cce4bd",
"d8fa886884ce577a7282deceacf4786e7c68fc69b141137ff5dc7cb3c5f8abc845716dd27397e8bd5ce245107a984a3f8b21f19f99ed40118621dc85303a30b4");
testKatHex(new Keccak512(),
"69f9abba65592ee01db4dce52dbab90b08fc04193602792ee4daa263033d59081587b09bbe49d0b49c9825d22840b2ff5d9c5155f975f8f2c2e7a90c75d2e4a8040fe39f63bbafb403d9e28cc3b86e04e394a9c9e8065bd3c85fa9f0c7891600",
"c768cd313602fabb2193f9edbf667b4cdabd57d5ff60bdc22ba7bad5319ea04e7cbec5d4b4c4560ad52609fdd22750b618951796376ed41b2a8eaffdd9927722");
testKatHex(new Keccak512(),
"38a10a352ca5aedfa8e19c64787d8e9c3a75dbf3b8674bfab29b5dbfc15a63d10fae66cd1a6e6d2452d557967eaad89a4c98449787b0b3164ca5b717a93f24eb0b506ceb70cbbcb8d72b2a72993f909aad92f044e0b5a2c9ac9cb16a0ca2f81f49",
"8562ce9399806623b2695712266af3d4c14f77d2449143379246962c22398c813544a7dee4c4847f09d3cbe437349b7fc6738ac97075b5dd9e2add6ecaa610f4");
testKatHex(new Keccak512(),
"6d8c6e449bc13634f115749c248c17cd148b72157a2c37bf8969ea83b4d6ba8c0ee2711c28ee11495f43049596520ce436004b026b6c1f7292b9c436b055cbb72d530d860d1276a1502a5140e3c3f54a93663e4d20edec32d284e25564f624955b52",
"99ade7b13e8e79aea6ed01a25e10e401cd1d055884575eab3e66b2294f03f8d5dbf72ab1ae39103189383ebfd2e43258510c124a894a793b206fac752c035789");
testKatHex(new Keccak512(),
"6efcbcaf451c129dbe00b9cef0c3749d3ee9d41c7bd500ade40cdc65dedbbbadb885a5b14b32a0c0d087825201e303288a733842fa7e599c0c514e078f05c821c7a4498b01c40032e9f1872a1c925fa17ce253e8935e4c3c71282242cb716b2089ccc1",
"d12831ba39dbcd41f56bc7fc071bdaabfb6e7572d08b2fda3bddfc6fa5662f4bdbfa431ca2e38b18172709072e50120db6be93e86cb4ace3c11dd0e1f3f5c712");
testKatHex(new Keccak512(),
"433c5303131624c0021d868a30825475e8d0bd3052a022180398f4ca4423b98214b6beaac21c8807a2c33f8c93bd42b092cc1b06cedf3224d5ed1ec29784444f22e08a55aa58542b524b02cd3d5d5f6907afe71c5d7462224a3f9d9e53e7e0846dcbb4ce",
"527d28e341e6b14f4684adb4b824c496c6482e51149565d3d17226828884306b51d6148a72622c2b75f5d3510b799d8bdc03eaede453676a6ec8fe03a1ad0eab");
testKatHex(new Keccak512(),
"a873e0c67ca639026b6683008f7aa6324d4979550e9bce064ca1e1fb97a30b147a24f3f666c0a72d71348ede701cf2d17e2253c34d1ec3b647dbcef2f879f4eb881c4830b791378c901eb725ea5c172316c6d606e0af7df4df7f76e490cd30b2badf45685f",
"cacdcf8bf855040e9795c422069d8e37b6286066a2197a320bd934061f66995227be6b85fd928b834d3ca45e1ac3844d9dc66d61581e7799ccfde008639ab3dd");
testKatHex(new Keccak512(),
"006917b64f9dcdf1d2d87c8a6173b64f6587168e80faa80f82d84f60301e561e312d9fbce62f39a6fb476e01e925f26bcc91de621449be6504c504830aae394096c8fc7694651051365d4ee9070101ec9b68086f2ea8f8ab7b811ea8ad934d5c9b62c60a4771",
"f454a953501e191a12a80c7a5398f081cef738e25d48b076a52f77fb09ef0bc2325116020bb06c2c585da9f115bd9d8f13b50e8e1fb1664450fae690b7783400");
testKatHex(new Keccak512(),
"f13c972c52cb3cc4a4df28c97f2df11ce089b815466be88863243eb318c2adb1a417cb1041308598541720197b9b1cb5ba2318bd5574d1df2174af14884149ba9b2f446d609df240ce335599957b8ec80876d9a085ae084907bc5961b20bf5f6ca58d5dab38adb",
"5f968cc6ecf71c588a3c3ba68858bbff96861f66c0733fd61fa91a479a49618df22d9490219df8008dc78840ae022c5d41af2b890d0214e562da8df0cb3f8522");
testKatHex(new Keccak512(),
"e35780eb9799ad4c77535d4ddb683cf33ef367715327cf4c4a58ed9cbdcdd486f669f80189d549a9364fa82a51a52654ec721bb3aab95dceb4a86a6afa93826db923517e928f33e3fba850d45660ef83b9876accafa2a9987a254b137c6e140a21691e1069413848",
"e7149461f9cd00b71c216c50041b3eda9707d7360d4c21740c44c212256a31da398fe09708e450ea4e2826b7ec20bef76cd2fbd9d096af6f77f84abc2e4fb093");
testKatHex(new Keccak512(),
"64ec021c9585e01ffe6d31bb50d44c79b6993d72678163db474947a053674619d158016adb243f5c8d50aa92f50ab36e579ff2dabb780a2b529370daa299207cfbcdd3a9a25006d19c4f1fe33e4b1eaec315d8c6ee1e730623fd1941875b924eb57d6d0c2edc4e78d6",
"77097413caa5a2d38259d47ec078871fa09ee5614d4c14feb7a95c921c0aae93b8737a6dc89e57693be8a0710206664b80b657a1079605a0ff9664bbcb0722d6");
testKatHex(new Keccak512(),
"5954bab512cf327d66b5d9f296180080402624ad7628506b555eea8382562324cf452fba4a2130de3e165d11831a270d9cb97ce8c2d32a96f50d71600bb4ca268cf98e90d6496b0a6619a5a8c63db6d8a0634dfc6c7ec8ea9c006b6c456f1b20cd19e781af20454ac880",
"55d8e5202360d7d5841419362f864cc900e11c582fd0cab2ff5f1680f6ce927b5379e27a335ebafe1286b9d4a172ab761a36eade60f10468eac4ceafbf63c7cc");
testKatHex(new Keccak512(),
"03d9f92b2c565709a568724a0aff90f8f347f43b02338f94a03ed32e6f33666ff5802da4c81bdce0d0e86c04afd4edc2fc8b4141c2975b6f07639b1994c973d9a9afce3d9d365862003498513bfa166d2629e314d97441667b007414e739d7febf0fe3c32c17aa188a8683",
"effb03b497add6230a0ed99122ea868138644ab81e861491e526fae37c39872ca731804a0004599849478a787bc7fce21903ed551d7db881d2a2c367b6168547");
testKatHex(new Keccak512(),
"f31e8b4f9e0621d531d22a380be5d9abd56faec53cbd39b1fab230ea67184440e5b1d15457bd25f56204fa917fa48e669016cb48c1ffc1e1e45274b3b47379e00a43843cf8601a5551411ec12503e5aac43d8676a1b2297ec7a0800dbfee04292e937f21c005f17411473041",
"a2269a6ef2ea8f1cf8bc3394d27657b0db996c55e7c47784c0b451202fc5279679d79e06f8dbaa9a63665fd0e914d13c6e056ea006daaf4cb61d2629468e3d25");
testKatHex(new Keccak512(),
"758ea3fea738973db0b8be7e599bbef4519373d6e6dcd7195ea885fc991d896762992759c2a09002912fb08e0cb5b76f49162aeb8cf87b172cf3ad190253df612f77b1f0c532e3b5fc99c2d31f8f65011695a087a35ee4eee5e334c369d8ee5d29f695815d866da99df3f79403",
"5a2970d5ec346a8e4e1d5d1e57dc22f6875ddf1ce3626b49a91109e0de991033e932f883b6a795016d5014e268304abe2f7577505aab00956911781f075d113a");
testKatHex(new Keccak512(),
"47c6e0c2b74948465921868804f0f7bd50dd323583dc784f998a93cd1ca4c6ef84d41dc81c2c40f34b5bee6a93867b3bdba0052c5f59e6f3657918c382e771d33109122cc8bb0e1e53c4e3d13b43ce44970f5e0c079d2ad7d7a3549cd75760c21bb15b447589e86e8d76b1e9ced2",
"2b4356a64df31936b27f4530f076ee73e71e4e48abde04ff1f548e0727f4a5810b71874187fd96ed510d0d6886af11960a0b3bad1ee75dda4cdc148e162edae9");
testKatHex(new Keccak512(),
"f690a132ab46b28edfa6479283d6444e371c6459108afd9c35dbd235e0b6b6ff4c4ea58e7554bd002460433b2164ca51e868f7947d7d7a0d792e4abf0be5f450853cc40d85485b2b8857ea31b5ea6e4ccfa2f3a7ef3380066d7d8979fdac618aad3d7e886dea4f005ae4ad05e5065f",
"edcb59984267bb00402a78f2ca345ef2494956172e10927ee63aff23d0c834bca50c47cdbffd8995036307e9ed4b143e853450367d0e14afc8490073653cd850");
testKatHex(new Keccak512(),
"58d6a99bc6458824b256916770a8417040721cccfd4b79eacd8b65a3767ce5ba7e74104c985ac56b8cc9aebd16febd4cda5adb130b0ff2329cc8d611eb14dac268a2f9e633c99de33997fea41c52a7c5e1317d5b5daed35eba7d5a60e45d1fa7eaabc35f5c2b0a0f2379231953322c4e",
"d0b453fbe709c69125dc8fe9e8ae9245211612970373b454f8656a755e8435b321dd3a980fa28719641747e254dc42c9bf012b4d6dbd7ed13020a83b44c504aa");
testKatHex(new Keccak512(),
"befab574396d7f8b6705e2d5b58b2c1c820bb24e3f4bae3e8fbcd36dbf734ee14e5d6ab972aedd3540235466e825850ee4c512ea9795abfd33f330d9fd7f79e62bbb63a6ea85de15beaeea6f8d204a28956059e2632d11861dfb0e65bc07ac8a159388d5c3277e227286f65ff5e5b5aec1",
"fe97c011e525110e03149fac4179891afcb6304e1cfd9d84cb7389755554ee723571d76b80b9333a695884192340b3fe022d4a233b7aa8e8c7686745cfe75e67");
testKatHex(new Keccak512(),
"8e58144fa9179d686478622ce450c748260c95d1ba43b8f9b59abeca8d93488da73463ef40198b4d16fb0b0707201347e0506ff19d01bea0f42b8af9e71a1f1bd168781069d4d338fdef00bf419fbb003031df671f4a37979564f69282de9c65407847dd0da505ab1641c02dea4f0d834986",
"1bc4ac8d979ca62a7fc81c710cedf65af56c9b652eec356aa92da924d370fdebdf076f91ba4fe1ec5cd78fc4c8885ea4304ba2e8e64944ab4bf4d1b3d7dee745");
testKatHex(new Keccak512(),
"b55c10eae0ec684c16d13463f29291bf26c82e2fa0422a99c71db4af14dd9c7f33eda52fd73d017cc0f2dbe734d831f0d820d06d5f89dacc485739144f8cfd4799223b1aff9031a105cb6a029ba71e6e5867d85a554991c38df3c9ef8c1e1e9a7630be61caabca69280c399c1fb7a12d12aefc",
"76e970e9449d868067cd23b1a202cbdc99693ff6fa74ba644ec41cbf8fd139cb0f5d1106fcd6c871c315ff41c3eaf99c636288f0fcf6a40b480cb881d87e098f");
testKatHex(new Keccak512(),
"2eeea693f585f4ed6f6f8865bbae47a6908aecd7c429e4bec4f0de1d0ca0183fa201a0cb14a529b7d7ac0e6ff6607a3243ee9fb11bcf3e2304fe75ffcddd6c5c2e2a4cd45f63c962d010645058d36571404a6d2b4f44755434d76998e83409c3205aa1615db44057db991231d2cb42624574f545",
"871666b230c5ad75b96d63be22870621c68fd0899655ba7dc0e0e5299915af252c226dd7217601d3a6880d55ee5a20b10820e21c74f730eea9d47fe26debe006");
testKatHex(new Keccak512(),
"dab11dc0b047db0420a585f56c42d93175562852428499f66a0db811fcdddab2f7cdffed1543e5fb72110b64686bc7b6887a538ad44c050f1e42631bc4ec8a9f2a047163d822a38989ee4aab01b4c1f161b062d873b1cfa388fd301514f62224157b9bef423c7783b7aac8d30d65cd1bba8d689c2d",
"7e3ef62552b28a2b18a71ceef2dd8659c8bdf291385ad02fed353775e01594f27cc28cc78663e17cb8b39fd4ea48d494ad0bd7aee9277ec9b21e46523812736e");
testKatHex(new Keccak512(),
"42e99a2f80aee0e001279a2434f731e01d34a44b1a8101726921c0590c30f3120eb83059f325e894a5ac959dca71ce2214799916424e859d27d789437b9d27240bf8c35adbafcecc322b48aa205b293962d858652abacbd588bcf6cbc388d0993bd622f96ed54614c25b6a9aa527589eaaffcf17ddf7",
"0b87f6ebaa293ff79c873820846c0fcc943e3a83bd8111931ff03ff3b0bf785c961ca84cf3fd40e0d831dbaea595498fc12da88cc507de720a35c01d73fc9595");
testKatHex(new Keccak512(),
"3c9b46450c0f2cae8e3823f8bdb4277f31b744ce2eb17054bddc6dff36af7f49fb8a2320cc3bdf8e0a2ea29ad3a55de1165d219adeddb5175253e2d1489e9b6fdd02e2c3d3a4b54d60e3a47334c37913c5695378a669e9b72dec32af5434f93f46176ebf044c4784467c700470d0c0b40c8a088c815816",
"681babbd2e351501c285812e06f20940fd865516cf028b4787d1ffccd0d537705e8e9b73c608d5a8dc4f08eee0902ac12936ddb8c7b29228c6aaf8d0b909c30d");
testKatHex(new Keccak512(),
"d1e654b77cb155f5c77971a64df9e5d34c26a3cad6c7f6b300d39deb1910094691adaa095be4ba5d86690a976428635d5526f3e946f7dc3bd4dbc78999e653441187a81f9adcd5a3c5f254bc8256b0158f54673dcc1232f6e918ebfc6c51ce67eaeb042d9f57eec4bfe910e169af78b3de48d137df4f2840",
"c46d2262f186421d07fd740f922306d99b1e3826f6a32486be5a91dc298f177f50915e17eb4ea2e45494c501736cefb0e22acd989da41ac7bb7be56b04bfb5e1");
testKatHex(new Keccak512(),
"626f68c18a69a6590159a9c46be03d5965698f2dac3de779b878b3d9c421e0f21b955a16c715c1ec1e22ce3eb645b8b4f263f60660ea3028981eebd6c8c3a367285b691c8ee56944a7cd1217997e1d9c21620b536bdbd5de8925ff71dec6fbc06624ab6b21e329813de90d1e572dfb89a18120c3f606355d25",
"0b3dbc770332823e686470d842104d3b3c1452f64f1bcc71c5f3fad1c0d93f21efbd48d73c7d4909227b06b06d54057a74e03c36d9c106eba79411f1e6e1cffe");
testKatHex(new Keccak512(),
"651a6fb3c4b80c7c68c6011675e6094eb56abf5fc3057324ebc6477825061f9f27e7a94633abd1fa598a746e4a577caf524c52ec1788471f92b8c37f23795ca19d559d446cab16cbcdce90b79fa1026cee77bf4ab1b503c5b94c2256ad75b3eac6fd5dcb96aca4b03a834bfb4e9af988cecbf2ae597cb9097940",
"ca46276b0dc2ec4424bb7136eae1af207bd6e5cd833691c7d37b2caeaf4f484b96a3476fc25feb206ad37cf975383dd522ca0cc6200a3867fee7f178d6953fef");
testKatHex(new Keccak512(),
"8aaf072fce8a2d96bc10b3c91c809ee93072fb205ca7f10abd82ecd82cf040b1bc49ea13d1857815c0e99781de3adbb5443ce1c897e55188ceaf221aa9681638de05ae1b322938f46bce51543b57ecdb4c266272259d1798de13be90e10efec2d07484d9b21a3870e2aa9e06c21aa2d0c9cf420080a80a91dee16f",
"815b44668bf3751a3392940fca54c1e3e4ef5227b052332afe6eb7a10ac8ad6438ce8a0277aa14bcc41590f6d6a10b6b1babe6bb4f8d777ea576d634b0be41c0");
testKatHex(new Keccak512(),
"53f918fd00b1701bd504f8cdea803acca21ac18c564ab90c2a17da592c7d69688f6580575395551e8cd33e0fef08ca6ed4588d4d140b3e44c032355df1c531564d7f4835753344345a6781e11cd5e095b73df5f82c8ae3ad00877936896671e947cc52e2b29dcd463d90a0c9929128da222b5a211450bbc0e02448e2",
"f47799a8547fc9c07d0f808029e7335607d72224be286e118657bd13a2c51d0374426d9eeb7693bde5ec6181574c1404df29bf96941862ba1a0a9a5903319498");
testKatHex(new Keccak512(),
"a64599b8a61b5ccec9e67aed69447459c8da3d1ec6c7c7c82a7428b9b584fa67e90f68e2c00fbbed4613666e5168da4a16f395f7a3c3832b3b134bfc9cbaa95d2a0fe252f44ac6681eb6d40ab91c1d0282fed6701c57463d3c5f2bb8c6a7301fb4576aa3b5f15510db8956ff77478c26a7c09bea7b398cfc83503f538e",
"8a0ae12a9e797fb7bd46cbb910076a32873bffcb9ad98b4fc37316aed681ec49c65abbb9586405ff96cc80da4bb8fa73be1ba9e737595b2307cf369d61baf59c");
testKatHex(new Keccak512(),
"0e3ab0e054739b00cdb6a87bd12cae024b54cb5e550e6c425360c2e87e59401f5ec24ef0314855f0f56c47695d56a7fb1417693af2a1ed5291f2fee95f75eed54a1b1c2e81226fbff6f63ade584911c71967a8eb70933bc3f5d15bc91b5c2644d9516d3c3a8c154ee48e118bd1442c043c7a0dba5ac5b1d5360aae5b9065",
"a3c6d58872bafdedfdd50c0309089240d6977d4d3d59fb3f2be133c57d2dfcfcc7c027296f74fe58b2a9a6cb7e5d70088934d051cba57001fe27965cfa071a6f");
testKatHex(new Keccak512(),
"a62fc595b4096e6336e53fcdfc8d1cc175d71dac9d750a6133d23199eaac288207944cea6b16d27631915b4619f743da2e30a0c00bbdb1bbb35ab852ef3b9aec6b0a8dcc6e9e1abaa3ad62ac0a6c5de765de2c3711b769e3fde44a74016fff82ac46fa8f1797d3b2a726b696e3dea5530439acee3a45c2a51bc32dd055650b",
"11e0e521b55f02befc7207c06444fcc0c16dcf6f34962921b709a322f35e2193477b0dfa21f213f209705ff3958531a75d94346075feb29a288b62e2315ae270");
testKatHex(new Keccak512(),
"2b6db7ced8665ebe9deb080295218426bdaa7c6da9add2088932cdffbaa1c14129bccdd70f369efb149285858d2b1d155d14de2fdb680a8b027284055182a0cae275234cc9c92863c1b4ab66f304cf0621cd54565f5bff461d3b461bd40df28198e3732501b4860eadd503d26d6e69338f4e0456e9e9baf3d827ae685fb1d817",
"aebba57c8ed5af6ec93f4aa45772ff5167b7ea88dfa71364f37d8fc5fdb7dc3b2c8331a08023f21d110b7d821e2dc7e860826235e7e6291912ac521384747354");
testKatHex(new Keccak512(),
"10db509b2cdcaba6c062ae33be48116a29eb18e390e1bbada5ca0a2718afbcd23431440106594893043cc7f2625281bf7de2655880966a23705f0c5155c2f5cca9f2c2142e96d0a2e763b70686cd421b5db812daced0c6d65035fde558e94f26b3e6dde5bd13980cc80292b723013bd033284584bff27657871b0cf07a849f4ae2",
"2df1e09540b53a17222dab66275cebeceb1f8a5db26b0c41f955fa0549f3367e82299e0cd673958af7dfa04d741aa63ba2c1ad351764dc9228d215f22c24ca58");
testKatHex(new Keccak512(),
"9334de60c997bda6086101a6314f64e4458f5ff9450c509df006e8c547983c651ca97879175aaba0c539e82d05c1e02c480975cbb30118121061b1ebac4f8d9a3781e2db6b18042e01ecf9017a64a0e57447ec7fcbe6a7f82585f7403ee2223d52d37b4bf426428613d6b4257980972a0acab508a7620c1cb28eb4e9d30fc41361ec",
"8299cfcea5f00c93a5eb8a84a13628a68b26796d53fb6a986c95b0b1c248920fb946d8af98343d14efc74a4611c53ccc27c5f14c7237af28364346ca5cd70d1a");
testKatHex(new Keccak512(),
"e88ab086891693aa535ceb20e64c7ab97c7dd3548f3786339897a5f0c39031549ca870166e477743ccfbe016b4428d89738e426f5ffe81626137f17aecff61b72dbee2dc20961880cfe281dfab5ee38b1921881450e16032de5e4d55ad8d4fca609721b0692bac79be5a06e177fe8c80c0c83519fb3347de9f43d5561cb8107b9b5edc",
"af57bea357fcba0579c4204c0f8dff181bc8a473014bae78df76069de478b2f2a390327a65bdd24be926551c78f70b0d5f1c8f4b970997d557f06336a315a749");
testKatHex(new Keccak512(),
"fd19e01a83eb6ec810b94582cb8fbfa2fcb992b53684fb748d2264f020d3b960cb1d6b8c348c2b54a9fcea72330c2aaa9a24ecdb00c436abc702361a82bb8828b85369b8c72ece0082fe06557163899c2a0efa466c33c04343a839417057399a63a3929be1ee4805d6ce3e5d0d0967fe9004696a5663f4cac9179006a2ceb75542d75d68",
"b299e421061ef26c32bb4f50ee669d05feb2ccba3297289c30e6434057b3ea7f617bbbf7a5555328fc291f794987577f458350df99af3a5778300be0bd80164f");
testKatHex(new Keccak512(),
"59ae20b6f7e0b3c7a989afb28324a40fca25d8651cf1f46ae383ef6d8441587aa1c04c3e3bf88e8131ce6145cfb8973d961e8432b202fa5af3e09d625faad825bc19da9b5c6c20d02abda2fcc58b5bd3fe507bf201263f30543819510c12bc23e2ddb4f711d087a86edb1b355313363a2de996b891025e147036087401ccf3ca7815bf3c49",
"cbdfb0d0e720f87259dd0d0b4e9c5319e7f88aaef7f7ab2fa1ca639afa0160822f96b3c357a4894ce53cd713fab23ad052e8565fa3b3a523cb9ce39a6bd535cc");
testKatHex(new Keccak512(),
"77ee804b9f3295ab2362798b72b0a1b2d3291dceb8139896355830f34b3b328561531f8079b79a6e9980705150866402fdc176c05897e359a6cb1a7ab067383eb497182a7e5aef7038e4c96d133b2782917417e391535b5e1b51f47d8ed7e4d4025fe98dc87b9c1622614bff3d1029e68e372de719803857ca52067cddaad958951cb2068cc6",
"059a181c83a22bff0aa9baa22d872bdf23cbe341032cf0bf57997a4a1924d24fbae9dca14b6d290692b6a6b6344cbe531734f58ad0224c6e39bd1e87f870aad6");
testKatHex(new Keccak512(),
"b771d5cef5d1a41a93d15643d7181d2a2ef0a8e84d91812f20ed21f147bef732bf3a60ef4067c3734b85bc8cd471780f10dc9e8291b58339a677b960218f71e793f2797aea349406512829065d37bb55ea796fa4f56fd8896b49b2cd19b43215ad967c712b24e5032d065232e02c127409d2ed4146b9d75d763d52db98d949d3b0fed6a8052fbb",
"9edeeb10ee1b7bb8f16a280d8cc3eda5e909c554419ddc523b69ecedf2adf3b3c9bc66fef365342471c458126f083a3b8e7c0c9d9d77e9f90196b71f9aadf492");
testKatHex(new Keccak512(),
"b32d95b0b9aad2a8816de6d06d1f86008505bd8c14124f6e9a163b5a2ade55f835d0ec3880ef50700d3b25e42cc0af050ccd1be5e555b23087e04d7bf9813622780c7313a1954f8740b6ee2d3f71f768dd417f520482bd3a08d4f222b4ee9dbd015447b33507dd50f3ab4247c5de9a8abd62a8decea01e3b87c8b927f5b08beb37674c6f8e380c04",
"a6054ffc3d81591be964c4b004a3a21142365b59ee98b2873d488293f93a8d7154bf72100012c60d3c9418f6af8ea66372cb4703f5f6381de6d4b9b98cff1e90");
testKatHex(new Keccak512(),
"04410e31082a47584b406f051398a6abe74e4da59bb6f85e6b49e8a1f7f2ca00dfba5462c2cd2bfde8b64fb21d70c083f11318b56a52d03b81cac5eec29eb31bd0078b6156786da3d6d8c33098c5c47bb67ac64db14165af65b44544d806dde5f487d5373c7f9792c299e9686b7e5821e7c8e2458315b996b5677d926dac57b3f22da873c601016a0d",
"b0e54a12fdba0738898f1bbf0ba81f81de77648d8d14c20bdd5d90f300d382e069f5dba7eec6b23168b008b9f39c2b93fd742a5902a5e02728f57712d6a61d4e");
testKatHex(new Keccak512(),
"8b81e9badde026f14d95c019977024c9e13db7a5cd21f9e9fc491d716164bbacdc7060d882615d411438aea056c340cdf977788f6e17d118de55026855f93270472d1fd18b9e7e812bae107e0dfde7063301b71f6cfe4e225cab3b232905a56e994f08ee2891ba922d49c3dafeb75f7c69750cb67d822c96176c46bd8a29f1701373fb09a1a6e3c7158f",
"3ce96077eb17c6a9c95a9a477748876c6451098dbea2b3261e6d75b64a988e1c75d7eac73bc2402afc726543e2a5bdb76689c0931ff762818dd2d3fe57a50fa9");
testKatHex(new Keccak512(),
"fa6eed24da6666a22208146b19a532c2ec9ba94f09f1def1e7fc13c399a48e41acc2a589d099276296348f396253b57cb0e40291bd282773656b6e0d8bea1cda084a3738816a840485fcf3fb307f777fa5feac48695c2af4769720258c77943fb4556c362d9cba8bf103aeb9034baa8ea8bfb9c4f8e6742ce0d52c49ea8e974f339612e830e9e7a9c29065",
"c9acd6d98a349512b952d151ed501562f04ea4bb4b8965812510b9b842531a2b41a0108ac129cf9c9517be790921df64ad1dfc0b93ddba3415eebaf0da72f6a0");
testKatHex(new Keccak512(),
"9bb4af1b4f09c071ce3cafa92e4eb73ce8a6f5d82a85733440368dee4eb1cbc7b55ac150773b6fe47dbe036c45582ed67e23f4c74585dab509df1b83610564545642b2b1ec463e18048fc23477c6b2aa035594ecd33791af6af4cbc2a1166aba8d628c57e707f0b0e8707caf91cd44bdb915e0296e0190d56d33d8dde10b5b60377838973c1d943c22ed335e",
"26b4e5c4fa85cb33359450e7f7158fb6a0739984565e9d9ebe6ad65b118296e9c1098c11541c871eb1b89853f1fa73ad8702ebf4fc9be4d0ab057e4391df964e");
testKatHex(new Keccak512(),
"2167f02118cc62043e9091a647cadbed95611a521fe0d64e8518f16c808ab297725598ae296880a773607a798f7c3cfce80d251ebec6885015f9abf7eaabae46798f82cb5926de5c23f44a3f9f9534b3c6f405b5364c2f8a8bdc5ca49c749bed8ce4ba48897062ae8424ca6dde5f55c0e42a95d1e292ca54fb46a84fbc9cd87f2d0c9e7448de3043ae22fdd229",
"913bba5c0c13cc49d8310014cf5af1b63ba3d5db8a27699fcfc573688f0e826fb5a7b5d10d3a1de693aa66e08c0915e7278f61b5fa30f1263b134f016f74841f");
testKatHex(new Keccak512(),
"94b7fa0bc1c44e949b1d7617d31b4720cbe7ca57c6fa4f4094d4761567e389ecc64f6968e4064df70df836a47d0c713336b5028b35930d29eb7a7f9a5af9ad5cf441745baec9bb014ceeff5a41ba5c1ce085feb980bab9cf79f2158e03ef7e63e29c38d7816a84d4f71e0f548b7fc316085ae38a060ff9b8dec36f91ad9ebc0a5b6c338cbb8f6659d342a24368cf",
"e5d53e81866283179012d9239340b0cbfb8d7aebce0c824dc6653a652bb1b54e0883991be2c3e39ad111a7b24e95daf6f7d9a379d884d64f9c2afd645e1db5e2");
testKatHex(new Keccak512(),
"ea40e83cb18b3a242c1ecc6ccd0b7853a439dab2c569cfc6dc38a19f5c90acbf76aef9ea3742ff3b54ef7d36eb7ce4ff1c9ab3bc119cff6be93c03e208783335c0ab8137be5b10cdc66ff3f89a1bddc6a1eed74f504cbe7290690bb295a872b9e3fe2cee9e6c67c41db8efd7d863cf10f840fe618e7936da3dca5ca6df933f24f6954ba0801a1294cd8d7e66dfafec",
"5da83b7e221933cd67fa2af8c9934db74ce822212c99e0ee01f5220b4fe1e9b0388e42e328a1d174e6368f5773853042543a9b493a94b625980b73df3f3fccbb");
testKatHex(new Keccak512(),
"157d5b7e4507f66d9a267476d33831e7bb768d4d04cc3438da12f9010263ea5fcafbde2579db2f6b58f911d593d5f79fb05fe3596e3fa80ff2f761d1b0e57080055c118c53e53cdb63055261d7c9b2b39bd90acc32520cbbdbda2c4fd8856dbcee173132a2679198daf83007a9b5c51511ae49766c792a29520388444ebefe28256fb33d4260439cba73a9479ee00c63",
"72de9184beb5c6a37ea2c395734d0d5412991a57cffcc13ff9b5fa0f2046ee87c61811fe8ef2470239d5066c220173de5ebe41885ed8acae397fb395e6ca9aee");
testKatHex(new Keccak512(),
"836b34b515476f613fe447a4e0c3f3b8f20910ac89a3977055c960d2d5d2b72bd8acc715a9035321b86703a411dde0466d58a59769672aa60ad587b8481de4bba552a1645779789501ec53d540b904821f32b0bd1855b04e4848f9f8cfe9ebd8911be95781a759d7ad9724a7102dbe576776b7c632bc39b9b5e19057e226552a5994c1dbb3b5c7871a11f5537011044c53",
"b678fa7655584970dedbbc73a16d7840935b104d06dcb468ddd9814d6cf443fa6f9245824dbff3ab5fffef24b29cb2978796f37e7b49b1682d59f79e3c169e81");
testKatHex(new Keccak512(),
"cc7784a4912a7ab5ad3620aab29ba87077cd3cb83636adc9f3dc94f51edf521b2161ef108f21a0a298557981c0e53ce6ced45bdf782c1ef200d29bab81dd6460586964edab7cebdbbec75fd7925060f7da2b853b2b089588fa0f8c16ec6498b14c55dcee335cb3a91d698e4d393ab8e8eac0825f8adebeee196df41205c011674e53426caa453f8de1cbb57932b0b741d4c6",
"66c64d5b0585dd8c40becd456e4b0188061ae8059f03e79fe04c40925442ba93b052f52087b30bdbfd4816bbd148696d4fa6c61f216253d7ac178b39ec44c770");
testKatHex(new Keccak512(),
"7639b461fff270b2455ac1d1afce782944aea5e9087eb4a39eb96bb5c3baaf0e868c8526d3404f9405e79e77bfac5ffb89bf1957b523e17d341d7323c302ea7083872dd5e8705694acdda36d5a1b895aaa16eca6104c82688532c8bfe1790b5dc9f4ec5fe95baed37e1d287be710431f1e5e8ee105bc42ed37d74b1e55984bf1c09fe6a1fa13ef3b96faeaed6a2a1950a12153",
"a7bd506db9c0509ad47413af4b0e3948b47c18278f15f5b19fbb0b76e2c1c1f19db9438528eb6d87b0b4a509567db39f32641e2944365780914296cf3e48cecf");
testKatHex(new Keccak512(),
"eb6513fc61b30cfba58d4d7e80f94d14589090cf1d80b1df2e68088dc6104959ba0d583d585e9578ab0aec0cf36c48435eb52ed9ab4bbce7a5abe679c97ae2dbe35e8cc1d45b06dda3cf418665c57cbee4bbb47fa4caf78f4ee656fec237fe4eebbafa206e1ef2bd0ee4ae71bd0e9b2f54f91daadf1febfd7032381d636b733dcb3bf76fb14e23aff1f68ed3dbcf75c9b99c6f26",
"2e681f9ddbd7c77eab0d225e2ad1f72256be239df25933bcd6cedd757269b35e2a5352b3298a4cda0542ff7d3add2b0cf42f10fbe05a67c8763d54a78a43aea7");
testKatHex(new Keccak512(),
"1594d74bf5dde444265d4c04dad9721ff3e34cbf622daf341fe16b96431f6c4df1f760d34f296eb97d98d560ad5286fec4dce1724f20b54fd7df51d4bf137add656c80546fb1bf516d62ee82baa992910ef4cc18b70f3f8698276fcfb44e0ec546c2c39cfd8ee91034ff9303058b4252462f86c823eb15bf481e6b79cc3a02218595b3658e8b37382bd5048eaed5fd02c37944e73b",
"fd9be24763f682043243525e5e0780534a82ad5e83b65eb4acaf5353313a4cc7c5eea9da141de570232cb4126287e5c77657ca8d6a16b5be53f470343e722fd6");
testKatHex(new Keccak512(),
"4cfa1278903026f66fedd41374558be1b585d03c5c55dac94361df286d4bd39c7cb8037ed3b267b07c346626449d0cc5b0dd2cf221f7e4c3449a4be99985d2d5e67bff2923357ddeab5abcb4619f3a3a57b2cf928a022eb27676c6cf805689004fca4d41ea6c2d0a4789c7605f7bb838dd883b3ad3e6027e775bcf262881428099c7fff95b14c095ea130e0b9938a5e22fc52650f591",
"14ea33bb33fdf0426e0dfb12de1c613ba97141454c8971bcce25c6d87a6c2403ccfad1e8a6c15754c3cc5ac1718b7f7f1ec003c1b98d70968c5dbb95540b4a17");
testKatHex(new Keccak512(),
"d3e65cb92cfa79662f6af493d696a07ccf32aaadcceff06e73e8d9f6f909209e66715d6e978788c49efb9087b170ecf3aa86d2d4d1a065ae0efc8924f365d676b3cb9e2bec918fd96d0b43dee83727c9a93bf56ca2b2e59adba85696546a815067fc7a78039629d4948d157e7b0d826d1bf8e81237bab7321312fdaa4d521744f988db6fdf04549d0fdca393d639c729af716e9c8bba48",
"3b4b395514e0cab04fc9f9d6c358006ce06c93831e8948fb9bd2a863f3fa064e78eb57c76dd2d058d09ab3d105c28c2dacaebd4a473f1fa023053cc15366082f");
testKatHex(new Keccak512(),
"842cc583504539622d7f71e7e31863a2b885c56a0ba62db4c2a3f2fd12e79660dc7205ca29a0dc0a87db4dc62ee47a41db36b9ddb3293b9ac4baae7df5c6e7201e17f717ab56e12cad476be49608ad2d50309e7d48d2d8de4fa58ac3cfeafeee48c0a9eec88498e3efc51f54d300d828dddccb9d0b06dd021a29cf5cb5b2506915beb8a11998b8b886e0f9b7a80e97d91a7d01270f9a7717",
"2d7d28c4311e0424d71e7f9d267a2e048aa175455fcb724cf0b13debf448b59b0f28265b0f010f4e4f4065004904a7c2687a5a1b30ab593bc44f698dff5dde33");
testKatHex(new Keccak512(),
"6c4b0a0719573e57248661e98febe326571f9a1ca813d3638531ae28b4860f23c3a3a8ac1c250034a660e2d71e16d3acc4bf9ce215c6f15b1c0fc7e77d3d27157e66da9ceec9258f8f2bf9e02b4ac93793dd6e29e307ede3695a0df63cbdc0fc66fb770813eb149ca2a916911bee4902c47c7802e69e405fe3c04ceb5522792a5503fa829f707272226621f7c488a7698c0d69aa561be9f378",
"cb665ec69abd75743c8713034e9e41736f8c1ce2c77a8518e50388c411e6284d9aadcd4d3bd5a9eb74672325e41e8a67acf380d1e8a61684f0e501f5663a031d");
testKatHex(new Keccak512(),
"51b7dbb7ce2ffeb427a91ccfe5218fd40f9e0b7e24756d4c47cd55606008bdc27d16400933906fd9f30effdd4880022d081155342af3fb6cd53672ab7fb5b3a3bcbe47be1fd3a2278cae8a5fd61c1433f7d350675dd21803746cadca574130f01200024c6340ab0cc2cf74f2234669f34e9009ef2eb94823d62b31407f4ba46f1a1eec41641e84d77727b59e746b8a671bef936f05be820759fa",
"4515a104fc68094d244b234d9dc06a0243b71d419d29a95c46e3cba6f51e121abe049b34535db3ccbf2ad68d83fc36331f615b3e33deb39a3381dfbcb798fe4d");
testKatHex(new Keccak512(),
"83599d93f5561e821bd01a472386bc2ff4efbd4aed60d5821e84aae74d8071029810f5e286f8f17651cd27da07b1eb4382f754cd1c95268783ad09220f5502840370d494beb17124220f6afce91ec8a0f55231f9652433e5ce3489b727716cf4aeba7dcda20cd29aa9a859201253f948dd94395aba9e3852bd1d60dda7ae5dc045b283da006e1cbad83cc13292a315db5553305c628dd091146597",
"cee3e60a49f7caed9387f3ea699524c4ccafd37c1a7e60d2f0ab037720649f108cce8769f70b0c5d049359eeb821022f17c4b5f646b750e3070558ec127057f1");
testKatHex(new Keccak512(),
"2be9bf526c9d5a75d565dd11ef63b979d068659c7f026c08bea4af161d85a462d80e45040e91f4165c074c43ac661380311a8cbed59cc8e4c4518e80cd2c78ab1cabf66bff83eab3a80148550307310950d034a6286c93a1ece8929e6385c5e3bb6ea8a7c0fb6d6332e320e71cc4eb462a2a62e2bfe08f0ccad93e61bedb5dd0b786a728ab666f07e0576d189c92bf9fb20dca49ac2d3956d47385e2",
"e6ed6f060906d1a772f47e83907507f88a151de401ed79acb56be57c2596792dc0bc5a9dc1045e37c6a31da1c36200214e4f5698aa2754eeb2caecfc03bec39d");
testKatHex(new Keccak512(),
"ca76d3a12595a817682617006848675547d3e8f50c2210f9af906c0e7ce50b4460186fe70457a9e879e79fd4d1a688c70a347361c847ba0dd6aa52936eaf8e58a1be2f5c1c704e20146d366aeb3853bed9de9befe9569ac8aaea37a9fb7139a1a1a7d5c748605a8defb297869ebedd71d615a5da23496d11e11abbb126b206fa0a7797ee7de117986012d0362dcef775c2fe145ada6bda1ccb326bf644",
"9ed4eee87f56ae2741e8e4d65623e4d1fa3aa111f64a85f66e99093baed990fe1d788d6a4be1a72a6615281eb45e1b6fb60afefdd93987f794084bda962fac7f");
testKatHex(new Keccak512(),
"f76b85dc67421025d64e93096d1d712b7baf7fb001716f02d33b2160c2c882c310ef13a576b1c2d30ef8f78ef8d2f465007109aad93f74cb9e7d7bef7c9590e8af3b267c89c15db238138c45833c98cc4a471a7802723ef4c744a853cf80a0c2568dd4ed58a2c9644806f42104cee53628e5bdf7b63b0b338e931e31b87c24b146c6d040605567ceef5960df9e022cb469d4c787f4cba3c544a1ac91f95f",
"23139bdd84e9f43a6cc615f0f036199328d39807bec9e786d4251b83b30800f9dbe8edc0b910fcd9d9f204c2ddd4d3b92bc26a0cfaabe764bfb90a1444733cd0");
testKatHex(new Keccak512(),
"25b8c9c032ea6bcd733ffc8718fbb2a503a4ea8f71dea1176189f694304f0ff68e862a8197b839957549ef243a5279fc2646bd4c009b6d1edebf24738197abb4c992f6b1dc9ba891f570879accd5a6b18691a93c7d0a8d38f95b639c1daeb48c4c2f15ccf5b9d508f8333c32de78781b41850f261b855c4bebcc125a380c54d501c5d3bd07e6b52102116088e53d76583b0161e2a58d0778f091206aabd5a1",
"ec69397000aed63cb7e86b4fb0bfd3dcee8a6f6a1cfe01a324da13484b73599fcd37ad392662d4c41d90baca66be4d6e3424efd35d7ff4cb07cbdfbebddb7b50");
testKatHex(new Keccak512(),
"21cfdc2a7ccb7f331b3d2eefff37e48ad9fa9c788c3f3c200e0173d99963e1cbca93623b264e920394ae48bb4c3a5bb96ffbc8f0e53f30e22956adabc2765f57fb761e147ecbf8567533db6e50c8a1f894310a94edf806dd8ca6a0e141c0fa7c9fae6c6ae65f18c93a8529e6e5b553bf55f25be2e80a9882bd37f145fecbeb3d447a3c4e46c21524cc55cdd62f521ab92a8ba72b897996c49bb273198b7b1c9e",
"2ea3ea00e6e9305ced0fc160e004265221306a2be9613474126825aa3c3170ae07e5ea42f6b74f0b2c1bd2a6cd4d26eb1e04c67c9a4afefc1dd0cb57c2a9f4c7");
testKatHex(new Keccak512(),
"4e452ba42127dcc956ef4f8f35dd68cb225fb73b5bc7e1ec5a898bba2931563e74faff3b67314f241ec49f4a7061e3bd0213ae826bab380f1f14faab8b0efddd5fd1bb49373853a08f30553d5a55ccbbb8153de4704f29ca2bdeef0419468e05dd51557ccc80c0a96190bbcc4d77ecff21c66bdf486459d427f986410f883a80a5bcc32c20f0478bb9a97a126fc5f95451e40f292a4614930d054c851acd019ccf",
"6a7addb28f4f2c23cf0c264579fba5f892e010689f837b84d006d91402fbfe9ba44b9126f8b5de1ec6bbe194a3e3854235056a09901d18e8d6f1727dd430212a");
testKatHex(new Keccak512(),
"fa85671df7dadf99a6ffee97a3ab9991671f5629195049880497487867a6c446b60087fac9a0f2fcc8e3b24e97e42345b93b5f7d3691829d3f8ccd4bb36411b85fc2328eb0c51cb3151f70860ad3246ce0623a8dc8b3c49f958f8690f8e3860e71eb2b1479a5cea0b3f8befd87acaf5362435eaeccb52f38617bc6c5c2c6e269ead1fbd69e941d4ad2012da2c5b21bcfbf98e4a77ab2af1f3fda3233f046d38f1dc8",
"2c0ee8a165bf88c44c8601c6372e522da9ecf42544dcdc098698f50df8e70eb7440cab2953bb490cd2a5e0887beeae3482192da95e5098d3b318f16fc08d1e1e");
testKatHex(new Keccak512(),
"e90847ae6797fbc0b6b36d6e588c0a743d725788ca50b6d792352ea8294f5ba654a15366b8e1b288d84f5178240827975a763bc45c7b0430e8a559df4488505e009c63da994f1403f407958203cebb6e37d89c94a5eacf6039a327f6c4dbbc7a2a307d976aa39e41af6537243fc218dfa6ab4dd817b6a397df5ca69107a9198799ed248641b63b42cb4c29bfdd7975ac96edfc274ac562d0474c60347a078ce4c25e88",
"ddd4ff117231eca0445eada7c7f1d84686520daa70e160c87dbbb3fb32bb9e2f4cc53db5413d4e88de18a0118570318bd6d0e5264d779339ac6f4f4a95546a53");
testKatHex(new Keccak512(),
"f6d5c2b6c93954fc627602c00c4ca9a7d3ed12b27173f0b2c9b0e4a5939398a665e67e69d0b12fb7e4ceb253e8083d1ceb724ac07f009f094e42f2d6f2129489e846eaff0700a8d4453ef453a3eddc18f408c77a83275617fabc4ea3a2833aa73406c0e966276079d38e8e38539a70e194cc5513aaa457c699383fd1900b1e72bdfb835d1fd321b37ba80549b078a49ea08152869a918ca57f5b54ed71e4fd3ac5c06729",
"a9744efa42887df292fc09dfeb885f1e801855ded09dc2f97cbfcbd019751878619da1bc9573201c7cc050e2aa1d453e951366d81c188d329b3cb861c1d78f92");
testKatHex(new Keccak512(),
"cf8562b1bed89892d67ddaaf3deeb28246456e972326dbcdb5cf3fb289aca01e68da5d59896e3a6165358b071b304d6ab3d018944be5049d5e0e2bb819acf67a6006111089e6767132d72dd85beddcbb2d64496db0cc92955ab4c6234f1eea24f2d51483f2e209e4589bf9519fac51b4d061e801125e605f8093bb6997bc163d551596fe4ab7cfae8fb9a90f6980480ce0c229fd1675409bd788354daf316240cfe0af93eb",
"89cae46246efedad1147eb1868c23a6be54f6bac75f0c98a9aefc6bf3ccb89ae012f2e88a9c838b55e57b232cb3c80bc3c2e9fb3fc9768c6226e93284e208bf2");
testKatHex(new Keccak512(),
"2ace31abb0a2e3267944d2f75e1559985db7354c6e605f18dc8470423fca30b7331d9b33c4a4326783d1caae1b4f07060eff978e4746bf0c7e30cd61040bd5ec2746b29863eb7f103ebda614c4291a805b6a4c8214230564a0557bc7102e0bd3ed23719252f7435d64d210ee2aafc585be903fa41e1968c50fd5d5367926df7a05e3a42cf07e656ff92de73b036cf8b19898c0cb34557c0c12c2d8b84e91181af467bc75a9d1",
"e80a63faf248ae762d13887afe8e1954f97327edd9641ce563f4148f9796669827b3a12b06ebd710d4171b86e21bc13360a541845354e0f4934e6fbbd7acbf2d");
testKatHex(new Keccak512(),
"0d8d09aed19f1013969ce5e7eb92f83a209ae76be31c754844ea9116ceb39a22ebb6003017bbcf26555fa6624185187db8f0cb3564b8b1c06bf685d47f3286eda20b83358f599d2044bbf0583fab8d78f854fe0a596183230c5ef8e54426750eaf2cc4e29d3bdd037e734d863c2bd9789b4c243096138f7672c232314effdfc6513427e2da76916b5248933be312eb5dde4cf70804fb258ac5fb82d58d08177ac6f4756017fff5",
"09c10c4818a6821c170d6780d006f7e853e30fe2d9a4e96545673704ec0a1a3e356375715994e1ac1d8cb0e56dbdb2f77dc558ed228fb56ee62217e63455fd0b");
testKatHex(new Keccak512(),
"c3236b73deb7662bf3f3daa58f137b358ba610560ef7455785a9befdb035a066e90704f929bd9689cef0ce3bda5acf4480bceb8d09d10b098ad8500d9b6071dfc3a14af6c77511d81e3aa8844986c3bea6f469f9e02194c92868cd5f51646256798ff0424954c1434bdfed9facb390b07d342e992936e0f88bfd0e884a0ddb679d0547ccdec6384285a45429d115ac7d235a717242021d1dc35641f5f0a48e8445dba58e6cb2c8ea",
"d1cab5979eb7f53c97dca5d725d8b33008906d7759fd3ebb8401ee2fff01db895495a0a062d47f251bc3fc13988607c6798969d213c941efc152e7db1da68e72");
testKatHex(new Keccak512(),
"b39feb8283eadc63e8184b51df5ae3fd41aac8a963bb0be1cd08aa5867d8d910c669221e73243360646f6553d1ca05a84e8dc0de05b6419ec349ca994480193d01c92525f3fb3dcefb08afc6d26947bdbbfd85193f53b50609c6140905c53a6686b58e53a319a57b962331ede98149af3de3118a819da4d76706a0424b4e1d2910b0ed26af61d150ebcb46595d4266a0bd7f651ba47d0c7f179ca28545007d92e8419d48fdfbd744ce",
"96ad163869ae2ffdb89b96f4dc700ece27d1f4daafbc5fb81a8e9513c6ea5e2b6a8bccf4e49a294af326f872740661629ab780581155810e492424c24f8d1dd3");
testKatHex(new Keccak512(),
"a983d54f503803e8c7999f4edbbe82e9084f422143a932ddddc47a17b0b7564a7f37a99d0786e99476428d29e29d3c197a72bfab1342c12a0fc4787fd7017d7a6174049ea43b5779169ef7472bdbbd941dcb82fc73aac45a8a94c9f2bd3477f61fd3b796f02a1b8264a214c6fea74b7051b226c722099ec7883a462b83b6afdd4009248b8a237f605fe5a08fe7d8b45321421ebba67bd70a0b00ddbf94baab7f359d5d1eea105f28dcfb",
"fd2e7a6e11e5d00278099eaf403054d617acac5bd3d0a4908191782c89f9217a3f0118bc2b284fdbce803f66b78dd795eb18dc16ba85e19cb6393dc56c06ecca");
testKatHex(new Keccak512(),
"e4d1c1897a0a866ce564635b74222f9696bf2c7f640dd78d7e2aca66e1b61c642bb03ea7536aae597811e9bf4a7b453ede31f97b46a5f0ef51a071a2b3918df16b152519ae3776f9f1edab4c2a377c3292e96408359d3613844d5eb393000283d5ad3401a318b12fd1474b8612f2bb50fb6a8b9e023a54d7dde28c43d6d8854c8d9d1155935c199811dbfc87e9e0072e90eb88681cc7529714f8fb8a2c9d88567adfb974ee205a9bf7b848",
"ae53776d969a9b285641998a9f2c70ca71856c956a3c430a32a1e03a8e08d544f16511a27cfa59f6b8275a2357f8efa6544b1cd0c00a9460f47954a146429e49");
testKatHex(new Keccak512(),
"b10c59723e3dcadd6d75df87d0a1580e73133a9b7d00cb95ec19f5547027323be75158b11f80b6e142c6a78531886d9047b08e551e75e6261e79785366d7024bd7cd9cf322d9be7d57fb661069f2481c7bb759cd71b4b36ca2bc2df6d3a328faebdb995a9794a8d72155ed551a1f87c80bf6059b43fc764900b18a1c2441f7487743cf84e565f61f8dd2ece6b6ccc9444049197aaaf53e926fbee3bfca8be588ec77f29d211be89de18b15f6",
"d4748c8e17f4117bf2bf71557abb559247552126c36192c5df5c6c3e307d879b703c3fcd7099ddab243e2f1d5ae5066990a7b38d3f2cd7fb115aa6d135e7261d");
testKatHex(new Keccak512(),
"db11f609baba7b0ca634926b1dd539c8cbada24967d7add4d9876f77c2d80c0f4dcefbd7121548373582705cca2495bd2a43716fe64ed26d059cfb566b3364bd49ee0717bdd9810dd14d8fad80dbbdc4cafb37cc60fb0fe2a80fb4541b8ca9d59dce457738a9d3d8f641af8c3fd6da162dc16fc01aac527a4a0255b4d231c0be50f44f0db0b713af03d968fe7f0f61ed0824c55c4b5265548febd6aad5c5eedf63efe793489c39b8fd29d104ce",
"d8ff0481a63890f0e5a536ebba2f253fa2cfa19c0f353587af4bdc3190e4f8f54d17d665e8b2011121d444bfadfff3e192d97fa03b849d63f36db20f4cf88a74");
testKatHex(new Keccak512(),
"bebd4f1a84fc8b15e4452a54bd02d69e304b7f32616aadd90537937106ae4e28de9d8aab02d19bc3e2fde1d651559e296453e4dba94370a14dbbb2d1d4e2022302ee90e208321efcd8528ad89e46dc839ea9df618ea8394a6bff308e7726bae0c19bcd4be52da6258e2ef4e96aa21244429f49ef5cb486d7ff35cac1bacb7e95711944bccb2ab34700d42d1eb38b5d536b947348a458ede3dc6bd6ec547b1b0cae5b257be36a7124e1060c170ffa",
"52d771b5016c6b1b93d3bf6a13f718a7b4741d528798609308b54cea6037862d923751fddce10580a7d6431bf208df17c1b825f7c7401ccbd6d806b744241acf");
testKatHex(new Keccak512(),
"5aca56a03a13784bdc3289d9364f79e2a85c12276b49b92db0adaa4f206d5028f213f678c3510e111f9dc4c1c1f8b6acb17a6413aa227607c515c62a733817ba5e762cc6748e7e0d6872c984d723c9bb3b117eb8963185300a80bfa65cde495d70a46c44858605fccbed086c2b45cef963d33294dbe9706b13af22f1b7c4cd5a001cfec251fba18e722c6e1c4b1166918b4f6f48a98b64b3c07fc86a6b17a6d0480ab79d4e6415b520f1c484d675b1",
"36d472a8ae13d1e70e1fd275117ffe34063befccf6706fab0816e1b81f7fe7f2ddb2a122f1f52c9950644659430f81bcedad5d833df4814cf60ae6c542cc4478");
testKatHex(new Keccak512(),
"a5aad0e4646a32c85cfcac73f02fc5300f1982fabb2f2179e28303e447854094cdfc854310e5c0f60993ceff54d84d6b46323d930adb07c17599b35b505f09e784bca5985e0172257797fb53649e2e9723efd16865c31b5c3d5113b58bb0bfc8920fabdda086d7537e66d709d050bd14d0c960873f156fad5b3d3840cdfcdc9be6af519db262a27f40896ab25cc39f96984d650611c0d5a3080d5b3a1bf186abd42956588b3b58cd948970d298776060",
"e504ad7f33d65b8d3487b28805d478778c901c0aff5f889ae95e2919b4f431a80116a8993469e822895f3c21a41d67afda93a5b29b6250f76335a76fe8919274");
testKatHex(new Keccak512(),
"06cbbe67e94a978203ead6c057a1a5b098478b4b4cbef5a97e93c8e42f5572713575fc2a884531d7622f8f879387a859a80f10ef02708cd8f7413ab385afc357678b9578c0ebf641ef076a1a30f1f75379e9dcb2a885bdd295905ee80c0168a62a9597d10cf12dd2d8cee46645c7e5a141f6e0e23aa482abe5661c16e69ef1e28371e2e236c359ba4e92c25626a7b7ff13f6ea4ae906e1cfe163e91719b1f750a96cbde5fbc953d9e576cd216afc90323a",
"1dca53be0a34114447d1c1443b92b69dfded705956eae60bbab39178ccb11f526a302aae83720652ef4c5dd450a3647df7b77c4664717d935b4f5b20f206fefe");
testKatHex(new Keccak512(),
"f1c528cf7739874707d4d8ad5b98f7c77169de0b57188df233b2dc8a5b31eda5db4291dd9f68e6bad37b8d7f6c9c0044b3bf74bbc3d7d1798e138709b0d75e7c593d3cccdc1b20c7174b4e692add820ace262d45ccfae2077e878796347168060a162ecca8c38c1a88350bd63bb539134f700fd4addd5959e255337daa06bc86358fabcbefdfb5bc889783d843c08aadc6c4f6c36f65f156e851c9a0f917e4a367b5ad93d874812a1de6a7b93cd53ad97232",
"cb1b03b180e04021e0099050eb6b7eb9092c5bd5c445e9d31ee39c724f038e9f619a96d3a2812ca7f208feb2d074c3f817262f7504705623e635b9f273e37a59");
testKatHex(new Keccak512(),
"9d9f3a7ecd51b41f6572fd0d0881e30390dfb780991dae7db3b47619134718e6f987810e542619dfaa7b505c76b7350c6432d8bf1cfebdf1069b90a35f0d04cbdf130b0dfc7875f4a4e62cdb8e525aadd7ce842520a482ac18f09442d78305fe85a74e39e760a4837482ed2f437dd13b2ec1042afcf9decdc3e877e50ff4106ad10a525230d11920324a81094da31deab6476aa42f20c84843cfc1c58545ee80352bdd3740dd6a16792ae2d86f11641bb717c2",
"f0482f098b93624bcde1aab58097198649a8dc84421826d1c1011ad41b948384c8ed5a97c64c134b38a0075812a35f9ce3cb200972c2ecdfc408714139b9bff0");
testKatHex(new Keccak512(),
"5179888724819fbad3afa927d3577796660e6a81c52d98e9303261d5a4a83232f6f758934d50aa83ff9e20a5926dfebaac49529d006eb923c5ae5048ed544ec471ed7191edf46363383824f915769b3e688094c682b02151e5ee01e510b431c8865aff8b6b6f2f59cb6d129da79e97c6d2b8fa6c6da3f603199d2d1bcab547682a81cd6cf65f6551121391d78bcc23b5bd0e922ec6d8bf97c952e84dd28aef909aba31edb903b28fbfc33b7703cd996215a11238",
"a3188426cea0c18cb638bcc45c4337c40be41f6e03cd2d7c4fee26025c5ca281cfbb3ad1554d45edc2eb03e2ebe3de02f57d36d5b6a88a3c61a6aaede62180d0");
testKatHex(new Keccak512(),
"576ef3520d30b7a4899b8c0d5e359e45c5189add100e43be429a02fb3de5ff4f8fd0e79d9663acca72cd29c94582b19292a557c5b1315297d168fbb54e9e2ecd13809c2b5fce998edc6570545e1499dbe7fb74d47cd7f35823b212b05bf3f5a79caa34224fdd670d335fcb106f5d92c3946f44d3afcbae2e41ac554d8e6759f332b76be89a0324aa12c5482d1ea3ee89ded4936f3e3c080436f539fa137e74c6d3389bdf5a45074c47bc7b20b0948407a66d855e2f",
"0b14693e6320668d64ebb3bf6eeb81aafcdb7320ecde80a245786d1b0a808a15c717dc8e8813bf64bf4aa57c29c33e913d6ce1879e52e1919fb83e4a208edaa4");
testKatHex(new Keccak512(),
"0df2152fa4f4357c8741529dd77e783925d3d76e95bafa2b542a2c33f3d1d117d159cf473f82310356fee4c90a9e505e70f8f24859656368ba09381fa245eb6c3d763f3093f0c89b972e66b53d59406d9f01aea07f8b3b615cac4ee4d05f542e7d0dab45d67ccccd3a606ccbeb31ea1fa7005ba07176e60dab7d78f6810ef086f42f08e595f0ec217372b98970cc6321576d92ce38f7c397a403bada1548d205c343ac09deca86325373c3b76d9f32028fea8eb32515",
"a9abc3f554c1e717935d28c28e7c26aa9dc5bd6d7b02ed7dc6afe21a0ea027a8801ae076f2872d08635ee81420711862edc4e448c85513289438b3c8be456b5b");
testKatHex(new Keccak512(),
"3e15350d87d6ebb5c8ad99d42515cfe17980933c7a8f6b8bbbf0a63728cefaad2052623c0bd5931839112a48633fb3c2004e0749c87a41b26a8b48945539d1ff41a4b269462fd199bfecd45374756f55a9116e92093ac99451aefb2af9fd32d6d7f5fbc7f7a540d5097c096ebc3b3a721541de073a1cc02f7fb0fb1b9327fb0b1218ca49c9487ab5396622a13ae546c97abdef6b56380dda7012a8384091b6656d0ab272d363cea78163ff765cdd13ab1738b940d16cae",
"04dd83d20f58e854d857f24720c50a4b5f83dbc8cabd460d379417cd4813772aa85591b90462f34db3faa4dcae335fb1252bf41162e24975a0dbd308c41a4a6b");
testKatHex(new Keccak512(),
"c38d6b0b757cb552be40940ece0009ef3b0b59307c1451686f1a22702922800d58bce7a636c1727ee547c01b214779e898fc0e560f8ae7f61bef4d75eaa696b921fd6b735d171535e9edd267c192b99880c87997711002009095d8a7a437e258104a41a505e5ef71e5613ddd2008195f0c574e6ba3fe40099cfa116e5f1a2fa8a6da04badcb4e2d5d0de31fdc4800891c45781a0aac7c907b56d631fca5ce8b2cde620d11d1777ed9fa603541de794ddc5758fcd5fad78c0",
"ce76b25c928cb75c09c0674e8fcd22089654182cd3d84b85cc44b186a8b1a7cc1bb66f389da6d744a24a7b02bf5c85542d1ba8ef0db4a86d2fc394471b396519");
testKatHex(new Keccak512(),
"8d2de3f0b37a6385c90739805b170057f091cd0c7a0bc951540f26a5a75b3e694631bb64c7635eed316f51318e9d8de13c70a2aba04a14836855f35e480528b776d0a1e8a23b547c8b8d6a0d09b241d3be9377160cca4e6793d00a515dc2992cb7fc741daca171431da99cce6f7789f129e2ac5cf65b40d703035cd2185bb936c82002daf8cbc27a7a9e554b06196630446a6f0a14ba155ed26d95bd627b7205c072d02b60db0fd7e49ea058c2e0ba202daff0de91e845cf79",
"02d1671981c2e85d0455ee85f41b8e9c32b1c80221dd432b8bcb5fcefe0996f32fe9fc3eeb3f1f557ae1632750b92d05239af857c42d59a3daeb9629e1158bec");
testKatHex(new Keccak512(),
"c464bbdad275c50dcd983b65ad1019b9ff85a1e71c807f3204bb2c921dc31fbcd8c5fc45868ae9ef85b6c9b83bba2a5a822201ed68586ec5ec27fb2857a5d1a2d09d09115f22dcc39fe61f5e1ba0ff6e8b4acb4c6da748be7f3f0839739394ff7fa8e39f7f7e84a33c3866875c01bcb1263c9405d91908e9e0b50e7459fabb63d8c6bbb73d8e3483c099b55bc30ff092ff68b6adedfd477d63570c9f5515847f36e24ba0b705557130cec57ebad1d0b31a378e91894ee26e3a04",
"6b8bc6211fe5001e07b7d20e0c49d314211e3893a39da241b8839bb3a494f9a2fd8561009d22cca1330a69362b386e715f1dbe6291dbeecfadf196da47e53198");
testKatHex(new Keccak512(),
"8b8d68bb8a75732fe272815a68a1c9c5aa31b41dedc8493e76525d1d013d33cebd9e21a5bb95db2616976a8c07fcf411f5f6bc6f7e0b57aca78cc2790a6f9b898858ac9c79b165ff24e66677531e39f572be5d81eb3264524181115f32780257bfb9aeec6af12af28e587cac068a1a2953b59ad680f4c245b2e3ec36f59940d37e1d3db38e13edb29b5c0f404f6ff87f80fc8be7a225ff22fbb9c8b6b1d7330c57840d24bc75b06b80d30dad6806544d510af6c4785e823ac3e0b8",
"d00e919dafff3d5e51ad3a3046f5e59d64b69cbcda223cb28bc370201d2c722bae74dfe0086b0eb47bdcb62fabee870c3340d46e55d8cfedf2dd3ced8a8db3f2");
testKatHex(new Keccak512(),
"6b018710446f368e7421f1bc0ccf562d9c1843846bc8d98d1c9bf7d9d6fcb48bfc3bf83b36d44c4fa93430af75cd190bde36a7f92f867f58a803900df8018150384d85d82132f123006ac2aeba58e02a037fe6afbd65eca7c44977dd3dc74f48b6e7a1bfd5cc4dcf24e4d52e92bd4455848e4928b0eac8b7476fe3cc03e862aa4dff4470dbfed6de48e410f25096487ecfc32a27277f3f5023b2725ade461b1355889554a8836c9cf53bd767f5737d55184eea1ab3f53edd0976c485",
"cf63f28f107a509a416f9a92c4e4db4dbf00fb52c2e16d8bb9694e09f9142a904c34e1e960bd97b8cfb2c53e7660c79b841d1565cdab83293234026a23a56d12");
testKatHex(new Keccak512(),
"c9534a24714bd4be37c88a3da1082eda7cabd154c309d7bd670dccd95aa535594463058a29f79031d6ecaa9f675d1211e9359be82669a79c855ea8d89dd38c2c761ddd0ec0ce9e97597432e9a1beae062cdd71edfdfd464119be9e69d18a7a7fd7ce0e2106f0c8b0abf4715e2ca48ef9f454dc203c96656653b727083513f8efb86e49c513bb758b3b052fe21f1c05bb33c37129d6cc81f1aef6adc45b0e8827a830fe545cf57d0955802c117d23ccb55ea28f95c0d8c2f9c5a242b33f",
"f21b8d45b6a857ce663c074c18cc54d914cdd5eb0d968e6153a5f70069345d205ddf4370ec473fc80b05f937d014c0a464582cb4a73b1b72041c5c99f576a41e");
testKatHex(new Keccak512(),
"07906c87297b867abf4576e9f3cc7f82f22b154afcbf293b9319f1b0584da6a40c27b32e0b1b7f412c4f1b82480e70a9235b12ec27090a5a33175a2bb28d8adc475cefe33f7803f8ce27967217381f02e67a3b4f84a71f1c5228e0c2ad971373f6f672624fcea8d1a9f85170fad30fa0bbd25035c3b41a6175d467998bd1215f6f3866f53847f9cf68ef3e2fbb54bc994de2302b829c5eea68ec441fcbafd7d16ae4fe9fff98bf00e5bc2ad54dd91ff9fda4dd77b6c754a91955d1fbaad0",
"92287f42ab1a2123669c4d35f18257d3a536445f0e4d2c801e99f8529cd9e2a79205982c280c7a6cdddef24ce960ec6ca9a35f590aeebc40448c389e915fc4e0");
testKatHex(new Keccak512(),
"588e94b9054abc2189df69b8ba34341b77cdd528e7860e5defcaa79b0c9a452ad4b82aa306be84536eb7cedcbe058d7b84a6aef826b028b8a0271b69ac3605a9635ea9f5ea0aa700f3eb7835bc54611b922964300c953efe7491e3677c2cebe0822e956cd16433b02c68c4a23252c3f9e151a416b4963257b783e038f6b4d5c9f110f871652c7a649a7bcedcbccc6f2d0725bb903cc196ba76c76aa9f10a190b1d1168993baa9ffc96a1655216773458bec72b0e39c9f2c121378feab4e76a",
"74a9d8f9f72908c7502d1c41212cd86cf4344721a6f02d390346f2baec6e6137421e6516c3235443bc2337b3a77630712a12f11b7ba24b2d7085499ba74bcb90");
testKatHex(new Keccak512(),
"08959a7e4baae874928813364071194e2939772f20db7c3157078987c557c2a6d5abe68d520eef3dc491692e1e21bcd880adebf63bb4213b50897fa005256ed41b5690f78f52855c8d9168a4b666fce2da2b456d7a7e7c17ab5f2fb1ee90b79e698712e963715983fd07641ae4b4e9dc73203fac1ae11fa1f8c7941fcc82eab247addb56e2638447e9d609e610b60ce086656aaebf1da3c8a231d7d94e2fd0afe46b391ff14a72eaeb3f44ad4df85866def43d4781a0b3578bc996c87970b132",
"7432861132e6894bb6ae5115398198317e12cc73c0c5dfc61cb189ff5aa9fb0d62224cbb1bfa8b105784405718e6f8e15e041dad80d11ae507b33c15c6cac824");
testKatHex(new Keccak512(),
"cb2a234f45e2ecd5863895a451d389a369aab99cfef0d5c9ffca1e6e63f763b5c14fb9b478313c8e8c0efeb3ac9500cf5fd93791b789e67eac12fd038e2547cc8e0fc9db591f33a1e4907c64a922dda23ec9827310b306098554a4a78f050262db5b545b159e1ff1dca6eb734b872343b842c57eafcfda8405eedbb48ef32e99696d135979235c3a05364e371c2d76f1902f1d83146df9495c0a6c57d7bf9ee77e80f9787aee27be1fe126cdc9ef893a4a7dcbbc367e40fe4e1ee90b42ea25af01",
"6af4ff4c423051e3306ace812e5cfa85532b73deef0dfe601d2630632389d0fab2a109214d32508d2391775665b87a94d1df29db1214cb48dec10dbd3d8cf591");
testKatHex(new Keccak512(),
"d16beadf02ab1d4dc6f88b8c4554c51e866df830b89c06e786a5f8757e8909310af51c840efe8d20b35331f4355d80f73295974653ddd620cdde4730fb6c8d0d2dcb2b45d92d4fbdb567c0a3e86bd1a8a795af26fbf29fc6c65941cddb090ff7cd230ac5268ab4606fccba9eded0a2b5d014ee0c34f0b2881ac036e24e151be89eeb6cd9a7a790afccff234d7cb11b99ebf58cd0c589f20bdac4f9f0e28f75e3e04e5b3debce607a496d848d67fa7b49132c71b878fd5557e082a18eca1fbda94d4b",
"4648d263b608cf28ca65b28a361ebb00e0784c65ab1d55c46a785737b6c8d83dd52e3367d898921ea36dada42d893800d0bfcf86554cdf5e7630d60a2e8ee29f");
testKatHex(new Keccak512(),
"8f65f6bc59a85705016e2bae7fe57980de3127e5ab275f573d334f73f8603106ec3553016608ef2dd6e69b24be0b7113bf6a760ba6e9ce1c48f9e186012cf96a1d4849d75df5bb8315387fd78e9e153e76f8ba7ec6c8849810f59fb4bb9b004318210b37f1299526866f44059e017e22e96cbe418699d014c6ea01c9f0038b10299884dbec3199bb05adc94e955a1533219c1115fed0e5f21228b071f40dd57c4240d98d37b73e412fe0fa4703120d7c0c67972ed233e5deb300a22605472fa3a3ba86",
"dbd3732440010595ab26f84efeb07732227a7b7b52d6ff339c7ff1b6442249202ae33a0aef5167f5b0474d74a5b50cdb033d6c5c72894a3686fe6ecb36e357f3");
testKatHex(new Keccak512(),
"84891e52e0d451813210c3fd635b39a03a6b7a7317b221a7abc270dfa946c42669aacbbbdf801e1584f330e28c729847ea14152bd637b3d0f2b38b4bd5bf9c791c58806281103a3eabbaede5e711e539e6a8b2cf297cf351c078b4fa8f7f35cf61bebf8814bf248a01d41e86c5715ea40c63f7375379a7eb1d78f27622fb468ab784aaaba4e534a6dfd1df6fa15511341e725ed2e87f98737ccb7b6a6dfae416477472b046bf1811187d151bfa9f7b2bf9acdb23a3be507cdf14cfdf517d2cb5fb9e4ab6",
"c24d4054110889290cbc40b82ad8599229d8e86e4ce76bddbbb6f5386223512c9d7e00973c706442b2c80edd20904067af8e4e681aecbfadc6aa15a2ebfe7ddd");
testKatHex(new Keccak512(),
"fdd7a9433a3b4afabd7a3a5e3457e56debf78e84b7a0b0ca0e8c6d53bd0c2dae31b2700c6128334f43981be3b213b1d7a118d59c7e6b6493a86f866a1635c12859cfb9ad17460a77b4522a5c1883c3d6acc86e6162667ec414e9a104aa892053a2b1d72165a855bacd8faf8034a5dd9b716f47a0818c09bb6baf22aa503c06b4ca261f557761989d2afbd88b6a678ad128af68672107d0f1fc73c5ca740459297b3292b281e93bceb761bde7221c3a55708e5ec84472cddcaa84ecf23723cc0991355c6280",
"4a6404d278a0ba70488c18d7d1861cde26fd57d66a9affe74f1e646e616003a52fe42520504ac4ace5ca6665cf9155f44ecaa05d55f80fe9794ade17871c5728");
testKatHex(new Keccak512(),
"70a40bfbef92277a1aad72f6b79d0177197c4ebd432668cfec05d099accb651062b5dff156c0b27336687a94b26679cfdd9daf7ad204338dd9c4d14114033a5c225bd11f217b5f4732da167ee3f939262d4043fc9cba92303b7b5e96aea12adda64859df4b86e9ee0b58e39091e6b188b408ac94e1294a8911245ee361e60e601eff58d1d37639f3753bec80ebb4efde25817436076623fc65415fe51d1b0280366d12c554d86743f3c3b6572e400361a60726131441ba493a83fbe9afda90f7af1ae717238d",
"fffd1b1e31377dff00b492295bccc735733b021f47bb4afba6549ea6c1ba3832e8587099ad0cc216af5899ac683eb7c246871e21c30feef9bceedfc78d0c966c");
testKatHex(new Keccak512(),
"74356e449f4bf8644f77b14f4d67cb6bd9c1f5ae357621d5b8147e562b65c66585caf2e491b48529a01a34d226d436959153815380d5689e30b35357cdac6e08d3f2b0e88e200600d62bd9f5eaf488df86a4470ea227006182e44809009868c4c280c43d7d64a5268fa719074960087b3a6abc837882f882c837834535929389a12b2c78187e2ea07ef8b8eef27dc85002c3ae35f1a50bee6a1c48ba7e175f3316670b27983472aa6a61eed0a683a39ee323080620ea44a9f74411ae5ce99030528f9ab49c79f2",
"33c8f40e1bd1eb1a3a70d2071d27460ef0f6b2d3ece373743842d6b928f3771e4b7446a9ecfbbf552c064f6b26095401097581c38b95e9551119a1fdcb3d58e7");
testKatHex(new Keccak512(),
"8c3798e51bc68482d7337d3abb75dc9ffe860714a9ad73551e120059860dde24ab87327222b64cf774415a70f724cdf270de3fe47dda07b61c9ef2a3551f45a5584860248fabde676e1cd75f6355aa3eaeabe3b51dc813d9fb2eaa4f0f1d9f834d7cad9c7c695ae84b329385bc0bef895b9f1edf44a03d4b410cc23a79a6b62e4f346a5e8dd851c2857995ddbf5b2d717aeb847310e1f6a46ac3d26a7f9b44985af656d2b7c9406e8a9e8f47dcb4ef6b83caacf9aefb6118bfcff7e44bef6937ebddc89186839b77",
"2a11cb6921ea662a39ddee7982e3cf5b317195661d5505ad04d11ee23e178ed65f3e06a7f096f4eaf1ff6a09239cf5a0a39dc9f4c92af63fdf7211e1cf467653");
testKatHex(new Keccak512(),
"fa56bf730c4f8395875189c10c4fb251605757a8fecc31f9737e3c2503b02608e6731e85d7a38393c67de516b85304824bfb135e33bf22b3a23b913bf6acd2b7ab85198b8187b2bcd454d5e3318cacb32fd6261c31ae7f6c54ef6a7a2a4c9f3ecb81ce3555d4f0ad466dd4c108a90399d70041997c3b25345a9653f3c9a6711ab1b91d6a9d2216442da2c973cbd685ee7643bfd77327a2f7ae9cb283620a08716dfb462e5c1d65432ca9d56a90e811443cd1ecb8f0de179c9cb48ba4f6fec360c66f252f6e64edc96b",
"9196bbbd194541ffee7edbab970738bdd3aadbd6b73d1c85b580afac1232ae8077f743ce8b5b6f2b418b5134cccd4f83645e8631885b14fbbcb909a9836c374c");
testKatHex(new Keccak512(),
"b6134f9c3e91dd8000740d009dd806240811d51ab1546a974bcb18d344642baa5cd5903af84d58ec5ba17301d5ec0f10ccd0509cbb3fd3fff9172d193af0f782252fd1338c7244d40e0e42362275b22d01c4c3389f19dd69bdf958ebe28e31a4ffe2b5f18a87831cfb7095f58a87c9fa21db72ba269379b2dc2384b3da953c7925761fed324620acea435e52b424a7723f6a2357374157a34cd8252351c25a1b232826cefe1bd3e70ffc15a31e7c0598219d7f00436294d11891b82497bc78aa5363892a2495df8c1eef",
"1959cae3600f128f72e1821c337d841b14cbbfef3a6d22286f18bdfc3ef63528c11bffa841a6d2208afeb5664d524de83090ab0db07cd47ef52f4d2eaa8454ce");
testKatHex(new Keccak512(),
"c941cdb9c28ab0a791f2e5c8e8bb52850626aa89205bec3a7e22682313d198b1fa33fc7295381354858758ae6c8ec6fac3245c6e454d16fa2f51c4166fab51df272858f2d603770c40987f64442d487af49cd5c3991ce858ea2a60dab6a65a34414965933973ac2457089e359160b7cdedc42f29e10a91921785f6b7224ee0b349393cdcff6151b50b377d609559923d0984cda6000829b916ab6896693ef6a2199b3c22f7dc5500a15b8258420e314c222bc000bc4e5413e6dd82c993f8330f5c6d1be4bc79f08a1a0a46",
"a913ddc5bb089c121ff093be529225148df787d48f4f61699eff9fc2910282a898a81a38d66be9b06428d6466a614ca822a872c1c2c4d503d434d3b1d6942102");
testKatHex(new Keccak512(),
"4499efffac4bcea52747efd1e4f20b73e48758be915c88a1ffe5299b0b005837a46b2f20a9cb3c6e64a9e3c564a27c0f1c6ad1960373036ec5bfe1a8fc6a435c2185ed0f114c50e8b3e4c7ed96b06a036819c9463e864a58d6286f785e32a804443a56af0b4df6abc57ed5c2b185ddee8489ea080deeee66aa33c2e6dab36251c402682b6824821f998c32163164298e1fafd31babbcffb594c91888c6219079d907fdb438ed89529d6d96212fd55abe20399dbefd342248507436931cdead496eb6e4a80358acc78647d043",
"f10b91564ad93d734743281949bacef065a6432a455236f1bf798de9aec6ccac9b8d373b07c5acfbd676ef21e4a3a9e0f7c38e8756d177d0a5c283d520844b4d");
testKatHex(new Keccak512(),
"eecbb8fdfa4da62170fd06727f697d81f83f601ff61e478105d3cb7502f2c89bf3e8f56edd469d049807a38882a7eefbc85fc9a950952e9fa84b8afebd3ce782d4da598002827b1eb98882ea1f0a8f7aa9ce013a6e9bc462fb66c8d4a18da21401e1b93356eb12f3725b6db1684f2300a98b9a119e5d27ff704affb618e12708e77e6e5f34139a5a41131fd1d6336c272a8fc37080f041c71341bee6ab550cb4a20a6ddb6a8e0299f2b14bc730c54b8b1c1c487b494bdccfd3a53535ab2f231590bf2c4062fd2ad58f906a2d0d",
"ef26a1baf33d4de047bdd2ce34736e042ecd33aa569ffc0cb81ecfa66e9f87da8d025ecba24bcb187e4201046fb99a02dfa6f1bf88ec2b88de216cf759fac41d");
testKatHex(new Keccak512(),
"e64f3e4ace5c8418d65fec2bc5d2a303dd458034736e3b0df719098be7a206deaf52d6ba82316caf330ef852375188cde2b39cc94aa449578a7e2a8e3f5a9d68e816b8d16889fbc0ebf0939d04f63033ae9ae2bdab73b88c26d6bd25ee460ee1ef58fb0afa92cc539f8c76d3d097e7a6a63ebb9b5887edf3cf076028c5bbd5b9db3211371ad3fe121d4e9bf44229f4e1ecf5a0f9f0eba4d5ceb72878ab22c3f0eb5a625323ac66f7061f4a81fac834471e0c59553f108475fe290d43e6a055ae3ee46fb67422f814a68c4be3e8c9",
"f8e079a6dc5a6a7e7f32ff7e8015d1b26d43b54f166f2111cfb2b1eb238cabee58630ef845e0db00ddf1d800ad67ce7b2b658b42118cc15c8ef3bc9fb252db64");
testKatHex(new Keccak512(),
"d2cb2d733033f9e91395312808383cc4f0ca974e87ec68400d52e96b3fa6984ac58d9ad0938dde5a973008d818c49607d9de2284e7618f1b8aed8372fbd52ed54557af4220fac09dfa8443011699b97d743f8f2b1aef3537ebb45dcc9e13dfb438428ee190a4efdb3caeb7f3933117bf63abdc7e57beb4171c7e1ad260ab0587806c4d137b6316b50abc9cce0dff3acada47bbb86be777e617bbe578ff4519844db360e0a96c6701290e76bb95d26f0f804c8a4f2717eac4e7de9f2cff3bbc55a17e776c0d02856032a6cd10ad2838",
"a5bfaa52499a688d9c8d3ddc0ba06decdf3829be5d444acfa412f4c6e863f4786be9935805310734e4f0affe05558999807408e97e100fadd0c93ff160f8b11b");
testKatHex(new Keccak512(),
"f2998955613dd414cc111df5ce30a995bb792e260b0e37a5b1d942fe90171a4ac2f66d4928d7ad377f4d0554cbf4c523d21f6e5f379d6f4b028cdcb9b1758d3b39663242ff3cb6ede6a36a6f05db3bc41e0d861b384b6dec58bb096d0a422fd542df175e1be1571fb52ae66f2d86a2f6824a8cfaacbac4a7492ad0433eeb15454af8f312b3b2a577750e3efbd370e8a8cac1582581971fba3ba4bd0d76e718dacf8433d33a59d287f8cc92234e7a271041b526e389efb0e40b6a18b3aaf658e82ed1c78631fd23b4c3eb27c3faec8685",
"ccea9fcf1ad93270ac4690e96b875122c5b5ec20d2cc27079cbf893126c44e0208a8bfa139057d72bd2638059ec8da8a720499af9d4c117f86799d7515dfc6e0");
testKatHex(new Keccak512(),
"447797e2899b72a356ba55bf4df3acca6cdb1041eb477bd1834a9f9acbc340a294d729f2f97df3a610be0ff15edb9c6d5db41644b9874360140fc64f52aa03f0286c8a640670067a84e017926a70438db1bb361defee7317021425f8821def26d1efd77fc853b818545d055adc9284796e583c76e6fe74c9ac2587aa46aa8f8804f2feb5836cc4b3ababab8429a5783e17d5999f32242eb59ef30cd7adabc16d72dbdb097623047c98989f88d14eaf02a7212be16ec2d07981aaa99949ddf89ecd90333a77bc4e1988a82abf7c7caf3291",
"2efc5dfe028a35503a25bdf8b2164d86ca7496b7c5ded09c5d414b6977adbb4a6988ab9939d1ec65f46bcc99c1dcd5f19e035d8d3dc387361200e4da80c80671");
testKatHex(new Keccak512(),
"9f2c18ade9b380c784e170fb763e9aa205f64303067eb1bcea93df5dac4bf5a2e00b78195f808df24fc76e26cb7be31dc35f0844cded1567bba29858cffc97fb29010331b01d6a3fb3159cc1b973d255da9843e34a0a4061cabdb9ed37f241bfabb3c20d32743f4026b59a4ccc385a2301f83c0b0a190b0f2d01acb8f0d41111e10f2f4e149379275599a52dc089b35fdd5234b0cfb7b6d8aebd563ca1fa653c5c021dfd6f5920e6f18bfafdbecbf0ab00281333ed50b9a999549c1c8f8c63d7626c48322e9791d5ff72294049bde91e73f8",
"e80d7a934fdaf17db8dbb1dc6c42e90e139211c2f599890c06b15d6248fdbe682d77d4e05f26d72852f7492bce118ce7c36950bd2c50f9699bb47d89c3115377");
testKatHex(new Keccak512(),
"ae159f3fa33619002ae6bcce8cbbdd7d28e5ed9d61534595c4c9f43c402a9bb31f3b301cbfd4a43ce4c24cd5c9849cc6259eca90e2a79e01ffbac07ba0e147fa42676a1d668570e0396387b5bcd599e8e66aaed1b8a191c5a47547f61373021fa6deadcb55363d233c24440f2c73dbb519f7c9fa5a8962efd5f6252c0407f190dfefad707f3c7007d69ff36b8489a5b6b7c557e79dd4f50c06511f599f56c896b35c917b63ba35c6ff8092baf7d1658e77fc95d8a6a43eeb4c01f33f03877f92774be89c1114dd531c011e53a34dc248a2f0e6",
"c414b29fd07720f46c351f5c80be2094e95d13ad97bdd1f7c5207b695693cd5e1e0169b1aa2e271115bd5171fec51d04b71e3e7ce1618fbfeb382f56f65f7eff");
testKatHex(new Keccak512(),
"3b8e97c5ffc2d6a40fa7de7fcefc90f3b12c940e7ab415321e29ee692dfac799b009c99dcddb708fce5a178c5c35ee2b8617143edc4c40b4d313661f49abdd93cea79d117518805496fe6acf292c4c2a1f76b403a97d7c399daf85b46ad84e16246c67d6836757bde336c290d5d401e6c1386ab32797af6bb251e9b2d8fe754c47482b72e0b394eab76916126fd68ea7d65eb93d59f5b4c5ac40f7c3b37e7f3694f29424c24af8c8f0ef59cd9dbf1d28e0e10f799a6f78cad1d45b9db3d7dee4a7059abe99182714983b9c9d44d7f5643596d4f3",
"a4679a4cbee6292203bafba8913245f30e046aba6c0937b407c00b73d17d8d696690ee25ba1b39deb3db93525a8fbcfd88173ba9c7a65b4406d0550ba9b6cc07");
testKatHex(new Keccak512(),
"3434ec31b10fafdbfeec0dd6bd94e80f7ba9dca19ef075f7eb017512af66d6a4bcf7d16ba0819a1892a6372f9b35bcc7ca8155ee19e8428bc22d214856ed5fa9374c3c09bde169602cc219679f65a1566fc7316f4cc3b631a18fb4449fa6afa16a3db2bc4212eff539c67cf184680826535589c7111d73bffce431b4c40492e763d9279560aaa38eb2dc14a212d723f994a1fe656ff4dd14551ce4e7c621b2aa5604a10001b2878a897a28a08095c325e10a26d2fb1a75bfd64c250309bb55a44f23bbac0d5516a1c687d3b41ef2fbbf9cc56d4739",
"5f49d6594da939987d1906294b33a037f63c79e078531dfa7e6ce67279d4d5dbeb650ff8690f23b63b7e9c48ea8791b80fdb34ef66dcf0cefe45842ecff4ad1d");
testKatHex(new Keccak512(),
"7c7953d81c8d208fd1c97681d48f49dd003456de60475b84070ef4847c333b74575b1fc8d2a186964485a3b8634feaa3595aaa1a2f4595a7d6b6153563dee31bbac443c8a33eed6d5d956a980a68366c2527b550ee950250dfb691eacbd5d56ae14b970668be174c89df2fea43ae52f13142639c884fd62a3683c0c3792f0f24ab1318bcb27e21f4737fab62c77ea38bc8fd1cf41f7dab64c13febe7152bf5bb7ab5a78f5346d43cc741cb6f72b7b8980f268b68bf62abdfb1577a52438fe14b591498cc95f071228460c7c5d5ceb4a7bde588e7f21c",
"b77fb79669ea52c738e58a9ef3ed1501bbe7974478afb5a8bed44549d6232ff8d7aa9eeeaf02f6755327951093243110d7bcfc0e51299db793856b57a77e8420");
testKatHex(new Keccak512(),
"7a6a4f4fdc59a1d223381ae5af498d74b7252ecf59e389e49130c7eaee626e7bd9897effd92017f4ccde66b0440462cdedfd352d8153e6a4c8d7a0812f701cc737b5178c2556f07111200eb627dbc299caa792dfa58f35935299fa3a3519e9b03166dffa159103ffa35e8577f7c0a86c6b46fe13db8e2cdd9dcfba85bdddcce0a7a8e155f81f712d8e9fe646153d3d22c811bd39f830433b2213dd46301941b59293fd0a33e2b63adbd95239bc01315c46fdb678875b3c81e053a40f581cfbec24a1404b1671a1b88a6d06120229518fb13a74ca0ac5ae",
"caca0ff43107f730a7fbe6869fba5af1e626c96303be3bc95155164199c88922194511b24c48911186f647ca246427f2ce7ba747271cd8d7c5e1d127c21f1eaa");
testKatHex(new Keccak512(),
"d9faa14cebe9b7de551b6c0765409a33938562013b5e8e0e1e0a6418df7399d0a6a771fb81c3ca9bd3bb8e2951b0bc792525a294ebd1083688806fe5e7f1e17fd4e3a41d00c89e8fcf4a363caedb1acb558e3d562f1302b3d83bb886ed27b76033798131dab05b4217381eaaa7ba15ec820bb5c13b516dd640eaec5a27d05fdfca0f35b3a5312146806b4c0275bcd0aaa3b2017f346975db566f9b4d137f4ee10644c2a2da66deeca5342e236495c3c6280528bfd32e90af4cd9bb908f34012b52b4bc56d48cc8a6b59bab014988eabd12e1a0a1c2e170e7",
"e5106b2a0d49d6d1e13e3323232101cea5da71caa24e70efcac57e0ccf156cdf4c2492b03ce0e13437018dab76b9c989883bea69e849f33bb937a397b84ada6a");
testKatHex(new Keccak512(),
"2d8427433d0c61f2d96cfe80cf1e932265a191365c3b61aaa3d6dcc039f6ba2ad52a6a8cc30fc10f705e6b7705105977fa496c1c708a277a124304f1fc40911e7441d1b5e77b951aad7b01fd5db1b377d165b05bbf898042e39660caf8b279fe5229d1a8db86c0999ed65e53d01ccbc4b43173ccf992b3a14586f6ba42f5fe30afa8ae40c5df29966f9346da5f8b35f16a1de3ab6de0f477d8d8660918060e88b9b9e9ca6a4207033b87a812dbf5544d39e4882010f82b6ce005f8e8ff6fe3c3806bc2b73c2b83afb704345629304f9f86358712e9fae3ca3e",
"faee462e4bced12ad54d3757d644396ed9203037741661aea32bccadae568c4bdc925eda76610e964fbe3fb26b33bc0bc123ddf9b528715317ce5c92e00ac96f");
testKatHex(new Keccak512(),
"5e19d97887fcaac0387e22c6f803c34a3dacd2604172433f7a8a7a526ca4a2a1271ecfc5d5d7be5ac0d85d921095350dfc65997d443c21c8094e0a3fefd2961bcb94aed03291ae310ccda75d8ace4bc7d89e7d3e5d1650bda5d668b8b50bfc8e608e184f4d3a9a2badc4ff5f07e0c0bc8a9f2e0b2a26fd6d8c550008faaab75fd71af2a424bec9a7cd9d83fad4c8e9319115656a8717d3b523a68ff8004258b9990ed362308461804ba3e3a7e92d8f2ffae5c2fba55ba5a3c27c0a2f71bd711d2fe1799c2adb31b200035481e9ee5c4adf2ab9c0fa50b23975cf",
"fbe25b43e540104a3aade897838c63511928af5add4f952f1e6d4c39e70c923df191faa36f46b21f827d9b437996ff7206f73337cf20c6b0db748a707455b420");
testKatHex(new Keccak512(),
"c8e976ab4638909387ce3b8d4e510c3230e5690e02c45093b1d297910abc481e56eea0f296f98379dfc9080af69e73b2399d1c143bee80ae1328162ce1ba7f6a8374679b20aacd380eb4e61382c99998704d62701afa914f9a2705cdb065885f50d086c3eb5753700c387118bb142f3e6da1e988dfb31ac75d7368931e45d1391a274b22f83ceb072f9bcabc0b216685bfd789f5023971024b1878a205442522f9ea7d8797a4102a3df41703768251fd5e017c85d1200a464118aa35654e7ca39f3c375b8ef8cbe7534dbc64bc20befb417cf60ec92f63d9ee7397",
"0a41a004573e0a983fe9c93bd57439a20c8f99b800a60d4a07117e8d9b25c0ee38bab3cdb6fc9216b8e07f0ccdd028c418ef97b6d7e15decde7425497644e2e4");
testKatHex(new Keccak512(),
"7145fa124b7429a1fc2231237a949ba7201bcc1822d3272de005b682398196c25f7e5cc2f289fbf44415f699cb7fe6757791b1443410234ae061edf623359e2b4e32c19bf88450432dd01caa5eb16a1dc378f391ca5e3c4e5f356728bddd4975db7c890da8bbc84cc73ff244394d0d48954978765e4a00b593f70f2ca082673a261ed88dbcef1127728d8cd89bc2c597e9102ced6010f65fa75a14ebe467fa57ce3bd4948b6867d74a9df5c0ec6f530cbf2ee61ce6f06bc8f2864dff5583776b31df8c7ffcb61428a56bf7bd37188b4a5123bbf338393af46eda85e6",
"ff081507f979f69c6743e42ee758858713b570cb48ff85ef0d728c4e1bb5456d035e498c05ea4cebd820e134bb252ac76ba4949a4fad76871a9972ae2fccceea");
testKatHex(new Keccak512(),
"7fdfadcc9d29bad23ae038c6c65cda1aef757221b8872ed3d75ff8df7da0627d266e224e812c39f7983e4558bfd0a1f2bef3feb56ba09120ef762917b9c093867948547aee98600d10d87b20106878a8d22c64378bf634f7f75900c03986b077b0bf8b740a82447b61b99fee5376c5eb6680ec9e3088f0bdd0c56883413d60c1357d3c811950e5890e7600103c916341b80c743c6a852b7b4fb60c3ba21f3bc15b8382437a68454779cf3cd7f9f90ccc8ef28d0b706535b1e4108eb5627bb45d719cb046839aee311ca1abdc8319e050d67972cb35a6b1601b25dbf487",
"03444ae8319ebd121e7707b9cdfd1fdfd52f3d6b3d4bcb2748af421a3c8666c22d8c0d8a096767b1cd16a8d54738c5f67a6f9d48c90827be71691a42be87108b");
testKatHex(new Keccak512(),
"988638219fd3095421f826f56e4f09e356296b628c3ce6930c9f2e758fd1a80c8273f2f61e4daae65c4f110d3e7ca0965ac7d24e34c0dc4ba2d6ff0bf5bbe93b3585f354d7543cb542a1aa54674d375077f2d360a8f4d42f3db131c3b7ab7306267ba107659864a90c8c909460a73621d1f5d9d3fd95beb19b23db1cb6c0d0fba91d36891529b8bd8263caa1bab56a4affaed44962df096d8d5b1eb845ef31188b3e10f1af811a13f156beb7a288aae593ebd1471b624aa1a7c6adf01e2200b3d72d88a3aed3100c88231e41efc376906f0b580dc895f080fda5741db1cb",
"5ee0a4459724037b7318815a80147c172d6c8f8874c9a0057706fb3e300fe936815f07672e6447b771de699dfadf345c3bb5974cf019315fadd5534dff6a079c");
testKatHex(new Keccak512(),
"5aab62756d307a669d146aba988d9074c5a159b3de85151a819b117ca1ff6597f6156e80fdd28c9c3176835164d37da7da11d94e09add770b68a6e081cd22ca0c004bfe7cd283bf43a588da91f509b27a6584c474a4a2f3ee0f1f56447379240a5ab1fb77fdca49b305f07ba86b62756fb9efb4fc225c86845f026ea542076b91a0bc2cdd136e122c659be259d98e5841df4c2f60330d4d8cdee7bf1a0a244524eecc68ff2aef5bf0069c9e87a11c6e519de1a4062a10c83837388f7ef58598a3846f49d499682b683c4a062b421594fafbc1383c943ba83bdef515efcf10d",
"54085a2f9c327e5d8ee225eff5bd2c2837e44e8057cf1691e6202050079d26851061c4da8d88fc19237e5b658950e66866e92019d9e425e2416240a59d25a6cf");
testKatHex(new Keccak512(),
"47b8216aa0fbb5d67966f2e82c17c07aa2d6327e96fcd83e3de7333689f3ee79994a1bf45082c4d725ed8d41205cb5bcdf5c341f77facb1da46a5b9b2cbc49eadf786bcd881f371a95fa17df73f606519aea0ff79d5a11427b98ee7f13a5c00637e2854134691059839121fea9abe2cd1bcbbbf27c74caf3678e05bfb1c949897ea01f56ffa4dafbe8644611685c617a3206c7a7036e4ac816799f693dafe7f19f303ce4eba09d21e03610201bfc665b72400a547a1e00fa9b7ad8d84f84b34aef118515e74def11b9188bd1e1f97d9a12c30132ec2806339bdadacda2fd8b78",
"3ea49b6abd39cdf04bccd648fb7e1f8ae3dae9d3e3a5eab9ce29be356defbbbeb1bb93ae40d31cc1f011dcc6c6ac85b102f2654e2dbbac47333bcdb4758a1a28");
testKatHex(new Keccak512(),
"8cff1f67fe53c098896d9136389bd8881816ccab34862bb67a656e3d98896f3ce6ffd4da73975809fcdf9666760d6e561c55238b205d8049c1cedeef374d1735daa533147bfa960b2cce4a4f254176bb4d1bd1e89654432b8dbe1a135c42115b394b024856a2a83dc85d6782be4b444239567ccec4b184d4548eae3ff6a192f343292ba2e32a0f267f31cc26719eb85245d415fb897ac2da433ee91a99424c9d7f1766a44171d1651001c38fc79294accc68ceb5665d36218454d3ba169ae058a831338c17743603f81ee173bfc0927464f9bd728dee94c6aeab7aae6ee3a627e8",
"b3851790ca47575dbf988f82c3b501dc8390a8e8598698166167567a0332913ccc8868584db4acfb2c9dc0f0a6833292f4dcedc47cf003217689bc2422b53b93");
testKatHex(new Keccak512(),
"eacd07971cff9b9939903f8c1d8cbb5d4db1b548a85d04e037514a583604e787f32992bf2111b97ac5e8a938233552731321522ab5e8583561260b7d13ebeef785b23a41fd8576a6da764a8ed6d822d4957a545d5244756c18aa80e1aad4d1f9c20d259dee1711e2cc8fd013169fb7cc4ce38b362f8e0936ae9198b7e838dcea4f7a5b9429bb3f6bbcf2dc92565e3676c1c5e6eb3dd2a0f86aa23edd3d0891f197447692794b3dfa269611ad97f72b795602b4fdb198f3fd3eb41b415064256e345e8d8c51c555dc8a21904a9b0f1ad0effab7786aac2da3b196507e9f33ca356427",
"a710cb26c632f289504cd0039ba6ab9b4d3524c52b286d466e2f8939f8684e3f18dca298a2ba67eb710997b7bb10ae279438b9b4868d0adb248f282bb440a130");
testKatHex(new Keccak512(),
"23ac4e9a42c6ef45c3336ce6dfc2ff7de8884cd23dc912fef0f7756c09d335c189f3ad3a23697abda851a81881a0c8ccafc980ab2c702564c2be15fe4c4b9f10dfb2248d0d0cb2e2887fd4598a1d4acda897944a2ffc580ff92719c95cf2aa42dc584674cb5a9bc5765b9d6ddf5789791d15f8dd925aa12bffafbce60827b490bb7df3dda6f2a143c8bf96abc903d83d59a791e2d62814a89b8080a28060568cf24a80ae61179fe84e0ffad00388178cb6a617d37efd54cc01970a4a41d1a8d3ddce46edbba4ab7c90ad565398d376f431189ce8c1c33e132feae6a8cd17a61c630012",
"8f677a8089052b47be60c0bb7666e403a5daa5e28a2b632f2e496c587f1fdca0ee33d9e78daa4ef575b13389748b8c24110053b0b96a082c06c3f80ebe8de976");
testKatHex(new Keccak512(),
"0172df732282c9d488669c358e3492260cbe91c95cfbc1e3fea6c4b0ec129b45f242ace09f152fc6234e1bee8aab8cd56e8b486e1dcba9c05407c2f95da8d8f1c0af78ee2ed82a3a79ec0cb0709396ee62aadb84f8a4ee8a7ccca3c1ee84e302a09ea802204afecf04097e67d0f8e8a9d2651126c0a598a37081e42d168b0ae8a71951c524259e4e2054e535b779679bdade566fe55700858618e626b4a0faf895bcce9011504a49e05fd56127eae3d1f8917afb548ecadabda1020111fec9314c413498a360b08640549a22cb23c731ace743252a8227a0d2689d4c6001606678dfb921",
"ce631e6f2c2dc5738c0fa958571773b58af130b94824331419ee57e2691ce5f29db3d8fe456cd1e7cdc07f6105fa1b6fd729c2b419008ccd889169c3385db1b9");
testKatHex(new Keccak512(),
"3875b9240cf3e0a8b59c658540f26a701cf188496e2c2174788b126fd29402d6a75453ba0635284d08835f40051a2a9683dc92afb9383719191231170379ba6f4adc816fecbb0f9c446b785bf520796841e58878b73c58d3ebb097ce4761fdeabe15de2f319dfbaf1742cdeb389559c788131a6793e193856661376c81ce9568da19aa6925b47ffd77a43c7a0e758c37d69254909ff0fbd415ef8eb937bcd49f91468b49974c07dc819abd67395db0e05874ff83dddab895344abd0e7111b2df9e58d76d85ad98106b36295826be04d435615595605e4b4bb824b33c4afeb5e7bb0d19f909",
"fff677bb58909c158ea677be704253505b106af934f639abfec63bd0c63097aa4bf032fe924149dd991d335e1c44c0220e4d13cbc41b6a98fb5a05faa3fe15b3");
testKatHex(new Keccak512(),
"747cc1a59fefba94a9c75ba866c30dc5c1cb0c0f8e9361d98484956dd5d1a40f6184afbe3dac9f76028d1caeccfbf69199c6ce2b4c092a3f4d2a56fe5a33a00757f4d7dee5dfb0524311a97ae0668a47971b95766e2f6dd48c3f57841f91f04a00ad5ea70f2d479a2620dc5cd78eaab3a3b011719b7e78d19ddf70d9423798af77517ebc55392fcd01fc600d8d466b9e7a7a85bf33f9cc5419e9bd874ddfd60981150ddaf8d7febaa4374f0872a5628d318000311e2f5655365ad4d407c20e5c04df17a222e7deec79c5ab1116d8572f91cd06e1ccc7ced53736fc867fd49ecebe6bf8082e8a",
"451ee587226c99989f5ec10050983b1fd661228a4ab48618f1d1173c94fac39ecfd3c26c16653633b26097e31a0f2213b4f1153a57cb48a70d2af1adeb1bbc06");
testKatHex(new Keccak512(),
"57af971fccaec97435dc2ec9ef0429bcedc6b647729ea168858a6e49ac1071e706f4a5a645ca14e8c7746d65511620682c906c8b86ec901f3dded4167b3f00b06cbfac6aee3728051b3e5ff10b4f9ed8bd0b8da94303c833755b3ca3aeddf0b54bc8d6632138b5d25bab03d17b3458a9d782108006f5bb7de75b5c0ba854b423d8bb801e701e99dc4feaad59bc1c7112453b04d33ea3635639fb802c73c2b71d58a56bbd671b18fe34ed2e3dca38827d63fdb1d4fb3285405004b2b3e26081a8ff08cd6d2b08f8e7b7e90a2ab1ed7a41b1d0128522c2f8bff56a7fe67969422ce839a9d4608f03",
"f9d6ad8686125e71fe0856e806d68ba97ef123443938d28283387f33e3ac6e2a7de042a3ee5f7994c1eecc5b6f22cbae1349cab2fb7a0a0125ec2320320858d4");
testKatHex(new Keccak512(),
"04e16dedc1227902baaf332d3d08923601bdd64f573faa1bb7201918cfe16b1e10151dae875da0c0d63c59c3dd050c4c6a874011b018421afc4623ab0381831b2da2a8ba42c96e4f70864ac44e106f94311051e74c77c1291bf5db9539e69567bf6a11cf6932bbbad33f8946bf5814c066d851633d1a513510039b349939bfd42b858c21827c8ff05f1d09b1b0765dc78a135b5ca4dfba0801bcaddfa175623c8b647eacfb4444b85a44f73890607d06d507a4f8393658788669f6ef4deb58d08c50ca0756d5e2f49d1a7ad73e0f0b3d3b5f090acf622b1878c59133e4a848e05153592ea81c6fbf",
"f26f3268fd620fc476a49aac3ed1580864934a2f6ba881ed8c8fb757aaaa64bcdf501e1913de600bbef6f12c949fea8fd68c645086d5e30c9253588ffbd19be5");
testKatHex(new Keccak512(),
"7c815c384eee0f288ece27cced52a01603127b079c007378bc5d1e6c5e9e6d1c735723acbbd5801ac49854b2b569d4472d33f40bbb8882956245c366dc3582d71696a97a4e19557e41e54dee482a14229005f93afd2c4a7d8614d10a97a9dfa07f7cd946fa45263063ddd29db8f9e34db60daa32684f0072ea2a9426ecebfa5239fb67f29c18cbaa2af6ed4bf4283936823ac1790164fec5457a9cba7c767ca59392d94cab7448f50eb34e9a93a80027471ce59736f099c886dea1ab4cba4d89f5fc7ae2f21ccd27f611eca4626b2d08dc22382e92c1efb2f6afdc8fdc3d2172604f5035c46b8197d3",
"080845d6fd22a00b30fa01a4b4f81fdc7b46ca4c6a676ad5863a9dbf6611ba97f24fb59bb5bac4e376b3b8b3357166782876b701273ff351bc8c5805532767d4");
testKatHex(new Keccak512(),
"e29d505158dbdd937d9e3d2145658ee6f5992a2fc790f4f608d9cdb44a091d5b94b88e81fac4fdf5c49442f13b911c55886469629551189eaff62488f1a479b7db11a1560e198ddccccf50159093425ff7f1cb8d1d1246d0978764087d6bac257026b090efae8cec5f22b6f21c59ace1ac7386f5b8837ca6a12b6fbf5534dd0560ef05ca78104d3b943ddb220feaec89aa5e692a00f822a2ab9a2fe60350d75e7be16ff2526dc643872502d01f42f188abed0a6e9a6f5fd0d1ce7d5755c9ffa66b0af0b20bd806f08e06156690d81ac811778ca3dac2c249b96002017fce93e507e3b953acf99964b847",
"2678a8715fc7e538522dd7608d769508b63017d9eb6cc48f1cb07d14e741066936c8316bf3211e09f62611e140ddd14a07f97f9f372e99c084ffe289eb302bd8");
testKatHex(new Keccak512(),
"d85588696f576e65eca0155f395f0cfacd83f36a99111ed5768df2d116d2121e32357ba4f54ede927f189f297d3a97fad4e9a0f5b41d8d89dd7fe20156799c2b7b6bf9c957ba0d6763f5c3bc5129747bbb53652b49290cff1c87e2cdf2c4b95d8aaee09bc8fbfa6883e62d237885810491bfc101f1d8c636e3d0ede838ad05c207a3df4fad76452979eb99f29afaecedd1c63b8d36cf378454a1bb67a741c77ac6b6b3f95f4f02b64dabc15438613ea49750df42ee90101f115aa9abb9ff64324dde9dabbb01054e1bd6b4bcdc7930a44c2300d87ca78c06924d0323ad7887e46c90e8c4d100acd9eed21e",
"aa03eb09417435da9e6e7803f3b6eab66faa3d59cc622950d61f9b962b69145ac2255cd752cb9607742092697b1a79d124817ae26421e61d1176764832ed354c");
testKatHex(new Keccak512(),
"3a12f8508b40c32c74492b66323375dcfe49184c78f73179f3314b79e63376b8ac683f5a51f1534bd729b02b04d002f55cbd8e8fc9b5ec1ea6bbe6a0d0e7431518e6ba45d124035f9d3dce0a8bb7bf1430a9f657e0b4ea9f20eb20c786a58181a1e20a96f1628f8728a13bdf7a4b4b32fc8aa7054cc4881ae7fa19afa65c6c3ee1b3ade3192af42054a8a911b8ec1826865d46d93f1e7c5e2b7813c92a506e53886f3d4701bb93d2a681ad109c845904bb861af8af0646b6e399b38b614051d34f6842563a0f37ec00cb3d865fc5d746c4987de2a65071100883a2a9c7a2bfe1e2dd603d9ea24dc7c5fd06be",
"d3012f2fb56845b258d7598c0bbb2c97d53b602deae9326dc3678b2228454a1e29f28848ed140c70be85cdea9f99a8dc347deabd46d362ed1afb231146a0255d");
testKatHex(new Keccak512(),
"1861edce46fa5ad17e1ff1deae084dec580f97d0a67885dfe834b9dfac1ae076742ce9e267512ca51f6df5a455af0c5fd6abf94acea103a3370c354485a7846fb84f3ac7c2904b5b2fbf227002ce512133bb7e1c4e50057bfd1e44db33c7cdb969a99e284b184f50a14b068a1fc5009d9b298dbe92239572a7627aac02abe8f3e3b473417f36d4d2505d16b7577f4526c9d94a270a2dfe450d06da8f6fa956879a0a55cfe99e742ea555ea477ba3e9b44ccd508c375423611af92e55345dc215779b2d5119eba49c71d49b9fe3f1569fa24e5ca3e332d042422a8b8158d3ec66a80012976f31ffdf305f0c9c5e",
"b50c896f2cdf7f105de751ff6cf664e592fab752d652b06898b9b288052df22f721ad87e702af043e6b1e88929850cbd5698a9172c3932400b2538e401a6f081");
testKatHex(new Keccak512(),
"08d0ffde3a6e4ef65608ea672e4830c12943d7187ccff08f4941cfc13e545f3b9c7ad5eebbe2b01642b486caf855c2c73f58c1e4e3391da8e2d63d96e15fd84953ae5c231911b00ad6050cd7aafdaac9b0f663ae6aab45519d0f5391a541707d479034e73a6ad805ae3598096af078f1393301493d663dd71f83869ca27ba508b7e91e81e128c1716dc3acfe3084b2201e04cf8006617eecf1b640474a5d45cfde9f4d3ef92d6d055b909892194d8a8218db6d8203a84261d200d71473d7488f3427416b6896c137d455f231071cacbc86e0415ab88aec841d96b7b8af41e05bb461a40645bf176601f1e760de5f",
"a34a2f27c32f993a7e7007867733547481293c391255ffd0e5ccbe91e1cc749b13525af6adfa0c2d1d64bf87dd65b996ada9111c5df55bff8a5742e54b8444f6");
testKatHex(new Keccak512(),
"d782abb72a5be3392757be02d3e45be6e2099d6f000d042c8a543f50ed6ebc055a7f133b0dd8e9bc348536edcaae2e12ec18e8837df7a1b3c87ec46d50c241dee820fd586197552dc20beea50f445a07a38f1768a39e2b2ff05dddedf751f1def612d2e4d810daa3a0cc904516f9a43af660315385178a529e51f8aae141808c8bc5d7b60cac26bb984ac1890d0436ef780426c547e94a7b08f01acbfc4a3825eae04f520a9016f2fb8bf5165ed12736fc71e36a49a73614739eaa3ec834069b1b40f1350c2b3ab885c02c640b9f7686ed5f99527e41cfcd796fe4c256c9173186c226169ff257954ebda81c0e5f99",
"dd5f4b167175d9566dca6c5b1b54a33d02efd02e25e23bb6fb02d878a4415e5e8682c209beac04e9882a272d01e8eb435caa5bcd74fc825c6b9082d041dff333");
testKatHex(new Keccak512(),
"5fce8109a358570e40983e1184e541833bb9091e280f258cfb144387b05d190e431cb19baa67273ba0c58abe91308e1844dcd0b3678baa42f335f2fa05267a0240b3c718a5942b3b3e3bfa98a55c25a1466e8d7a603722cb2bbf03afa54cd769a99f310735ee5a05dae2c22d397bd95635f58c48a67f90e1b73aafcd3f82117f0166657838691005b18da6f341d6e90fc1cdb352b30fae45d348294e501b63252de14740f2b85ae5299ddec3172de8b6d0ba219a20a23bb5e10ff434d39db3f583305e9f5c039d98569e377b75a70ab837d1df269b8a4b566f40bb91b577455fd3c356c914fa06b9a7ce24c7317a172d",
"a43ae5dad936697564ae1bd9b8624c5c31cc36607322af40e253f10c285467afd0d08252d2bad76efa52e4775c9c26761abe38212855a80112fe02623fbf0a13");
testKatHex(new Keccak512(),
"6172f1971a6e1e4e6170afbad95d5fec99bf69b24b674bc17dd78011615e502de6f56b86b1a71d3f4348087218ac7b7d09302993be272e4a591968aef18a1262d665610d1070ee91cc8da36e1f841a69a7a682c580e836941d21d909a3afc1f0b963e1ca5ab193e124a1a53df1c587470e5881fb54dae1b0d840f0c8f9d1b04c645ba1041c7d8dbf22030a623aa15638b3d99a2c400ff76f3252079af88d2b37f35ee66c1ad7801a28d3d388ac450b97d5f0f79e4541755356b3b1a5696b023f39ab7ab5f28df4202936bc97393b93bc915cb159ea1bd7a0a414cb4b7a1ac3af68f50d79f0c9c7314e750f7d02faa58bfa",
"a5ac23d4a0d533cb9d8a68873f5cb749228458d43ce6bd0536c8733777b5e6e3f28fd36bffe69002a0777ba74fef22de3fac4c818b4842816c6094496f968555");
testKatHex(new Keccak512(),
"5668ecd99dfbe215c4118398ac9c9eaf1a1433fab4ccdd3968064752b625ea944731f75d48a27d047d67547f14dd0ffaa55fa5e29f7af0d161d85eafc4f2029b717c918eab9d304543290bdba7158b68020c0ba4e079bc95b5bc0fc044a992b94b4ccd3bd66d0eabb5dbbab904d62e00752c4e3b0091d773bcf4c14b4377da3efff824b1cb2fa01b32d1e46c909e626ed2dae920f4c7dbeb635bc754facbd8d49beba3f23c1c41ccbfcd0ee0c114e69737f5597c0bf1d859f0c767e18002ae8e39c26261ffde2920d3d0baf0e906138696cfe5b7e32b600f45df3aaa39932f3a7df95b60fa8712a2271fcaf3911ce7b511b1",
"07f3bcacf5f78816d515cedf1cbba4ffc58d83aa8687b0e7252faab43e7f59a7ff7415727addf9a22560adb5755a2c6df8c7e6dcaceb53106a714d807aaadbf3");
testKatHex(new Keccak512(),
"03d625488354df30e3f875a68edfcf340e8366a8e1ab67f9d5c5486a96829dfac0578289082b2a62117e1cf418b43b90e0adc881fc6ae8105c888e9ecd21aea1c9ae1a4038dfd17378fed71d02ae492087d7cdcd98f746855227967cb1ab4714261ee3bead3f4db118329d3ebef4bc48a875c19ba763966da0ebea800e01b2f50b00e9dd4caca6dcb314d00184ef71ea2391d760c950710db4a70f9212ffc54861f9dc752ce18867b8ad0c48df8466ef7231e7ac567f0eb55099e622ebb86cb237520190a61c66ad34f1f4e289cb3282ae3eaac6152ed24d2c92bae5a7658252a53c49b7b02dfe54fdb2e90074b6cf310ac661",
"13a592b73ede487036c8816bd6fc6cdc04dc6133409a6ee990584160518f9ef573264cf04d38a3ba75d150f4f026f6df8936e13c8f4f3ecc9ecbc43fdfc488a4");
testKatHex(new Keccak512(),
"2edc282ffb90b97118dd03aaa03b145f363905e3cbd2d50ecd692b37bf000185c651d3e9726c690d3773ec1e48510e42b17742b0b0377e7de6b8f55e00a8a4db4740cee6db0830529dd19617501dc1e9359aa3bcf147e0a76b3ab70c4984c13e339e6806bb35e683af8527093670859f3d8a0fc7d493bcba6bb12b5f65e71e705ca5d6c948d66ed3d730b26db395b3447737c26fad089aa0ad0e306cb28bf0acf106f89af3745f0ec72d534968cca543cd2ca50c94b1456743254e358c1317c07a07bf2b0eca438a709367fafc89a57239028fc5fecfd53b8ef958ef10ee0608b7f5cb9923ad97058ec067700cc746c127a61ee3",
"c2fb590ab74e230b8fe159892f94de04ef7adaa02b918d4994f996538d257f5a80c9b3be8f410170b0c5cac3f507401220881c5e08d8bf0a13247170d39085bc");
testKatHex(new Keccak512(),
"90b28a6aa1fe533915bcb8e81ed6cacdc10962b7ff82474f845eeb86977600cf70b07ba8e3796141ee340e3fce842a38a50afbe90301a3bdcc591f2e7d9de53e495525560b908c892439990a2ca2679c5539ffdf636777ad9c1cdef809cda9e8dcdb451abb9e9c17efa4379abd24b182bd981cafc792640a183b61694301d04c5b3eaad694a6bd4cc06ef5da8fa23b4fa2a64559c5a68397930079d250c51bcf00e2b16a6c49171433b0aadfd80231276560b80458dd77089b7a1bbcc9e7e4b9f881eacd6c92c4318348a13f4914eb27115a1cfc5d16d7fd94954c3532efaca2cab025103b2d02c6fd71da3a77f417d7932685888a",
"02951596a13a1a41188a4a1d6346f7eafb60a2051ea67c63237d1a9b79ec4733f33ecec223dedd946b78387b6f2df5e9ab6af7dfbabaf80f4fcc94fa087275e8");
testKatHex(new Keccak512(),
"2969447d175490f2aa9bb055014dbef2e6854c95f8d60950bfe8c0be8de254c26b2d31b9e4de9c68c9adf49e4ee9b1c2850967f29f5d08738483b417bb96b2a56f0c8aca632b552059c59aac3f61f7b45c966b75f1d9931ff4e596406378cee91aaa726a3a84c33f37e9cdbe626b5745a0b06064a8a8d56e53aaf102d23dd9df0a3fdf7a638509a6761a33fa42fa8ddbd8e16159c93008b53765019c3f0e9f10b144ce2ac57f5d7297f9c9949e4ff68b70d339f87501ce8550b772f32c6da8ad2ce2100a895d8b08fa1eead7c376b407709703c510b50f87e73e43f8e7348f87c3832a547ef2bbe5799abedcf5e1f372ea809233f006",
"5aa4e32f0ea3e853929bf64acc9565a01300bc007063b939f6dbbe9cae0545ea95fbcac32575aa0727ee4d937071e6b3be74e23fe76fd63ec05c7f7d8a407af0");
testKatHex(new Keccak512(),
"721645633a44a2c78b19024eaecf58575ab23c27190833c26875dc0f0d50b46aea9c343d82ea7d5b3e50ec700545c615daeaea64726a0f05607576dcd396d812b03fb6551c641087856d050b10e6a4d5577b82a98afb89cee8594c9dc19e79feff0382fcfd127f1b803a4b9946f4ac9a4378e1e6e041b1389a53e3450cd32d9d2941b0cbabdb50da8ea2513145164c3ab6bcbd251c448d2d4b087ac57a59c2285d564f16da4ed5e607ed979592146ffb0ef3f3db308fb342df5eb5924a48256fc763141a278814c82d6d6348577545870ae3a83c7230ac02a1540fe1798f7ef09e335a865a2ae0949b21e4f748fb8a51f44750e213a8fb",
"495b2aa2103159d9a937e9dd56b059aca98a5e3cb7b59bb690dedc00c692e9d7a18614a73d12e07634b209cc630d1818b09f1076a941ff80474493e3d42b9812");
testKatHex(new Keccak512(),
"6b860d39725a14b498bb714574b4d37ca787404768f64c648b1751b353ac92bac2c3a28ea909fdf0423336401a02e63ec24325300d823b6864bb701f9d7c7a1f8ec9d0ae3584aa6dd62ea1997cd831b4babd9a4da50932d4efda745c61e4130890e156aee6113716daf95764222a91187db2effea49d5d0596102d619bd26a616bbfda8335505fbb0d90b4c180d1a2335b91538e1668f9f9642790b4e55f9cab0fe2bdd2935d001ee6419abab5457880d0dbff20ed8758f4c20fe759efb33141cf0e892587fe8187e5fbc57786b7e8b089612c936dfc03d27efbbe7c8673f1606bd51d5ff386f4a7ab68edf59f385eb1291f117bfe717399",
"217b5a985bed80008274470e254443238c5aeacbc7ee2289f0e63b7afe6d0f395e2361fd6d9dc33b4f54f03ff56f6b264976161d80091788ee9d262f147a35fc");
testKatHex(new Keccak512(),
"6a01830af3889a25183244decb508bd01253d5b508ab490d3124afbf42626b2e70894e9b562b288d0a2450cfacf14a0ddae5c04716e5a0082c33981f6037d23d5e045ee1ef2283fb8b6378a914c5d9441627a722c282ff452e25a7ea608d69cee4393a0725d17963d0342684f255496d8a18c2961145315130549311fc07f0312fb78e6077334f87eaa873bee8aa95698996eb21375eb2b4ef53c14401207deb4568398e5dd9a7cf97e8c9663e23334b46912f8344c19efcf8c2ba6f04325f1a27e062b62a58d0766fc6db4d2c6a1928604b0175d872d16b7908ebc041761187cc785526c2a3873feac3a642bb39f5351550af9770c328af7b",
"293c551e753bba7f314dcb93a0fad94f3f5dee6ed45d765a708e6fd277601f03f6c905d7e1eaeaec513cbbbd672b817f6d60fbf02c20167d7f4b7b84afeeb3f6");
testKatHex(new Keccak512(),
"b3c5e74b69933c2533106c563b4ca20238f2b6e675e8681e34a389894785bdade59652d4a73d80a5c85bd454fd1e9ffdad1c3815f5038e9ef432aac5c3c4fe840cc370cf86580a6011778bbedaf511a51b56d1a2eb68394aa299e26da9ada6a2f39b9faff7fba457689b9c1a577b2a1e505fdf75c7a0a64b1df81b3a356001bf0df4e02a1fc59f651c9d585ec6224bb279c6beba2966e8882d68376081b987468e7aed1ef90ebd090ae825795cdca1b4f09a979c8dfc21a48d8a53cdbb26c4db547fc06efe2f9850edd2685a4661cb4911f165d4b63ef25b87d0a96d3dff6ab0758999aad214d07bd4f133a6734fde445fe474711b69a98f7e2b",
"89fe6314a0246eff3bfd07a95fe239bd5071467f53799175b226daf6c3db618cad4ca1c1af64bf5793f03254f560e6335beaaa86bcb9e961f214b2ae97b47af0");
testKatHex(new Keccak512(),
"83af34279ccb5430febec07a81950d30f4b66f484826afee7456f0071a51e1bbc55570b5cc7ec6f9309c17bf5befdd7c6ba6e968cf218a2b34bd5cf927ab846e38a40bbd81759e9e33381016a755f699df35d660007b5eadf292feefb735207ebf70b5bd17834f7bfa0e16cb219ad4af524ab1ea37334aa66435e5d397fc0a065c411ebbce32c240b90476d307ce802ec82c1c49bc1bec48c0675ec2a6c6f3ed3e5b741d13437095707c565e10d8a20b8c20468ff9514fcf31b4249cd82dcee58c0a2af538b291a87e3390d737191a07484a5d3f3fb8c8f15ce056e5e5f8febe5e1fb59d6740980aa06ca8a0c20f5712b4cde5d032e92ab89f0ae1",
"7690f703e894ee22d4dff55a7f8d5021d5f17b729f95a59c4d55cfb225c67be105f2e7cdf56d140e566648e9e9c39bbed96f985a6dae1f21d8ba500f7fd40edf");
testKatHex(new Keccak512(),
"a7ed84749ccc56bb1dfba57119d279d412b8a986886d810f067af349e8749e9ea746a60b03742636c464fc1ee233acc52c1983914692b64309edfdf29f1ab912ec3e8da074d3f1d231511f5756f0b6eead3e89a6a88fe330a10face267bffbfc3e3090c7fd9a850561f363ad75ea881e7244f80ff55802d5ef7a1a4e7b89fcfa80f16df54d1b056ee637e6964b9e0ffd15b6196bdd7db270c56b47251485348e49813b4eb9ed122a01b3ea45ad5e1a929df61d5c0f3e77e1fdc356b63883a60e9cbb9fc3e00c2f32dbd469659883f690c6772e335f617bc33f161d6f6984252ee12e62b6000ac5231e0c9bc65be223d8dfd94c5004a101af9fd6c0fb",
"65e415c7958a47fca9eed3846fd1283afeb38e5130f57ecd99dcb21bedda856e3b5fb9f839e579c5ea386eaca8cdc0a9549eaaf6ec452dd6cb5212b709bf5c59");
testKatHex(new Keccak512(),
"a6fe30dcfcda1a329e82ab50e32b5f50eb25c873c5d2305860a835aecee6264aa36a47429922c4b8b3afd00da16035830edb897831c4e7b00f2c23fc0b15fdc30d85fb70c30c431c638e1a25b51caf1d7e8b050b7f89bfb30f59f0f20fecff3d639abc4255b3868fc45dd81e47eb12ab40f2aac735df5d1dc1ad997cefc4d836b854cee9ac02900036f3867fe0d84afff37bde3308c2206c62c4743375094108877c73b87b2546fe05ea137bedfc06a2796274099a0d554da8f7d7223a48cbf31b7decaa1ebc8b145763e3673168c1b1b715c1cd99ecd3ddb238b06049885ecad9347c2436dff32c771f34a38587a44a82c5d3d137a03caa27e66c8ff6",
"d6542a2f0654b9b874a627d3d53764a65b1df2c0cec3bcd0b4b088faa1095e54f1799757c4371f8d544e298d600e21e11b2f90d295712621231a09c58b05a704");
testKatHex(new Keccak512(),
"83167ff53704c3aa19e9fb3303539759c46dd4091a52ddae9ad86408b69335989e61414bc20ab4d01220e35241eff5c9522b079fba597674c8d716fe441e566110b6211531ceccf8fd06bc8e511d00785e57788ed9a1c5c73524f01830d2e1148c92d0edc97113e3b7b5cd3049627abdb8b39dd4d6890e0ee91993f92b03354a88f52251c546e64434d9c3d74544f23fb93e5a2d2f1fb15545b4e1367c97335b0291944c8b730ad3d4789273fa44fb98d78a36c3c3764abeeac7c569c1e43a352e5b770c3504f87090dee075a1c4c85c0c39cf421bdcc615f9eff6cb4fe6468004aece5f30e1ecc6db22ad9939bb2b0ccc96521dfbf4ae008b5b46bc006e",
"ec983e787628b94c87fff8d57d2d058667d12f5af458bce79bb7844fb41d9c55920f593c8d8730eb8d54ff1d51cd8ad2f1c2a0f7d6b299a21266744e47d142b2");
testKatHex(new Keccak512(),
"3a3a819c48efde2ad914fbf00e18ab6bc4f14513ab27d0c178a188b61431e7f5623cb66b23346775d386b50e982c493adbbfc54b9a3cd383382336a1a0b2150a15358f336d03ae18f666c7573d55c4fd181c29e6ccfde63ea35f0adf5885cfc0a3d84a2b2e4dd24496db789e663170cef74798aa1bbcd4574ea0bba40489d764b2f83aadc66b148b4a0cd95246c127d5871c4f11418690a5ddf01246a0c80a43c70088b6183639dcfda4125bd113a8f49ee23ed306faac576c3fb0c1e256671d817fc2534a52f5b439f72e424de376f4c565cca82307dd9ef76da5b7c4eb7e085172e328807c02d011ffbf33785378d79dc266f6a5be6bb0e4a92eceebaeb1",
"81950e7096d31d4f22e3db71cac725bf59e81af54c7ca9e6aeee71c010fc5467466312a01aa5c137cfb140646941556796f612c9351268737c7e9a2b9631d1fa");
}
}
| 118,187
| 141.566948
| 525
|
java
|
ethereumj
|
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/crypto/cryptohash/AbstractCryptoTest.java
|
/*
* Copyright (c) [2016] [ <ether.camp> ]
* This file is part of the ethereumJ library.
*
* The ethereumJ library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The ethereumJ library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the ethereumJ library. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* Copyright (c) 2014, Stephan Fuhrmann <stephan@tynne.de>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package org.ethereum.crypto.cryptohash;
import org.spongycastle.util.encoders.Hex;
import static org.junit.Assert.*;
/**
* Generic test utility class that gets extended from the digest test
* classes.
* @author Stephan Fuhrmann <stephan@tynne.de>
*/
public class AbstractCryptoTest {
protected void testKatHex(Digest dig, String data, String ref) {
testFrom(dig, Hex.decode(data), Hex.decode(ref));
}
/** Does the comparison using the digest and some calls on it.
* @param digest the digest to operate on.
* @param message the input data to pass to the digest.
* @param expected the expected data out of the digest.
*/
private static void testFrom(Digest digest, byte[] message, byte[] expected) {
/*
* First test the hashing itself.
*/
byte[] out = digest.digest(message);
assertArrayEquals(expected, out);
/*
* Now the update() API; this also exercises auto-reset.
*/
for (int i = 0; i < message.length; i++) {
digest.update(message[i]);
}
assertArrayEquals(expected, digest.digest());
/*
* The cloning API.
*/
int blen = message.length;
digest.update(message, 0, blen / 2);
Digest dig2 = digest.copy();
digest.update(message, blen / 2, blen - (blen / 2));
assertArrayEquals(expected, digest.digest());
dig2.update(message, blen / 2, blen - (blen / 2));
assertArrayEquals(expected, dig2.digest());
}
}
| 3,740
| 40.10989
| 82
|
java
|
ethereumj
|
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/crypto/cryptohash/Keccak256Test.java
|
/*
* Copyright (c) [2016] [ <ether.camp> ]
* This file is part of the ethereumJ library.
*
* The ethereumJ library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The ethereumJ library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the ethereumJ library. If not, see <http://www.gnu.org/licenses/>.
*/
package org.ethereum.crypto.cryptohash;
import org.junit.Test;
/**
* This class is a program entry point; it includes tests for the
* implementation of the hash functions.
*
* <pre>
* ==========================(LICENSE BEGIN)============================
*
* Copyright (c) 2007-2010 Projet RNRT SAPHIR
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* ===========================(LICENSE END)=============================
* </pre>
*
* @version $Revision: 257 $
* @author Thomas Pornin <thomas.pornin@cryptolog.com>
*/
public class Keccak256Test extends AbstractCryptoTest {
@Test
public void testKeccak256() {
testKatHex(new Keccak256(),
"",
"c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470");
testKatHex(new Keccak256(),
"cc",
"eead6dbfc7340a56caedc044696a168870549a6a7f6f56961e84a54bd9970b8a");
testKatHex(new Keccak256(),
"41fb",
"a8eaceda4d47b3281a795ad9e1ea2122b407baf9aabcb9e18b5717b7873537d2");
testKatHex(new Keccak256(),
"1f877c",
"627d7bc1491b2ab127282827b8de2d276b13d7d70fb4c5957fdf20655bc7ac30");
testKatHex(new Keccak256(),
"c1ecfdfc",
"b149e766d7612eaf7d55f74e1a4fdd63709a8115b14f61fcd22aa4abc8b8e122");
testKatHex(new Keccak256(),
"21f134ac57",
"67f05544dbe97d5d6417c1b1ea9bc0e3a99a541381d1cd9b08a9765687eb5bb4");
testKatHex(new Keccak256(),
"c6f50bb74e29",
"923062c4e6f057597220d182dbb10e81cd25f60b54005b2a75dd33d6dac518d0");
testKatHex(new Keccak256(),
"119713cc83eeef",
"feb8405dcd315d48c6cbf7a3504996de8e25cc22566efec67433712eda99894f");
testKatHex(new Keccak256(),
"4a4f202484512526",
"e620d8f2982b24fedaaa3baa9b46c3f9ce204ee356666553ecb35e15c3ff9bf9");
testKatHex(new Keccak256(),
"1f66ab4185ed9b6375",
"9e03f7c9a3d055eca1d786ed6fb624d93f1cf0ac27f9c2b6c05e509fac9e7fca");
testKatHex(new Keccak256(),
"eed7422227613b6f53c9",
"caad8e1ed546630748a12f5351b518a9a431cda6ba56cbfc3ccbdd8aae5092f7");
testKatHex(new Keccak256(),
"eaeed5cdffd89dece455f1",
"d61708bdb3211a9aab28d4df01dfa4b29ed40285844d841042257e97488617b0");
testKatHex(new Keccak256(),
"5be43c90f22902e4fe8ed2d3",
"0f53be55990780b3fad9870f04f7d8153c3ae605c057c85abb5d71765043aaa8");
testKatHex(new Keccak256(),
"a746273228122f381c3b46e4f1",
"32215ae88204a782b62d1810d945de49948de458600f5e1e3896ceca2ed3292b");
testKatHex(new Keccak256(),
"3c5871cd619c69a63b540eb5a625",
"9510da68e58ebb8d2ab9de8485bb408e358299a9c011ae8544b0d0faf9d4a4ea");
testKatHex(new Keccak256(),
"fa22874bcc068879e8ef11a69f0722",
"f20b3bcf743aa6fa084038520791c364cb6d3d1dd75841f8d7021cd98322bd8f");
testKatHex(new Keccak256(),
"52a608ab21ccdd8a4457a57ede782176",
"0e32defa2071f0b5ac0e6a108b842ed0f1d3249712f58ee0ddf956fe332a5f95");
testKatHex(new Keccak256(),
"82e192e4043ddcd12ecf52969d0f807eed",
"9204550677b9aa770e6e93e319b9958540d54ff4dccb063c8561302cd8aff676");
testKatHex(new Keccak256(),
"75683dcb556140c522543bb6e9098b21a21e",
"a6d5444cb7aa61f5106cdedb39d5e1dd7d608f102798d7e818ac87289123a1db");
testKatHex(new Keccak256(),
"06e4efe45035e61faaf4287b4d8d1f12ca97e5",
"5796b993d0bd1257cf26782b4e58fafb22b0986d88684ab5a2e6cec6706275f9");
testKatHex(new Keccak256(),
"e26193989d06568fe688e75540aea06747d9f851",
"cfbe73c6585be6204dd473abe356b539477174c4b770bfc91e9fdbcbc57086e6");
testKatHex(new Keccak256(),
"d8dc8fdefbdce9d44e4cbafe78447bae3b5436102a",
"31c8006b0ec35e690674297cb27476db6066b5fa9825c60728e9e0bb338fb7c3");
testKatHex(new Keccak256(),
"57085fd7e14216ab102d8317b0cb338a786d5fc32d8f",
"3b8fa3904fe1b837565a50d0fbf03e487d6d72fc3cea41adcce33df1b835d247");
testKatHex(new Keccak256(),
"a05404df5dbb57697e2c16fa29defac8ab3560d6126fa0",
"37febc4df9d50daeabd0caa6578812a687e55f1ac0b109d2512810d00548c85b");
testKatHex(new Keccak256(),
"aecbb02759f7433d6fcb06963c74061cd83b5b3ffa6f13c6",
"2329810b5a4735bcd49c10e6456c0b1ded5eac258af47cbb797ca162ab6d1ba8");
testKatHex(new Keccak256(),
"aafdc9243d3d4a096558a360cc27c8d862f0be73db5e88aa55",
"6fffa070b865be3ee766dc2db49b6aa55c369f7de3703ada2612d754145c01e6");
testKatHex(new Keccak256(),
"7bc84867f6f9e9fdc3e1046cae3a52c77ed485860ee260e30b15",
"b30761c053e926f150b9dce7e005b4d87811ccfb9e3b6edb0221022f01711cf0");
testKatHex(new Keccak256(),
"fac523575a99ec48279a7a459e98ff901918a475034327efb55843",
"04f1b3c1e25ba5d012e22ad144e5a8719d94322d05ad9ef61e7db49b59959b3a");
testKatHex(new Keccak256(),
"0f8b2d8fcfd9d68cffc17ccfb117709b53d26462a3f346fb7c79b85e",
"aeef4b4da420834ffced26db291248fb2d01e765e2b0564057f8e6c2030ac37f");
testKatHex(new Keccak256(),
"a963c3e895ff5a0be4824400518d81412f875fa50521e26e85eac90c04",
"03d26aeeb4a7bdddbff7cff667198c425941a2776922df2bec545f5304e2c61c");
testKatHex(new Keccak256(),
"03a18688b10cc0edf83adf0a84808a9718383c4070c6c4f295098699ac2c",
"435cfc0d1afd8d5509a9ccbf49706575038685bf08db549d9714548240463ee9");
testKatHex(new Keccak256(),
"84fb51b517df6c5accb5d022f8f28da09b10232d42320ffc32dbecc3835b29",
"d477fb02caaa95b3280ec8ee882c29d9e8a654b21ef178e0f97571bf9d4d3c1c");
testKatHex(new Keccak256(),
"9f2fcc7c90de090d6b87cd7e9718c1ea6cb21118fc2d5de9f97e5db6ac1e9c10",
"24dd2ee02482144f539f810d2caa8a7b75d0fa33657e47932122d273c3f6f6d1");
testKatHex(new Keccak256(),
"de8f1b3faa4b7040ed4563c3b8e598253178e87e4d0df75e4ff2f2dedd5a0be046",
"e78c421e6213aff8de1f025759a4f2c943db62bbde359c8737e19b3776ed2dd2");
testKatHex(new Keccak256(),
"62f154ec394d0bc757d045c798c8b87a00e0655d0481a7d2d9fb58d93aedc676b5a0",
"cce3e3d498328a4d9c5b4dbf9a1209628ab82621ad1a0d0a18680362889e6164");
testKatHex(new Keccak256(),
"b2dcfe9ff19e2b23ce7da2a4207d3e5ec7c6112a8a22aec9675a886378e14e5bfbad4e",
"f871db93c5c92ecd65d4edb96fcb12e4729bc2a1899f7fb029f50bff431cbb72");
testKatHex(new Keccak256(),
"47f5697ac8c31409c0868827347a613a3562041c633cf1f1f86865a576e02835ed2c2492",
"4eb143477431df019311aed936cab91a912ec1e6868b71e9eddb777408d4af34");
testKatHex(new Keccak256(),
"512a6d292e67ecb2fe486bfe92660953a75484ff4c4f2eca2b0af0edcdd4339c6b2ee4e542",
"9a0c1d50a59dbf657f6713c795ed14e1f23b4eaa137c5540aacdb0a7e32c29fc");
testKatHex(new Keccak256(),
"973cf2b4dcf0bfa872b41194cb05bb4e16760a1840d8343301802576197ec19e2a1493d8f4fb",
"ba062e5d370216d11985c4ca7a2658ddc7328b4be4b40a52dd8fa3ca662f09d1");
testKatHex(new Keccak256(),
"80beebcd2e3f8a9451d4499961c9731ae667cdc24ea020ce3b9aa4bbc0a7f79e30a934467da4b0",
"3a083ae163df42bd51b9c664bee9dc4362f16e63383df16473df71be6dd40c1c");
testKatHex(new Keccak256(),
"7abaa12ec2a7347674e444140ae0fb659d08e1c66decd8d6eae925fa451d65f3c0308e29446b8ed3",
"4876e273ac00942576d9608d5b63ecc9a3e75d5e0c42c6abdbcde037785af9a7");
testKatHex(new Keccak256(),
"c88dee9927679b8af422abcbacf283b904ff31e1cac58c7819809f65d5807d46723b20f67ba610c2b7",
"4797ba1c7ab7197050d6b2e506f2df4550e4b673df78f18c465424e48df5e997");
testKatHex(new Keccak256(),
"01e43fe350fcec450ec9b102053e6b5d56e09896e0ddd9074fe138e6038210270c834ce6eadc2bb86bf6",
"41c91be98c5813a4c5d8ae7c29b9919c1cc95b4a05f82433948cb99d9a6d039c");
testKatHex(new Keccak256(),
"337023370a48b62ee43546f17c4ef2bf8d7ecd1d49f90bab604b839c2e6e5bd21540d29ba27ab8e309a4b7",
"ee354290e3f9ce9123c49ba616e1a2684a90f3ddd84e73a1d2c232f740412b18");
testKatHex(new Keccak256(),
"6892540f964c8c74bd2db02c0ad884510cb38afd4438af31fc912756f3efec6b32b58ebc38fc2a6b913596a8",
"fbec0b6d71696eede900b77aa6d7d25f4ab45df8961ca9c8b3f4f9b51af983ab");
testKatHex(new Keccak256(),
"f5961dfd2b1ffffda4ffbf30560c165bfedab8ce0be525845deb8dc61004b7db38467205f5dcfb34a2acfe96c0",
"9d24aeea08f9a4b5fb8b6de85a2296f5f4108ddd1eea4f8ee58819cf84edb765");
testKatHex(new Keccak256(),
"ca061a2eb6ceed8881ce2057172d869d73a1951e63d57261384b80ceb5451e77b06cf0f5a0ea15ca907ee1c27eba",
"732034cae3ff1116f07fc18b5a26ef8faf3fe75d3dbca05e48795365e0a17c40");
testKatHex(new Keccak256(),
"1743a77251d69242750c4f1140532cd3c33f9b5ccdf7514e8584d4a5f9fbd730bcf84d0d4726364b9bf95ab251d9bb",
"deac521805bc6a97c0870e9e225d1c4b2fd8f3a9a7f6b39e357c26414821e2dd");
testKatHex(new Keccak256(),
"d8faba1f5194c4db5f176fabfff856924ef627a37cd08cf55608bba8f1e324d7c7f157298eabc4dce7d89ce5162499f9",
"ad55537347b20d9fca02683e6de1032ec10eb84da4cbd501e49744a666292edf");
testKatHex(new Keccak256(),
"be9684be70340860373c9c482ba517e899fc81baaa12e5c6d7727975d1d41ba8bef788cdb5cf4606c9c1c7f61aed59f97d",
"b1f990204bf630569a3edc634864274786f40ce1c57165ee32d0e29f5d0c6851");
testKatHex(new Keccak256(),
"7e15d2b9ea74ca60f66c8dfab377d9198b7b16deb6a1ba0ea3c7ee2042f89d3786e779cf053c77785aa9e692f821f14a7f51",
"fa460cd51bc611786d364fcabe39052bcd5f009edfa81f4701c5b22b729b0016");
testKatHex(new Keccak256(),
"9a219be43713bd578015e9fda66c0f2d83cac563b776ab9f38f3e4f7ef229cb443304fba401efb2bdbd7ece939102298651c86",
"f7b0fe5a69ff44060d4f6ad2486e6cde9ed679af9aa1ada613e4cc392442beb5");
testKatHex(new Keccak256(),
"c8f2b693bd0d75ef99caebdc22adf4088a95a3542f637203e283bbc3268780e787d68d28cc3897452f6a22aa8573ccebf245972a",
"24204d491f202534859fc0a208237184471a2d801fb3b934d0968d0d843d0345");
testKatHex(new Keccak256(),
"ec0f99711016c6a2a07ad80d16427506ce6f441059fd269442baaa28c6ca037b22eeac49d5d894c0bf66219f2c08e9d0e8ab21de52",
"81147cba0647eee78c4784874c0557621a138ca781fb6f5dcd0d9c609af56f35");
testKatHex(new Keccak256(),
"0dc45181337ca32a8222fe7a3bf42fc9f89744259cff653504d6051fe84b1a7ffd20cb47d4696ce212a686bb9be9a8ab1c697b6d6a33",
"5b6d7eda559574fae882e6266f4c2be362133e44b5a947ecb6e75db9fc8567e0");
testKatHex(new Keccak256(),
"de286ba4206e8b005714f80fb1cdfaebde91d29f84603e4a3ebc04686f99a46c9e880b96c574825582e8812a26e5a857ffc6579f63742f",
"86f87e75c87f9be39e4aa6d0c5a37a5964d6ffdc462525c0642c9db010de38ee");
testKatHex(new Keccak256(),
"eebcc18057252cbf3f9c070f1a73213356d5d4bc19ac2a411ec8cdeee7a571e2e20eaf61fd0c33a0ffeb297ddb77a97f0a415347db66bcaf",
"959fe007b57c2947c36d1d66cc0808d80db7df45d68a34852b70d2dda192c25c");
testKatHex(new Keccak256(),
"416b5cdc9fe951bd361bd7abfc120a5054758eba88fdd68fd84e39d3b09ac25497d36b43cbe7b85a6a3cebda8db4e5549c3ee51bb6fcb6ac1e",
"1a93567eebc41cc44d9346cde646005d3e82de8eeeb131e9c1f6d1e4afd260f7");
testKatHex(new Keccak256(),
"5c5faf66f32e0f8311c32e8da8284a4ed60891a5a7e50fb2956b3cbaa79fc66ca376460e100415401fc2b8518c64502f187ea14bfc9503759705",
"549db056b65edf7d05bd66661b6d0a39b29b825bc80910f8bf7060a53bff68e1");
testKatHex(new Keccak256(),
"7167e1e02be1a7ca69d788666f823ae4eef39271f3c26a5cf7cee05bca83161066dc2e217b330df821103799df6d74810eed363adc4ab99f36046a",
"794abfd7eb622d5608c1c7b3f0a7821a71900b7172847fb0907aa2899972663e");
testKatHex(new Keccak256(),
"2fda311dbba27321c5329510fae6948f03210b76d43e7448d1689a063877b6d14c4f6d0eaa96c150051371f7dd8a4119f7da5c483cc3e6723c01fb7d",
"9ce89958cbddd8dcb22f66e8cba5f6091a51953189464803bdc773abc7faa906");
testKatHex(new Keccak256(),
"95d1474a5aab5d2422aca6e481187833a6212bd2d0f91451a67dd786dfc91dfed51b35f47e1deb8a8ab4b9cb67b70179cc26f553ae7b569969ce151b8d",
"6da733817dc826e8da773beca7338131ab7396417104eda25970980c4eb2a15f");
testKatHex(new Keccak256(),
"c71bd7941f41df044a2927a8ff55b4b467c33d089f0988aa253d294addbdb32530c0d4208b10d9959823f0c0f0734684006df79f7099870f6bf53211a88d",
"66c9cdc8e8c6c9417d7ffbef3b54b702eee5f01a9bda8dd4e28fe3335debbb51");
testKatHex(new Keccak256(),
"f57c64006d9ea761892e145c99df1b24640883da79d9ed5262859dcda8c3c32e05b03d984f1ab4a230242ab6b78d368dc5aaa1e6d3498d53371e84b0c1d4ba",
"24ab37a93674ccb1ceec9e5681efc8bdf9fcc7721cf1cac175e0b20e461575b8");
testKatHex(new Keccak256(),
"e926ae8b0af6e53176dbffcc2a6b88c6bd765f939d3d178a9bde9ef3aa131c61e31c1e42cdfaf4b4dcde579a37e150efbef5555b4c1cb40439d835a724e2fae7",
"574271cd13959e8ddeae5bfbdb02a3fdf54f2babfd0cbeb893082a974957d0c1");
testKatHex(new Keccak256(),
"16e8b3d8f988e9bb04de9c96f2627811c973ce4a5296b4772ca3eefeb80a652bdf21f50df79f32db23f9f73d393b2d57d9a0297f7a2f2e79cfda39fa393df1ac00",
"1947e901fa59ea789845775f2a4db9b4848f8a776073d53d84cbd5d927a96bff");
testKatHex(new Keccak256(),
"fc424eeb27c18a11c01f39c555d8b78a805b88dba1dc2a42ed5e2c0ec737ff68b2456d80eb85e11714fa3f8eabfb906d3c17964cb4f5e76b29c1765db03d91be37fc",
"0c1b8c1af237e9c5501b50316a80865aac08a34acf4f8bedd4a2d6e7b7bcbb85");
testKatHex(new Keccak256(),
"abe3472b54e72734bdba7d9158736464251c4f21b33fbbc92d7fac9a35c4e3322ff01d2380cbaa4ef8fb07d21a2128b7b9f5b6d9f34e13f39c7ffc2e72e47888599ba5",
"c4315666c71fea834d8ff27f025f5cc34f37c1aae78604a4b08dac45decd42be");
testKatHex(new Keccak256(),
"36f9f0a65f2ca498d739b944d6eff3da5ebba57e7d9c41598a2b0e4380f3cf4b479ec2348d015ffe6256273511154afcf3b4b4bf09d6c4744fdd0f62d75079d440706b05",
"5ff8734db3f9977eee9cf5e2cf725c57af09926490c55abd9d00a42e91a8c344");
testKatHex(new Keccak256(),
"abc87763cae1ca98bd8c5b82caba54ac83286f87e9610128ae4de68ac95df5e329c360717bd349f26b872528492ca7c94c2c1e1ef56b74dbb65c2ac351981fdb31d06c77a4",
"1e141a171cab085252ea4c2f8f1f1087dd85a75ab3acd0b3c28eaa5735d349af");
testKatHex(new Keccak256(),
"94f7ca8e1a54234c6d53cc734bb3d3150c8ba8c5f880eab8d25fed13793a9701ebe320509286fd8e422e931d99c98da4df7e70ae447bab8cffd92382d8a77760a259fc4fbd72",
"ef763f22f359dd7f5b3fe6a745c423d6b641ec07ba5235232a0701510f74426e");
testKatHex(new Keccak256(),
"13bd2811f6ed2b6f04ff3895aceed7bef8dcd45eb121791bc194a0f806206bffc3b9281c2b308b1a729ce008119dd3066e9378acdcc50a98a82e20738800b6cddbe5fe9694ad6d",
"6a769f93f255b078fe73aff68f0422a279939920e4690b4aff0e433cfa3d3df3");
testKatHex(new Keccak256(),
"1eed9cba179a009ec2ec5508773dd305477ca117e6d569e66b5f64c6bc64801ce25a8424ce4a26d575b8a6fb10ead3fd1992edddeec2ebe7150dc98f63adc3237ef57b91397aa8a7",
"c06dd4261638c44afcb186f0af5de20ea53aa63316fbb71728f874ff3daceb0d");
testKatHex(new Keccak256(),
"ba5b67b5ec3a3ffae2c19dd8176a2ef75c0cd903725d45c9cb7009a900c0b0ca7a2967a95ae68269a6dbf8466c7b6844a1d608ac661f7eff00538e323db5f2c644b78b2d48de1a08aa",
"b5d84b1809e83b5e75aa53bdee79e3a97f3fe3a7d3162ebd4908240ff69131d8");
testKatHex(new Keccak256(),
"0efa26ac5673167dcacab860932ed612f65ff49b80fa9ae65465e5542cb62075df1c5ae54fba4db807be25b070033efa223bdd5b1d3c94c6e1909c02b620d4b1b3a6c9fed24d70749604",
"cad7abb5bba5905b5181dd2dbc4e68cfd01ba8659f21c8290d3f835c1a68bbe5");
testKatHex(new Keccak256(),
"bbfd933d1fd7bf594ac7f435277dc17d8d5a5b8e4d13d96d2f64e771abbd51a5a8aea741beccbddb177bcea05243ebd003cfdeae877cca4da94605b67691919d8b033f77d384ca01593c1b",
"83ca09c1f418b5dad0a7f64a904a2e07c3314f7d02d92622f8f4674bc1f6aa3d");
testKatHex(new Keccak256(),
"90078999fd3c35b8afbf4066cbde335891365f0fc75c1286cdd88fa51fab94f9b8def7c9ac582a5dbcd95817afb7d1b48f63704e19c2baa4df347f48d4a6d603013c23f1e9611d595ebac37c",
"330de3ee16aef6711461a994863eed47af71b362d4c2f243534ef432f63a091a");
testKatHex(new Keccak256(),
"64105eca863515c20e7cfbaa0a0b8809046164f374d691cdbd6508aaabc1819f9ac84b52bafc1b0fe7cddbc554b608c01c8904c669d8db316a0953a4c68ece324ec5a49ffdb59a1bd6a292aa0e",
"b5675197e49b357218f7118cd15ee773b39bd59b224d9a45ca71c6e371d938f1");
testKatHex(new Keccak256(),
"d4654be288b9f3b711c2d02015978a8cc57471d5680a092aa534f7372c71ceaab725a383c4fcf4d8deaa57fca3ce056f312961eccf9b86f14981ba5bed6ab5b4498e1f6c82c6cae6fc14845b3c8a",
"cd9038c1066a59990df5752107b066eebbe672cbca0f60d687d03a9d821934be");
testKatHex(new Keccak256(),
"12d9394888305ac96e65f2bf0e1b18c29c90fe9d714dd59f651f52b88b3008c588435548066ea2fc4c101118c91f32556224a540de6efddbca296ef1fb00341f5b01fecfc146bdb251b3bdad556cd2",
"d3172ca263aff2b9db6fb13337f2543c5af51151801a76194012f710306c14f6");
testKatHex(new Keccak256(),
"871a0d7a5f36c3da1dfce57acd8ab8487c274fad336bc137ebd6ff4658b547c1dcfab65f037aa58f35ef16aff4abe77ba61f65826f7be681b5b6d5a1ea8085e2ae9cd5cf0991878a311b549a6d6af230",
"9e3d4bcf580eece39bcf13e5716e5bb8f5e8c3fc3723f66246f836d8db1238f1");
testKatHex(new Keccak256(),
"e90b4ffef4d457bc7711ff4aa72231ca25af6b2e206f8bf859d8758b89a7cd36105db2538d06da83bad5f663ba11a5f6f61f236fd5f8d53c5e89f183a3cec615b50c7c681e773d109ff7491b5cc22296c5",
"edc2d3b49c85b8dd75f7b5128da04cd76bf4878779a0077af3f1d7fb44f18931");
testKatHex(new Keccak256(),
"e728de62d75856500c4c77a428612cd804f30c3f10d36fb219c5ca0aa30726ab190e5f3f279e0733d77e7267c17be27d21650a9a4d1e32f649627638dbada9702c7ca303269ed14014b2f3cf8b894eac8554",
"80dce7f04dd6ac17ce709b56cf6ea6c0a57190649bb187b5e6d95fa18100c7ac");
testKatHex(new Keccak256(),
"6348f229e7b1df3b770c77544e5166e081850fa1c6c88169db74c76e42eb983facb276ad6a0d1fa7b50d3e3b6fcd799ec97470920a7abed47d288ff883e24ca21c7f8016b93bb9b9e078bdb9703d2b781b616e",
"49bbd5435d2706f85fe77b84a5fa15ddd8259e5d2c20fb947f139373e5c86121");
testKatHex(new Keccak256(),
"4b127fde5de733a1680c2790363627e63ac8a3f1b4707d982caea258655d9bf18f89afe54127482ba01e08845594b671306a025c9a5c5b6f93b0a39522dc877437be5c2436cbf300ce7ab6747934fcfc30aeaaf6",
"6b6c11f9731d60789d713daf53d2eb10ab9ccf15430ea5d1249be06edfe2bff6");
testKatHex(new Keccak256(),
"08461f006cff4cc64b752c957287e5a0faabc05c9bff89d23fd902d324c79903b48fcb8f8f4b01f3e4ddb483593d25f000386698f5ade7faade9615fdc50d32785ea51d49894e45baa3dc707e224688c6408b68b11",
"7e738e8eb3d47d18e97d87c7b3fc681f86417883ced92ba93c3077812bbd17e7");
testKatHex(new Keccak256(),
"68c8f8849b120e6e0c9969a5866af591a829b92f33cd9a4a3196957a148c49138e1e2f5c7619a6d5edebe995acd81ec8bb9c7b9cfca678d081ea9e25a75d39db04e18d475920ce828b94e72241f24db72546b352a0e4",
"a278ba93ba0d7cd2677be08c9dfc5f516a37f722bb06565fa22500f66fe031a9");
testKatHex(new Keccak256(),
"b8d56472954e31fb54e28fca743f84d8dc34891cb564c64b08f7b71636debd64ca1edbdba7fc5c3e40049ce982bba8c7e0703034e331384695e9de76b5104f2fbc4535ecbeebc33bc27f29f18f6f27e8023b0fbb6f563c",
"9c0a9f0da113d39f491b7da6c4da5d84fe1cc46367e5acc433ca3e0500951738");
testKatHex(new Keccak256(),
"0d58ac665fa84342e60cefee31b1a4eacdb092f122dfc68309077aed1f3e528f578859ee9e4cefb4a728e946324927b675cd4f4ac84f64db3dacfe850c1dd18744c74ceccd9fe4dc214085108f404eab6d8f452b5442a47d",
"6bed496d02fe4cc27d96dceed14a67da7bdf75e19b624896dff6b0b68e4fcc12");
testKatHex(new Keccak256(),
"1755e2d2e5d1c1b0156456b539753ff416651d44698e87002dcf61dcfa2b4e72f264d9ad591df1fdee7b41b2eb00283c5aebb3411323b672eaa145c5125185104f20f335804b02325b6dea65603f349f4d5d8b782dd3469ccd",
"ecd2e3faf4ba4dd67e5a8656cebebdb24611611678e92eb60f7cbd3111d0a345");
testKatHex(new Keccak256(),
"b180de1a611111ee7584ba2c4b020598cd574ac77e404e853d15a101c6f5a2e5c801d7d85dc95286a1804c870bb9f00fd4dcb03aa8328275158819dcad7253f3e3d237aeaa7979268a5db1c6ce08a9ec7c2579783c8afc1f91a7",
"634a95a7e8ba58f7818a13903ec8f3411b6ecb7e389ec9aa97c0ecf87fadd588");
testKatHex(new Keccak256(),
"cf3583cbdfd4cbc17063b1e7d90b02f0e6e2ee05f99d77e24e560392535e47e05077157f96813544a17046914f9efb64762a23cf7a49fe52a0a4c01c630cfe8727b81fb99a89ff7cc11dca5173057e0417b8fe7a9efba6d95c555f",
"a0fe352ba2389b0430edbe1201032eb09c255514c5c5b529c4baafceb1ac9817");
testKatHex(new Keccak256(),
"072fc02340ef99115bad72f92c01e4c093b9599f6cfc45cb380ee686cb5eb019e806ab9bd55e634ab10aa62a9510cc0672cd3eddb589c7df2b67fcd3329f61b1a4441eca87a33c8f55da4fbbad5cf2b2527b8e983bb31a2fadec7523",
"9a0bfe14f9f3127aca86773a620945731df781a6d7dc82930ccde2f69dac8f94");
testKatHex(new Keccak256(),
"76eecf956a52649f877528146de33df249cd800e21830f65e90f0f25ca9d6540fde40603230eca6760f1139c7f268deba2060631eea92b1fff05f93fd5572fbe29579ecd48bc3a8d6c2eb4a6b26e38d6c5fbf2c08044aeea470a8f2f26",
"19e5101bde60b200a8b171e4c3ea3dfd913e10111d96f9682acc7467282b4e31");
testKatHex(new Keccak256(),
"7adc0b6693e61c269f278e6944a5a2d8300981e40022f839ac644387bfac9086650085c2cdc585fea47b9d2e52d65a2b29a7dc370401ef5d60dd0d21f9e2b90fae919319b14b8c5565b0423cefb827d5f1203302a9d01523498a4db10374",
"4cc2aff141987f4c2e683fa2de30042bacdcd06087d7a7b014996e9cfeaa58ce");
testKatHex(new Keccak256(),
"e1fffa9826cce8b86bccefb8794e48c46cdf372013f782eced1e378269b7be2b7bf51374092261ae120e822be685f2e7a83664bcfbe38fe8633f24e633ffe1988e1bc5acf59a587079a57a910bda60060e85b5f5b6f776f0529639d9cce4bd",
"9a8ce819894efccc2153b239c3adc3f07d0968eac5ec8080ac0174f2d5e6959c");
testKatHex(new Keccak256(),
"69f9abba65592ee01db4dce52dbab90b08fc04193602792ee4daa263033d59081587b09bbe49d0b49c9825d22840b2ff5d9c5155f975f8f2c2e7a90c75d2e4a8040fe39f63bbafb403d9e28cc3b86e04e394a9c9e8065bd3c85fa9f0c7891600",
"8b35768525f59ac77d35522ac885831a9947299e114a8956fe5bca103db7bb2c");
testKatHex(new Keccak256(),
"38a10a352ca5aedfa8e19c64787d8e9c3a75dbf3b8674bfab29b5dbfc15a63d10fae66cd1a6e6d2452d557967eaad89a4c98449787b0b3164ca5b717a93f24eb0b506ceb70cbbcb8d72b2a72993f909aad92f044e0b5a2c9ac9cb16a0ca2f81f49",
"955f1f7e4e54660b26f30086f2dddaedd32813547c1b95d305d882682b4ff7a0");
testKatHex(new Keccak256(),
"6d8c6e449bc13634f115749c248c17cd148b72157a2c37bf8969ea83b4d6ba8c0ee2711c28ee11495f43049596520ce436004b026b6c1f7292b9c436b055cbb72d530d860d1276a1502a5140e3c3f54a93663e4d20edec32d284e25564f624955b52",
"8fac5a34ebafa38b55333624a9514fe97d9956e74309c5252cd2090d3bbe2f9e");
testKatHex(new Keccak256(),
"6efcbcaf451c129dbe00b9cef0c3749d3ee9d41c7bd500ade40cdc65dedbbbadb885a5b14b32a0c0d087825201e303288a733842fa7e599c0c514e078f05c821c7a4498b01c40032e9f1872a1c925fa17ce253e8935e4c3c71282242cb716b2089ccc1",
"62039e0f53869480f88c87bb3d19a31aad32878f27f2c4e78ff02bbea2b8b0b9");
testKatHex(new Keccak256(),
"433c5303131624c0021d868a30825475e8d0bd3052a022180398f4ca4423b98214b6beaac21c8807a2c33f8c93bd42b092cc1b06cedf3224d5ed1ec29784444f22e08a55aa58542b524b02cd3d5d5f6907afe71c5d7462224a3f9d9e53e7e0846dcbb4ce",
"ce87a5173bffd92399221658f801d45c294d9006ee9f3f9d419c8d427748dc41");
testKatHex(new Keccak256(),
"a873e0c67ca639026b6683008f7aa6324d4979550e9bce064ca1e1fb97a30b147a24f3f666c0a72d71348ede701cf2d17e2253c34d1ec3b647dbcef2f879f4eb881c4830b791378c901eb725ea5c172316c6d606e0af7df4df7f76e490cd30b2badf45685f",
"2ef8907b60108638e50eac535cc46ca02e04581ddb4235fbac5cb5c53583e24b");
testKatHex(new Keccak256(),
"006917b64f9dcdf1d2d87c8a6173b64f6587168e80faa80f82d84f60301e561e312d9fbce62f39a6fb476e01e925f26bcc91de621449be6504c504830aae394096c8fc7694651051365d4ee9070101ec9b68086f2ea8f8ab7b811ea8ad934d5c9b62c60a4771",
"be8b5bd36518e9c5f4c768fc02461bb3d39a5d00edef82cec7df351df80238e0");
testKatHex(new Keccak256(),
"f13c972c52cb3cc4a4df28c97f2df11ce089b815466be88863243eb318c2adb1a417cb1041308598541720197b9b1cb5ba2318bd5574d1df2174af14884149ba9b2f446d609df240ce335599957b8ec80876d9a085ae084907bc5961b20bf5f6ca58d5dab38adb",
"52cbc5dbe49b009663c43f079dd180e38a77533778062a72a29e864a58522922");
testKatHex(new Keccak256(),
"e35780eb9799ad4c77535d4ddb683cf33ef367715327cf4c4a58ed9cbdcdd486f669f80189d549a9364fa82a51a52654ec721bb3aab95dceb4a86a6afa93826db923517e928f33e3fba850d45660ef83b9876accafa2a9987a254b137c6e140a21691e1069413848",
"3a8dfcfd1b362003ddfa17910727539e64b18021abba018b5f58d71f7a449733");
testKatHex(new Keccak256(),
"64ec021c9585e01ffe6d31bb50d44c79b6993d72678163db474947a053674619d158016adb243f5c8d50aa92f50ab36e579ff2dabb780a2b529370daa299207cfbcdd3a9a25006d19c4f1fe33e4b1eaec315d8c6ee1e730623fd1941875b924eb57d6d0c2edc4e78d6",
"fa221deee80e25e53c6c448aa22028b72501f07d1ff2c3fc7f93af9838b2d0a9");
testKatHex(new Keccak256(),
"5954bab512cf327d66b5d9f296180080402624ad7628506b555eea8382562324cf452fba4a2130de3e165d11831a270d9cb97ce8c2d32a96f50d71600bb4ca268cf98e90d6496b0a6619a5a8c63db6d8a0634dfc6c7ec8ea9c006b6c456f1b20cd19e781af20454ac880",
"ed9c8b87fce27be4e95610db1ddd0c035847f4699dfc8c039a798a30343a6059");
testKatHex(new Keccak256(),
"03d9f92b2c565709a568724a0aff90f8f347f43b02338f94a03ed32e6f33666ff5802da4c81bdce0d0e86c04afd4edc2fc8b4141c2975b6f07639b1994c973d9a9afce3d9d365862003498513bfa166d2629e314d97441667b007414e739d7febf0fe3c32c17aa188a8683",
"a485cc9cf4ca4f659f89a0b791a4423953424ac57146b879d385a9e4062afe52");
testKatHex(new Keccak256(),
"f31e8b4f9e0621d531d22a380be5d9abd56faec53cbd39b1fab230ea67184440e5b1d15457bd25f56204fa917fa48e669016cb48c1ffc1e1e45274b3b47379e00a43843cf8601a5551411ec12503e5aac43d8676a1b2297ec7a0800dbfee04292e937f21c005f17411473041",
"93cd4369a7796239a5cdf78bce22ebb2137a631c3a613d5e35816d2a64a34947");
testKatHex(new Keccak256(),
"758ea3fea738973db0b8be7e599bbef4519373d6e6dcd7195ea885fc991d896762992759c2a09002912fb08e0cb5b76f49162aeb8cf87b172cf3ad190253df612f77b1f0c532e3b5fc99c2d31f8f65011695a087a35ee4eee5e334c369d8ee5d29f695815d866da99df3f79403",
"3751ce08750d927eb5c3ae4ca62a703a481d86a4fa1c011e812b4bc0a2fef08d");
testKatHex(new Keccak256(),
"47c6e0c2b74948465921868804f0f7bd50dd323583dc784f998a93cd1ca4c6ef84d41dc81c2c40f34b5bee6a93867b3bdba0052c5f59e6f3657918c382e771d33109122cc8bb0e1e53c4e3d13b43ce44970f5e0c079d2ad7d7a3549cd75760c21bb15b447589e86e8d76b1e9ced2",
"a88c7ef7b89b7b6f75d83922b8fd00f034d719f97c67884121434447ae9dd3b9");
testKatHex(new Keccak256(),
"f690a132ab46b28edfa6479283d6444e371c6459108afd9c35dbd235e0b6b6ff4c4ea58e7554bd002460433b2164ca51e868f7947d7d7a0d792e4abf0be5f450853cc40d85485b2b8857ea31b5ea6e4ccfa2f3a7ef3380066d7d8979fdac618aad3d7e886dea4f005ae4ad05e5065f",
"2b4f8f9ef7d6ed60bb4881e635e0f887a51b0c1a42bab077976b43d2c715e11a");
testKatHex(new Keccak256(),
"58d6a99bc6458824b256916770a8417040721cccfd4b79eacd8b65a3767ce5ba7e74104c985ac56b8cc9aebd16febd4cda5adb130b0ff2329cc8d611eb14dac268a2f9e633c99de33997fea41c52a7c5e1317d5b5daed35eba7d5a60e45d1fa7eaabc35f5c2b0a0f2379231953322c4e",
"586cffdc434313cc4e133e85ac88b3e5dea71818abcac236f0aae418f72b6cde");
testKatHex(new Keccak256(),
"befab574396d7f8b6705e2d5b58b2c1c820bb24e3f4bae3e8fbcd36dbf734ee14e5d6ab972aedd3540235466e825850ee4c512ea9795abfd33f330d9fd7f79e62bbb63a6ea85de15beaeea6f8d204a28956059e2632d11861dfb0e65bc07ac8a159388d5c3277e227286f65ff5e5b5aec1",
"52d14ab96b24aa4a7a55721aa8550b1fccac3653c78234783f7295ae5f39a17a");
testKatHex(new Keccak256(),
"8e58144fa9179d686478622ce450c748260c95d1ba43b8f9b59abeca8d93488da73463ef40198b4d16fb0b0707201347e0506ff19d01bea0f42b8af9e71a1f1bd168781069d4d338fdef00bf419fbb003031df671f4a37979564f69282de9c65407847dd0da505ab1641c02dea4f0d834986",
"b6345edd966030cf70dfb5b7552bc141c42efe7a7e84f957b1baf4671bae4354");
testKatHex(new Keccak256(),
"b55c10eae0ec684c16d13463f29291bf26c82e2fa0422a99c71db4af14dd9c7f33eda52fd73d017cc0f2dbe734d831f0d820d06d5f89dacc485739144f8cfd4799223b1aff9031a105cb6a029ba71e6e5867d85a554991c38df3c9ef8c1e1e9a7630be61caabca69280c399c1fb7a12d12aefc",
"0347901965d3635005e75a1095695cca050bc9ed2d440c0372a31b348514a889");
testKatHex(new Keccak256(),
"2eeea693f585f4ed6f6f8865bbae47a6908aecd7c429e4bec4f0de1d0ca0183fa201a0cb14a529b7d7ac0e6ff6607a3243ee9fb11bcf3e2304fe75ffcddd6c5c2e2a4cd45f63c962d010645058d36571404a6d2b4f44755434d76998e83409c3205aa1615db44057db991231d2cb42624574f545",
"f0bf7105870f2382b76863bb97aee79f95ae0e8142675bbccdb3475b0c99352f");
testKatHex(new Keccak256(),
"dab11dc0b047db0420a585f56c42d93175562852428499f66a0db811fcdddab2f7cdffed1543e5fb72110b64686bc7b6887a538ad44c050f1e42631bc4ec8a9f2a047163d822a38989ee4aab01b4c1f161b062d873b1cfa388fd301514f62224157b9bef423c7783b7aac8d30d65cd1bba8d689c2d",
"631c6f5abe50b27c9dea557fc3fbd3fb25781fcb1bbf9f2e010cca20ec52dbc4");
testKatHex(new Keccak256(),
"42e99a2f80aee0e001279a2434f731e01d34a44b1a8101726921c0590c30f3120eb83059f325e894a5ac959dca71ce2214799916424e859d27d789437b9d27240bf8c35adbafcecc322b48aa205b293962d858652abacbd588bcf6cbc388d0993bd622f96ed54614c25b6a9aa527589eaaffcf17ddf7",
"3757a53d195b43b403a796a74aafb2064072a69e372ee5b36cc2b7a791f75c9f");
testKatHex(new Keccak256(),
"3c9b46450c0f2cae8e3823f8bdb4277f31b744ce2eb17054bddc6dff36af7f49fb8a2320cc3bdf8e0a2ea29ad3a55de1165d219adeddb5175253e2d1489e9b6fdd02e2c3d3a4b54d60e3a47334c37913c5695378a669e9b72dec32af5434f93f46176ebf044c4784467c700470d0c0b40c8a088c815816",
"0cc903acbced724b221d34877d1d1427182f9493a33df7758720e8bfc7af98ee");
testKatHex(new Keccak256(),
"d1e654b77cb155f5c77971a64df9e5d34c26a3cad6c7f6b300d39deb1910094691adaa095be4ba5d86690a976428635d5526f3e946f7dc3bd4dbc78999e653441187a81f9adcd5a3c5f254bc8256b0158f54673dcc1232f6e918ebfc6c51ce67eaeb042d9f57eec4bfe910e169af78b3de48d137df4f2840",
"f23750c32973f24c2422f4e2b43589d9e76d6a575938e01a96ae8e73d026569c");
testKatHex(new Keccak256(),
"626f68c18a69a6590159a9c46be03d5965698f2dac3de779b878b3d9c421e0f21b955a16c715c1ec1e22ce3eb645b8b4f263f60660ea3028981eebd6c8c3a367285b691c8ee56944a7cd1217997e1d9c21620b536bdbd5de8925ff71dec6fbc06624ab6b21e329813de90d1e572dfb89a18120c3f606355d25",
"1ece87e44a99f59d26411418fb8793689ff8a9c6ef75599056087d8c995bce1e");
testKatHex(new Keccak256(),
"651a6fb3c4b80c7c68c6011675e6094eb56abf5fc3057324ebc6477825061f9f27e7a94633abd1fa598a746e4a577caf524c52ec1788471f92b8c37f23795ca19d559d446cab16cbcdce90b79fa1026cee77bf4ab1b503c5b94c2256ad75b3eac6fd5dcb96aca4b03a834bfb4e9af988cecbf2ae597cb9097940",
"71b4f90ac9215d7474b1197d1b8b24449fd57e9b05483d32edbebcb21a82f866");
testKatHex(new Keccak256(),
"8aaf072fce8a2d96bc10b3c91c809ee93072fb205ca7f10abd82ecd82cf040b1bc49ea13d1857815c0e99781de3adbb5443ce1c897e55188ceaf221aa9681638de05ae1b322938f46bce51543b57ecdb4c266272259d1798de13be90e10efec2d07484d9b21a3870e2aa9e06c21aa2d0c9cf420080a80a91dee16f",
"3b3678bb116fadab484291f0cf972606523501f5b45d51063797972928e333c0");
testKatHex(new Keccak256(),
"53f918fd00b1701bd504f8cdea803acca21ac18c564ab90c2a17da592c7d69688f6580575395551e8cd33e0fef08ca6ed4588d4d140b3e44c032355df1c531564d7f4835753344345a6781e11cd5e095b73df5f82c8ae3ad00877936896671e947cc52e2b29dcd463d90a0c9929128da222b5a211450bbc0e02448e2",
"4068246495f508897813332962d3ae0b84685045e832a9a39ad5e94c154d2679");
testKatHex(new Keccak256(),
"a64599b8a61b5ccec9e67aed69447459c8da3d1ec6c7c7c82a7428b9b584fa67e90f68e2c00fbbed4613666e5168da4a16f395f7a3c3832b3b134bfc9cbaa95d2a0fe252f44ac6681eb6d40ab91c1d0282fed6701c57463d3c5f2bb8c6a7301fb4576aa3b5f15510db8956ff77478c26a7c09bea7b398cfc83503f538e",
"82696259536520e5e4d47e106bd1dcb397529aafb75878f332d2af2684493f1b");
testKatHex(new Keccak256(),
"0e3ab0e054739b00cdb6a87bd12cae024b54cb5e550e6c425360c2e87e59401f5ec24ef0314855f0f56c47695d56a7fb1417693af2a1ed5291f2fee95f75eed54a1b1c2e81226fbff6f63ade584911c71967a8eb70933bc3f5d15bc91b5c2644d9516d3c3a8c154ee48e118bd1442c043c7a0dba5ac5b1d5360aae5b9065",
"b494852603393b2b71845bacbdce89fa1427dfe4af9cdf925d4f93fa83b9966b");
testKatHex(new Keccak256(),
"a62fc595b4096e6336e53fcdfc8d1cc175d71dac9d750a6133d23199eaac288207944cea6b16d27631915b4619f743da2e30a0c00bbdb1bbb35ab852ef3b9aec6b0a8dcc6e9e1abaa3ad62ac0a6c5de765de2c3711b769e3fde44a74016fff82ac46fa8f1797d3b2a726b696e3dea5530439acee3a45c2a51bc32dd055650b",
"d8a619c0dfbed2a9498a147b53d7b33dd653d390e5c0cd691f02c8608822d06a");
testKatHex(new Keccak256(),
"2b6db7ced8665ebe9deb080295218426bdaa7c6da9add2088932cdffbaa1c14129bccdd70f369efb149285858d2b1d155d14de2fdb680a8b027284055182a0cae275234cc9c92863c1b4ab66f304cf0621cd54565f5bff461d3b461bd40df28198e3732501b4860eadd503d26d6e69338f4e0456e9e9baf3d827ae685fb1d817",
"d82e257d000dc9fa279a00e2961e3286d2fe1c02ef59833ab8a6a7101bc25054");
testKatHex(new Keccak256(),
"10db509b2cdcaba6c062ae33be48116a29eb18e390e1bbada5ca0a2718afbcd23431440106594893043cc7f2625281bf7de2655880966a23705f0c5155c2f5cca9f2c2142e96d0a2e763b70686cd421b5db812daced0c6d65035fde558e94f26b3e6dde5bd13980cc80292b723013bd033284584bff27657871b0cf07a849f4ae2",
"8d5b7dbf3947219acdb04fb2e11a84a313c54c22f2ae858dfc8887bf6265f5f3");
testKatHex(new Keccak256(),
"9334de60c997bda6086101a6314f64e4458f5ff9450c509df006e8c547983c651ca97879175aaba0c539e82d05c1e02c480975cbb30118121061b1ebac4f8d9a3781e2db6b18042e01ecf9017a64a0e57447ec7fcbe6a7f82585f7403ee2223d52d37b4bf426428613d6b4257980972a0acab508a7620c1cb28eb4e9d30fc41361ec",
"607c3f31342c3ee5c93e552a8dd79fa86dccae2c1b58aabac25b5918acfa4da5");
testKatHex(new Keccak256(),
"e88ab086891693aa535ceb20e64c7ab97c7dd3548f3786339897a5f0c39031549ca870166e477743ccfbe016b4428d89738e426f5ffe81626137f17aecff61b72dbee2dc20961880cfe281dfab5ee38b1921881450e16032de5e4d55ad8d4fca609721b0692bac79be5a06e177fe8c80c0c83519fb3347de9f43d5561cb8107b9b5edc",
"0656de9dcd7b7112a86c7ba199637d2c1c9e9cfbb713e4ede79f8862ee69993f");
testKatHex(new Keccak256(),
"fd19e01a83eb6ec810b94582cb8fbfa2fcb992b53684fb748d2264f020d3b960cb1d6b8c348c2b54a9fcea72330c2aaa9a24ecdb00c436abc702361a82bb8828b85369b8c72ece0082fe06557163899c2a0efa466c33c04343a839417057399a63a3929be1ee4805d6ce3e5d0d0967fe9004696a5663f4cac9179006a2ceb75542d75d68",
"4ddd6224858299f3378e3f5a0ecc52fa4c419c8ebb20f635c4c43f36324ecb4e");
testKatHex(new Keccak256(),
"59ae20b6f7e0b3c7a989afb28324a40fca25d8651cf1f46ae383ef6d8441587aa1c04c3e3bf88e8131ce6145cfb8973d961e8432b202fa5af3e09d625faad825bc19da9b5c6c20d02abda2fcc58b5bd3fe507bf201263f30543819510c12bc23e2ddb4f711d087a86edb1b355313363a2de996b891025e147036087401ccf3ca7815bf3c49",
"ec096314e2f73b6a7027fffa02104c2f6dd187f20c743445befd4b5c034b3295");
testKatHex(new Keccak256(),
"77ee804b9f3295ab2362798b72b0a1b2d3291dceb8139896355830f34b3b328561531f8079b79a6e9980705150866402fdc176c05897e359a6cb1a7ab067383eb497182a7e5aef7038e4c96d133b2782917417e391535b5e1b51f47d8ed7e4d4025fe98dc87b9c1622614bff3d1029e68e372de719803857ca52067cddaad958951cb2068cc6",
"fe71d01c2ee50e054d6b07147ef62954fde7e6959d6eeba68e3c94107eb0084d");
testKatHex(new Keccak256(),
"b771d5cef5d1a41a93d15643d7181d2a2ef0a8e84d91812f20ed21f147bef732bf3a60ef4067c3734b85bc8cd471780f10dc9e8291b58339a677b960218f71e793f2797aea349406512829065d37bb55ea796fa4f56fd8896b49b2cd19b43215ad967c712b24e5032d065232e02c127409d2ed4146b9d75d763d52db98d949d3b0fed6a8052fbb",
"bd6f5492582a7c1b116304de28314df9fffe95b0da11af52fe9440a717a34859");
testKatHex(new Keccak256(),
"b32d95b0b9aad2a8816de6d06d1f86008505bd8c14124f6e9a163b5a2ade55f835d0ec3880ef50700d3b25e42cc0af050ccd1be5e555b23087e04d7bf9813622780c7313a1954f8740b6ee2d3f71f768dd417f520482bd3a08d4f222b4ee9dbd015447b33507dd50f3ab4247c5de9a8abd62a8decea01e3b87c8b927f5b08beb37674c6f8e380c04",
"e717a7769448abbe5fef8187954a88ac56ded1d22e63940ab80d029585a21921");
testKatHex(new Keccak256(),
"04410e31082a47584b406f051398a6abe74e4da59bb6f85e6b49e8a1f7f2ca00dfba5462c2cd2bfde8b64fb21d70c083f11318b56a52d03b81cac5eec29eb31bd0078b6156786da3d6d8c33098c5c47bb67ac64db14165af65b44544d806dde5f487d5373c7f9792c299e9686b7e5821e7c8e2458315b996b5677d926dac57b3f22da873c601016a0d",
"a95d50b50b4545f0947441df74a1e9d74622eb3baa49c1bbfc3a0cce6619c1aa");
testKatHex(new Keccak256(),
"8b81e9badde026f14d95c019977024c9e13db7a5cd21f9e9fc491d716164bbacdc7060d882615d411438aea056c340cdf977788f6e17d118de55026855f93270472d1fd18b9e7e812bae107e0dfde7063301b71f6cfe4e225cab3b232905a56e994f08ee2891ba922d49c3dafeb75f7c69750cb67d822c96176c46bd8a29f1701373fb09a1a6e3c7158f",
"ed53d72595ace3a6d5166a4ede41cce362d644bded772be616b87bcf678a6364");
testKatHex(new Keccak256(),
"fa6eed24da6666a22208146b19a532c2ec9ba94f09f1def1e7fc13c399a48e41acc2a589d099276296348f396253b57cb0e40291bd282773656b6e0d8bea1cda084a3738816a840485fcf3fb307f777fa5feac48695c2af4769720258c77943fb4556c362d9cba8bf103aeb9034baa8ea8bfb9c4f8e6742ce0d52c49ea8e974f339612e830e9e7a9c29065",
"810401b247c23529e24655cab86c42df44085da76ca01c9a14618e563b7c41be");
testKatHex(new Keccak256(),
"9bb4af1b4f09c071ce3cafa92e4eb73ce8a6f5d82a85733440368dee4eb1cbc7b55ac150773b6fe47dbe036c45582ed67e23f4c74585dab509df1b83610564545642b2b1ec463e18048fc23477c6b2aa035594ecd33791af6af4cbc2a1166aba8d628c57e707f0b0e8707caf91cd44bdb915e0296e0190d56d33d8dde10b5b60377838973c1d943c22ed335e",
"9f01e63f2355393ecb1908d0caf39718833004a4bf37ebf4cf8d7319b65172df");
testKatHex(new Keccak256(),
"2167f02118cc62043e9091a647cadbed95611a521fe0d64e8518f16c808ab297725598ae296880a773607a798f7c3cfce80d251ebec6885015f9abf7eaabae46798f82cb5926de5c23f44a3f9f9534b3c6f405b5364c2f8a8bdc5ca49c749bed8ce4ba48897062ae8424ca6dde5f55c0e42a95d1e292ca54fb46a84fbc9cd87f2d0c9e7448de3043ae22fdd229",
"7ec11de7db790a850281f043592779b409195db4ecedeefbb93ba683d3bca851");
testKatHex(new Keccak256(),
"94b7fa0bc1c44e949b1d7617d31b4720cbe7ca57c6fa4f4094d4761567e389ecc64f6968e4064df70df836a47d0c713336b5028b35930d29eb7a7f9a5af9ad5cf441745baec9bb014ceeff5a41ba5c1ce085feb980bab9cf79f2158e03ef7e63e29c38d7816a84d4f71e0f548b7fc316085ae38a060ff9b8dec36f91ad9ebc0a5b6c338cbb8f6659d342a24368cf",
"a74af9c523b4a08d9db9692ea89255977a5919b9292b7cd0d92c90c97c98e224");
testKatHex(new Keccak256(),
"ea40e83cb18b3a242c1ecc6ccd0b7853a439dab2c569cfc6dc38a19f5c90acbf76aef9ea3742ff3b54ef7d36eb7ce4ff1c9ab3bc119cff6be93c03e208783335c0ab8137be5b10cdc66ff3f89a1bddc6a1eed74f504cbe7290690bb295a872b9e3fe2cee9e6c67c41db8efd7d863cf10f840fe618e7936da3dca5ca6df933f24f6954ba0801a1294cd8d7e66dfafec",
"344d129c228359463c40555d94213d015627e5871c04f106a0feef9361cdecb6");
testKatHex(new Keccak256(),
"157d5b7e4507f66d9a267476d33831e7bb768d4d04cc3438da12f9010263ea5fcafbde2579db2f6b58f911d593d5f79fb05fe3596e3fa80ff2f761d1b0e57080055c118c53e53cdb63055261d7c9b2b39bd90acc32520cbbdbda2c4fd8856dbcee173132a2679198daf83007a9b5c51511ae49766c792a29520388444ebefe28256fb33d4260439cba73a9479ee00c63",
"4ce7c2b935f21fc34c5e56d940a555c593872aec2f896de4e68f2a017060f535");
testKatHex(new Keccak256(),
"836b34b515476f613fe447a4e0c3f3b8f20910ac89a3977055c960d2d5d2b72bd8acc715a9035321b86703a411dde0466d58a59769672aa60ad587b8481de4bba552a1645779789501ec53d540b904821f32b0bd1855b04e4848f9f8cfe9ebd8911be95781a759d7ad9724a7102dbe576776b7c632bc39b9b5e19057e226552a5994c1dbb3b5c7871a11f5537011044c53",
"24b69d8ab35baccbd92f94e1b70b07c4c0ecf14eaeac4b6b8560966d5be086f3");
testKatHex(new Keccak256(),
"cc7784a4912a7ab5ad3620aab29ba87077cd3cb83636adc9f3dc94f51edf521b2161ef108f21a0a298557981c0e53ce6ced45bdf782c1ef200d29bab81dd6460586964edab7cebdbbec75fd7925060f7da2b853b2b089588fa0f8c16ec6498b14c55dcee335cb3a91d698e4d393ab8e8eac0825f8adebeee196df41205c011674e53426caa453f8de1cbb57932b0b741d4c6",
"19f34215373e8e80f686953e03ca472b50216719cb515e0667d4e686e45fcf7c");
testKatHex(new Keccak256(),
"7639b461fff270b2455ac1d1afce782944aea5e9087eb4a39eb96bb5c3baaf0e868c8526d3404f9405e79e77bfac5ffb89bf1957b523e17d341d7323c302ea7083872dd5e8705694acdda36d5a1b895aaa16eca6104c82688532c8bfe1790b5dc9f4ec5fe95baed37e1d287be710431f1e5e8ee105bc42ed37d74b1e55984bf1c09fe6a1fa13ef3b96faeaed6a2a1950a12153",
"290bd4808e5676eb0c978084e4cd68e745031659a26807ad615b10cda589b969");
testKatHex(new Keccak256(),
"eb6513fc61b30cfba58d4d7e80f94d14589090cf1d80b1df2e68088dc6104959ba0d583d585e9578ab0aec0cf36c48435eb52ed9ab4bbce7a5abe679c97ae2dbe35e8cc1d45b06dda3cf418665c57cbee4bbb47fa4caf78f4ee656fec237fe4eebbafa206e1ef2bd0ee4ae71bd0e9b2f54f91daadf1febfd7032381d636b733dcb3bf76fb14e23aff1f68ed3dbcf75c9b99c6f26",
"70999ab9818309afa8f1adc4fea47a071a8abd94012f7ce28cc794a0d997c5cb");
testKatHex(new Keccak256(),
"1594d74bf5dde444265d4c04dad9721ff3e34cbf622daf341fe16b96431f6c4df1f760d34f296eb97d98d560ad5286fec4dce1724f20b54fd7df51d4bf137add656c80546fb1bf516d62ee82baa992910ef4cc18b70f3f8698276fcfb44e0ec546c2c39cfd8ee91034ff9303058b4252462f86c823eb15bf481e6b79cc3a02218595b3658e8b37382bd5048eaed5fd02c37944e73b",
"83120033b0140fe3e3e1cbfebff323abc08535c0aa017803f5d2f4ecb35f5dfb");
testKatHex(new Keccak256(),
"4cfa1278903026f66fedd41374558be1b585d03c5c55dac94361df286d4bd39c7cb8037ed3b267b07c346626449d0cc5b0dd2cf221f7e4c3449a4be99985d2d5e67bff2923357ddeab5abcb4619f3a3a57b2cf928a022eb27676c6cf805689004fca4d41ea6c2d0a4789c7605f7bb838dd883b3ad3e6027e775bcf262881428099c7fff95b14c095ea130e0b9938a5e22fc52650f591",
"5584bf3e93bc25945c508b9188d0502c6e755bbebabfc8cb907fa7a252ef464a");
testKatHex(new Keccak256(),
"d3e65cb92cfa79662f6af493d696a07ccf32aaadcceff06e73e8d9f6f909209e66715d6e978788c49efb9087b170ecf3aa86d2d4d1a065ae0efc8924f365d676b3cb9e2bec918fd96d0b43dee83727c9a93bf56ca2b2e59adba85696546a815067fc7a78039629d4948d157e7b0d826d1bf8e81237bab7321312fdaa4d521744f988db6fdf04549d0fdca393d639c729af716e9c8bba48",
"c234b252c21edb842634cc124da5bee8a4749cffba134723f7963b3a9729c0b4");
testKatHex(new Keccak256(),
"842cc583504539622d7f71e7e31863a2b885c56a0ba62db4c2a3f2fd12e79660dc7205ca29a0dc0a87db4dc62ee47a41db36b9ddb3293b9ac4baae7df5c6e7201e17f717ab56e12cad476be49608ad2d50309e7d48d2d8de4fa58ac3cfeafeee48c0a9eec88498e3efc51f54d300d828dddccb9d0b06dd021a29cf5cb5b2506915beb8a11998b8b886e0f9b7a80e97d91a7d01270f9a7717",
"645f25456752091fffcaade806c34c79dffe72140c7c75d6a6ecfeedf6db401c");
testKatHex(new Keccak256(),
"6c4b0a0719573e57248661e98febe326571f9a1ca813d3638531ae28b4860f23c3a3a8ac1c250034a660e2d71e16d3acc4bf9ce215c6f15b1c0fc7e77d3d27157e66da9ceec9258f8f2bf9e02b4ac93793dd6e29e307ede3695a0df63cbdc0fc66fb770813eb149ca2a916911bee4902c47c7802e69e405fe3c04ceb5522792a5503fa829f707272226621f7c488a7698c0d69aa561be9f378",
"2d7cac697e7410c1f7735dd691624a7d04fa51815858e8ba98b19b0ded0638b5");
testKatHex(new Keccak256(),
"51b7dbb7ce2ffeb427a91ccfe5218fd40f9e0b7e24756d4c47cd55606008bdc27d16400933906fd9f30effdd4880022d081155342af3fb6cd53672ab7fb5b3a3bcbe47be1fd3a2278cae8a5fd61c1433f7d350675dd21803746cadca574130f01200024c6340ab0cc2cf74f2234669f34e9009ef2eb94823d62b31407f4ba46f1a1eec41641e84d77727b59e746b8a671bef936f05be820759fa",
"f664f626bc6b7a8cf03be429155ee1f5cd6ecf14816de49a5e229903f89a4dc6");
testKatHex(new Keccak256(),
"83599d93f5561e821bd01a472386bc2ff4efbd4aed60d5821e84aae74d8071029810f5e286f8f17651cd27da07b1eb4382f754cd1c95268783ad09220f5502840370d494beb17124220f6afce91ec8a0f55231f9652433e5ce3489b727716cf4aeba7dcda20cd29aa9a859201253f948dd94395aba9e3852bd1d60dda7ae5dc045b283da006e1cbad83cc13292a315db5553305c628dd091146597",
"06425e83e4af817d735e9962c0cddce2cd40a087a6b0af3599719e415ab9a72a");
testKatHex(new Keccak256(),
"2be9bf526c9d5a75d565dd11ef63b979d068659c7f026c08bea4af161d85a462d80e45040e91f4165c074c43ac661380311a8cbed59cc8e4c4518e80cd2c78ab1cabf66bff83eab3a80148550307310950d034a6286c93a1ece8929e6385c5e3bb6ea8a7c0fb6d6332e320e71cc4eb462a2a62e2bfe08f0ccad93e61bedb5dd0b786a728ab666f07e0576d189c92bf9fb20dca49ac2d3956d47385e2",
"e8c329149b075c459e11c8ac1e7e6acfa51ca981c89ec0768ed79d19f4e484fb");
testKatHex(new Keccak256(),
"ca76d3a12595a817682617006848675547d3e8f50c2210f9af906c0e7ce50b4460186fe70457a9e879e79fd4d1a688c70a347361c847ba0dd6aa52936eaf8e58a1be2f5c1c704e20146d366aeb3853bed9de9befe9569ac8aaea37a9fb7139a1a1a7d5c748605a8defb297869ebedd71d615a5da23496d11e11abbb126b206fa0a7797ee7de117986012d0362dcef775c2fe145ada6bda1ccb326bf644",
"c86768f6c349eb323bd82db19676e10bd8ae9f7057763556bbb6d0b671e60f2a");
testKatHex(new Keccak256(),
"f76b85dc67421025d64e93096d1d712b7baf7fb001716f02d33b2160c2c882c310ef13a576b1c2d30ef8f78ef8d2f465007109aad93f74cb9e7d7bef7c9590e8af3b267c89c15db238138c45833c98cc4a471a7802723ef4c744a853cf80a0c2568dd4ed58a2c9644806f42104cee53628e5bdf7b63b0b338e931e31b87c24b146c6d040605567ceef5960df9e022cb469d4c787f4cba3c544a1ac91f95f",
"d97f46f3b7edbfb16e52bfec7dba0815b94d46e4251e48a853eabdf876127714");
testKatHex(new Keccak256(),
"25b8c9c032ea6bcd733ffc8718fbb2a503a4ea8f71dea1176189f694304f0ff68e862a8197b839957549ef243a5279fc2646bd4c009b6d1edebf24738197abb4c992f6b1dc9ba891f570879accd5a6b18691a93c7d0a8d38f95b639c1daeb48c4c2f15ccf5b9d508f8333c32de78781b41850f261b855c4bebcc125a380c54d501c5d3bd07e6b52102116088e53d76583b0161e2a58d0778f091206aabd5a1",
"51d08e00aaa252812d873357107616055b1b8c5fb2ac7917d0f901dfb01fac47");
testKatHex(new Keccak256(),
"21cfdc2a7ccb7f331b3d2eefff37e48ad9fa9c788c3f3c200e0173d99963e1cbca93623b264e920394ae48bb4c3a5bb96ffbc8f0e53f30e22956adabc2765f57fb761e147ecbf8567533db6e50c8a1f894310a94edf806dd8ca6a0e141c0fa7c9fae6c6ae65f18c93a8529e6e5b553bf55f25be2e80a9882bd37f145fecbeb3d447a3c4e46c21524cc55cdd62f521ab92a8ba72b897996c49bb273198b7b1c9e",
"c6a188a6bdaca4dd7b1bc3e41019afe93473063f932c166e3242b7f52a3c6f8e");
testKatHex(new Keccak256(),
"4e452ba42127dcc956ef4f8f35dd68cb225fb73b5bc7e1ec5a898bba2931563e74faff3b67314f241ec49f4a7061e3bd0213ae826bab380f1f14faab8b0efddd5fd1bb49373853a08f30553d5a55ccbbb8153de4704f29ca2bdeef0419468e05dd51557ccc80c0a96190bbcc4d77ecff21c66bdf486459d427f986410f883a80a5bcc32c20f0478bb9a97a126fc5f95451e40f292a4614930d054c851acd019ccf",
"2b31fbc565110110011ab2c8f6cc3da8fb55d41b1ae5e04310283f207d39682d");
testKatHex(new Keccak256(),
"fa85671df7dadf99a6ffee97a3ab9991671f5629195049880497487867a6c446b60087fac9a0f2fcc8e3b24e97e42345b93b5f7d3691829d3f8ccd4bb36411b85fc2328eb0c51cb3151f70860ad3246ce0623a8dc8b3c49f958f8690f8e3860e71eb2b1479a5cea0b3f8befd87acaf5362435eaeccb52f38617bc6c5c2c6e269ead1fbd69e941d4ad2012da2c5b21bcfbf98e4a77ab2af1f3fda3233f046d38f1dc8",
"1351f5dba46098b9a773381d85d52fad491b3a82af9107f173db81fb35ed91d2");
testKatHex(new Keccak256(),
"e90847ae6797fbc0b6b36d6e588c0a743d725788ca50b6d792352ea8294f5ba654a15366b8e1b288d84f5178240827975a763bc45c7b0430e8a559df4488505e009c63da994f1403f407958203cebb6e37d89c94a5eacf6039a327f6c4dbbc7a2a307d976aa39e41af6537243fc218dfa6ab4dd817b6a397df5ca69107a9198799ed248641b63b42cb4c29bfdd7975ac96edfc274ac562d0474c60347a078ce4c25e88",
"dffc700f3e4d84d9131cbb1f98fb843dbafcb2ef94a52e89d204d431451a3331");
testKatHex(new Keccak256(),
"f6d5c2b6c93954fc627602c00c4ca9a7d3ed12b27173f0b2c9b0e4a5939398a665e67e69d0b12fb7e4ceb253e8083d1ceb724ac07f009f094e42f2d6f2129489e846eaff0700a8d4453ef453a3eddc18f408c77a83275617fabc4ea3a2833aa73406c0e966276079d38e8e38539a70e194cc5513aaa457c699383fd1900b1e72bdfb835d1fd321b37ba80549b078a49ea08152869a918ca57f5b54ed71e4fd3ac5c06729",
"26726b52242ef8ecf4c66aed9c4b46bf6f5d87044a0b99d4e4af47dc360b9b0e");
testKatHex(new Keccak256(),
"cf8562b1bed89892d67ddaaf3deeb28246456e972326dbcdb5cf3fb289aca01e68da5d59896e3a6165358b071b304d6ab3d018944be5049d5e0e2bb819acf67a6006111089e6767132d72dd85beddcbb2d64496db0cc92955ab4c6234f1eea24f2d51483f2e209e4589bf9519fac51b4d061e801125e605f8093bb6997bc163d551596fe4ab7cfae8fb9a90f6980480ce0c229fd1675409bd788354daf316240cfe0af93eb",
"25e536315f08a40976adecb54756ebc0b224c38faf11509371b5a692a5269ab5");
testKatHex(new Keccak256(),
"2ace31abb0a2e3267944d2f75e1559985db7354c6e605f18dc8470423fca30b7331d9b33c4a4326783d1caae1b4f07060eff978e4746bf0c7e30cd61040bd5ec2746b29863eb7f103ebda614c4291a805b6a4c8214230564a0557bc7102e0bd3ed23719252f7435d64d210ee2aafc585be903fa41e1968c50fd5d5367926df7a05e3a42cf07e656ff92de73b036cf8b19898c0cb34557c0c12c2d8b84e91181af467bc75a9d1",
"ab504592ad7184be83cc659efb5d3de88ba04b060b45d16a76f034080dde56c6");
testKatHex(new Keccak256(),
"0d8d09aed19f1013969ce5e7eb92f83a209ae76be31c754844ea9116ceb39a22ebb6003017bbcf26555fa6624185187db8f0cb3564b8b1c06bf685d47f3286eda20b83358f599d2044bbf0583fab8d78f854fe0a596183230c5ef8e54426750eaf2cc4e29d3bdd037e734d863c2bd9789b4c243096138f7672c232314effdfc6513427e2da76916b5248933be312eb5dde4cf70804fb258ac5fb82d58d08177ac6f4756017fff5",
"5d8ee133ec441a3df50a5268a8f393f13f30f23f226ae3a18ec331844402ff54");
testKatHex(new Keccak256(),
"c3236b73deb7662bf3f3daa58f137b358ba610560ef7455785a9befdb035a066e90704f929bd9689cef0ce3bda5acf4480bceb8d09d10b098ad8500d9b6071dfc3a14af6c77511d81e3aa8844986c3bea6f469f9e02194c92868cd5f51646256798ff0424954c1434bdfed9facb390b07d342e992936e0f88bfd0e884a0ddb679d0547ccdec6384285a45429d115ac7d235a717242021d1dc35641f5f0a48e8445dba58e6cb2c8ea",
"712b1cc04c009b52035cc44c9505bb5cb577ba0ad1734ec23620f57eef3d37fb");
testKatHex(new Keccak256(),
"b39feb8283eadc63e8184b51df5ae3fd41aac8a963bb0be1cd08aa5867d8d910c669221e73243360646f6553d1ca05a84e8dc0de05b6419ec349ca994480193d01c92525f3fb3dcefb08afc6d26947bdbbfd85193f53b50609c6140905c53a6686b58e53a319a57b962331ede98149af3de3118a819da4d76706a0424b4e1d2910b0ed26af61d150ebcb46595d4266a0bd7f651ba47d0c7f179ca28545007d92e8419d48fdfbd744ce",
"942e39e230a2251ffdb2f85202871c98597008401b322ff9840cc90cc85b337d");
testKatHex(new Keccak256(),
"a983d54f503803e8c7999f4edbbe82e9084f422143a932ddddc47a17b0b7564a7f37a99d0786e99476428d29e29d3c197a72bfab1342c12a0fc4787fd7017d7a6174049ea43b5779169ef7472bdbbd941dcb82fc73aac45a8a94c9f2bd3477f61fd3b796f02a1b8264a214c6fea74b7051b226c722099ec7883a462b83b6afdd4009248b8a237f605fe5a08fe7d8b45321421ebba67bd70a0b00ddbf94baab7f359d5d1eea105f28dcfb",
"b542b6cd8ef2dab4ed83b77ac6dc52daf554ecda4ef7ab0a50e546bebe2d8e5a");
testKatHex(new Keccak256(),
"e4d1c1897a0a866ce564635b74222f9696bf2c7f640dd78d7e2aca66e1b61c642bb03ea7536aae597811e9bf4a7b453ede31f97b46a5f0ef51a071a2b3918df16b152519ae3776f9f1edab4c2a377c3292e96408359d3613844d5eb393000283d5ad3401a318b12fd1474b8612f2bb50fb6a8b9e023a54d7dde28c43d6d8854c8d9d1155935c199811dbfc87e9e0072e90eb88681cc7529714f8fb8a2c9d88567adfb974ee205a9bf7b848",
"f7e9e825722e6554a8619cca3e57f5b5e6b7347431d55ce178372c917bfb3dc2");
testKatHex(new Keccak256(),
"b10c59723e3dcadd6d75df87d0a1580e73133a9b7d00cb95ec19f5547027323be75158b11f80b6e142c6a78531886d9047b08e551e75e6261e79785366d7024bd7cd9cf322d9be7d57fb661069f2481c7bb759cd71b4b36ca2bc2df6d3a328faebdb995a9794a8d72155ed551a1f87c80bf6059b43fc764900b18a1c2441f7487743cf84e565f61f8dd2ece6b6ccc9444049197aaaf53e926fbee3bfca8be588ec77f29d211be89de18b15f6",
"14bb22b98eaf41a4c224fd3c37188a755f9b04f46f3e23a652da3db9e25d2f2c");
testKatHex(new Keccak256(),
"db11f609baba7b0ca634926b1dd539c8cbada24967d7add4d9876f77c2d80c0f4dcefbd7121548373582705cca2495bd2a43716fe64ed26d059cfb566b3364bd49ee0717bdd9810dd14d8fad80dbbdc4cafb37cc60fb0fe2a80fb4541b8ca9d59dce457738a9d3d8f641af8c3fd6da162dc16fc01aac527a4a0255b4d231c0be50f44f0db0b713af03d968fe7f0f61ed0824c55c4b5265548febd6aad5c5eedf63efe793489c39b8fd29d104ce",
"eb5668f9941c06e5e38ea01b7fa980638b9536ca1939950c1629f84a6eff3866");
testKatHex(new Keccak256(),
"bebd4f1a84fc8b15e4452a54bd02d69e304b7f32616aadd90537937106ae4e28de9d8aab02d19bc3e2fde1d651559e296453e4dba94370a14dbbb2d1d4e2022302ee90e208321efcd8528ad89e46dc839ea9df618ea8394a6bff308e7726bae0c19bcd4be52da6258e2ef4e96aa21244429f49ef5cb486d7ff35cac1bacb7e95711944bccb2ab34700d42d1eb38b5d536b947348a458ede3dc6bd6ec547b1b0cae5b257be36a7124e1060c170ffa",
"913014bb6e243fac3a22a185f8227a68c2311dc0b718e276bbbdb73af98be35f");
testKatHex(new Keccak256(),
"5aca56a03a13784bdc3289d9364f79e2a85c12276b49b92db0adaa4f206d5028f213f678c3510e111f9dc4c1c1f8b6acb17a6413aa227607c515c62a733817ba5e762cc6748e7e0d6872c984d723c9bb3b117eb8963185300a80bfa65cde495d70a46c44858605fccbed086c2b45cef963d33294dbe9706b13af22f1b7c4cd5a001cfec251fba18e722c6e1c4b1166918b4f6f48a98b64b3c07fc86a6b17a6d0480ab79d4e6415b520f1c484d675b1",
"0284418c10190f413042e3eceb3954979b94afbf2e545fc7f8a3c7db2c235916");
testKatHex(new Keccak256(),
"a5aad0e4646a32c85cfcac73f02fc5300f1982fabb2f2179e28303e447854094cdfc854310e5c0f60993ceff54d84d6b46323d930adb07c17599b35b505f09e784bca5985e0172257797fb53649e2e9723efd16865c31b5c3d5113b58bb0bfc8920fabdda086d7537e66d709d050bd14d0c960873f156fad5b3d3840cdfcdc9be6af519db262a27f40896ab25cc39f96984d650611c0d5a3080d5b3a1bf186abd42956588b3b58cd948970d298776060",
"8febff801787f5803e151dca3434a5cd44adb49f1c2ffd5d0cd077a9075a492d");
testKatHex(new Keccak256(),
"06cbbe67e94a978203ead6c057a1a5b098478b4b4cbef5a97e93c8e42f5572713575fc2a884531d7622f8f879387a859a80f10ef02708cd8f7413ab385afc357678b9578c0ebf641ef076a1a30f1f75379e9dcb2a885bdd295905ee80c0168a62a9597d10cf12dd2d8cee46645c7e5a141f6e0e23aa482abe5661c16e69ef1e28371e2e236c359ba4e92c25626a7b7ff13f6ea4ae906e1cfe163e91719b1f750a96cbde5fbc953d9e576cd216afc90323a",
"ea7511b993b786df59a3b3e0b3cd876c0f056d6ca43cc89c51c1b21ccdc79b42");
testKatHex(new Keccak256(),
"f1c528cf7739874707d4d8ad5b98f7c77169de0b57188df233b2dc8a5b31eda5db4291dd9f68e6bad37b8d7f6c9c0044b3bf74bbc3d7d1798e138709b0d75e7c593d3cccdc1b20c7174b4e692add820ace262d45ccfae2077e878796347168060a162ecca8c38c1a88350bd63bb539134f700fd4addd5959e255337daa06bc86358fabcbefdfb5bc889783d843c08aadc6c4f6c36f65f156e851c9a0f917e4a367b5ad93d874812a1de6a7b93cd53ad97232",
"baaecb6e9db57971d5c70f5819ff89c5093254de19ef6059c43cc0afda7c5d34");
testKatHex(new Keccak256(),
"9d9f3a7ecd51b41f6572fd0d0881e30390dfb780991dae7db3b47619134718e6f987810e542619dfaa7b505c76b7350c6432d8bf1cfebdf1069b90a35f0d04cbdf130b0dfc7875f4a4e62cdb8e525aadd7ce842520a482ac18f09442d78305fe85a74e39e760a4837482ed2f437dd13b2ec1042afcf9decdc3e877e50ff4106ad10a525230d11920324a81094da31deab6476aa42f20c84843cfc1c58545ee80352bdd3740dd6a16792ae2d86f11641bb717c2",
"56db69430b8ca852221d55d7bbff477dc83f7cb44ab44ddd64c31a52c483db4f");
testKatHex(new Keccak256(),
"5179888724819fbad3afa927d3577796660e6a81c52d98e9303261d5a4a83232f6f758934d50aa83ff9e20a5926dfebaac49529d006eb923c5ae5048ed544ec471ed7191edf46363383824f915769b3e688094c682b02151e5ee01e510b431c8865aff8b6b6f2f59cb6d129da79e97c6d2b8fa6c6da3f603199d2d1bcab547682a81cd6cf65f6551121391d78bcc23b5bd0e922ec6d8bf97c952e84dd28aef909aba31edb903b28fbfc33b7703cd996215a11238",
"f8538f597f4463cad7a91905744b87156db33c65ba87b912427fec3669f425d4");
testKatHex(new Keccak256(),
"576ef3520d30b7a4899b8c0d5e359e45c5189add100e43be429a02fb3de5ff4f8fd0e79d9663acca72cd29c94582b19292a557c5b1315297d168fbb54e9e2ecd13809c2b5fce998edc6570545e1499dbe7fb74d47cd7f35823b212b05bf3f5a79caa34224fdd670d335fcb106f5d92c3946f44d3afcbae2e41ac554d8e6759f332b76be89a0324aa12c5482d1ea3ee89ded4936f3e3c080436f539fa137e74c6d3389bdf5a45074c47bc7b20b0948407a66d855e2f",
"447eda923cfe1112a6f1a3e4c735bf8ee9e4f2aee7de666a472ff8cf0fc65315");
testKatHex(new Keccak256(),
"0df2152fa4f4357c8741529dd77e783925d3d76e95bafa2b542a2c33f3d1d117d159cf473f82310356fee4c90a9e505e70f8f24859656368ba09381fa245eb6c3d763f3093f0c89b972e66b53d59406d9f01aea07f8b3b615cac4ee4d05f542e7d0dab45d67ccccd3a606ccbeb31ea1fa7005ba07176e60dab7d78f6810ef086f42f08e595f0ec217372b98970cc6321576d92ce38f7c397a403bada1548d205c343ac09deca86325373c3b76d9f32028fea8eb32515",
"74d94c13afea4ddd07a637b68b6fe095017c092b3cdccdc498e26035d86d921e");
testKatHex(new Keccak256(),
"3e15350d87d6ebb5c8ad99d42515cfe17980933c7a8f6b8bbbf0a63728cefaad2052623c0bd5931839112a48633fb3c2004e0749c87a41b26a8b48945539d1ff41a4b269462fd199bfecd45374756f55a9116e92093ac99451aefb2af9fd32d6d7f5fbc7f7a540d5097c096ebc3b3a721541de073a1cc02f7fb0fb1b9327fb0b1218ca49c9487ab5396622a13ae546c97abdef6b56380dda7012a8384091b6656d0ab272d363cea78163ff765cdd13ab1738b940d16cae",
"cc11196c095bffa090a05ba0bc255d38bda7218d9311143f4f200b1852d1bb0d");
testKatHex(new Keccak256(),
"c38d6b0b757cb552be40940ece0009ef3b0b59307c1451686f1a22702922800d58bce7a636c1727ee547c01b214779e898fc0e560f8ae7f61bef4d75eaa696b921fd6b735d171535e9edd267c192b99880c87997711002009095d8a7a437e258104a41a505e5ef71e5613ddd2008195f0c574e6ba3fe40099cfa116e5f1a2fa8a6da04badcb4e2d5d0de31fdc4800891c45781a0aac7c907b56d631fca5ce8b2cde620d11d1777ed9fa603541de794ddc5758fcd5fad78c0",
"8c085b54c213704374ddd920a45168608be65dfd036a562659f47143604144c2");
testKatHex(new Keccak256(),
"8d2de3f0b37a6385c90739805b170057f091cd0c7a0bc951540f26a5a75b3e694631bb64c7635eed316f51318e9d8de13c70a2aba04a14836855f35e480528b776d0a1e8a23b547c8b8d6a0d09b241d3be9377160cca4e6793d00a515dc2992cb7fc741daca171431da99cce6f7789f129e2ac5cf65b40d703035cd2185bb936c82002daf8cbc27a7a9e554b06196630446a6f0a14ba155ed26d95bd627b7205c072d02b60db0fd7e49ea058c2e0ba202daff0de91e845cf79",
"d2e233264a3773495ffd12159ef7b631660c1b3e53a3da0f24ae14466f167757");
testKatHex(new Keccak256(),
"c464bbdad275c50dcd983b65ad1019b9ff85a1e71c807f3204bb2c921dc31fbcd8c5fc45868ae9ef85b6c9b83bba2a5a822201ed68586ec5ec27fb2857a5d1a2d09d09115f22dcc39fe61f5e1ba0ff6e8b4acb4c6da748be7f3f0839739394ff7fa8e39f7f7e84a33c3866875c01bcb1263c9405d91908e9e0b50e7459fabb63d8c6bbb73d8e3483c099b55bc30ff092ff68b6adedfd477d63570c9f5515847f36e24ba0b705557130cec57ebad1d0b31a378e91894ee26e3a04",
"ffac7ca5fa067419d1bdb00c0e49c6e1a748880923a23ed5dd67dde63d777edb");
testKatHex(new Keccak256(),
"8b8d68bb8a75732fe272815a68a1c9c5aa31b41dedc8493e76525d1d013d33cebd9e21a5bb95db2616976a8c07fcf411f5f6bc6f7e0b57aca78cc2790a6f9b898858ac9c79b165ff24e66677531e39f572be5d81eb3264524181115f32780257bfb9aeec6af12af28e587cac068a1a2953b59ad680f4c245b2e3ec36f59940d37e1d3db38e13edb29b5c0f404f6ff87f80fc8be7a225ff22fbb9c8b6b1d7330c57840d24bc75b06b80d30dad6806544d510af6c4785e823ac3e0b8",
"5b2eca0920d32b1964bbf5810a6e6e53675ed1b83897fd04600d72e097845859");
testKatHex(new Keccak256(),
"6b018710446f368e7421f1bc0ccf562d9c1843846bc8d98d1c9bf7d9d6fcb48bfc3bf83b36d44c4fa93430af75cd190bde36a7f92f867f58a803900df8018150384d85d82132f123006ac2aeba58e02a037fe6afbd65eca7c44977dd3dc74f48b6e7a1bfd5cc4dcf24e4d52e92bd4455848e4928b0eac8b7476fe3cc03e862aa4dff4470dbfed6de48e410f25096487ecfc32a27277f3f5023b2725ade461b1355889554a8836c9cf53bd767f5737d55184eea1ab3f53edd0976c485",
"68f41fdfc7217e89687ed118bc31ac6ed2d9d1e1a2f1b20a2d429729fa03517b");
testKatHex(new Keccak256(),
"c9534a24714bd4be37c88a3da1082eda7cabd154c309d7bd670dccd95aa535594463058a29f79031d6ecaa9f675d1211e9359be82669a79c855ea8d89dd38c2c761ddd0ec0ce9e97597432e9a1beae062cdd71edfdfd464119be9e69d18a7a7fd7ce0e2106f0c8b0abf4715e2ca48ef9f454dc203c96656653b727083513f8efb86e49c513bb758b3b052fe21f1c05bb33c37129d6cc81f1aef6adc45b0e8827a830fe545cf57d0955802c117d23ccb55ea28f95c0d8c2f9c5a242b33f",
"fa2f3de31e9cf25ab9a978c82d605a43ee39b68ac8e30f49f9d209cb4e172ab4");
testKatHex(new Keccak256(),
"07906c87297b867abf4576e9f3cc7f82f22b154afcbf293b9319f1b0584da6a40c27b32e0b1b7f412c4f1b82480e70a9235b12ec27090a5a33175a2bb28d8adc475cefe33f7803f8ce27967217381f02e67a3b4f84a71f1c5228e0c2ad971373f6f672624fcea8d1a9f85170fad30fa0bbd25035c3b41a6175d467998bd1215f6f3866f53847f9cf68ef3e2fbb54bc994de2302b829c5eea68ec441fcbafd7d16ae4fe9fff98bf00e5bc2ad54dd91ff9fda4dd77b6c754a91955d1fbaad0",
"ba2af506c10da8d7751e67ed766cfcd47d048d6ef9277dbd2abfe2fd5d787b79");
testKatHex(new Keccak256(),
"588e94b9054abc2189df69b8ba34341b77cdd528e7860e5defcaa79b0c9a452ad4b82aa306be84536eb7cedcbe058d7b84a6aef826b028b8a0271b69ac3605a9635ea9f5ea0aa700f3eb7835bc54611b922964300c953efe7491e3677c2cebe0822e956cd16433b02c68c4a23252c3f9e151a416b4963257b783e038f6b4d5c9f110f871652c7a649a7bcedcbccc6f2d0725bb903cc196ba76c76aa9f10a190b1d1168993baa9ffc96a1655216773458bec72b0e39c9f2c121378feab4e76a",
"3cd33f8811af12183c53e978528f53ae7d559432724029e55fcfa9b990b91713");
testKatHex(new Keccak256(),
"08959a7e4baae874928813364071194e2939772f20db7c3157078987c557c2a6d5abe68d520eef3dc491692e1e21bcd880adebf63bb4213b50897fa005256ed41b5690f78f52855c8d9168a4b666fce2da2b456d7a7e7c17ab5f2fb1ee90b79e698712e963715983fd07641ae4b4e9dc73203fac1ae11fa1f8c7941fcc82eab247addb56e2638447e9d609e610b60ce086656aaebf1da3c8a231d7d94e2fd0afe46b391ff14a72eaeb3f44ad4df85866def43d4781a0b3578bc996c87970b132",
"3ecc9d27994022045cbeab4fc041f12419cec8060c8f6f9f0372884df6074b5c");
testKatHex(new Keccak256(),
"cb2a234f45e2ecd5863895a451d389a369aab99cfef0d5c9ffca1e6e63f763b5c14fb9b478313c8e8c0efeb3ac9500cf5fd93791b789e67eac12fd038e2547cc8e0fc9db591f33a1e4907c64a922dda23ec9827310b306098554a4a78f050262db5b545b159e1ff1dca6eb734b872343b842c57eafcfda8405eedbb48ef32e99696d135979235c3a05364e371c2d76f1902f1d83146df9495c0a6c57d7bf9ee77e80f9787aee27be1fe126cdc9ef893a4a7dcbbc367e40fe4e1ee90b42ea25af01",
"1501988a55372ac1b0b78849f3b7e107e0bf1f2cbaf670de7f15acbb1a00ad3d");
testKatHex(new Keccak256(),
"d16beadf02ab1d4dc6f88b8c4554c51e866df830b89c06e786a5f8757e8909310af51c840efe8d20b35331f4355d80f73295974653ddd620cdde4730fb6c8d0d2dcb2b45d92d4fbdb567c0a3e86bd1a8a795af26fbf29fc6c65941cddb090ff7cd230ac5268ab4606fccba9eded0a2b5d014ee0c34f0b2881ac036e24e151be89eeb6cd9a7a790afccff234d7cb11b99ebf58cd0c589f20bdac4f9f0e28f75e3e04e5b3debce607a496d848d67fa7b49132c71b878fd5557e082a18eca1fbda94d4b",
"5c4e860a0175c92c1e6af2cbb3084162403ced073faac901d0d358b6bf5eefa9");
testKatHex(new Keccak256(),
"8f65f6bc59a85705016e2bae7fe57980de3127e5ab275f573d334f73f8603106ec3553016608ef2dd6e69b24be0b7113bf6a760ba6e9ce1c48f9e186012cf96a1d4849d75df5bb8315387fd78e9e153e76f8ba7ec6c8849810f59fb4bb9b004318210b37f1299526866f44059e017e22e96cbe418699d014c6ea01c9f0038b10299884dbec3199bb05adc94e955a1533219c1115fed0e5f21228b071f40dd57c4240d98d37b73e412fe0fa4703120d7c0c67972ed233e5deb300a22605472fa3a3ba86",
"272b4f689263057fbf7605aaa67af012d742267164c4fab68035d99c5829b4f0");
testKatHex(new Keccak256(),
"84891e52e0d451813210c3fd635b39a03a6b7a7317b221a7abc270dfa946c42669aacbbbdf801e1584f330e28c729847ea14152bd637b3d0f2b38b4bd5bf9c791c58806281103a3eabbaede5e711e539e6a8b2cf297cf351c078b4fa8f7f35cf61bebf8814bf248a01d41e86c5715ea40c63f7375379a7eb1d78f27622fb468ab784aaaba4e534a6dfd1df6fa15511341e725ed2e87f98737ccb7b6a6dfae416477472b046bf1811187d151bfa9f7b2bf9acdb23a3be507cdf14cfdf517d2cb5fb9e4ab6",
"9b28e42b67ef32ec80da10a07b004e1d71c6dce71d8013ffa0305d0d0ce0469d");
testKatHex(new Keccak256(),
"fdd7a9433a3b4afabd7a3a5e3457e56debf78e84b7a0b0ca0e8c6d53bd0c2dae31b2700c6128334f43981be3b213b1d7a118d59c7e6b6493a86f866a1635c12859cfb9ad17460a77b4522a5c1883c3d6acc86e6162667ec414e9a104aa892053a2b1d72165a855bacd8faf8034a5dd9b716f47a0818c09bb6baf22aa503c06b4ca261f557761989d2afbd88b6a678ad128af68672107d0f1fc73c5ca740459297b3292b281e93bceb761bde7221c3a55708e5ec84472cddcaa84ecf23723cc0991355c6280",
"ee53f83d2e2ccc315c6377eadda5f42f42f3aadd664e3e895c37cbe9d0e9b9de");
testKatHex(new Keccak256(),
"70a40bfbef92277a1aad72f6b79d0177197c4ebd432668cfec05d099accb651062b5dff156c0b27336687a94b26679cfdd9daf7ad204338dd9c4d14114033a5c225bd11f217b5f4732da167ee3f939262d4043fc9cba92303b7b5e96aea12adda64859df4b86e9ee0b58e39091e6b188b408ac94e1294a8911245ee361e60e601eff58d1d37639f3753bec80ebb4efde25817436076623fc65415fe51d1b0280366d12c554d86743f3c3b6572e400361a60726131441ba493a83fbe9afda90f7af1ae717238d",
"21ccfda65c4b915303012b852ab29481030f87347c29917e21f210f2bd5efc9c");
testKatHex(new Keccak256(),
"74356e449f4bf8644f77b14f4d67cb6bd9c1f5ae357621d5b8147e562b65c66585caf2e491b48529a01a34d226d436959153815380d5689e30b35357cdac6e08d3f2b0e88e200600d62bd9f5eaf488df86a4470ea227006182e44809009868c4c280c43d7d64a5268fa719074960087b3a6abc837882f882c837834535929389a12b2c78187e2ea07ef8b8eef27dc85002c3ae35f1a50bee6a1c48ba7e175f3316670b27983472aa6a61eed0a683a39ee323080620ea44a9f74411ae5ce99030528f9ab49c79f2",
"f5bf70710da440edb43afd3eb7698180317ffefa81406bb4df9c2bb8b0b1c034");
testKatHex(new Keccak256(),
"8c3798e51bc68482d7337d3abb75dc9ffe860714a9ad73551e120059860dde24ab87327222b64cf774415a70f724cdf270de3fe47dda07b61c9ef2a3551f45a5584860248fabde676e1cd75f6355aa3eaeabe3b51dc813d9fb2eaa4f0f1d9f834d7cad9c7c695ae84b329385bc0bef895b9f1edf44a03d4b410cc23a79a6b62e4f346a5e8dd851c2857995ddbf5b2d717aeb847310e1f6a46ac3d26a7f9b44985af656d2b7c9406e8a9e8f47dcb4ef6b83caacf9aefb6118bfcff7e44bef6937ebddc89186839b77",
"e83ea21f5bc0976953af86069a10eb6024a1ac59d609688e4a9759bb8b6c9441");
testKatHex(new Keccak256(),
"fa56bf730c4f8395875189c10c4fb251605757a8fecc31f9737e3c2503b02608e6731e85d7a38393c67de516b85304824bfb135e33bf22b3a23b913bf6acd2b7ab85198b8187b2bcd454d5e3318cacb32fd6261c31ae7f6c54ef6a7a2a4c9f3ecb81ce3555d4f0ad466dd4c108a90399d70041997c3b25345a9653f3c9a6711ab1b91d6a9d2216442da2c973cbd685ee7643bfd77327a2f7ae9cb283620a08716dfb462e5c1d65432ca9d56a90e811443cd1ecb8f0de179c9cb48ba4f6fec360c66f252f6e64edc96b",
"a2d93c6367e1862809d367ec37f9da44cb3a8b4319c6a094c5e7d7266fe3a593");
testKatHex(new Keccak256(),
"b6134f9c3e91dd8000740d009dd806240811d51ab1546a974bcb18d344642baa5cd5903af84d58ec5ba17301d5ec0f10ccd0509cbb3fd3fff9172d193af0f782252fd1338c7244d40e0e42362275b22d01c4c3389f19dd69bdf958ebe28e31a4ffe2b5f18a87831cfb7095f58a87c9fa21db72ba269379b2dc2384b3da953c7925761fed324620acea435e52b424a7723f6a2357374157a34cd8252351c25a1b232826cefe1bd3e70ffc15a31e7c0598219d7f00436294d11891b82497bc78aa5363892a2495df8c1eef",
"3c647b195f22dc16d6decc8873017df369ee1c4696340934db158dc4059c76df");
testKatHex(new Keccak256(),
"c941cdb9c28ab0a791f2e5c8e8bb52850626aa89205bec3a7e22682313d198b1fa33fc7295381354858758ae6c8ec6fac3245c6e454d16fa2f51c4166fab51df272858f2d603770c40987f64442d487af49cd5c3991ce858ea2a60dab6a65a34414965933973ac2457089e359160b7cdedc42f29e10a91921785f6b7224ee0b349393cdcff6151b50b377d609559923d0984cda6000829b916ab6896693ef6a2199b3c22f7dc5500a15b8258420e314c222bc000bc4e5413e6dd82c993f8330f5c6d1be4bc79f08a1a0a46",
"3bb394d056d94fde68920cd383378ee3abcc44b7259d3db9cd0a897e021f7e2e");
testKatHex(new Keccak256(),
"4499efffac4bcea52747efd1e4f20b73e48758be915c88a1ffe5299b0b005837a46b2f20a9cb3c6e64a9e3c564a27c0f1c6ad1960373036ec5bfe1a8fc6a435c2185ed0f114c50e8b3e4c7ed96b06a036819c9463e864a58d6286f785e32a804443a56af0b4df6abc57ed5c2b185ddee8489ea080deeee66aa33c2e6dab36251c402682b6824821f998c32163164298e1fafd31babbcffb594c91888c6219079d907fdb438ed89529d6d96212fd55abe20399dbefd342248507436931cdead496eb6e4a80358acc78647d043",
"43640f408613cbf7393d900b921f22b826357f3b4fdff7168ec45cbfb3ef5eff");
testKatHex(new Keccak256(),
"eecbb8fdfa4da62170fd06727f697d81f83f601ff61e478105d3cb7502f2c89bf3e8f56edd469d049807a38882a7eefbc85fc9a950952e9fa84b8afebd3ce782d4da598002827b1eb98882ea1f0a8f7aa9ce013a6e9bc462fb66c8d4a18da21401e1b93356eb12f3725b6db1684f2300a98b9a119e5d27ff704affb618e12708e77e6e5f34139a5a41131fd1d6336c272a8fc37080f041c71341bee6ab550cb4a20a6ddb6a8e0299f2b14bc730c54b8b1c1c487b494bdccfd3a53535ab2f231590bf2c4062fd2ad58f906a2d0d",
"cb3713a5d5abbc6af72f8b38a701c71269b3b51c62ec5116f96ad0d42a10fd90");
testKatHex(new Keccak256(),
"e64f3e4ace5c8418d65fec2bc5d2a303dd458034736e3b0df719098be7a206deaf52d6ba82316caf330ef852375188cde2b39cc94aa449578a7e2a8e3f5a9d68e816b8d16889fbc0ebf0939d04f63033ae9ae2bdab73b88c26d6bd25ee460ee1ef58fb0afa92cc539f8c76d3d097e7a6a63ebb9b5887edf3cf076028c5bbd5b9db3211371ad3fe121d4e9bf44229f4e1ecf5a0f9f0eba4d5ceb72878ab22c3f0eb5a625323ac66f7061f4a81fac834471e0c59553f108475fe290d43e6a055ae3ee46fb67422f814a68c4be3e8c9",
"b304fc4ca22131857d242eb12fe899ed9e6b55717c3360f113512a84174e6a77");
testKatHex(new Keccak256(),
"d2cb2d733033f9e91395312808383cc4f0ca974e87ec68400d52e96b3fa6984ac58d9ad0938dde5a973008d818c49607d9de2284e7618f1b8aed8372fbd52ed54557af4220fac09dfa8443011699b97d743f8f2b1aef3537ebb45dcc9e13dfb438428ee190a4efdb3caeb7f3933117bf63abdc7e57beb4171c7e1ad260ab0587806c4d137b6316b50abc9cce0dff3acada47bbb86be777e617bbe578ff4519844db360e0a96c6701290e76bb95d26f0f804c8a4f2717eac4e7de9f2cff3bbc55a17e776c0d02856032a6cd10ad2838",
"a3ca830d4771c1baa7fada76c5fceadd0f3cb9736e19cfec52e9e74f56bfdd55");
testKatHex(new Keccak256(),
"f2998955613dd414cc111df5ce30a995bb792e260b0e37a5b1d942fe90171a4ac2f66d4928d7ad377f4d0554cbf4c523d21f6e5f379d6f4b028cdcb9b1758d3b39663242ff3cb6ede6a36a6f05db3bc41e0d861b384b6dec58bb096d0a422fd542df175e1be1571fb52ae66f2d86a2f6824a8cfaacbac4a7492ad0433eeb15454af8f312b3b2a577750e3efbd370e8a8cac1582581971fba3ba4bd0d76e718dacf8433d33a59d287f8cc92234e7a271041b526e389efb0e40b6a18b3aaf658e82ed1c78631fd23b4c3eb27c3faec8685",
"ca158c46370e64a9f032f5ba8e091460fd555ef700edf7087e56bebffa261de7");
testKatHex(new Keccak256(),
"447797e2899b72a356ba55bf4df3acca6cdb1041eb477bd1834a9f9acbc340a294d729f2f97df3a610be0ff15edb9c6d5db41644b9874360140fc64f52aa03f0286c8a640670067a84e017926a70438db1bb361defee7317021425f8821def26d1efd77fc853b818545d055adc9284796e583c76e6fe74c9ac2587aa46aa8f8804f2feb5836cc4b3ababab8429a5783e17d5999f32242eb59ef30cd7adabc16d72dbdb097623047c98989f88d14eaf02a7212be16ec2d07981aaa99949ddf89ecd90333a77bc4e1988a82abf7c7caf3291",
"5901cda0cd1510db5455d072d2737a6721ad9ee3272953a19c7ab378bf3646c5");
testKatHex(new Keccak256(),
"9f2c18ade9b380c784e170fb763e9aa205f64303067eb1bcea93df5dac4bf5a2e00b78195f808df24fc76e26cb7be31dc35f0844cded1567bba29858cffc97fb29010331b01d6a3fb3159cc1b973d255da9843e34a0a4061cabdb9ed37f241bfabb3c20d32743f4026b59a4ccc385a2301f83c0b0a190b0f2d01acb8f0d41111e10f2f4e149379275599a52dc089b35fdd5234b0cfb7b6d8aebd563ca1fa653c5c021dfd6f5920e6f18bfafdbecbf0ab00281333ed50b9a999549c1c8f8c63d7626c48322e9791d5ff72294049bde91e73f8",
"f64562d6273efb5ebd027e0a6f38c3fb204a6dbe894ee01200ea249b747cfe66");
testKatHex(new Keccak256(),
"ae159f3fa33619002ae6bcce8cbbdd7d28e5ed9d61534595c4c9f43c402a9bb31f3b301cbfd4a43ce4c24cd5c9849cc6259eca90e2a79e01ffbac07ba0e147fa42676a1d668570e0396387b5bcd599e8e66aaed1b8a191c5a47547f61373021fa6deadcb55363d233c24440f2c73dbb519f7c9fa5a8962efd5f6252c0407f190dfefad707f3c7007d69ff36b8489a5b6b7c557e79dd4f50c06511f599f56c896b35c917b63ba35c6ff8092baf7d1658e77fc95d8a6a43eeb4c01f33f03877f92774be89c1114dd531c011e53a34dc248a2f0e6",
"e7d7a113b3a33175d0abd2cf4f9add8e41dc86c93c9552c5b3588277fbcaa24a");
testKatHex(new Keccak256(),
"3b8e97c5ffc2d6a40fa7de7fcefc90f3b12c940e7ab415321e29ee692dfac799b009c99dcddb708fce5a178c5c35ee2b8617143edc4c40b4d313661f49abdd93cea79d117518805496fe6acf292c4c2a1f76b403a97d7c399daf85b46ad84e16246c67d6836757bde336c290d5d401e6c1386ab32797af6bb251e9b2d8fe754c47482b72e0b394eab76916126fd68ea7d65eb93d59f5b4c5ac40f7c3b37e7f3694f29424c24af8c8f0ef59cd9dbf1d28e0e10f799a6f78cad1d45b9db3d7dee4a7059abe99182714983b9c9d44d7f5643596d4f3",
"3b40c1493af411ae7849904d478df2407254bf62b88e9bffd7b42bd2a60ce0fa");
testKatHex(new Keccak256(),
"3434ec31b10fafdbfeec0dd6bd94e80f7ba9dca19ef075f7eb017512af66d6a4bcf7d16ba0819a1892a6372f9b35bcc7ca8155ee19e8428bc22d214856ed5fa9374c3c09bde169602cc219679f65a1566fc7316f4cc3b631a18fb4449fa6afa16a3db2bc4212eff539c67cf184680826535589c7111d73bffce431b4c40492e763d9279560aaa38eb2dc14a212d723f994a1fe656ff4dd14551ce4e7c621b2aa5604a10001b2878a897a28a08095c325e10a26d2fb1a75bfd64c250309bb55a44f23bbac0d5516a1c687d3b41ef2fbbf9cc56d4739",
"feeb172aeab2f0deb748fb77801ca22d3ce99b7a9f9789e479b93d1f4b1d227f");
testKatHex(new Keccak256(),
"7c7953d81c8d208fd1c97681d48f49dd003456de60475b84070ef4847c333b74575b1fc8d2a186964485a3b8634feaa3595aaa1a2f4595a7d6b6153563dee31bbac443c8a33eed6d5d956a980a68366c2527b550ee950250dfb691eacbd5d56ae14b970668be174c89df2fea43ae52f13142639c884fd62a3683c0c3792f0f24ab1318bcb27e21f4737fab62c77ea38bc8fd1cf41f7dab64c13febe7152bf5bb7ab5a78f5346d43cc741cb6f72b7b8980f268b68bf62abdfb1577a52438fe14b591498cc95f071228460c7c5d5ceb4a7bde588e7f21c",
"b240bc52b8af1b502e26bf1d5e75fe2663bfba503faf10f46754dc3d23cb61c1");
testKatHex(new Keccak256(),
"7a6a4f4fdc59a1d223381ae5af498d74b7252ecf59e389e49130c7eaee626e7bd9897effd92017f4ccde66b0440462cdedfd352d8153e6a4c8d7a0812f701cc737b5178c2556f07111200eb627dbc299caa792dfa58f35935299fa3a3519e9b03166dffa159103ffa35e8577f7c0a86c6b46fe13db8e2cdd9dcfba85bdddcce0a7a8e155f81f712d8e9fe646153d3d22c811bd39f830433b2213dd46301941b59293fd0a33e2b63adbd95239bc01315c46fdb678875b3c81e053a40f581cfbec24a1404b1671a1b88a6d06120229518fb13a74ca0ac5ae",
"3ebace41f578fde6603e032fc1c7cfeef1cb79fe938a94d4c7b58b0ba4cb9720");
testKatHex(new Keccak256(),
"d9faa14cebe9b7de551b6c0765409a33938562013b5e8e0e1e0a6418df7399d0a6a771fb81c3ca9bd3bb8e2951b0bc792525a294ebd1083688806fe5e7f1e17fd4e3a41d00c89e8fcf4a363caedb1acb558e3d562f1302b3d83bb886ed27b76033798131dab05b4217381eaaa7ba15ec820bb5c13b516dd640eaec5a27d05fdfca0f35b3a5312146806b4c0275bcd0aaa3b2017f346975db566f9b4d137f4ee10644c2a2da66deeca5342e236495c3c6280528bfd32e90af4cd9bb908f34012b52b4bc56d48cc8a6b59bab014988eabd12e1a0a1c2e170e7",
"65eb4bd5ecca7164ce9b66727f112c1ac6120ddd200dcb5ce75b7487843fcdb8");
testKatHex(new Keccak256(),
"2d8427433d0c61f2d96cfe80cf1e932265a191365c3b61aaa3d6dcc039f6ba2ad52a6a8cc30fc10f705e6b7705105977fa496c1c708a277a124304f1fc40911e7441d1b5e77b951aad7b01fd5db1b377d165b05bbf898042e39660caf8b279fe5229d1a8db86c0999ed65e53d01ccbc4b43173ccf992b3a14586f6ba42f5fe30afa8ae40c5df29966f9346da5f8b35f16a1de3ab6de0f477d8d8660918060e88b9b9e9ca6a4207033b87a812dbf5544d39e4882010f82b6ce005f8e8ff6fe3c3806bc2b73c2b83afb704345629304f9f86358712e9fae3ca3e",
"d7155f6d3a90801f5e547689389ff62a604c81b7c1583d9204ac6b0194f0e8dd");
testKatHex(new Keccak256(),
"5e19d97887fcaac0387e22c6f803c34a3dacd2604172433f7a8a7a526ca4a2a1271ecfc5d5d7be5ac0d85d921095350dfc65997d443c21c8094e0a3fefd2961bcb94aed03291ae310ccda75d8ace4bc7d89e7d3e5d1650bda5d668b8b50bfc8e608e184f4d3a9a2badc4ff5f07e0c0bc8a9f2e0b2a26fd6d8c550008faaab75fd71af2a424bec9a7cd9d83fad4c8e9319115656a8717d3b523a68ff8004258b9990ed362308461804ba3e3a7e92d8f2ffae5c2fba55ba5a3c27c0a2f71bd711d2fe1799c2adb31b200035481e9ee5c4adf2ab9c0fa50b23975cf",
"aa7adaf16f39e398b4ab0ada037710556b720b0248d84817b2cfdf7600933595");
testKatHex(new Keccak256(),
"c8e976ab4638909387ce3b8d4e510c3230e5690e02c45093b1d297910abc481e56eea0f296f98379dfc9080af69e73b2399d1c143bee80ae1328162ce1ba7f6a8374679b20aacd380eb4e61382c99998704d62701afa914f9a2705cdb065885f50d086c3eb5753700c387118bb142f3e6da1e988dfb31ac75d7368931e45d1391a274b22f83ceb072f9bcabc0b216685bfd789f5023971024b1878a205442522f9ea7d8797a4102a3df41703768251fd5e017c85d1200a464118aa35654e7ca39f3c375b8ef8cbe7534dbc64bc20befb417cf60ec92f63d9ee7397",
"b195463fe22a160802be0a0464ee3ab4d2b117de517b331c7bf04c8ba90c6120");
testKatHex(new Keccak256(),
"7145fa124b7429a1fc2231237a949ba7201bcc1822d3272de005b682398196c25f7e5cc2f289fbf44415f699cb7fe6757791b1443410234ae061edf623359e2b4e32c19bf88450432dd01caa5eb16a1dc378f391ca5e3c4e5f356728bddd4975db7c890da8bbc84cc73ff244394d0d48954978765e4a00b593f70f2ca082673a261ed88dbcef1127728d8cd89bc2c597e9102ced6010f65fa75a14ebe467fa57ce3bd4948b6867d74a9df5c0ec6f530cbf2ee61ce6f06bc8f2864dff5583776b31df8c7ffcb61428a56bf7bd37188b4a5123bbf338393af46eda85e6",
"9f9296c53e753a4de4e5c5a547f51763a96903b083fbc7a7828effe4763a7ce6");
testKatHex(new Keccak256(),
"7fdfadcc9d29bad23ae038c6c65cda1aef757221b8872ed3d75ff8df7da0627d266e224e812c39f7983e4558bfd0a1f2bef3feb56ba09120ef762917b9c093867948547aee98600d10d87b20106878a8d22c64378bf634f7f75900c03986b077b0bf8b740a82447b61b99fee5376c5eb6680ec9e3088f0bdd0c56883413d60c1357d3c811950e5890e7600103c916341b80c743c6a852b7b4fb60c3ba21f3bc15b8382437a68454779cf3cd7f9f90ccc8ef28d0b706535b1e4108eb5627bb45d719cb046839aee311ca1abdc8319e050d67972cb35a6b1601b25dbf487",
"51de4090aec36f6c446476c709253272cab595d9887ca5d52a9b38086854d58f");
testKatHex(new Keccak256(),
"988638219fd3095421f826f56e4f09e356296b628c3ce6930c9f2e758fd1a80c8273f2f61e4daae65c4f110d3e7ca0965ac7d24e34c0dc4ba2d6ff0bf5bbe93b3585f354d7543cb542a1aa54674d375077f2d360a8f4d42f3db131c3b7ab7306267ba107659864a90c8c909460a73621d1f5d9d3fd95beb19b23db1cb6c0d0fba91d36891529b8bd8263caa1bab56a4affaed44962df096d8d5b1eb845ef31188b3e10f1af811a13f156beb7a288aae593ebd1471b624aa1a7c6adf01e2200b3d72d88a3aed3100c88231e41efc376906f0b580dc895f080fda5741db1cb",
"87a17400f919f2f53232b2205e1e8b14bd5698a76e74b9bdd5638a5c7ba5de1e");
testKatHex(new Keccak256(),
"5aab62756d307a669d146aba988d9074c5a159b3de85151a819b117ca1ff6597f6156e80fdd28c9c3176835164d37da7da11d94e09add770b68a6e081cd22ca0c004bfe7cd283bf43a588da91f509b27a6584c474a4a2f3ee0f1f56447379240a5ab1fb77fdca49b305f07ba86b62756fb9efb4fc225c86845f026ea542076b91a0bc2cdd136e122c659be259d98e5841df4c2f60330d4d8cdee7bf1a0a244524eecc68ff2aef5bf0069c9e87a11c6e519de1a4062a10c83837388f7ef58598a3846f49d499682b683c4a062b421594fafbc1383c943ba83bdef515efcf10d",
"9742536c461d0c3503a6c943fa8105dbcd1e542f728d71ccc0517cffc232ea68");
testKatHex(new Keccak256(),
"47b8216aa0fbb5d67966f2e82c17c07aa2d6327e96fcd83e3de7333689f3ee79994a1bf45082c4d725ed8d41205cb5bcdf5c341f77facb1da46a5b9b2cbc49eadf786bcd881f371a95fa17df73f606519aea0ff79d5a11427b98ee7f13a5c00637e2854134691059839121fea9abe2cd1bcbbbf27c74caf3678e05bfb1c949897ea01f56ffa4dafbe8644611685c617a3206c7a7036e4ac816799f693dafe7f19f303ce4eba09d21e03610201bfc665b72400a547a1e00fa9b7ad8d84f84b34aef118515e74def11b9188bd1e1f97d9a12c30132ec2806339bdadacda2fd8b78",
"ae3bf0936497a2955df874b7f2685314c7606030b9c6e7bfb8a8dff9825957b5");
testKatHex(new Keccak256(),
"8cff1f67fe53c098896d9136389bd8881816ccab34862bb67a656e3d98896f3ce6ffd4da73975809fcdf9666760d6e561c55238b205d8049c1cedeef374d1735daa533147bfa960b2cce4a4f254176bb4d1bd1e89654432b8dbe1a135c42115b394b024856a2a83dc85d6782be4b444239567ccec4b184d4548eae3ff6a192f343292ba2e32a0f267f31cc26719eb85245d415fb897ac2da433ee91a99424c9d7f1766a44171d1651001c38fc79294accc68ceb5665d36218454d3ba169ae058a831338c17743603f81ee173bfc0927464f9bd728dee94c6aeab7aae6ee3a627e8",
"5fe0216dcc1bdb48f3375b9173b7b232939aa2177c6d056e908c8f2b9293b030");
testKatHex(new Keccak256(),
"eacd07971cff9b9939903f8c1d8cbb5d4db1b548a85d04e037514a583604e787f32992bf2111b97ac5e8a938233552731321522ab5e8583561260b7d13ebeef785b23a41fd8576a6da764a8ed6d822d4957a545d5244756c18aa80e1aad4d1f9c20d259dee1711e2cc8fd013169fb7cc4ce38b362f8e0936ae9198b7e838dcea4f7a5b9429bb3f6bbcf2dc92565e3676c1c5e6eb3dd2a0f86aa23edd3d0891f197447692794b3dfa269611ad97f72b795602b4fdb198f3fd3eb41b415064256e345e8d8c51c555dc8a21904a9b0f1ad0effab7786aac2da3b196507e9f33ca356427",
"c339904ec865f24fb3f88f142a8786d770934e006eaeddbf45acbb6b38431021");
testKatHex(new Keccak256(),
"23ac4e9a42c6ef45c3336ce6dfc2ff7de8884cd23dc912fef0f7756c09d335c189f3ad3a23697abda851a81881a0c8ccafc980ab2c702564c2be15fe4c4b9f10dfb2248d0d0cb2e2887fd4598a1d4acda897944a2ffc580ff92719c95cf2aa42dc584674cb5a9bc5765b9d6ddf5789791d15f8dd925aa12bffafbce60827b490bb7df3dda6f2a143c8bf96abc903d83d59a791e2d62814a89b8080a28060568cf24a80ae61179fe84e0ffad00388178cb6a617d37efd54cc01970a4a41d1a8d3ddce46edbba4ab7c90ad565398d376f431189ce8c1c33e132feae6a8cd17a61c630012",
"4ca8b7febdf0a8062e9b76185cf4165071bb30928c18f14338c305626789c6d3");
testKatHex(new Keccak256(),
"0172df732282c9d488669c358e3492260cbe91c95cfbc1e3fea6c4b0ec129b45f242ace09f152fc6234e1bee8aab8cd56e8b486e1dcba9c05407c2f95da8d8f1c0af78ee2ed82a3a79ec0cb0709396ee62aadb84f8a4ee8a7ccca3c1ee84e302a09ea802204afecf04097e67d0f8e8a9d2651126c0a598a37081e42d168b0ae8a71951c524259e4e2054e535b779679bdade566fe55700858618e626b4a0faf895bcce9011504a49e05fd56127eae3d1f8917afb548ecadabda1020111fec9314c413498a360b08640549a22cb23c731ace743252a8227a0d2689d4c6001606678dfb921",
"23d2614420859b2f13ac084453dd35c33fe47c894dd50c087fd1653fcaeea00b");
testKatHex(new Keccak256(),
"3875b9240cf3e0a8b59c658540f26a701cf188496e2c2174788b126fd29402d6a75453ba0635284d08835f40051a2a9683dc92afb9383719191231170379ba6f4adc816fecbb0f9c446b785bf520796841e58878b73c58d3ebb097ce4761fdeabe15de2f319dfbaf1742cdeb389559c788131a6793e193856661376c81ce9568da19aa6925b47ffd77a43c7a0e758c37d69254909ff0fbd415ef8eb937bcd49f91468b49974c07dc819abd67395db0e05874ff83dddab895344abd0e7111b2df9e58d76d85ad98106b36295826be04d435615595605e4b4bb824b33c4afeb5e7bb0d19f909",
"5590bb75247d7cd0b35620f0062b90ffb2a24de41220ed629d9e9a7abcadfb51");
testKatHex(new Keccak256(),
"747cc1a59fefba94a9c75ba866c30dc5c1cb0c0f8e9361d98484956dd5d1a40f6184afbe3dac9f76028d1caeccfbf69199c6ce2b4c092a3f4d2a56fe5a33a00757f4d7dee5dfb0524311a97ae0668a47971b95766e2f6dd48c3f57841f91f04a00ad5ea70f2d479a2620dc5cd78eaab3a3b011719b7e78d19ddf70d9423798af77517ebc55392fcd01fc600d8d466b9e7a7a85bf33f9cc5419e9bd874ddfd60981150ddaf8d7febaa4374f0872a5628d318000311e2f5655365ad4d407c20e5c04df17a222e7deec79c5ab1116d8572f91cd06e1ccc7ced53736fc867fd49ecebe6bf8082e8a",
"e5932441b012e503b0b0c6104703ba02613e472ad65655c085b0adb07656b28f");
testKatHex(new Keccak256(),
"57af971fccaec97435dc2ec9ef0429bcedc6b647729ea168858a6e49ac1071e706f4a5a645ca14e8c7746d65511620682c906c8b86ec901f3dded4167b3f00b06cbfac6aee3728051b3e5ff10b4f9ed8bd0b8da94303c833755b3ca3aeddf0b54bc8d6632138b5d25bab03d17b3458a9d782108006f5bb7de75b5c0ba854b423d8bb801e701e99dc4feaad59bc1c7112453b04d33ea3635639fb802c73c2b71d58a56bbd671b18fe34ed2e3dca38827d63fdb1d4fb3285405004b2b3e26081a8ff08cd6d2b08f8e7b7e90a2ab1ed7a41b1d0128522c2f8bff56a7fe67969422ce839a9d4608f03",
"21c0d84eb7b61774f97db5d9acf1dffafb662c01ed291a442bec6f14d1334699");
testKatHex(new Keccak256(),
"04e16dedc1227902baaf332d3d08923601bdd64f573faa1bb7201918cfe16b1e10151dae875da0c0d63c59c3dd050c4c6a874011b018421afc4623ab0381831b2da2a8ba42c96e4f70864ac44e106f94311051e74c77c1291bf5db9539e69567bf6a11cf6932bbbad33f8946bf5814c066d851633d1a513510039b349939bfd42b858c21827c8ff05f1d09b1b0765dc78a135b5ca4dfba0801bcaddfa175623c8b647eacfb4444b85a44f73890607d06d507a4f8393658788669f6ef4deb58d08c50ca0756d5e2f49d1a7ad73e0f0b3d3b5f090acf622b1878c59133e4a848e05153592ea81c6fbf",
"0d1e6bb88188b49af0a9a05eb1af94255e6799515a2f8eb46aa6af9a9dd5b9e0");
testKatHex(new Keccak256(),
"7c815c384eee0f288ece27cced52a01603127b079c007378bc5d1e6c5e9e6d1c735723acbbd5801ac49854b2b569d4472d33f40bbb8882956245c366dc3582d71696a97a4e19557e41e54dee482a14229005f93afd2c4a7d8614d10a97a9dfa07f7cd946fa45263063ddd29db8f9e34db60daa32684f0072ea2a9426ecebfa5239fb67f29c18cbaa2af6ed4bf4283936823ac1790164fec5457a9cba7c767ca59392d94cab7448f50eb34e9a93a80027471ce59736f099c886dea1ab4cba4d89f5fc7ae2f21ccd27f611eca4626b2d08dc22382e92c1efb2f6afdc8fdc3d2172604f5035c46b8197d3",
"935ded24f5cecc69e1f012b60b7831abce7ef50eeb0bea7f816c3dbf2b4abdc1");
testKatHex(new Keccak256(),
"e29d505158dbdd937d9e3d2145658ee6f5992a2fc790f4f608d9cdb44a091d5b94b88e81fac4fdf5c49442f13b911c55886469629551189eaff62488f1a479b7db11a1560e198ddccccf50159093425ff7f1cb8d1d1246d0978764087d6bac257026b090efae8cec5f22b6f21c59ace1ac7386f5b8837ca6a12b6fbf5534dd0560ef05ca78104d3b943ddb220feaec89aa5e692a00f822a2ab9a2fe60350d75e7be16ff2526dc643872502d01f42f188abed0a6e9a6f5fd0d1ce7d5755c9ffa66b0af0b20bd806f08e06156690d81ac811778ca3dac2c249b96002017fce93e507e3b953acf99964b847",
"6755bf7e60e4e07965bac24e51b1de93e3dd42ae780f256647d4cc2ef8eff771");
testKatHex(new Keccak256(),
"d85588696f576e65eca0155f395f0cfacd83f36a99111ed5768df2d116d2121e32357ba4f54ede927f189f297d3a97fad4e9a0f5b41d8d89dd7fe20156799c2b7b6bf9c957ba0d6763f5c3bc5129747bbb53652b49290cff1c87e2cdf2c4b95d8aaee09bc8fbfa6883e62d237885810491bfc101f1d8c636e3d0ede838ad05c207a3df4fad76452979eb99f29afaecedd1c63b8d36cf378454a1bb67a741c77ac6b6b3f95f4f02b64dabc15438613ea49750df42ee90101f115aa9abb9ff64324dde9dabbb01054e1bd6b4bcdc7930a44c2300d87ca78c06924d0323ad7887e46c90e8c4d100acd9eed21e",
"62c9f5e5b56e2994327a7f9a03888da7bad67e387593803b1807482b137b4509");
testKatHex(new Keccak256(),
"3a12f8508b40c32c74492b66323375dcfe49184c78f73179f3314b79e63376b8ac683f5a51f1534bd729b02b04d002f55cbd8e8fc9b5ec1ea6bbe6a0d0e7431518e6ba45d124035f9d3dce0a8bb7bf1430a9f657e0b4ea9f20eb20c786a58181a1e20a96f1628f8728a13bdf7a4b4b32fc8aa7054cc4881ae7fa19afa65c6c3ee1b3ade3192af42054a8a911b8ec1826865d46d93f1e7c5e2b7813c92a506e53886f3d4701bb93d2a681ad109c845904bb861af8af0646b6e399b38b614051d34f6842563a0f37ec00cb3d865fc5d746c4987de2a65071100883a2a9c7a2bfe1e2dd603d9ea24dc7c5fd06be",
"9927fa5efd86304e73d54aa4928818c05b01504672c529471394a82e049e5f95");
testKatHex(new Keccak256(),
"1861edce46fa5ad17e1ff1deae084dec580f97d0a67885dfe834b9dfac1ae076742ce9e267512ca51f6df5a455af0c5fd6abf94acea103a3370c354485a7846fb84f3ac7c2904b5b2fbf227002ce512133bb7e1c4e50057bfd1e44db33c7cdb969a99e284b184f50a14b068a1fc5009d9b298dbe92239572a7627aac02abe8f3e3b473417f36d4d2505d16b7577f4526c9d94a270a2dfe450d06da8f6fa956879a0a55cfe99e742ea555ea477ba3e9b44ccd508c375423611af92e55345dc215779b2d5119eba49c71d49b9fe3f1569fa24e5ca3e332d042422a8b8158d3ec66a80012976f31ffdf305f0c9c5e",
"84e056bf7bdfc73a3aaa95b00a74a136d776069beeb304423bead90120db6350");
testKatHex(new Keccak256(),
"08d0ffde3a6e4ef65608ea672e4830c12943d7187ccff08f4941cfc13e545f3b9c7ad5eebbe2b01642b486caf855c2c73f58c1e4e3391da8e2d63d96e15fd84953ae5c231911b00ad6050cd7aafdaac9b0f663ae6aab45519d0f5391a541707d479034e73a6ad805ae3598096af078f1393301493d663dd71f83869ca27ba508b7e91e81e128c1716dc3acfe3084b2201e04cf8006617eecf1b640474a5d45cfde9f4d3ef92d6d055b909892194d8a8218db6d8203a84261d200d71473d7488f3427416b6896c137d455f231071cacbc86e0415ab88aec841d96b7b8af41e05bb461a40645bf176601f1e760de5f",
"401c3be59cc373453aef9603f7335c1d5fe669909a1425d7671dcb84a49887ca");
testKatHex(new Keccak256(),
"d782abb72a5be3392757be02d3e45be6e2099d6f000d042c8a543f50ed6ebc055a7f133b0dd8e9bc348536edcaae2e12ec18e8837df7a1b3c87ec46d50c241dee820fd586197552dc20beea50f445a07a38f1768a39e2b2ff05dddedf751f1def612d2e4d810daa3a0cc904516f9a43af660315385178a529e51f8aae141808c8bc5d7b60cac26bb984ac1890d0436ef780426c547e94a7b08f01acbfc4a3825eae04f520a9016f2fb8bf5165ed12736fc71e36a49a73614739eaa3ec834069b1b40f1350c2b3ab885c02c640b9f7686ed5f99527e41cfcd796fe4c256c9173186c226169ff257954ebda81c0e5f99",
"020485dcd264296afdb7f643ca828c93356f1714cbcc2fbbdd30f9896c3f2789");
testKatHex(new Keccak256(),
"5fce8109a358570e40983e1184e541833bb9091e280f258cfb144387b05d190e431cb19baa67273ba0c58abe91308e1844dcd0b3678baa42f335f2fa05267a0240b3c718a5942b3b3e3bfa98a55c25a1466e8d7a603722cb2bbf03afa54cd769a99f310735ee5a05dae2c22d397bd95635f58c48a67f90e1b73aafcd3f82117f0166657838691005b18da6f341d6e90fc1cdb352b30fae45d348294e501b63252de14740f2b85ae5299ddec3172de8b6d0ba219a20a23bb5e10ff434d39db3f583305e9f5c039d98569e377b75a70ab837d1df269b8a4b566f40bb91b577455fd3c356c914fa06b9a7ce24c7317a172d",
"f8c43e28816bb41993bdb866888f3cc59efba208390144d3878dbf9fbfa1d57e");
testKatHex(new Keccak256(),
"6172f1971a6e1e4e6170afbad95d5fec99bf69b24b674bc17dd78011615e502de6f56b86b1a71d3f4348087218ac7b7d09302993be272e4a591968aef18a1262d665610d1070ee91cc8da36e1f841a69a7a682c580e836941d21d909a3afc1f0b963e1ca5ab193e124a1a53df1c587470e5881fb54dae1b0d840f0c8f9d1b04c645ba1041c7d8dbf22030a623aa15638b3d99a2c400ff76f3252079af88d2b37f35ee66c1ad7801a28d3d388ac450b97d5f0f79e4541755356b3b1a5696b023f39ab7ab5f28df4202936bc97393b93bc915cb159ea1bd7a0a414cb4b7a1ac3af68f50d79f0c9c7314e750f7d02faa58bfa",
"4ea524e705020284b18284e34683725590e1ee565a6ff598ed4d42b1c987471e");
testKatHex(new Keccak256(),
"5668ecd99dfbe215c4118398ac9c9eaf1a1433fab4ccdd3968064752b625ea944731f75d48a27d047d67547f14dd0ffaa55fa5e29f7af0d161d85eafc4f2029b717c918eab9d304543290bdba7158b68020c0ba4e079bc95b5bc0fc044a992b94b4ccd3bd66d0eabb5dbbab904d62e00752c4e3b0091d773bcf4c14b4377da3efff824b1cb2fa01b32d1e46c909e626ed2dae920f4c7dbeb635bc754facbd8d49beba3f23c1c41ccbfcd0ee0c114e69737f5597c0bf1d859f0c767e18002ae8e39c26261ffde2920d3d0baf0e906138696cfe5b7e32b600f45df3aaa39932f3a7df95b60fa8712a2271fcaf3911ce7b511b1",
"e4963e74ae01ff7774b96b4f614d1cb2a4cf8d206ed93c66fa42f71432be2c3f");
testKatHex(new Keccak256(),
"03d625488354df30e3f875a68edfcf340e8366a8e1ab67f9d5c5486a96829dfac0578289082b2a62117e1cf418b43b90e0adc881fc6ae8105c888e9ecd21aea1c9ae1a4038dfd17378fed71d02ae492087d7cdcd98f746855227967cb1ab4714261ee3bead3f4db118329d3ebef4bc48a875c19ba763966da0ebea800e01b2f50b00e9dd4caca6dcb314d00184ef71ea2391d760c950710db4a70f9212ffc54861f9dc752ce18867b8ad0c48df8466ef7231e7ac567f0eb55099e622ebb86cb237520190a61c66ad34f1f4e289cb3282ae3eaac6152ed24d2c92bae5a7658252a53c49b7b02dfe54fdb2e90074b6cf310ac661",
"0f0d72bf8c0198459e45ece9cc18e930cb86263accf1fc7a00bc857ac9f201ad");
testKatHex(new Keccak256(),
"2edc282ffb90b97118dd03aaa03b145f363905e3cbd2d50ecd692b37bf000185c651d3e9726c690d3773ec1e48510e42b17742b0b0377e7de6b8f55e00a8a4db4740cee6db0830529dd19617501dc1e9359aa3bcf147e0a76b3ab70c4984c13e339e6806bb35e683af8527093670859f3d8a0fc7d493bcba6bb12b5f65e71e705ca5d6c948d66ed3d730b26db395b3447737c26fad089aa0ad0e306cb28bf0acf106f89af3745f0ec72d534968cca543cd2ca50c94b1456743254e358c1317c07a07bf2b0eca438a709367fafc89a57239028fc5fecfd53b8ef958ef10ee0608b7f5cb9923ad97058ec067700cc746c127a61ee3",
"dd1d2a92b3f3f3902f064365838e1f5f3468730c343e2974e7a9ecfcd84aa6db");
testKatHex(new Keccak256(),
"90b28a6aa1fe533915bcb8e81ed6cacdc10962b7ff82474f845eeb86977600cf70b07ba8e3796141ee340e3fce842a38a50afbe90301a3bdcc591f2e7d9de53e495525560b908c892439990a2ca2679c5539ffdf636777ad9c1cdef809cda9e8dcdb451abb9e9c17efa4379abd24b182bd981cafc792640a183b61694301d04c5b3eaad694a6bd4cc06ef5da8fa23b4fa2a64559c5a68397930079d250c51bcf00e2b16a6c49171433b0aadfd80231276560b80458dd77089b7a1bbcc9e7e4b9f881eacd6c92c4318348a13f4914eb27115a1cfc5d16d7fd94954c3532efaca2cab025103b2d02c6fd71da3a77f417d7932685888a",
"21bf20664cec2cd2ceb1dffc1d78893d5ca1a7da88eb6bfd0c6efca6190c9e15");
testKatHex(new Keccak256(),
"2969447d175490f2aa9bb055014dbef2e6854c95f8d60950bfe8c0be8de254c26b2d31b9e4de9c68c9adf49e4ee9b1c2850967f29f5d08738483b417bb96b2a56f0c8aca632b552059c59aac3f61f7b45c966b75f1d9931ff4e596406378cee91aaa726a3a84c33f37e9cdbe626b5745a0b06064a8a8d56e53aaf102d23dd9df0a3fdf7a638509a6761a33fa42fa8ddbd8e16159c93008b53765019c3f0e9f10b144ce2ac57f5d7297f9c9949e4ff68b70d339f87501ce8550b772f32c6da8ad2ce2100a895d8b08fa1eead7c376b407709703c510b50f87e73e43f8e7348f87c3832a547ef2bbe5799abedcf5e1f372ea809233f006",
"6472d7c530b548e4b47d2278d7172b421a0fb6398a2823dd2f2b26208af8942e");
testKatHex(new Keccak256(),
"721645633a44a2c78b19024eaecf58575ab23c27190833c26875dc0f0d50b46aea9c343d82ea7d5b3e50ec700545c615daeaea64726a0f05607576dcd396d812b03fb6551c641087856d050b10e6a4d5577b82a98afb89cee8594c9dc19e79feff0382fcfd127f1b803a4b9946f4ac9a4378e1e6e041b1389a53e3450cd32d9d2941b0cbabdb50da8ea2513145164c3ab6bcbd251c448d2d4b087ac57a59c2285d564f16da4ed5e607ed979592146ffb0ef3f3db308fb342df5eb5924a48256fc763141a278814c82d6d6348577545870ae3a83c7230ac02a1540fe1798f7ef09e335a865a2ae0949b21e4f748fb8a51f44750e213a8fb",
"2ac7ff80ee36d500995c973b8746d8466715e6d8b0f554aacb5d2876d7f5b874");
testKatHex(new Keccak256(),
"6b860d39725a14b498bb714574b4d37ca787404768f64c648b1751b353ac92bac2c3a28ea909fdf0423336401a02e63ec24325300d823b6864bb701f9d7c7a1f8ec9d0ae3584aa6dd62ea1997cd831b4babd9a4da50932d4efda745c61e4130890e156aee6113716daf95764222a91187db2effea49d5d0596102d619bd26a616bbfda8335505fbb0d90b4c180d1a2335b91538e1668f9f9642790b4e55f9cab0fe2bdd2935d001ee6419abab5457880d0dbff20ed8758f4c20fe759efb33141cf0e892587fe8187e5fbc57786b7e8b089612c936dfc03d27efbbe7c8673f1606bd51d5ff386f4a7ab68edf59f385eb1291f117bfe717399",
"9ff81d575f7bf0c4ef340b4279d56e16ce68821afcdf2a69105d4f9cadadd3cf");
testKatHex(new Keccak256(),
"6a01830af3889a25183244decb508bd01253d5b508ab490d3124afbf42626b2e70894e9b562b288d0a2450cfacf14a0ddae5c04716e5a0082c33981f6037d23d5e045ee1ef2283fb8b6378a914c5d9441627a722c282ff452e25a7ea608d69cee4393a0725d17963d0342684f255496d8a18c2961145315130549311fc07f0312fb78e6077334f87eaa873bee8aa95698996eb21375eb2b4ef53c14401207deb4568398e5dd9a7cf97e8c9663e23334b46912f8344c19efcf8c2ba6f04325f1a27e062b62a58d0766fc6db4d2c6a1928604b0175d872d16b7908ebc041761187cc785526c2a3873feac3a642bb39f5351550af9770c328af7b",
"09edc465d4fd91c5e86b292f041bcc17571e1f2e17d584dff21dd7dd8d8bff35");
testKatHex(new Keccak256(),
"b3c5e74b69933c2533106c563b4ca20238f2b6e675e8681e34a389894785bdade59652d4a73d80a5c85bd454fd1e9ffdad1c3815f5038e9ef432aac5c3c4fe840cc370cf86580a6011778bbedaf511a51b56d1a2eb68394aa299e26da9ada6a2f39b9faff7fba457689b9c1a577b2a1e505fdf75c7a0a64b1df81b3a356001bf0df4e02a1fc59f651c9d585ec6224bb279c6beba2966e8882d68376081b987468e7aed1ef90ebd090ae825795cdca1b4f09a979c8dfc21a48d8a53cdbb26c4db547fc06efe2f9850edd2685a4661cb4911f165d4b63ef25b87d0a96d3dff6ab0758999aad214d07bd4f133a6734fde445fe474711b69a98f7e2b",
"c6d86cc4ccef3bb70bf7bfddec6a9a04a0dd0a68fe1bf51c14648cf506a03e98");
testKatHex(new Keccak256(),
"83af34279ccb5430febec07a81950d30f4b66f484826afee7456f0071a51e1bbc55570b5cc7ec6f9309c17bf5befdd7c6ba6e968cf218a2b34bd5cf927ab846e38a40bbd81759e9e33381016a755f699df35d660007b5eadf292feefb735207ebf70b5bd17834f7bfa0e16cb219ad4af524ab1ea37334aa66435e5d397fc0a065c411ebbce32c240b90476d307ce802ec82c1c49bc1bec48c0675ec2a6c6f3ed3e5b741d13437095707c565e10d8a20b8c20468ff9514fcf31b4249cd82dcee58c0a2af538b291a87e3390d737191a07484a5d3f3fb8c8f15ce056e5e5f8febe5e1fb59d6740980aa06ca8a0c20f5712b4cde5d032e92ab89f0ae1",
"1afc9ba63eea27603b3a7a5562e12b31e8fe9a96812b531e9d048385fb76d44f");
testKatHex(new Keccak256(),
"a7ed84749ccc56bb1dfba57119d279d412b8a986886d810f067af349e8749e9ea746a60b03742636c464fc1ee233acc52c1983914692b64309edfdf29f1ab912ec3e8da074d3f1d231511f5756f0b6eead3e89a6a88fe330a10face267bffbfc3e3090c7fd9a850561f363ad75ea881e7244f80ff55802d5ef7a1a4e7b89fcfa80f16df54d1b056ee637e6964b9e0ffd15b6196bdd7db270c56b47251485348e49813b4eb9ed122a01b3ea45ad5e1a929df61d5c0f3e77e1fdc356b63883a60e9cbb9fc3e00c2f32dbd469659883f690c6772e335f617bc33f161d6f6984252ee12e62b6000ac5231e0c9bc65be223d8dfd94c5004a101af9fd6c0fb",
"9b5e15531385f0d495fdbe686e3e02eca42b9f1b1ce8837ad3b3e42e6198050a");
testKatHex(new Keccak256(),
"a6fe30dcfcda1a329e82ab50e32b5f50eb25c873c5d2305860a835aecee6264aa36a47429922c4b8b3afd00da16035830edb897831c4e7b00f2c23fc0b15fdc30d85fb70c30c431c638e1a25b51caf1d7e8b050b7f89bfb30f59f0f20fecff3d639abc4255b3868fc45dd81e47eb12ab40f2aac735df5d1dc1ad997cefc4d836b854cee9ac02900036f3867fe0d84afff37bde3308c2206c62c4743375094108877c73b87b2546fe05ea137bedfc06a2796274099a0d554da8f7d7223a48cbf31b7decaa1ebc8b145763e3673168c1b1b715c1cd99ecd3ddb238b06049885ecad9347c2436dff32c771f34a38587a44a82c5d3d137a03caa27e66c8ff6",
"216fc325f942eed08401527a8f41c088527c6479342622c907ea08ff3290f8c6");
testKatHex(new Keccak256(),
"83167ff53704c3aa19e9fb3303539759c46dd4091a52ddae9ad86408b69335989e61414bc20ab4d01220e35241eff5c9522b079fba597674c8d716fe441e566110b6211531ceccf8fd06bc8e511d00785e57788ed9a1c5c73524f01830d2e1148c92d0edc97113e3b7b5cd3049627abdb8b39dd4d6890e0ee91993f92b03354a88f52251c546e64434d9c3d74544f23fb93e5a2d2f1fb15545b4e1367c97335b0291944c8b730ad3d4789273fa44fb98d78a36c3c3764abeeac7c569c1e43a352e5b770c3504f87090dee075a1c4c85c0c39cf421bdcc615f9eff6cb4fe6468004aece5f30e1ecc6db22ad9939bb2b0ccc96521dfbf4ae008b5b46bc006e",
"43184b9f2db5b6da5160bc255dbe19a0c94533b884809815b7b326d868589edc");
testKatHex(new Keccak256(),
"3a3a819c48efde2ad914fbf00e18ab6bc4f14513ab27d0c178a188b61431e7f5623cb66b23346775d386b50e982c493adbbfc54b9a3cd383382336a1a0b2150a15358f336d03ae18f666c7573d55c4fd181c29e6ccfde63ea35f0adf5885cfc0a3d84a2b2e4dd24496db789e663170cef74798aa1bbcd4574ea0bba40489d764b2f83aadc66b148b4a0cd95246c127d5871c4f11418690a5ddf01246a0c80a43c70088b6183639dcfda4125bd113a8f49ee23ed306faac576c3fb0c1e256671d817fc2534a52f5b439f72e424de376f4c565cca82307dd9ef76da5b7c4eb7e085172e328807c02d011ffbf33785378d79dc266f6a5be6bb0e4a92eceebaeb1",
"348fb774adc970a16b1105669442625e6adaa8257a89effdb5a802f161b862ea");
}
}
| 101,807
| 121.660241
| 525
|
java
|
ethereumj
|
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/validator/ProofOfWorkRuleTest.java
|
/*
* Copyright (c) [2016] [ <ether.camp> ]
* This file is part of the ethereumJ library.
*
* The ethereumJ library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The ethereumJ library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the ethereumJ library. If not, see <http://www.gnu.org/licenses/>.
*/
package org.ethereum.validator;
import org.ethereum.core.Block;
import org.junit.Ignore;
import org.junit.Test;
import org.spongycastle.util.encoders.Hex;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
/**
* @author Mikhail Kalinin
* @since 02.09.2015
*/
public class ProofOfWorkRuleTest {
private ProofOfWorkRule rule = new ProofOfWorkRule();
@Test // check exact values
public void test_0() {
byte[] rlp = Hex.decode("f9021af90215a0809870664d9a43cf1827aa515de6374e2fad1bf64290a9f261dd49c525d6a0efa01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934794f927a40c8b7f6e07c5af7fa2155b4864a4112b13a010c8ec4f62ecea600c616443bcf527d97e5b1c5bb4a9769c496d1bf32636c95da056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b901000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000086015a1c28ae5e82bf958302472c808455c4e47b99476574682f76312e302e312f6c696e75782f676f312e342e32a0788ac534cb2f6a226a01535e29b11a96602d447aed972463b5cbcc7dd5d633f288e2ff1b6435006517c0c0");
Block b = new Block(rlp);
byte[] boundary = b.getHeader().getPowBoundary();
byte[] pow = b.getHeader().calcPowValue();
assertArrayEquals(Hex.decode("0000000000bd59a74a8619f14c3d793747f1989a29ed6c83a5a488bac185679b"), boundary);
assertArrayEquals(Hex.decode("000000000017f78925469f2f18fe7866ef6d3ed28d36fb013bc93d081e05809c"), pow);
}
@Test // valid block
public void test_1() {
byte[] rlp = Hex.decode("f9021af90215a0809870664d9a43cf1827aa515de6374e2fad1bf64290a9f261dd49c525d6a0efa01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934794f927a40c8b7f6e07c5af7fa2155b4864a4112b13a010c8ec4f62ecea600c616443bcf527d97e5b1c5bb4a9769c496d1bf32636c95da056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b901000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000086015a1c28ae5e82bf958302472c808455c4e47b99476574682f76312e302e312f6c696e75782f676f312e342e32a0788ac534cb2f6a226a01535e29b11a96602d447aed972463b5cbcc7dd5d633f288e2ff1b6435006517c0c0");
Block b = new Block(rlp);
assertTrue(rule.validate(b.getHeader()).success);
}
@Test // invalid block
public void test_2() {
byte[] rlp = Hex.decode("f90219f90214a0809870664d9a43cf1827aa515de6374e2fad1bf64290a9f261dd49c525d6a0efa01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934794f927a40c8b7f6e07c5af7fa2155b4864a4112b13a010c8ec4f62ecea600c616443bcf527d97e5b1c5bb4a9769c496d1bf32636c95da056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000857147839e5e82bf958302472c808455c4e47b99476574682f76312e302e312f6c696e75782f676f312e342e32a0788ac534cb2f6a226a01535e29b11a96602d447aed972463b5cbcc7dd5d633f288e2ff1b6435006517c0c0");
Block b = new Block(rlp);
assertFalse(rule.validate(b.getHeader()).success);
}
@Ignore
@Test // stress test
public void test_3() {
int iterCnt = 1_000_000;
byte[] rlp = Hex.decode("f9021af90215a0809870664d9a43cf1827aa515de6374e2fad1bf64290a9f261dd49c525d6a0efa01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934794f927a40c8b7f6e07c5af7fa2155b4864a4112b13a010c8ec4f62ecea600c616443bcf527d97e5b1c5bb4a9769c496d1bf32636c95da056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b901000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000086015a1c28ae5e82bf958302472c808455c4e47b99476574682f76312e302e312f6c696e75782f676f312e342e32a0788ac534cb2f6a226a01535e29b11a96602d447aed972463b5cbcc7dd5d633f288e2ff1b6435006517c0c0");
Block b = new Block(rlp);
long start = System.currentTimeMillis();
for (int i = 0; i < iterCnt; i++)
rule.validate(b.getHeader());
long total = System.currentTimeMillis() - start;
System.out.println(String.format("Time: total = %d ms, per block = %.2f ms", total, (double) total / iterCnt));
}
}
| 6,908
| 85.3625
| 1,118
|
java
|
ethereumj
|
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/validator/EthashRuleTest.java
|
package org.ethereum.validator;
import org.ethereum.core.Block;
import org.ethereum.core.BlockHeader;
import org.ethereum.core.BlockSummary;
import org.ethereum.listener.CompositeEthereumListener;
import org.ethereum.listener.EthereumListener;
import org.ethereum.mine.EthashValidationHelper;
import org.junit.Test;
import org.spongycastle.util.encoders.Hex;
import java.util.Collections;
import static org.ethereum.validator.BlockHeaderRule.Success;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;
/**
* @author Mikhail Kalinin
* @since 12.07.2018
*/
public class EthashRuleTest {
static class CompositeEthereumListenerMock extends CompositeEthereumListener {
@Override
public void onBlock(final BlockSummary blockSummary, final boolean best) {
for (final EthereumListener listener : listeners) {
listener.onBlock(blockSummary, best);
}
}
@Override
public void onSyncDone(final SyncState state) {
for (final EthereumListener listener : listeners) {
listener.onSyncDone(state);
}
}
}
static class EthashValidationHelperMock extends EthashValidationHelper {
long preCacheCounter = 0;
public EthashValidationHelperMock(CacheOrder cacheOrder) {
super(cacheOrder);
}
@Override
public void preCache(long blockNumber) {
preCacheCounter += 1;
}
}
BlockHeader validHeader = new BlockHeader(Hex.decode("f90211a0d4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d493479405a56e2d52c817161883f50c441c3228cfe54d9fa0d67e4d450343046425ae4271474353857ab860dbc0a1dde64b41b5cd3a532bf3a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b90100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008503ff80000001821388808455ba422499476574682f76312e302e302f6c696e75782f676f312e342e32a0969b900de27b6ac6a67742365dd65f55a0526c41fd18e1b16f1a1215c2e66f5988539bd4979fef1ec4"));
BlockHeader partlyValidHeader = new BlockHeader(Hex.decode("f9020aa0548911f91c652dd110641a55f09fa4fa83d9c28d3afddce60a64256fb58468e9a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347940000000000000000000000000000000000000000a09c7460dbfd853c07a340e55bab456d4035190400246b731b193ec8c8044f41aea056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000830200000185100000000080845b471fc591457468657265756d4a20706f7765726564a03e2b0549a7219dd2a5c125aee28676a754272fea5d548f314521508635a8387888d3c67376b7804888"));
BlockHeader invalidHeader = new BlockHeader(Hex.decode("f90211a0d4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d493479405a56e2d52c817161883f50c441c3228cfe54d9fa0d67e4d450343046425ae4271474353857ab860dbc0a1dde64b41b5cd3a532bf3a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b90100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008503ff80000001821388808455ba422499476574682f76312e302e302f6c696e75782f676f312e342e32a0969b900de27b6ac6a67742365dd65f55a0526c41fd18e1b16f1a1215c2e66f5a88539bd4979fef1ec4"));
BlockSummary dummySummaryNum_1 = new BlockSummary(new Block(validHeader, Collections.emptyList(), Collections.emptyList()),
Collections.emptyMap(), Collections.emptyList(), Collections.emptyList());
@Test
public void fake() {
System.out.println(Hex.toHexString(new Block(Hex.decode("f9020ff9020aa0548911f91c652dd110641a55f09fa4fa83d9c28d3afddce60a64256fb58468e9a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347940000000000000000000000000000000000000000a09c7460dbfd853c07a340e55bab456d4035190400246b731b193ec8c8044f41aea056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000830200000185100000000080845b471fc591457468657265756d4a20706f7765726564a03e2b0549a7219dd2a5c125aee28676a754272fea5d548f314521508635a8387888d3c67376b7804888c0c0")).getHeader().getEncoded()));
}
@Test
public void testFake() {
CompositeEthereumListener listener = new CompositeEthereumListenerMock();
EthashRule rule = new EthashRule(EthashRule.Mode.fake, EthashRule.ChainType.main, listener);
assertEquals(Success, rule.validate(validHeader));
assertEquals(Success, rule.validate(partlyValidHeader));
assertNotEquals(Success, rule.validate(invalidHeader));
}
@Test
public void testStrict() {
CompositeEthereumListener listener = new CompositeEthereumListenerMock();
EthashRule rule = new EthashRule(EthashRule.Mode.strict, EthashRule.ChainType.main, listener);
// cache is empty, fallback into fake rule
assertEquals(Success, rule.validate(partlyValidHeader));
// trigger ethash cache
listener.onBlock(dummySummaryNum_1, true);
assertEquals(Success, rule.validate(validHeader));
assertNotEquals(Success, rule.validate(partlyValidHeader));
assertNotEquals(Success, rule.validate(invalidHeader));
// check that full verification is done on each run in strict mode
for (int i = 0; i < 100; i++) {
assertNotEquals(Success, rule.validate(partlyValidHeader));
}
}
@Test
public void testMixed() {
CompositeEthereumListener listener = new CompositeEthereumListenerMock();
EthashRule rule = new EthashRule(EthashRule.Mode.mixed, EthashRule.ChainType.main, listener);
// trigger ethash cache
listener.onBlock(dummySummaryNum_1, true);
// check mixed mode randomness
boolean fullCheckTriggered = false;
boolean partialCheckTriggered = false;
for (int i = 0; i < 100; i++) {
if (Success != rule.validate(partlyValidHeader)) {
fullCheckTriggered = true;
} else {
partialCheckTriggered = true;
}
if (partialCheckTriggered & fullCheckTriggered) break;
}
assertTrue(fullCheckTriggered);
assertTrue(partialCheckTriggered);
// trigger onSyncDone
listener.onSyncDone(EthereumListener.SyncState.COMPLETE);
// check that full verification is done on each run in strict mode
for (int i = 0; i < 100; i++) {
assertNotEquals(Success, rule.validate(partlyValidHeader));
}
}
@Test
public void testCacheMain() {
EthashValidationHelperMock helper = new EthashValidationHelperMock(EthashValidationHelper.CacheOrder.direct);
CompositeEthereumListener listener = new CompositeEthereumListenerMock();
EthashRule rule = new EthashRule(EthashRule.Mode.mixed, EthashRule.ChainType.main, listener);
rule.ethashHelper = helper;
// trigger cache
for (int i = 0; i < 100; i++) {
listener.onBlock(dummySummaryNum_1, false);
listener.onBlock(dummySummaryNum_1, true);
}
// must be triggered on best block only
assertEquals(100, helper.preCacheCounter);
}
@Test
public void testCacheDirect() {
EthashValidationHelperMock helper = new EthashValidationHelperMock(EthashValidationHelper.CacheOrder.direct);
CompositeEthereumListener listener = new CompositeEthereumListenerMock();
EthashRule rule = new EthashRule(EthashRule.Mode.mixed, EthashRule.ChainType.direct, listener);
rule.ethashHelper = helper;
// trigger cache
for (int i = 0; i < 100; i++) {
rule.validate(validHeader);
}
// must be triggered each verification attempt, in spite of mixed mode
assertEquals(100, helper.preCacheCounter);
}
@Test
public void testCacheReverse() {
EthashValidationHelperMock helper = new EthashValidationHelperMock(EthashValidationHelper.CacheOrder.direct);
CompositeEthereumListener listener = new CompositeEthereumListenerMock();
EthashRule rule = new EthashRule(EthashRule.Mode.mixed, EthashRule.ChainType.reverse, listener);
rule.ethashHelper = helper;
// trigger cache
for (int i = 0; i < 100; i++) {
rule.validate(validHeader);
}
// must be triggered each verification attempt, in spite of mixed mode
assertEquals(100, helper.preCacheCounter);
}
}
| 10,678
| 58.994382
| 1,156
|
java
|
ethereumj
|
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/core/StateTest.java
|
/*
* Copyright (c) [2016] [ <ether.camp> ]
* This file is part of the ethereumJ library.
*
* The ethereumJ library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The ethereumJ library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the ethereumJ library. If not, see <http://www.gnu.org/licenses/>.
*/
package org.ethereum.core;
import org.ethereum.crypto.HashUtil;
import org.ethereum.trie.Trie;
import org.ethereum.trie.TrieImpl;
import org.ethereum.db.ByteArrayWrapper;
import org.junit.Ignore;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.spongycastle.util.encoders.Hex;
import java.math.BigInteger;
import static org.junit.Assert.assertEquals;
public class StateTest {
private static final String GENESIS_STATE_ROOT = "7e204dc9cfb7acdf062ff0b8052f7fcb0b7e6593754773967932ce458d134af3";
private static final Logger logger = LoggerFactory.getLogger("test");
@Ignore //TODO #POC9
@Test
public void testGenesisAccounts() {
Trie trie = generateGenesisState();
assertEquals(GENESIS_STATE_ROOT, Hex.toHexString(trie.getRootHash()));
}
@Ignore
@Test // calc state after applying first tx on genesis
public void test2() {
// explanation:
// 0) create genesis
// 1) apply cost of tx to cd2a3d9f938e13cd947ec05abc7fe734df8dd826
// 2) create AccountState for 77045e71a7a2c50903d88e564cd72fab11e82051
// 3) minner gets the gas + coinbase ==> 6260000000000000 + 1500000000000000000
// 4) calc the root
Trie<byte[]> trie = generateGenesisState();
String expected = "c12b4d771fbcc0d56ec106f8d465d24b9d4c36d60275bbafa7d69694d6708660";
// Get and update sender in world state
byte[] cowAddress = Hex.decode("cd2a3d9f938e13cd947ec05abc7fe734df8dd826");
byte[] rlpEncodedState = trie.get(cowAddress);
AccountState account_1 = new AccountState(rlpEncodedState)
.withBalanceIncrement(new BigInteger("-6260000000001000"))
.withIncrementedNonce();
trie.put(cowAddress, account_1.getEncoded());
// Add contract to world state
byte[] codeData = Hex.decode("61778e600054");
AccountState account_2 = new AccountState(BigInteger.ZERO, BigInteger.valueOf(1000))
.withCodeHash(HashUtil.sha3(codeData));
byte[] contractAddress = Hex.decode("77045e71a7a2c50903d88e564cd72fab11e82051"); // generated based on sender + nonce
trie.put(contractAddress, account_2.getEncoded());
// this is saved in the db
// trie.update(HashUtil.keccak(codeData), codeData);
// Update miner in world state
byte[] minerAddress = Hex.decode("4c5f4d519dff3c16f0d54b6866e256fbbbc1a600");
AccountState account_3 = new AccountState(BigInteger.ZERO, new BigInteger("1506260000000000000"));
trie.put(minerAddress, account_3.getEncoded());
assertEquals(expected, Hex.toHexString(trie.getRootHash()));
/* *** GROSS DATA ***
BlockData [
hash=22cf863ab836a6f5c29389d2e77f4792a3b3b52908c98ed14b1cbe91491a3e36
parentHash=77ef4fdaf389dca53236bcf7f72698e154eab2828f86fbc4fc6cd9225d285c89
unclesHash=1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347
coinbase=4c5f4d519dff3c16f0d54b6866e256fbbbc1a600
stateHash=69c21ff84a5af0b53b11c61110a16d6ad43dad37b3eb29ae8e88c936eb06456a
txTrieHash=a77691cf47bec9021d3f027fc8ef2d51b758b600a79967154354b8e37108896f
difficulty=3ff000
number=1
minGasPrice=10000000000000
gasLimit=999023
gasUsed=626
timestamp=1401979976 (2014.06.05 15:52:56)
extraData=null
nonce=0000000000000000000000000000000000000000000000005d439960040e4505
TransactionReceipt[
TransactionData [ hash=1ee6fa3149a5e9c09b54009eb6e108aaa7ecd79483d57eedcf2dff93a1505588 nonce=null,
gasPrice=09184e72a000, gas=03e8, receiveAddress=0000000000000000000000000000000000000000, value=03e8,
data=60016000546006601160003960066000f261778e600054, signatureV=27,
signatureR=2b379f22050e3554c3fa5423d9040bb28dcc7f905300db4e67c03bcf9b27003c,
signatureS=59f47793e050974e6b5fca2848b19925637b883a012693b54d712f1c4f74def5
]
, postTxState=7fa5bd00f6e03b5a5718560f1e25179b227167585a3c3da06a48f554365fb527
, cumulativeGas=0272]
]
+++ 4c5f4d519dff3c16f0d54b6866e256fbbbc1a600:
+++ 77045e71a7a2c50903d88e564cd72fab11e82051: $[61,77,8e,60,0,54] ([])
* cd2a3d9f938e13cd947ec05abc7fe734df8dd826: #1 1606938044258990275541962092341162602522202987522792835300376 (-6260000000001000)
*/
assertEquals(expected, Hex.toHexString(trie.getRootHash()));
}
private Trie generateGenesisState() {
Trie<byte[]> trie = new TrieImpl();
Genesis genesis = (Genesis)Genesis.getInstance();
for (ByteArrayWrapper key : genesis.getPremine().keySet()) {
trie.put(key.getData(), genesis.getPremine().get(key).accountState.getEncoded());
}
return trie;
}
}
| 5,707
| 38.916084
| 139
|
java
|
ethereumj
|
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/core/ImportLightTest.java
|
/*
* Copyright (c) [2016] [ <ether.camp> ]
* This file is part of the ethereumJ library.
*
* The ethereumJ library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The ethereumJ library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the ethereumJ library. If not, see <http://www.gnu.org/licenses/>.
*/
package org.ethereum.core;
import org.ethereum.config.CommonConfig;
import org.ethereum.config.SystemProperties;
import org.ethereum.core.genesis.GenesisLoader;
import org.ethereum.crypto.ECKey;
import org.ethereum.crypto.HashUtil;
import org.ethereum.datasource.inmem.HashMapDB;
import org.ethereum.datasource.NoDeleteSource;
import org.ethereum.db.IndexedBlockStore;
import org.ethereum.db.RepositoryRoot;
import org.ethereum.listener.EthereumListenerAdapter;
import org.ethereum.mine.Ethash;
import org.ethereum.util.ByteUtil;
import org.ethereum.util.blockchain.SolidityContract;
import org.ethereum.util.blockchain.StandaloneBlockchain;
import org.ethereum.validator.DependentBlockHeaderRuleAdapter;
import org.ethereum.vm.LogInfo;
import org.ethereum.vm.program.invoke.ProgramInvokeFactoryImpl;
import org.junit.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.spongycastle.util.encoders.Hex;
import java.io.FileInputStream;
import java.io.IOException;
import java.math.BigInteger;
import java.util.*;
/**
* Created by Anton Nashatyrev on 29.12.2015.
*/
public class ImportLightTest {
@BeforeClass
public static void setup() {
SystemProperties.getDefault().setBlockchainConfig(StandaloneBlockchain.getEasyMiningConfig());
}
@AfterClass
public static void cleanup() {
SystemProperties.resetToDefault();
}
@Test
public void simpleFork() {
StandaloneBlockchain sb = new StandaloneBlockchain();
Block b1 = sb.createBlock();
Block b2_ = sb.createBlock();
Block b3_ = sb.createForkBlock(b2_);
Block b2 = sb.createForkBlock(b1);
Block b3 = sb.createForkBlock(b2);
Block b4 = sb.createForkBlock(b3);
Block b5 = sb.createForkBlock(b4);
}
@Test
@Ignore
public void importBlocks() throws Exception {
Logger logger = LoggerFactory.getLogger("VM");
logger.info("#######################################");
BlockchainImpl blockchain = createBlockchain(GenesisLoader.loadGenesis(
getClass().getResourceAsStream("/genesis/frontier.json")));
try (Scanner scanner = new Scanner(new FileInputStream("D:\\ws\\ethereumj\\work\\blocks-rec.dmp"))) {
while (scanner.hasNext()) {
String blockHex = scanner.next();
Block block = new Block(Hex.decode(blockHex));
ImportResult result = blockchain.tryToConnect(block);
if (result != ImportResult.EXIST && result != ImportResult.IMPORTED_BEST) {
throw new RuntimeException(result + ": " + block + "");
}
System.out.println("Imported " + block.getShortDescr());
}
}
}
@Ignore // periodically get different roots ?
@Test
public void putZeroValue() {
StandaloneBlockchain sb = new StandaloneBlockchain();
SolidityContract a = sb.submitNewContract("contract A { uint public a; function set() { a = 0;}}");
a.callFunction("set");
Block block = sb.createBlock();
System.out.println(Hex.toHexString(block.getStateRoot()));
Assert.assertEquals("cad42169cafc7855c25b8889df83faf38e493fb6e95b2c9c8e155dbc340160d6", Hex.toHexString(block.getStateRoot()));
}
@Test
public void simpleRebranch() {
StandaloneBlockchain sb = new StandaloneBlockchain();
Block b0 = sb.getBlockchain().getBestBlock();
ECKey addr1 = ECKey.fromPrivate(HashUtil.sha3("1".getBytes()));
BigInteger bal2 = sb.getBlockchain().getRepository().getBalance(sb.getSender().getAddress());
sb.sendEther(addr1.getAddress(), BigInteger.valueOf(100));
Block b1 = sb.createBlock();
sb.sendEther(addr1.getAddress(), BigInteger.valueOf(100));
Block b2 = sb.createBlock();
sb.sendEther(addr1.getAddress(), BigInteger.valueOf(100));
Block b3 = sb.createBlock();
BigInteger bal1 = sb.getBlockchain().getRepository().getBalance(addr1.getAddress());
Assert.assertEquals(BigInteger.valueOf(300), bal1);
sb.sendEther(addr1.getAddress(), BigInteger.valueOf(200));
Block b1_ = sb.createForkBlock(b0);
sb.sendEther(addr1.getAddress(), BigInteger.valueOf(200));
Block b2_ = sb.createForkBlock(b1_);
sb.sendEther(addr1.getAddress(), BigInteger.valueOf(200));
Block b3_ = sb.createForkBlock(b2_);
sb.sendEther(addr1.getAddress(), BigInteger.valueOf(200));
Block b4_ = sb.createForkBlock(b3_);
BigInteger bal1_ = sb.getBlockchain().getRepository().getBalance(addr1.getAddress());
Assert.assertEquals(BigInteger.valueOf(800), bal1_);
// BigInteger bal2_ = sb.getBlockchain().getRepository().getBalance(sb.getSender().getAddress());
// Assert.assertEquals(bal2, bal2_);
}
@Test
public void createFork() throws Exception {
// importing forked chain
BlockchainImpl blockchain = createBlockchain(GenesisLoader.loadGenesis(
getClass().getResourceAsStream("/genesis/genesis-light.json")));
blockchain.setMinerCoinbase(Hex.decode("ee0250c19ad59305b2bdb61f34b45b72fe37154f"));
Block parent = blockchain.getBestBlock();
System.out.println("Mining #1 ...");
Block b1 = blockchain.createNewBlock(parent, Collections.EMPTY_LIST, Collections.EMPTY_LIST);
Ethash.getForBlock(SystemProperties.getDefault(), b1.getNumber()).mineLight(b1).get();
ImportResult importResult = blockchain.tryToConnect(b1);
System.out.println("Best: " + blockchain.getBestBlock().getShortDescr());
Assert.assertTrue(importResult == ImportResult.IMPORTED_BEST);
System.out.println("Mining #2 ...");
Block b2 = blockchain.createNewBlock(b1, Collections.EMPTY_LIST, Collections.EMPTY_LIST);
Ethash.getForBlock(SystemProperties.getDefault(), b2.getNumber()).mineLight(b2).get();
importResult = blockchain.tryToConnect(b2);
System.out.println("Best: " + blockchain.getBestBlock().getShortDescr());
Assert.assertTrue(importResult == ImportResult.IMPORTED_BEST);
System.out.println("Mining #3 ...");
Block b3 = blockchain.createNewBlock(b2, Collections.EMPTY_LIST, Collections.EMPTY_LIST);
Ethash.getForBlock(SystemProperties.getDefault(), b3.getNumber()).mineLight(b3).get();
importResult = blockchain.tryToConnect(b3);
System.out.println("Best: " + blockchain.getBestBlock().getShortDescr());
Assert.assertTrue(importResult == ImportResult.IMPORTED_BEST);
System.out.println("Mining #2' ...");
Block b2_ = blockchain.createNewBlock(b1, Collections.EMPTY_LIST, Collections.EMPTY_LIST);
b2_.setExtraData(new byte[]{77, 77}); // setting extra data to differ from block #2
Ethash.getForBlock(SystemProperties.getDefault(), b2_.getNumber()).mineLight(b2_).get();
importResult = blockchain.tryToConnect(b2_);
System.out.println("Best: " + blockchain.getBestBlock().getShortDescr());
Assert.assertTrue(importResult == ImportResult.IMPORTED_NOT_BEST);
System.out.println("Mining #3' ...");
Block b3_ = blockchain.createNewBlock(b2_, Collections.EMPTY_LIST, Collections.singletonList(b2.getHeader()));
Ethash.getForBlock(SystemProperties.getDefault(), b3_.getNumber()).mineLight(b3_).get();
importResult = blockchain.tryToConnect(b3_);
System.out.println("Best: " + blockchain.getBestBlock().getShortDescr());
Assert.assertTrue(importResult == ImportResult.IMPORTED_NOT_BEST);
}
@Test
public void invalidBlockTest() throws Exception {
// testing that bad block import effort doesn't affect the repository state
BlockchainImpl blockchain = createBlockchain(GenesisLoader.loadGenesis(
getClass().getResourceAsStream("/genesis/genesis-light.json")));
blockchain.setMinerCoinbase(Hex.decode("ee0250c19ad59305b2bdb61f34b45b72fe37154f"));
Block parent = blockchain.getBestBlock();
ECKey senderKey = ECKey.fromPrivate(Hex.decode("3ec771c31cac8c0dba77a69e503765701d3c2bb62435888d4ffa38fed60c445c"));
byte[] receiverAddr = Hex.decode("31e2e1ed11951c7091dfba62cd4b7145e947219c");
System.out.println("Mining #1 ...");
Transaction tx = new Transaction(ByteUtil.intToBytesNoLeadZeroes(0),
ByteUtil.longToBytesNoLeadZeroes(50_000_000_000L),
ByteUtil.longToBytesNoLeadZeroes(0xfffff),
receiverAddr, new byte[]{77}, new byte[0]);
tx.sign(senderKey.getPrivKeyBytes());
Block b1bad = blockchain.createNewBlock(parent, Collections.singletonList(tx), Collections.EMPTY_LIST);
// making the block bad
b1bad.getStateRoot()[0] = 0;
b1bad.setStateRoot(b1bad.getStateRoot()); // invalidate block
Ethash.getForBlock(SystemProperties.getDefault(), b1bad.getNumber()).mineLight(b1bad).get();
ImportResult importResult = blockchain.tryToConnect(b1bad);
Assert.assertTrue(importResult == ImportResult.INVALID_BLOCK);
Block b1 = blockchain.createNewBlock(parent, Collections.singletonList(tx), Collections.EMPTY_LIST);
Ethash.getForBlock(SystemProperties.getDefault(), b1.getNumber()).mineLight(b1).get();
importResult = blockchain.tryToConnect(b1);
Assert.assertTrue(importResult == ImportResult.IMPORTED_BEST);
}
@Test
public void doubleTransactionTest() throws Exception {
// Testing that blocks containing tx with invalid nonce are rejected
BlockchainImpl blockchain = createBlockchain(GenesisLoader.loadGenesis(
getClass().getResourceAsStream("/genesis/genesis-light.json")));
blockchain.setMinerCoinbase(Hex.decode("ee0250c19ad59305b2bdb61f34b45b72fe37154f"));
Block parent = blockchain.getBestBlock();
ECKey senderKey = ECKey.fromPrivate(Hex.decode("3ec771c31cac8c0dba77a69e503765701d3c2bb62435888d4ffa38fed60c445c"));
byte[] receiverAddr = Hex.decode("31e2e1ed11951c7091dfba62cd4b7145e947219c");
System.out.println("Mining #1 ...");
Transaction tx = new Transaction(ByteUtil.intToBytesNoLeadZeroes(0),
ByteUtil.longToBytesNoLeadZeroes(50_000_000_000L),
ByteUtil.longToBytesNoLeadZeroes(0xfffff),
receiverAddr, new byte[]{77}, new byte[0]);
tx.sign(senderKey);
Block b1 = blockchain.createNewBlock(parent, Collections.singletonList(tx), Collections.EMPTY_LIST);
Ethash.getForBlock(SystemProperties.getDefault(), b1.getNumber()).mineLight(b1).get();
ImportResult importResult = blockchain.tryToConnect(b1);
Assert.assertTrue(importResult == ImportResult.IMPORTED_BEST);
System.out.println("Mining #2 (bad) ...");
Block b2 = blockchain.createNewBlock(b1, Collections.singletonList(tx), Collections.EMPTY_LIST);
Ethash.getForBlock(SystemProperties.getDefault(), b2.getNumber()).mineLight(b2).get();
importResult = blockchain.tryToConnect(b2);
Assert.assertTrue(importResult == ImportResult.INVALID_BLOCK);
System.out.println("Mining #2 (bad) ...");
Transaction tx1 = new Transaction(ByteUtil.intToBytesNoLeadZeroes(1),
ByteUtil.longToBytesNoLeadZeroes(50_000_000_000L),
ByteUtil.longToBytesNoLeadZeroes(0xfffff),
receiverAddr, new byte[]{77}, new byte[0]);
tx1.sign(senderKey);
b2 = blockchain.createNewBlock(b1, Arrays.asList(tx1, tx1), Collections.EMPTY_LIST);
Ethash.getForBlock(SystemProperties.getDefault(), b2.getNumber()).mineLight(b2).get();
importResult = blockchain.tryToConnect(b2);
Assert.assertTrue(importResult == ImportResult.INVALID_BLOCK);
System.out.println("Mining #2 ...");
Transaction tx2 = new Transaction(ByteUtil.intToBytesNoLeadZeroes(2),
ByteUtil.longToBytesNoLeadZeroes(50_000_000_000L),
ByteUtil.longToBytesNoLeadZeroes(0xfffff),
receiverAddr, new byte[]{77}, new byte[0]);
tx2.sign(senderKey);
b2 = blockchain.createNewBlock(b1, Arrays.asList(tx1, tx2), Collections.EMPTY_LIST);
Ethash.getForBlock(SystemProperties.getDefault(), b2.getNumber()).mineLight(b2).get();
importResult = blockchain.tryToConnect(b2);
Assert.assertTrue(importResult == ImportResult.IMPORTED_BEST);
System.out.println("Mining #2 (fork) ...");
tx1 = new Transaction(ByteUtil.intToBytesNoLeadZeroes(1),
ByteUtil.longToBytesNoLeadZeroes(50_000_000_000L),
ByteUtil.longToBytesNoLeadZeroes(0xfffff),
receiverAddr, new byte[]{88}, new byte[0]);
tx1.sign(senderKey);
Block b2f = blockchain.createNewBlock(b1, Collections.singletonList(tx1), Collections.EMPTY_LIST);
Ethash.getForBlock(SystemProperties.getDefault(), b2f.getNumber()).mineLight(b2f).get();
importResult = blockchain.tryToConnect(b2f);
Assert.assertTrue(importResult == ImportResult.IMPORTED_NOT_BEST);
System.out.println("Mining #3 ...");
tx1 = new Transaction(ByteUtil.intToBytesNoLeadZeroes(3),
ByteUtil.longToBytesNoLeadZeroes(50_000_000_000L),
ByteUtil.longToBytesNoLeadZeroes(0xfffff),
receiverAddr, new byte[]{88}, new byte[0]);
tx1.sign(senderKey);
tx2 = new Transaction(ByteUtil.intToBytesNoLeadZeroes(4),
ByteUtil.longToBytesNoLeadZeroes(50_000_000_000L),
ByteUtil.longToBytesNoLeadZeroes(0xfffff),
receiverAddr, new byte[]{88}, new byte[0]);
tx2.sign(senderKey);
Transaction tx3 = new Transaction(ByteUtil.intToBytesNoLeadZeroes(5),
ByteUtil.longToBytesNoLeadZeroes(50_000_000_000L),
ByteUtil.longToBytesNoLeadZeroes(0xfffff),
receiverAddr, new byte[]{88}, new byte[0]);
tx3.sign(senderKey);
Block b3 = blockchain.createNewBlock(b2, Arrays.asList(tx1, tx2, tx3), Collections.EMPTY_LIST);
Ethash.getForBlock(SystemProperties.getDefault(), b3.getNumber()).mineLight(b3).get();
importResult = blockchain.tryToConnect(b3);
Assert.assertTrue(importResult == ImportResult.IMPORTED_BEST);
}
@Test
public void invalidBlockTotalDiff() throws Exception {
// Check that importing invalid block doesn't affect totalDifficulty
BlockchainImpl blockchain = createBlockchain(GenesisLoader.loadGenesis(
getClass().getResourceAsStream("/genesis/genesis-light.json")));
blockchain.setMinerCoinbase(Hex.decode("ee0250c19ad59305b2bdb61f34b45b72fe37154f"));
Block parent = blockchain.getBestBlock();
System.out.println("Mining #1 ...");
BigInteger totalDifficulty = blockchain.getTotalDifficulty();
Block b1 = blockchain.createNewBlock(parent, Collections.EMPTY_LIST, Collections.EMPTY_LIST);
b1.setStateRoot(new byte[32]);
Ethash.getForBlock(SystemProperties.getDefault(), b1.getNumber()).mineLight(b1).get();
ImportResult importResult = blockchain.tryToConnect(b1);
Assert.assertTrue(importResult == ImportResult.INVALID_BLOCK);
Assert.assertEquals(totalDifficulty, blockchain.getTotalDifficulty());
}
@Test
public void simpleDbTest() {
StandaloneBlockchain bc = new StandaloneBlockchain();
SolidityContract parent = bc.submitNewContract("contract A {" +
" uint public a;" +
" function set(uint a_) { a = a_;}" +
"}");
bc.createBlock();
parent.callFunction("set", 123);
bc.createBlock();
Object ret = parent.callConstFunction("a")[0];
System.out.println("Ret = " + ret);
}
@Test
public void createContractFork() throws Exception {
// #1 (Parent) --> #2 --> #3 (Child) ----------------------> #4 (call Child)
// \-------------------------------> #2' (forked Child)
//
// Testing the situation when the Child contract is created by the Parent contract
// first on the main chain with one parameter (#3) and then on the fork with another parameter (#2')
// so their storages are different. Check that original Child storage is not broken
// on the main chain (#4)
String contractSrc =
"contract Child {" +
" int a;" +
" int b;" +
" int public c;" +
" function Child(int i) {" +
" a = 333 + i;" +
" b = 444 + i;" +
" }" +
" function sum() {" +
" c = a + b;" +
" }" +
"}" +
"contract Parent {" +
" address public child;" +
" function createChild(int a) returns (address) {" +
" child = new Child(a);" +
" return child;" +
" }" +
"}";
StandaloneBlockchain bc = new StandaloneBlockchain();
SolidityContract parent = bc.submitNewContract(contractSrc, "Parent");
Block b1 = bc.createBlock();
Block b2 = bc.createBlock();
parent.callFunction("createChild", 100);
Block b3 = bc.createBlock();
byte[] childAddress = (byte[]) parent.callConstFunction("child")[0];
parent.callFunction("createChild", 200);
Block b2_ = bc.createForkBlock(b1);
SolidityContract child = bc.createExistingContractFromSrc(contractSrc, "Child", childAddress);
child.callFunction("sum");
Block b4 = bc.createBlock();
Assert.assertEquals(BigInteger.valueOf(100 + 333 + 100 + 444), child.callConstFunction("c")[0]);
}
@Test
public void createContractFork1() throws Exception {
// Test creation of the contract on forked branch with different storage
String contractSrc =
"contract A {" +
" int public a;" +
" function A() {" +
" a = 333;" +
" }" +
"}" +
"contract B {" +
" int public a;" +
" function B() {" +
" a = 111;" +
" }" +
"}";
{
StandaloneBlockchain bc = new StandaloneBlockchain();
Block b1 = bc.createBlock();
Block b2 = bc.createBlock();
SolidityContract a = bc.submitNewContract(contractSrc, "A");
Block b3 = bc.createBlock();
SolidityContract b = bc.submitNewContract(contractSrc, "B");
Block b2_ = bc.createForkBlock(b1);
Assert.assertEquals(BigInteger.valueOf(333), a.callConstFunction("a")[0]);
Assert.assertEquals(BigInteger.valueOf(111), b.callConstFunction(b2_, "a")[0]);
Block b3_ = bc.createForkBlock(b2_);
Block b4_ = bc.createForkBlock(b3_);
Assert.assertEquals(BigInteger.valueOf(111), a.callConstFunction("a")[0]);
Assert.assertEquals(BigInteger.valueOf(333), a.callConstFunction(b3, "a")[0]);
}
}
@Test
public void createValueTest() throws IOException, InterruptedException {
// checks that correct msg.value is passed when contract internally created with value
String contract =
"pragma solidity ^0.4.3;\n" +
"contract B {\n" +
" uint public valReceived;\n" +
" \n" +
" function B() payable {\n" +
" valReceived = msg.value;\n" +
" }\n" +
"}\n" +
"contract A {\n" +
" function () payable { }\n" +
" address public child;\n" +
" function create() payable {\n" +
" child = (new B).value(20)();\n" +
" }\n" +
"}";
StandaloneBlockchain bc = new StandaloneBlockchain().withAutoblock(true);
SolidityContract a = bc.submitNewContract(contract, "A");
bc.sendEther(a.getAddress(), BigInteger.valueOf(10_000));
a.callFunction(10, "create");
byte[] childAddress = (byte[]) a.callConstFunction("child")[0];
SolidityContract b = bc.createExistingContractFromSrc(contract, "B", childAddress);
BigInteger val = (BigInteger) b.callConstFunction("valReceived")[0];
Assert.assertEquals(20, val.longValue());
}
@Test
public void contractCodeForkTest() throws IOException, InterruptedException {
String contractA =
"contract A {" +
" function call() returns (uint) {" +
" return 111;" +
" }" +
"}";
String contractB =
"contract B {" +
" function call() returns (uint) {" +
" return 222222;" +
" }" +
"}";
StandaloneBlockchain bc = new StandaloneBlockchain();
Block b1 = bc.createBlock();
SolidityContract a = bc.submitNewContract(contractA);
Block b2 = bc.createBlock();
Assert.assertEquals(BigInteger.valueOf(111), a.callConstFunction("call")[0]);
SolidityContract b = bc.submitNewContract(contractB);
Block b2_ = bc.createForkBlock(b1);
Block b3 = bc.createForkBlock(b2);
Assert.assertEquals(BigInteger.valueOf(111), a.callConstFunction("call")[0]);
Assert.assertEquals(BigInteger.valueOf(111), a.callConstFunction(b2, "call")[0]);
Assert.assertEquals(BigInteger.valueOf(222222), b.callConstFunction(b2_, "call")[0]);
}
@Test
public void operateNotExistingContractTest() throws IOException, InterruptedException {
// checking that addr.balance doesn't cause the account to be created
// and the subsequent call to that non-existent address costs 25K gas
byte[] addr = Hex.decode("0101010101010101010101010101010101010101");
String contractA =
"pragma solidity ^0.4.3;" +
"contract B { function dummy() {}}" +
"contract A {" +
" function callBalance() returns (uint) {" +
" address addr = 0x" + Hex.toHexString(addr) + ";" +
" uint bal = addr.balance;" +
" }" +
" function callMethod() returns (uint) {" +
" address addr = 0x" + Hex.toHexString(addr) + ";" +
" B b = B(addr);" +
" b.dummy();" +
" }" +
"}";
StandaloneBlockchain bc = new StandaloneBlockchain()
.withGasPrice(1)
.withGasLimit(5_000_000L);
SolidityContract a = bc.submitNewContract(contractA, "A");
bc.createBlock();
{
BigInteger balance1 = getSenderBalance(bc);
a.callFunction("callBalance");
bc.createBlock();
BigInteger balance2 = getSenderBalance(bc);
long spent = balance1.subtract(balance2).longValue();
// checking balance of not existed address should take
// less that gas limit
Assert.assertTrue(spent < 100_000);
}
{
BigInteger balance1 = getSenderBalance(bc);
a.callFunction("callMethod");
bc.createBlock();
BigInteger balance2 = getSenderBalance(bc);
long spent = balance1.subtract(balance2).longValue();
// invalid jump error occurred
// all gas wasted
// (for history: it is worked fine in ^0.3.1)
// Assert.assertEquals(5_000_000L, spent);
// FIX for 0.4.25 and apparently some earlier versions
Assert.assertTrue(spent < 100_000);
}
}
private BigInteger getSenderBalance(StandaloneBlockchain bc) {
return bc.getBlockchain().getRepository().getBalance(bc.getSender().getAddress());
}
@Test
public void spendGasSimpleTest() throws IOException, InterruptedException {
// check the caller spend value for tx
StandaloneBlockchain bc = new StandaloneBlockchain().withGasPrice(1);
BigInteger balance1 = bc.getBlockchain().getRepository().getBalance(bc.getSender().getAddress());
bc.sendEther(new byte[20], BigInteger.ZERO);
bc.createBlock();
BigInteger balance2 = bc.getBlockchain().getRepository().getBalance(bc.getSender().getAddress());
long spent = balance1.subtract(balance2).longValue();
Assert.assertNotEquals(0, spent);
}
@Test
@Ignore
public void deepRecursionTest() throws Exception {
String contractA =
"contract A {" +
" function recursive(){" +
" this.recursive();" +
" }" +
"}";
StandaloneBlockchain bc = new StandaloneBlockchain().withGasLimit(5_000_000);
SolidityContract a = bc.submitNewContract(contractA, "A");
bc.createBlock();
a.callFunction("recursive");
bc.createBlock();
// no StackOverflowException
}
@Test
public void prevBlockHashOnFork() throws Exception {
String contractA =
"contract A {" +
" bytes32 public blockHash;" +
" function a(){" +
" blockHash = block.blockhash(block.number - 1);" +
" }" +
"}";
StandaloneBlockchain bc = new StandaloneBlockchain();
SolidityContract a = bc.submitNewContract(contractA);
Block b1 = bc.createBlock();
Block b2 = bc.createBlock();
Block b3 = bc.createBlock();
Block b4 = bc.createBlock();
Block b5 = bc.createBlock();
Block b6 = bc.createBlock();
Block b2_ = bc.createForkBlock(b1);
a.callFunction("a");
Block b3_ = bc.createForkBlock(b2_);
Object hash = a.callConstFunction(b3_, "blockHash")[0];
Assert.assertArrayEquals((byte[]) hash, b2_.getHash());
// no StackOverflowException
}
@Test
public void rollbackInternalTx() throws Exception {
String contractA =
"contract A {" +
" uint public a;" +
" uint public b;" +
" function f() {" +
" b = 1;" +
" this.call.gas(10000)(bytes4(sha3('exception()')));" +
" a = 2;" +
" }" +
" function exception() {" +
" b = 2;" +
" throw;" +
" }" +
"}";
StandaloneBlockchain bc = new StandaloneBlockchain();
SolidityContract a = bc.submitNewContract(contractA);
bc.createBlock();
a.callFunction("f");
bc.createBlock();
Object av = a.callConstFunction("a")[0];
Object bv = a.callConstFunction("b")[0];
assert BigInteger.valueOf(2).equals(av);
assert BigInteger.valueOf(1).equals(bv);
}
@Test()
public void selfdestructAttack() throws Exception {
String contractSrc = "" +
"pragma solidity ^0.4.3;" +
"contract B {" +
" function suicide(address benefic) {" +
" selfdestruct(benefic);" +
" }" +
"}" +
"contract A {" +
" uint public a;" +
" function f() {" +
" B b = new B();" +
" for (uint i = 0; i < 3500; i++) {" +
" b.suicide.gas(10000)(address(i));" +
" }" +
" a = 2;" +
" }" +
"}";
StandaloneBlockchain bc = new StandaloneBlockchain()
.withGasLimit(1_000_000_000L)
.withDbDelay(0);
SolidityContract a = bc.submitNewContract(contractSrc, "A");
bc.createBlock();
a.callFunction("f");
bc.createBlock();
String stateRoot = Hex.toHexString(bc.getBlockchain().getRepository().getRoot());
// Assert.assertEquals("82d5bdb6531e26011521da5601481c9dbef326aa18385f2945fd77bee288ca31", stateRoot);
Object av = a.callConstFunction("a")[0];
assert BigInteger.valueOf(2).equals(av);
assert bc.getTotalDbHits() < 8300; // reduce this assertion if you make further optimizations
}
@Test
@Ignore
public void threadRacePendingTest() throws Exception {
String contractA =
"contract A {" +
" uint[32] public somedata1;" +
" uint[32] public somedata2;" +
" function set1(uint idx, uint val){" +
" somedata1[idx] = val;" +
" }" +
" function set2(uint idx, uint val){" +
" somedata2[idx] = val;" +
" }" +
"}";
final StandaloneBlockchain bc = new StandaloneBlockchain();
final StandaloneBlockchain.SolidityContractImpl a = (StandaloneBlockchain.SolidityContractImpl) bc.submitNewContract(contractA);
bc.createBlock();
Block b = null;
int cnt = 1;
final CallTransaction.Function function = a.contract.getByName("set");
new Thread(() -> {
int cnt1 = 1;
while (cnt1++ > 0) {
try {
bc.generatePendingTransactions();
// byte[] encode = function.encode(cnt % 32, cnt);
// Transaction callTx1 = bc.createTransaction(new ECKey(), 0, a.getAddress(), BigInteger.ZERO, encode);
// bc.getPendingState().addPendingTransaction(callTx1);
// Transaction callTx2 = bc.createTransaction(, 0, a.getAddress(), BigInteger.ZERO, encode);
// bc.getPendingState().addPendingTransaction(callTx);
Thread.sleep(10);
} catch (Exception e) {
e.printStackTrace();
}
}
}).start();
Block b_1 = null;
while(cnt++ > 0) {
long s = System.nanoTime();
a.callFunction("set1", cnt % 32, cnt);
a.callFunction("set2", cnt % 32, cnt);
bc.sendEther(new byte[32], BigInteger.ONE);
a.callFunction("set1", (cnt + 1) % 32, cnt + 1);
a.callFunction("set2", (cnt + 1) % 32, cnt + 1);
bc.sendEther(new byte[32], BigInteger.ONE);
Block prev = b;
if (cnt % 5 == 0) {
b = bc.createForkBlock(b_1);
} else {
b = bc.createBlock();
}
b_1 = prev;
if (cnt % 3 == 0) {
bc.getBlockchain().flush();
}
long t = System.nanoTime() - s;
System.out.println("" + String.format(Locale.US, "%1$.2f", t / 1_000_000d) + ", " + b.getDifficultyBI() + ", " + b.getShortDescr());
}
// SolidityContract a = bc.submitNewContract(contractA);
// Block b1 = bc.createBlock();
// Block b2 = bc.createBlock();
// Block b3 = bc.createBlock();
// Block b4 = bc.createBlock();
// Block b5 = bc.createBlock();
// Block b6 = bc.createBlock();
// Block b2_ = bc.createForkBlock(b1);
// a.callFunction("a");
// Block b3_ = bc.createForkBlock(b2_);
// Object hash = a.callConstFunction(b3_, "blockHash")[0];
//
// System.out.println(Hex.toHexString((byte[]) hash));
// System.out.println(Hex.toHexString(b2_.getHash()));
// no StackOverflowException
}
@Test
public void suicideInFailedCall() throws Exception {
// check that if a contract is suicide in call which is failed (thus suicide is reverted)
// the refund for this suicide is not added
String contractA =
"contract B {" +
" function f(){" +
" suicide(msg.sender);" +
" }" +
"}" +
"contract A {" +
" function f(){" +
" this.call(bytes4(sha3('bad()')));" +
" }" +
" function bad() {" +
" B b = new B();" +
" b.call(bytes4(sha3('f()')));" +
" throw;" +
" }" +
"}";
StandaloneBlockchain bc = new StandaloneBlockchain().withGasLimit(5_000_000);
SolidityContract a = bc.submitNewContract(contractA, "A");
bc.createBlock();
final BigInteger[] refund = new BigInteger[1];
bc.addEthereumListener(new EthereumListenerAdapter() {
@Override
public void onTransactionExecuted(TransactionExecutionSummary summary) {
refund[0] = summary.getGasRefund();
}
});
a.callFunction("f");
bc.createBlock();
Assert.assertEquals(BigInteger.ZERO, refund[0]);
// no StackOverflowException
}
@Test
public void logInFailedCall() throws Exception {
// check that if a contract is suicide in call which is failed (thus suicide is reverted)
// the refund for this suicide is not added
String contractA =
"contract A {" +
" function f(){" +
" this.call(bytes4(sha3('bad()')));" +
" }" +
" function bad() {" +
" log0(1234);" +
" throw;" +
" }" +
"}";
StandaloneBlockchain bc = new StandaloneBlockchain().withGasLimit(5_000_000);
SolidityContract a = bc.submitNewContract(contractA, "A");
bc.createBlock();
final List<LogInfo> logs = new ArrayList<>();
bc.addEthereumListener(new EthereumListenerAdapter() {
@Override
public void onTransactionExecuted(TransactionExecutionSummary summary) {
logs.addAll(summary.getLogs());
}
});
a.callFunction("f");
bc.createBlock();
Assert.assertEquals(0, logs.size());
// no StackOverflowException
}
@Test
public void ecRecoverTest() throws Exception {
// checks that ecrecover precompile contract rejects v > 255
String contractA =
"contract A {" +
" function f (bytes32 hash, bytes32 v, bytes32 r, bytes32 s) returns (address) {" +
" assembly {" +
" mstore(0x100, hash)" +
" mstore(0x120, v)" +
" mstore(0x140, r)" +
" mstore(0x160, s)" +
" let ret := callcode(0x50000, 0x01, 0x0, 0x100, 0x80, 0x200, 0x220)" + // call ecrecover
" return(0x200, 0x20)" +
" }" +
" }" +
"}";
StandaloneBlockchain bc = new StandaloneBlockchain().withGasLimit(5_000_000);
SolidityContract a = bc.submitNewContract(contractA, "A");
bc.createBlock();
ECKey key = ECKey.DUMMY;
byte[] hash = new byte[32];
ECKey.ECDSASignature signature = key.sign(hash);
Object[] ret = a.callConstFunction("f", hash,
ByteUtil.merge(new byte[31], new byte[]{signature.v}),
ByteUtil.bigIntegerToBytes(signature.r, 32),
ByteUtil.bigIntegerToBytes(signature.s, 32));
Assert.assertArrayEquals(key.getAddress(), (byte[]) ret[0]);
ret = a.callConstFunction("f", hash,
ByteUtil.merge(new byte[] {1}, new byte[30], new byte[]{signature.v}),
ByteUtil.bigIntegerToBytes(signature.r, 32),
ByteUtil.bigIntegerToBytes(signature.s, 32));
Assert.assertArrayEquals(new byte[20], (byte[]) ret[0]);
}
@Test
public void functionTypeTest() throws IOException, InterruptedException {
String contractA =
"contract A {" +
" int public res;" +
" function calc(int b, function (int a) external returns (int) f) external returns (int) {" +
" return f.gas(10000)(b);" +
" }" +
" function fInc(int a) external returns (int) { return a + 1;}" +
" function fDec(int a) external returns (int) { return a - 1;}" +
" function test() {" +
" res = this.calc.gas(100000)(111, this.fInc);" +
" }" +
"}";
StandaloneBlockchain bc = new StandaloneBlockchain();
SolidityContract a = bc.submitNewContract(contractA);
bc.createBlock();
a.callFunction("test");
bc.createBlock();
Assert.assertEquals(BigInteger.valueOf(112), a.callConstFunction("res")[0]);
BigInteger r1 = (BigInteger) a.callConstFunction("calc", 222, a.getFunction("fInc"))[0];
Assert.assertEquals(223, r1.intValue());
BigInteger r2 = (BigInteger) a.callConstFunction("calc", 222, a.getFunction("fDec"))[0];
Assert.assertEquals(221, r2.intValue());
}
public static BlockchainImpl createBlockchain(Genesis genesis) {
IndexedBlockStore blockStore = new IndexedBlockStore();
blockStore.init(new HashMapDB<byte[]>(), new HashMapDB<byte[]>());
RepositoryRoot repository = new RepositoryRoot(new NoDeleteSource<>(new HashMapDB<byte[]>()));
ProgramInvokeFactoryImpl programInvokeFactory = new ProgramInvokeFactoryImpl();
EthereumListenerAdapter listener = new EthereumListenerAdapter();
BlockchainImpl blockchain = new BlockchainImpl(blockStore, repository)
.withParentBlockHeaderValidator(new CommonConfig().parentHeaderValidator());
blockchain.setParentHeaderValidator(new DependentBlockHeaderRuleAdapter());
blockchain.setProgramInvokeFactory(programInvokeFactory);
blockchain.byTest = true;
PendingStateImpl pendingState = new PendingStateImpl(listener);
pendingState.setBlockchain(blockchain);
blockchain.setPendingState(pendingState);
Repository track = repository.startTracking();
Genesis.populateRepository(track, genesis);
track.commit();
repository.commit();
blockStore.saveBlock(genesis, genesis.getDifficultyBI(), true);
blockchain.setBestBlock(genesis);
blockchain.setTotalDifficulty(genesis.getDifficultyBI());
return blockchain;
}
}
| 40,103
| 42.168999
| 144
|
java
|
ethereumj
|
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/core/ChainTest.java
|
package org.ethereum.core;
import org.ethereum.core.genesis.GenesisJson;
import org.ethereum.core.genesis.GenesisLoader;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.InputStream;
import java.math.BigInteger;
import static org.junit.Assert.*;
/**
* @author alexbraz
* @since 29/03/2019
*/
public class ChainTest {
private static final Logger logger = LoggerFactory.getLogger("test");
Block genesis = GenesisLoader.loadGenesis(getClass().getResourceAsStream("/genesis/olympic.json"));
GenesisJson genesisJson = GenesisLoader.loadGenesisJson((InputStream) getClass().getResourceAsStream("/genesis/olympic.json"));
@Test
public void testContainsBlock() {
Chain c = new Chain();
c.add(genesis);
assertEquals(genesis, c.getLast());
}
@Test
public void testBlockHashNotNull() {
Chain c = new Chain();
c.add(genesis);
assertNotNull(c.getLast().getHash());
}
@Test
public void testDifficultyGenesisCorrectLoadedAndConverted() {
Chain c = new Chain();
c.add(genesis);
assertEquals(new BigInteger(genesisJson.getDifficulty().replace("0x", ""), 16).intValue(), c.getLast().getDifficultyBI().intValue());
}
@Test
public void testParentOnTheChain() {
Chain c = new Chain();
c.add(genesis);
Block block = new Block(genesis.getHeader(), genesis.getTransactionsList(), null);
assertFalse(c.isParentOnTheChain(block));
}
@Test
public void testParentOnTheChain2() {
Chain c = new Chain();
c.add(genesis);
assertFalse(c.isParentOnTheChain(genesis));
}
}
| 1,702
| 25.2
| 141
|
java
|
ethereumj
|
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/core/AccountStateTest.java
|
/*
* Copyright (c) [2016] [ <ether.camp> ]
* This file is part of the ethereumJ library.
*
* The ethereumJ library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The ethereumJ library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the ethereumJ library. If not, see <http://www.gnu.org/licenses/>.
*/
package org.ethereum.core;
import org.junit.Test;
import org.spongycastle.util.encoders.Hex;
import java.math.BigInteger;
import static org.junit.Assert.assertEquals;
public class AccountStateTest {
@Test
public void testGetEncoded() {
String expected = "f85e809"
+ "a0100000000000000000000000000000000000000000000000000"
+ "a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"
+ "a0c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470";
AccountState acct = new AccountState(BigInteger.ZERO, BigInteger.valueOf(2).pow(200));
assertEquals(expected, Hex.toHexString(acct.getEncoded()));
}
}
| 1,497
| 35.536585
| 94
|
java
|
ethereumj
|
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/core/LogInfoTest.java
|
/*
* Copyright (c) [2016] [ <ether.camp> ]
* This file is part of the ethereumJ library.
*
* The ethereumJ library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The ethereumJ library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the ethereumJ library. If not, see <http://www.gnu.org/licenses/>.
*/
package org.ethereum.core;
import org.ethereum.vm.LogInfo;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.spongycastle.util.encoders.Hex;
import org.junit.Ignore;
import static org.junit.Assert.assertEquals;
/**
* @author Roman Mandeleil
* @since 05.12.2014
*/
public class LogInfoTest {
private static final Logger logger = LoggerFactory.getLogger("test");
@Test // rlp decode
public void test_1() {
// LogInfo{address=d5ccd26ba09ce1d85148b5081fa3ed77949417be, topics=[000000000000000000000000459d3a7595df9eba241365f4676803586d7d199c 436f696e73000000000000000000000000000000000000000000000000000000 ], data=}
byte[] rlp = Hex.decode("f85a94d5ccd26ba09ce1d85148b5081fa3ed77949417bef842a0000000000000000000000000459d3a7595df9eba241365f4676803586d7d199ca0436f696e7300000000000000000000000000000000000000000000000000000080");
LogInfo logInfo = new LogInfo(rlp);
assertEquals("d5ccd26ba09ce1d85148b5081fa3ed77949417be",
Hex.toHexString(logInfo.getAddress()));
assertEquals("", Hex.toHexString(logInfo.getData()));
assertEquals("000000000000000000000000459d3a7595df9eba241365f4676803586d7d199c",
logInfo.getTopics().get(0).toString());
assertEquals("436f696e73000000000000000000000000000000000000000000000000000000",
logInfo.getTopics().get(1).toString());
logger.info("{}", logInfo);
}
@Test // rlp decode
public void test_2() {
LogInfo log = new LogInfo(Hex.decode("d5ccd26ba09ce1d85148b5081fa3ed77949417be"), null, null);
assertEquals("d794d5ccd26ba09ce1d85148b5081fa3ed77949417bec080", Hex.toHexString(log.getEncoded()));
logger.info("{}", log);
}
@Ignore //TODO #POC9
@Test // rlp decode
public void test_3() {
// LogInfo{address=f2b1a404bcb6112a0ff2c4197cb02f3de40018b3, topics=[5a360139cff27713da0fe18a2100048a7ce1b7700c953a82bc3ff011437c8c2a 588d7ddcc06c14843ea68e690dfd4ec91ba09a8ada15c5b7fa6fead9c8befe4b ], data=}
byte[] rlp = Hex.decode("f85a94f2b1a404bcb6112a0ff2c4197cb02f3de40018b3f842a05a360139cff27713da0fe18a2100048a7ce1b7700c953a82bc3ff011437c8c2aa0588d7ddcc06c14843ea68e690dfd4ec91ba09a8ada15c5b7fa6fead9c8befe4b80");
LogInfo logInfo = new LogInfo(rlp);
assertEquals("f2b1a404bcb6112a0ff2c4197cb02f3de40018b3",
Hex.toHexString(logInfo.getAddress()));
assertEquals("00800000000000000010000000000000000000000000002000000000000000000012000000100000000050000020000000000000000000000000000000000000",
logInfo.getBloom().toString());
assertEquals("f85a94f2b1a404bcb6112a0ff2c4197cb02f3de40018b3f842a05a360139cff27713da0fe18a2100048a7ce1b7700c953a82bc3ff011437c8c2aa0588d7ddcc06c14843ea68e690dfd4ec91ba09a8ada15c5b7fa6fead9c8befe4b80",
Hex.toHexString(logInfo.getEncoded()));
logger.info("{}", logInfo);
}
}
| 3,762
| 41.761364
| 220
|
java
|
ethereumj
|
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/core/TransactionReceiptTest.java
|
/*
* Copyright (c) [2016] [ <ether.camp> ]
* This file is part of the ethereumJ library.
*
* The ethereumJ library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The ethereumJ library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the ethereumJ library. If not, see <http://www.gnu.org/licenses/>.
*/
package org.ethereum.core;
import org.ethereum.crypto.ECKey;
import org.ethereum.vm.DataWord;
import org.ethereum.vm.LogInfo;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.spongycastle.util.encoders.Hex;
import java.util.Collections;
import static org.junit.Assert.assertEquals;
/**
* @author Roman Mandeleil
* @since 05.12.2014
*/
public class TransactionReceiptTest {
private static final Logger logger = LoggerFactory.getLogger("test");
@Test // rlp decode
public void test_1() {
byte[] rlp = Hex.decode("f88aa0966265cc49fa1f10f0445f035258d116563931022a3570a640af5d73a214a8da822b6fb84000000010000000010000000000008000000000000000000000000000000000000000000000000000000000020000000000000014000000000400000000000440d8d7948513d39a34a1a8570c9c9f0af2cba79ac34e0ac8c0808301e24086873423437898");
TransactionReceipt txReceipt = new TransactionReceipt(rlp);
assertEquals(1, txReceipt.getLogInfoList().size());
assertEquals("966265cc49fa1f10f0445f035258d116563931022a3570a640af5d73a214a8da",
Hex.toHexString(txReceipt.getPostTxState()));
assertEquals("2b6f",
Hex.toHexString(txReceipt.getCumulativeGas()));
assertEquals("01e240",
Hex.toHexString(txReceipt.getGasUsed()));
assertEquals("00000010000000010000000000008000000000000000000000000000000000000000000000000000000000020000000000000014000000000400000000000440",
Hex.toHexString(txReceipt.getBloomFilter().getData()));
assertEquals("873423437898",
Hex.toHexString(txReceipt.getExecutionResult()));
logger.info("{}", txReceipt);
}
@Test
public void test_2() {
byte[] rlp = Hex.decode("f9012ea02d0cd041158c807326dae7cf5f044f3b9d4bd91a378cc55781b75455206e0c368339dc68b9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c08252088080");
TransactionReceipt txReceipt = new TransactionReceipt(rlp);
txReceipt.setExecutionResult(new byte[0]);
byte[] encoded = txReceipt.getEncoded();
TransactionReceipt txReceipt1 = new TransactionReceipt(encoded);
System.out.println(txReceipt1);
}
}
| 3,476
| 41.925926
| 646
|
java
|
ethereumj
|
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/core/ABITest.java
|
/*
* Copyright (c) [2016] [ <ether.camp> ]
* This file is part of the ethereumJ library.
*
* The ethereumJ library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The ethereumJ library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the ethereumJ library. If not, see <http://www.gnu.org/licenses/>.
*/
package org.ethereum.core;
import static org.ethereum.crypto.HashUtil.sha3;
import org.ethereum.solidity.SolidityType;
import org.ethereum.util.blockchain.SolidityCallResult;
import org.ethereum.util.blockchain.SolidityContract;
import org.ethereum.util.blockchain.StandaloneBlockchain;
import org.junit.Assert;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.spongycastle.util.encoders.Hex;
import java.math.BigInteger;
/**
* @author Anton Nashatyrev
*/
public class ABITest {
private static final Logger logger = LoggerFactory.getLogger("test");
@Test
public void testTransactionCreate() {
// demo only
CallTransaction.Function function = CallTransaction.Function.fromJsonInterface(funcJson1);
Transaction ctx = CallTransaction.createCallTransaction(1, 1_000_000_000, 1_000_000_000,
"86e0497e32a8e1d79fe38ab87dc80140df5470d9", 0, function, "1234567890abcdef1234567890abcdef12345678");
ctx.sign(sha3("974f963ee4571e86e5f9bc3b493e453db9c15e5bd19829a4ef9a790de0da0015".getBytes()));
}
static String funcJson1 = "{ \n" +
" 'constant': false, \n" +
" 'inputs': [{'name':'to', 'type':'address'}], \n" +
" 'name': 'delegate', \n" +
" 'outputs': [], \n" +
" 'type': 'function' \n" +
"} \n";
static {funcJson1 = funcJson1.replaceAll("'", "\"");}
@Test
public void testSimple1() {
logger.info("\n{}", funcJson1);
CallTransaction.Function function = CallTransaction.Function.fromJsonInterface(funcJson1);
Assert.assertEquals("5c19a95c0000000000000000000000001234567890abcdef1234567890abcdef12345678",
Hex.toHexString(function.encode("1234567890abcdef1234567890abcdef12345678")));
Assert.assertEquals("5c19a95c0000000000000000000000001234567890abcdef1234567890abcdef12345678",
Hex.toHexString(function.encode("0x1234567890abcdef1234567890abcdef12345678")));
try {
Hex.toHexString(function.encode("0xa1234567890abcdef1234567890abcdef12345678"));
Assert.assertTrue(false);
} catch (Exception e) {}
try {
Hex.toHexString(function.encode("blabla"));
Assert.assertTrue(false);
} catch (Exception e) {}
}
static String funcJson2 = "{\n" +
" 'constant':false, \n" +
" 'inputs':[], \n" +
" 'name':'tst', \n" +
" 'outputs':[], \n" +
" 'type':'function' \n" +
"}";
static {funcJson2 = funcJson2.replaceAll("'", "\"");}
@Test
public void testSimple2() {
logger.info("\n{}", funcJson2);
CallTransaction.Function function = CallTransaction.Function.fromJsonInterface(funcJson2);
Transaction ctx = CallTransaction.createCallTransaction(1, 1_000_000_000, 1_000_000_000,
"86e0497e32a8e1d79fe38ab87dc80140df5470d9", 0, function);
ctx.sign(sha3("974f963ee4571e86e5f9bc3b493e453db9c15e5bd19829a4ef9a790de0da0015".getBytes()));
Assert.assertEquals("91888f2e", Hex.toHexString(ctx.getData()));
}
static String funcJson3 = "{\n" +
" 'constant':false, \n" +
" 'inputs':[ \n" +
" {'name':'i','type':'int'}, \n" +
" {'name':'u','type':'uint'}, \n" +
" {'name':'i8','type':'int8'}, \n" +
" {'name':'b2','type':'bytes2'}, \n" +
" {'name':'b32','type':'bytes32'} \n" +
" ], \n" +
" 'name':'f1', \n" +
" 'outputs':[], \n" +
" 'type':'function' \n" +
"}\n";
static {funcJson3 = funcJson3.replaceAll("'", "\"");}
@Test
public void test3() {
logger.info("\n{}", funcJson3);
CallTransaction.Function function = CallTransaction.Function.fromJsonInterface(funcJson3);
Assert.assertEquals("a4f72f5a" +
"fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffb2e" +
"00000000000000000000000000000000000000000000000000000000000004d2" +
"000000000000000000000000000000000000000000000000000000000000007b61" +
"000000000000000000000000000000000000000000000000000000000000007468" +
"6520737472696e6700000000000000000000000000000000000000000000",
Hex.toHexString(function.encode(-1234, 1234, 123, "a", "the string")));
}
static String funcJson4 = "{\n" +
" 'constant':false, \n" +
" 'inputs':[{'name':'i','type':'int[3]'}, {'name':'j','type':'int[]'}], \n" +
" 'name':'f2', \n" +
" 'outputs':[], \n" +
" 'type':'function' \n" +
"}\n";
static {funcJson4 = funcJson4.replaceAll("'", "\"");};
@Test
public void test4() {
logger.info("\n{}", funcJson4);
CallTransaction.Function function = CallTransaction.Function.fromJsonInterface(funcJson4);
Assert.assertEquals("d383b9f6" +
"0000000000000000000000000000000000000000000000000000000000000001" +
"0000000000000000000000000000000000000000000000000000000000000002" +
"0000000000000000000000000000000000000000000000000000000000000003",
Hex.toHexString(function.encode(new int[] {1,2,3})));
Assert.assertEquals(
"d383b9f60000000000000000000000000000000000000000000000000000000000000001" +
"0000000000000000000000000000000000000000000000000000000000000002" +
"0000000000000000000000000000000000000000000000000000000000000003" +
"0000000000000000000000000000000000000000000000000000000000000080" +
"0000000000000000000000000000000000000000000000000000000000000002" +
"0000000000000000000000000000000000000000000000000000000000000004" +
"0000000000000000000000000000000000000000000000000000000000000005",
Hex.toHexString(function.encode(new int[]{1, 2, 3}, new int[]{4, 5})));
}
static String funcJson5 = "{\n" +
" 'constant':false, \n" +
" 'inputs':[{'name':'i','type':'int'}, \n" +
" {'name':'s','type':'bytes'}, \n" +
" {'name':'j','type':'int'}], \n" +
" 'name':'f4', \n" +
" 'outputs':[], \n" +
" 'type':'function' \n" +
"}\n";
static {funcJson5 = funcJson5.replaceAll("'", "\"");};
@Test
public void test5() {
logger.info("\n{}", funcJson5);
CallTransaction.Function function = CallTransaction.Function.fromJsonInterface(funcJson5);
Assert.assertEquals(
"3ed2792b000000000000000000000000000000000000000000000000000000000000006f" +
"0000000000000000000000000000000000000000000000000000000000000060" +
"00000000000000000000000000000000000000000000000000000000000000de" +
"0000000000000000000000000000000000000000000000000000000000000003" +
"abcdef0000000000000000000000000000000000000000000000000000000000",
Hex.toHexString(function.encode(111, new byte[] {(byte) 0xab, (byte) 0xcd, (byte) 0xef}, 222)));
}
@Test
public void decodeDynamicTest1() {
String funcJson = "{\n" +
" 'constant':false, \n" +
" 'inputs':[{'name':'i','type':'int'}, \n" +
" {'name':'s','type':'bytes'}, \n" +
" {'name':'j','type':'int'}], \n" +
" 'name':'f4', \n" +
" 'outputs':[{'name':'i','type':'int'}, \n" +
" {'name':'s','type':'bytes'}, \n" +
" {'name':'j','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[] encoded = function.encodeArguments(111, bytes, 222);
Object[] objects = function.decodeResult(encoded);
// System.out.println(Arrays.toString(objects));
Assert.assertEquals(((Number) objects[0]).intValue(), 111);
Assert.assertArrayEquals((byte[]) objects[1], bytes);
Assert.assertEquals(((Number) objects[2]).intValue(), 222);
}
@Test
public void decodeDynamicTest2() {
String funcJson = "{\n" +
" 'constant':false, \n" +
" 'inputs':[{'name':'i','type':'int'}, \n" +
" {'name':'s','type':'string[]'}, \n" +
" {'name':'j','type':'int'}], \n" +
" 'name':'f4', \n" +
" 'outputs':[{'name':'i','type':'int'}, \n" +
" {'name':'s','type':'string[]'}, \n" +
" {'name':'j','type':'int'}], \n" +
" 'type':'function' \n" +
"}\n";
funcJson = funcJson.replaceAll("'", "\"");
CallTransaction.Function function = CallTransaction.Function.fromJsonInterface(funcJson);
String[] strings = new String[] {"aaa", "long string: 123456789012345678901234567890", "ccc"};
byte[] encoded = function.encodeArguments(111, strings, 222);
Object[] objects = function.decodeResult(encoded);
// System.out.println(Arrays.toString(objects));
Assert.assertEquals(((Number) objects[0]).intValue(), 111);
Assert.assertArrayEquals((Object[]) objects[1], strings);
Assert.assertEquals(((Number) objects[2]).intValue(), 222);
}
@Test
public void decodeWithUnknownPropertiesTest() {
String funcJson = "{\n" +
" 'constant':false, \n" +
" 'inputs':[{'name':'i','type':'int'}, \n" +
" {'name':'s','type':'string[]'}, \n" +
" {'name':'j','type':'int'}], \n" +
" 'name':'f4', \n" +
" 'outputs':[{'name':'i','type':'int'}, \n" +
" {'name':'s','type':'string[]'}, \n" +
" {'name':'j','type':'int'}], \n" +
" 'type':'function', \n" +
" 'test':'test' \n" +
"}\n";
funcJson = funcJson.replaceAll("'", "\"");
CallTransaction.Function function = CallTransaction.Function.fromJsonInterface(funcJson);
String[] strings = new String[] {"aaa", "long string: 123456789012345678901234567890", "ccc"};
byte[] encoded = function.encodeArguments(111, strings, 222);
Object[] objects = function.decodeResult(encoded);
Assert.assertEquals(((Number) objects[0]).intValue(), 111);
Assert.assertArrayEquals((Object[]) objects[1], strings);
Assert.assertEquals(((Number) objects[2]).intValue(), 222);
}
@Test
public void decodeWithPayablePropertyTest() {
String funcJson = "{\n" +
" 'constant':false, \n" +
" 'inputs':[{'name':'i','type':'int'}, \n" +
" {'name':'s','type':'string[]'}, \n" +
" {'name':'j','type':'int'}], \n" +
" 'name':'f4', \n" +
" 'outputs':[{'name':'i','type':'int'}, \n" +
" {'name':'s','type':'string[]'}, \n" +
" {'name':'j','type':'int'}], \n" +
" 'type':'function', \n" +
" 'payable':true \n" +
"}\n";
funcJson = funcJson.replaceAll("'", "\"");
CallTransaction.Function function = CallTransaction.Function.fromJsonInterface(funcJson);
Assert.assertTrue(function.payable);
String[] strings = new String[] {"aaa", "long string: 123456789012345678901234567890", "ccc"};
byte[] encoded = function.encodeArguments(111, strings, 222);
Object[] objects = function.decodeResult(encoded);
Assert.assertEquals(((Number) objects[0]).intValue(), 111);
Assert.assertArrayEquals((Object[]) objects[1], strings);
Assert.assertEquals(((Number) objects[2]).intValue(), 222);
}
@Test
public void decodeWithFunctionTypeFallbackTest() {
String funcJson = "{\n" +
" 'constant':false, \n" +
" 'inputs':[{'name':'i','type':'int'}, \n" +
" {'name':'s','type':'string[]'}, \n" +
" {'name':'j','type':'int'}], \n" +
" 'name':'f4', \n" +
" 'outputs':[{'name':'i','type':'int'}, \n" +
" {'name':'s','type':'string[]'}, \n" +
" {'name':'j','type':'int'}], \n" +
" 'type':'fallback' \n" +
"}\n";
funcJson = funcJson.replaceAll("'", "\"");
CallTransaction.Function function = CallTransaction.Function.fromJsonInterface(funcJson);
Assert.assertEquals(CallTransaction.FunctionType.fallback, function.type);
String[] strings = new String[] {"aaa", "long string: 123456789012345678901234567890", "ccc"};
byte[] encoded = function.encodeArguments(111, strings, 222);
Object[] objects = function.decodeResult(encoded);
Assert.assertEquals(((Number) objects[0]).intValue(), 111);
Assert.assertArrayEquals((Object[]) objects[1], strings);
Assert.assertEquals(((Number) objects[2]).intValue(), 222);
}
@Test
public void decodeWithUnknownFunctionTypeTest() {
String funcJson = "{\n" +
" 'constant':false, \n" +
" 'inputs':[{'name':'i','type':'int'}, \n" +
" {'name':'s','type':'string[]'}, \n" +
" {'name':'j','type':'int'}], \n" +
" 'name':'f4', \n" +
" 'outputs':[{'name':'i','type':'int'}, \n" +
" {'name':'s','type':'string[]'}, \n" +
" {'name':'j','type':'int'}], \n" +
" 'type':'test' \n" +
"}\n";
funcJson = funcJson.replaceAll("'", "\"");
CallTransaction.Function function = CallTransaction.Function.fromJsonInterface(funcJson);
Assert.assertEquals(null, function.type);
String[] strings = new String[] {"aaa", "long string: 123456789012345678901234567890", "ccc"};
byte[] encoded = function.encodeArguments(111, strings, 222);
Object[] objects = function.decodeResult(encoded);
Assert.assertEquals(((Number) objects[0]).intValue(), 111);
Assert.assertArrayEquals((Object[]) objects[1], strings);
Assert.assertEquals(((Number) objects[2]).intValue(), 222);
}
@Test
public void twoDimensionalArrayType_hasDimensionDefinitionInCorrectOrder() {
String funcJson = "{ \n" +
" 'constant':false,\n" +
" 'inputs':[ \n" +
" { \n" +
" 'name':'param1',\n" +
" 'type':'address[5][]'\n" +
" },\n" +
" { \n" +
" 'name':'param2',\n" +
" 'type':'uint256[6][2]'\n" +
" },\n" +
" { \n" +
" 'name':'param2',\n" +
" 'type':'uint256[][]'\n" +
" },\n" +
" { \n" +
" 'name':'param3',\n" +
" 'type':'uint256[][2]'\n" +
" }\n" +
" ],\n" +
" 'name':'testTwoDimArray',\n" +
" 'outputs':[],\n" +
" 'payable':false,\n" +
" 'type':'function'\n" +
"}";
funcJson = funcJson.replaceAll("'", "\"");
CallTransaction.Function function = CallTransaction.Function.fromJsonInterface(funcJson);
String expected = "testTwoDimArray(address[5][],uint256[6][2],uint256[][],uint256[][2])";
String actual = function.toString();
Assert.assertEquals(expected, actual);
}
@Test
public void twoDimensionalArrayTypeAsParameter_isDecoded() {
String funcJson = "{ " +
" 'constant':false, " +
" 'inputs':[ " +
" { " +
" 'name':'orderAddresses', " +
" 'type':'address[5][]' " +
" }, " +
" { " +
" 'name':'orderValues', " +
" 'type':'uint256[6][]' " +
" }, " +
" { " +
" 'name':'fillTakerTokenAmounts', " +
" 'type':'uint256[]' " +
" }, " +
" { " +
" 'name':'v', " +
" 'type':'uint8[]' " +
" }, " +
" { " +
" 'name':'r', " +
" 'type':'bytes32[]' " +
" }, " +
" { " +
" 'name':'s', " +
" 'type':'bytes32[]' " +
" } " +
" ], " +
" 'name':'batchFillOrKillOrders', " +
" 'outputs':[], " +
" 'payable':false, " +
" 'type':'function' " +
" }";
funcJson = funcJson.replaceAll("'", "\"");
CallTransaction.Function function = CallTransaction.Function.fromJsonInterface(funcJson);
Object[] args = new Object[]{
new byte[][][]{
new byte[][]{
Hex.decode("1b2a9cc5ea11c11b70908d75207b5b1f0ac4a839"),
Hex.decode("e697a9f14f182c5291287dbeb47d41773091f035"),
Hex.decode("c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"),
Hex.decode("2d0ea9f9591205a642eb01826ba4fa019eb0efc6"),
Hex.decode("8124071f810d533ff63de61d0c98db99eeb99d64")
},
new byte[][]{
Hex.decode("1b2a9cc5ea11c11b70908d75207b5b1f0ac4a839"),
Hex.decode("e697a9f14f182c5291287dbeb47d41773091f035"),
Hex.decode("2d0ea9f9591205a642eb01826ba4fa019eb0efc6"),
Hex.decode("c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"),
Hex.decode("8124071f810d533ff63de61d0c98db99eeb99d64")
}
}, new BigInteger[][]{
new BigInteger[]{
new BigInteger("15920000000000000000"),
new BigInteger("1592000000000000000000"),
BigInteger.valueOf(0),
BigInteger.valueOf(0),
BigInteger.valueOf(1537516391517L),
new BigInteger("88416929899962839058958574884878701761157019606353286750292520499350182621314")
},
new BigInteger[]{
new BigInteger("1642000000000000000000"),
new BigInteger("16420000000000002000"),
BigInteger.valueOf(0),
BigInteger.valueOf(0),
BigInteger.valueOf(1537517358153L),
new BigInteger("93513067008724755490443777049125356883124657581213787456489051336421643029820")
}
},
new BigInteger[]{
new BigInteger("14000000000000000000"),
new BigInteger("140000000000000017")
},
new BigInteger[]{
BigInteger.valueOf(27),
BigInteger.valueOf(28)
},
new byte[][]{
Hex.decode("9202d3602753ffdb469e9dbae74cbe7528c648f708334f7791acc6fe0ce8182b"),
Hex.decode("ef362daf1bc2c805797761ae93a6c46ed53d73483a2bcc5b499ab65a8ba7f16c")
},
new byte[][]{
Hex.decode("0b43ad3ff547ebf5089802a74e764692bdc092190438b31be34d1d79406a75ba"),
Hex.decode("4e87fcd4ead36423d5bbcc7f1b41616235a17ec1f053a66827281bab104b718b")
}
};
byte[] bytes = function.encode(args);
String input = "4f15078700000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000022000000000000000000000000000000000000000000000000000000000000003c00000000000000000000000000000000000000000000000000000000000000420000000000000000000000000000000000000000000000000000000000000048000000000000000000000000000000000000000000000000000000000000004e000000000000000000000000000000000000000000000000000000000000000020000000000000000000000001b2a9cc5ea11c11b70908d75207b5b1f0ac4a839000000000000000000000000e697a9f14f182c5291287dbeb47d41773091f035000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000002d0ea9f9591205a642eb01826ba4fa019eb0efc60000000000000000000000008124071f810d533ff63de61d0c98db99eeb99d640000000000000000000000001b2a9cc5ea11c11b70908d75207b5b1f0ac4a839000000000000000000000000e697a9f14f182c5291287dbeb47d41773091f0350000000000000000000000002d0ea9f9591205a642eb01826ba4fa019eb0efc6000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000008124071f810d533ff63de61d0c98db99eeb99d640000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000dcef33a6f83800000000000000000000000000000000000000000000000000564d702d38f5e000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000165fb1e4c5dc37a357a19313983db8360977d0c3cfe274a9deb63fc1a994f3c290b2644f0820000000000000000000000000000000000000000000000590353dc4fa7680000000000000000000000000000000000000000000000000000e3df8f00cbea07d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000165fb2d0c49cebe85312f1f1cc97430bc1315aff0fbb0d7f1219c8759774672c9939e168d3c0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000c249fdd32778000000000000000000000000000000000000000000000000000001f161421c8e00110000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000001b000000000000000000000000000000000000000000000000000000000000001c00000000000000000000000000000000000000000000000000000000000000029202d3602753ffdb469e9dbae74cbe7528c648f708334f7791acc6fe0ce8182bef362daf1bc2c805797761ae93a6c46ed53d73483a2bcc5b499ab65a8ba7f16c00000000000000000000000000000000000000000000000000000000000000020b43ad3ff547ebf5089802a74e764692bdc092190438b31be34d1d79406a75ba4e87fcd4ead36423d5bbcc7f1b41616235a17ec1f053a66827281bab104b718b";
Assert.assertEquals(input, Hex.toHexString(bytes));
Object[] decode = function.decode(Hex.decode(input));
Assert.assertArrayEquals(args, decode);
}
@Test
public void staticArrayWithDynamicElements() {
// static array with dynamic elements is itself dynamic type
String funcJson = "{ " +
" 'constant':false, " +
" 'inputs':[{ " +
" 'name':'p1', " +
" 'type':'address[][2]' " +
" }]," +
" 'name':'f1', " +
" 'outputs':[], " +
" 'payable':false, " +
" 'type':'function' " +
"}";
funcJson = funcJson.replaceAll("'", "\"");
CallTransaction.Function function = CallTransaction.Function.fromJsonInterface(funcJson);
Assert.assertTrue(function.inputs[0].type instanceof SolidityType.StaticArrayType);
Assert.assertTrue(function.inputs[0].type.isDynamicType());
try {
function.encode((Object) new byte[][][]{
new byte[][]{
Hex.decode("1111111111111111111111111111111111111111"),
}}
);
throw new RuntimeException("Exception should be thrown");
} catch (Exception e) {
System.out.println("Expected exception: " + e);
}
Object[] args = new Object[]{
new byte[][][]{
new byte[][]{
Hex.decode("1111111111111111111111111111111111111111"),
Hex.decode("2222222222222222222222222222222222222222"),
Hex.decode("3333333333333333333333333333333333333333"),
},
new byte[][]{
Hex.decode("4444444444444444444444444444444444444444"),
}
}
};
byte[] bytes = function.encode(args);
String input = "7e5f5dc50000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000000300000000000000000000000011111111111111111111111111111111111111110000000000000000000000002222222222222222222222222222222222222222000000000000000000000000333333333333333333333333333333333333333300000000000000000000000000000000000000000000000000000000000000010000000000000000000000004444444444444444444444444444444444444444";
System.out.println(Hex.toHexString(bytes));
Assert.assertEquals(input, Hex.toHexString(bytes));
Object[] decode = function.decode(bytes);
Assert.assertArrayEquals(args, decode);
}
@Test
public void staticArrayWithDynamicElementsSolidity() {
String contract =
"pragma solidity ^0.4.3;\n" +
"pragma experimental ABIEncoderV2;\n"+
"contract A {" +
" function call(uint[][2] arr) public returns (uint) {" +
" if (arr.length != 2) return 2;" +
" if (arr[0].length != 3) return 3;" +
" if (arr[1].length != 2) return 4;" +
" if (arr[0][0] != 10) return 5;" +
" if (arr[0][1] != 11) return 6;" +
" if (arr[0][2] != 12) return 7;" +
" if (arr[1][0] != 13) return 8;" +
" if (arr[1][1] != 14) return 9;" +
" return 1;" +
" }" +
" function ret() public returns (uint[][2]) {" +
" uint[][2] a1;" +
" a1[0] = [uint(3),uint(4),uint(5)];" +
" a1[1] = [uint(6),uint(7)];" +
" return a1;" +
" }" +
"}";
StandaloneBlockchain bc = new StandaloneBlockchain().withAutoblock(true);
SolidityContract a = bc.submitNewContract(contract);
SolidityCallResult res = a.callFunction("call",
(Object) new BigInteger[][]{
new BigInteger[]{
BigInteger.valueOf(10),
BigInteger.valueOf(11),
BigInteger.valueOf(12),
},
new BigInteger[]{
BigInteger.valueOf(13),
BigInteger.valueOf(14),
},
}
);
Assert.assertTrue(res.isSuccessful());
Assert.assertEquals(BigInteger.valueOf(1), res.getReturnValue());
Object[] ret = a.callConstFunction("ret");
Assert.assertArrayEquals(
new Object[] {
new BigInteger[][]{
new BigInteger[]{
BigInteger.valueOf(3),
BigInteger.valueOf(4),
BigInteger.valueOf(5),
},
new BigInteger[]{
BigInteger.valueOf(6),
BigInteger.valueOf(7),
},
}}, ret);
}
}
| 30,384
| 50.5
| 2,722
|
java
|
ethereumj
|
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/core/PendingStateTest.java
|
/*
* Copyright (c) [2016] [ <ether.camp> ]
* This file is part of the ethereumJ library.
*
* The ethereumJ library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The ethereumJ library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the ethereumJ library. If not, see <http://www.gnu.org/licenses/>.
*/
package org.ethereum.core;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.commons.lang3.tuple.Triple;
import org.ethereum.config.SystemProperties;
import org.ethereum.config.blockchain.FrontierConfig;
import org.ethereum.config.net.MainNetConfig;
import org.ethereum.crypto.ECKey;
import org.ethereum.db.ByteArrayWrapper;
import org.ethereum.listener.EthereumListener;
import org.ethereum.listener.EthereumListenerAdapter;
import org.ethereum.util.blockchain.SolidityContract;
import org.ethereum.util.blockchain.StandaloneBlockchain;
import org.junit.*;
import java.math.BigInteger;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.ethereum.listener.EthereumListener.PendingTransactionState.*;
import static org.ethereum.util.blockchain.EtherUtil.Unit.ETHER;
import static org.ethereum.util.blockchain.EtherUtil.convert;
/**
* @author Mikhail Kalinin
* @since 28.09.2015
*/
public class PendingStateTest {
@BeforeClass
public static void setup() {
SystemProperties.getDefault().setBlockchainConfig(StandaloneBlockchain.getEasyMiningConfig());
}
@AfterClass
public static void cleanup() {
SystemProperties.resetToDefault();
}
static class PendingListener extends EthereumListenerAdapter {
public BlockingQueue<Pair<Block, List<TransactionReceipt>>> onBlock = new LinkedBlockingQueue<>();
public BlockingQueue<Object> onPendingStateChanged = new LinkedBlockingQueue<>();
// public BlockingQueue<Triple<TransactionReceipt, PendingTransactionState, Block>> onPendingTransactionUpdate = new LinkedBlockingQueue<>();
Map<ByteArrayWrapper, BlockingQueue<Triple<TransactionReceipt, PendingTransactionState, Block>>>
onPendingTransactionUpdate = new HashMap<>();
@Override
public void onBlock(Block block, List<TransactionReceipt> receipts) {
System.out.println("PendingStateTest.onBlock:" + "block = [" + block.getShortDescr() + "]");
onBlock.add(Pair.of(block, receipts));
}
@Override
public void onPendingStateChanged(PendingState pendingState) {
System.out.println("PendingStateTest.onPendingStateChanged.");
onPendingStateChanged.add(new Object());
}
@Override
public void onPendingTransactionUpdate(TransactionReceipt txReceipt, PendingTransactionState state, Block block) {
System.out.println("PendingStateTest.onPendingTransactionUpdate:" + "txReceipt.err = [" + txReceipt.getError() + "], state = [" + state + "], block: " + block.getShortDescr());
getQueueFor(txReceipt.getTransaction()).add(Triple.of(txReceipt, state, block));
}
public synchronized BlockingQueue<Triple<TransactionReceipt, PendingTransactionState, Block>> getQueueFor(Transaction tx) {
ByteArrayWrapper hashW = new ByteArrayWrapper(tx.getHash());
BlockingQueue<Triple<TransactionReceipt, PendingTransactionState, Block>> queue = onPendingTransactionUpdate.get(hashW);
if (queue == null) {
queue = new LinkedBlockingQueue<>();
onPendingTransactionUpdate.put(hashW, queue);
}
return queue;
}
public PendingTransactionState pollTxUpdateState(Transaction tx) throws InterruptedException {
return getQueueFor(tx).poll(5, SECONDS).getMiddle();
}
public Triple<TransactionReceipt, PendingTransactionState, Block> pollTxUpdate(Transaction tx) throws InterruptedException {
return getQueueFor(tx).poll(5, SECONDS);
}
}
@Test
public void testSimple() throws InterruptedException {
StandaloneBlockchain bc = new StandaloneBlockchain();
PendingListener l = new PendingListener();
bc.addEthereumListener(l);
Triple<TransactionReceipt, EthereumListener.PendingTransactionState, Block> txUpd;
PendingStateImpl pendingState = (PendingStateImpl) bc.getBlockchain().getPendingState();
ECKey alice = new ECKey();
bc.sendEther(new byte[20], BigInteger.valueOf(100000));
bc.sendEther(new byte[20], BigInteger.valueOf(100000));
bc.createBlock();
l.onBlock.poll(5, SECONDS);
Transaction tx1 = bc.createTransaction(100, new byte[32], 1000, new byte[0]);
pendingState.addPendingTransaction(tx1);
// dropped due to large nonce
Assert.assertEquals(l.pollTxUpdateState(tx1), DROPPED);
Transaction tx1_ = bc.createTransaction(0, new byte[32], 1000, new byte[0]);
pendingState.addPendingTransaction(tx1_);
// dropped due to low nonce
Assert.assertEquals(l.pollTxUpdateState(tx1_), DROPPED);
Transaction tx2 = bc.createTransaction(2, alice.getAddress(), 1000000, new byte[0]);
Transaction tx3 = bc.createTransaction(3, alice.getAddress(), 1000000, new byte[0]);
pendingState.addPendingTransaction(tx2);
pendingState.addPendingTransaction(tx3);
txUpd = l.pollTxUpdate(tx2);
Assert.assertEquals(txUpd.getMiddle(), NEW_PENDING);
Assert.assertTrue(txUpd.getLeft().isValid());
txUpd = l.pollTxUpdate(tx3);
Assert.assertEquals(txUpd.getMiddle(), NEW_PENDING);
Assert.assertTrue(txUpd.getLeft().isValid());
Assert.assertTrue(pendingState.getRepository().getBalance(alice.getAddress()).
compareTo(BigInteger.valueOf(2000000 - 100000)) > 0);
pendingState.addPendingTransaction(tx2); // double transaction submit
Assert.assertTrue(l.getQueueFor(tx2).isEmpty());
bc.createBlock();
Assert.assertEquals(l.pollTxUpdateState(tx2), PENDING);
Assert.assertEquals(l.pollTxUpdateState(tx3), PENDING);
bc.submitTransaction(tx2);
Block b3 = bc.createBlock();
txUpd = l.pollTxUpdate(tx2);
Assert.assertEquals(txUpd.getMiddle(), INCLUDED);
Assert.assertEquals(txUpd.getRight(), b3);
Assert.assertEquals(l.pollTxUpdateState(tx3), PENDING);
Assert.assertTrue(pendingState.getRepository().getBalance(alice.getAddress()).
compareTo(BigInteger.valueOf(2000000 - 100000)) > 0);
for (int i = 0; i < SystemProperties.getDefault().txOutdatedThreshold() + 1; i++) {
bc.createBlock();
txUpd = l.pollTxUpdate(tx3);
if (txUpd.getMiddle() != PENDING) break;
}
// tx3 dropped due to timeout
Assert.assertEquals(txUpd.getMiddle(), DROPPED);
Assert.assertEquals(txUpd.getLeft().getTransaction(), tx3);
Assert.assertFalse(pendingState.getRepository().getBalance(alice.getAddress()).
compareTo(BigInteger.valueOf(2000000 - 100000)) > 0);
}
@Test
public void testRebranch1() throws InterruptedException {
StandaloneBlockchain bc = new StandaloneBlockchain();
PendingListener l = new PendingListener();
bc.addEthereumListener(l);
Triple<TransactionReceipt, EthereumListener.PendingTransactionState, Block> txUpd = null;
PendingStateImpl pendingState = (PendingStateImpl) bc.getBlockchain().getPendingState();
ECKey alice = new ECKey();
ECKey bob = new ECKey();
ECKey charlie = new ECKey();
bc.sendEther(bob.getAddress(), convert(100, ETHER));
bc.sendEther(charlie.getAddress(), convert(100, ETHER));
Block b1 = bc.createBlock();
Transaction tx1 = bc.createTransaction(bob, 0, alice.getAddress(), BigInteger.valueOf(1000000), new byte[0]);
pendingState.addPendingTransaction(tx1);
Transaction tx2 = bc.createTransaction(charlie, 0, alice.getAddress(), BigInteger.valueOf(1000000), new byte[0]);;
pendingState.addPendingTransaction(tx2);
Assert.assertEquals(l.pollTxUpdateState(tx1), NEW_PENDING);
Assert.assertEquals(l.pollTxUpdateState(tx2), NEW_PENDING);
Assert.assertTrue(pendingState.getRepository().getBalance(alice.getAddress()).
compareTo(BigInteger.valueOf(2000000)) == 0);
bc.submitTransaction(tx1);
Block b2 = bc.createBlock();
Assert.assertEquals(l.pollTxUpdateState(tx1), INCLUDED);
Assert.assertEquals(l.pollTxUpdateState(tx2), PENDING);
Assert.assertTrue(pendingState.getRepository().getBalance(alice.getAddress()).
compareTo(BigInteger.valueOf(2000000)) == 0);
bc.submitTransaction(tx2);
Block b3 = bc.createBlock();
Assert.assertEquals(l.pollTxUpdateState(tx2), INCLUDED);
Assert.assertTrue(pendingState.getRepository().getBalance(alice.getAddress()).
compareTo(BigInteger.valueOf(2000000)) == 0);
Block b2_ = bc.createForkBlock(b1);
Block b3_ = bc.createForkBlock(b2_);
bc.submitTransaction(tx2);
Block b4_ = bc.createForkBlock(b3_);
Assert.assertEquals(l.pollTxUpdateState(tx1), PENDING);
Assert.assertTrue(l.getQueueFor(tx1).isEmpty());
Assert.assertEquals(l.pollTxUpdateState(tx2), INCLUDED);
Assert.assertTrue(l.getQueueFor(tx2).isEmpty());
Assert.assertTrue(pendingState.getRepository().getBalance(alice.getAddress()).
compareTo(BigInteger.valueOf(2000000)) == 0);
bc.submitTransaction(tx1);
Block b5_ = bc.createForkBlock(b4_);
Assert.assertEquals(l.pollTxUpdateState(tx1), INCLUDED);
Assert.assertTrue(l.getQueueFor(tx1).isEmpty());
Assert.assertTrue(l.getQueueFor(tx2).isEmpty());
Assert.assertTrue(pendingState.getRepository().getBalance(alice.getAddress()).
compareTo(BigInteger.valueOf(2000000)) == 0);
}
@Test
public void testRebranch2() throws InterruptedException {
StandaloneBlockchain bc = new StandaloneBlockchain();
PendingListener l = new PendingListener();
bc.addEthereumListener(l);
Triple<TransactionReceipt, EthereumListener.PendingTransactionState, Block> txUpd = null;
PendingStateImpl pendingState = (PendingStateImpl) bc.getBlockchain().getPendingState();
ECKey alice = new ECKey();
ECKey bob = new ECKey();
ECKey charlie = new ECKey();
bc.sendEther(bob.getAddress(), convert(100, ETHER));
bc.sendEther(charlie.getAddress(), convert(100, ETHER));
Block b1 = bc.createBlock();
Transaction tx1 = bc.createTransaction(bob, 0, alice.getAddress(), BigInteger.valueOf(1000000), new byte[0]);
pendingState.addPendingTransaction(tx1);
Transaction tx2 = bc.createTransaction(charlie, 0, alice.getAddress(), BigInteger.valueOf(1000000), new byte[0]);;
pendingState.addPendingTransaction(tx2);
Assert.assertEquals(l.pollTxUpdateState(tx1), NEW_PENDING);
Assert.assertEquals(l.pollTxUpdateState(tx2), NEW_PENDING);
Assert.assertTrue(pendingState.getRepository().getBalance(alice.getAddress()).
compareTo(BigInteger.valueOf(2000000)) == 0);
bc.submitTransaction(tx1);
bc.sendEther(alice.getAddress(), BigInteger.valueOf(1000000));
Block b2 = bc.createBlock();
Transaction tx3 = b2.getTransactionsList().get(1);
Assert.assertEquals(l.pollTxUpdateState(tx1), INCLUDED);
Assert.assertEquals(l.pollTxUpdateState(tx2), PENDING);
Assert.assertTrue(l.getQueueFor(tx1).isEmpty());
Assert.assertTrue(l.getQueueFor(tx2).isEmpty());
Assert.assertTrue(pendingState.getRepository().getBalance(alice.getAddress()).
compareTo(BigInteger.valueOf(3000000)) == 0);
bc.sendEther(alice.getAddress(), BigInteger.valueOf(1000000));
bc.submitTransaction(tx2);
Block b3 = bc.createBlock();
Transaction tx4 = b3.getTransactionsList().get(0);
Assert.assertEquals(l.pollTxUpdateState(tx2), INCLUDED);
Assert.assertTrue(pendingState.getRepository().getBalance(alice.getAddress()).
compareTo(BigInteger.valueOf(4000000)) == 0);
bc.submitTransaction(tx2);
Block b2_ = bc.createForkBlock(b1);
bc.submitTransaction(tx1);
Block b3_ = bc.createForkBlock(b2_);
Block b4_ = bc.createForkBlock(b3_); // becoming the best branch
txUpd = l.pollTxUpdate(tx1);
Assert.assertEquals(txUpd.getMiddle(), INCLUDED);
Assert.assertEquals(txUpd.getRight(), b3_);
Assert.assertTrue(l.getQueueFor(tx1).isEmpty());
txUpd = l.pollTxUpdate(tx2);
Assert.assertEquals(txUpd.getMiddle(), INCLUDED);
Assert.assertEquals(txUpd.getRight(), b2_);
Assert.assertTrue(l.getQueueFor(tx2).isEmpty());
Assert.assertEquals(l.pollTxUpdateState(tx3), PENDING);
Assert.assertEquals(l.pollTxUpdateState(tx4), PENDING);
Assert.assertTrue(pendingState.getRepository().getBalance(alice.getAddress()).
compareTo(BigInteger.valueOf(4000000)) == 0);
// rebranching back
Block b4 = bc.createForkBlock(b3);
Block b5 = bc.createForkBlock(b4);
txUpd = l.pollTxUpdate(tx1);
Assert.assertEquals(txUpd.getMiddle(), INCLUDED);
Assert.assertEquals(txUpd.getRight(), b2);
Assert.assertTrue(l.getQueueFor(tx1).isEmpty());
txUpd = l.pollTxUpdate(tx2);
Assert.assertEquals(txUpd.getMiddle(), INCLUDED);
Assert.assertEquals(txUpd.getRight(), b3);
Assert.assertTrue(l.getQueueFor(tx2).isEmpty());
Assert.assertEquals(l.pollTxUpdateState(tx3), INCLUDED);
Assert.assertEquals(l.pollTxUpdateState(tx4), INCLUDED);
Assert.assertTrue(pendingState.getRepository().getBalance(alice.getAddress()).
compareTo(BigInteger.valueOf(4000000)) == 0);
}
@Test
public void testRebranch3() throws InterruptedException {
StandaloneBlockchain bc = new StandaloneBlockchain();
PendingListener l = new PendingListener();
bc.addEthereumListener(l);
Triple<TransactionReceipt, EthereumListener.PendingTransactionState, Block> txUpd = null;
PendingStateImpl pendingState = (PendingStateImpl) bc.getBlockchain().getPendingState();
ECKey alice = new ECKey();
ECKey bob = new ECKey();
ECKey charlie = new ECKey();
bc.sendEther(bob.getAddress(), convert(100, ETHER));
bc.sendEther(charlie.getAddress(), convert(100, ETHER));
Block b1 = bc.createBlock();
Transaction tx1 = bc.createTransaction(bob, 0, alice.getAddress(), BigInteger.valueOf(1000000), new byte[0]);
pendingState.addPendingTransaction(tx1);
Assert.assertEquals(l.pollTxUpdateState(tx1), NEW_PENDING);
bc.submitTransaction(tx1);
Block b2 = bc.createBlock();
txUpd = l.pollTxUpdate(tx1);
Assert.assertEquals(txUpd.getMiddle(), INCLUDED);
Assert.assertTrue(l.getQueueFor(tx1).isEmpty());
Block b3 = bc.createBlock();
Assert.assertTrue(l.getQueueFor(tx1).isEmpty());
bc.submitTransaction(tx1);
Block b2_ = bc.createForkBlock(b1);
Assert.assertTrue(l.getQueueFor(tx1).isEmpty());
Block b3_ = bc.createForkBlock(b2_);
Block b4_ = bc.createForkBlock(b3_);
txUpd = l.pollTxUpdate(tx1);
Assert.assertEquals(txUpd.getMiddle(), INCLUDED);
Assert.assertArrayEquals(txUpd.getRight().getHash(), b2_.getHash());
Block b4 = bc.createForkBlock(b3);
Block b5 = bc.createForkBlock(b4);
txUpd = l.pollTxUpdate(tx1);
Assert.assertEquals(txUpd.getMiddle(), INCLUDED);
Assert.assertArrayEquals(txUpd.getRight().getHash(), b2.getHash());
}
@Test
public void testOldBlockIncluded() throws InterruptedException {
StandaloneBlockchain bc = new StandaloneBlockchain();
PendingListener l = new PendingListener();
bc.addEthereumListener(l);
Triple<TransactionReceipt, EthereumListener.PendingTransactionState, Block> txUpd = null;
PendingStateImpl pendingState = (PendingStateImpl) bc.getBlockchain().getPendingState();
ECKey alice = new ECKey();
ECKey bob = new ECKey();
ECKey charlie = new ECKey();
bc.sendEther(bob.getAddress(), convert(100, ETHER));
Block b1 = bc.createBlock();
for (int i = 0; i < 16; i++) {
bc.createBlock();
}
Transaction tx1 = bc.createTransaction(bob, 0, alice.getAddress(), BigInteger.valueOf(1000000), new byte[0]);
pendingState.addPendingTransaction(tx1);
Assert.assertEquals(l.pollTxUpdateState(tx1), NEW_PENDING);
bc.submitTransaction(tx1);
Block b2_ = bc.createForkBlock(b1);
Assert.assertTrue(l.getQueueFor(tx1).isEmpty());
bc.submitTransaction(tx1);
Block b18 = bc.createBlock();
txUpd = l.pollTxUpdate(tx1);
Assert.assertEquals(txUpd.getMiddle(), INCLUDED);
Assert.assertArrayEquals(txUpd.getRight().getHash(), b18.getHash());
}
@Test
public void testBlockOnlyIncluded() throws InterruptedException {
StandaloneBlockchain bc = new StandaloneBlockchain();
PendingListener l = new PendingListener();
bc.addEthereumListener(l);
Triple<TransactionReceipt, EthereumListener.PendingTransactionState, Block> txUpd = null;
PendingStateImpl pendingState = (PendingStateImpl) bc.getBlockchain().getPendingState();
ECKey alice = new ECKey();
ECKey bob = new ECKey();
bc.sendEther(bob.getAddress(), convert(100, ETHER));
Block b1 = bc.createBlock();
Transaction tx1 = bc.createTransaction(bob, 0, alice.getAddress(), BigInteger.valueOf(1000000), new byte[0]);
bc.submitTransaction(tx1);
Block b2 = bc.createBlock();
Block b2_ = bc.createForkBlock(b1);
Assert.assertTrue(l.getQueueFor(tx1).isEmpty());
Block b3_ = bc.createForkBlock(b2_);
txUpd = l.pollTxUpdate(tx1);
Assert.assertEquals(txUpd.getMiddle(), PENDING);
}
@Test
public void testTrackTx1() throws InterruptedException {
StandaloneBlockchain bc = new StandaloneBlockchain();
PendingListener l = new PendingListener();
bc.addEthereumListener(l);
Triple<TransactionReceipt, EthereumListener.PendingTransactionState, Block> txUpd = null;
PendingStateImpl pendingState = (PendingStateImpl) bc.getBlockchain().getPendingState();
ECKey alice = new ECKey();
ECKey bob = new ECKey();
bc.sendEther(bob.getAddress(), convert(100, ETHER));
Block b1 = bc.createBlock();
Block b2 = bc.createBlock();
Block b3 = bc.createBlock();
Transaction tx1 = bc.createTransaction(bob, 0, alice.getAddress(), BigInteger.valueOf(1000000), new byte[0]);
bc.submitTransaction(tx1);
Block b2_ = bc.createForkBlock(b1);
Assert.assertTrue(l.getQueueFor(tx1).isEmpty());
pendingState.trackTransaction(tx1);
Assert.assertEquals(l.pollTxUpdateState(tx1), NEW_PENDING);
Block b3_ = bc.createForkBlock(b2_);
Block b4_ = bc.createForkBlock(b3_);
txUpd = l.pollTxUpdate(tx1);
Assert.assertEquals(txUpd.getMiddle(), INCLUDED);
Assert.assertArrayEquals(txUpd.getRight().getHash(), b2_.getHash());
}
@Test
public void testPrevBlock() throws InterruptedException {
StandaloneBlockchain bc = new StandaloneBlockchain();
PendingStateImpl pendingState = (PendingStateImpl) bc.getBlockchain().getPendingState();
ECKey alice = new ECKey();
ECKey bob = new ECKey();
SolidityContract contract = bc.submitNewContract("contract A {" +
" function getPrevBlockHash() returns (bytes32) {" +
" return block.blockhash(block.number - 1);" +
" }" +
"}");
bc.sendEther(bob.getAddress(), convert(100, ETHER));
Block b1 = bc.createBlock();
Block b2 = bc.createBlock();
Block b3 = bc.createBlock();
PendingListener l = new PendingListener();
bc.addEthereumListener(l);
Triple<TransactionReceipt, EthereumListener.PendingTransactionState, Block> txUpd;
contract.callFunction("getPrevBlockHash");
bc.generatePendingTransactions();
txUpd = l.onPendingTransactionUpdate.values().iterator().next().poll();
Assert.assertArrayEquals(txUpd.getLeft().getExecutionResult(), b3.getHash());
}
@Test
public void testTrackTx2() throws InterruptedException {
StandaloneBlockchain bc = new StandaloneBlockchain();
PendingListener l = new PendingListener();
bc.addEthereumListener(l);
Triple<TransactionReceipt, EthereumListener.PendingTransactionState, Block> txUpd = null;
PendingStateImpl pendingState = (PendingStateImpl) bc.getBlockchain().getPendingState();
ECKey alice = new ECKey();
ECKey bob = new ECKey();
bc.sendEther(bob.getAddress(), convert(100, ETHER));
Block b1 = bc.createBlock();
Transaction tx1 = bc.createTransaction(bob, 0, alice.getAddress(), BigInteger.valueOf(1000000), new byte[0]);
bc.submitTransaction(tx1);
Block b2 = bc.createBlock();
Assert.assertTrue(l.getQueueFor(tx1).isEmpty());
pendingState.trackTransaction(tx1);
txUpd = l.pollTxUpdate(tx1);
Assert.assertEquals(txUpd.getMiddle(), INCLUDED);
Assert.assertArrayEquals(txUpd.getRight().getHash(), b2.getHash());
Block b2_ = bc.createForkBlock(b1);
Block b3_ = bc.createForkBlock(b2_);
Assert.assertEquals(l.pollTxUpdateState(tx1), PENDING);
}
@Test
public void testRejected1() throws InterruptedException {
StandaloneBlockchain bc = new StandaloneBlockchain();
PendingListener l = new PendingListener();
bc.addEthereumListener(l);
Triple<TransactionReceipt, EthereumListener.PendingTransactionState, Block> txUpd = null;
PendingStateImpl pendingState = (PendingStateImpl) bc.getBlockchain().getPendingState();
ECKey alice = new ECKey();
ECKey bob = new ECKey();
ECKey charlie = new ECKey();
bc.sendEther(bob.getAddress(), convert(100, ETHER));
bc.sendEther(charlie.getAddress(), convert(100, ETHER));
Block b1 = bc.createBlock();
Transaction tx1 = bc.createTransaction(bob, 0, alice.getAddress(), BigInteger.valueOf(1000000), new byte[0]);
pendingState.addPendingTransaction(tx1);
Assert.assertEquals(l.pollTxUpdateState(tx1), NEW_PENDING);
bc.submitTransaction(tx1);
Block b2_ = bc.createForkBlock(b1);
Assert.assertEquals(l.pollTxUpdateState(tx1), INCLUDED);
Block b2 = bc.createForkBlock(b1);
Block b3 = bc.createForkBlock(b2);
Assert.assertEquals(l.pollTxUpdateState(tx1), PENDING);
Assert.assertTrue(l.getQueueFor(tx1).isEmpty());
for (int i = 0; i < 16; i++) {
bc.createBlock();
EthereumListener.PendingTransactionState state = l.pollTxUpdateState(tx1);
if (state == EthereumListener.PendingTransactionState.DROPPED) {
break;
}
if (i == 15) {
throw new RuntimeException("Transaction was not dropped");
}
}
}
@Test
public void testIncludedRejected() throws InterruptedException {
// check INCLUDED => DROPPED state transition when a new (long) fork without
// the transaction becomes the main chain
StandaloneBlockchain bc = new StandaloneBlockchain();
PendingListener l = new PendingListener();
bc.addEthereumListener(l);
Triple<TransactionReceipt, EthereumListener.PendingTransactionState, Block> txUpd = null;
PendingStateImpl pendingState = (PendingStateImpl) bc.getBlockchain().getPendingState();
ECKey alice = new ECKey();
ECKey bob = new ECKey();
ECKey charlie = new ECKey();
bc.sendEther(bob.getAddress(), convert(100, ETHER));
bc.sendEther(charlie.getAddress(), convert(100, ETHER));
Block b1 = bc.createBlock();
Transaction tx1 = bc.createTransaction(bob, 0, alice.getAddress(), BigInteger.valueOf(1000000), new byte[0]);
pendingState.addPendingTransaction(tx1);
Assert.assertEquals(l.pollTxUpdateState(tx1), NEW_PENDING);
bc.submitTransaction(tx1);
Block b2 = bc.createForkBlock(b1);
Assert.assertEquals(l.pollTxUpdateState(tx1), INCLUDED);
for (int i = 0; i < 10; i++) {
bc.createBlock();
}
Block b_ = bc.createForkBlock(b1);
for (int i = 0; i < 11; i++) {
b_ = bc.createForkBlock(b_);
}
Assert.assertEquals(l.pollTxUpdateState(tx1), DROPPED);
Assert.assertTrue(l.getQueueFor(tx1).isEmpty());
}
@Test
public void testInvalidTransaction() throws InterruptedException {
StandaloneBlockchain bc = new StandaloneBlockchain();
final CountDownLatch txHandle = new CountDownLatch(1);
PendingListener l = new PendingListener() {
@Override
public void onPendingTransactionUpdate(TransactionReceipt txReceipt, PendingTransactionState state, Block block) {
assert !txReceipt.isSuccessful();
assert txReceipt.getError().toLowerCase().contains("invalid");
assert txReceipt.getError().toLowerCase().contains("receive address");
txHandle.countDown();
}
};
bc.addEthereumListener(l);
PendingStateImpl pendingState = (PendingStateImpl) bc.getBlockchain().getPendingState();
ECKey alice = new ECKey();
Random rnd = new Random();
Block b1 = bc.createBlock();
byte[] b = new byte[21];
rnd.nextBytes(b);
Transaction tx1 = bc.createTransaction(alice, 0, b, BigInteger.ONE, new byte[0]);
pendingState.addPendingTransaction(tx1);
assert txHandle.await(3, TimeUnit.SECONDS);
}
}
| 27,207
| 40.858462
| 188
|
java
|
ethereumj
|
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/core/TransactionExecutionSummaryTest.java
|
/*
* Copyright (c) [2016] [ <ether.camp> ]
* This file is part of the ethereumJ library.
*
* The ethereumJ library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The ethereumJ library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the ethereumJ library. If not, see <http://www.gnu.org/licenses/>.
*/
package org.ethereum.core;
import org.ethereum.vm.DataWord;
import org.ethereum.vm.LogInfo;
import org.ethereum.vm.program.InternalTransaction;
import org.junit.Test;
import java.math.BigInteger;
import java.util.*;
import static org.apache.commons.collections4.CollectionUtils.size;
import static org.ethereum.util.ByteUtil.toHexString;
import static org.junit.Assert.*;
public class TransactionExecutionSummaryTest {
@Test
public void testRlpEncoding() {
Transaction tx = randomTransaction();
Set<DataWord> deleteAccounts = new HashSet<>(randomDataWords(10));
List<LogInfo> logs = randomLogsInfo(5);
final Map<DataWord, DataWord> readOnly = randomStorageEntries(20);
final Map<DataWord, DataWord> changed = randomStorageEntries(5);
Map<DataWord, DataWord> all = new HashMap<DataWord, DataWord>() {{
putAll(readOnly);
putAll(changed);
}};
BigInteger gasLeftover = new BigInteger("123");
BigInteger gasRefund = new BigInteger("125");
BigInteger gasUsed = new BigInteger("556");
final int nestedLevelCount = 5000;
final int countByLevel = 1;
List<InternalTransaction> internalTransactions = randomInternalTransactions(tx, nestedLevelCount, countByLevel);
byte[] result = randomBytes(32);
byte[] encoded = new TransactionExecutionSummary.Builder(tx)
.deletedAccounts(deleteAccounts)
.logs(logs)
.touchedStorage(all, changed)
.gasLeftover(gasLeftover)
.gasRefund(gasRefund)
.gasUsed(gasUsed)
.internalTransactions(internalTransactions)
.result(result)
.build()
.getEncoded();
TransactionExecutionSummary summary = new TransactionExecutionSummary(encoded);
assertArrayEquals(tx.getHash(), summary.getTransactionHash());
assertEquals(size(deleteAccounts), size(summary.getDeletedAccounts()));
for (DataWord account : summary.getDeletedAccounts()) {
assertTrue(deleteAccounts.contains(account));
}
assertEquals(size(logs), size(summary.getLogs()));
for (int i = 0; i < logs.size(); i++) {
assertLogInfoEquals(logs.get(i), summary.getLogs().get(i));
}
assertStorageEquals(all, summary.getTouchedStorage().getAll());
assertStorageEquals(changed, summary.getTouchedStorage().getChanged());
assertStorageEquals(readOnly, summary.getTouchedStorage().getReadOnly());
assertEquals(gasRefund, summary.getGasRefund());
assertEquals(gasLeftover, summary.getGasLeftover());
assertEquals(gasUsed, summary.getGasUsed());
assertEquals(nestedLevelCount * countByLevel, size(internalTransactions));
assertArrayEquals(result, summary.getResult());
}
private static void assertStorageEquals(Map<DataWord, DataWord> expected, Map<DataWord, DataWord> actual) {
assertNotNull(expected);
assertNotNull(actual);
assertEquals(expected.size(), actual.size());
for (DataWord key : expected.keySet()) {
DataWord actualValue = actual.get(key);
assertNotNull(actualValue);
assertArrayEquals(expected.get(key).getData(), actualValue.getData());
}
}
private static void assertLogInfoEquals(LogInfo expected, LogInfo actual) {
assertNotNull(expected);
assertNotNull(actual);
assertArrayEquals(expected.getAddress(), actual.getAddress());
assertEquals(size(expected.getTopics()), size(actual.getTopics()));
for (int i = 0; i < size(expected.getTopics()); i++) {
assertArrayEquals(expected.getTopics().get(i).getData(), actual.getTopics().get(i).getData());
}
assertArrayEquals(expected.getData(), actual.getData());
}
private static Map<DataWord, DataWord> randomStorageEntries(int count) {
Map<DataWord, DataWord> result = new HashMap<>();
for (int i = 0; i < count; i++) {
result.put(randomDataWord(), randomDataWord());
}
return result;
}
private static LogInfo randomLogInfo() {
return new LogInfo(randomBytes(20), randomDataWords(5), randomBytes(8));
}
private static List<LogInfo> randomLogsInfo(int count) {
List<LogInfo> result = new ArrayList<>(count);
for (int i = 0; i < count; i++) {
result.add(randomLogInfo());
}
return result;
}
private static DataWord randomDataWord() {
return DataWord.of(randomBytes(32));
}
private static DataWord randomAddress() {
return DataWord.of(randomBytes(20));
}
private static List<DataWord> randomDataWords(int count) {
List<DataWord> result = new ArrayList<>(count);
for (int i = 0; i < count; i++) {
result.add(randomDataWord());
}
return result;
}
private static InternalTransaction randomInternalTransaction(Transaction parent, int deep, int index) {
try {
return new InternalTransaction(parent.getHash(), deep, index, randomBytes(1), DataWord.ZERO, DataWord.ZERO,
parent.getReceiveAddress(), randomBytes(20), randomBytes(2), randomBytes(64), "test note");
} catch (StackOverflowError e) {
System.out.println("\n !!! StackOverflowError: update your java run command with -Xss8M !!!\n");
throw e;
}
}
private static List<InternalTransaction> randomInternalTransactions(Transaction parent, int nestedLevelCount, int countByLevel) {
List<InternalTransaction> result = new ArrayList<>();
if (nestedLevelCount > 0) {
for (int index = 0; index < countByLevel; index++) {
result.add(randomInternalTransaction(parent, nestedLevelCount, index));
}
result.addAll(0, randomInternalTransactions(result.get(result.size() - 1), nestedLevelCount - 1, countByLevel));
}
return result;
}
private static Transaction randomTransaction() {
Transaction transaction = Transaction.createDefault(toHexString(randomBytes(20)), new BigInteger(randomBytes(2)), new BigInteger(randomBytes(1)), null);
transaction.sign(randomBytes(32));
return transaction;
}
private static byte[] randomBytes(int len) {
byte[] bytes = new byte[len];
new Random().nextBytes(bytes);
return bytes;
}
}
| 7,363
| 37.962963
| 160
|
java
|
ethereumj
|
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/core/PendingStateLongRunTest.java
|
/*
* Copyright (c) [2016] [ <ether.camp> ]
* This file is part of the ethereumJ library.
*
* The ethereumJ library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The ethereumJ library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the ethereumJ library. If not, see <http://www.gnu.org/licenses/>.
*/
package org.ethereum.core;
import org.ethereum.config.CommonConfig;
import org.ethereum.datasource.inmem.HashMapDB;
import org.ethereum.db.RepositoryRoot;
import org.ethereum.db.ByteArrayWrapper;
import org.ethereum.db.IndexedBlockStore;
import org.ethereum.listener.EthereumListenerAdapter;
import org.ethereum.validator.DependentBlockHeaderRuleAdapter;
import org.ethereum.vm.program.invoke.ProgramInvokeFactoryImpl;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.spongycastle.util.encoders.Hex;
import java.io.File;
import java.io.IOException;
import java.math.BigInteger;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.List;
import static org.ethereum.util.BIUtil.toBI;
import static org.junit.Assert.*;
/**
* @author Mikhail Kalinin
* @since 24.09.2015
*/
@Ignore
public class PendingStateLongRunTest {
private Blockchain blockchain;
private PendingState pendingState;
private List<String> strData;
@Before
public void setup() throws URISyntaxException, IOException, InterruptedException {
blockchain = createBlockchain((Genesis) Genesis.getInstance());
pendingState = ((BlockchainImpl) blockchain).getPendingState();
URL blocks = ClassLoader.getSystemResource("state/47250.dmp");
File file = new File(blocks.toURI());
strData = Files.readAllLines(file.toPath(), StandardCharsets.UTF_8);
for (int i = 0; i < 46000; i++) {
Block b = new Block(Hex.decode(strData.get(i)));
blockchain.tryToConnect(b);
}
}
@Test // test with real data from the frontier net
public void test_1() {
Block b46169 = new Block(Hex.decode(strData.get(46169)));
Block b46170 = new Block(Hex.decode(strData.get(46170)));
Transaction tx46169 = b46169.getTransactionsList().get(0);
Transaction tx46170 = b46170.getTransactionsList().get(0);
Repository pending = pendingState.getRepository();
BigInteger balanceBefore46169 = pending.getAccountState(tx46169.getReceiveAddress()).getBalance();
BigInteger balanceBefore46170 = pending.getAccountState(tx46170.getReceiveAddress()).getBalance();
pendingState.addPendingTransaction(tx46169);
pendingState.addPendingTransaction(tx46170);
for (int i = 46000; i < 46169; i++) {
Block b = new Block(Hex.decode(strData.get(i)));
blockchain.tryToConnect(b);
}
pending = pendingState.getRepository();
BigInteger balanceAfter46169 = balanceBefore46169.add(toBI(tx46169.getValue()));
assertEquals(pendingState.getPendingTransactions().size(), 2);
assertEquals(balanceAfter46169, pending.getAccountState(tx46169.getReceiveAddress()).getBalance());
blockchain.tryToConnect(b46169);
pending = pendingState.getRepository();
assertEquals(balanceAfter46169, pending.getAccountState(tx46169.getReceiveAddress()).getBalance());
assertEquals(pendingState.getPendingTransactions().size(), 1);
BigInteger balanceAfter46170 = balanceBefore46170.add(toBI(tx46170.getValue()));
assertEquals(balanceAfter46170, pending.getAccountState(tx46170.getReceiveAddress()).getBalance());
blockchain.tryToConnect(b46170);
pending = pendingState.getRepository();
assertEquals(balanceAfter46170, pending.getAccountState(tx46170.getReceiveAddress()).getBalance());
assertEquals(pendingState.getPendingTransactions().size(), 0);
}
private Blockchain createBlockchain(Genesis genesis) {
IndexedBlockStore blockStore = new IndexedBlockStore();
blockStore.init(new HashMapDB<byte[]>(), new HashMapDB<byte[]>());
Repository repository = new RepositoryRoot(new HashMapDB());
ProgramInvokeFactoryImpl programInvokeFactory = new ProgramInvokeFactoryImpl();
BlockchainImpl blockchain = new BlockchainImpl(blockStore, repository)
.withParentBlockHeaderValidator(new CommonConfig().parentHeaderValidator());
blockchain.setParentHeaderValidator(new DependentBlockHeaderRuleAdapter());
blockchain.setProgramInvokeFactory(programInvokeFactory);
blockchain.byTest = true;
PendingStateImpl pendingState = new PendingStateImpl(new EthereumListenerAdapter());
pendingState.setBlockchain(blockchain);
blockchain.setPendingState(pendingState);
Repository track = repository.startTracking();
Genesis.populateRepository(track, genesis);
track.commit();
blockStore.saveBlock(Genesis.getInstance(), Genesis.getInstance().getDifficultyBI(), true);
blockchain.setBestBlock(Genesis.getInstance());
blockchain.setTotalDifficulty(Genesis.getInstance().getDifficultyBI());
return blockchain;
}
}
| 5,721
| 36.398693
| 107
|
java
|
ethereumj
|
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/core/BloomTest.java
|
/*
* Copyright (c) [2016] [ <ether.camp> ]
* This file is part of the ethereumJ library.
*
* The ethereumJ library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The ethereumJ library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the ethereumJ library. If not, see <http://www.gnu.org/licenses/>.
*/
package org.ethereum.core;
import org.ethereum.crypto.HashUtil;
import org.junit.Assert;
import org.junit.Test;
import org.spongycastle.util.encoders.Hex;
/**
* @author Roman Mandeleil
* @since 20.11.2014
*/
public class BloomTest {
@Test /// based on http://bit.ly/1MtXxFg
public void test1(){
byte[] address = Hex.decode("095e7baea6a6c7c4c2dfeb977efac326af552d87");
Bloom addressBloom = Bloom.create(HashUtil.sha3(address));
byte[] topic = Hex.decode("0000000000000000000000000000000000000000000000000000000000000000");
Bloom topicBloom = Bloom.create(HashUtil.sha3(topic));
Bloom totalBloom = new Bloom();
totalBloom.or(addressBloom);
totalBloom.or(topicBloom);
Assert.assertEquals(
"00000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000040000000000000000000000000000000000000000000000000000000",
totalBloom.toString()
);
Assert.assertTrue(totalBloom.matches(addressBloom));
Assert.assertTrue(totalBloom.matches(topicBloom));
Assert.assertFalse(totalBloom.matches(Bloom.create(HashUtil.sha3(Hex.decode("1000000000000000000000000000000000000000000000000000000000000000")))));
Assert.assertFalse(totalBloom.matches(Bloom.create(HashUtil.sha3(Hex.decode("195e7baea6a6c7c4c2dfeb977efac326af552d87")))));
}
@Test
public void test2() {
// todo: more testing
}
@Test
public void test3() {
// todo: more testing
}
@Test
public void test4() {
// todo: more testing
}
}
| 2,782
| 36.106667
| 531
|
java
|
ethereumj
|
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/core/PremineRawTest.java
|
package org.ethereum.core;
import org.junit.Test;
import java.math.BigInteger;
import static org.junit.Assert.*;
/**
* @author alexbraz
* @since 29/03/2019
*/
public class PremineRawTest {
@Test
public void testPremineRawNotNull() {
byte[] addr = "0xcf0f482f2c1ef1f221f09e3cf14122fce0424f94".getBytes();
PremineRaw pr = new PremineRaw(addr, BigInteger.ONE, Denomination.ETHER);
assertTrue(pr.getDenomination() == Denomination.ETHER);
assertEquals(pr.value, BigInteger.ONE);
assertNotNull(pr.getAddr());
}
}
| 569
| 20.923077
| 81
|
java
|
ethereumj
|
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/core/PruneTest.java
|
/*
* Copyright (c) [2016] [ <ether.camp> ]
* This file is part of the ethereumJ library.
*
* The ethereumJ library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The ethereumJ library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the ethereumJ library. If not, see <http://www.gnu.org/licenses/>.
*/
package org.ethereum.core;
import org.ethereum.config.SystemProperties;
import org.ethereum.crypto.ECKey;
import org.ethereum.crypto.HashUtil;
import org.ethereum.datasource.*;
import org.ethereum.datasource.inmem.HashMapDB;
import org.ethereum.db.ByteArrayWrapper;
import org.ethereum.db.prune.Pruner;
import org.ethereum.db.prune.Segment;
import org.ethereum.trie.SecureTrie;
import org.ethereum.trie.TrieImpl;
import org.ethereum.util.FastByteComparisons;
import org.ethereum.util.blockchain.SolidityContract;
import org.ethereum.util.blockchain.StandaloneBlockchain;
import org.junit.*;
import org.spongycastle.util.encoders.Hex;
import java.math.BigInteger;
import java.util.*;
import static org.ethereum.util.ByteUtil.intToBytes;
import static org.ethereum.util.blockchain.EtherUtil.Unit.ETHER;
import static org.ethereum.util.blockchain.EtherUtil.convert;
import static org.junit.Assert.assertTrue;
/**
* Created by Anton Nashatyrev on 05.07.2016.
*/
public class PruneTest {
@AfterClass
public static void cleanup() {
SystemProperties.resetToDefault();
}
@Test
public void testJournal1() throws Exception {
HashMapDB<byte[]> db = new HashMapDB<>();
JournalSource<byte[]> journalDB = new JournalSource<>(db);
Pruner pruner = new Pruner(journalDB.getJournal(), db);
pruner.init();
put(journalDB, "11");
put(journalDB, "22");
put(journalDB, "33");
pruner.feed(journalDB.commitUpdates(intToBytes(1)));
checkKeys(db.getStorage(), "11", "22", "33");
put(journalDB, "22");
delete(journalDB, "33");
put(journalDB, "44");
pruner.feed(journalDB.commitUpdates(intToBytes(2)));
checkKeys(db.getStorage(), "11", "22", "33", "44");
pruner.feed(journalDB.commitUpdates(intToBytes(12)));
Segment segment = new Segment(0, intToBytes(0), intToBytes(0));
segment.startTracking()
.addMain(1, intToBytes(1), intToBytes(0))
.addItem(1, intToBytes(2), intToBytes(0))
.addMain(2, intToBytes(12), intToBytes(1))
.commit();
pruner.prune(segment);
checkKeys(db.getStorage(), "11", "22", "33");
put(journalDB, "22");
delete(journalDB, "33");
put(journalDB, "44");
pruner.feed(journalDB.commitUpdates(intToBytes(3)));
checkKeys(db.getStorage(), "11", "22", "33", "44");
delete(journalDB, "22");
put(journalDB, "33");
delete(journalDB, "44");
pruner.feed(journalDB.commitUpdates(intToBytes(4)));
checkKeys(db.getStorage(), "11", "22", "33", "44");
segment = new Segment(0, intToBytes(0), intToBytes(0));
segment.startTracking()
.addMain(1, intToBytes(3), intToBytes(0))
.commit();
pruner.prune(segment);
checkKeys(db.getStorage(), "11", "22", "33", "44");
segment = new Segment(0, intToBytes(0), intToBytes(0));
segment.startTracking()
.addMain(1, intToBytes(4), intToBytes(0))
.commit();
pruner.prune(segment);
checkKeys(db.getStorage(), "11", "33");
}
private static void put(Source<byte[], byte[]> db, String key) {
db.put(Hex.decode(key), Hex.decode(key));
}
private static void delete(Source<byte[], byte[]> db, String key) {
db.delete(Hex.decode(key));
}
private static void checkKeys(Map<byte[], byte[]> map, String ... keys) {
Assert.assertEquals(keys.length, map.size());
for (String key : keys) {
assertTrue(map.containsKey(Hex.decode(key)));
}
}
@Test
public void simpleTest() throws Exception {
final int pruneCount = 3;
SystemProperties.getDefault().overrideParams(
"database.prune.enabled", "true",
"database.prune.maxDepth", "" + pruneCount,
"mine.startNonce", "0");
StandaloneBlockchain bc = new StandaloneBlockchain();
ECKey alice = ECKey.fromPrivate(BigInteger.TEN);
ECKey bob = ECKey.fromPrivate(BigInteger.ONE);
// System.out.println("Gen root: " + Hex.toHexString(bc.getBlockchain().getBestBlock().getStateRoot()));
bc.createBlock();
Block b0 = bc.getBlockchain().getBestBlock();
bc.sendEther(alice.getAddress(), convert(3, ETHER));
Block b1_1 = bc.createBlock();
bc.sendEther(alice.getAddress(), convert(3, ETHER));
Block b1_2 = bc.createForkBlock(b0);
bc.sendEther(alice.getAddress(), convert(3, ETHER));
Block b1_3 = bc.createForkBlock(b0);
bc.sendEther(alice.getAddress(), convert(3, ETHER));
Block b1_4 = bc.createForkBlock(b0);
bc.sendEther(bob.getAddress(), convert(5, ETHER));
bc.createBlock();
bc.sendEther(alice.getAddress(), convert(3, ETHER));
bc.createForkBlock(b1_2);
for (int i = 0; i < 9; i++) {
bc.sendEther(alice.getAddress(), convert(3, ETHER));
bc.sendEther(bob.getAddress(), convert(5, ETHER));
bc.createBlock();
}
byte[][] roots = new byte[pruneCount + 1][];
for (int i = 0; i < pruneCount + 1; i++) {
long bNum = bc.getBlockchain().getBestBlock().getNumber() - i;
Block b = bc.getBlockchain().getBlockByNumber(bNum);
roots[i] = b.getStateRoot();
}
checkPruning(bc.getStateDS(), bc.getPruningStateDS(), roots);
long bestBlockNum = bc.getBlockchain().getBestBlock().getNumber();
Assert.assertEquals(convert(30, ETHER), bc.getBlockchain().getRepository().getBalance(alice.getAddress()));
Assert.assertEquals(convert(50, ETHER), bc.getBlockchain().getRepository().getBalance(bob.getAddress()));
{
Block b1 = bc.getBlockchain().getBlockByNumber(bestBlockNum - 1);
Repository r1 = bc.getBlockchain().getRepository().getSnapshotTo(b1.getStateRoot());
Assert.assertEquals(convert(3 * 9, ETHER), r1.getBalance(alice.getAddress()));
Assert.assertEquals(convert(5 * 9, ETHER), r1.getBalance(bob.getAddress()));
}
{
Block b1 = bc.getBlockchain().getBlockByNumber(bestBlockNum - 2);
Repository r1 = bc.getBlockchain().getRepository().getSnapshotTo(b1.getStateRoot());
Assert.assertEquals(convert(3 * 8, ETHER), r1.getBalance(alice.getAddress()));
Assert.assertEquals(convert(5 * 8, ETHER), r1.getBalance(bob.getAddress()));
}
{
Block b1 = bc.getBlockchain().getBlockByNumber(bestBlockNum - 3);
Repository r1 = bc.getBlockchain().getRepository().getSnapshotTo(b1.getStateRoot());
Assert.assertEquals(convert(3 * 7, ETHER), r1.getBalance(alice.getAddress()));
Assert.assertEquals(convert(5 * 7, ETHER), r1.getBalance(bob.getAddress()));
}
{
// this state should be pruned already
Block b1 = bc.getBlockchain().getBlockByNumber(bestBlockNum - 6);
Repository r1 = bc.getBlockchain().getRepository().getSnapshotTo(b1.getStateRoot());
Assert.assertEquals(BigInteger.ZERO, r1.getBalance(alice.getAddress()));
Assert.assertEquals(BigInteger.ZERO, r1.getBalance(bob.getAddress()));
}
}
static HashMapDB<byte[]> stateDS;
static String getCount(String hash) {
byte[] bytes = stateDS.get(Hex.decode(hash));
return bytes == null ? "0" : "" + bytes[3];
}
@Test
public void contractTest() throws Exception {
// checks that pruning doesn't delete the nodes which were 're-added' later
// e.g. when a contract variable assigned value V1 the trie acquires node with key K1
// then if the variable reassigned value V2 the trie acquires new node with key K2
// and the node K1 is not needed anymore and added to the prune list
// we should avoid situations when the value V1 is back, the node K1 is also back to the trie
// but erroneously deleted later as was in the prune list
final int pruneCount = 3;
SystemProperties.getDefault().overrideParams(
"database.prune.enabled", "true",
"database.prune.maxDepth", "" + pruneCount);
StandaloneBlockchain bc = new StandaloneBlockchain();
SolidityContract contr = bc.submitNewContract(
"contract Simple {" +
" uint public n;" +
" function set(uint _n) { n = _n; } " +
"}");
bc.createBlock();
// add/remove/add in the same block
contr.callFunction("set", 0xaaaaaaaaaaaaL);
contr.callFunction("set", 0xbbbbbbbbbbbbL);
contr.callFunction("set", 0xaaaaaaaaaaaaL);
bc.createBlock();
Assert.assertEquals(BigInteger.valueOf(0xaaaaaaaaaaaaL), contr.callConstFunction("n")[0]);
// force prune
bc.createBlock();
bc.createBlock();
bc.createBlock();
bc.createBlock();
bc.createBlock();
bc.createBlock();
bc.createBlock();
Assert.assertEquals(BigInteger.valueOf(0xaaaaaaaaaaaaL), contr.callConstFunction("n")[0]);
for (int i = 1; i < 4; i++) {
for (int j = 0; j < 4; j++) {
contr.callFunction("set", 0xbbbbbbbbbbbbL);
for (int k = 0; k < j; k++) {
bc.createBlock();
}
if (j > 0)
Assert.assertEquals(BigInteger.valueOf(0xbbbbbbbbbbbbL), contr.callConstFunction("n")[0]);
contr.callFunction("set", 0xaaaaaaaaaaaaL);
for (int k = 0; k < i; k++) {
bc.createBlock();
}
Assert.assertEquals(BigInteger.valueOf(0xaaaaaaaaaaaaL), contr.callConstFunction("n")[0]);
}
}
byte[][] roots = new byte[pruneCount + 1][];
for (int i = 0; i < pruneCount + 1; i++) {
long bNum = bc.getBlockchain().getBestBlock().getNumber() - i;
Block b = bc.getBlockchain().getBlockByNumber(bNum);
roots[i] = b.getStateRoot();
}
checkPruning(bc.getStateDS(), bc.getPruningStateDS(), roots);
}
@Test
public void twoContractsTest() throws Exception {
final int pruneCount = 3;
SystemProperties.getDefault().overrideParams(
"database.prune.enabled", "true",
"database.prune.maxDepth", "" + pruneCount);
String src =
"contract Simple {" +
" uint public n;" +
" function set(uint _n) { n = _n; } " +
" function inc() { n++; } " +
"}";
StandaloneBlockchain bc = new StandaloneBlockchain();
Block b0 = bc.getBlockchain().getBestBlock();
SolidityContract contr1 = bc.submitNewContract(src);
SolidityContract contr2 = bc.submitNewContract(src);
Block b1 = bc.createBlock();
checkPruning(bc.getStateDS(), bc.getPruningStateDS(),
b1.getStateRoot(), b0.getStateRoot());
// add/remove/add in the same block
contr1.callFunction("set", 0xaaaaaaaaaaaaL);
contr2.callFunction("set", 0xaaaaaaaaaaaaL);
Block b2 = bc.createBlock();
Assert.assertEquals(BigInteger.valueOf(0xaaaaaaaaaaaaL), contr1.callConstFunction("n")[0]);
Assert.assertEquals(BigInteger.valueOf(0xaaaaaaaaaaaaL), contr2.callConstFunction("n")[0]);
checkPruning(bc.getStateDS(), bc.getPruningStateDS(),
b2.getStateRoot(), b1.getStateRoot(), b0.getStateRoot());
contr2.callFunction("set", 0xbbbbbbbbbbbbL);
Block b3 = bc.createBlock();
Assert.assertEquals(BigInteger.valueOf(0xaaaaaaaaaaaaL), contr1.callConstFunction("n")[0]);
Assert.assertEquals(BigInteger.valueOf(0xbbbbbbbbbbbbL), contr2.callConstFunction("n")[0]);
checkPruning(bc.getStateDS(), bc.getPruningStateDS(),
b3.getStateRoot(), b2.getStateRoot(), b1.getStateRoot(), b0.getStateRoot());
// force prune
Block b4 = bc.createBlock();
checkPruning(bc.getStateDS(), bc.getPruningStateDS(),
b4.getStateRoot(), b3.getStateRoot(), b2.getStateRoot(), b1.getStateRoot());
Block b5 = bc.createBlock();
checkPruning(bc.getStateDS(), bc.getPruningStateDS(),
b5.getStateRoot(), b4.getStateRoot(), b3.getStateRoot(), b2.getStateRoot());
Block b6 = bc.createBlock();
Assert.assertEquals(BigInteger.valueOf(0xaaaaaaaaaaaaL), contr1.callConstFunction("n")[0]);
Assert.assertEquals(BigInteger.valueOf(0xbbbbbbbbbbbbL), contr2.callConstFunction("n")[0]);
checkPruning(bc.getStateDS(), bc.getPruningStateDS(),
b6.getStateRoot(), b5.getStateRoot(), b4.getStateRoot(), b3.getStateRoot());
contr1.callFunction("set", 0xaaaaaaaaaaaaL);
contr2.callFunction("set", 0xaaaaaaaaaaaaL);
Block b7 = bc.createBlock();
Assert.assertEquals(BigInteger.valueOf(0xaaaaaaaaaaaaL), contr1.callConstFunction("n")[0]);
Assert.assertEquals(BigInteger.valueOf(0xaaaaaaaaaaaaL), contr2.callConstFunction("n")[0]);
checkPruning(bc.getStateDS(), bc.getPruningStateDS(),
b7.getStateRoot(), b6.getStateRoot(), b5.getStateRoot(), b4.getStateRoot());
contr1.callFunction("set", 0xbbbbbbbbbbbbL);
Block b8 = bc.createBlock();
Assert.assertEquals(BigInteger.valueOf(0xbbbbbbbbbbbbL), contr1.callConstFunction("n")[0]);
Assert.assertEquals(BigInteger.valueOf(0xaaaaaaaaaaaaL), contr2.callConstFunction("n")[0]);
checkPruning(bc.getStateDS(), bc.getPruningStateDS(),
b8.getStateRoot(), b7.getStateRoot(), b6.getStateRoot(), b5.getStateRoot());
contr2.callFunction("set", 0xbbbbbbbbbbbbL);
Block b8_ = bc.createForkBlock(b7);
checkPruning(bc.getStateDS(), bc.getPruningStateDS(),
b8.getStateRoot(), b8_.getStateRoot(), b7.getStateRoot(), b6.getStateRoot(), b5.getStateRoot());
Block b9_ = bc.createForkBlock(b8_);
Assert.assertEquals(BigInteger.valueOf(0xaaaaaaaaaaaaL), contr1.callConstFunction("n")[0]);
Assert.assertEquals(BigInteger.valueOf(0xbbbbbbbbbbbbL), contr2.callConstFunction("n")[0]);
checkPruning(bc.getStateDS(), bc.getPruningStateDS(),
b9_.getStateRoot(), b8.getStateRoot(), b8_.getStateRoot(), b7.getStateRoot(), b6.getStateRoot());
Block b9 = bc.createForkBlock(b8);
checkPruning(bc.getStateDS(), bc.getPruningStateDS(),
b9.getStateRoot(), b9_.getStateRoot(), b8.getStateRoot(), b8_.getStateRoot(), b7.getStateRoot(), b6.getStateRoot());
Block b10 = bc.createForkBlock(b9);
Assert.assertEquals(BigInteger.valueOf(0xbbbbbbbbbbbbL), contr1.callConstFunction("n")[0]);
Assert.assertEquals(BigInteger.valueOf(0xaaaaaaaaaaaaL), contr2.callConstFunction("n")[0]);
checkPruning(bc.getStateDS(), bc.getPruningStateDS(),
b10.getStateRoot(), b9.getStateRoot(), b9_.getStateRoot(), b8.getStateRoot(), b8_.getStateRoot(), b7.getStateRoot());
Block b11 = bc.createForkBlock(b10);
Assert.assertEquals(BigInteger.valueOf(0xbbbbbbbbbbbbL), contr1.callConstFunction("n")[0]);
Assert.assertEquals(BigInteger.valueOf(0xaaaaaaaaaaaaL), contr2.callConstFunction("n")[0]);
checkPruning(bc.getStateDS(), bc.getPruningStateDS(),
b11.getStateRoot(), b10.getStateRoot(), b9.getStateRoot(), /*b9_.getStateRoot(),*/ b8.getStateRoot());
}
@Test
public void branchTest() throws Exception {
final int pruneCount = 3;
SystemProperties.getDefault().overrideParams(
"database.prune.enabled", "true",
"database.prune.maxDepth", "" + pruneCount);
StandaloneBlockchain bc = new StandaloneBlockchain();
SolidityContract contr = bc.submitNewContract(
"contract Simple {" +
" uint public n;" +
" function set(uint _n) { n = _n; } " +
"}");
Block b1 = bc.createBlock();
contr.callFunction("set", 0xaaaaaaaaaaaaL);
Block b2 = bc.createBlock();
contr.callFunction("set", 0xbbbbbbbbbbbbL);
Block b2_ = bc.createForkBlock(b1);
bc.createForkBlock(b2);
bc.createBlock();
bc.createBlock();
bc.createBlock();
bc.createBlock();
bc.createBlock();
bc.createBlock();
bc.createBlock();
Assert.assertEquals(BigInteger.valueOf(0xaaaaaaaaaaaaL), contr.callConstFunction("n")[0]);
}
@Test
public void storagePruneTest() throws Exception {
final int pruneCount = 3;
SystemProperties.getDefault().overrideParams(
"details.inmemory.storage.limit", "200",
"database.prune.enabled", "true",
"database.prune.maxDepth", "" + pruneCount);
StandaloneBlockchain bc = new StandaloneBlockchain();
BlockchainImpl blockchain = (BlockchainImpl) bc.getBlockchain();
// RepositoryImpl repository = (RepositoryImpl) blockchain.getRepository();
// HashMapDB storageDS = new HashMapDB();
// repository.getDetailsDataStore().setStorageDS(storageDS);
SolidityContract contr = bc.submitNewContract(
"contract Simple {" +
" uint public n;" +
" mapping(uint => uint) largeMap;" +
" function set(uint _n) { n = _n; } " +
" function put(uint k, uint v) { largeMap[k] = v; }" +
"}");
Block b1 = bc.createBlock();
int entriesForExtStorage = 100;
for (int i = 0; i < entriesForExtStorage; i++) {
contr.callFunction("put", i, i);
if (i % 100 == 0) bc.createBlock();
}
bc.createBlock();
blockchain.flush();
contr.callFunction("put", 1000000, 1);
bc.createBlock();
blockchain.flush();
for (int i = 0; i < 100; i++) {
contr.callFunction("set", i);
bc.createBlock();
blockchain.flush();
System.out.println(bc.getStateDS().getStorage().size() + ", " + bc.getStateDS().getStorage().size());
}
System.out.println("Done");
}
@Ignore
@Test
public void rewriteSameTrieNode() throws Exception {
final int pruneCount = 3;
SystemProperties.getDefault().overrideParams(
"database.prune.enabled", "true",
"database.prune.maxDepth", "" + pruneCount);
StandaloneBlockchain bc = new StandaloneBlockchain();
byte[] receiver = Hex.decode("0000000000000000000000000000000000000000");
bc.sendEther(receiver, BigInteger.valueOf(0x77777777));
bc.createBlock();
for (int i = 0; i < 100; i++) {
bc.sendEther(new ECKey().getAddress(), BigInteger.valueOf(i));
}
SolidityContract contr = bc.submitNewContract(
"contract Stupid {" +
" function wrongAddress() { " +
" address addr = 0x0000000000000000000000000000000000000000; " +
" addr.call();" +
" } " +
"}");
Block b1 = bc.createBlock();
contr.callFunction("wrongAddress");
Block b2 = bc.createBlock();
contr.callFunction("wrongAddress");
Block b3 = bc.createBlock();
Assert.assertEquals(BigInteger.valueOf(0xaaaaaaaaaaaaL), contr.callConstFunction("n")[0]);
}
public void checkPruning(final HashMapDB<byte[]> stateDS, final Source<byte[], byte[]> stateJournalDS, byte[] ... roots) {
System.out.println("Pruned storage size: " + stateDS.getStorage().size());
Set<ByteArrayWrapper> allRefs = new HashSet<>();
for (byte[] root : roots) {
Set<ByteArrayWrapper> bRefs = getReferencedTrieNodes(stateJournalDS, true, root);
System.out.println("#" + Hex.toHexString(root).substring(0,8) + " refs: ");
for (ByteArrayWrapper bRef : bRefs) {
System.out.println(" " + bRef.toString().substring(0, 8));
}
allRefs.addAll(bRefs);
}
System.out.println("Trie nodes closure size: " + allRefs.size());
if (allRefs.size() != stateDS.getStorage().size()) {
for (byte[] hash : stateDS.getStorage().keySet()) {
if (!allRefs.contains(new ByteArrayWrapper(hash))) {
System.out.println("Extra node: " + Hex.toHexString(hash));
}
}
// Assert.assertEquals(allRefs.size(), stateDS.getStorage().size());
}
for (byte[] key : stateDS.getStorage().keySet()) {
// Assert.assertTrue(allRefs.contains(new ByteArrayWrapper(key)));
}
}
public Set<ByteArrayWrapper> getReferencedTrieNodes(final Source<byte[], byte[]> stateDS, final boolean includeAccounts,
byte[] ... roots) {
final Set<ByteArrayWrapper> ret = new HashSet<>();
for (byte[] root : roots) {
SecureTrie trie = new SecureTrie(stateDS, root);
trie.scanTree(new TrieImpl.ScanAction() {
@Override
public void doOnNode(byte[] hash, TrieImpl.Node node) {
ret.add(new ByteArrayWrapper(hash));
}
@Override
public void doOnValue(byte[] nodeHash, TrieImpl.Node node, byte[] key, byte[] value) {
if (includeAccounts) {
AccountState accountState = new AccountState(value);
if (!FastByteComparisons.equal(accountState.getCodeHash(), HashUtil.EMPTY_DATA_HASH)) {
ret.add(new ByteArrayWrapper(accountState.getCodeHash()));
}
if (!FastByteComparisons.equal(accountState.getStateRoot(), HashUtil.EMPTY_TRIE_HASH)) {
NodeKeyCompositor nodeKeyCompositor = new NodeKeyCompositor(key);
ret.addAll(getReferencedTrieNodes(new SourceCodec.KeyOnly<>(stateDS, nodeKeyCompositor), false, accountState.getStateRoot()));
}
}
}
});
}
return ret;
}
public String dumpState(final Source<byte[], byte[]> stateDS, final boolean includeAccounts,
byte[] root) {
final StringBuilder ret = new StringBuilder();
SecureTrie trie = new SecureTrie(stateDS, root);
trie.scanTree(new TrieImpl.ScanAction() {
@Override
public void doOnNode(byte[] hash, TrieImpl.Node node) {
}
@Override
public void doOnValue(byte[] nodeHash, TrieImpl.Node node, byte[] key, byte[] value) {
if (includeAccounts) {
AccountState accountState = new AccountState(value);
ret.append(Hex.toHexString(nodeHash) + ": Account: " + Hex.toHexString(key) + ", Nonce: " + accountState.getNonce() + ", Balance: " + accountState.getBalance() + "\n");
if (!FastByteComparisons.equal(accountState.getCodeHash(), HashUtil.EMPTY_DATA_HASH)) {
ret.append(" CodeHash: " + Hex.toHexString(accountState.getCodeHash()) + "\n");
}
if (!FastByteComparisons.equal(accountState.getStateRoot(), HashUtil.EMPTY_TRIE_HASH)) {
NodeKeyCompositor nodeKeyCompositor = new NodeKeyCompositor(key);
ret.append(dumpState(new SourceCodec.KeyOnly<>(stateDS, nodeKeyCompositor), false, accountState.getStateRoot()));
}
} else {
ret.append(" " + Hex.toHexString(nodeHash) + ": " + Hex.toHexString(key) + " = " + Hex.toHexString(value) + "\n");
}
}
});
return ret.toString();
}
}
| 25,182
| 42.19554
| 188
|
java
|
ethereumj
|
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/core/CloseTest.java
|
/*
* Copyright (c) [2016] [ <ether.camp> ]
* This file is part of the ethereumJ library.
*
* The ethereumJ library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The ethereumJ library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the ethereumJ library. If not, see <http://www.gnu.org/licenses/>.
*/
package org.ethereum.core;
import org.ethereum.facade.Ethereum;
import org.ethereum.facade.EthereumFactory;
import org.ethereum.listener.EthereumListenerAdapter;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import java.util.List;
import java.util.concurrent.CountDownLatch;
/**
* Created by Anton Nashatyrev on 24.06.2016.
*/
public class CloseTest {
@Ignore
@Test
public void relaunchTest() throws InterruptedException {
while (true) {
Ethereum ethereum = EthereumFactory.createEthereum();
Block bestBlock = ethereum.getBlockchain().getBestBlock();
Assert.assertNotNull(bestBlock);
final CountDownLatch latch = new CountDownLatch(1);
ethereum.addListener(new EthereumListenerAdapter() {
int counter = 0;
@Override
public void onBlock(Block block, List<TransactionReceipt> receipts) {
counter++;
if (counter > 1100) latch.countDown();
}
});
System.out.println("### Waiting for some blocks to be imported...");
latch.await();
System.out.println("### Closing Ethereum instance");
ethereum.close();
Thread.sleep(5000);
System.out.println("### Closed.");
}
}
}
| 2,162
| 34.459016
| 85
|
java
|
ethereumj
|
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/core/TransactionTest.java
|
/*
* Copyright (c) [2016] [ <ether.camp> ]
* This file is part of the ethereumJ library.
*
* The ethereumJ library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The ethereumJ library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the ethereumJ library. If not, see <http://www.gnu.org/licenses/>.
*/
package org.ethereum.core;
import org.ethereum.config.SystemProperties;
import org.ethereum.config.blockchain.HomesteadConfig;
import org.ethereum.config.net.MainNetConfig;
import org.ethereum.core.genesis.GenesisLoader;
import org.ethereum.crypto.ECKey;
import org.ethereum.crypto.ECKey.MissingPrivateKeyException;
import org.ethereum.crypto.HashUtil;
import org.ethereum.db.BlockStoreDummy;
import org.ethereum.jsontestsuite.suite.StateTestSuite;
import org.ethereum.jsontestsuite.suite.runners.StateTestRunner;
import org.ethereum.solidity.compiler.CompilationResult;
import org.ethereum.solidity.compiler.SolidityCompiler;
import org.ethereum.util.ByteUtil;
import org.ethereum.vm.LogInfo;
import org.ethereum.vm.program.ProgramResult;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.spongycastle.util.BigIntegers;
import org.spongycastle.util.encoders.Hex;
import java.io.IOException;
import java.math.BigInteger;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.ethereum.solidity.SolidityType.*;
import static org.slf4j.LoggerFactory.getLogger;
public class TransactionTest {
private final static Logger logger = getLogger(TransactionTest.class);
@Test /* sign transaction https://tools.ietf.org/html/rfc6979 */
public void test1() throws NoSuchProviderException, NoSuchAlgorithmException, InvalidKeyException, IOException {
//python taken exact data
String txRLPRawData = "a9e880872386f26fc1000085e8d4a510008203e89413978aee95f38490e9769c39b2773ed763d9cd5f80";
// String txRLPRawData = "f82804881bc16d674ec8000094cd2a3d9f938e13cd947ec05abc7fe734df8dd8268609184e72a0006480";
byte[] cowPrivKey = Hex.decode("c85ef7d79691fe79573b1a7064c19c1a9819ebdbd1faaab1a8ec92344438aaf4");
ECKey key = ECKey.fromPrivate(cowPrivKey);
byte[] data = Hex.decode(txRLPRawData);
// step 1: serialize + RLP encode
// step 2: hash = keccak(step1)
byte[] txHash = HashUtil.sha3(data);
String signature = key.doSign(txHash).toBase64();
logger.info(signature);
}
@Ignore
@Test /* achieve public key of the sender */
public void test2() throws Exception {
// cat --> 79b08ad8787060333663d19704909ee7b1903e58
// cow --> cd2a3d9f938e13cd947ec05abc7fe734df8dd826
BigInteger value = new BigInteger("1000000000000000000000");
byte[] privKey = HashUtil.sha3("cat".getBytes());
ECKey ecKey = ECKey.fromPrivate(privKey);
byte[] senderPrivKey = HashUtil.sha3("cow".getBytes());
byte[] gasPrice = Hex.decode("09184e72a000");
byte[] gas = Hex.decode("4255");
// Tn (nonce); Tp(pgas); Tg(gaslimi); Tt(value); Tv(value); Ti(sender); Tw; Tr; Ts
Transaction tx = new Transaction(null, gasPrice, gas, ecKey.getAddress(),
value.toByteArray(),
null);
tx.sign(ECKey.fromPrivate(senderPrivKey));
logger.info("v\t\t\t: " + Hex.toHexString(new byte[]{tx.getSignature().v}));
logger.info("r\t\t\t: " + Hex.toHexString(BigIntegers.asUnsignedByteArray(tx.getSignature().r)));
logger.info("s\t\t\t: " + Hex.toHexString(BigIntegers.asUnsignedByteArray(tx.getSignature().s)));
logger.info("RLP encoded tx\t\t: " + Hex.toHexString(tx.getEncoded()));
// retrieve the signer/sender of the transaction
ECKey key = ECKey.signatureToKey(tx.getHash(), tx.getSignature());
logger.info("Tx unsigned RLP\t\t: " + Hex.toHexString(tx.getEncodedRaw()));
logger.info("Tx signed RLP\t\t: " + Hex.toHexString(tx.getEncoded()));
logger.info("Signature public key\t: " + Hex.toHexString(key.getPubKey()));
logger.info("Sender is\t\t: " + Hex.toHexString(key.getAddress()));
assertEquals("cd2a3d9f938e13cd947ec05abc7fe734df8dd826",
Hex.toHexString(key.getAddress()));
logger.info(tx.toString());
}
@Ignore
@Test /* achieve public key of the sender nonce: 01 */
public void test3() throws Exception {
// cat --> 79b08ad8787060333663d19704909ee7b1903e58
// cow --> cd2a3d9f938e13cd947ec05abc7fe734df8dd826
ECKey ecKey = ECKey.fromPrivate(HashUtil.sha3("cat".getBytes()));
byte[] senderPrivKey = HashUtil.sha3("cow".getBytes());
byte[] nonce = {0x01};
byte[] gasPrice = Hex.decode("09184e72a000");
byte[] gasLimit = Hex.decode("4255");
BigInteger value = new BigInteger("1000000000000000000000000");
Transaction tx = new Transaction(nonce, gasPrice, gasLimit,
ecKey.getAddress(), value.toByteArray(), null);
tx.sign(ECKey.fromPrivate(senderPrivKey));
logger.info("v\t\t\t: " + Hex.toHexString(new byte[]{tx.getSignature().v}));
logger.info("r\t\t\t: " + Hex.toHexString(BigIntegers.asUnsignedByteArray(tx.getSignature().r)));
logger.info("s\t\t\t: " + Hex.toHexString(BigIntegers.asUnsignedByteArray(tx.getSignature().s)));
logger.info("RLP encoded tx\t\t: " + Hex.toHexString(tx.getEncoded()));
// retrieve the signer/sender of the transaction
ECKey key = ECKey.signatureToKey(tx.getHash(), tx.getSignature());
logger.info("Tx unsigned RLP\t\t: " + Hex.toHexString(tx.getEncodedRaw()));
logger.info("Tx signed RLP\t\t: " + Hex.toHexString(tx.getEncoded()));
logger.info("Signature public key\t: " + Hex.toHexString(key.getPubKey()));
logger.info("Sender is\t\t: " + Hex.toHexString(key.getAddress()));
assertEquals("cd2a3d9f938e13cd947ec05abc7fe734df8dd826",
Hex.toHexString(key.getAddress()));
}
// Testdata from: https://github.com/ethereum/tests/blob/master/txtest.json
String RLP_ENCODED_RAW_TX = "e88085e8d4a510008227109413978aee95f38490e9769c39b2773ed763d9cd5f872386f26fc1000080";
String RLP_ENCODED_UNSIGNED_TX = "eb8085e8d4a510008227109413978aee95f38490e9769c39b2773ed763d9cd5f872386f26fc1000080808080";
String HASH_TX = "328ea6d24659dec48adea1aced9a136e5ebdf40258db30d1b1d97ed2b74be34e";
String RLP_ENCODED_SIGNED_TX = "f86b8085e8d4a510008227109413978aee95f38490e9769c39b2773ed763d9cd5f872386f26fc10000801ba0eab47c1a49bf2fe5d40e01d313900e19ca485867d462fe06e139e3a536c6d4f4a014a569d327dcda4b29f74f93c0e9729d2f49ad726e703f9cd90dbb0fbf6649f1";
String KEY = "c85ef7d79691fe79573b1a7064c19c1a9819ebdbd1faaab1a8ec92344438aaf4";
byte[] testNonce = Hex.decode("");
byte[] testGasPrice = BigIntegers.asUnsignedByteArray(BigInteger.valueOf(1000000000000L));
byte[] testGasLimit = BigIntegers.asUnsignedByteArray(BigInteger.valueOf(10000));
byte[] testReceiveAddress = Hex.decode("13978aee95f38490e9769c39b2773ed763d9cd5f");
byte[] testValue = BigIntegers.asUnsignedByteArray(BigInteger.valueOf(10000000000000000L));
byte[] testData = Hex.decode("");
byte[] testInit = Hex.decode("");
@Ignore
@Test
public void testTransactionFromSignedRLP() throws Exception {
Transaction txSigned = new Transaction(Hex.decode(RLP_ENCODED_SIGNED_TX));
assertEquals(HASH_TX, Hex.toHexString(txSigned.getHash()));
assertEquals(RLP_ENCODED_SIGNED_TX, Hex.toHexString(txSigned.getEncoded()));
assertEquals(BigInteger.ZERO, new BigInteger(1, txSigned.getNonce()));
assertEquals(new BigInteger(1, testGasPrice), new BigInteger(1, txSigned.getGasPrice()));
assertEquals(new BigInteger(1, testGasLimit), new BigInteger(1, txSigned.getGasLimit()));
assertEquals(Hex.toHexString(testReceiveAddress), Hex.toHexString(txSigned.getReceiveAddress()));
assertEquals(new BigInteger(1, testValue), new BigInteger(1, txSigned.getValue()));
assertNull(txSigned.getData());
assertEquals(27, txSigned.getSignature().v);
assertEquals("eab47c1a49bf2fe5d40e01d313900e19ca485867d462fe06e139e3a536c6d4f4", Hex.toHexString(BigIntegers.asUnsignedByteArray(txSigned.getSignature().r)));
assertEquals("14a569d327dcda4b29f74f93c0e9729d2f49ad726e703f9cd90dbb0fbf6649f1", Hex.toHexString(BigIntegers.asUnsignedByteArray(txSigned.getSignature().s)));
}
@Ignore
@Test
public void testTransactionFromUnsignedRLP() throws Exception {
Transaction txUnsigned = new Transaction(Hex.decode(RLP_ENCODED_UNSIGNED_TX));
assertEquals(HASH_TX, Hex.toHexString(txUnsigned.getHash()));
assertEquals(RLP_ENCODED_UNSIGNED_TX, Hex.toHexString(txUnsigned.getEncoded()));
txUnsigned.sign(ECKey.fromPrivate(Hex.decode(KEY)));
assertEquals(RLP_ENCODED_SIGNED_TX, Hex.toHexString(txUnsigned.getEncoded()));
assertEquals(BigInteger.ZERO, new BigInteger(1, txUnsigned.getNonce()));
assertEquals(new BigInteger(1, testGasPrice), new BigInteger(1, txUnsigned.getGasPrice()));
assertEquals(new BigInteger(1, testGasLimit), new BigInteger(1, txUnsigned.getGasLimit()));
assertEquals(Hex.toHexString(testReceiveAddress), Hex.toHexString(txUnsigned.getReceiveAddress()));
assertEquals(new BigInteger(1, testValue), new BigInteger(1, txUnsigned.getValue()));
assertNull(txUnsigned.getData());
assertEquals(27, txUnsigned.getSignature().v);
assertEquals("eab47c1a49bf2fe5d40e01d313900e19ca485867d462fe06e139e3a536c6d4f4", Hex.toHexString(BigIntegers.asUnsignedByteArray(txUnsigned.getSignature().r)));
assertEquals("14a569d327dcda4b29f74f93c0e9729d2f49ad726e703f9cd90dbb0fbf6649f1", Hex.toHexString(BigIntegers.asUnsignedByteArray(txUnsigned.getSignature().s)));
}
@Ignore
@Test
public void testTransactionFromNew1() throws MissingPrivateKeyException {
Transaction txNew = new Transaction(testNonce, testGasPrice, testGasLimit, testReceiveAddress, testValue, testData);
assertEquals("", Hex.toHexString(txNew.getNonce()));
assertEquals(new BigInteger(1, testGasPrice), new BigInteger(1, txNew.getGasPrice()));
assertEquals(new BigInteger(1, testGasLimit), new BigInteger(1, txNew.getGasLimit()));
assertEquals(Hex.toHexString(testReceiveAddress), Hex.toHexString(txNew.getReceiveAddress()));
assertEquals(new BigInteger(1, testValue), new BigInteger(1, txNew.getValue()));
assertEquals("", Hex.toHexString(txNew.getData()));
assertNull(txNew.getSignature());
assertEquals(RLP_ENCODED_RAW_TX, Hex.toHexString(txNew.getEncodedRaw()));
assertEquals(HASH_TX, Hex.toHexString(txNew.getHash()));
assertEquals(RLP_ENCODED_UNSIGNED_TX, Hex.toHexString(txNew.getEncoded()));
txNew.sign(ECKey.fromPrivate(Hex.decode(KEY)));
assertEquals(RLP_ENCODED_SIGNED_TX, Hex.toHexString(txNew.getEncoded()));
assertEquals(27, txNew.getSignature().v);
assertEquals("eab47c1a49bf2fe5d40e01d313900e19ca485867d462fe06e139e3a536c6d4f4", Hex.toHexString(BigIntegers.asUnsignedByteArray(txNew.getSignature().r)));
assertEquals("14a569d327dcda4b29f74f93c0e9729d2f49ad726e703f9cd90dbb0fbf6649f1", Hex.toHexString(BigIntegers.asUnsignedByteArray(txNew.getSignature().s)));
}
@Ignore
@Test
public void testTransactionFromNew2() throws MissingPrivateKeyException {
byte[] privKeyBytes = Hex.decode("c85ef7d79691fe79573b1a7064c19c1a9819ebdbd1faaab1a8ec92344438aaf4");
String RLP_TX_UNSIGNED = "eb8085e8d4a510008227109413978aee95f38490e9769c39b2773ed763d9cd5f872386f26fc1000080808080";
String RLP_TX_SIGNED = "f86b8085e8d4a510008227109413978aee95f38490e9769c39b2773ed763d9cd5f872386f26fc10000801ba0eab47c1a49bf2fe5d40e01d313900e19ca485867d462fe06e139e3a536c6d4f4a014a569d327dcda4b29f74f93c0e9729d2f49ad726e703f9cd90dbb0fbf6649f1";
String HASH_TX_UNSIGNED = "328ea6d24659dec48adea1aced9a136e5ebdf40258db30d1b1d97ed2b74be34e";
byte[] nonce = BigIntegers.asUnsignedByteArray(BigInteger.ZERO);
byte[] gasPrice = Hex.decode("e8d4a51000"); // 1000000000000
byte[] gas = Hex.decode("2710"); // 10000
byte[] recieveAddress = Hex.decode("13978aee95f38490e9769c39b2773ed763d9cd5f");
byte[] value = Hex.decode("2386f26fc10000"); //10000000000000000"
byte[] data = new byte[0];
Transaction tx = new Transaction(nonce, gasPrice, gas, recieveAddress, value, data);
// Testing unsigned
String encodedUnsigned = Hex.toHexString(tx.getEncoded());
assertEquals(RLP_TX_UNSIGNED, encodedUnsigned);
assertEquals(HASH_TX_UNSIGNED, Hex.toHexString(tx.getHash()));
// Testing signed
tx.sign(ECKey.fromPrivate(privKeyBytes));
String encodedSigned = Hex.toHexString(tx.getEncoded());
assertEquals(RLP_TX_SIGNED, encodedSigned);
assertEquals(HASH_TX_UNSIGNED, Hex.toHexString(tx.getHash()));
}
@Test
public void testTransactionCreateContract() {
// String rlp =
// "f89f808609184e72a0008203e8808203e8b84b4560005444602054600f60056002600a02010b0d630000001d596002602054630000003b5860066000530860056006600202010a0d6300000036596004604054630000003b5860056060541ca0ddc901d83110ea50bc40803f42083afea1bbd420548f6392a679af8e24b21345a06620b3b512bea5f0a272703e8d6933177c23afc79516fd0ca4a204aa6e34c7e9";
byte[] senderPrivKey = HashUtil.sha3("cow".getBytes());
byte[] nonce = BigIntegers.asUnsignedByteArray(BigInteger.ZERO);
byte[] gasPrice = Hex.decode("09184e72a000"); // 10000000000000
byte[] gas = Hex.decode("03e8"); // 1000
byte[] recieveAddress = null;
byte[] endowment = Hex.decode("03e8"); //10000000000000000"
byte[] init = Hex.decode
("4560005444602054600f60056002600a02010b0d630000001d596002602054630000003b5860066000530860056006600202010a0d6300000036596004604054630000003b586005606054");
Transaction tx1 = new Transaction(nonce, gasPrice, gas,
recieveAddress, endowment, init);
tx1.sign(ECKey.fromPrivate(senderPrivKey));
byte[] payload = tx1.getEncoded();
logger.info(Hex.toHexString(payload));
Transaction tx2 = new Transaction(payload);
// tx2.getSender();
String plainTx1 = Hex.toHexString(tx1.getEncodedRaw());
String plainTx2 = Hex.toHexString(tx2.getEncodedRaw());
// Transaction tx = new Transaction(Hex.decode(rlp));
logger.info("tx1.hash: " + Hex.toHexString(tx1.getHash()));
logger.info("tx2.hash: " + Hex.toHexString(tx2.getHash()));
logger.info("");
logger.info("plainTx1: " + plainTx1);
logger.info("plainTx2: " + plainTx2);
logger.info(Hex.toHexString(tx2.getSender()));
}
@Ignore
@Test
public void encodeReceiptTest() {
String data = "f90244a0f5ff3fbd159773816a7c707a9b8cb6bb778b934a8f6466c7830ed970498f4b688301e848b902000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000dbda94cd2a3d9f938e13cd947ec05abc7fe734df8dd826c083a1a1a1";
byte[] stateRoot = Hex.decode("f5ff3fbd159773816a7c707a9b8cb6bb778b934a8f6466c7830ed970498f4b68");
byte[] gasUsed = Hex.decode("01E848");
Bloom bloom = new Bloom(Hex.decode("0000000000000000800000000000000004000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"));
LogInfo logInfo1 = new LogInfo(
Hex.decode("cd2a3d9f938e13cd947ec05abc7fe734df8dd826"),
null,
Hex.decode("a1a1a1")
);
List<LogInfo> logs = new ArrayList<>();
logs.add(logInfo1);
// TODO calculate cumulative gas
TransactionReceipt receipt = new TransactionReceipt(stateRoot, gasUsed, bloom, logs);
assertEquals(data,
Hex.toHexString(receipt.getEncoded()));
}
@Test
public void constantCallConflictTest() throws Exception {
/*
0x095e7baea6a6c7c4c2dfeb977efac326af552d87 contract is the following Solidity code:
contract Test {
uint a = 256;
function set(uint s) {
a = s;
}
function get() returns (uint) {
return a;
}
}
*/
String json = "{ " +
" 'test1' : { " +
" 'env' : { " +
" 'currentCoinbase' : '2adc25665018aa1fe0e6bc666dac8fc2697ff9ba', " +
" 'currentDifficulty' : '0x0100', " +
" 'currentGasLimit' : '0x0f4240', " +
" 'currentNumber' : '0x00', " +
" 'currentTimestamp' : '0x01', " +
" 'previousHash' : '5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6' " +
" }, " +
" 'logs' : [ " +
" ], " +
" 'out' : '0x', " +
" 'post' : { " +
" '095e7baea6a6c7c4c2dfeb977efac326af552d87' : { " +
" 'balance' : '0x0de0b6b3a76586a0', " +
" 'code' : '0x606060405260e060020a600035046360fe47b1811460245780636d4ce63c14602e575b005b6004356000556022565b6000546060908152602090f3', " +
" 'nonce' : '0x00', " +
" 'storage' : { " +
" '0x00' : '0x0400' " +
" } " +
" }, " +
" '2adc25665018aa1fe0e6bc666dac8fc2697ff9ba' : { " +
" 'balance' : '0x67c3', " +
" 'code' : '0x', " +
" 'nonce' : '0x00', " +
" 'storage' : { " +
" } " +
" }, " +
" 'a94f5374fce5edbc8e2a8697c15331677e6ebf0b' : { " +
" 'balance' : '0x0DE0B6B3A762119D', " +
" 'code' : '0x', " +
" 'nonce' : '0x01', " +
" 'storage' : { " +
" } " +
" } " +
" }, " +
" 'postStateRoot' : '17454a767e5f04461256f3812ffca930443c04a47d05ce3f38940c4a14b8c479', " +
" 'pre' : { " +
" '095e7baea6a6c7c4c2dfeb977efac326af552d87' : { " +
" 'balance' : '0x0de0b6b3a7640000', " +
" 'code' : '0x606060405260e060020a600035046360fe47b1811460245780636d4ce63c14602e575b005b6004356000556022565b6000546060908152602090f3', " +
" 'nonce' : '0x00', " +
" 'storage' : { " +
" '0x00' : '0x02' " +
" } " +
" }, " +
" 'a94f5374fce5edbc8e2a8697c15331677e6ebf0b' : { " +
" 'balance' : '0x0de0b6b3a7640000', " +
" 'code' : '0x', " +
" 'nonce' : '0x00', " +
" 'storage' : { " +
" } " +
" } " +
" }, " +
" 'transaction' : { " +
" 'data' : '0x60fe47b10000000000000000000000000000000000000000000000000000000000000400', " +
" 'gasLimit' : '0x061a80', " +
" 'gasPrice' : '0x01', " +
" 'nonce' : '0x00', " +
" 'secretKey' : '45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8', " +
" 'to' : '095e7baea6a6c7c4c2dfeb977efac326af552d87', " +
" 'value' : '0x0186a0' " +
" } " +
" } " +
"}";
StateTestSuite stateTestSuite = new StateTestSuite(json.replaceAll("'", "\""));
List<String> res = new StateTestRunner(stateTestSuite.getTestCases().get("test1")) {
@Override
protected ProgramResult executeTransaction(Transaction tx) {
// first emulating the constant call (Ethereum.callConstantFunction)
// to ensure it doesn't affect the final state
{
Repository track = repository.startTracking();
Transaction txConst = CallTransaction.createCallTransaction(0, 0, 100000000000000L,
"095e7baea6a6c7c4c2dfeb977efac326af552d87", 0, CallTransaction.Function.fromSignature("get"));
txConst.sign(new ECKey());
Block bestBlock = block;
TransactionExecutor executor = new TransactionExecutor
(txConst, bestBlock.getCoinbase(), track, new BlockStoreDummy(),
invokeFactory, bestBlock)
.setLocalCall(true);
executor.init();
executor.execute();
executor.go();
executor.finalization();
track.rollback();
logger.info("Return value: " + new IntType("uint").decode(executor.getResult().getHReturn()));
}
// now executing the JSON test transaction
return super.executeTransaction(tx);
}
}.runImpl();
if (!res.isEmpty()) throw new RuntimeException("Test failed: " + res);
}
@Test
public void homesteadContractCreationTest() throws Exception {
// Checks Homestead updates (1) & (3) from
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-2.mediawiki
/*
trying to create a contract with the following Solidity code:
contract Test {
uint a = 256;
function set(uint s) {
a = s;
}
function get() returns (uint) {
return a;
}
}
*/
int iBitLowGas = 0x015f84; // [actual gas required] - 1
String aBitLowGas = "0x0" + Integer.toHexString(iBitLowGas);
String senderPostBalance = "0x0" + Long.toHexString(1000000000000000000L - iBitLowGas);
String json = "{ " +
" 'test1' : { " +
" 'env' : { " +
" 'currentCoinbase' : '2adc25665018aa1fe0e6bc666dac8fc2697ff9ba', " +
" 'currentDifficulty' : '0x0100', " +
" 'currentGasLimit' : '0x0f4240', " +
" 'currentNumber' : '0x01', " +
" 'currentTimestamp' : '0x01', " +
" 'previousHash' : '5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6' " +
" }, " +
" 'logs' : [ " +
" ], " +
" 'out' : '0x', " +
" 'post' : { " +
" '2adc25665018aa1fe0e6bc666dac8fc2697ff9ba' : { " +
" 'balance' : '" + aBitLowGas + "', " +
" 'code' : '0x', " +
" 'nonce' : '0x00', " +
" 'storage' : { " +
" } " +
" }," +
" 'a94f5374fce5edbc8e2a8697c15331677e6ebf0b' : { " +
" 'balance' : '" + senderPostBalance + "', " +
" 'code' : '0x', " +
" 'nonce' : '0x01', " +
" 'storage' : { " +
" } " +
" } " +
" }, " +
" 'postStateRoot' : '17454a767e5f04461256f3812ffca930443c04a47d05ce3f38940c4a14b8c479', " +
" 'pre' : { " +
" 'a94f5374fce5edbc8e2a8697c15331677e6ebf0b' : { " +
" 'balance' : '0x0de0b6b3a7640000', " +
" 'code' : '0x', " +
" 'nonce' : '0x00', " +
" 'storage' : { " +
" } " +
" } " +
" }, " +
" 'transaction' : { " +
" 'data' : '0x6060604052610100600060005055603b8060196000396000f3606060405260e060020a600035046360fe47b1811460245780636d4ce63c14602e575b005b6004356000556022565b6000546060908152602090f3', " +
" 'gasLimit' : '" + aBitLowGas + "', " +
" 'gasPrice' : '0x01', " +
" 'nonce' : '0x00', " +
" 'secretKey' : '45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8', " +
" 'to' : '', " +
" 'value' : '0x0' " +
" } " +
" } " +
"}";
StateTestSuite stateTestSuite = new StateTestSuite(json.replaceAll("'", "\""));
logger.info(json.replaceAll("'", "\""));
try {
SystemProperties.getDefault().setBlockchainConfig(new HomesteadConfig());
List<String> res = new StateTestRunner(stateTestSuite.getTestCases().get("test1")).runImpl();
if (!res.isEmpty()) throw new RuntimeException("Test failed: " + res);
} finally {
SystemProperties.getDefault().setBlockchainConfig(MainNetConfig.INSTANCE);
}
}
@Test
public void multiSuicideTest() throws IOException, InterruptedException {
String contract =
"pragma solidity ^0.4.3;" +
"contract PsychoKiller {" +
" function () payable {}" +
" function homicide() {" +
" suicide(msg.sender);" +
" }" +
" function multipleHomocide() {" +
" PsychoKiller k = this;" +
" k.homicide.gas(10000)();" +
" k.homicide.gas(10000)();" +
" k.homicide.gas(10000)();" +
" k.homicide.gas(10000)();" +
" }" +
"}";
SolidityCompiler.Result res = SolidityCompiler.compile(
contract.getBytes(), true, SolidityCompiler.Options.ABI, SolidityCompiler.Options.BIN);
logger.info(res.errors);
CompilationResult cres = CompilationResult.parse(res.output);
BlockchainImpl blockchain = ImportLightTest.createBlockchain(GenesisLoader.loadGenesis(
getClass().getResourceAsStream("/genesis/genesis-light.json")));
ECKey sender = ECKey.fromPrivate(Hex.decode("3ec771c31cac8c0dba77a69e503765701d3c2bb62435888d4ffa38fed60c445c")).compress();
logger.info("address: " + Hex.toHexString(sender.getAddress()));
if (cres.getContract("PsychoKiller") != null) {
Transaction tx = createTx(blockchain, sender, new byte[0],
Hex.decode(cres.getContract("PsychoKiller").bin));
executeTransaction(blockchain, tx);
byte[] contractAddress = tx.getContractAddress();
CallTransaction.Contract contract1 = new CallTransaction.Contract(cres.getContract("PsychoKiller").abi);
byte[] callData = contract1.getByName("multipleHomocide").encode();
Transaction tx1 = createTx(blockchain, sender, contractAddress, callData, 0l);
ProgramResult programResult = executeTransaction(blockchain, tx1).getResult();
// suicide of a single account should be counted only once
Assert.assertEquals(24000, programResult.getFutureRefund());
} else {
Assert.fail();
}
}
@Test
public void receiptErrorTest() throws Exception {
BlockchainImpl blockchain = ImportLightTest.createBlockchain(GenesisLoader.loadGenesis(
getClass().getResourceAsStream("/genesis/genesis-light.json")));
ECKey sender = ECKey.fromPrivate(Hex.decode("3ec771c31cac8c0dba77a69e503765701d3c2bb62435888d4ffa38fed60c445c"));
{
// Receipt RLP backward compatibility
TransactionReceipt receipt = new TransactionReceipt(Hex.decode("f9010c80825208b9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c082520880"));
Assert.assertTrue(receipt.isValid());
Assert.assertTrue(receipt.isSuccessful());
}
{
Transaction tx = createTx(blockchain, sender, new byte[32], new byte[0], 100);
TransactionReceipt receipt = executeTransaction(blockchain, tx).getReceipt();
logger.info(Hex.toHexString(receipt.getEncoded()));
receipt = new TransactionReceipt(receipt.getEncoded());
Assert.assertTrue(receipt.isValid());
Assert.assertTrue(receipt.isSuccessful());
}
{
Transaction tx = createTx(blockchain, new ECKey(), new byte[32], new byte[0], 100);
TransactionReceipt receipt = executeTransaction(blockchain, tx).getReceipt();
receipt = new TransactionReceipt(receipt.getEncoded());
Assert.assertFalse(receipt.isValid());
Assert.assertFalse(receipt.isSuccessful());
Assert.assertTrue(receipt.getError().contains("Not enough"));
}
{
Transaction tx = new Transaction(
ByteUtil.intToBytesNoLeadZeroes(100500),
ByteUtil.longToBytesNoLeadZeroes(1),
ByteUtil.longToBytesNoLeadZeroes(3_000_000),
new byte[0],
ByteUtil.longToBytesNoLeadZeroes(0),
new byte[0]);
tx.sign(sender);
TransactionReceipt receipt = executeTransaction(blockchain, tx).getReceipt();
receipt = new TransactionReceipt(receipt.getEncoded());
Assert.assertFalse(receipt.isValid());
Assert.assertFalse(receipt.isSuccessful());
Assert.assertTrue(receipt.getError().contains("nonce"));
}
{
String contract =
"contract GasConsumer {" +
" function GasConsumer() {" +
" int i = 0;" +
" while(true) sha3(i++);" +
" }" +
"}";
SolidityCompiler.Result res = SolidityCompiler.compile(
contract.getBytes(), true, SolidityCompiler.Options.ABI, SolidityCompiler.Options.BIN);
logger.info(res.errors);
CompilationResult cres = CompilationResult.parse(res.output);
Transaction tx = createTx(blockchain, sender, new byte[0], Hex.decode(cres.getContract("GasConsumer").bin), 0);
TransactionReceipt receipt = executeTransaction(blockchain, tx).getReceipt();
receipt = new TransactionReceipt(receipt.getEncoded());
Assert.assertTrue(receipt.isValid());
Assert.assertFalse(receipt.isSuccessful());
Assert.assertTrue(receipt.getError().contains("Not enough gas"));
}
}
private Transaction createTx(BlockchainImpl blockchain, ECKey sender, byte[] receiveAddress, byte[] data) {
return createTx(blockchain, sender, receiveAddress, data, 0);
}
private Transaction createTx(BlockchainImpl blockchain, ECKey sender, byte[] receiveAddress,
byte[] data, long value) {
BigInteger nonce = blockchain.getRepository().getNonce(sender.getAddress());
Transaction tx = new Transaction(
ByteUtil.bigIntegerToBytes(nonce),
ByteUtil.longToBytesNoLeadZeroes(0),
ByteUtil.longToBytesNoLeadZeroes(3_000_000),
receiveAddress,
ByteUtil.longToBytesNoLeadZeroes(value),
data);
tx.sign(sender);
return tx;
}
private TransactionExecutor executeTransaction(BlockchainImpl blockchain, Transaction tx) {
Repository track = blockchain.getRepository().startTracking();
TransactionExecutor executor = new TransactionExecutor(tx, new byte[32], blockchain.getRepository(),
blockchain.getBlockStore(), blockchain.getProgramInvokeFactory(), blockchain.getBestBlock());
executor.init();
executor.execute();
executor.go();
executor.finalization();
track.commit();
return executor;
}
@Test
public void afterEIP158Test() throws Exception {
int chainId = 1;
String rlpUnsigned = "ec098504a817c800825208943535353535353535353535353535353535353535880de0b6b3a764000080018080";
String unsignedHash = "daf5a779ae972f972197303d7b574746c7ef83eadac0f2791ad23db92e4c8e53";
String privateKey = "4646464646464646464646464646464646464646464646464646464646464646";
BigInteger signatureR = new BigInteger("18515461264373351373200002665853028612451056578545711640558177340181847433846");
BigInteger signatureS = new BigInteger("46948507304638947509940763649030358759909902576025900602547168820602576006531");
String signedTxRlp = "f86c098504a817c800825208943535353535353535353535353535353535353535880de0b6b3a76400008025a028ef61340bd939bc2195fe537567866003e1a15d3c71ff63e1590620aa636276a067cbe9d8997f761aecb703304b3800ccf555c9f3dc64214b297fb1966a3b6d83";
Transaction tx = Transaction.create(
"3535353535353535353535353535353535353535",
new BigInteger("1000000000000000000"),
new BigInteger("9"),
new BigInteger("20000000000"),
new BigInteger("21000"),
chainId
);
// Checking RLP of unsigned transaction and its hash
assertArrayEquals(Hex.decode(rlpUnsigned), tx.getEncoded());
assertArrayEquals(Hex.decode(unsignedHash), tx.getHash());
assertNull(tx.getSignature());
ECKey ecKey = ECKey.fromPrivate(Hex.decode(privateKey));
tx.sign(ecKey);
// Checking modified signature
assertEquals(signatureR, tx.getSignature().r);
assertEquals(signatureS, tx.getSignature().s);
// TODO: Strange, it's still 27. Why is signature used for getEncoded() never assigned to signature field?
assertEquals(27, tx.getSignature().v);
// Checking that we get correct TX in the end
assertArrayEquals(Hex.decode(signedTxRlp), tx.getEncoded());
// Check that we could correctly extract tx from new RLP
Transaction txSigned = new Transaction(Hex.decode(signedTxRlp));
assertEquals((int)txSigned.getChainId(), chainId);
}
@Test
public void etcChainIdTest() {
Transaction tx = new Transaction(Hex.decode("f871830617428504a817c80083015f90940123286bd94beecd40905321f5c3202c7628d685880ecab7b2bae2c27080819ea021355678b1aa704f6ad4706fb8647f5125beadd1d84c6f9cf37dda1b62f24b1aa06b4a64fd29bb6e54a2c5107e8be42ac039a8ffb631e16e7bcbd15cdfc0015ee2"));
Integer chainId = tx.getChainId();
assertEquals(61, chainId.intValue());
}
@Test
public void longChainIdTest() {
Transaction tx = new Transaction(Hex.decode("f8ae82477b8504a817c80083015f9094977ddf44438d540892d1b8618fea65395399971680b844eceb6e3e57696e6454757262696e655f30310000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007827e19a025f55532f5cebec362f3f750a3b9c47ab76322622eb3a26ad24c80f9c388c15ba02dcc7ebcfb6ad6ae09f56a29d710cc4115e960a83b98405cf98f7177c14d8a51"));
Integer chainId = tx.getChainId();
assertEquals(16123, chainId.intValue());
Transaction tx1 = Transaction.create(
"3535353535353535353535353535353535353535",
new BigInteger("1000000000000000000"),
new BigInteger("9"),
new BigInteger("20000000000"),
new BigInteger("21000"),
333333
);
ECKey key = new ECKey();
tx1.sign(key);
Transaction tx2 = new Transaction(tx1.getEncoded());
assertEquals(333333, tx2.getChainId().intValue());
assertArrayEquals(tx2.getSender(), key.getAddress());
}
@Test
public void unsignedChainIdTransactionTest() {
byte[] rlpUnsignedTx = Hex.decode("ef098504a817c800825208943535353535353535353535353535353535353535880de0b6b3a764000080830516158080");
Transaction tx = new Transaction(rlpUnsignedTx);
assertEquals(333333, (long) tx.getChainId());
Transaction copyTx = new Transaction(tx.getNonce(), tx.getGasPrice(), tx.getGasLimit(), tx.getReceiveAddress(), tx.getValue(), tx.getData(), tx.getChainId());
assertArrayEquals(rlpUnsignedTx, copyTx.getEncoded());
}
}
| 40,705
| 50.461441
| 1,191
|
java
|
ethereumj
|
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/core/BlockchainGetHeadersTest.java
|
/*
* Copyright (c) [2016] [ <ether.camp> ]
* This file is part of the ethereumJ library.
*
* The ethereumJ library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The ethereumJ library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the ethereumJ library. If not, see <http://www.gnu.org/licenses/>.
*/
package org.ethereum.core;
import org.ethereum.datasource.inmem.HashMapDB;
import org.ethereum.db.RepositoryRoot;
import org.ethereum.db.BlockStoreDummy;
import org.junit.Test;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* Testing {@link BlockchainImpl#getListOfHeadersStartFrom(BlockIdentifier, int, int, boolean)}
*/
public class BlockchainGetHeadersTest {
private class BlockStoreMock extends BlockStoreDummy {
private List<Block> dummyBlocks = new ArrayList<>();
public BlockStoreMock() {
byte [] emptyArray = new byte[0];
byte [] recentHash = emptyArray;
for (long i = 0; i < 10; ++i) {
BlockHeader blockHeader = new BlockHeader(recentHash, emptyArray, emptyArray, emptyArray, emptyArray,
i, emptyArray, 0L, 0L, emptyArray, emptyArray, emptyArray);
recentHash = blockHeader.getHash();
Block block = new Block(blockHeader, new ArrayList<Transaction>(), new ArrayList<BlockHeader>());
dummyBlocks.add(block);
}
}
@Override
public Block getBlockByHash(byte[] hash) {
for (Block block: dummyBlocks) {
if (Arrays.equals(block.getHash(), hash)) {
return block;
}
}
return null;
}
@Override
public Block getChainBlockByNumber(long blockNumber) {
return blockNumber < dummyBlocks.size() ? dummyBlocks.get((int) blockNumber) : null;
}
@Override
public List<BlockHeader> getListHeadersEndWith(byte[] hash, long qty) {
List<BlockHeader> headers = new ArrayList<>();
Block start = getBlockByHash(hash);
if (start != null) {
long i = start.getNumber();
while (i >= 0 && headers.size() < qty) {
headers.add(getChainBlockByNumber(i).getHeader());
--i;
}
}
return headers;
}
@Override
public Block getBestBlock() {
return dummyBlocks.get(dummyBlocks.size() - 1);
}
}
private class BlockchainImplTester extends BlockchainImpl {
public BlockchainImplTester() {
blockStore = new BlockStoreMock();
setRepository(new RepositoryRoot(new HashMapDB<byte[]>()));
setBestBlock(blockStore.getChainBlockByNumber(9));
}
}
private BlockchainImpl blockchain;
public BlockchainGetHeadersTest() {
blockchain = new BlockchainImplTester();
}
@Test
public void singleHeader() {
// Get by number
long blockNumber = 2L;
BlockIdentifier identifier = new BlockIdentifier(null, blockNumber);
List<BlockHeader> headers = blockchain.getListOfHeadersStartFrom(identifier, 0, 1, false);
assert headers.size() == 1;
assert headers.get(0).getNumber() == blockNumber;
// Get by hash
byte[] hash = headers.get(0).getHash();
BlockIdentifier hashIdentifier = new BlockIdentifier(hash, 0L);
List<BlockHeader> headersByHash = blockchain.getListOfHeadersStartFrom(hashIdentifier, 0, 1, false);
assert headersByHash.size() == 1;
assert headersByHash.get(0).getNumber() == blockNumber;
// Reverse doesn't matter for single block
List<BlockHeader> headersReverse = blockchain.getListOfHeadersStartFrom(hashIdentifier, 0, 1, true);
assert headersReverse.size() == 1;
assert headersReverse.get(0).getNumber() == blockNumber;
// Skip doesn't matter for single block
List<BlockHeader> headersSkip = blockchain.getListOfHeadersStartFrom(hashIdentifier, 15, 1, false);
assert headersSkip.size() == 1;
assert headersSkip.get(0).getNumber() == blockNumber;
}
@Test
public void continuousHeaders() {
// Get by number
long blockNumber = 2L;
BlockIdentifier identifier = new BlockIdentifier(null, blockNumber);
List<BlockHeader> headers = blockchain.getListOfHeadersStartFrom(identifier, 0, 3, false);
assert headers.size() == 3;
assert headers.get(0).getNumber() == blockNumber;
assert headers.get(1).getNumber() == blockNumber + 1;
assert headers.get(2).getNumber() == blockNumber + 2;
List<BlockHeader> headersReverse = blockchain.getListOfHeadersStartFrom(identifier, 0, 3, true);
assert headersReverse.size() == 3;
assert headersReverse.get(0).getNumber() == blockNumber;
assert headersReverse.get(1).getNumber() == blockNumber - 1;
assert headersReverse.get(2).getNumber() == blockNumber - 2;
// Requesting more than we have
BlockIdentifier identifierMore = new BlockIdentifier(null, 8L);
List<BlockHeader> headersMore = blockchain.getListOfHeadersStartFrom(identifierMore, 0, 3, false);
assert headersMore.size() == 2;
assert headersMore.get(0).getNumber() == 8L;
assert headersMore.get(1).getNumber() == 9L;
}
@Test
public void gapedHeaders() {
int skip = 2;
BlockIdentifier identifier = new BlockIdentifier(null, 2L);
List<BlockHeader> headers = blockchain.getListOfHeadersStartFrom(identifier, skip, 3, false);
assert headers.size() == 3;
assert headers.get(0).getNumber() == 2L;
assert headers.get(1).getNumber() == 5L; // 2, [3, 4], 5 - skipping []
assert headers.get(2).getNumber() == 8L; // 5, [6, 7], 8 - skipping []
// Same for reverse
BlockIdentifier identifierReverse = new BlockIdentifier(null, 8L);
List<BlockHeader> headersReverse = blockchain.getListOfHeadersStartFrom(identifierReverse, skip, 3, true);
assert headersReverse.size() == 3;
assert headersReverse.get(0).getNumber() == 8L;
assert headersReverse.get(1).getNumber() == 5L;
assert headersReverse.get(2).getNumber() == 2L;
// Requesting more than we have
BlockIdentifier identifierMore = new BlockIdentifier(null, 8L);
List<BlockHeader> headersMore = blockchain.getListOfHeadersStartFrom(identifierMore, skip, 3, false);
assert headersMore.size() == 1;
assert headersMore.get(0).getNumber() == 8L;
}
@Test
public void closeToBounds() {
int skip = 1;
BlockIdentifier identifier = new BlockIdentifier(null, 2L);
List<BlockHeader> headers = blockchain.getListOfHeadersStartFrom(identifier, skip, 3, true);
assert headers.size() == 2;
assert headers.get(0).getNumber() == 2L;
assert headers.get(1).getNumber() == 0L;
BlockIdentifier identifier2 = new BlockIdentifier(null, 0L);
List<BlockHeader> headers2 = blockchain.getListOfHeadersStartFrom(identifier2, skip, 3, true);
assert headers2.size() == 1;
assert headers2.get(0).getNumber() == 0L;
BlockIdentifier identifier3 = new BlockIdentifier(null, 0L);
List<BlockHeader> headers3 = blockchain.getListOfHeadersStartFrom(identifier3, skip, 1, true);
assert headers3.size() == 1;
assert headers3.get(0).getNumber() == 0L;
BlockIdentifier identifier4 = new BlockIdentifier(null, blockchain.getBestBlock().getNumber());
List<BlockHeader> headers4 = blockchain.getListOfHeadersStartFrom(identifier4, skip, 3, false);
assert headers4.size() == 1;
assert headers4.get(0).getNumber() == blockchain.getBestBlock().getNumber();
BlockIdentifier identifier5 = new BlockIdentifier(null, blockchain.getBestBlock().getNumber() - 1);
List<BlockHeader> headers5 = blockchain.getListOfHeadersStartFrom(identifier5, 0, 3, false);
assert headers5.size() == 2;
assert headers5.get(0).getNumber() == blockchain.getBestBlock().getNumber() - 1;
assert headers5.get(1).getNumber() == blockchain.getBestBlock().getNumber();
}
}
| 8,839
| 38.81982
| 117
|
java
|
ethereumj
|
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/core/BlockTest.java
|
/*
* Copyright (c) [2016] [ <ether.camp> ]
* This file is part of the ethereumJ library.
*
* The ethereumJ library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The ethereumJ library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the ethereumJ library. If not, see <http://www.gnu.org/licenses/>.
*/
package org.ethereum.core;
import org.ethereum.config.SystemProperties;
import org.ethereum.core.genesis.GenesisLoader;
import org.ethereum.trie.SecureTrie;
import org.ethereum.trie.Trie;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import org.junit.*;
import org.junit.runners.MethodSorters;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.spongycastle.util.encoders.Hex;
import java.math.BigInteger;
import java.util.Collection;
import java.util.Set;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class BlockTest {
private static final Logger logger = LoggerFactory.getLogger("test");
// https://github.com/ethereum/tests/blob/71d80bd63aaf7cee523b6ca9d12a131698d41e98/BasicTests/genesishashestest.json
private String GENESIS_RLP = "f901f8f901f3a00000000000000000000000000000000000000000000000000000000000000000a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347940000000000000000000000000000000000000000a09178d0f23c965d81f0834a4c72c6253ce6830f4022b1359aaebfc1ecba442d4ea056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b90100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008302000080832fefd8808080a0000000000000000000000000000000000000000000000000000000000000000088000000000000002ac0c0";
private String GENESIS_HASH = "fd4af92a79c7fc2fd8bf0d342f2e832e1d4f485c85b9152d2039e03bc604fdca";
private String GENESIS_STATE_ROOT = "9178d0f23c965d81f0834a4c72c6253ce6830f4022b1359aaebfc1ecba442d4e";
private String MESSY_NONCE_GENESIS_RLP = "f901f8f901f3a00000000000000000000000000000000000000000000000000000000000000000a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347940000000000000000000000000000000000000000a0da3d5bd4c2f8443fbca1f12c0b9eaa4996825e9d32d239ffb302b8f98f202c97a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b90100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008301000080832fefd8808080a00000000000000000000000000000000000000000000000000000000000000000880000000000000000c0c0";
private String MESSY_NONCE_GENESIS_HASH = "b096cfdeb2a3c0abd3ce9f77cf5adc92a8cead34aa4d2be54c004373e3986788";
static String TEST_GENESIS =
"{" +
"'0000000000000000000000000000000000000001': { 'wei': '1' }" +
"'0000000000000000000000000000000000000002': { 'wei': '1' }" +
"'0000000000000000000000000000000000000003': { 'wei': '1' }" +
"'0000000000000000000000000000000000000004': { 'wei': '1' }" +
"'dbdbdb2cbd23b783741e8d7fcf51e459b497e4a6': { 'wei': '1606938044258990275541962092341162602522202993782792835301376' }" +
"'e6716f9544a56c530d868e4bfbacb172315bdead': { 'wei': '1606938044258990275541962092341162602522202993782792835301376' }" +
"'b9c015918bdaba24b4ff057a92a3873d6eb201be': { 'wei': '1606938044258990275541962092341162602522202993782792835301376' }" +
"'1a26338f0d905e295fccb71fa9ea849ffa12aaf4': { 'wei': '1606938044258990275541962092341162602522202993782792835301376' }" +
"'2ef47100e0787b915105fd5e3f4ff6752079d5cb': { 'wei': '1606938044258990275541962092341162602522202993782792835301376' }" +
"'cd2a3d9f938e13cd947ec05abc7fe734df8dd826': { 'wei': '1606938044258990275541962092341162602522202993782792835301376' }" +
"'6c386a4b26f73c802f34673f7248bb118f97424a': { 'wei': '1606938044258990275541962092341162602522202993782792835301376' }" +
"'e4157b34ea9615cfbde6b4fda419828124b70c78': { 'wei': '1606938044258990275541962092341162602522202993782792835301376' }" +
"}";
static {
TEST_GENESIS = TEST_GENESIS.replace("'", "\"");
}
@Test
public void testGenesisFromRLP() {
// from RLP encoding
byte[] genesisBytes = Hex.decode(GENESIS_RLP);
Block genesisFromRLP = new Block(genesisBytes);
Block genesis = GenesisLoader.loadGenesis(getClass().getResourceAsStream("/genesis/olympic.json"));
assertEquals(Hex.toHexString(genesis.getHash()), Hex.toHexString(genesisFromRLP.getHash()));
assertEquals(Hex.toHexString(genesis.getParentHash()), Hex.toHexString(genesisFromRLP.getParentHash()));
assertEquals(Hex.toHexString(genesis.getStateRoot()), Hex.toHexString(genesisFromRLP.getStateRoot()));
}
private Block loadGenesisFromFile(String resPath) {
Block genesis = GenesisLoader.loadGenesis(getClass().getResourceAsStream(resPath));
logger.info(genesis.toString());
logger.info("genesis hash: [{}]", Hex.toHexString(genesis.getHash()));
logger.info("genesis rlp: [{}]", Hex.toHexString(genesis.getEncoded()));
return genesis;
}
@Test
public void testGenesisFromNew() {
Block genesis = loadGenesisFromFile("/genesis/olympic.json");
assertEquals(GENESIS_HASH, Hex.toHexString(genesis.getHash()));
assertEquals(GENESIS_RLP, Hex.toHexString(genesis.getEncoded()));
}
/**
* Test genesis loading from JSON with some
* freedom for user like odd length of hex values etc.
*/
@Test
public void testGenesisFromNewMessy() {
Block genesis = loadGenesisFromFile("/genesis/olympic-messy.json");
assertEquals(GENESIS_HASH, Hex.toHexString(genesis.getHash()));
assertEquals(GENESIS_RLP, Hex.toHexString(genesis.getEncoded()));
}
/**
* Test genesis with empty nonce
* + alloc addresses with 0x
*/
@Test
public void testGenesisEmptyNonce() {
Block genesis = loadGenesisFromFile("/genesis/nonce-messy.json");
assertEquals(MESSY_NONCE_GENESIS_HASH, Hex.toHexString(genesis.getHash()));
assertEquals(MESSY_NONCE_GENESIS_RLP, Hex.toHexString(genesis.getEncoded()));
}
/**
* Test genesis with short nonce
* + alloc addresses with 0x
*/
@Test
public void testGenesisShortNonce() {
Block genesis = loadGenesisFromFile("/genesis/nonce-messy2.json");
assertEquals(MESSY_NONCE_GENESIS_HASH, Hex.toHexString(genesis.getHash()));
assertEquals(MESSY_NONCE_GENESIS_RLP, Hex.toHexString(genesis.getEncoded()));
}
@Test
public void testGenesisPremineData() {
Genesis genesis = GenesisLoader.loadGenesis(getClass().getResourceAsStream("/genesis/olympic.json"));
Collection<Genesis.PremineAccount> accounts = genesis.getPremine().values();
assertTrue(accounts.size() == 12);
}
@Test
public void testPremineFromJSON() throws ParseException {
JSONParser parser = new JSONParser();
JSONObject genesisMap = (JSONObject) parser.parse(TEST_GENESIS);
Set keys = genesisMap.keySet();
Trie state = new SecureTrie((byte[]) null);
for (Object key : keys) {
JSONObject val = (JSONObject) genesisMap.get(key);
String denom = (String) val.keySet().toArray()[0];
String value = (String) val.values().toArray()[0];
BigInteger wei = Denomination.valueOf(denom.toUpperCase()).value().multiply(new BigInteger(value));
AccountState acctState = new AccountState(BigInteger.ZERO, wei);
state.put(Hex.decode(key.toString()), acctState.getEncoded());
}
logger.info("root: " + Hex.toHexString(state.getRootHash()));
assertEquals(GENESIS_STATE_ROOT, Hex.toHexString(state.getRootHash()));
}
@Test
public void testFrontierGenesis(){
SystemProperties config = new SystemProperties();
config.setGenesisInfo("frontier.json");
Block genesis = config.getGenesis();
String hash = Hex.toHexString(genesis.getHash());
String root = Hex.toHexString(genesis.getStateRoot());
assertEquals("d7f8974fb5ac78d9ac099b9ad5018bedc2ce0a72dad1827a1709da30580f0544", root);
assertEquals("d4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3", hash);
}
@Test
public void testZeroPrecedingDifficultyGenesis(){
SystemProperties config = new SystemProperties();
config.setGenesisInfo("genesis-low-difficulty.json");
Block genesis = config.getGenesis();
String hash = Hex.toHexString(genesis.getHash());
String root = Hex.toHexString(genesis.getStateRoot());
assertEquals("8028c28b55eab8be08883e921f20d1b6cc9f2aa02cc6cd90cfaa9b0462ff6d3e", root);
assertEquals("05b2dc41ade973d26db921052bcdaf54e2e01b308c9e90723b514823a0923592", hash);
}
@Test
public void testMemEstimator() {
Block b = new Block(Hex.decode("f964daf9020da0a7f0248bfbb49ba21302f9a6dbfabda21de4a59d9ac33e832f406501373aa893a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d493479452bc44d5378309ee2abf1539bf71de1b7d7be3b5a093f9be92b8a699a8ab8f72b8539b307f150e230aab3cf106bc40041cd472a35ea0d13172adf6cab541a651710427c88a92a47f51bb58c8705ca8c2bf6adace555ca003ff1726fd8f2b3b213cf47dafb927253858dfe47bc16060549561f774b8afdeb90100502260304042380280110c240b140002180040200aa4017002998ca01a38a128070a0c04040841494836c0015d8200108b020304810502409a8088000abb8201004000c1044ac093221046ac092c04880600000600080060120a80408a49a40215213020120040022582b98442025a00484802240804006800810219b411201020030028142c00400062002194008442442401c00008813451099620002000120a0051809844320000040250d006c20320a0440d11088000090000000054000201848a0ac08c1011a88092042880a74684a044070008100001815004005860130450690000000005449000800005ca96e0253016025440004200000800030000870a4cc6a8954c6e834e428e837a121d837842ea845a8d16158c6e616e6f706f6f6c2e6f7267a034438c68867b67ef20beef55844105289c21f97f1abd4b0a0f9f49b4f71ad1728896f95450073af434f962c6f8ad8305844a8514f46b04008301a22c944470bb87d77b963a013db939be332f927f2b992e80b844a9059cbb0000000000000000000000009aa154abbeed087fc637b02220f6f9ca1e839afb000000000000000000000000000000000000000000000000000000000009cfb826a0233b1f37a3198f3bedf03c294c41513fe2f755057d50552b8b88cd7b11c19b74a019fe8c087e8261b1258a2a792a450cacedf7d51c72651cf81b1404f4d357be45f86c01850dbcac8e0082520894e46013f9ac84c0c92e597fc77d1b6f5a12d051f58801434c04928f80008026a0b07eb57ffe0f169754266958fe9016ef4b72337f03b95dd8736501963da68220a01e384c1a34b17ab42ef0f0aa3e54834b41561f4b09355c8fad8e13a3ed6a1155f8708304f6b9850ba43b7400830668a094b3408f57077bb2dde0c5515af76bdc33878c975c880ff59ee833b300008025a01ce0f9e7e30e24a883512df526724d7ab87332b554b5f4f609862b234b327b7ca003f5c63bc8e64c13ec4483769425fade4a353b76d9a6c40fd91eb3b2b270bb4af86c04850ba43b740082520894236f9f97e0e62388479bf9e5ba4889e46b0273c3880eab03262a30e0008025a07b859da40ce711bf005d028dc3e642f02f1b8a840ece4779461434060a1bea13a062e59be0a3f252358bce0f8f667c17c3ebacb0a91f9f31ace0cef25f429ad77ef8653285098bca5a0083014c089412fb5d5802c3b284761d76c3e723ea913877afba808026a0e5e1b99e0028be6f807f8eeba50dc2a88d9ae03b2c6e90877a69f7e54c66a3d7a0561055a4cbcdc9d7ffa9b366da54dc942164c2029e59bc416b75e50f12a98f71f86d0485098bca5a008303d0909456eb83949fdf543e8cee4569739d21f07e4eafa9880326774c1c0380008025a0ca5fe5e0ff90124a77e0f4516cb9c46ee80633787c06079bd4d3211fb0e3d330a05ae9853ff257d8bfa6d5f54f5d297588d2acf3174d37de44c044f21edfcf6c35f8a92585098bca5a0082ca609478b039921e84e726eb72e7b1212bb35504c645ca80b844a9059cbb0000000000000000000000009c3e7e5a0e072eb394d75c0d18e10cec5851117600000000000000000000000000000000000000000000000b2ad30490b278000026a09c12914b07c23f1694b9c835e4bcccda9dda0a49377bc8690df1ee199f1944dba037f30add470ca323a924ef085778dcd38ae37e3f86f067fe971e40d4a16f04bef8a91685098bca5a0082cc9594dd974d5c2e2928dea5f71b9825b8b646686bd20080b844a9059cbb0000000000000000000000008401e4983ca4a4a1f1cddeb89c4085b69169e6c9000000000000000000000000000000000000000000000002ce1b2b57de96800026a05e57d944a3049060276c562f8cf704dee9aa2b91da007717e848cc0f012de8aaa007a8fbd6ab346e6478b43dfd573acdf9c166b1f914c81614757a8cb4630b54f8f870830df28e8509502f9000830186a094933bc4e63edfe770f962459b66da5388a32263c2880531d5b3461364008026a04db7659cf5e3db86701be5d204d4229c232d8bc34bd6fe60c282b3e1a670df22a013b5069962e32c568e602571434db0d85b77a44697355d8af54fcb0a81b3ffbdf8718307288d8509502f900083015f9094009c40e9589129974a515ea90c2ab414ccde79ca89056ba3d73af34f00008026a0e75c1b66ca1dfd848668959e4cac392b0c1f35870dbeb2cb6996eedc2f19a898a072764cfb083400808d0d8fbdf5277bb5c5ae42e7d757b0e7e8712ccc6694c11ef871158509502f90008303d090942a0c0dbecc7e4d658f48e01e3fa353f44050c208880f9db9ca32d7600084d0e30db01ca05c73421d0c3bbfc765cad8fb8ac759d5eb8107ef1919d85824eddbd7f02ecea7a077dd3b92923663c8030d0a9eb1c540bad33b9f13c857a801d718b12d5d821650f86b823548850737be76008303d09094c7f7ec818f65459c3a692065fc5f1c52129c893480849ac8441425a0d593908326699956dc84bd35aaa6e86cd4a8b824ece525d817048ff5e4d31ccca0603ca0397148bcbd236cfc0251b3dba50400ae0050d7b050960503a51668caf3f8aa808506fc23ac008301d4c09486fa049857e0209aa7d9e616f7eb3b3b78ecfdb080b844a9059cbb000000000000000000000000692da4782d996dac7d66b5822f3c504f67da849300000000000000000000000000000000000000000000001dd0ed9ba758e9e4001ba0ce3a7a5d0ef258a8518b7cfa4f505415b47d9f311577599235e0a40d243964d1a02ccb5aa80f3fb93f551759237f139c6a77668594d386c52260b54a64ecd700aff86b018506fc23ac0082520894e65a88f487f5d26469cfd37ce7ef763d6d9be45487304a920b74dc00801ba0ca7aa102e2c1edf6c12491f7eeca2763135b43e4efb280566d7fd381cb2a31fda036624504908c0545ef8e9f17ede76b4e41a54a55112ace60528329566ee28880f8708301098f850684ee180083015f90945ca08c42f0dfd09cba09fd94320bbdcf4d50586c881b9de674df0700008026a0707232fb5b62a713210b5829ba560f516c130ed48710504fdca6b68ea64f4183a05a0100cc3b8cc5d07324be52d47172b5ec146dc86ac6f7784bad2ccce8cfccc7f86c07850684ee18008252089486e6df2933f88a00caa11ad19413123c3abef3de881adb9d6629d7e6008026a081f6c734fb3523566f78adb1569c95bef37e2e659335c723c35259812ca0a32ca078dd5577804b470bc295b854155c3e2c156711d11bede02e6223cc6455966345f8a90e850668fd895082f56b945ca9a71b1d01849c0a95490cc00559717fcf0d1d80b844a9059cbb000000000000000000000000e7bbdd9e22e4763272e417cc247219b72422a04e0000000000000000000000000000000000000000000001c9966829aa5044000026a0853b5c66e2a77a074ca76ac16f092a0e2f9cf4c4bb29deb126be7deb6df415f9a015491c274e59b9cc4f8fb909a58ef086bf6879ef71256a5d4df488beef46d72af86c0a85055ae8260082520894053b270864d6a858c809a68c0b00280dff2bc7eb880118c146a62a46f4801ca0afc989860bf3301f538690dc138533eebd3d239f7fb75cd6f7773323af2b543ea02673f53178299e28eb1c5a8be2cfe951121439b272f2622cdb027481a5e1d332f9016e8304ea1685051f4d5c008303f7a0942a0c0dbecc7e4d658f48e01e3fa353f44050c20880b901042295115b000000000000000000000000aa7a9ca87d3694b5755f213b5d04094b8d0f0a6f00000000000000000000000000000000000000000000012976ee0708e4c8241c000000000000000000000000a75fcdf436c9713b3757819f1fb235918749c3ba000000000000000000000000000000000000000000000000000000000000003a000000000000000000000000000000000000000000000000000000000000001c43dc24648536c130879e8927f3adb53c3c9a01cee9379fa14b004846385265306c9fc438db8b8e1e72441e7fa5c463e3eb62c9f5c0457d339961e52309e448650000000000000000000000000000000000000000000000000007cb57bdce51231ba03f4b39ae10286e5b01bc0f6e0eb29498498640327980932cc2e0767c7acf1ae3a04d3ce562a78eeb60ce835a4ddc6228ee104d3edaf9ffc4678586488c888f211cf86d5c8504e3b2920082520894737d60f2490210da0f6ce401e2dadff995ca80058902b5e3af16b18800008026a0bfc3f176f41c6e53135a66b13113b8fcc3e12be96354809475fc719bf4a8d990a07e34b40c5c24a02d7e1e26a43981e30d0a94bc5eb3518268dd4cfe783931bad1f864048504e3b2920082cbd89445555629aabfea138ead1c1e5f2ac3cce2add830808026a029856a81c5fc062e8e2835836c3c57511ec5d7a9869e4a827fe1e1d0392b3f90a02aa4333475aff5acee9deaf748bfee321ecb664da8a9070f56d4162a021adfc1f86c4c8504a817c80082a410943f5ce5fbfe3e9af3971dd833d26ba9b5c936f0be88456213856625c0008026a0bbc22c5a7c90b7a9069d1cb7d9d033013ae28ccb0b60666ded5eefe11d00ff21a07f528d89ca785104becf15f59ff48ee048df35dff3860c05e89156e1b45b9b58f86c048504a817c8008255f09415e310ebf90b07bc44817c4f6c312e0220b81e4e880f8b0a10e4700000001ca04ff7de42037f13e0345617295dcba17c765d5725680414b035756c4ece6a2b00a03bbbcef9953a172e9f3837b3c8052ea3a34726e3a4db17d3e95b9367c6814066f8ac8205888504a817c800830f42409464cdf819d3e75ac8ec217b3496d7ce167be42e8080b844a9059cbb000000000000000000000000ee13c3012681e2d758ea6d098b73fbad1b1ae850000000000000000000000000000000000000000000000292993e7bd6dcb4000026a0e7b18eb3f25ff7ac57ea90cbc32dff69fb93c086ab2d8118b16efa3129baa3afa00f4e426723dc595bbcbfbec3236af2b6ecda9ba1b275b2186fa97f7f8e6d9b87f86c078504a817c8008252089405ee546c1a62f90d7acbffd6d846c9c54c7cf94c881d178d98cc2cf8e08025a0a5b3a3335f8df2d6171c0e559ca44644d64cd8a0073d5d5a580caa0ba8be4f1ca06de00817dff5ce59bcbe3fe34963367ef3192f3285bc975208c13f590627fb2ff8ad8307ddee8504a817c80083030d4094cb97e65f07da24d46bcdd078ebebd7c6e6e3d75080b844a9059cbb0000000000000000000000002571586392956e467b4124def92cf3da22a3096500000000000000000000000000000000000000000000000000000072dbf46a2025a0b3d069846501c4a9d2f6724c41041b5d98fa2fe2edc615145fcfbd5c54605b0fa016ad5eed174c506a1d1c05c4ac168de99459c8febe3477fd3cb47f122c4df1b6f86f8301f6c485045d964b8082c3509437632b659660988d99acb59575880410e2f43dc6881efc523ffa056c008025a085d1e9e7831a902cecbd73820a705e0058f8700e326056de9c58952baa880d73a05326a3d89da4ed1e0a775bcd4830517052de8b10451c3d8bd59d3e0a216b3da9f8ac8207c58503f5476a00831e848094d780ae2bf04cd96e577d3d014762f831d97129d080b844a9059cbb000000000000000000000000fab4b2081dac9fc307dd4eaefe9e92268562a658000000000000000000000000000000000000000000000001ec93f1f8126800001ba0dc8b5bb15c0d6e84ccb4dbbaa690e6199e35260bada02147b77a023e9abe9caea03d736e049525904f3e7bed060a4990a6bf28875f7d27e51c5c33547bac8bb41ef8ac821b218502cb417800831e84809490335e6f8cf5b4b3cc28217b6b2ece290439e49280b844a9059cbb000000000000000000000000ba702b32e37d3537209babad75ee7d318c7e7769000000000000000000000000000000000000000000000006fe3c10875964000026a0f55ec9369d983969c6989184720db22f2a265f2fceff7f774947b0db3bf9d22fa0617af4f0a210df4a599cd5149dfb1d34b5848a5ce6b5b4e1a07d6197f94b900df9033083059cee8502540be400830e57e08080b902da6060604052341561000f57600080fd5b5b60008054600160a060020a03191633600160a060020a03161790555b5b61029e8061003c6000396000f300606060405236156100465763ffffffff60e060020a600035041663395ede4d811461004a57806383197ef01461006b5780638da5cb5b14610080578063e5225381146100af575b5b5b005b341561005557600080fd5b610046600160a060020a03600435166100c4565b005b341561007657600080fd5b6100466101df565b005b341561008b57600080fd5b61009361020b565b604051600160a060020a03909116815260200160405180910390f35b34156100ba57600080fd5b61004661021a565b005b60008054819033600160a060020a039081169116146100e257600080fd5b82915081600160a060020a03166370a082313060006040516020015260405160e060020a63ffffffff8416028152600160a060020a039091166004820152602401602060405180830381600087803b151561013c57600080fd5b6102c65a03f1151561014d57600080fd5b505050604051805160008054919350600160a060020a03808616935063a9059cbb92169084906040516020015260405160e060020a63ffffffff8516028152600160a060020a0390921660048301526024820152604401602060405180830381600087803b15156101bd57600080fd5b6102c65a03f115156101ce57600080fd5b505050604051805150505b5b505050565b60005433600160a060020a039081169116146101fa57600080fd5b600054600160a060020a0316ff5b5b565b600054600160a060020a031681565b60005433600160a060020a0390811691161461023557600080fd5b600054600160a060020a039081169030163180156108fc0290604051600060405180830381858888f19350505050151561020857600080fd5b5b5b5600a165627a7a7230582046378ee80aabd231215e1636373ac5eccd4f45b88b2a03d6fc70c9671e4802a0002926a012ebb3326445e6342f20a9a2e8e44d0b4430feacafca98bb5e46944a1dd8c309a07a0dd3a18c9d0cc1927c7d4757c0522567b7af9e2432714b548bee948fe948c7f8ac8205158502540be400830e57e0942c974b2d0ba1716e644c1fc59982a89ddd2ff72480b844a9059cbb0000000000000000000000005cea26d5c431e6d2c88b32f7b5bf48ccbe4cee20000000000000000000000000000000000000000000000007e651f8215e16a00026a08b2d5a76c394bb10c542bf009724107d0b32f83f5647f030e7664bdb97ab9d88a03473c68cdd3d4d63b9336c49a417894d8e0a69d3959c28062fde00f89d21c7e2f86d168502540be40082627094db5b2ab29b624ac3644e437393ffecf1ff5818028901e5b8fa8fe2ac00008026a0a0c207b23d0990615901a3f4bbc20550b6809b73dbc6f28ec9c63b62f7224df7a05ab4f627471594013be68b19a1ea5956d797571dc6bb2fbb84b01643e0422e0bf86d808502540be40083015f909495153c5e1d9e1c6754e95e92d164373020088d278802f93026b03590008026a08779b66ed23d164aca7765af843a8bc12df59cb83c24795430aca993bc096741a008dd09661fa350e68213b061d88d7fe057a142edb71222a8cd00058dfc02b47ef86d8202848502540be40082520894fa3d425d4e09ec8431f881593f45fccdbcfa4488870bfbd981743d478025a023d60fc1e19fbb54d19a85daa626ca48d3994822f0830606ffac7db72baac9f5a0107a6c1e4cf9a909f8f87b57985d219ea9d8ce7f0ec382c989e2f176e4a600a6f8ac8261538502540be400830186a09493e682107d1e9defb0b5ee701c71707a4b2e46bc80b844a9059cbb000000000000000000000000860c7f15df4165a23fbd10587f30bb5c850bf796000000000000000000000000000000000000000000000000000000009b9c45f025a0c1e5c33fa4cf45c519dd044e0d9b525130201352f04af4da9edf0da71f99312fa04fcc6f9de62b6e009a49bc75e715dd217bcc5ff4a54e0405948b0565d9f2618ff865808502540be400830188eb941530df3e1c69501d4ecb7e58eb045b90de158873808026a0d00295afd845cd81c1259e2e17b5c8d0d2e1e9ae8eb6738f42096aecc89d9aeea064f6cfebdce252978736eebad6ed3b371416b662f6229e25f886c0fcd8bdeb12f8a9018502540be40082ea60941530df3e1c69501d4ecb7e58eb045b90de15887380b844a9059cbb00000000000000000000000004923c5c744653c78a41a26c443b1e78b9c4961200000000000000000000000000000000000000000000000000000036a7b76cd025a0b0a643ed5ab4138344c4177dd946d50cc060d4a3cfedcfd8642c46197cbbae83a07e93439db7761c5863cede3beffc2e2649e64bc6b3631c0aa61f05e0d98a01a5f86d808502540be40083015f90942c71e8491862e24bf5217673aea600468301245b88031156963dd028008025a0ded7d8edd2562f3165d845df049dffad61e27318a264623522aa6e7e448b1b32a00d76d2248ddc97a4b18874f444c0a34b83c2259ed7ae317a3e3071baf92d51d2f86c808502540be40083015f909416bb92ea0de563a97d2a9252dda4764d06c3e89b870c04c66d0afc008025a0f08ca8cfc85c5bb19cf9765de3e38d154e0c8d63629d58b481556a7dda0bb971a057d9e7f09903922727df0e13fc22889710f3dc7eeb991ec2a3b90596f436d1e3f8a9028502540be40082ea6094b98660a7784c494f34ec6ee343499e2d2c47b12880b844a9059cbb0000000000000000000000005296eeabd756f156eecb68a6a87e046be56f91cf00000000000000000000000000000000000000000000001e162c177be5cc000026a02b846ffc5dedfb0d60b177e5b310deade11aaed4d463884764726d2a52613168a06bc4381887b0dcc86de234c12ceaa248d231a618f02445adb3812a4cc7b4c807f86e822d348502540be40082520894f37910f86d5a1fbd3de7f7d6089c54c0390f8b628804a03d81c58f60008025a0ee4e35bc83212404e299ab15919858db1bcbc7ddf2d6a3753e2f701062ace231a02d979b9de92aa251642c300a0ef7dd78a5803a355b7f92efab8628812cd29ed0f86d808502540be40083015f9094bea97ea3ff568c553cdd4fe98eaf5a08e4fc484088119fa980a91e1c008026a00ccf7a44ff4aed3052f8067bce0abe5be8a340ef81f52ff6fed78802175243eaa051e39021e9cc5e5d8edfdd0bc77f03b74fdedf1c811d5b044d3faf9b6f14ece5f86d81938502540be400825208944fe6fc250e21e29820462c856891d5cbb1a5984c880e92596fd62900008025a0450e58ff000fd6993db264e38921b2d89d0a8f12162b6b74471a857eeb152ce1a076a046d293bfaa1e6d525154ab43dd0f3a64aef9ce1b8f779c96223436248626f86b098502540be40082520894be7bac1c616df2bfec24dd1e083c47cc03ab319887038d7ea4c680008026a037f0f9248fbfb2f9977f1ad7f2794c13670e6c68892f20175b11292b82a2e471a048a886b22bbabe8f8aee9d72b4d6775a149d7b6c8cde5def4f5448b3a36f7c18f86b808502540be400825208943b61cd9539c7adb09029590eb2134f50264c0fee87030f132f26d0008025a03f3b29668d917062255742627381a3be53789c93b82a0b1787dfda49c1ce0e7fa06be0bd05ff3e09bb86453f20c814088ec00af3c7445c4d756a082a3bb4eccdf5f86d73850218711a008301117094137822b91c6451762e036c529c33c64e94e9c625884563918244f400008026a01d1c69c6f1ab3a13d4c31d380c104c5f265878adaf0ad9c19b53682924941adba064a85d344d9c6c3aada6b69c60eb4004d8a6892f5adfdfffe389c69879b97459f8ab820a1b8501dcd6500082ca8f946f259637dcd74c767781e37bc6133cd6a68aa16180b844a9059cbb0000000000000000000000002ee8c7ace08ba528c0a17426d5b32af7bb59efdf0000000000000000000000000000000000000000000000000de0b6b3a764000025a0825d5a8b86f3c83cd075318c8e09eb560e8fee2c9ed2c17c2e11550855f38bafa070b8e4432c714377df5bc1779d12c019203456c8066a2b0fac72f8a495963becf865178501dcd6500083011ea29445555629aabfea138ead1c1e5f2ac3cce2add830808025a05f91c347847d091eb093680a922170cc5594fe1572c60fd313d4310a7b3b2234a07d961331105de03d1320f9bc06dd4781bceec8d12e77fa2b3155776d8f6304fff8a9018501dcd6500082ea60941530df3e1c69501d4ecb7e58eb045b90de15887380b844a9059cbb000000000000000000000000f9ac17f4eda48b0ac0bf7baf2d09eaff37a62ed6000000000000000000000000000000000000000000000000000000000000000026a065bf2cfee714276b351ee713cfd119d6235b771a4e10ff97990f8fe54ed9d7f2a056b36888c9f37e63df49c06290937047c5a6526de637f4df5eb23cad53475262f865808501dcd65000830188eb941530df3e1c69501d4ecb7e58eb045b90de158873808025a0767806eb1a58d2bc390531310376628b533d156c19c89791d5e8a387b5cebc8aa071fd413b5052ef60ece9d474d0ba88f9d94d5b2ae47ad6d0d638b83a38353aecf865808501dcd6500083015422949c821d1eed859080c307e326fcc888c230d2bf86808026a0df03333e11fee3c55609648b6a7bc2507b33678938f23b87d278435666c9d586a010fd91a15a0512c05f34c24399445d0e60af1bf581d8a31b64b7ff986dccbec5f86b188501dcd6500082627094878d7954c16f6f0aafdda7aa5dbd825cb50281ba8725449973b1a0008026a026ffa3b09d46f37987debcb5ec81d27e317735c28d0bf1774bc4da33e20e7642a014fcedf54797ed1051afaa488cce6b0295703bf158585604953dfe63cfbd4119f86b378501dcd650008262709480f8662b859e2ad3b5e7feaaca716ab3ecec800a87044364c5bb00008026a0bb20d28877d03f4f623d09fcc7d4ddb2e522e5670bb70300ce857140e275351da06c298ae62ba525c4864472dfa0cb005ee7f408056facfffcfee53624a839678bf86d82041f8501dcd65000826270946e92d5b6f866986bb38ae1d6d8d749c437c158b08703e871b540c0008025a0f8381ce353bc914caf0aa8b8443d09bf5873510d90d0f3f7b6a5eefe7f5629eda01bc402fdf8e667e91fdadfd8470e1f83acdecfe7c3732ce59bb15ef6642aae7ff86b498501dcd6500082627094defffb1eed8571ffc601e7114f626bb1ce8e01b987044364c5bb00008026a04994d82ae686511bde97390411ad41aaa431da7b9010b88897bb31ec8cd4b9aca07b426f7d9dfa2e67a96c48ab9975715ccc9a09fe230ebb5d444a5f307268a45bf865808501dcd65000830188eb941530df3e1c69501d4ecb7e58eb045b90de158873808026a07d2577aadd023057ef2ec01b997390c3fa2dc22429d1903f13b700347024c32ca06f37824c896fab4ae721e87d85735ee0b673f361e86468cb778cc547af2b003bf86b058501dcd6500082627094d550552430a5a9c2c7e9dd3c2f042b72e0181cb487044364c5bb00008025a07841ed68678aabd69c13ca18d9d2fd7fd15f8a24a81ea1019c9b3f7db1d3c44ca014e076bc30b3e67a702d2a707b4816da89654a8ea48f58c326bc896e2c5608d3f865018501dcd6500083011ea29445555629aabfea138ead1c1e5f2ac3cce2add830808026a03a78781565c6deb9db3256151c0d4ee6fd9e9c6167738b77c4ac5054b65bc26ca0724cedc0d77ba1971c77b096131f79127bf5b17d77c329493bbce342049bd190f865808501dcd65000830188eb941530df3e1c69501d4ecb7e58eb045b90de158873808025a022a0e74b66fe5435d6863f4f54e3e818ccb6a1fad444d6547434189ac93a76bfa010223854280edca930e916ac8a5063a3eddf9fa827426535e2da306eddfc139ef865018501dcd6500083011ea29445555629aabfea138ead1c1e5f2ac3cce2add830808026a08658358028c1daa5af9ccc69ddb8907eaf141f1cf85af74bfc335c50e46fdff0a0615fa95dda08f087d2e0be3696c4add62fbc3c601b3aeb480a0418f6842eac98f8a9018501dcd6500082ea60941530df3e1c69501d4ecb7e58eb045b90de15887380b844a9059cbb00000000000000000000000085b1af16abf053364284207a8b4180b9bcce54850000000000000000000000000000000000000000000000000000002e24ccfef026a0931463dc408eed8a294e3a9cc5b4e07c07b595e9c1ef9741e203929e72fd2672a04be66179d4fd07b8265d03085885c541ee546e0c8cdba030d34f85958813fe28f86b028501dcd6500082627094131f4d14341e7ac99ee99af4d0af03ae6b1e11a48729ec09985980008025a0ad4da4ad9f2f3f50dac6fbab36198f3e77aaa44c5089829dcc2ad63067377fdba0050fb9099ff87702520e9f40e39825ca9af42db837988ac301bc6a5f04df1d80f9010a3a8501dcd65000832dc6c09456cd53067e5acd557dbbfb4c66580dfb9722962a80b8a453047154000000000000000000000000eec23ec894f2fe3879472861da6064e4a4dd715a0000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000016345785d8a000000000000000000000000000000000000000000000000000000000000000000094a6f686e205769636b000000000000000000000000000000000000000000000025a01c4c38cc4bd08b460cffdf0c77218d10ef90e7eceb0456c6d1d18dbcb6dda981a05e0d3f06396e2c89ae000e8ba228774054888a52aa3b65e4b45a83c7b052b7e5f865808501dcd65000830188eb941530df3e1c69501d4ecb7e58eb045b90de158873808026a0848b074de4ffcbea27e2ea29632a5188bb4a9475928b184a509b5f7f32d7e336a0239b7abe6e53cce99b6ecb5d2e2fb179fac53b9750158b563895414a3139db37f86a058501dcd65000826270948d94432f09d47b07f16409dcdc89668d06c80f3c865af3107a40008025a08db32e28dfb01e7f4b78d7e97ade00db194dad14d992854fe2873a5a074b2160a010408bba59e242162a276945185f0cfb2e2e9679a7f29493399df8eea3b86419f86c058501dcd65000826270943c3c3ca45ad57b24b64f72d570f1bd0e46424ee0881bc16d674ec800008025a03914b8eb0a53afbbc1c4f52c5d8d902a83025818b3149fda8460b9fcc5eedd24a05d6acf8b6f45aa723d1bdcc6f8fde115bc4d4ccff0e1d1e0ae43d368df8e94d9f865018501dcd65000830188ba94041fe8df8b4aaa868941eb877952f17babe57da5808026a0fb92d03e8f6c565e099cf9f8ea9b425ed30b800c8c98a60a75dc21e017e85f51a01602956fb3dfe04def18e8ac26cd538aa2fabd1581accf17e7c4685899ce8f4cf8a9048501dcd6500082ea6094041fe8df8b4aaa868941eb877952f17babe57da580b844a9059cbb0000000000000000000000001ecbbf170219e1a6855d0529850b5e518c78e2380000000000000000000000000000000000000000000000000000003a184861e026a01a69934d2d8466e196f8a5e366d444d8729730f57e426d7f8347b6ad46e4abcca01ff262d01953845c12f89d7ac1b12b29241b18d81e6d0c75e5eb68b98621a4a0f8a9018501dcd6500082ea60941530df3e1c69501d4ecb7e58eb045b90de15887380b844a9059cbb0000000000000000000000006943adb55f9849366cc51741b1535d596c91784e0000000000000000000000000000000000000000000000000000002e1e3e877025a02dbd07ad96b2b02d7c73973a2ec45dcea415d01155c54d1e490fb70d13e0e3b7a06c93882133cbccd591ed06376f4f8dacaa478f884d243ae26bca23779f1d4915f86b028501dcd65000826270947d2337f89b641d9c5ef8eb9ce686750f3a20dd64870d8014722580008026a07a0a88e6bef92235d56c733fe9c7b497212e6dd37bc299d52d13d28c62fcc0c8a03467a9dea1c4f482d047f9ca5f3531e41fbe8e51f083168761a996bf0f8ebe6cf8a9808501dcd6500082ea609420e94867794dba030ee287f1406e100d03c84cd380b844a9059cbb00000000000000000000000061652ac9f52bad1b9d2b9833d54d88182a5073530000000000000000000000000000000000000000000000821ab0d4414980000025a03e55b84b41093367bb8bf03590a58365b8340c1e9fa8e5bc20848a362fdd1dcba03697e776bfaac2d870ebca903daaccff004f4692226d9c54d368222e126fac94f8680d8501dcd650008301a1bf943618516f45cd3c913f81f9987af41077932bc40d808439055172259f8fdb3b77253d6f7cf3f36ee0ead450c39aa3044b37e01539b6efa13f6aee82a05fc31294d0bcff616477caa91faa54ec9538a0d50eafa95dae08a4c62acd4811f865038501dcd65000830188ba94041fe8df8b4aaa868941eb877952f17babe57da5808026a0e6e1a06e4bb30fe466bc7c5ed1470d6093c9cd18a4f1b0f17e4939fd7079e734a07673bb62b3129caee22a8fb4e26dd7f727061a6ac845833ccbb23add328f9c83f865018501dcd65000830188ba94041fe8df8b4aaa868941eb877952f17babe57da5808025a0f17d8db4cb69da7e00a5c8c543b3b403602a9b78f458615cfbead6317360340da0793929655871a0d81d5f64151526deb1b769970160f9554457652baaa589967bf8678201448501dcd65000830249f09445555629aabfea138ead1c1e5f2ac3cce2add830808026a0ab499b2473b857f9a40f4ec90bc5c04b16825e7a2d92ee445534ff4eeabd3e0ba060c7bcf537b0d55c14e968449a3eb938f871dba0a78e4fcb1dce91ba09205334f8a9018501dcd6500082ea60941530df3e1c69501d4ecb7e58eb045b90de15887380b844a9059cbb000000000000000000000000297e4a2a65b53d57659b250ae2fef7b57851f5d00000000000000000000000000000000000000000000000000000002e211af37026a03060b1f66c92579a8abbbc9fd84531586909c6666e385479726fb16e88348f72a069ed6630d96e1e9bd133ccc3929e1471e60375b1ca9b27fc30da44e4906a6063f865048501dcd65000830188ba94041fe8df8b4aaa868941eb877952f17babe57da5808025a0c04ff31100078fea393437bc326421ca10b85c3a3712d15c4e4fafb278ac7107a049d1f082e0d3627e56630657f0dd2bbbe5a30ae6e05d441b0f732445966bb430f865808501dcd65000830188eb941530df3e1c69501d4ecb7e58eb045b90de158873808026a0b18e5ab1569e09a1b51e0615d98fc67ed475859fa7e37808d34963e316fa581ca0644d546af52528fa6cca893895a059a2c41829afc6590c83aaa30b18f84bcf63f8aa078501dcd650008303d0909470a72833d6bf7f508c8224ce59ea1ef3d0ea3a3880b844095ea7b30000000000000000000000008d12a197cb00d4747a1fe03395095ce2a5cc681900000000000000000000000000000000000000000000003102eb135ac856b8001ba0824921bdf2549600ca3e4926b6b6118ec838e80e61d25f01d606192c0cbcdd97a04c1531ba1db290020244d1f0efd026c401b468eacbee78565d270129614df997f865808501dcd6500083015422949c821d1eed859080c307e326fcc888c230d2bf86808025a014eda6b30d89a40fe9cacd1f3f0bc18ca50428dddb974e9b5dc1619e86efbd84a04fe40e4abdbe8a97e08a52a2dc11c985889ad97e89d1b2154ddfc2075a4be5c4f8a9058501dcd6500082ea6094041fe8df8b4aaa868941eb877952f17babe57da580b844a9059cbb0000000000000000000000005ffd96366c0d3ea6d8fa2f91223d65d52cedbd710000000000000000000000000000000000000000000000000000003a243423e025a081715992bf76a845033dd4df3ba659e714a6335f217738027bb6142cddf33c32a006196b965820971a50d35065a27ea3f37799f1b0f6196f14d44a5d0961b1579bf8a9018501dcd6500082ea60941530df3e1c69501d4ecb7e58eb045b90de15887380b844a9059cbb000000000000000000000000285049ff70c9acd36b0829b1364762e25df830120000000000000000000000000000000000000000000000000000002e1d4bc30025a0054c26bdd55b89cae30fdae5446bb6b479ea3b4c3e89376940b39dcea1450f05a03b24ce62aeb16c20b1f4eb35d04b6caedeaf3442c6939e91687e000b1fce1f5af86c81c58501dcd650008262709420021f82ebe035557eb44b42a4ed201cfa046d3b870775f05a0740008026a0b828a3b0c3f6fbe26f53f7484994dfc32f2a46db65d45f2f3e18e3689d067646a075218ac434f9b3df83ec4ab75f4a13cac02b8f3482e970c7e00dac765c8e43f7f865048501dcd65000830188eb941530df3e1c69501d4ecb7e58eb045b90de158873808025a0d73c2c97b88a1214bfa6b94997d019de6e6509db165523f11da5d5a85ddb0453a0448dd5e8509b51effe195c4ac7a932c48b8b2afcfaf1ca9904418184da41cabff8a9018501dcd6500082ea60941530df3e1c69501d4ecb7e58eb045b90de15887380b844a9059cbb00000000000000000000000094e6dffb38cade4f8946176479b32c9444969ebf0000000000000000000000000000000000000000000000000000002e28f91c7025a03d34dda851947973c1fcaadf818f2c564ec442471ef5847b9a8112f2eca53543a06da49c7d9e58546244449a88854070c33b02f47991cc3b38600a35f9a4f09b1bf865808501dcd65000830188eb941530df3e1c69501d4ecb7e58eb045b90de158873808025a0d41c9093a124f7d43b98e63b57da3319f0b3684c7a4ef477f13b95d21a99c9fca016698d94f95f351d985746134b54299b568bc1ee9485bc417bcf0ae1f3027874f865808501dcd65000830188eb941530df3e1c69501d4ecb7e58eb045b90de158873808026a056670ea85d93fc362d2d97817976a4c09ebf45df30fa408994805fd7f3364311a0325607212adaa85e51d0a525b637339a7155279646c2c455367508f302a1eeeaf865808501dcd65000830188eb941530df3e1c69501d4ecb7e58eb045b90de158873808026a084c6ca7c20efd06f116e4195e57773fa95254ba65d8db3d940b6cdb04c32fb98a03d62df0104c0be2aab0eaadafc0a15bec508ab4471ec607734338a0665a92ffdf86b028501dcd6500082627094e8a92b7f5b1ca356e42af878ba0a3804f30da5fc87c85667fee260008026a0cc179d1682f27ba3462fc467c3aae7d84f414dc933d04dddde24fc6f164ea17aa06620fa60bf3645f85c6f8338751d71cc093a69bbb88bffe60bfa18798d4fdd4bf8a9048501dcd6500082ea6094041fe8df8b4aaa868941eb877952f17babe57da580b844a9059cbb000000000000000000000000a26606347b1ca55695781fdf9bb97b1bd5e7f7a60000000000000000000000000000000000000000000000000000003a20c6c28025a030fd5263601d0614e11f3368f0f53b5c3b17fa3cda2ae3140792d45675d5bfeda01a129961517a13116fb249d0e0d2108bdac5e955bb84fddd939cafea1e34226df865258501dcd650008301adb09445555629aabfea138ead1c1e5f2ac3cce2add830808026a0adfd88dfbbae0604764fb248362dda15ff70251b2e9dc196953fcbc9a2a6aacaa06f253e0b0438c495571e02b315cbebf18c2b654aa63fab0942a82640a1009226f864028501dcd6500082627094275b69aa7c8c1d648a0557656bce1c286e69a29d808026a0ce76e53b280e96e399a694251b01cafed48890a22099239f75e9724c934af85fa043f2a2c351003aec48a6a80786a5d955be65ebbd5e965cfcb90e72b2c321cffbf865038501dcd65000830188eb941530df3e1c69501d4ecb7e58eb045b90de158873808026a0477492d12369fbb1d979b20ee4ec6b65b2bc609dca95bf40f091d77d63d795e2a05f6c9cf205a20a1d3e8a67f05f0a7ad04f37d4cfe69292cdb475213a3ac166d1f865018501dcd6500083011ea29445555629aabfea138ead1c1e5f2ac3cce2add830808025a08e35620e56bd5246b14d30955a30d60284ccf52ab3bdcb2595a14e344317417ca017f78d258350cbff103d92053f932c432af31e03748a11646ded8b2d13cfe95cf86c0a8501dcd6500082627094e9dd33253476a52f68036b03c5fe19465999d639880de0b6b3a76400008026a0e480e36da4c11371298833fd2edab0c4ee2aa8acc6bdd14f9daf0d211e24a5a7a04ef1d2f6e98ccc0935bf190aec550cc63af5162ceb9f869d8876181ff0e2b456f86b058501dcd6500082627094a3543a59ef459d512ee17c663024f3f89dffbcac87470de4df8200008025a0ccc009c9e617851612cd4ede7a5012c3163b6961815ec24a3d2edc76553725dca04296d1f5c92f78fdc27429c6fcae5e8d884d714c83067f2b71ae863a29bf371cf86b2a8501dcd6500082627094480ae00f320a90b7f0e79521cc4e8bf5527ded7787044364c5bb00008025a06e4630fa99b13df833b075ee4ceebe287bc1cdd3d95357053eeba503655337dea03b4bc3e6fe72d77f6dd2400e24945ffc24017ba362785511986733e2b736d5f9f865218501dcd65000830188ba94041fe8df8b4aaa868941eb877952f17babe57da5808025a0ee20d7430fd44bfd6edebcc005cfdb157edeb435dbce04c0f3978721c1eb450ba007637fa44c4925203536b02f46df354f29c56d92015d920b9d8e97bfb2f5bd93f865038501dcd65000830188eb94f7dca20054469a1d548b20859a100b9ec6ff1f61808025a062a7a1611b105ed26090edf659fa1784fd04da136b54d55f34abf4fd1547903ba06443c369a2ada0edfcb706d2e672867e418eeaebbbb2524ef0eed4903c2c1f9df86a028501dcd650008262709471a1a75889278820ea73ac45930ae4ebe5013d4b8612309ce540008026a0625d20ae39aea4cc31665511d5423b7ed6692465307e18b19a625b6d9dd70518a01905fdf82657f8c9ae9e986e0d1695dd691e08993079141015f90bee5d9953a0f8a9048501dcd6500082ea60941530df3e1c69501d4ecb7e58eb045b90de15887380b844a9059cbb000000000000000000000000c328f30cad4f14fd2e80cb7fabb444ab36521d9c0000000000000000000000000000000000000000000000000000002e5b47606026a02090b02053fecb987465a656106817f76e3989bf3bc90882e57a9ae885247f38a07d5ca3fbf0a9451e12c70f14cd9de45a3c327a5bf176b2a297311463f2d416a7f8a9018501a13b8600828dd5943a26746ddb79b1b8e4450e3f4ffe3285a307387e80b844a9059cbb0000000000000000000000002b6401fbf71effb2edc0d419271b7e3466130d01000000000000000000000000000000000000000000000000000000009502f90025a0cadba085ea9d933fba063d0bccc0f8d4a041cb4cab0aed0a8382dcb1adea4753a051ac59ec94067c37b4f997163c95af8c986dcab316e06e946c6bf295bfb2c880f86d0c8501a13b8600830186a094fe7fb69b43e5d912c0af2547d3291864254d4b2b881774160bc66900008025a015827600b51aabff9eaefafb5b9e1cf5386b9a14044b6d0663c8ca098de5cf97a07bc7a99107ea82d31e32c9cf56479b6a9e2d1d8c71ff1c52ea70a21f096fcaedf8652e8501a13b8600830249f0949c821d1eed859080c307e326fcc888c230d2bf86018026a068098f560e4c38f05c88a37d3f3008bb350380f117e292b983e2404bf02b5f67a00178e4644acb2d3c2d7be66fc318917c6dea23f10cc26432d0e0dae64c67a3f8f891818a850165a0bc008303d09094b1690c08e213a35ed9bab7b318de14420fb57d8c8711c37937e08000a4454a2ab3000000000000000000000000000000000000000000000000000000000004453d26a0904e0bc877f87df103e4c71ce23d689b80e585d803c982a384871d3dc2ac574ea00e1aa5df6ba0af2f3f5a8feec6d9181947291d80c3cef19cc74f722e38bc21b8f9018b0c850165a0bc008303d090941ce7ae555139c5ef5a57cc8d814a867ee6ee33d880b90124278b8c0e000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001c4f89310dcc0000000000000000000000000004c251de85ad3498c5b89388d8efc696ddd0b0fe700000000000000000000000000000000000000000000000821ab0d441498000000000000000000000000000000000000000000000000000000000000004e63540000000000000000000000000000000000000000000000000000000037535952000000000000000000000000000000000000000000000000000000000000001c589e03657e41e05a0e386be971c3ff3f24e9a9ecefb176e29ce26c68bdb298a33fa7414cb54cb89afb8d40f04a5a69ba4aa14bdef016fd68d56355c0d54364561ba0c8c60ae751a38116679045d8b1760b3dcb0f6223a9d69b51114f4f63dad4d7dba04a1084ba5790b08892a8339afe0cf20332cd0c99252b94cc12eeda5970934259f8b3820b72850165a0bc008301b54f9406012c8cf97bead5deae237070f9587f8e7a266d871c6bf526340000b844f7d8c8830000000000000000000000000000000000000000000000000000000000081531000000000000000000000000000000000000000000000000000000000004a6b825a01e6eecb6467cfd4cec83c349392e5cba97170cc20d89cece0bd0156e307f3789a074926b4aa0a2d8b3ed69d4a7028e84066f02e9fe65be3a659d4ec35b65e8a909f870830df28f8509502f9000830186a094fefb07a2f0f161994bcad68393e96772c21794be88020091c1e30f44008026a0d43f9003b351e5f08ee41034d158d9916bf41325ed3ee8e2e4d23282a10ac069a00419c3fb210210530880b357cd267d4c4865f3374c999fd046b84452398998e4f8ad8307288e8509502f9000830193869441e5560054824ea6b0732e656e3ad64e20e94e4580b844a9059cbb00000000000000000000000069964ad8dd235535288df785e8f7a450f5912552000000000000000000000000000000000000000000000000000000000bebc20025a0210b8732c3b847d870fa47c16d7e1d9b267ee1e46cdeaa1e7314bf4ee624dfa8a0566c5a6cb04a74af926a812e000eb875e425960e9b07371005754a2539b8e992f87083010990850684ee180083015f9094811a27c1b32a1c265a909ba826a6408f2a35c5c8883782dace9d9000008025a05854558634b7bdf9fe0346c6adb7b9aed883f9e14ce5265d0c28d05bcff99853a05d7e572f5e045aa2f2c9857aa9c21f270f2598856a6860b536e7974f9603bbdbf902ae8304ea1785051f4d5c008303f7a0942a0c0dbecc7e4d658f48e01e3fa353f44050c20880b90244ef34358800000000000000000000000000000000000000000000003ba389df387ff6c4800000000000000000000000000000000000000000000000001627c93273beb2640000000000000000000000000000000000000000000000000000000000002710000000000000000000000000000000000000000000000000000000004c31756a00000000000000000000000000000000000000000000003ba389df387ff6c48000000000000000000000000000000000000000000000000000000000000000af00000000000000000000000000000000000000000000000000038d7ea4c68000000000000000000000000000000000000000000000000000000f6da3bc686c810000000000000000000000009992ec3cf6a55b00978cddf2b27bc6882d88d1ec0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c91674d315cc89ba9d6ab194bd0b812bf750cae5000000000000000000000000c6b7d0789d9dc186735d83024c635b0e9a8548b8000000000000000000000000000000000000000000000000000000000000001b000000000000000000000000000000000000000000000000000000000000001b35ed1bdc59fe1f965e48cc2be1c48442115d8c0bd15f1133d39986b34769e891062f86dbaef0f0f52d4b37c14a5da2eb1d85d60546a39086c277f87a31c1d39bc6bee6576b09fc4de1954b6fdb31e5b6d5fef0710960977c824447a6175e40c42f4321568697ddfef8cc1b49448e764e9fbb304686ed294dc0ddf970b61afbe31ca0a0f7194cb51c0ba628c05e9fd6413a2b73f0251884d7f286bd5c3329b8545bf4a0537ade4b71462b9608f429b33c905f8e304ad3c5609051c5894fb6c059c213daf9033083059cef8502540be400830e57e08080b902da6060604052341561000f57600080fd5b5b60008054600160a060020a03191633600160a060020a03161790555b5b61029e8061003c6000396000f300606060405236156100465763ffffffff60e060020a600035041663395ede4d811461004a57806383197ef01461006b5780638da5cb5b14610080578063e5225381146100af575b5b5b005b341561005557600080fd5b610046600160a060020a03600435166100c4565b005b341561007657600080fd5b6100466101df565b005b341561008b57600080fd5b61009361020b565b604051600160a060020a03909116815260200160405180910390f35b34156100ba57600080fd5b61004661021a565b005b60008054819033600160a060020a039081169116146100e257600080fd5b82915081600160a060020a03166370a082313060006040516020015260405160e060020a63ffffffff8416028152600160a060020a039091166004820152602401602060405180830381600087803b151561013c57600080fd5b6102c65a03f1151561014d57600080fd5b505050604051805160008054919350600160a060020a03808616935063a9059cbb92169084906040516020015260405160e060020a63ffffffff8516028152600160a060020a0390921660048301526024820152604401602060405180830381600087803b15156101bd57600080fd5b6102c65a03f115156101ce57600080fd5b505050604051805150505b5b505050565b60005433600160a060020a039081169116146101fa57600080fd5b600054600160a060020a0316ff5b5b565b600054600160a060020a031681565b60005433600160a060020a0390811691161461023557600080fd5b600054600160a060020a039081169030163180156108fc0290604051600060405180830381858888f19350505050151561020857600080fd5b5b5b5600a165627a7a7230582046378ee80aabd231215e1636373ac5eccd4f45b88b2a03d6fc70c9671e4802a0002926a0642924aedbabe87fbc3f9189c0926313425aab11144fce53f6410eb8302225b8a049723bf79ede4f45182466b34bd5a5979a269a1b098ca352d14e4ee583155ea1f8ab820a1c8501dcd6500082ca8f946f259637dcd74c767781e37bc6133cd6a68aa16180b844a9059cbb00000000000000000000000053587ba1e1144d03a5819d5101f94ab0600fb4f20000000000000000000000000000000000000000000000000de0b6b3a764000025a030b21caaf789d4d6fccf7b2b504e9fe28d78621e1c3c97c843447a1da0e6fc0fa07aac66eb4346ecb120b2ac262b7a00e8a296d79870d3d65d424bcef3fafabab3f8aa088501dcd650008303d090948d12a197cb00d4747a1fe03395095ce2a5cc681980b844338b5dea00000000000000000000000070a72833d6bf7f508c8224ce59ea1ef3d0ea3a3800000000000000000000000000000000000000000000003102eb135ac856b8001ca0fabe31e791c83093ba302cc0f0245015ab58c68bdfebf18adce487e9769a142ca053599a2ddb513f5e004c6acd2e76b5ddbd6994757cf979e87c0a4b8ae94a7362f870830df2908509502f9000830186a09403c779e9b0277310f5347674f2f7fe1897fd3b0c8806ed3fd58500d0008026a0172f976a8fac2ded91b87ea888c81933efd9197069556bcc89bef3fdebde444ca00a1a5dbca5f7c5fb5769ec49be7066ac347295cd48802e37585b2f23e5ec21a9f9033083059cf08502540be400830e57e08080b902da6060604052341561000f57600080fd5b5b60008054600160a060020a03191633600160a060020a03161790555b5b61029e8061003c6000396000f300606060405236156100465763ffffffff60e060020a600035041663395ede4d811461004a57806383197ef01461006b5780638da5cb5b14610080578063e5225381146100af575b5b5b005b341561005557600080fd5b610046600160a060020a03600435166100c4565b005b341561007657600080fd5b6100466101df565b005b341561008b57600080fd5b61009361020b565b604051600160a060020a03909116815260200160405180910390f35b34156100ba57600080fd5b61004661021a565b005b60008054819033600160a060020a039081169116146100e257600080fd5b82915081600160a060020a03166370a082313060006040516020015260405160e060020a63ffffffff8416028152600160a060020a039091166004820152602401602060405180830381600087803b151561013c57600080fd5b6102c65a03f1151561014d57600080fd5b505050604051805160008054919350600160a060020a03808616935063a9059cbb92169084906040516020015260405160e060020a63ffffffff8516028152600160a060020a0390921660048301526024820152604401602060405180830381600087803b15156101bd57600080fd5b6102c65a03f115156101ce57600080fd5b505050604051805150505b5b505050565b60005433600160a060020a039081169116146101fa57600080fd5b600054600160a060020a0316ff5b5b565b600054600160a060020a031681565b60005433600160a060020a0390811691161461023557600080fd5b600054600160a060020a039081169030163180156108fc0290604051600060405180830381858888f19350505050151561020857600080fd5b5b5b5600a165627a7a7230582046378ee80aabd231215e1636373ac5eccd4f45b88b2a03d6fc70c9671e4802a0002926a0b96d8d3220fa13515f9c9ef3dec544e42fdb5f541602f12bf4eff1fab17e13a9a051c7b6723b49b6f4a3ba196ff57c324455fd5dfc9497c2a96b6a569aacd07231f8ab820a1d8501dcd6500082ca8f946f259637dcd74c767781e37bc6133cd6a68aa16180b844a9059cbb0000000000000000000000004949da879392266ab412dc0897115db66aeb20dd0000000000000000000000000000000000000000000000000de0b6b3a764000025a08bad8678c23c3f580b4215ab67668d071898ac96a018b7ee0576fa8994868894a06b44f01a4947bcb7cc2461c73c663448347c5369e1c982d07a9e612fed669b56f86f830df2918509502f9000830186a09422091806f89d266afbbb1c22fdf6a5354d649075872008bdad0ea4008025a0bf95b3c1308097200fb39558b44721a2525fcb417ce4e78cf49e8c462802045fa059ad4c267320eba469d92b25a5e6f9b28350fadd44ea37fffc53233675a203b1f9033083059cf18502540be400830e57e08080b902da6060604052341561000f57600080fd5b5b60008054600160a060020a03191633600160a060020a03161790555b5b61029e8061003c6000396000f300606060405236156100465763ffffffff60e060020a600035041663395ede4d811461004a57806383197ef01461006b5780638da5cb5b14610080578063e5225381146100af575b5b5b005b341561005557600080fd5b610046600160a060020a03600435166100c4565b005b341561007657600080fd5b6100466101df565b005b341561008b57600080fd5b61009361020b565b604051600160a060020a03909116815260200160405180910390f35b34156100ba57600080fd5b61004661021a565b005b60008054819033600160a060020a039081169116146100e257600080fd5b82915081600160a060020a03166370a082313060006040516020015260405160e060020a63ffffffff8416028152600160a060020a039091166004820152602401602060405180830381600087803b151561013c57600080fd5b6102c65a03f1151561014d57600080fd5b505050604051805160008054919350600160a060020a03808616935063a9059cbb92169084906040516020015260405160e060020a63ffffffff8516028152600160a060020a0390921660048301526024820152604401602060405180830381600087803b15156101bd57600080fd5b6102c65a03f115156101ce57600080fd5b505050604051805150505b5b505050565b60005433600160a060020a039081169116146101fa57600080fd5b600054600160a060020a0316ff5b5b565b600054600160a060020a031681565b60005433600160a060020a0390811691161461023557600080fd5b600054600160a060020a039081169030163180156108fc0290604051600060405180830381858888f19350505050151561020857600080fd5b5b5b5600a165627a7a7230582046378ee80aabd231215e1636373ac5eccd4f45b88b2a03d6fc70c9671e4802a0002925a087de2873f51df7667488f118710e6e31e8f94a950662b17486baabb0843c6f74a01db4acea166f0621d89e5096ac96b0abc561ada3c38c304f757d066d4afea672f8ab820a1e8501dcd6500082ca8f946f259637dcd74c767781e37bc6133cd6a68aa16180b844a9059cbb000000000000000000000000af733e15beace714ee335cc1b81ee7a5153def620000000000000000000000000000000000000000000000000de0b6b3a764000026a0951f9ba9f22863ba96483a1e72bcdfebfd6cb282a88b32bc25d9991c1155b5c9a04f6b3005b1fb6b84e15880561a45aa7426aa6aabc0acff286f92fde899556e43f86f830df2928509502f9000830186a0942fe8283062fc30cb0bed18408ace49d8adccdfa7872030d285c0a0008026a0fc5b060da34701b884dbfaf04d78f49599cc1fc9d5256f15f39c101c1488f192a03ee91184d7ed01242456bfecb892ac45240c083fea7e11ae46cae8db00c01764f9033083059cf28502540be400830e57e08080b902da6060604052341561000f57600080fd5b5b60008054600160a060020a03191633600160a060020a03161790555b5b61029e8061003c6000396000f300606060405236156100465763ffffffff60e060020a600035041663395ede4d811461004a57806383197ef01461006b5780638da5cb5b14610080578063e5225381146100af575b5b5b005b341561005557600080fd5b610046600160a060020a03600435166100c4565b005b341561007657600080fd5b6100466101df565b005b341561008b57600080fd5b61009361020b565b604051600160a060020a03909116815260200160405180910390f35b34156100ba57600080fd5b61004661021a565b005b60008054819033600160a060020a039081169116146100e257600080fd5b82915081600160a060020a03166370a082313060006040516020015260405160e060020a63ffffffff8416028152600160a060020a039091166004820152602401602060405180830381600087803b151561013c57600080fd5b6102c65a03f1151561014d57600080fd5b505050604051805160008054919350600160a060020a03808616935063a9059cbb92169084906040516020015260405160e060020a63ffffffff8516028152600160a060020a0390921660048301526024820152604401602060405180830381600087803b15156101bd57600080fd5b6102c65a03f115156101ce57600080fd5b505050604051805150505b5b505050565b60005433600160a060020a039081169116146101fa57600080fd5b600054600160a060020a0316ff5b5b565b600054600160a060020a031681565b60005433600160a060020a0390811691161461023557600080fd5b600054600160a060020a039081169030163180156108fc0290604051600060405180830381858888f19350505050151561020857600080fd5b5b5b5600a165627a7a7230582046378ee80aabd231215e1636373ac5eccd4f45b88b2a03d6fc70c9671e4802a0002925a005974e86452eb8a23e1f89fafce732d7dd1aea9060d31e5517d47c42d0630acca07447ce67592b3d29dd5736186f4c5a509013710976fe78e43e765e36b6e6441ff8ab820a1f8501dcd6500082ca8f946f259637dcd74c767781e37bc6133cd6a68aa16180b844a9059cbb0000000000000000000000009ec8b099d4b766295e8fa44423f228c2c293dcd00000000000000000000000000000000000000000000000000de0b6b3a764000026a0b2b960146500680200383e219d612efa1886e36c49147fe8a414b1db1636cb62a067c85fd8971110c87961ba1c96887efa838e7acef3ded44b1232fc0f3a168afaf86f830df2938509502f9000830186a0946cc2e200c58d2280ac0d0c2f50350bb1f466659987200f32c608fc008025a0676717fc06167d628b197c80c4b558ce597856ba3260caec436bb9e25e762b89a0710c755ba691e3b04fe20e85f644633affc30514ca4f2a9109261a834187f790f9033083059cf38502540be400830e57e08080b902da6060604052341561000f57600080fd5b5b60008054600160a060020a03191633600160a060020a03161790555b5b61029e8061003c6000396000f300606060405236156100465763ffffffff60e060020a600035041663395ede4d811461004a57806383197ef01461006b5780638da5cb5b14610080578063e5225381146100af575b5b5b005b341561005557600080fd5b610046600160a060020a03600435166100c4565b005b341561007657600080fd5b6100466101df565b005b341561008b57600080fd5b61009361020b565b604051600160a060020a03909116815260200160405180910390f35b34156100ba57600080fd5b61004661021a565b005b60008054819033600160a060020a039081169116146100e257600080fd5b82915081600160a060020a03166370a082313060006040516020015260405160e060020a63ffffffff8416028152600160a060020a039091166004820152602401602060405180830381600087803b151561013c57600080fd5b6102c65a03f1151561014d57600080fd5b505050604051805160008054919350600160a060020a03808616935063a9059cbb92169084906040516020015260405160e060020a63ffffffff8516028152600160a060020a0390921660048301526024820152604401602060405180830381600087803b15156101bd57600080fd5b6102c65a03f115156101ce57600080fd5b505050604051805150505b5b505050565b60005433600160a060020a039081169116146101fa57600080fd5b600054600160a060020a0316ff5b5b565b600054600160a060020a031681565b60005433600160a060020a0390811691161461023557600080fd5b600054600160a060020a039081169030163180156108fc0290604051600060405180830381858888f19350505050151561020857600080fd5b5b5b5600a165627a7a7230582046378ee80aabd231215e1636373ac5eccd4f45b88b2a03d6fc70c9671e4802a0002925a06ed8fbbe361c6b3664d8d20ff5ba00f6ca20de8a5a5629d90e6dc102ff4b8d58a048ebfb81610f9256a975c6ea1774c043a5e0251084a890b1fe9fad626129b694f8ab820a208501dcd6500082ca4f946f259637dcd74c767781e37bc6133cd6a68aa16180b844a9059cbb00000000000000000000000016b50005e6e463107abd5c1342f06590cd871ff50000000000000000000000000000000000000000000000000de0b6b3a764000025a0e134eb6eb936034bef58afc25fa0775556cef2032dce73e34d30f7a8a136d381a017a1dd92b25da2d1927809ddaef71b2d9cc7deb7e556ad2bd85804bc8299af7bf870830df2948509502f9000830186a094b21ae44f4136a04ca7d0c9ede7a5a5bccf3197898829a192fa2d014c008026a0151021ae31f035402eaef55ec6aaf10c6b7a6131338cfd0c35ed6d323f80787aa07167bbee65f1fab34ee097fe5798cd6a497a9be35eac4ec81de9ed404706ffe1f9033083059cf48502540be400830e57e08080b902da6060604052341561000f57600080fd5b5b60008054600160a060020a03191633600160a060020a03161790555b5b61029e8061003c6000396000f300606060405236156100465763ffffffff60e060020a600035041663395ede4d811461004a57806383197ef01461006b5780638da5cb5b14610080578063e5225381146100af575b5b5b005b341561005557600080fd5b610046600160a060020a03600435166100c4565b005b341561007657600080fd5b6100466101df565b005b341561008b57600080fd5b61009361020b565b604051600160a060020a03909116815260200160405180910390f35b34156100ba57600080fd5b61004661021a565b005b60008054819033600160a060020a039081169116146100e257600080fd5b82915081600160a060020a03166370a082313060006040516020015260405160e060020a63ffffffff8416028152600160a060020a039091166004820152602401602060405180830381600087803b151561013c57600080fd5b6102c65a03f1151561014d57600080fd5b505050604051805160008054919350600160a060020a03808616935063a9059cbb92169084906040516020015260405160e060020a63ffffffff8516028152600160a060020a0390921660048301526024820152604401602060405180830381600087803b15156101bd57600080fd5b6102c65a03f115156101ce57600080fd5b505050604051805150505b5b505050565b60005433600160a060020a039081169116146101fa57600080fd5b600054600160a060020a0316ff5b5b565b600054600160a060020a031681565b60005433600160a060020a0390811691161461023557600080fd5b600054600160a060020a039081169030163180156108fc0290604051600060405180830381858888f19350505050151561020857600080fd5b5b5b5600a165627a7a7230582046378ee80aabd231215e1636373ac5eccd4f45b88b2a03d6fc70c9671e4802a0002926a084927134839f43240baf45f18c42938ed61e2d9de4adc0dc8f37bff01e0993e6a02a9db9d8b8062a6227c74a3cbd3344e789c0e7a15573a34008057253bd18c90bf8ab820a218501dcd6500082ca8f946f259637dcd74c767781e37bc6133cd6a68aa16180b844a9059cbb000000000000000000000000dd0ea1397cc744c49e26f2ce569e968569cfd4610000000000000000000000000000000000000000000000000de0b6b3a764000026a0b876183777d985188bfc2634f5122f474ba1ff64cbdd7e9f15a0eccd4d501dd0a0539ef3bb823780bb5284e3d2795e477b40bee2331c014f7849c289f7c1e2e388f9033083059cf58502540be400830e57e08080b902da6060604052341561000f57600080fd5b5b60008054600160a060020a03191633600160a060020a03161790555b5b61029e8061003c6000396000f300606060405236156100465763ffffffff60e060020a600035041663395ede4d811461004a57806383197ef01461006b5780638da5cb5b14610080578063e5225381146100af575b5b5b005b341561005557600080fd5b610046600160a060020a03600435166100c4565b005b341561007657600080fd5b6100466101df565b005b341561008b57600080fd5b61009361020b565b604051600160a060020a03909116815260200160405180910390f35b34156100ba57600080fd5b61004661021a565b005b60008054819033600160a060020a039081169116146100e257600080fd5b82915081600160a060020a03166370a082313060006040516020015260405160e060020a63ffffffff8416028152600160a060020a039091166004820152602401602060405180830381600087803b151561013c57600080fd5b6102c65a03f1151561014d57600080fd5b505050604051805160008054919350600160a060020a03808616935063a9059cbb92169084906040516020015260405160e060020a63ffffffff8516028152600160a060020a0390921660048301526024820152604401602060405180830381600087803b15156101bd57600080fd5b6102c65a03f115156101ce57600080fd5b505050604051805150505b5b505050565b60005433600160a060020a039081169116146101fa57600080fd5b600054600160a060020a0316ff5b5b565b600054600160a060020a031681565b60005433600160a060020a0390811691161461023557600080fd5b600054600160a060020a039081169030163180156108fc0290604051600060405180830381858888f19350505050151561020857600080fd5b5b5b5600a165627a7a7230582046378ee80aabd231215e1636373ac5eccd4f45b88b2a03d6fc70c9671e4802a0002926a0b2e65cd39820b9450cba6b6a52e5d68231bd6b7c75c3fc0542009fdc29ca092aa0317632816e88e1c8c25af20b86e374251b0ad3dfc3d59829e56ddacd0ca2da2ff8ab820a228501dcd6500082ca8f946f259637dcd74c767781e37bc6133cd6a68aa16180b844a9059cbb00000000000000000000000047089369db79cde40279ec52a77370e1e23c35be0000000000000000000000000000000000000000000000000de0b6b3a764000026a0e4b5971a9589874ecb421774c9c8cc9160ab8dbb1087bc0535dd75b41848e22aa059305c7c2eb6bd5637933af1da6dc9cd270ad764b9e0edb2becfc517228274b4f8ab820a238501dcd6500082ca8f946f259637dcd74c767781e37bc6133cd6a68aa16180b844a9059cbb000000000000000000000000f4ae63922475f9e7fefc03c788a0acf6c9788c770000000000000000000000000000000000000000000000000de0b6b3a764000025a03c630f0858b8e658e942bc5e86e91a988ce18bda2828cc33f219a8f3a3c93342a0256971ff6264ccb39e5e49ef9a873d30a0079841fdb9cf155a58da0bc6cd84f5f8ab820a248501dcd6500082ca4f946f259637dcd74c767781e37bc6133cd6a68aa16180b844a9059cbb0000000000000000000000004de06deaa4f48753167229b258fb9b8400126d0f0000000000000000000000000000000000000000000000000de0b6b3a764000026a0ab72b91539ee3a2e7b0de0357784c78c38e82b4361e5d3af082c2185304c787fa00b16bbd40f5b7b32e71842b57fbe7829501161c62b3b24da4f87022ec8fc221df8ab820a258501dcd6500082ca8f946f259637dcd74c767781e37bc6133cd6a68aa16180b844a9059cbb000000000000000000000000d57a83e33c37316b49296d19fa2877c734198eee0000000000000000000000000000000000000000000000000de0b6b3a764000026a0d57829b1dbf307cefc07a287961c5116c807b5f81216cac4e5425381a95fd75ea00758d5963b1de16e6f872457d77c27128559cb4ceb977e92b11890d5a8dfeedff8ab820a268501dcd6500082ca8f946f259637dcd74c767781e37bc6133cd6a68aa16180b844a9059cbb00000000000000000000000089997319c1350af9cd24a84fd41f6786bdd985b00000000000000000000000000000000000000000000000000de0b6b3a764000026a03891a150e5488b9c16e14d7bb66ea550029f43db91310ac5d8e1c5a416448e5da023be5ead4a1d12114f3fb6d9f58271903281df05f7002f07dfb0fc262ea00dadf8ab820a278501dcd6500082ca8f946f259637dcd74c767781e37bc6133cd6a68aa16180b844a9059cbb0000000000000000000000009fea9854d48655d830d66819983a1793430b2b590000000000000000000000000000000000000000000000000de0b6b3a764000025a02e53fc2de677cd051e954d9ebec9ca7db7b248d39e7432bc397546fca21e438aa0750010f13b411b3d5bf80f936c2201ffe075d7d6755dbec68489ca2f6fe6084ef8ab820a288501dcd6500082ca4f946f259637dcd74c767781e37bc6133cd6a68aa16180b844a9059cbb0000000000000000000000002bd4af55f12b86e1f2f00068d92ee34fe1d2f6c10000000000000000000000000000000000000000000000000de0b6b3a764000025a067d7b75c838db2ea807e1060ffedd61bfefaa8de5a84ebb2a586a7442f4ca190a07128e74bbb58a97b857fd2cf364c2885d6e35cbc8d0df9027d08198694a6e4d0f8ab820a298501dcd6500082ca8f946f259637dcd74c767781e37bc6133cd6a68aa16180b844a9059cbb000000000000000000000000238ad34dcd7f049a8a85aecdb6b6a18d094220be0000000000000000000000000000000000000000000000000de0b6b3a764000026a079fcafbeeedbecae31a70e56c386c2da78556b6e8d4370eed1da85c2c3da8130a00e685d3a5afda668a9e89764eb1225de3ee4c510ae0fc550d3aaac5d635ed65af8ab820a2a8501dcd6500082ca8f946f259637dcd74c767781e37bc6133cd6a68aa16180b844a9059cbb00000000000000000000000006381059d6b5db97a8c73ad668973d6e85a6de840000000000000000000000000000000000000000000000000de0b6b3a764000025a08748f823480daf9ebfd9ec01463ec22b825e3c37ebba48876005c01d30450428a005fbfdec03fc8114b10ed4eb319e0d2d6fb9b43fb7578c2dbefb13c4d3419099f8ab820a2b8501dcd6500082ca8f946f259637dcd74c767781e37bc6133cd6a68aa16180b844a9059cbb00000000000000000000000014f8392a7fedcf8e40cbde99dc3b5629ae6a887c0000000000000000000000000000000000000000000000000de0b6b3a764000026a0da1e5fee3bab46f642b1e0c33b13f9b017ed967917969a6f278dac4f8d01a85da002ea288e9f0dd7138c2c2602b3f1836c0bcc379eb3662e45d0737a809bce1e0bf8ab820a2c8501dcd6500082ca8f946f259637dcd74c767781e37bc6133cd6a68aa16180b844a9059cbb000000000000000000000000fef76c4de9a9d591056cd26ed58478e392c9e1660000000000000000000000000000000000000000000000000de0b6b3a764000025a09609b8ab63a2648b016cb475a3b334b716e1eeb59637fd627348ad92f8e44157a07a27c3484330f4175636e598d1c6c449c786ee0ce56c49bacdfc2946ad85d7c7c0"));
System.out.println("Size of encoded block: " + Block.MemEstimator.estimateSize(b));
b.getNumber();
System.out.println("Size of parsed block: " + Block.MemEstimator.estimateSize(b));
b.getTransactionsList().forEach(Transaction::getSender);
System.out.println("Size of parsed block with parsed txes: " + Block.MemEstimator.estimateSize(b));
}
}
| 62,584
| 291.453271
| 51,686
|
java
|
ethereumj
|
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/core/ImportTest.java
|
/*
* Copyright (c) [2016] [ <ether.camp> ]
* This file is part of the ethereumJ library.
*
* The ethereumJ library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The ethereumJ library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the ethereumJ library. If not, see <http://www.gnu.org/licenses/>.
*/
package org.ethereum.core;
import org.ethereum.config.NoAutoscan;
import org.ethereum.config.SystemProperties;
import org.ethereum.datasource.inmem.HashMapDB;
import org.ethereum.db.BlockStore;
import org.ethereum.db.IndexedBlockStore;
import org.ethereum.manager.WorldManager;
import org.junit.AfterClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.spongycastle.util.encoders.Hex;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.support.AnnotationConfigContextLoader;
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.List;
import static org.junit.Assert.assertEquals;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(loader = AnnotationConfigContextLoader.class)
@NoAutoscan
public class ImportTest {
private static final Logger logger = LoggerFactory.getLogger("test");
@Configuration
@ComponentScan(basePackages = "org.ethereum")
@NoAutoscan
static class ContextConfiguration {
@Bean
public BlockStore blockStore(){
IndexedBlockStore blockStore = new IndexedBlockStore();
blockStore.init(new HashMapDB<byte[]>(), new HashMapDB<byte[]>());
return blockStore;
}
}
@Autowired
WorldManager worldManager;
@AfterClass
public static void close(){
// FileUtil.recursiveDelete(CONFIG.databaseDir());
}
@Ignore
@Test
public void testScenario1() throws URISyntaxException, IOException {
BlockchainImpl blockchain = (BlockchainImpl) worldManager.getBlockchain();
logger.info("Running as: {}", SystemProperties.getDefault().genesisInfo());
URL scenario1 = ClassLoader
.getSystemResource("blockload/scenario1.dmp");
File file = new File(scenario1.toURI());
List<String> strData = Files.readAllLines(file.toPath(), StandardCharsets.UTF_8);
byte[] root = Genesis.getInstance().getStateRoot();
for (String blockRLP : strData) {
Block block = new Block(
Hex.decode(blockRLP));
logger.info("sending block.hash: {}", Hex.toHexString(block.getHash()));
blockchain.tryToConnect(block);
root = block.getStateRoot();
}
Repository repository = (Repository)worldManager.getRepository();
logger.info("asserting root state is: {}", Hex.toHexString(root));
assertEquals(Hex.toHexString(root),
Hex.toHexString(repository.getRoot()));
}
}
| 3,863
| 33.19469
| 89
|
java
|
ethereumj
|
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/core/genesis/GenesisLoadTest.java
|
/*
* Copyright (c) [2016] [ <ether.camp> ]
* This file is part of the ethereumJ library.
*
* The ethereumJ library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The ethereumJ library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the ethereumJ library. If not, see <http://www.gnu.org/licenses/>.
*/
package org.ethereum.core.genesis;
import com.typesafe.config.Config;
import com.typesafe.config.ConfigFactory;
import com.typesafe.config.ConfigValueFactory;
import org.ethereum.config.BlockchainNetConfig;
import org.ethereum.config.SystemProperties;
import org.ethereum.config.blockchain.*;
import org.ethereum.core.Genesis;
import org.ethereum.util.FastByteComparisons;
import org.ethereum.util.blockchain.StandaloneBlockchain;
import static org.ethereum.util.FastByteComparisons.equal;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.*;
import org.junit.Test;
import org.spongycastle.util.encoders.Hex;
import java.io.File;
import java.math.BigInteger;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Path;
/**
* Testing system exit
* http://stackoverflow.com/questions/309396/java-how-to-test-methods-that-call-system-exit
*
* Created by Stan Reshetnyk on 17.09.16.
*/
public class GenesisLoadTest {
@Test
public void shouldLoadGenesis_whenShortWay() {
loadGenesis(null, "frontier-test.json");
assertTrue(true);
}
@Test
public void shouldLoadGenesis_whenFullPathSpecified() throws URISyntaxException {
URL url = GenesisLoadTest.class.getClassLoader().getResource("genesis/frontier-test.json");
// full path
System.out.println("url.getPath() " + url.getPath());
loadGenesis(url.getPath(), null);
Path path = new File(url.toURI()).toPath();
Path curPath = new File("").getAbsoluteFile().toPath();
String relPath = curPath.relativize(path).toFile().getPath();
System.out.println("Relative path: " + relPath);
loadGenesis(relPath, null);
assertTrue(true);
}
@Test
public void shouldLoadGenesisFromFile_whenBothSpecified() {
URL url = GenesisLoadTest.class.getClassLoader().getResource("genesis/frontier-test.json");
// full path
System.out.println("url.getPath() " + url.getPath());
loadGenesis(url.getPath(), "NOT_EXIST");
assertTrue(true);
}
@Test(expected = RuntimeException.class)
public void shouldError_whenWrongPath() {
loadGenesis("NON_EXISTED_PATH", null);
assertTrue(false);
}
@Test
public void shouldLoadGenesis_whenManyOrderedConfigs() {
SystemProperties properties = loadGenesis(null, "genesis-with-config.json");
properties.getGenesis();
BlockchainNetConfig bnc = properties.getBlockchainConfig();
assertThat(bnc.getConfigForBlock(0), instanceOf(FrontierConfig.class));
assertThat(bnc.getConfigForBlock(149), instanceOf(FrontierConfig.class));
assertThat(bnc.getConfigForBlock(150), instanceOf(HomesteadConfig.class));
assertThat(bnc.getConfigForBlock(299), instanceOf(HomesteadConfig.class));
assertThat(bnc.getConfigForBlock(300), instanceOf(DaoHFConfig.class));
assertThat(bnc.getConfigForBlock(300), instanceOf(DaoHFConfig.class));
DaoHFConfig daoHFConfig = (DaoHFConfig) bnc.getConfigForBlock(300);
assertThat(bnc.getConfigForBlock(450), instanceOf(Eip150HFConfig.class));
assertThat(bnc.getConfigForBlock(10_000_000), instanceOf(Eip150HFConfig.class));
}
@Test
public void shouldLoadGenesis_withCodeAndNonceInAlloc() {
final Genesis genesis = GenesisLoader.loadGenesis(
getClass().getResourceAsStream("/genesis/genesis-alloc.json"));
final StandaloneBlockchain bc = new StandaloneBlockchain();
bc.withGenesis(genesis);
final byte[] account = Hex.decode("cd2a3d9f938e13cd947ec05abc7fe734df8dd826");
byte[] expectedCode = Hex.decode("00ff00");
long expectedNonce = 255; //FF
final BigInteger actualNonce = bc.getBlockchain().getRepository().getNonce(account);
final byte[] actualCode = bc.getBlockchain().getRepository().getCode(account);
assertEquals(BigInteger.valueOf(expectedNonce), actualNonce);
assertTrue(equal(expectedCode, actualCode));
}
@Test
public void shouldLoadGenesis_withSameBlockManyConfigs() {
SystemProperties properties = loadGenesis(null, "genesis-alloc.json");
properties.getGenesis();
BlockchainNetConfig bnc = properties.getBlockchainConfig();
assertThat(bnc.getConfigForBlock(0), instanceOf(FrontierConfig.class));
assertThat(bnc.getConfigForBlock(1999), instanceOf(FrontierConfig.class));
assertThat(bnc.getConfigForBlock(2000), instanceOf(Eip160HFConfig.class));
assertThat(bnc.getConfigForBlock(10_000_000), instanceOf(Eip160HFConfig.class));
// check DAO extradata for mining
final byte[] SOME_EXTRA_DATA = "some-extra-data".getBytes();
final byte[] inDaoForkExtraData = bnc.getConfigForBlock(2000).getExtraData(SOME_EXTRA_DATA, 2000);
final byte[] pastDaoForkExtraData = bnc.getConfigForBlock(2200).getExtraData(SOME_EXTRA_DATA, 2200);
assertTrue(FastByteComparisons.equal(AbstractDaoConfig.DAO_EXTRA_DATA, inDaoForkExtraData));
assertTrue(FastByteComparisons.equal(SOME_EXTRA_DATA, pastDaoForkExtraData));
}
private SystemProperties loadGenesis(String genesisFile, String genesisResource) {
Config config = ConfigFactory.empty();
if (genesisResource != null) {
config = config.withValue("genesis",
ConfigValueFactory.fromAnyRef(genesisResource));
}
if (genesisFile != null) {
config = config.withValue("genesisFile",
ConfigValueFactory.fromAnyRef(genesisFile));
}
SystemProperties properties = new SystemProperties(config);
properties.getGenesis();
return properties;
}
}
| 6,641
| 38.535714
| 108
|
java
|
ethereumj
|
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/config/DaoLightMiningTest.java
|
/*
* Copyright (c) [2016] [ <ether.camp> ]
* This file is part of the ethereumJ library.
*
* The ethereumJ library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The ethereumJ library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the ethereumJ library. If not, see <http://www.gnu.org/licenses/>.
*/
package org.ethereum.config;
import org.ethereum.config.blockchain.DaoHFConfig;
import org.ethereum.config.blockchain.DaoNoHFConfig;
import org.ethereum.config.blockchain.FrontierConfig;
import org.ethereum.config.net.BaseNetConfig;
import org.ethereum.core.Block;
import org.ethereum.util.blockchain.StandaloneBlockchain;
import org.junit.Test;
import java.math.BigInteger;
import static org.junit.Assert.*;
/**
* Created by Stan Reshetnyk on 29.12.16.
*/
public class DaoLightMiningTest {
// configure
final int FORK_BLOCK = 20;
final int FORK_BLOCK_AFFECTED = 10; // hardcoded in DAO config
@Test
public void testDaoExtraData() {
final StandaloneBlockchain sb = createBlockchain(true);
for (int i = 0; i < FORK_BLOCK + 30; i++) {
Block b = sb.createBlock();
// System.out.println("Created block " + b.getNumber() + " " + getData(b.getExtraData()));
}
assertEquals("EthereumJ powered", getData(sb, FORK_BLOCK - 1));
assertEquals("dao-hard-fork", getData(sb, FORK_BLOCK));
assertEquals("dao-hard-fork", getData(sb, FORK_BLOCK + FORK_BLOCK_AFFECTED - 1));
assertEquals("EthereumJ powered", getData(sb, FORK_BLOCK + FORK_BLOCK_AFFECTED));
}
@Test
public void testNoDaoExtraData() {
final StandaloneBlockchain sb = createBlockchain(false);
for (int i = 0; i < FORK_BLOCK + 30; i++) {
Block b = sb.createBlock();
}
assertEquals("EthereumJ powered", getData(sb, FORK_BLOCK - 1));
assertEquals("", getData(sb, FORK_BLOCK));
assertEquals("", getData(sb, FORK_BLOCK + FORK_BLOCK_AFFECTED - 1));
assertEquals("EthereumJ powered", getData(sb, FORK_BLOCK + FORK_BLOCK_AFFECTED));
}
private String getData(StandaloneBlockchain sb, long blockNumber) {
return new String(sb.getBlockchain().getBlockByNumber(blockNumber).getExtraData());
}
private StandaloneBlockchain createBlockchain(boolean proFork) {
final BaseNetConfig netConfig = new BaseNetConfig();
final BlockchainConfig c1 = StandaloneBlockchain.getEasyMiningConfig();
netConfig.add(0, StandaloneBlockchain.getEasyMiningConfig());
netConfig.add(FORK_BLOCK, proFork ? new DaoHFConfig(c1, FORK_BLOCK) : new DaoNoHFConfig(c1, FORK_BLOCK));
// create blockchain
return new StandaloneBlockchain()
.withAutoblock(true)
.withNetConfig(netConfig);
}
}
| 3,285
| 36.770115
| 113
|
java
|
ethereumj
|
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/config/ConfigTest.java
|
/*
* Copyright (c) [2016] [ <ether.camp> ]
* This file is part of the ethereumJ library.
*
* The ethereumJ library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The ethereumJ library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the ethereumJ library. If not, see <http://www.gnu.org/licenses/>.
*/
package org.ethereum.config;
import com.typesafe.config.*;
import org.junit.Assert;
import org.junit.Test;
import java.io.File;
import java.util.List;
import java.util.Map;
/**
* Created by Anton Nashatyrev on 13.07.2015.
*/
public class ConfigTest {
@Test
public void simpleTest() {
Config config = ConfigFactory.parseResources("ethereumj.conf");
System.out.println(config.root().render(ConfigRenderOptions.defaults().setComments(false)));
for (Map.Entry<String, ConfigValue> entry : config.entrySet()) {
// System.out.println("Name: " + entry.getKey());
// System.out.println(entry);
}
System.out.println("peer.listen.port: " + config.getInt("peer.listen.port"));
System.out.println("peer.discovery.ip.list: " + config.getAnyRefList("peer.discovery.ip.list"));
System.out.println("peer.discovery.ip.list: " + config.getAnyRefList("peer.active"));
List<? extends ConfigObject> list = config.getObjectList("peer.active");
for (ConfigObject configObject : list) {
if (configObject.get("url") != null) {
System.out.println("URL: " + configObject.get("url"));
}
if (configObject.get("ip") != null) {
System.out.println("IP: " + configObject);
}
}
System.out.println("blocks.loader = " + config.hasPath("blocks.loader"));
System.out.println("blocks.loader = " + config.getAnyRef("blocks.loader"));
}
@Test
public void fallbackTest() {
System.setProperty("blocks.loader", "bla-bla");
Config config = ConfigFactory.load("ethereumj.conf");
// Ignore this assertion since the SystemProperties are loaded by the static initializer
// so if the ConfigFactory was used prior to this test the setProperty() has no effect
// Assert.assertEquals("bla-bla", config.getString("blocks.loader"));
String string = config.getString("keyvalue.datasource");
Assert.assertNotNull(string);
Config overrides = ConfigFactory.parseString("blocks.loader=another, peer.active=[{url=sdfsfd}]");
Config merged = overrides.withFallback(config);
Assert.assertEquals("another", merged.getString("blocks.loader"));
Assert.assertTrue(merged.getObjectList("peer.active").size() == 1);
Assert.assertNotNull(merged.getString("keyvalue.datasource"));
Config emptyConf = ConfigFactory.parseFile(new File("nosuchfile.conf"), ConfigParseOptions.defaults());
Assert.assertFalse(emptyConf.hasPath("blocks.loader"));
}
@Test
public void ethereumjConfTest() {
System.out.println("'" + SystemProperties.getDefault().databaseDir() + "'");
System.out.println(SystemProperties.getDefault().peerActive());
}
}
| 3,621
| 42.119048
| 111
|
java
|
ethereumj
|
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/config/DefaultConfigTest.java
|
/*
* Copyright (c) [2017] [ <ether.camp> ]
* This file is part of the ethereumJ library.
*
* The ethereumJ library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The ethereumJ library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the ethereumJ library. If not, see <http://www.gnu.org/licenses/>.
*
*
*/
package org.ethereum.config;
import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.classic.spi.IThrowableProxy;
import ch.qos.logback.core.read.ListAppender;
import org.ethereum.db.PruneManager;
import org.junit.Test;
import org.slf4j.LoggerFactory;
import java.util.List;
import java.util.concurrent.Executors;
import static org.junit.Assert.*;
public class DefaultConfigTest {
/**
* TODO: For better testability, consider making setDefaultUncaughtExceptionHandler pluggable or Spring configurable as an autowired list
*/
@Test
public void testConstruction() throws InterruptedException {
ListAppender<ILoggingEvent> inMemoryAppender = new ListAppender<>();
inMemoryAppender.start();
Logger logger = (Logger) LoggerFactory.getLogger("general");
try {
logger.setLevel(Level.DEBUG);
logger.addAppender(inMemoryAppender);
// Registers the safety net
new DefaultConfig();
// Trigger an exception in the background
Executors.newSingleThreadExecutor().execute(new ExceptionThrower());
Thread.sleep(600);
ILoggingEvent firstException = inMemoryAppender.list.get(0);
assertEquals("Uncaught exception", firstException.getMessage());
IThrowableProxy cause = firstException.getThrowableProxy();
assertEquals("Unit test throwing an exception", cause.getMessage());
} finally {
inMemoryAppender.stop();
logger.detachAppender(inMemoryAppender);
}
}
@Test
public void testNoopPruneManager() throws Exception {
DefaultConfig defaultConfig = new DefaultConfig();
defaultConfig.config = new SystemProperties();
defaultConfig.config.overrideParams("database.prune.enabled", "false");
PruneManager noopPruneManager = defaultConfig.pruneManager();
// Should throw exception unless this is a NOOP prune manager
noopPruneManager.blockCommitted(null);
}
private static class ExceptionThrower implements Runnable {
@Override
public void run() {
throw new IllegalStateException("Unit test throwing an exception");
}
}
}
| 3,129
| 35.395349
| 141
|
java
|
ethereumj
|
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/config/GenerateNodeIdRandomlyTest.java
|
/*
* Copyright (c) [2017] [ <ether.camp> ]
* This file is part of the ethereumJ library.
*
* The ethereumJ library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The ethereumJ library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the ethereumJ library. If not, see <http://www.gnu.org/licenses/>.
*/
package org.ethereum.config;
import org.junit.Test;
import org.springframework.util.FileCopyUtils;
import org.springframework.util.StringUtils;
import javax.annotation.concurrent.NotThreadSafe;
import java.io.File;
import java.io.FileReader;
import static org.junit.Assert.*;
/**
* Not thread safe - testGeneratedNodePrivateKey temporarily removes the nodeId.properties
* file which may influence other tests.
*/
@SuppressWarnings("ConstantConditions")
@NotThreadSafe
public class GenerateNodeIdRandomlyTest {
@Test
public void testGenerateNodeIdRandomlyCreatesFileWithNodeIdAndPrivateKey() throws Exception {
File nodeIdPropertiesFile = new File("database-test/nodeId.properties");
//Cleanup previous nodeId.properties file (if exists)
//noinspection ResultOfMethodCallIgnored
nodeIdPropertiesFile.delete();
new GenerateNodeIdRandomly("database-test").getNodePrivateKey();
assertTrue(nodeIdPropertiesFile.exists());
String contents = FileCopyUtils.copyToString(new FileReader(nodeIdPropertiesFile));
String[] lines = StringUtils.tokenizeToStringArray(contents, "\n");
assertEquals(4, lines.length);
assertTrue(lines[0].startsWith("#Generated NodeID."));
assertTrue(lines[1].startsWith("#"));
assertTrue(lines[2].startsWith("nodeIdPrivateKey="));
assertEquals("nodeIdPrivateKey=".length() + 64, lines[2].length());
assertTrue(lines[3].startsWith("nodeId="));
assertEquals("nodeId=".length() + 128, lines[3].length());
//noinspection ResultOfMethodCallIgnored
nodeIdPropertiesFile.delete();
}
}
| 2,444
| 37.809524
| 97
|
java
|
ethereumj
|
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/config/SystemPropertiesTest.java
|
/*
* Copyright (c) [2016] [ <ether.camp> ]
* This file is part of the ethereumJ library.
*
* The ethereumJ library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The ethereumJ library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the ethereumJ library. If not, see <http://www.gnu.org/licenses/>.
*/
package org.ethereum.config;
import com.typesafe.config.Config;
import com.typesafe.config.ConfigFactory;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.RandomUtils;
import org.ethereum.config.blockchain.OlympicConfig;
import org.ethereum.config.net.*;
import org.ethereum.core.AccountState;
import org.ethereum.core.Genesis;
import org.ethereum.db.ByteArrayWrapper;
import org.ethereum.net.rlpx.Node;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.spongycastle.util.encoders.Hex;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.util.FileCopyUtils;
import org.springframework.util.StringUtils;
import javax.annotation.concurrent.NotThreadSafe;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.math.BigInteger;
import java.net.InetAddress;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import static com.google.common.collect.Lists.newArrayList;
import static junit.framework.TestCase.assertNotNull;
import static org.junit.Assert.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
/**
* Not thread safe - testUseOnlySprintConfig temporarily sets a static flag that may influence other tests.
* Not thread safe - testGeneratedNodePrivateKey temporarily removes the nodeId.properties file which may influence other tests.
*/
@SuppressWarnings("ConstantConditions")
@NotThreadSafe
public class SystemPropertiesTest {
private final static Logger logger = LoggerFactory.getLogger(SystemPropertiesTest.class);
@Test
public void testPunchBindIp() {
SystemProperties.getDefault().overrideParams("peer.bind.ip", "");
long st = System.currentTimeMillis();
String ip = SystemProperties.getDefault().bindIp();
long t = System.currentTimeMillis() - st;
logger.info(ip + " in " + t + " msec");
Assert.assertTrue(t < 10 * 1000);
Assert.assertFalse(ip.isEmpty());
}
@Test
public void testExternalIp() {
SystemProperties.getDefault().overrideParams("peer.discovery.external.ip", "");
long st = System.currentTimeMillis();
String ip = SystemProperties.getDefault().externalIp();
long t = System.currentTimeMillis() - st;
logger.info(ip + " in " + t + " msec");
Assert.assertTrue(t < 10 * 1000);
Assert.assertFalse(ip.isEmpty());
}
@Test
public void testExternalIpWhenSpecificallyConfigured() {
SystemProperties props = SystemProperties.getDefault();
props.overrideParams("peer.discovery.external.ip", "1.1.1.1");
assertEquals("1.1.1.1", props.externalIp());
props.overrideParams("peer.discovery.external.ip", "no_validation_rules_on_this_value");
assertEquals("no_validation_rules_on_this_value", props.externalIp());
}
@Test
public void testBlockchainNetConfig() {
assertConfigNameResolvesToType("main", MainNetConfig.class);
assertConfigNameResolvesToType("olympic", OlympicConfig.class);
assertConfigNameResolvesToType("morden", MordenNetConfig.class);
assertConfigNameResolvesToType("ropsten", RopstenNetConfig.class);
assertConfigNameResolvesToType("testnet", TestNetConfig.class);
}
private <T extends BlockchainNetConfig> void assertConfigNameResolvesToType(String configName, Class<T> expectedConfigType) {
SystemProperties props = new SystemProperties();
props.overrideParams("blockchain.config.name", configName);
BlockchainNetConfig blockchainConfig = props.getBlockchainConfig();
assertTrue(blockchainConfig.getClass().isAssignableFrom(expectedConfigType));
}
@Test
public void testConfigNamesAreCaseSensitive() {
assertConfigNameIsUnsupported("mAin");
assertConfigNameIsUnsupported("Main");
}
@Test
public void testGarbageConfigNamesTriggerExceptions() {
assertConfigNameIsUnsupported("\t");
assertConfigNameIsUnsupported("\n");
assertConfigNameIsUnsupported("");
assertConfigNameIsUnsupported("fake");
}
private void assertConfigNameIsUnsupported(String configName) {
try {
SystemProperties props = new SystemProperties();
props.overrideParams("blockchain.config.name", configName);
props.getBlockchainConfig();
fail("Should throw error for unsupported config name " + configName);
} catch (Exception e) {
assertEquals("Unknown value for 'blockchain.config.name': '" + configName + "'", e.getMessage());
}
}
@Test
public void testUseOnlySprintConfig() {
boolean originalValue = SystemProperties.isUseOnlySpringConfig();
try {
SystemProperties.setUseOnlySpringConfig(false);
assertNotNull(SystemProperties.getDefault());
SystemProperties.setUseOnlySpringConfig(true);
assertNull(SystemProperties.getDefault());
} finally {
SystemProperties.setUseOnlySpringConfig(originalValue);
}
}
@Test
public void testValidateMeAnnotatedGetters() {
assertIncorrectValueTriggersConfigException("peer.discovery.enabled", "not_a_boolean");
assertIncorrectValueTriggersConfigException("peer.discovery.persist", "not_a_boolean");
assertIncorrectValueTriggersConfigException("peer.discovery.workers", "not_a_number");
assertIncorrectValueTriggersConfigException("peer.discovery.touchPeriod", "not_a_number");
assertIncorrectValueTriggersConfigException("peer.connection.timeout", "not_a_number");
assertIncorrectValueTriggersConfigException("peer.p2p.version", "not_a_number");
assertIncorrectValueTriggersConfigException("peer.p2p.framing.maxSize", "not_a_number");
assertIncorrectValueTriggersConfigException("transaction.approve.timeout", "not_a_number");
assertIncorrectValueTriggersConfigException("peer.discovery.ip.list", "not_a_ip");
assertIncorrectValueTriggersConfigException("database.reset", "not_a_boolean");
assertIncorrectValueTriggersConfigException("database.resetBlock", "not_a_number");
assertIncorrectValueTriggersConfigException("database.prune.enabled", "not_a_boolean");
assertIncorrectValueTriggersConfigException("database.resetBlock", "not_a_number");
}
private void assertIncorrectValueTriggersConfigException(String... keyValuePairs) {
try {
new SystemProperties().overrideParams(keyValuePairs);
fail("Should've thrown ConfigException");
} catch (Exception ignore) {
}
}
@Test
public void testDatabasePruneShouldAdhereToMax() {
SystemProperties props = new SystemProperties();
props.overrideParams("database.prune.enabled", "false");
assertEquals("When database.prune.maxDepth is not set, defaults to -1", -1, props.databasePruneDepth());
props.overrideParams("database.prune.enabled", "true", "database.prune.maxDepth", "42");
assertEquals(42, props.databasePruneDepth());
}
@Test
public void testRequireEitherNameOrClassConfiguration() {
try {
SystemProperties props = new SystemProperties();
props.overrideParams("blockchain.config.name", "test", "blockchain.config.class", "org.ethereum.config.net.TestNetConfig");
props.getBlockchainConfig();
fail("Should've thrown exception because not 'Only one of two options should be defined'");
} catch (RuntimeException e) {
assertEquals("Only one of two options should be defined: 'blockchain.config.name' and 'blockchain.config.class'", e.getMessage());
}
}
@Test
public void testRequireTypeBlockchainNetConfigOnManualClass() {
SystemProperties props = new SystemProperties();
props.overrideParams("blockchain.config.name", null, "blockchain.config.class", "org.ethereum.config.net.TestNetConfig");
assertTrue(props.getBlockchainConfig().getClass().isAssignableFrom(TestNetConfig.class));
}
@Test
public void testNonExistentBlockchainNetConfigClass() {
SystemProperties props = new SystemProperties();
try {
props.overrideParams("blockchain.config.name", null, "blockchain.config.class", "org.ethereum.config.net.NotExistsConfig");
props.getBlockchainConfig();
fail("Should throw exception for invalid class");
} catch (RuntimeException expected) {
assertEquals("The class specified via blockchain.config.class 'org.ethereum.config.net.NotExistsConfig' not found", expected.getMessage());
}
}
@Test
public void testNotInstanceOfBlockchainForkConfig() {
SystemProperties props = new SystemProperties(ConfigFactory.empty(), getClass().getClassLoader());
try {
props.overrideParams("blockchain.config.name", null, "blockchain.config.class", "org.ethereum.config.NodeFilter");
props.getBlockchainConfig();
fail("Should throw exception for invalid class");
} catch (RuntimeException expected) {
assertEquals("The class specified via blockchain.config.class 'org.ethereum.config.NodeFilter' is not instance of org.ethereum.config.BlockchainForkConfig", expected.getMessage());
}
}
@Test
public void testEmptyListOnEmptyPeerActiveConfiguration() {
SystemProperties props = new SystemProperties();
props.overrideParams("peer.active", null);
assertEquals(newArrayList(), props.peerActive());
}
@Test
public void testPeerActive() {
ActivePeer node1 = ActivePeer.asEnodeUrl("node-1", "1.1.1.1");
ActivePeer node2 = ActivePeer.asNode("node-2", "2.2.2.2");
Config config = createActivePeersConfig(node1, node2);
SystemProperties props = new SystemProperties();
props.overrideParams(config);
List<Node> activePeers = props.peerActive();
assertEquals(2, activePeers.size());
}
@Test
public void testRequire64CharsNodeId() {
assertInvalidNodeId(RandomStringUtils.randomAlphanumeric(63));
assertInvalidNodeId(RandomStringUtils.randomAlphanumeric(1));
assertInvalidNodeId(RandomStringUtils.randomAlphanumeric(65));
}
private void assertInvalidNodeId(String nodeId) {
String hexEncodedNodeId = Hex.toHexString(nodeId.getBytes());
ActivePeer nodeWithInvalidNodeId = ActivePeer.asNodeWithId("node-1", "1.1.1.1", hexEncodedNodeId);
Config config = createActivePeersConfig(nodeWithInvalidNodeId);
SystemProperties props = new SystemProperties();
try {
props.overrideParams(config);
fail("Should've thrown exception for invalid node id");
} catch (RuntimeException ignore) { }
}
@Test
public void testUnexpectedElementInNodeConfigThrowsException() {
String nodeWithUnexpectedElement = "peer = {" +
"active = [{\n" +
" port = 30303\n" +
" nodeName = Test\n" +
" unexpectedElement = 12345\n" +
"}]}";
Config invalidConfig = ConfigFactory.parseString(nodeWithUnexpectedElement);
SystemProperties props = new SystemProperties();
try {
props.overrideParams(invalidConfig);
} catch (RuntimeException ignore) { }
}
@Test
public void testActivePeersUsingNodeName() {
ActivePeer node = ActivePeer.asNodeWithName("node-1", "1.1.1.1", "peer-1");
Config config = createActivePeersConfig(node);
SystemProperties props = new SystemProperties();
props.overrideParams(config);
List<Node> activePeers = props.peerActive();
assertEquals(1, activePeers.size());
Node peer = activePeers.get(0);
String expectedKeccak512HashOfNodeName = "fcaf073315aa0fe284dd6d76200ede5cc9277f3cb1fd7649ddab3b6a61e96ee91e957" +
"0b14932be6d6cd837027d50d9521923962909e5a9fdcdcabc3fe29408bb";
String actualHexEncodedId = Hex.toHexString(peer.getId());
assertEquals(expectedKeccak512HashOfNodeName, actualHexEncodedId);
}
@Test
public void testRequireEitherNodeNameOrNodeId() {
ActivePeer node = ActivePeer.asNodeWithName("node-1", "1.1.1.1", null);
Config config = createActivePeersConfig(node);
SystemProperties props = new SystemProperties();
try {
props.overrideParams(config);
fail("Should require either nodeName or nodeId");
} catch (RuntimeException ignore) { }
}
private static Config createActivePeersConfig(ActivePeer... activePeers) {
StringBuilder config = new StringBuilder("peer = {");
config.append(" active =[");
for (int i = 0; i < activePeers.length; i++) {
ActivePeer activePeer = activePeers[i];
config.append(activePeer.toString());
if (i < activePeers.length - 1) {
config.append(",");
}
}
config.append(" ]");
config.append("}");
return ConfigFactory.parseString(config.toString());
}
@Test
public void testPeerTrusted() throws Exception{
TrustedPeer peer1 = TrustedPeer.asNode("node-1", "1.1.1.1");
TrustedPeer peer2 = TrustedPeer.asNode("node-2", "2.1.1.*");
TrustedPeer peer3 = TrustedPeer.asNode("node-2", "3.*");
Config config = createTrustedPeersConfig(peer1, peer2, peer3);
SystemProperties props = new SystemProperties();
props.overrideParams(config);
NodeFilter filter = props.peerTrusted();
assertTrue(filter.accept(InetAddress.getByName("1.1.1.1")));
assertTrue(filter.accept(InetAddress.getByName("2.1.1.1")));
assertTrue(filter.accept(InetAddress.getByName("2.1.1.9")));
assertTrue(filter.accept(InetAddress.getByName("3.1.1.1")));
assertTrue(filter.accept(InetAddress.getByName("3.1.1.9")));
assertTrue(filter.accept(InetAddress.getByName("3.9.1.9")));
assertFalse(filter.accept(InetAddress.getByName("4.1.1.1")));
}
private static Config createTrustedPeersConfig(TrustedPeer... trustedPeers) {
StringBuilder config = new StringBuilder("peer = {");
config.append(" trusted =[");
for (int i = 0; i < trustedPeers.length; i++) {
TrustedPeer activePeer = trustedPeers[i];
config.append(activePeer.toString());
if (i < trustedPeers.length - 1) {
config.append(",");
}
}
config.append(" ]");
config.append("}");
return ConfigFactory.parseString(config.toString());
}
@Test
public void testRequire64CharsPrivateKey() {
assertInvalidPrivateKey(RandomUtils.nextBytes(1));
assertInvalidPrivateKey(RandomUtils.nextBytes(31));
assertInvalidPrivateKey(RandomUtils.nextBytes(33));
assertInvalidPrivateKey(RandomUtils.nextBytes(64));
assertInvalidPrivateKey(RandomUtils.nextBytes(0));
String validPrivateKey = Hex.toHexString(RandomUtils.nextBytes(32));
SystemProperties props = new SystemProperties();
props.overrideParams("peer.privateKey", validPrivateKey);
assertEquals(validPrivateKey, props.privateKey());
}
private void assertInvalidPrivateKey(byte[] privateKey) {
String hexEncodedPrivateKey = Hex.toHexString(privateKey);
SystemProperties props = new SystemProperties();
try {
props.overrideParams("peer.privateKey", hexEncodedPrivateKey);
props.privateKey();
fail("Should've thrown exception for invalid private key");
} catch (RuntimeException ignore) { }
}
@Test
public void testExposeBugWhereNonHexEncodedIsAcceptedWithoutValidation() {
SystemProperties props = new SystemProperties();
String nonHexEncoded = RandomStringUtils.randomAlphanumeric(64);
try {
props.overrideParams("peer.privateKey", nonHexEncoded);
props.privateKey();
fail("Should've thrown exception for invalid private key");
} catch (RuntimeException ignore) { }
}
/**
* TODO: Consider using a strategy interface for #getGeneratedNodePrivateKey().
* Anything 'File' and 'random' generation are difficult to test and assert
*/
@Test
public void testGeneratedNodePrivateKeyThroughECKey() throws Exception {
File outputFile = new File("database-test/nodeId.properties");
//noinspection ResultOfMethodCallIgnored
outputFile.delete();
SystemProperties props = new SystemProperties();
props.privateKey();
assertTrue(outputFile.exists());
String contents = FileCopyUtils.copyToString(new FileReader(outputFile));
String[] lines = StringUtils.tokenizeToStringArray(contents, "\n");
assertEquals(4, lines.length);
assertTrue(lines[0].startsWith("#Generated NodeID."));
assertTrue(lines[1].startsWith("#"));
assertTrue(lines[2].startsWith("nodeIdPrivateKey="));
assertEquals("nodeIdPrivateKey=".length() + 64, lines[2].length());
assertTrue(lines[3].startsWith("nodeId="));
assertEquals("nodeId=".length() + 128, lines[3].length());
}
@Test
public void testGeneratedNodePrivateKeyDelegatesToStrategy() {
File outputFile = new File("database-test/nodeId.properties");
//noinspection ResultOfMethodCallIgnored
outputFile.delete();
GenerateNodeIdStrategy generateNodeIdStrategyMock = mock(GenerateNodeIdStrategy.class);
SystemProperties props = new SystemProperties();
props.setGenerateNodeIdStrategy(generateNodeIdStrategyMock);
props.privateKey();
verify(generateNodeIdStrategyMock).getNodePrivateKey();
}
@Test
public void testFastSyncPivotBlockHash() {
SystemProperties props = new SystemProperties();
assertNull(props.getFastSyncPivotBlockHash());
byte[] validPivotBlockHash = RandomUtils.nextBytes(32);
props.overrideParams("sync.fast.pivotBlockHash", Hex.toHexString(validPivotBlockHash));
assertTrue(Arrays.equals(validPivotBlockHash, props.getFastSyncPivotBlockHash()));
assertInvalidPivotBlockHash(RandomUtils.nextBytes(0));
assertInvalidPivotBlockHash(RandomUtils.nextBytes(1));
assertInvalidPivotBlockHash(RandomUtils.nextBytes(31));
assertInvalidPivotBlockHash(RandomUtils.nextBytes(33));
}
private void assertInvalidPivotBlockHash(byte[] pivotBlockHash) {
String hexEncodedPrivateKey = Hex.toHexString(pivotBlockHash);
SystemProperties props = new SystemProperties();
try {
props.overrideParams("sync.fast.pivotBlockHash", hexEncodedPrivateKey);
props.getFastSyncPivotBlockHash();
fail("Should've thrown exception for invalid private key");
} catch (RuntimeException ignore) { }
}
@Test
public void testUseGenesis() throws IOException {
BigInteger mordenInitialNonse = BigInteger.valueOf(0x100000);
SystemProperties props = new SystemProperties() {
@Override
public BlockchainNetConfig getBlockchainConfig() {
return new MordenNetConfig();
}
};
Resource sampleGenesisBlock = new ClassPathResource("/config/genesis-sample.json");
Genesis genesis = props.useGenesis(sampleGenesisBlock.getInputStream());
/*
* Assert that MordenNetConfig is used when generating the
* premine state.
*/
Map<ByteArrayWrapper, Genesis.PremineAccount> premine = genesis.getPremine();
assertEquals(1, premine.size());
Genesis.PremineAccount account = premine.values().iterator().next();
AccountState state = account.accountState;
assertEquals(state.getNonce(), mordenInitialNonse);
//noinspection SpellCheckingInspection
assertEquals("#0 (4addb5 <~ 000000) Txs:0, Unc: 0", genesis.getShortDescr());
}
@Test
public void testDump() {
SystemProperties props = new SystemProperties();
/*
* No intend to test TypeSafe's render functionality. Perform
* some high-level asserts to verify that:
* - it's probably a config
* - it's probably fairly sized
* - it didn't break
*/
String dump = props.dump().trim();
assertTrue(dump.startsWith("{"));
assertTrue(dump.endsWith("}"));
assertTrue(dump.length() > 5 * 1024);
assertTrue(StringUtils.countOccurrencesOf(dump, "{") > 50);
assertTrue(StringUtils.countOccurrencesOf(dump, "{") > 50);
}
@Test
public void testMergeConfigs1() {
String firstConfig = "";
SystemProperties props = new SystemProperties();
Config config = props.mergeConfigs(firstConfig, ConfigFactory::parseString);
assertFalse(config.hasPath("peer.listen.port"));
}
@Test
public void testMergeConfigs2() {
String firstConfig = "peer.listen.port=30123";
SystemProperties props = new SystemProperties();
Config config = props.mergeConfigs(firstConfig, ConfigFactory::parseString);
assertEquals(30123, config.getInt("peer.listen.port"));
}
@Test
public void testMergeConfigs3() {
String firstConfig = "peer.listen.port=30123,peer.listen.port=30145";
SystemProperties props = new SystemProperties();
Config config = props.mergeConfigs(firstConfig, ConfigFactory::parseString);
assertEquals(30145, config.getInt("peer.listen.port"));
}
@Test
public void testMergeConfigs4() {
String firstConfig = "peer.listen.port=30123,sync.enabled=true";
SystemProperties props = new SystemProperties();
Config config = props.mergeConfigs(firstConfig, ConfigFactory::parseString);
assertEquals(30123, config.getInt("peer.listen.port"));
assertEquals(Boolean.TRUE, config.getBoolean("sync.enabled"));
}
@SuppressWarnings("SameParameterValue")
static class ActivePeer {
boolean asEnodeUrl;
String node;
String host;
String nodeId;
String nodeName;
static ActivePeer asEnodeUrl(String node, String host) {
return new ActivePeer(true, node, host, "e437a4836b77ad9d9ffe73ee782ef2614e6d8370fcf62191a6e488276e23717147073a7ce0b444d485fff5a0c34c4577251a7a990cf80d8542e21b95aa8c5e6c", null);
}
static ActivePeer asNode(String node, String host) {
return asNodeWithId(node, host, "e437a4836b77ad9d9ffe73ee782ef2614e6d8370fcf62191a6e488276e23717147073a7ce0b444d485fff5a0c34c4577251a7a990cf80d8542e21b95aa8c5e6c");
}
static ActivePeer asNodeWithId(String node, String host, String nodeId) {
return new ActivePeer(false, node, host, nodeId, null);
}
static ActivePeer asNodeWithName(String node, String host, String name) {
return new ActivePeer(false, node, host, null, name);
}
private ActivePeer(boolean asEnodeUrl, String node, String host, String nodeId, String nodeName) {
this.asEnodeUrl = asEnodeUrl;
this.node = node;
this.host = host;
this.nodeId = nodeId;
this.nodeName = nodeName;
}
public String toString() {
String hexEncodedNode = Hex.toHexString(node.getBytes());
if (asEnodeUrl) {
return "{\n" +
" url = \"enode://" + hexEncodedNode + "@" + host + ".com:30303\" \n" +
"}";
}
if (StringUtils.hasText(nodeName)) {
return "{\n" +
" ip = " + host + "\n" +
" port = 30303\n" +
" nodeName = " + nodeName + "\n" +
"}\n";
}
return "{\n" +
" ip = " + host + "\n" +
" port = 30303\n" +
" nodeId = " + nodeId + "\n" +
"}\n";
}
}
@SuppressWarnings("SameParameterValue")
static class TrustedPeer {
String ip;
String nodeId;
static TrustedPeer asNode(String nodeId, String ipPattern) {
return new TrustedPeer(nodeId, ipPattern);
}
private TrustedPeer(String nodeId, String ipPattern) {
this.ip = ipPattern;
this.nodeId = Hex.toHexString(nodeId.getBytes());
}
public String toString() {
return "{\n" +
" ip = \"" + ip + "\"\n" +
" nodeId = " + nodeId + "\n" +
"}\n";
}
}
}
| 25,948
| 40.058544
| 192
|
java
|
ethereumj
|
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/config/GetNodeIdFromPropsFileTest.java
|
/*
* Copyright (c) [2017] [ <ether.camp> ]
* This file is part of the ethereumJ library.
*
* The ethereumJ library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The ethereumJ library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the ethereumJ library. If not, see <http://www.gnu.org/licenses/>.
*/
package org.ethereum.config;
import org.ethereum.crypto.ECKey;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.spongycastle.util.encoders.Hex;
import org.springframework.util.FileCopyUtils;
import org.springframework.util.StringUtils;
import javax.annotation.concurrent.NotThreadSafe;
import java.io.*;
import java.util.Properties;
import static org.junit.Assert.*;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions;
/**
* Not thread safe - testGeneratedNodePrivateKey temporarily removes the nodeId.properties
* file which may influence other tests.
*/
@SuppressWarnings("ConstantConditions")
@NotThreadSafe
public class GetNodeIdFromPropsFileTest {
@Rule
public ExpectedException exception = ExpectedException.none();
private File nodeIdPropertiesFile;
@Before
public void init() {
//Cleanup previous nodeId.properties file (if exists)
nodeIdPropertiesFile = new File("database-test/nodeId.properties");
//noinspection ResultOfMethodCallIgnored
nodeIdPropertiesFile.delete();
}
@After
public void teardown() {
//Cleanup created nodeId.properties file
//noinspection ResultOfMethodCallIgnored
nodeIdPropertiesFile.delete();
}
@Test
public void testGenerateNodeIdFromPropsFileReadsExistingFile() throws Exception {
// Create temporary nodeId.properties file
ECKey key = new ECKey();
String expectedNodePrivateKey = Hex.toHexString(key.getPrivKeyBytes());
String expectedNodeId = Hex.toHexString(key.getNodeId());
createNodeIdPropertiesFile("database-test", key);
new GetNodeIdFromPropsFile("database-test").getNodePrivateKey();
assertTrue(nodeIdPropertiesFile.exists());
String contents = FileCopyUtils.copyToString(new FileReader(nodeIdPropertiesFile));
String[] lines = StringUtils.tokenizeToStringArray(contents, "\n");
assertEquals(4, lines.length);
assertTrue(lines[0].startsWith("#Generated NodeID."));
assertTrue(lines[1].startsWith("#"));
assertTrue(lines[2].startsWith("nodeIdPrivateKey=" + expectedNodePrivateKey));
assertTrue(lines[3].startsWith("nodeId=" + expectedNodeId));
}
@Test
public void testGenerateNodeIdFromPropsDoesntGenerateRandomWhenFileIsPresent() throws Exception {
// Create temporary nodeId.properties file
createNodeIdPropertiesFile("database-test", new ECKey());
GenerateNodeIdRandomly randomNodeIdGeneratorStrategySpy = spy(new GenerateNodeIdRandomly("database-test"));
GenerateNodeIdStrategy fileNodeIdGeneratorStrategy = new GetNodeIdFromPropsFile("database-test")
.withFallback(randomNodeIdGeneratorStrategySpy);
fileNodeIdGeneratorStrategy.getNodePrivateKey();
verifyZeroInteractions(randomNodeIdGeneratorStrategySpy);
}
@Test
public void testGenerateNodeIdFromPropsGeneratesRandomWhenFileIsNotPresent() {
GenerateNodeIdRandomly randomNodeIdGeneratorStrategySpy = spy(new GenerateNodeIdRandomly("database-test"));
GenerateNodeIdStrategy fileNodeIdGeneratorStrategy = new GetNodeIdFromPropsFile("database-test")
.withFallback(randomNodeIdGeneratorStrategySpy);
fileNodeIdGeneratorStrategy.getNodePrivateKey();
verify(randomNodeIdGeneratorStrategySpy).getNodePrivateKey();
}
@Test
public void testGenerateNodeIdFromPropsGeneratesRandomWhenFileIsNotPresentAndNoFallback() {
exception.expect(RuntimeException.class);
exception.expectMessage("Can't read 'nodeId.properties' and no fallback method has been set");
GenerateNodeIdStrategy fileNodeIdGeneratorStrategy = new GetNodeIdFromPropsFile("database-test");
fileNodeIdGeneratorStrategy.getNodePrivateKey();
}
private void createNodeIdPropertiesFile(String dir, ECKey key) throws IOException {
Properties props = new Properties();
props.setProperty("nodeIdPrivateKey", Hex.toHexString(key.getPrivKeyBytes()));
props.setProperty("nodeId", Hex.toHexString(key.getNodeId()));
File file = new File(dir, "nodeId.properties");
file.getParentFile().mkdirs();
try (Writer writer = new FileWriter(file)) {
props.store(writer, "Generated NodeID. To use your own nodeId please refer to 'peer.privateKey' config option.");
}
}
}
| 5,369
| 38.777778
| 125
|
java
|
ethereumj
|
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/config/InitializerTest.java
|
/*
* Copyright (c) [2016] [ <ether.camp> ]
* This file is part of the ethereumJ library.
*
* The ethereumJ library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The ethereumJ library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the ethereumJ library. If not, see <http://www.gnu.org/licenses/>.
*/
package org.ethereum.config;
import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.read.ListAppender;
import com.google.common.io.Files;
import com.typesafe.config.Config;
import com.typesafe.config.ConfigFactory;
import com.typesafe.config.ConfigValueFactory;
import org.ethereum.util.FileUtil;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.IOException;
import java.util.List;
import static org.ethereum.config.Initializer.DatabaseVersionHandler.Behavior;
import static org.ethereum.config.Initializer.DatabaseVersionHandler.Behavior.*;
import static org.junit.Assert.*;
/**
* Created by Stan Reshetnyk on 11.09.16.
*/
public class InitializerTest {
private final Initializer.DatabaseVersionHandler resetHelper = new Initializer.DatabaseVersionHandler();
private File tempFile;
private String databaseDir;
private File versionFile;
@Before
public void before() {
tempFile = Files.createTempDir();
databaseDir = tempFile.getAbsolutePath() + "/database";
versionFile = new File(databaseDir + "/version.properties");
}
@After
public void after() {
FileUtil.recursiveDelete(tempFile.getAbsolutePath());
}
@Test
public void helper_shouldAllowCleanWorkspace() {
SystemProperties props = withConfig(2, null);
resetHelper.process(props);
assertEquals(new Integer(2), resetHelper.getDatabaseVersion(versionFile));
resetHelper.process(props);
}
@Test
public void helper_shouldCreateVersionFile() {
SystemProperties props = withConfig(1, null);
// state without database
assertEquals(new Integer(-1), resetHelper.getDatabaseVersion(versionFile));
assertTrue(!resetHelper.isDatabaseDirectoryExists(props));
// create database version file
resetHelper.process(props);
// state with just created database
assertEquals(new Integer(1), resetHelper.getDatabaseVersion(versionFile));
assertTrue(resetHelper.isDatabaseDirectoryExists(props));
// running process for a second time should change nothing
resetHelper.process(props);
assertEquals(new Integer(1), resetHelper.getDatabaseVersion(versionFile));
assertTrue(resetHelper.isDatabaseDirectoryExists(props));
}
@Test
public void helper_shouldCreateVersionFile_whenOldVersion() {
// create database without version
SystemProperties props1 = withConfig(1, null);
resetHelper.process(props1);
//noinspection ResultOfMethodCallIgnored
versionFile.renameTo(new File(versionFile.getAbsoluteFile() + ".renamed"));
SystemProperties props2 = withConfig(2, IGNORE);
resetHelper.process(props2);
assertEquals(new Integer(1), resetHelper.getDatabaseVersion(versionFile));
assertTrue(resetHelper.isDatabaseDirectoryExists(props2));
}
@Test(expected = RuntimeException.class)
public void helper_shouldStop_whenNoVersionFileAndNotFirstVersion() throws IOException {
SystemProperties props = withConfig(2, EXIT);
resetHelper.process(props);
// database is assumed to exist if dir is not empty
//noinspection ResultOfMethodCallIgnored
versionFile.renameTo(new File(versionFile.getAbsoluteFile() + ".renamed"));
resetHelper.process(props);
}
@Test
public void helper_shouldReset_whenDifferentVersionAndFlag() {
SystemProperties props1 = withConfig(1, null);
resetHelper.process(props1);
final File testFile = createFile();
SystemProperties props2 = withConfig(2, RESET);
resetHelper.process(props2);
assertFalse(testFile.exists());
assertEquals(new Integer(2), resetHelper.getDatabaseVersion(versionFile));
}
@Test(expected = RuntimeException.class)
public void helper_shouldExit_whenDifferentVersionAndFlag() {
final SystemProperties props1 = withConfig(1, null);
resetHelper.process(props1);
final SystemProperties props2 = withConfig(2, EXIT);
resetHelper.process(props2);
}
@Test(expected = RuntimeException.class)
public void helper_shouldExit_byDefault() {
final SystemProperties props1 = withConfig(1, null);
resetHelper.process(props1);
final SystemProperties props2 = withConfig(2, null);
resetHelper.process(props2);
}
@Test
public void helper_shouldIgnore_whenDifferentVersionAndFlag() {
final SystemProperties props1 = withConfig(1, EXIT);
resetHelper.process(props1);
final File testFile = createFile();
final SystemProperties props2 = withConfig(2, IGNORE);
resetHelper.process(props2);
assertTrue(testFile.exists());
assertEquals(new Integer(1), resetHelper.getDatabaseVersion(versionFile));
}
@Test
public void helper_shouldPutVersion_afterDatabaseReset() throws IOException {
Config config = ConfigFactory.empty()
.withValue("database.reset", ConfigValueFactory.fromAnyRef(true));
SPO systemProperties = new SPO(config);
systemProperties.setDataBaseDir(databaseDir);
systemProperties.setDatabaseVersion(33);
final File testFile = createFile();
assertTrue(testFile.exists());
resetHelper.process(systemProperties);
assertEquals(new Integer(33), resetHelper.getDatabaseVersion(versionFile));
assertFalse(testFile.exists()); // reset should have cleared file
}
@Test
public void helper_shouldPrintCapabilityEthVersion_whenInfoEnabled() {
SystemProperties system = new SystemProperties();
Initializer initializer = new Initializer();
ListAppender<ILoggingEvent> inMemoryAppender = new ListAppender<>();
inMemoryAppender.start();
Logger logger = (Logger) LoggerFactory.getLogger("general");
try {
logger.setLevel(Level.DEBUG);
logger.addAppender(inMemoryAppender);
initializer.postProcessBeforeInitialization(system, "initializerBean");
assertContainsLogLine(inMemoryAppender.list, "capability eth version: [62, 63]");
assertContainsLogLine(inMemoryAppender.list, "capability shh version: [3]");
assertContainsLogLine(inMemoryAppender.list, "capability bzz version: [0]");
} finally {
inMemoryAppender.stop();
logger.detachAppender(inMemoryAppender);
}
}
private void assertContainsLogLine(List<ILoggingEvent> lines, final String line) {
for (ILoggingEvent loggingEvent : lines) {
if (loggingEvent.getFormattedMessage().equals(line)) {
return;
}
}
fail("Could not find log line that matches: " + line);
}
// HELPERS
@SuppressWarnings("ResultOfMethodCallIgnored")
private File createFile() {
final File testFile = new File(databaseDir + "/empty.file");
testFile.getParentFile().mkdirs();
try {
testFile.createNewFile();
} catch (IOException e) {
throw new RuntimeException("Can't create file in database dir");
}
return testFile;
}
private SystemProperties withConfig(int databaseVersion, Behavior behavior) {
Config config = ConfigFactory.empty()
// reset is true for tests
.withValue("database.reset", ConfigValueFactory.fromAnyRef(false));
if (behavior != null) {
config = config.withValue("database.incompatibleDatabaseBehavior",
ConfigValueFactory.fromAnyRef(behavior.toString().toLowerCase()));
}
SPO systemProperties = new SPO(config);
systemProperties.setDataBaseDir(databaseDir);
systemProperties.setDatabaseVersion(databaseVersion);
return systemProperties;
}
public static class SPO extends SystemProperties {
SPO(Config config) {
super(config);
}
void setDatabaseVersion(Integer databaseVersion) {
this.databaseVersion = databaseVersion;
}
}
}
| 9,140
| 34.707031
| 108
|
java
|
ethereumj
|
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/config/NodeFilterTest.java
|
/*
* Copyright (c) [2017] [ <ether.camp> ]
* This file is part of the ethereumJ library.
*
* The ethereumJ library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The ethereumJ library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the ethereumJ library. If not, see <http://www.gnu.org/licenses/>.
*
*
*/
package org.ethereum.config;
import org.ethereum.net.rlpx.Node;
import org.junit.Test;
import org.spongycastle.util.encoders.Hex;
import java.net.InetAddress;
import static junit.framework.TestCase.assertFalse;
import static org.junit.Assert.assertTrue;
public class NodeFilterTest {
private static final byte[] NODE_1 = "node-1".getBytes();
private static final byte[] NODE_2 = "node-2".getBytes();
@Test
public void addByHostIpPattern() throws Exception {
NodeFilter filter = new NodeFilter();
filter.add(NODE_1, "1.2.3.4");
assertTrue(filter.accept(createTestNode("node-1", "1.2.3.4")));
}
@Test
public void doNotAcceptDifferentNodeNameButSameIp() throws Exception {
NodeFilter filter = new NodeFilter();
filter.add(NODE_1, "1.2.3.4");
assertTrue(filter.accept(createTestNode("node-1", "1.2.3.4")));
assertFalse(filter.accept(createTestNode("node-2", "1.2.3.4")));
}
@Test
public void acceptDifferentNodeWithoutNameButSameIp() throws Exception {
NodeFilter filter = new NodeFilter();
filter.add(null, "1.2.3.4");
assertTrue(filter.accept(createTestNode("node-1", "1.2.3.4")));
assertTrue(filter.accept(createTestNode("node-2", "1.2.3.4")));
}
@Test
public void acceptDuplicateFilter() {
NodeFilter filter = new NodeFilter();
filter.add(NODE_1, "1.2.3.4");
filter.add(NODE_1, "1.2.3.4");
assertTrue(filter.accept(createTestNode("node-1", "1.2.3.4")));
}
@Test
public void acceptDifferentNodeNameButOverlappingIp() {
NodeFilter filter = new NodeFilter();
filter.add(NODE_1, "1.2.3.4");
filter.add(NODE_2, "1.2.3.*");
assertTrue(filter.accept(createTestNode("node-1", "1.2.3.4")));
assertTrue(filter.accept(createTestNode("node-2", "1.2.3.4")));
assertTrue(filter.accept(createTestNode("node-2", "1.2.3.99")));
assertFalse(filter.accept(createTestNode("invalid-1", "1.2.4.1")));
}
@Test
public void acceptMultipleWildcards() {
NodeFilter filter = new NodeFilter();
filter.add(NODE_1, "1.2.3.*");
filter.add(NODE_2, "1.*.3.*");
assertTrue(filter.accept(createTestNode("node-1", "1.2.3.4")));
assertTrue(filter.accept(createTestNode("node-2", "1.2.3.4")));
assertTrue(filter.accept(createTestNode("node-2", "1.2.3.99")));
assertTrue(filter.accept(createTestNode("node-2", "1.2.99.99")));
assertTrue(filter.accept(createTestNode("node-2", "1.99.99.99")));
assertFalse(filter.accept(createTestNode("node-2", "2.99.99.99")));
}
@Test
public void addInvalidNodeShouldThrowException() throws Exception {
NodeFilter filter = new NodeFilter();
assertFalse(filter.accept(createTestNode("invalid-1", null)));
}
@Test
public void neverAcceptOnEmptyFilter() throws Exception {
NodeFilter filter = new NodeFilter();
assertFalse(filter.accept(createTestNode("node-1", "1.2.3.4")));
assertFalse(filter.accept(createTestNode("node-2", "1.2.3.4")));
assertFalse(filter.accept(createTestNode("node-2", "1.2.3.99")));
assertFalse(filter.accept(createTestNode("node-2", "1.2.99.99")));
assertFalse(filter.accept(createTestNode("node-2", "1.99.99.99")));
assertFalse(filter.accept(createTestNode("node-2", "2.99.99.99")));
}
@Test
public void acceptByInetAddress() throws Exception {
NodeFilter filter = new NodeFilter();
filter.add(NODE_1, "8.*");
assertTrue(filter.accept(InetAddress.getByName("8.8.8.8")));
}
@Test
public void doNotAcceptTheCatchAllWildcard() throws Exception {
NodeFilter filter = new NodeFilter();
filter.add(NODE_1, "*");
assertFalse(filter.accept(InetAddress.getByName("1.2.3.4")));
assertFalse(filter.accept(createTestNode("node-1", "255.255.255.255")));
}
@Test
public void acceptNullIpPatternAsCatchAllForNodes() throws Exception {
NodeFilter filter = new NodeFilter();
filter.add(NODE_1, null);
assertTrue(filter.accept(createTestNode("node-1", "1.2.3.4")));
assertTrue(filter.accept(createTestNode("node-1", "255.255.255.255")));
}
@Test
public void acceptNullIpPatternAsCatchAllForInetAddresses() throws Exception {
NodeFilter filter = new NodeFilter();
filter.add(NODE_1, null);
assertTrue(filter.accept(InetAddress.getByName("1.2.3.4")));
assertTrue(filter.accept(InetAddress.getByName("255.255.255.255")));
}
@Test
public void acceptLoopback() throws Exception {
NodeFilter filter = new NodeFilter();
filter.add(NODE_1, "127.0.0.1");
assertTrue(filter.accept(InetAddress.getByName("localhost")));
}
@Test
public void doNotAcceptInvalidNodeHostnameWhenUsingPattern() throws Exception {
NodeFilter filter = new NodeFilter();
filter.add(null, "1.2.3.4");
Node nodeWithInvalidHostname = new Node("enode://" + Hex.toHexString(NODE_1) + "@unknown:30303");
assertFalse(filter.accept(nodeWithInvalidHostname));
}
@Test
public void doNotAcceptInvalidNodeHostnameWhenUsingWildcard() throws Exception {
NodeFilter filter = new NodeFilter();
filter.add(null, null);
Node nodeWithInvalidHostname = new Node("enode://" + Hex.toHexString(NODE_1) + "@unknown:30303");
assertFalse(filter.accept(nodeWithInvalidHostname));
}
private static Node createTestNode(String nodeName, String hostIpPattern) {
return new Node("enode://" + Hex.toHexString(nodeName.getBytes()) + "@" + hostIpPattern + ":30303");
}
}
| 6,553
| 37.327485
| 108
|
java
|
ethereumj
|
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/config/blockchain/BlockHeaderBuilder.java
|
/*
* Copyright (c) [2017] [ <ether.camp> ]
* This file is part of the ethereumJ library.
*
* The ethereumJ library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The ethereumJ library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the ethereumJ library. If not, see <http://www.gnu.org/licenses/>.
*
*
*/
package org.ethereum.config.blockchain;
import org.apache.commons.lang3.StringUtils;
import org.ethereum.core.BlockHeader;
import java.math.BigInteger;
class BlockHeaderBuilder {
private byte[] EMPTY_ARRAY = new byte[0];
private byte[] parentHash;
private long blockNumber;
private BigInteger difficulty = BigInteger.ZERO;
private long timestamp = 2L;
private byte[] unclesHash = EMPTY_ARRAY;
BlockHeaderBuilder(byte[] parentHash, long blockNumber, String difficulty) {
this(parentHash, blockNumber, parse(difficulty));
}
BlockHeaderBuilder(byte[] parentHash, long blockNumber, int difficulty) {
this(parentHash, blockNumber, BigInteger.valueOf(difficulty));
}
BlockHeaderBuilder(byte[] parentHash, long blockNumber, BigInteger difficulty) {
this.parentHash = parentHash;
this.blockNumber = blockNumber;
this.difficulty = difficulty;
}
BlockHeaderBuilder withTimestamp(long timestamp) {
this.timestamp = timestamp;
return this;
}
BlockHeaderBuilder withUncles(byte[] unclesHash) {
this.unclesHash = unclesHash;
return this;
}
BlockHeader build() {
return new BlockHeader(parentHash, unclesHash, EMPTY_ARRAY, EMPTY_ARRAY,
difficulty.toByteArray(), blockNumber, EMPTY_ARRAY, 1L, timestamp, EMPTY_ARRAY, EMPTY_ARRAY, EMPTY_ARRAY);
}
public static BigInteger parse(String val) {
return new BigInteger(StringUtils.replace(val, ",", ""));
}
}
| 2,329
| 32.285714
| 122
|
java
|
ethereumj
|
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/config/blockchain/ETCFork3MTest.java
|
/*
* Copyright (c) [2017] [ <ether.camp> ]
* This file is part of the ethereumJ library.
*
* The ethereumJ library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The ethereumJ library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the ethereumJ library. If not, see <http://www.gnu.org/licenses/>.
*
*
*/
package org.ethereum.config.blockchain;
import org.apache.commons.lang3.StringUtils;
import org.ethereum.core.BlockHeader;
import org.junit.Test;
import java.math.BigInteger;
import static org.junit.Assert.*;
@SuppressWarnings("SameParameterValue")
public class ETCFork3MTest {
/**
* Ethereum Classic's Chain ID should be '61' according to
* https://github.com/ethereum/EIPs/blob/master/EIPS/eip-155.md
*/
@Test
public void textPredefinedChainId() throws Exception {
ETCFork3M etcFork3M = new ETCFork3M(new TestBlockchainConfig());
assertEquals(61, (int) etcFork3M.getChainId());
}
@Test
public void testRelatedEip() throws Exception {
TestBlockchainConfig parent = new TestBlockchainConfig();
ETCFork3M etcFork3M = new ETCFork3M(parent);
// Inherited from parent
assertFalse(etcFork3M.eip198());
assertFalse(etcFork3M.eip206());
assertFalse(etcFork3M.eip211());
assertFalse(etcFork3M.eip212());
assertFalse(etcFork3M.eip213());
assertFalse(etcFork3M.eip214());
assertFalse(etcFork3M.eip658());
// Always false
assertFalse(etcFork3M.eip161());
/*
* By flipping parent's eip values, we assert that
* ETCFork3M delegates respective eip calls to parent.
*/
parent.enableAllEip();
// Inherited from parent
assertTrue(etcFork3M.eip198());
assertFalse(etcFork3M.eip206());
assertFalse(etcFork3M.eip211());
assertTrue(etcFork3M.eip212());
assertTrue(etcFork3M.eip213());
assertFalse(etcFork3M.eip214());
assertFalse(etcFork3M.eip658());
// Always false
assertFalse(etcFork3M.eip161());
}
@Test
public void testDifficultyWithoutExplosion() throws Exception {
ETCFork3M etcFork3M = new ETCFork3M(new TestBlockchainConfig());
BlockHeader parent = new BlockHeaderBuilder(new byte[]{11, 12}, 0L, 1_000_000).build();
BlockHeader current = new BlockHeaderBuilder(parent.getHash(), 1L, -1).build();
BigInteger difficulty = etcFork3M.calcDifficulty(current, parent);
assertEquals(BigInteger.valueOf(269435944), difficulty);
}
@Test
public void testDifficultyWithExplosionShouldBeImpactedByBlockTimestamp() throws Exception {
ETCFork3M etcFork3M = new ETCFork3M(new TestBlockchainConfig());
BlockHeader parent = new BlockHeaderBuilder(new byte[]{11, 12}, 2_500_000, 8_388_608)
.withTimestamp(0)
.build();
BlockHeader current = new BlockHeaderBuilder(parent.getHash(), 2_500_001, -1)
.withTimestamp(10 * 60) // 10 minutes later, longer time: lowers difficulty
.build();
BigInteger difficulty = etcFork3M.calcDifficulty(current, parent);
assertEquals(BigInteger.valueOf(276582400), difficulty);
parent = new BlockHeaderBuilder(new byte[]{11, 12}, 2_500_000, 8_388_608)
.withTimestamp(0)
.build();
current = new BlockHeaderBuilder(parent.getHash(), 2_500_001, -1)
.withTimestamp(5) // 5 seconds later, shorter time: higher difficulty
.build();
difficulty = etcFork3M.calcDifficulty(current, parent);
assertEquals(BigInteger.valueOf(276828160), difficulty);
}
@Test
public void testDifficultyAboveBlock5MShouldTriggerExplosion() throws Exception {
ETCFork3M etcFork3M = new ETCFork3M(new TestBlockchainConfig());
BlockHeader parent = new BlockHeaderBuilder(new byte[]{11, 12}, 5_000_000, 268_435_456).build();
BlockHeader current = new BlockHeaderBuilder(parent.getHash(), 5_000_001, -1).build();
assertEquals(BigInteger.valueOf(537_001_984), etcFork3M.calcDifficulty(current, parent));
parent = new BlockHeaderBuilder(new byte[]{11, 12}, 5_199_999, 1_073_872_896).build();
current = new BlockHeaderBuilder(parent.getHash(), 5_200_000, 1_073_872_896).build();
assertEquals(BlockHeaderBuilder.parse("2,148,139,072"), etcFork3M.calcDifficulty(current, parent));
}
@Test
@SuppressWarnings("PointlessArithmeticExpression")
public void testCalcDifficultyMultiplier() throws Exception {
// Note; timestamps are in seconds
assertCalcDifficultyMultiplier(0L, 1L, 1);
assertCalcDifficultyMultiplier(0L, 5, 1); // 5 seconds
assertCalcDifficultyMultiplier(0L, 1 * 10, 0); // 10 seconds
assertCalcDifficultyMultiplier(0L, 2 * 10, -1); // 20 seconds
assertCalcDifficultyMultiplier(0L, 10 * 10, -9); // 100 seconds
assertCalcDifficultyMultiplier(0L, 60 * 10, -59); // 10 mins
assertCalcDifficultyMultiplier(0L, 60 * 12, -71); // 12 mins
}
private void assertCalcDifficultyMultiplier(long parentBlockTimestamp, long curBlockTimestamp, int expectedMultiplier) {
ETCFork3M etcFork3M = new ETCFork3M(new TestBlockchainConfig());
BlockHeader parent = new BlockHeaderBuilder(new byte[]{11, 12}, 0L, 0)
.withTimestamp(parentBlockTimestamp)
.build();
BlockHeader current = new BlockHeaderBuilder(parent.getHash(), 1L, 0)
.withTimestamp(curBlockTimestamp)
.build();
assertEquals(expectedMultiplier, etcFork3M.getCalcDifficultyMultiplier(current, parent).intValue());
}
/**
* https://github.com/ethereumproject/ECIPs/blob/master/ECIPs/ECIP-1010.md
*
<pre>
if (block.number < pause_block) {
explosion = (block.number / 100000) - 2
} else if (block.number < cont_block) {
explosion = fixed_diff
} else { // block.number >= cont_block
explosion = (block.number / 100000) - delay - 2
}
</pre>
* Expected explosion values would be:
<pre>
Block 3,000,000 == 2**28 == 268,435,456
Block 4,000,000 == 2**28 == 268,435,456
Block 5,000,000 == 2**28 == 268,435,456
Block 5,200,000 == 2**30 == 1 TH
Block 6,000,000 == 2**38 == 274 TH
</pre>
Where the explosion is the value after '**'.
*/
@Test
public void testEcip1010ExplosionChanges() throws Exception {
ETCFork3M etcFork3M = new ETCFork3M(new TestBlockchainConfig());
/*
* Technically, a block number < 3_000_000 should result in an explosion < fixed_diff, or explosion < 28
*
* Block number 3_000_000 occurred on Jan 15, 2017. The ETCFork3M configuration was committed a day after. It
* is therefor not necessary to have block.number < pause_block be implemented
*/
BlockHeader beforePauseBlock = new BlockHeaderBuilder(new byte[]{11, 12}, 2_500_000, 0).build();
int unimplementedPrePauseBlockExplosion = 28;
assertEquals(unimplementedPrePauseBlockExplosion, etcFork3M.getExplosion(beforePauseBlock, null));
BlockHeader endOfIceAge = new BlockHeaderBuilder(new byte[]{11, 12}, 5_000_000, 0).build();
assertEquals(28, etcFork3M.getExplosion(endOfIceAge, null));
BlockHeader startExplodingBlock = new BlockHeaderBuilder(new byte[]{11, 12}, 5_200_000, 0).build();
assertEquals(30, etcFork3M.getExplosion(startExplodingBlock, null));
startExplodingBlock = new BlockHeaderBuilder(new byte[]{11, 12}, 6_000_000, 0).build();
assertEquals(38, etcFork3M.getExplosion(startExplodingBlock, null));
}
}
| 8,273
| 40.164179
| 124
|
java
|
ethereumj
|
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/config/blockchain/ConstantinopleConfigTest.java
|
/*
* Copyright (c) [2017] [ <ether.camp> ]
* This file is part of the ethereumJ library.
*
* The ethereumJ library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The ethereumJ library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the ethereumJ library. If not, see <http://www.gnu.org/licenses/>.
*
*
*/
package org.ethereum.config.blockchain;
import org.ethereum.config.Constants;
import org.ethereum.config.ConstantsAdapter;
import org.ethereum.core.BlockHeader;
import org.ethereum.util.blockchain.EtherUtil;
import org.junit.Test;
import java.math.BigInteger;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@SuppressWarnings("SameParameterValue")
public class ConstantinopleConfigTest {
private static final byte[] FAKE_HASH = {11, 12};
private static final ConstantinopleConfig constantinopleConfig = new ConstantinopleConfig(new TestBlockchainConfig());
@Test
public void testRelatedEip() throws Exception {
// Byzantium
assertTrue(constantinopleConfig.eip198());
assertTrue(constantinopleConfig.eip206());
assertTrue(constantinopleConfig.eip211());
assertTrue(constantinopleConfig.eip212());
assertTrue(constantinopleConfig.eip213());
assertTrue(constantinopleConfig.eip214());
assertTrue(constantinopleConfig.eip658());
// Constantinople
assertTrue(constantinopleConfig.eip145());
assertTrue(constantinopleConfig.eip1014());
assertTrue(constantinopleConfig.eip1052());
assertTrue(constantinopleConfig.eip1283());
ByzantiumConfig byzantiumConfig = new ByzantiumConfig(new TestBlockchainConfig());
// Constantinople eips in Byzantium
assertFalse(byzantiumConfig.eip145());
assertFalse(byzantiumConfig.eip1014());
assertFalse(byzantiumConfig.eip1052());
assertFalse(byzantiumConfig.eip1283());
}
@Test
public void testDifficultyWithoutExplosion() throws Exception {
BlockHeader parent = new BlockHeaderBuilder(FAKE_HASH, 0L, 1_000_000).build();
BlockHeader current = new BlockHeaderBuilder(parent.getHash(), 1L, -1).build();
BigInteger difficulty = constantinopleConfig.calcDifficulty(current, parent);
assertEquals(BigInteger.valueOf(1_000_976), difficulty);
}
@Test
public void testDifficultyAdjustedForParentBlockHavingUncles() throws Exception {
BlockHeader parent = new BlockHeaderBuilder(FAKE_HASH, 0L, 0)
.withTimestamp(0L)
.withUncles(new byte[]{1, 2})
.build();
BlockHeader current = new BlockHeaderBuilder(parent.getHash(), 1L, 0)
.withTimestamp(9L)
.build();
assertEquals(1, constantinopleConfig.getCalcDifficultyMultiplier(current, parent).intValue());
}
@Test
public void testDifficultyWithExplosionShouldBeImpactedByBlockTimestamp() throws Exception {
BlockHeader parent = new BlockHeaderBuilder(new byte[]{11, 12}, 2_500_000, 8_388_608)
.withTimestamp(0)
.build();
BlockHeader current = new BlockHeaderBuilder(parent.getHash(), 2_500_001, 8_388_608)
.withTimestamp(10 * 60) // 10 minutes later, longer time: lowers difficulty
.build();
BigInteger difficulty = constantinopleConfig.calcDifficulty(current, parent);
assertEquals(BigInteger.valueOf(8126464), difficulty);
parent = new BlockHeaderBuilder(new byte[]{11, 12}, 2_500_000, 8_388_608)
.withTimestamp(0)
.build();
current = new BlockHeaderBuilder(parent.getHash(), 2_500_001, 8_388_608)
.withTimestamp(5) // 5 seconds later, shorter time: higher difficulty
.build();
difficulty = constantinopleConfig.calcDifficulty(current, parent);
assertEquals(BigInteger.valueOf(8396800), difficulty);
}
@Test
public void testDifficultyAboveBlock5MShouldTriggerExplosion() throws Exception {
int parentDifficulty = 268_435_456;
BlockHeader parent = new BlockHeaderBuilder(FAKE_HASH, 6_000_000, parentDifficulty).build();
BlockHeader current = new BlockHeaderBuilder(parent.getHash(), 6_000_001, -1).build();
int actualDifficulty = constantinopleConfig.calcDifficulty(current, parent).intValue();
int differenceWithoutExplosion = actualDifficulty - parentDifficulty;
assertEquals(262_400, differenceWithoutExplosion);
parent = new BlockHeaderBuilder(FAKE_HASH, 7_000_000, parentDifficulty).build();
current = new BlockHeaderBuilder(parent.getHash(), 7_000_001, -1).build();
actualDifficulty = constantinopleConfig.calcDifficulty(current, parent).intValue();
differenceWithoutExplosion = actualDifficulty - parentDifficulty;
assertEquals(524_288, differenceWithoutExplosion);
parent = new BlockHeaderBuilder(FAKE_HASH, 8_000_000, parentDifficulty).build();
current = new BlockHeaderBuilder(parent.getHash(), 8_000_001, -1).build();
actualDifficulty = constantinopleConfig.calcDifficulty(current, parent).intValue();
differenceWithoutExplosion = actualDifficulty - parentDifficulty;
assertEquals(268_697_600, differenceWithoutExplosion); // Explosion!
}
@Test
@SuppressWarnings("PointlessArithmeticExpression")
public void testCalcDifficultyMultiplier() throws Exception {
// Note; timestamps are in seconds
assertCalcDifficultyMultiplier(0L, 1L, 2);
assertCalcDifficultyMultiplier(0L, 5, 2); // 5 seconds
assertCalcDifficultyMultiplier(0L, 1 * 10, 1); // 10 seconds
assertCalcDifficultyMultiplier(0L, 2 * 10, -0); // 20 seconds
assertCalcDifficultyMultiplier(0L, 10 * 10, -9); // 100 seconds
assertCalcDifficultyMultiplier(0L, 60 * 10, -64); // 10 mins
assertCalcDifficultyMultiplier(0L, 60 * 12, -78); // 12 mins
}
private void assertCalcDifficultyMultiplier(long parentBlockTimestamp, long curBlockTimestamp, int expectedMultiplier) {
BlockHeader parent = new BlockHeaderBuilder(FAKE_HASH, 0L, 0)
.withTimestamp(parentBlockTimestamp)
.build();
BlockHeader current = new BlockHeaderBuilder(parent.getHash(), 1L, 0)
.withTimestamp(curBlockTimestamp)
.build();
assertEquals(expectedMultiplier, constantinopleConfig.getCalcDifficultyMultiplier(current, parent).intValue());
}
@Test
public void testExplosionChanges() throws Exception {
BlockHeader beforePauseBlock = new BlockHeaderBuilder(FAKE_HASH, 4_000_000, 0).build();
assertEquals(-2, constantinopleConfig.getExplosion(beforePauseBlock, null));
BlockHeader endOfIceAge = new BlockHeaderBuilder(FAKE_HASH, 5_000_000, 0).build();
assertEquals(-2, constantinopleConfig.getExplosion(endOfIceAge, null));
BlockHeader startExplodingBlock = new BlockHeaderBuilder(FAKE_HASH, 5_200_000, 0).build();
assertEquals(0, constantinopleConfig.getExplosion(startExplodingBlock, null));
startExplodingBlock = new BlockHeaderBuilder(FAKE_HASH, 6_000_000, 0).build();
assertEquals(8, constantinopleConfig.getExplosion(startExplodingBlock, null));
startExplodingBlock = new BlockHeaderBuilder(FAKE_HASH, 8_000_000, 0).build();
assertEquals(28, constantinopleConfig.getExplosion(startExplodingBlock, null));
}
@Test
public void testBlockReward() throws Exception {
ConstantinopleConfig constantinopleConfig2 = new ConstantinopleConfig(new TestBlockchainConfig() {
@Override
public Constants getConstants() {
return new ConstantsAdapter(super.getConstants()) {
@Override
public BigInteger getBLOCK_REWARD() {
// Make sure ConstantinopleConfig is not using parent's block reward
return BigInteger.TEN;
}
};
}
});
assertEquals(EtherUtil.convert(2, EtherUtil.Unit.ETHER), constantinopleConfig2.getConstants().getBLOCK_REWARD());
}
}
| 8,791
| 43.857143
| 124
|
java
|
ethereumj
|
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/config/blockchain/Eip150HFConfigTest.java
|
/*
* Copyright (c) [2017] [ <ether.camp> ]
* This file is part of the ethereumJ library.
*
* The ethereumJ library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The ethereumJ library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the ethereumJ library. If not, see <http://www.gnu.org/licenses/>.
*
*
*/
package org.ethereum.config.blockchain;
import org.ethereum.config.SystemProperties;
import org.ethereum.core.Transaction;
import org.ethereum.vm.DataWord;
import org.ethereum.vm.OpCode;
import org.junit.Test;
import java.math.BigInteger;
import static org.junit.Assert.*;
/**
* <p>This unit test covers EIP-150:</p>
*
* <pre>
* EIP: 150
* Title: Gas cost changes for IO-heavy operations
* Author: Vitalik Buterin
* Type: Standard Track
* Category: Core
* Status: Final
* Created: 2016-09-24
* </pre>
*
* <pre>If block.number >= FORK_BLKNUM, then:</pre>
* <ul>
* <li>Increase the gas cost of EXTCODESIZE to 700</li>
* <li>Increase the base gas cost of EXTCODECOPY to 700</li>
* <li>Increase the gas cost of BALANCE to 400</li>
* <li>Increase the gas cost of SLOAD to 200</li>
* <li>Increase the gas cost of CALL, DELEGATECALL, CALLCODE to 700</li>
* <li>Increase the gas cost of SELFDESTRUCT to 5000</li>
* <li>If SELFDESTRUCT hits a newly created account, it triggers an additional gas cost of 25000 (similar to CALLs)</li>
* <li>Increase the recommended gas limit target to 5.5 million</li>
* <li>Define "all but one 64th" of N as N - floor(N / 64)</li>
* <li>If a call asks for more gas than the maximum allowed amount (ie. total amount of gas remaining
* in the parent after subtracting the gas cost of the call and memory expansion), do not return an
* OOG error; instead, if a call asks for more gas than all but one 64th of the maximum allowed amount,
* call with all but one 64th of the maximum allowed amount of gas (this is equivalent to a version of
* #90 plus #114). CREATE only provides all but one 64th of the parent gas to the child call.</li>
* </ul>
* <p>Source -- https://github.com/ethereum/EIPs/blob/master/EIPS/eip-150.md</p>
*/
public class Eip150HFConfigTest {
@Test
public void testNewGasCost() {
Eip150HFConfig.GasCostEip150HF gasCostEip150HF = new Eip150HFConfig.GasCostEip150HF();
assertEquals(700, gasCostEip150HF.getEXT_CODE_SIZE());
assertEquals(700, gasCostEip150HF.getEXT_CODE_COPY());
assertEquals(400, gasCostEip150HF.getBALANCE());
assertEquals(200, gasCostEip150HF.getSLOAD());
assertEquals(700, gasCostEip150HF.getCALL());
assertEquals(5000, gasCostEip150HF.getSUICIDE());
assertEquals(25000, gasCostEip150HF.getNEW_ACCT_SUICIDE());
// TODO: Verify recommended gas limit target of 5.5 million. This may no longer apply though.
}
@Test
public void testGetCreateGas() {
Eip150HFConfig eip150 = new Eip150HFConfig(null);
DataWord createGas = eip150.getCreateGas(DataWord.of(64_000));
assertEquals(BigInteger.valueOf(63_000), createGas.value());
}
@Test
public void testAllButOne64thToUseFloor() {
Eip150HFConfig eip150 = new Eip150HFConfig(new DaoHFConfig());
assertCallGas(eip150, 63, 64, 63);
assertCallGas(eip150, 100, 64, 63);
assertCallGas(eip150, 10, 64, 10);
assertCallGas(eip150, 0, 64, 0);
assertCallGas(eip150, -10, 64, 63);
assertCallGas(eip150, 11, 10, 10);
}
private void assertCallGas(Eip150HFConfig eip150, long requestedGas, long availableGas, long expectedCallGas) {
DataWord callGas = eip150.getCallGas(OpCode.CALL, DataWord.of(requestedGas), DataWord.of(availableGas));
assertEquals(BigInteger.valueOf(expectedCallGas), callGas.value());
}
@Test
public void testRelatedEip() {
TestBlockchainConfig parentAllDependentEipTrue = new TestBlockchainConfig()
.enableEip161()
.enableEip198()
.enableEip212()
.enableEip213();
Eip150HFConfig eip150 = new Eip150HFConfig(parentAllDependentEipTrue);
// Inherited from parent
assertTrue(eip150.eip161());
assertTrue(eip150.eip198());
assertTrue(eip150.eip212());
assertTrue(eip150.eip213());
// Always false
assertFalse(eip150.eip206());
assertFalse(eip150.eip211());
assertFalse(eip150.eip214());
assertFalse(eip150.eip658());
/*
* By flipping parent's eip values, we assert that
* Eip150 delegates respective eip calls to parent.
*/
parentAllDependentEipTrue = new TestBlockchainConfig();
eip150 = new Eip150HFConfig(parentAllDependentEipTrue);
// Inherited from parent
assertFalse(eip150.eip161());
assertFalse(eip150.eip198());
assertFalse(eip150.eip212());
assertFalse(eip150.eip213());
// Always false
assertFalse(eip150.eip206());
assertFalse(eip150.eip211());
assertFalse(eip150.eip214());
assertFalse(eip150.eip658());
}
@Test
public void testParentInheritedProperties() {
byte[] emptyBytes = new byte[]{};
SystemProperties props = new SystemProperties();
TestBlockchainConfig parent = new TestBlockchainConfig();
Eip150HFConfig eip150 = new Eip150HFConfig(parent);
assertEquals(parent.constants, eip150.getConstants());
assertEquals(parent.minerIfc, eip150.getMineAlgorithm(props));
assertEquals(parent.difficulty, eip150.calcDifficulty(null, null));
assertEquals(parent.difficultyMultiplier, eip150.getCalcDifficultyMultiplier(null, null));
assertEquals(parent.transactionCost, eip150.getTransactionCost(null));
assertEquals(parent.validateTransactionChanges, eip150.validateTransactionChanges(null, null, null, null));
assertEquals(parent.extraData, eip150.getExtraData(emptyBytes, 0L));
assertEquals(parent.headerValidators, eip150.headerValidators());
assertEquals(parent.constants, eip150.getCommonConstants());
assertSame(eip150, eip150.getConfigForBlock(0));
assertSame(eip150, eip150.getConfigForBlock(1));
assertSame(eip150, eip150.getConfigForBlock(5_000_000));
assertTrue(eip150.getGasCost() instanceof Eip150HFConfig.GasCostEip150HF);
Transaction txWithoutChainId = new Transaction(emptyBytes, emptyBytes, emptyBytes, emptyBytes, emptyBytes, emptyBytes, null);
assertTrue(eip150.acceptTransactionSignature(txWithoutChainId));
Transaction txWithChainId = new Transaction(emptyBytes, emptyBytes, emptyBytes, emptyBytes, emptyBytes, emptyBytes, 1);
assertFalse(eip150.acceptTransactionSignature(txWithChainId));
}
}
| 7,321
| 42.070588
| 133
|
java
|
ethereumj
|
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/config/blockchain/TestBlockchainConfig.java
|
/*
* Copyright (c) [2017] [ <ether.camp> ]
* This file is part of the ethereumJ library.
*
* The ethereumJ library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The ethereumJ library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the ethereumJ library. If not, see <http://www.gnu.org/licenses/>.
*
*
*/
package org.ethereum.config.blockchain;
import com.google.common.util.concurrent.ListenableFuture;
import org.apache.commons.lang3.tuple.Pair;
import org.ethereum.config.Constants;
import org.ethereum.config.SystemProperties;
import org.ethereum.core.Block;
import org.ethereum.core.BlockHeader;
import org.ethereum.core.Repository;
import org.ethereum.core.Transaction;
import org.ethereum.db.BlockStore;
import org.ethereum.mine.MinerIfc;
import org.ethereum.mine.MinerListener;
import org.ethereum.validator.BlockHeaderValidator;
import java.math.BigInteger;
import java.util.Collection;
import java.util.List;
import static com.google.common.collect.Lists.newArrayList;
@SuppressWarnings("WeakerAccess")
class TestBlockchainConfig extends AbstractConfig {
boolean eip161 = false;
boolean eip198 = false;
boolean eip206 = false;
boolean eip211 = false;
boolean eip212 = false;
boolean eip213 = false;
boolean eip214 = false;
boolean eip658 = false;
Constants constants = new Constants();
MinerIfc minerIfc = new TestMinerIfc();
BigInteger difficulty = BigInteger.valueOf(100);
BigInteger difficultyMultiplier = BigInteger.valueOf(20);
long transactionCost = 200L;
boolean acceptTransactionSignature = true;
String validateTransactionChanges = "test";
byte[] extraData = new byte[]{};
List<Pair<Long, BlockHeaderValidator>> headerValidators = newArrayList();
public TestBlockchainConfig enableAllEip() {
return this
.enableEip161()
.enableEip198()
.enableEip206()
.enableEip211()
.enableEip212()
.enableEip213()
.enableEip214()
.enableEip658();
}
public TestBlockchainConfig enableEip161() {
this.eip161 = true;
return this;
}
public TestBlockchainConfig enableEip198() {
this.eip198 = true;
return this;
}
public TestBlockchainConfig enableEip206() {
this.eip206 = true;
return this;
}
public TestBlockchainConfig enableEip211() {
this.eip211 = true;
return this;
}
public TestBlockchainConfig enableEip212() {
this.eip212 = true;
return this;
}
public TestBlockchainConfig enableEip213() {
this.eip213 = true;
return this;
}
public TestBlockchainConfig enableEip214() {
this.eip214 = true;
return this;
}
public TestBlockchainConfig enableEip658() {
this.eip658 = true;
return this;
}
@Override
public Constants getConstants() {
return constants;
}
@Override
public MinerIfc getMineAlgorithm(SystemProperties config) {
return minerIfc;
}
@Override
public BigInteger calcDifficulty(BlockHeader curBlock, BlockHeader parent) {
return difficulty;
}
@Override
public BigInteger getCalcDifficultyMultiplier(BlockHeader curBlock, BlockHeader parent) {
return difficultyMultiplier;
}
@Override
public long getTransactionCost(Transaction tx) {
return transactionCost;
}
@Override
public boolean acceptTransactionSignature(Transaction tx) {
return acceptTransactionSignature;
}
@Override
public String validateTransactionChanges(BlockStore blockStore, Block curBlock, Transaction tx, Repository repository) {
return validateTransactionChanges;
}
@Override
public byte[] getExtraData(byte[] minerExtraData, long blockNumber) {
return extraData;
}
@Override
public List<Pair<Long, BlockHeaderValidator>> headerValidators() {
return headerValidators;
}
@Override
public boolean eip161() {
return eip161;
}
@Override
public boolean eip198() {
return eip198;
}
@Override
public boolean eip212() {
return eip212;
}
@Override
public boolean eip213() {
return eip213;
}
public class TestMinerIfc implements MinerIfc {
@Override
public ListenableFuture<MiningResult> mine(Block block) {
return null;
}
@Override
public boolean validate(BlockHeader blockHeader) {
return false;
}
@Override
public void setListeners(Collection<MinerListener> listeners) {}
}
}
| 5,232
| 25.69898
| 124
|
java
|
ethereumj
|
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/config/blockchain/ByzantiumConfigTest.java
|
/*
* Copyright (c) [2017] [ <ether.camp> ]
* This file is part of the ethereumJ library.
*
* The ethereumJ library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The ethereumJ library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the ethereumJ library. If not, see <http://www.gnu.org/licenses/>.
*
*
*/
package org.ethereum.config.blockchain;
import org.ethereum.config.Constants;
import org.ethereum.config.ConstantsAdapter;
import org.ethereum.core.BlockHeader;
import org.junit.Test;
import org.spongycastle.util.encoders.Hex;
import java.math.BigInteger;
import static org.junit.Assert.*;
@SuppressWarnings("SameParameterValue")
public class ByzantiumConfigTest {
private static final byte[] FAKE_HASH = {11, 12};
@Test
public void testPredefinedChainId() throws Exception {
ByzantiumConfig byzantiumConfig = new ByzantiumConfig(new TestBlockchainConfig());
assertEquals(1, (int) byzantiumConfig.getChainId());
}
@Test
public void testRelatedEip() throws Exception {
TestBlockchainConfig parent = new TestBlockchainConfig();
ByzantiumConfig byzantiumConfig = new ByzantiumConfig(parent);
// Inherited from parent
assertTrue(byzantiumConfig.eip198());
assertTrue(byzantiumConfig.eip206());
assertTrue(byzantiumConfig.eip211());
assertTrue(byzantiumConfig.eip212());
assertTrue(byzantiumConfig.eip213());
assertTrue(byzantiumConfig.eip214());
assertTrue(byzantiumConfig.eip658());
// Always false
assertTrue(byzantiumConfig.eip161());
}
@Test
public void testDifficultyWithoutExplosion() throws Exception {
ByzantiumConfig byzantiumConfig = new ByzantiumConfig(new TestBlockchainConfig());
BlockHeader parent = new BlockHeaderBuilder(new byte[]{11, 12}, 0L, 1_000_000).build();
BlockHeader current = new BlockHeaderBuilder(parent.getHash(), 1L, -1).build();
BigInteger difficulty = byzantiumConfig.calcDifficulty(current, parent);
assertEquals(BigInteger.valueOf(1_000_976), difficulty);
}
@Test
public void testDifficultyAdjustedForParentBlockHavingUncles() throws Exception {
ByzantiumConfig byzantiumConfig = new ByzantiumConfig(new TestBlockchainConfig());
BlockHeader parent = new BlockHeaderBuilder(new byte[]{11, 12}, 0L, 0)
.withTimestamp(0L)
.withUncles(new byte[]{1, 2})
.build();
BlockHeader current = new BlockHeaderBuilder(parent.getHash(), 1L, 0)
.withTimestamp(9L)
.build();
assertEquals(1, byzantiumConfig.getCalcDifficultyMultiplier(current, parent).intValue());
}
@Test
public void testEtherscanIoBlock4490790() throws Exception {
ByzantiumConfig byzantiumConfig = new ByzantiumConfig(new TestBlockchainConfig());
// https://etherscan.io/block/4490788
String parentHash = "fd9d7467e933ff2975c33ea3045ddf8773c87c4cec4e7da8de1bcc015361b38b";
BlockHeader parent = new BlockHeaderBuilder(parentHash.getBytes(), 4490788, "1,377,255,445,606,146")
.withTimestamp(1509827488)
// Actually an empty list hash, so _no_ uncles
.withUncles(Hex.decode("1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347"))
.build();
// https://etherscan.io/block/4490789
BlockHeader current = new BlockHeaderBuilder(parent.getHash(), 4490789, BigInteger.ZERO)
.withTimestamp(1509827494)
.build();
BigInteger minimumDifficulty = byzantiumConfig.calcDifficulty(current, parent);
BigInteger actualDifficultyOnEtherscan = BlockHeaderBuilder.parse("1,377,927,933,620,791");
assertTrue(actualDifficultyOnEtherscan.compareTo(minimumDifficulty) > -1);
}
@Test
public void testDifficultyWithExplosionShouldBeImpactedByBlockTimestamp() throws Exception {
ByzantiumConfig byzantiumConfig = new ByzantiumConfig(new TestBlockchainConfig());
BlockHeader parent = new BlockHeaderBuilder(new byte[]{11, 12}, 2_500_000, 8_388_608)
.withTimestamp(0)
.build();
BlockHeader current = new BlockHeaderBuilder(parent.getHash(), 2_500_001, 8_388_608)
.withTimestamp(10 * 60) // 10 minutes later, longer time: lowers difficulty
.build();
BigInteger difficulty = byzantiumConfig.calcDifficulty(current, parent);
assertEquals(BigInteger.valueOf(8126464), difficulty);
parent = new BlockHeaderBuilder(new byte[]{11, 12}, 2_500_000, 8_388_608)
.withTimestamp(0)
.build();
current = new BlockHeaderBuilder(parent.getHash(), 2_500_001, 8_388_608)
.withTimestamp(5) // 5 seconds later, shorter time: higher difficulty
.build();
difficulty = byzantiumConfig.calcDifficulty(current, parent);
assertEquals(BigInteger.valueOf(8396800), difficulty);
}
@Test
public void testDifficultyAboveBlock3MShouldTriggerExplosion() throws Exception {
ByzantiumConfig byzantiumConfig = new ByzantiumConfig(new TestBlockchainConfig());
int parentDifficulty = 268_435_456;
BlockHeader parent = new BlockHeaderBuilder(FAKE_HASH, 4_000_000, parentDifficulty).build();
BlockHeader current = new BlockHeaderBuilder(parent.getHash(), 4_000_001, -1).build();
int actualDifficulty = byzantiumConfig.calcDifficulty(current, parent).intValue();
int differenceWithoutExplosion = actualDifficulty - parentDifficulty;
assertEquals(262_400, differenceWithoutExplosion);
parent = new BlockHeaderBuilder(FAKE_HASH, 5_000_000, parentDifficulty).build();
current = new BlockHeaderBuilder(parent.getHash(), 5_000_001, -1).build();
actualDifficulty = byzantiumConfig.calcDifficulty(current, parent).intValue();
differenceWithoutExplosion = actualDifficulty - parentDifficulty;
assertEquals(524_288, differenceWithoutExplosion);
parent = new BlockHeaderBuilder(FAKE_HASH, 6_000_000, parentDifficulty).build();
current = new BlockHeaderBuilder(parent.getHash(), 6_000_001, -1).build();
actualDifficulty = byzantiumConfig.calcDifficulty(current, parent).intValue();
differenceWithoutExplosion = actualDifficulty - parentDifficulty;
assertEquals(268_697_600, differenceWithoutExplosion);
}
@Test
@SuppressWarnings("PointlessArithmeticExpression")
public void testCalcDifficultyMultiplier() throws Exception {
// Note; timestamps are in seconds
assertCalcDifficultyMultiplier(0L, 1L, 2);
assertCalcDifficultyMultiplier(0L, 5, 2); // 5 seconds
assertCalcDifficultyMultiplier(0L, 1 * 10, 1); // 10 seconds
assertCalcDifficultyMultiplier(0L, 2 * 10, -0); // 20 seconds
assertCalcDifficultyMultiplier(0L, 10 * 10, -9); // 100 seconds
assertCalcDifficultyMultiplier(0L, 60 * 10, -64); // 10 mins
assertCalcDifficultyMultiplier(0L, 60 * 12, -78); // 12 mins
}
private void assertCalcDifficultyMultiplier(long parentBlockTimestamp, long curBlockTimestamp, int expectedMultiplier) {
ByzantiumConfig byzantiumConfig = new ByzantiumConfig(new TestBlockchainConfig());
BlockHeader parent = new BlockHeaderBuilder(new byte[]{11, 12}, 0L, 0)
.withTimestamp(parentBlockTimestamp)
.build();
BlockHeader current = new BlockHeaderBuilder(parent.getHash(), 1L, 0)
.withTimestamp(curBlockTimestamp)
.build();
assertEquals(expectedMultiplier, byzantiumConfig.getCalcDifficultyMultiplier(current, parent).intValue());
}
@Test
public void testExplosionChanges() throws Exception {
ByzantiumConfig byzantiumConfig = new ByzantiumConfig(new TestBlockchainConfig());
BlockHeader beforePauseBlock = new BlockHeaderBuilder(FAKE_HASH, 2_000_000, 0).build();
assertEquals(-2, byzantiumConfig.getExplosion(beforePauseBlock, null));
BlockHeader endOfIceAge = new BlockHeaderBuilder(FAKE_HASH, 3_000_000, 0).build();
assertEquals(-2, byzantiumConfig.getExplosion(endOfIceAge, null));
BlockHeader startExplodingBlock = new BlockHeaderBuilder(FAKE_HASH, 3_200_000, 0).build();
assertEquals(0, byzantiumConfig.getExplosion(startExplodingBlock, null));
startExplodingBlock = new BlockHeaderBuilder(FAKE_HASH, 4_000_000, 0).build();
assertEquals(8, byzantiumConfig.getExplosion(startExplodingBlock, null));
startExplodingBlock = new BlockHeaderBuilder(FAKE_HASH, 6_000_000, 0).build();
assertEquals(28, byzantiumConfig.getExplosion(startExplodingBlock, null));
}
@Test
public void testBlockReward() throws Exception {
ByzantiumConfig byzantiumConfig = new ByzantiumConfig(new TestBlockchainConfig() {
@Override
public Constants getConstants() {
return new ConstantsAdapter(super.getConstants()) {
@Override
public BigInteger getBLOCK_REWARD() {
// Make sure ByzantiumConfig is not using parent's block reward
return BigInteger.TEN;
}
};
}
});
assertEquals(new BigInteger("3000000000000000000"), byzantiumConfig.getConstants().getBLOCK_REWARD());
}
}
| 10,025
| 44.572727
| 124
|
java
|
ethereumj
|
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/config/blockchain/Eip160HFConfigTest.java
|
/*
* Copyright (c) [2017] [ <ether.camp> ]
* This file is part of the ethereumJ library.
*
* The ethereumJ library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The ethereumJ library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the ethereumJ library. If not, see <http://www.gnu.org/licenses/>.
*
*
*/
package org.ethereum.config.blockchain;
import org.ethereum.config.Constants;
import org.ethereum.core.Transaction;
import org.ethereum.crypto.ECKey;
import org.ethereum.util.ByteUtil;
import org.junit.Test;
import org.spongycastle.util.BigIntegers;
import org.spongycastle.util.encoders.Hex;
import java.math.BigInteger;
import java.util.Arrays;
import static java.math.BigInteger.valueOf;
import static org.junit.Assert.*;
/**
<pre>
Specification
If block.number >= FORK_BLKNUM, increase the gas cost of EXP from 10 + 10 per byte in the
exponent to 10 + 50 per byte in the exponent.
</pre>
*
* https://github.com/ethereum/EIPs/blob/master/EIPS/eip-160.md
*/
public class Eip160HFConfigTest {
private byte[] emptyBytes = new byte[]{};
@Test
public void testGetGasCost() throws Exception {
TestBlockchainConfig parent = new TestBlockchainConfig();
Eip160HFConfig config = new Eip160HFConfig(parent);
assertTrue(config.getGasCost() instanceof Eip160HFConfig.GasCostEip160HF);
assertEquals(50, config.getGasCost().getEXP_BYTE_GAS());
}
@Test
public void testMaxContractSizeIsOnlyChangeInEip160() throws Exception {
TestBlockchainConfig parent = new TestBlockchainConfig();
Eip160HFConfig config = new Eip160HFConfig(parent);
assertEquals(0x6000, config.getConstants().getMAX_CONTRACT_SZIE());
Constants expected = parent.getConstants();
Constants actual = config.getConstants();
assertEquals(expected.getInitialNonce(), actual.getInitialNonce());
assertEquals(expected.getMINIMUM_DIFFICULTY(), actual.getMINIMUM_DIFFICULTY());
assertEquals(expected.getDIFFICULTY_BOUND_DIVISOR(), actual.getDIFFICULTY_BOUND_DIVISOR());
assertEquals(expected.getMAXIMUM_EXTRA_DATA_SIZE(), actual.getMAXIMUM_EXTRA_DATA_SIZE());
assertEquals(expected.getBLOCK_REWARD(), actual.getBLOCK_REWARD());
assertEquals(expected.getEXP_DIFFICULTY_PERIOD(), actual.getEXP_DIFFICULTY_PERIOD());
assertEquals(expected.getGAS_LIMIT_BOUND_DIVISOR(), actual.getGAS_LIMIT_BOUND_DIVISOR());
assertEquals(expected.getUNCLE_GENERATION_LIMIT(), actual.getUNCLE_GENERATION_LIMIT());
assertEquals(expected.getUNCLE_LIST_LIMIT(), actual.getUNCLE_LIST_LIMIT());
assertEquals(expected.getDURATION_LIMIT(), actual.getDURATION_LIMIT());
assertEquals(expected.getBEST_NUMBER_DIFF_LIMIT(), actual.getBEST_NUMBER_DIFF_LIMIT());
assertEquals(expected.createEmptyContractOnOOG(), actual.createEmptyContractOnOOG());
assertEquals(expected.hasDelegateCallOpcode(), actual.hasDelegateCallOpcode());
}
/**
* See also {@link org.ethereum.core.TransactionTest#afterEIP158Test} which tests the
* EIP-155 'signature.v' specification changes.
*/
@Test
public void testAcceptTransactionWithSignature() throws Exception {
Transaction tx = Transaction.create(
"3535353535353535353535353535353535353535",
new BigInteger("1000000000000000000"),
new BigInteger("9"),
new BigInteger("20000000000"),
new BigInteger("21000"),
1);
ECKey ecKey = ECKey.fromPrivate(Hex.decode("4646464646464646464646464646464646464646464646464646464646464646"));
tx.sign(ecKey);
TestBlockchainConfig parent = new TestBlockchainConfig();
Eip160HFConfig config = new Eip160HFConfig(parent);
assertTrue(config.acceptTransactionSignature(tx));
}
@Test
public void testDenyTransactionWithInvalidSignature() throws Exception {
Transaction tx = Transaction.create(
"3535353535353535353535353535353535353535",
new BigInteger("1000000000000000000"),
new BigInteger("9"),
new BigInteger("20000000000"),
new BigInteger("21000"),
1);
ECKey ecKey = ECKey.fromPrivate(Hex.decode("4646464646464646464646464646464646464646464646464646464646464646"));
tx.sign(ecKey);
TestBlockchainConfig parent = new TestBlockchainConfig();
Eip160HFConfig config = new Eip160HFConfig(parent);
// Corrupt the signature and assert it's *not* accepted
tx.getSignature().v = 99;
assertFalse(config.acceptTransactionSignature(tx));
}
@Test
public void testDenyTransactionWithoutSignature() throws Exception {
TestBlockchainConfig parent = new TestBlockchainConfig();
Eip160HFConfig config = new Eip160HFConfig(parent);
Transaction txWithoutSignature = new Transaction(emptyBytes, emptyBytes, emptyBytes, emptyBytes, emptyBytes, emptyBytes, null);
assertFalse(config.acceptTransactionSignature(txWithoutSignature));
}
}
| 5,605
| 41.469697
| 135
|
java
|
ethereumj
|
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/config/net/TestNetConfigTest.java
|
/*
* Copyright (c) [2017] [ <ether.camp> ]
* This file is part of the ethereumJ library.
*
* The ethereumJ library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The ethereumJ library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the ethereumJ library. If not, see <http://www.gnu.org/licenses/>.
*
*
*/
package org.ethereum.config.net;
import org.ethereum.config.BlockchainConfig;
import org.ethereum.config.BlockchainNetConfig;
import org.ethereum.config.blockchain.FrontierConfig;
import org.ethereum.config.blockchain.HomesteadConfig;
import org.junit.Test;
import static org.junit.Assert.assertTrue;
public class TestNetConfigTest {
@Test
public void verifyETCNetConfigConstruction() {
TestNetConfig config = new TestNetConfig();
assertBlockchainConfigExistsAt(config, 0, FrontierConfig.class);
assertBlockchainConfigExistsAt(config, 1_150_000, HomesteadConfig.class);
}
private <T extends BlockchainConfig> void assertBlockchainConfigExistsAt(BlockchainNetConfig netConfig, long blockNumber, Class<T> configType) {
BlockchainConfig block = netConfig.getConfigForBlock(blockNumber);
assertTrue(configType.isAssignableFrom(block.getClass()));
}
}
| 1,709
| 37
| 148
|
java
|
ethereumj
|
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/config/net/ETCNetConfigTest.java
|
/*
* Copyright (c) [2016] [ <ether.camp> ]
* This file is part of the ethereumJ library.
*
* The ethereumJ library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The ethereumJ library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the ethereumJ library. If not, see <http://www.gnu.org/licenses/>.
*/
package org.ethereum.config.net;
import org.ethereum.config.BlockchainConfig;
import org.ethereum.config.BlockchainNetConfig;
import org.ethereum.config.blockchain.Eip150HFConfig;
import org.ethereum.config.blockchain.Eip160HFConfig;
import org.ethereum.config.blockchain.FrontierConfig;
import org.ethereum.config.blockchain.HomesteadConfig;
import org.junit.Test;
import static org.junit.Assert.assertTrue;
public class ETCNetConfigTest {
@Test
public void verifyETCNetConfigConstruction() {
ETCNetConfig config = new ETCNetConfig();
assertBlockchainConfigExistsAt(config, 0, FrontierConfig.class);
assertBlockchainConfigExistsAt(config, 1_150_000, HomesteadConfig.class);
assertBlockchainConfigExistsAt(config, 2_500_000, Eip150HFConfig.class);
assertBlockchainConfigExistsAt(config, 3_000_000, Eip160HFConfig.class);
}
private <T extends BlockchainConfig> void assertBlockchainConfigExistsAt(BlockchainNetConfig netConfig, long blockNumber, Class<T> configType) {
BlockchainConfig block = netConfig.getConfigForBlock(blockNumber);
assertTrue(configType.isAssignableFrom(block.getClass()));
}
}
| 1,969
| 41.826087
| 148
|
java
|
ethereumj
|
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/config/net/JsonNetConfigTest.java
|
/*
* Copyright (c) [2017] [ <ether.camp> ]
* This file is part of the ethereumJ library.
*
* The ethereumJ library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The ethereumJ library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the ethereumJ library. If not, see <http://www.gnu.org/licenses/>.
*
*
*/
package org.ethereum.config.net;
import org.ethereum.config.BlockchainConfig;
import org.ethereum.config.BlockchainNetConfig;
import org.ethereum.config.blockchain.*;
import org.ethereum.core.genesis.GenesisConfig;
import org.ethereum.util.blockchain.EtherUtil;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
public class JsonNetConfigTest {
@Test
public void testCreationBasedOnGenesis() {
GenesisConfig genesisConfig = new GenesisConfig();
genesisConfig.eip155Block = 10;
JsonNetConfig config = new JsonNetConfig(genesisConfig);
assertBlockchainConfigExistsAt(config, 0, FrontierConfig.class);
assertBlockchainConfigExistsAt(config, 10, Eip150HFConfig.class);
}
@Test
public void testCreationBasedOnDaoForkAndEip150Blocks_noHardFork() {
GenesisConfig genesisConfig = new GenesisConfig();
genesisConfig.daoForkBlock = 10;
genesisConfig.eip150Block = 20;
genesisConfig.daoForkSupport = false;
JsonNetConfig config = new JsonNetConfig(genesisConfig);
assertBlockchainConfigExistsAt(config, 0, FrontierConfig.class);
assertBlockchainConfigExistsAt(config, 10, DaoNoHFConfig.class);
assertBlockchainConfigExistsAt(config, 20, Eip150HFConfig.class);
}
@Test
public void testCreationBasedOnDaoHardFork() {
GenesisConfig genesisConfig = new GenesisConfig();
genesisConfig.daoForkBlock = 10;
genesisConfig.daoForkSupport = true;
JsonNetConfig config = new JsonNetConfig(genesisConfig);
assertBlockchainConfigExistsAt(config, 0, FrontierConfig.class);
assertBlockchainConfigExistsAt(config, 10, DaoHFConfig.class);
}
@Test
public void testEip158WithoutEip155CreatesEip160HFConfig() {
GenesisConfig genesisConfig = new GenesisConfig();
genesisConfig.eip158Block = 10;
JsonNetConfig config = new JsonNetConfig(genesisConfig);
assertBlockchainConfigExistsAt(config, 10, Eip160HFConfig.class);
}
@Test
public void testEip155WithoutEip158CreatesEip160HFConfig() {
GenesisConfig genesisConfig = new GenesisConfig();
genesisConfig.eip155Block = 10;
JsonNetConfig config = new JsonNetConfig(genesisConfig);
assertBlockchainConfigExistsAt(config, 10, Eip160HFConfig.class);
}
@Test
public void testChainIdIsCorrectlySetOnEip160HFConfig() {
GenesisConfig genesisConfig = new GenesisConfig();
genesisConfig.eip155Block = 10;
JsonNetConfig config = new JsonNetConfig(genesisConfig);
BlockchainConfig eip160 = config.getConfigForBlock(10);
assertEquals("Default chainId must be '1'", new Integer(1), eip160.getChainId());
genesisConfig.chainId = 99;
config = new JsonNetConfig(genesisConfig);
eip160 = config.getConfigForBlock(10);
assertEquals("chainId should be copied from genesis config", new Integer(99), eip160.getChainId());
}
@Test
public void testEip155MustMatchEip158IfBothExist() {
GenesisConfig genesisConfig = new GenesisConfig();
genesisConfig.eip155Block = 10;
genesisConfig.eip158Block = 10;
JsonNetConfig config = new JsonNetConfig(genesisConfig);
assertBlockchainConfigExistsAt(config, 10, Eip160HFConfig.class);
try {
genesisConfig.eip158Block = 13;
new JsonNetConfig(genesisConfig);
fail("Must fail. EIP155 and EIP158 must have same blocks");
} catch (RuntimeException e) {
assertEquals("Unable to build config with different blocks for EIP155 (10) and EIP158 (13)", e.getMessage());
}
}
@Test
public void testByzantiumBlock() {
GenesisConfig genesisConfig = new GenesisConfig();
genesisConfig.byzantiumBlock = 50;
JsonNetConfig config = new JsonNetConfig(genesisConfig);
assertBlockchainConfigExistsAt(config, 50, ByzantiumConfig.class);
BlockchainConfig eip160 = config.getConfigForBlock(50);
assertEquals("Default chainId must be '1'", new Integer(1), eip160.getChainId());
genesisConfig.chainId = 99;
config = new JsonNetConfig(genesisConfig);
eip160 = config.getConfigForBlock(50);
assertEquals("chainId should be copied from genesis config", new Integer(99), eip160.getChainId());
}
@Test
public void testConstantinopleBlock() {
final int byzStart = 50;
final int cnstStart = 60;
GenesisConfig genesisConfig = new GenesisConfig();
genesisConfig.constantinopleBlock = cnstStart;
JsonNetConfig config = new JsonNetConfig(genesisConfig);
assertBlockchainConfigExistsAt(config, cnstStart, ConstantinopleConfig.class);
BlockchainConfig blockchainConfig = config.getConfigForBlock(cnstStart);
assertEquals("Default chainId must be '1'", new Integer(1), blockchainConfig.getChainId());
assertEquals("Reward should be 2 ETH", EtherUtil.convert(2, EtherUtil.Unit.ETHER), blockchainConfig.getConstants().getBLOCK_REWARD());
assertTrue("EIP-1014 skinny CREATE2 should be activated among others", blockchainConfig.eip1014());
genesisConfig.chainId = 99;
config = new JsonNetConfig(genesisConfig);
blockchainConfig = config.getConfigForBlock(cnstStart);
assertEquals("chainId should be copied from genesis config", new Integer(99), blockchainConfig.getChainId());
assertEquals("Default Frontier reward is 5 ETH", EtherUtil.convert(5, EtherUtil.Unit.ETHER),
config.getConfigForBlock(byzStart).getConstants().getBLOCK_REWARD());
genesisConfig.byzantiumBlock = byzStart;
config = new JsonNetConfig(genesisConfig); // Respawn so we have Byzantium on byzStart instead of Frontier
assertEquals("Reward should be 3 ETH in Byzantium", EtherUtil.convert(3, EtherUtil.Unit.ETHER),
config.getConfigForBlock(byzStart).getConstants().getBLOCK_REWARD());
assertEquals("Reward should be changed to 2 ETH in Constantinople", EtherUtil.convert(2, EtherUtil.Unit.ETHER),
config.getConfigForBlock(cnstStart).getConstants().getBLOCK_REWARD());
}
private <T extends BlockchainConfig> void assertBlockchainConfigExistsAt(BlockchainNetConfig netConfig, long blockNumber, Class<T> configType) {
BlockchainConfig block = netConfig.getConfigForBlock(blockNumber);
if (!configType.isAssignableFrom(block.getClass())) {
fail(block.getClass().getName() + " is not of type " + configType);
}
}
}
| 7,516
| 42.450867
| 148
|
java
|
ethereumj
|
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/config/net/BaseNetConfigTest.java
|
/*
* Copyright (c) [2016] [ <ether.camp> ]
* This file is part of the ethereumJ library.
*
* The ethereumJ library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The ethereumJ library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the ethereumJ library. If not, see <http://www.gnu.org/licenses/>.
*/
package org.ethereum.config.net;
import org.ethereum.config.BlockchainConfig;
import org.ethereum.config.blockchain.AbstractConfig;
import org.ethereum.core.BlockHeader;
import org.ethereum.core.Transaction;
import org.junit.Test;
import java.math.BigInteger;
import static org.junit.Assert.*;
public class BaseNetConfigTest {
@Test(expected = RuntimeException.class)
public void addedBlockShouldHaveIncrementedBlockNumber() throws Exception {
BlockchainConfig blockchainConfig = new TestBlockchainConfig();
BaseNetConfig config = new BaseNetConfig();
config.add(0, blockchainConfig);
config.add(1, blockchainConfig);
config.add(0, blockchainConfig);
}
@Test
public void toStringShouldCaterForNulls() throws Exception {
BaseNetConfig config = new BaseNetConfig();
assertEquals("BaseNetConfig{blockNumbers= (total: 0)}", config.toString());
BlockchainConfig blockchainConfig = new TestBlockchainConfig() {
@Override
public String toString() {
return "TestBlockchainConfig";
}
};
config.add(0, blockchainConfig);
assertEquals("BaseNetConfig{blockNumbers= #0 => TestBlockchainConfig (total: 1)}", config.toString());
config.add(1, blockchainConfig);
assertEquals("BaseNetConfig{blockNumbers= #0 => TestBlockchainConfig, #1 => TestBlockchainConfig (total: 2)}", config.toString());
}
private static class TestBlockchainConfig extends AbstractConfig {
@Override
public BigInteger getCalcDifficultyMultiplier(BlockHeader curBlock, BlockHeader parent) {
return BigInteger.ZERO;
}
@Override
public long getTransactionCost(Transaction tx) {
return 0;
}
}
}
| 2,608
| 36.271429
| 138
|
java
|
ethereumj
|
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/manager/BlockLoaderTest.java
|
package org.ethereum.manager;
import org.ethereum.core.Block;
import org.ethereum.core.Blockchain;
import org.ethereum.core.EventDispatchThread;
import org.ethereum.core.Genesis;
import org.ethereum.core.ImportResult;
import org.ethereum.db.DbFlushManager;
import org.ethereum.listener.CompositeEthereumListener;
import org.ethereum.validator.BlockHeaderRule;
import org.ethereum.validator.BlockHeaderValidator;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.core.io.Resource;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import static java.util.Objects.isNull;
import static java.util.stream.Collectors.toList;
import static org.ethereum.util.ByteUtil.EMPTY_BYTE_ARRAY;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = BlockLoaderTest.Config.class)
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
public class BlockLoaderTest {
private static class Holder<T> {
private T object;
public Holder(T object) {
this.object = object;
}
public T get() {
return object;
}
public void set(T object) {
this.object = object;
}
public boolean isEmpty() {
return isNull(object);
}
}
static class Config {
private static final Genesis GENESIS_BLOCK = new Genesis(
EMPTY_BYTE_ARRAY, EMPTY_BYTE_ARRAY, EMPTY_BYTE_ARRAY, EMPTY_BYTE_ARRAY, EMPTY_BYTE_ARRAY,
0, 0, 0, 0, EMPTY_BYTE_ARRAY, EMPTY_BYTE_ARRAY, EMPTY_BYTE_ARRAY);
@Bean
public BlockHeaderValidator headerValidator() {
BlockHeaderValidator validator = Mockito.mock(BlockHeaderValidator.class);
when(validator.validate(any())).thenReturn(new BlockHeaderRule.ValidationResult(true, null));
when(validator.validateAndLog(any(), any())).thenReturn(true);
return validator;
}
@Bean
public Blockchain blockchain(Holder<Block> lastBlockHolder) {
Blockchain blockchain = Mockito.mock(Blockchain.class);
when(blockchain.getBestBlock()).thenAnswer(invocation -> lastBlockHolder.get());
when(blockchain.tryToConnect(any(Block.class))).thenAnswer(invocation -> {
lastBlockHolder.set(invocation.getArgument(0));
return ImportResult.IMPORTED_BEST;
});
return blockchain;
}
@Bean
public Holder<Block> lastBlockHolder() {
return new Holder<>(GENESIS_BLOCK);
}
@Bean
public DbFlushManager dbFlushManager() {
return Mockito.mock(DbFlushManager.class);
}
@Bean
public CompositeEthereumListener ethereumListener() {
return Mockito.mock(CompositeEthereumListener.class);
}
@Bean
public EventDispatchThread dispatchThread() {
return EventDispatchThread.getDefault();
}
@Bean
public BlockLoader blockLoader(BlockHeaderValidator headerValidator, Blockchain blockchain, DbFlushManager dbFlushManager) {
return new BlockLoader(headerValidator, blockchain, dbFlushManager);
}
}
@Autowired
private BlockLoader blockLoader;
private List<Path> dumps;
@Value("classpath:dmp")
public void setDumps( Resource dmpDir) throws IOException {
this.dumps = Arrays.stream(dmpDir.getFile().listFiles())
.sorted()
.map(dmp -> Paths.get(dmp.toURI()))
.collect(toList());
}
@Test
public void testRegularLoading() {
Path[] paths = dumps.toArray(new Path[]{});
boolean loaded = blockLoader.loadBlocks(paths);
assertTrue(loaded);
}
@Test
public void testInconsistentDumpsLoading() {
List<Path> reversed = new ArrayList<>(dumps);
Collections.reverse(reversed);
Path[] paths = reversed.toArray(new Path[]{});
boolean loaded = blockLoader.loadBlocks(paths);
assertFalse(loaded);
}
@Test
public void testNoDumpsLoading() {
assertFalse(blockLoader.loadBlocks());
}
}
| 4,914
| 32.209459
| 132
|
java
|
ethereumj
|
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/db/ByteArrayWrapperTest.java
|
/*
* Copyright (c) [2016] [ <ether.camp> ]
* This file is part of the ethereumJ library.
*
* The ethereumJ library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The ethereumJ library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the ethereumJ library. If not, see <http://www.gnu.org/licenses/>.
*/
package org.ethereum.db;
import org.ethereum.util.FastByteComparisons;
import com.google.common.primitives.UnsignedBytes;
import org.junit.BeforeClass;
import org.junit.Test;
import org.spongycastle.util.encoders.Hex;
import java.util.Arrays;
import java.util.Comparator;
import static org.junit.Assert.*;
public class ByteArrayWrapperTest {
static ByteArrayWrapper wrapper1;
static ByteArrayWrapper wrapper2;
static ByteArrayWrapper wrapper3;
static ByteArrayWrapper wrapper4;
@BeforeClass
public static void loadByteArrays() {
String block = "f9072df8d3a077ef4fdaf389dca53236bcf7f72698e154eab2828f86fbc4fc6c"
+ "d9225d285c89a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0"
+ "a142fd40d493479476f5eabe4b342ee56b8ceba6ab2a770c3e2198e7a0faa0ca"
+ "43105f667dceb168eb4e0cdc98ef28a9da5c381edef70d843207601719a06785"
+ "f3860460b2aa29122698e83a5151b270e82532c1663e89e3df8c5445b8ca833f"
+ "f000018609184e72a000830f3e6f8227d2845387c58f80a00000000000000000"
+ "0000000000000000000000000000000094148d7738f78c04f90654f8c6f8a080"
+ "8609184e72a00082271094000000000000000000000000000000000000000080"
+ "b83a33604557602a5160106000396000f200604556330e0f602a59366000530a"
+ "0f602a596020600053013560005335576040600053016000546009581ca033a6"
+ "bfa5eb2f4b63f1b98bed9a987d096d32e56deecb050367c84955508f5365a015"
+ "034e7574ec073f0c448aac1d9f844387610dfef5342834b6825fbc35df5913a0"
+ "ee258e73d41ada73d8d6071ba7d236fbbe24fcfb9627fbd4310e24ffd87b961a"
+ "8203e9f90194f9016d018609184e72a000822710940000000000000000000000"
+ "00000000000000000080b901067f4e616d655265670000000000000000000000"
+ "00000000000000000000000000003057307f4e616d6552656700000000000000"
+ "000000000000000000000000000000000000577f436f6e666967000000000000"
+ "000000000000000000000000000000000000000073ccdeac59d35627b7de0933"
+ "2e819d5159e7bb72505773ccdeac59d35627b7de09332e819d5159e7bb72507f"
+ "436f6e6669670000000000000000000000000000000000000000000000000000"
+ "57336045576041516100c56000396000f20036602259604556330e0f600f5933"
+ "ff33560f601e5960003356576000335700604158600035560f602b590033560f"
+ "603659600033565733600035576000353357001ca0f3c527e484ea5546189979"
+ "c767b69aa9f1ad5a6f4b6077d4bccf5142723a67c9a069a4a29a2a315102fcd0"
+ "822d39ad696a6d7988c993bb2b911cc2a78bb8902d91a01ebe4782ea3ed224cc"
+ "bb777f5de9ee7b5bbb282ac08f7fa0ef95d3d1c1c6d1a1820ef7f8ccf8a60286"
+ "09184e72a00082271094ccdeac59d35627b7de09332e819d5159e7bb725080b8"
+ "4000000000000000000000000000000000000000000000000000000000000000"
+ "000000000000000000000000002d0aceee7e5ab874e22ccf8d1a649f59106d74"
+ "e81ba095ad45bf574c080e4d72da2cfd3dbe06cc814c1c662b5f74561f13e1e7"
+ "5058f2a057745a3db5482bccb5db462922b074f4b79244c4b1fa811ed094d728"
+ "e7b6da92a08599ea5d6cb6b9ad3311f0d82a3337125e05f4a82b9b0556cb3776"
+ "a6e1a02f8782132df8abf885038609184e72a000822710942d0aceee7e5ab874"
+ "e22ccf8d1a649f59106d74e880a0476176000000000000000000000000000000"
+ "00000000000000000000000000001ca09b5fdabd54ebc284249d2d2df6d43875"
+ "cb86c52bd2bac196d4f064c8ade054f2a07b33f5c8b277a408ec38d2457441d2"
+ "af32e55681c8ecb28eef3d2a152e8db5a9a0227a67fceb1bf4ddd31a7047e24b"
+ "e93c947ab3b539471555bb3509ed6e393c8e82178df90277f90250048609184e"
+ "72a0008246dd94000000000000000000000000000000000000000080b901e961"
+ "010033577f476176436f696e0000000000000000000000000000000000000000"
+ "000000000060005460006000600760006000732d0aceee7e5ab874e22ccf8d1a"
+ "649f59106d74e860645c03f150436000576000600157620f424060025761017d"
+ "5161006c6000396000f2006020360e0f61013f59602060006000374360205460"
+ "0056600054602056602054437f6e000000000000000000000000000000000000"
+ "00000000000000000000000000560e0f0f61008059437f6e0000000000000000"
+ "0000000000000000000000000000000000000000000000576000602054610400"
+ "60005304600053036000547f6400000000000000000000000000000000000000"
+ "0000000000000000000000005660016000030460406000200a0f61013e596001"
+ "60205301602054600a6020530b0f6100f45961040060005304600053017f6400"
+ "0000000000000000000000000000000000000000000000000000000000005760"
+ "20537f6900000000000000000000000000000000000000000000000000000000"
+ "000000576000537f640000000000000000000000000000000000000000000000"
+ "000000000000000057006040360e0f0f61014a59003356604054600035566060"
+ "546020356080546080536040530a0f6101695900608053604053033357608053"
+ "60605301600035571ba0190fc7ab634dc497fe1656fde523a4c26926d51a93db"
+ "2ba37af8e83c3741225da066ae0ec1217b0ca698a5369d4881e1c4cbde56af99"
+ "31ebf9281580a23b659c08a051f947cb2315d0259f55848c630caa10cd91d6e4"
+ "4ff8bad7758c65b25e2191308227d2c0";
byte[] test1 = Hex.decode(block);
byte[] test2 = Hex.decode(block);
byte[] test3 = Hex.decode("4ff8bad7758c65b25e2191308227d2c0");
byte[] test4 = Hex.decode("");
wrapper1 = new ByteArrayWrapper(test1);
wrapper2 = new ByteArrayWrapper(test2);
wrapper3 = new ByteArrayWrapper(test3);
wrapper4 = new ByteArrayWrapper(test4);
}
@Test
public void testEqualsObject() {
assertTrue(wrapper1.equals(wrapper2));
assertFalse(wrapper1.equals(wrapper3));
assertFalse(wrapper1.equals(wrapper4));
assertFalse(wrapper1.equals(null));
assertFalse(wrapper2.equals(wrapper3));
}
@Test
public void testCompareTo() {
assertTrue(wrapper1.compareTo(wrapper2) == 0);
assertTrue(wrapper1.compareTo(wrapper3) > 1);
assertTrue(wrapper1.compareTo(wrapper4) > 1);
assertTrue(wrapper2.compareTo(wrapper3) > 1);
}
@Test
public void testEqualsPerformance() {
boolean testEnabled = false;
if (testEnabled) {
final int ITERATIONS = 10000000;
long start1 = System.currentTimeMillis();
for (int i = 0; i < ITERATIONS; i++) {
Comparator<byte[]> comparator = UnsignedBytes
.lexicographicalComparator();
comparator.compare(wrapper1.getData(),
wrapper2.getData());
}
System.out.println(System.currentTimeMillis() - start1 + "ms");
long start2 = System.currentTimeMillis();
for (int i = 0; i < ITERATIONS; i++) {
Arrays.equals(wrapper1.getData(), wrapper2.getData());
}
System.out.println(System.currentTimeMillis() - start2 + "ms");
long start3 = System.currentTimeMillis();
for (int i = 0; i < ITERATIONS; i++) {
FastByteComparisons.compareTo(wrapper1.getData(), 0, wrapper1.getData().length, wrapper2.getData(), 0, wrapper1.getData().length);
}
System.out.println(System.currentTimeMillis() - start3 + "ms");
}
}
}
| 8,411
| 51.248447
| 146
|
java
|
ethereumj
|
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/db/IndexedBlockStoreTest.java
|
/*
* Copyright (c) [2016] [ <ether.camp> ]
* This file is part of the ethereumJ library.
*
* The ethereumJ library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The ethereumJ library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the ethereumJ library. If not, see <http://www.gnu.org/licenses/>.
*/
package org.ethereum.db;
import org.ethereum.config.SystemProperties;
import org.ethereum.core.Block;
import org.ethereum.core.Genesis;
import org.ethereum.datasource.DbSettings;
import org.ethereum.datasource.DbSource;
import org.ethereum.datasource.inmem.HashMapDB;
import org.ethereum.datasource.rocksdb.RocksDbDataSource;
import org.ethereum.util.FileUtil;
import org.ethereum.util.blockchain.StandaloneBlockchain;
import org.junit.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.spongycastle.util.encoders.Hex;
import java.io.File;
import java.io.IOException;
import java.math.BigInteger;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.*;
import static java.math.BigInteger.ZERO;
import static org.ethereum.TestUtils.*;
import static org.ethereum.util.ByteUtil.wrap;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
public class IndexedBlockStoreTest {
private static final Logger logger = LoggerFactory.getLogger("test");
private List<Block> blocks = new ArrayList<>();
private BigInteger totDifficulty = ZERO;
@AfterClass
public static void cleanup() {
SystemProperties.resetToDefault();
}
@Before
public void setup() throws URISyntaxException, IOException {
URL scenario1 = ClassLoader
.getSystemResource("blockstore/load.dmp");
File file = new File(scenario1.toURI());
List<String> strData = Files.readAllLines(file.toPath(), StandardCharsets.UTF_8);
Block genesis = Genesis.getInstance();
blocks.add(genesis);
totDifficulty = totDifficulty.add(genesis.getDifficultyBI());
for (String blockRLP : strData) {
Block block = new Block(
Hex.decode(blockRLP));
if (block.getNumber() % 1000 == 0)
logger.info("adding block.hash: [{}] block.number: [{}]",
block.getShortHash(),
block.getNumber());
blocks.add(block);
totDifficulty = totDifficulty.add(block.getDifficultyBI());
}
logger.info("total difficulty: {}", totDifficulty);
logger.info("total blocks loaded: {}", blocks.size());
}
@Test // no cache, save some load, and check it exist
public void test1(){
IndexedBlockStore indexedBlockStore = new IndexedBlockStore();
indexedBlockStore.init(new HashMapDB<byte[]>(), new HashMapDB<byte[]>());
BigInteger totalDiff = BigInteger.ZERO;
for (Block block : blocks){
totalDiff = totalDiff.add( block.getDifficultyBI() );
indexedBlockStore.saveBlock(block, totalDiff, true);
}
// testing: getTotalDifficulty()
// testing: getMaxNumber()
long bestIndex = blocks.get(blocks.size() - 1).getNumber();
assertEquals(bestIndex, indexedBlockStore.getMaxNumber());
assertEquals(totDifficulty, indexedBlockStore.getTotalDifficulty());
// testing: getBlockByHash(byte[])
Block block = blocks.get(50);
Block block_ = indexedBlockStore.getBlockByHash(block.getHash());
assertEquals(block.getNumber(), block_.getNumber());
block = blocks.get(150);
block_ = indexedBlockStore.getBlockByHash(block.getHash());
assertEquals(block.getNumber(), block_.getNumber());
block = blocks.get(0);
block_ = indexedBlockStore.getBlockByHash(block.getHash());
assertEquals(block.getNumber(), block_.getNumber());
block = blocks.get(8003);
block_ = indexedBlockStore.getBlockByHash(block.getHash());
assertEquals(block.getNumber(), block_.getNumber());
block_ = indexedBlockStore.getBlockByHash(Hex.decode("00112233"));
assertEquals(null, block_);
// testing: getChainBlockByNumber(long)
block = blocks.get(50);
block_ = indexedBlockStore.getChainBlockByNumber(block.getNumber());
assertEquals(block.getNumber(), block_.getNumber());
block = blocks.get(150);
block_ = indexedBlockStore.getChainBlockByNumber(block.getNumber());
assertEquals(block.getNumber(), block_.getNumber());
block = blocks.get(0);
block_ = indexedBlockStore.getChainBlockByNumber(block.getNumber());
assertEquals(block.getNumber(), block_.getNumber());
block = blocks.get(8003);
block_ = indexedBlockStore.getChainBlockByNumber(block.getNumber());
assertEquals(block.getNumber(), block_.getNumber());
block_ = indexedBlockStore.getChainBlockByNumber(10000);
assertEquals(null, block_);
// testing: getBlocksByNumber(long)
block = blocks.get(50);
block_ = indexedBlockStore.getBlocksByNumber(block.getNumber()).get(0);
assertEquals(block.getNumber(), block_.getNumber());
block = blocks.get(150);
block_ = indexedBlockStore.getBlocksByNumber(block.getNumber()).get(0);
assertEquals(block.getNumber(), block_.getNumber());
block = blocks.get(0);
block_ = indexedBlockStore.getBlocksByNumber(block.getNumber()).get(0);
assertEquals(block.getNumber(), block_.getNumber());
block = blocks.get(8003);
block_ = indexedBlockStore.getBlocksByNumber(block.getNumber()).get(0);
assertEquals(block.getNumber(), block_.getNumber());
int blocksNum = indexedBlockStore.getBlocksByNumber(10000).size();
assertEquals(0, blocksNum);
// testing: getListHashesEndWith(byte[], long)
block = blocks.get(8003);
List<byte[]> hashList = indexedBlockStore.getListHashesEndWith(block.getHash(), 100);
for (int i = 0; i < 100; ++i){
block = blocks.get(8003 - i);
String hash = Hex.toHexString(hashList.get(i));
String hash_ = Hex.toHexString( block.getHash() );
assertEquals(hash_, hash);
}
// testing: getListHashesStartWith(long, long)
block = blocks.get(7003);
hashList = indexedBlockStore.getListHashesStartWith(block.getNumber(), 100);
for (int i = 0; i < 100; ++i){
block = blocks.get(7003 + i);
String hash = Hex.toHexString(hashList.get(i));
String hash_ = Hex.toHexString( block.getHash() );
assertEquals(hash_, hash);
}
}
@Test // predefined cache, save some load, and check it exist
public void test2(){
IndexedBlockStore cache = new IndexedBlockStore();
cache.init(new HashMapDB<byte[]>(), new HashMapDB<byte[]>());
IndexedBlockStore indexedBlockStore = new IndexedBlockStore();
indexedBlockStore.init(new HashMapDB<byte[]>(), new HashMapDB<byte[]>());
BigInteger totalDiff = BigInteger.ZERO;
for (Block block : blocks){
totalDiff = totalDiff.add( block.getDifficultyBI() );
indexedBlockStore.saveBlock(block, totalDiff, true);
}
// testing: getTotalDifficulty()
// testing: getMaxNumber()
long bestIndex = blocks.get(blocks.size() - 1).getNumber();
assertEquals(bestIndex, indexedBlockStore.getMaxNumber());
assertEquals(totDifficulty, indexedBlockStore.getTotalDifficulty());
// testing: getBlockByHash(byte[])
Block block = blocks.get(50);
Block block_ = indexedBlockStore.getBlockByHash(block.getHash());
assertEquals(block.getNumber(), block_.getNumber());
block = blocks.get(150);
block_ = indexedBlockStore.getBlockByHash(block.getHash());
assertEquals(block.getNumber(), block_.getNumber());
block = blocks.get(0);
block_ = indexedBlockStore.getBlockByHash(block.getHash());
assertEquals(block.getNumber(), block_.getNumber());
block = blocks.get(8003);
block_ = indexedBlockStore.getBlockByHash(block.getHash());
assertEquals(block.getNumber(), block_.getNumber());
block_ = indexedBlockStore.getBlockByHash(Hex.decode("00112233"));
assertEquals(null, block_);
// testing: getChainBlockByNumber(long)
block = blocks.get(50);
block_ = indexedBlockStore.getChainBlockByNumber(block.getNumber());
assertEquals(block.getNumber(), block_.getNumber());
block = blocks.get(150);
block_ = indexedBlockStore.getChainBlockByNumber(block.getNumber());
assertEquals(block.getNumber(), block_.getNumber());
block = blocks.get(0);
block_ = indexedBlockStore.getChainBlockByNumber(block.getNumber());
assertEquals(block.getNumber(), block_.getNumber());
block = blocks.get(8003);
block_ = indexedBlockStore.getChainBlockByNumber(block.getNumber());
assertEquals(block.getNumber(), block_.getNumber());
block_ = indexedBlockStore.getChainBlockByNumber(10000);
assertEquals(null, block_);
// testing: getBlocksByNumber(long)
block = blocks.get(50);
block_ = indexedBlockStore.getBlocksByNumber(block.getNumber()).get(0);
assertEquals(block.getNumber(), block_.getNumber());
block = blocks.get(150);
block_ = indexedBlockStore.getBlocksByNumber(block.getNumber()).get(0);
assertEquals(block.getNumber(), block_.getNumber());
block = blocks.get(0);
block_ = indexedBlockStore.getBlocksByNumber(block.getNumber()).get(0);
assertEquals(block.getNumber(), block_.getNumber());
block = blocks.get(8003);
block_ = indexedBlockStore.getBlocksByNumber(block.getNumber()).get(0);
assertEquals(block.getNumber(), block_.getNumber());
int blocksNum = indexedBlockStore.getBlocksByNumber(10000).size();
assertEquals(0, blocksNum);
// testing: getListHashesEndWith(byte[], long)
block = blocks.get(8003);
List<byte[]> hashList = indexedBlockStore.getListHashesEndWith(block.getHash(), 100);
for (int i = 0; i < 100; ++i){
block = blocks.get(8003 - i);
String hash = Hex.toHexString(hashList.get(i));
String hash_ = Hex.toHexString( block.getHash() );
assertEquals(hash_, hash);
}
// testing: getListHashesStartWith(long, long)
block = blocks.get(7003);
hashList = indexedBlockStore.getListHashesStartWith(block.getNumber(), 100);
for (int i = 0; i < 100; ++i){
block = blocks.get(7003 + i);
String hash = Hex.toHexString(hashList.get(i));
String hash_ = Hex.toHexString( block.getHash() );
assertEquals(hash_, hash);
}
}
@Test // predefined cache loaded and flushed, check it exist
public void test3(){
IndexedBlockStore cache = new IndexedBlockStore();
cache.init(new HashMapDB<byte[]>(), new HashMapDB<byte[]>());
// TODO cache removed, remove this test?
IndexedBlockStore indexedBlockStore = new IndexedBlockStore();
indexedBlockStore.init(new HashMapDB<byte[]>(), new HashMapDB<byte[]>());
BigInteger totalDiff = BigInteger.ZERO;
for (Block block : blocks){
totalDiff = totalDiff.add( block.getDifficultyBI() );
indexedBlockStore.saveBlock(block, totalDiff, true);
}
indexedBlockStore.flush();
// testing: getTotalDifficulty()
// testing: getMaxNumber()
long bestIndex = blocks.get(blocks.size() - 1).getNumber();
assertEquals(bestIndex, indexedBlockStore.getMaxNumber());
assertEquals(totDifficulty, indexedBlockStore.getTotalDifficulty());
// testing: getBlockByHash(byte[])
Block block = blocks.get(50);
Block block_ = indexedBlockStore.getBlockByHash(block.getHash());
assertEquals(block.getNumber(), block_.getNumber());
block = blocks.get(150);
block_ = indexedBlockStore.getBlockByHash(block.getHash());
assertEquals(block.getNumber(), block_.getNumber());
block = blocks.get(0);
block_ = indexedBlockStore.getBlockByHash(block.getHash());
assertEquals(block.getNumber(), block_.getNumber());
block = blocks.get(8003);
block_ = indexedBlockStore.getBlockByHash(block.getHash());
assertEquals(block.getNumber(), block_.getNumber());
block_ = indexedBlockStore.getBlockByHash(Hex.decode("00112233"));
assertEquals(null, block_);
// testing: getChainBlockByNumber(long)
block = blocks.get(50);
block_ = indexedBlockStore.getChainBlockByNumber(block.getNumber());
assertEquals(block.getNumber(), block_.getNumber());
block = blocks.get(150);
block_ = indexedBlockStore.getChainBlockByNumber(block.getNumber());
assertEquals(block.getNumber(), block_.getNumber());
block = blocks.get(0);
block_ = indexedBlockStore.getChainBlockByNumber(block.getNumber());
assertEquals(block.getNumber(), block_.getNumber());
block = blocks.get(8003);
block_ = indexedBlockStore.getChainBlockByNumber(block.getNumber());
assertEquals(block.getNumber(), block_.getNumber());
block_ = indexedBlockStore.getChainBlockByNumber(10000);
assertEquals(null, block_);
// testing: getBlocksByNumber(long)
block = blocks.get(50);
block_ = indexedBlockStore.getBlocksByNumber(block.getNumber()).get(0);
assertEquals(block.getNumber(), block_.getNumber());
block = blocks.get(150);
block_ = indexedBlockStore.getBlocksByNumber(block.getNumber()).get(0);
assertEquals(block.getNumber(), block_.getNumber());
block = blocks.get(0);
block_ = indexedBlockStore.getBlocksByNumber(block.getNumber()).get(0);
assertEquals(block.getNumber(), block_.getNumber());
block = blocks.get(8003);
block_ = indexedBlockStore.getBlocksByNumber(block.getNumber()).get(0);
assertEquals(block.getNumber(), block_.getNumber());
int blocksNum = indexedBlockStore.getBlocksByNumber(10000).size();
assertEquals(0, blocksNum);
// testing: getListHashesEndWith(byte[], long)
block = blocks.get(8003);
List<byte[]> hashList = indexedBlockStore.getListHashesEndWith(block.getHash(), 100);
for (int i = 0; i < 100; ++i){
block = blocks.get(8003 - i);
String hash = Hex.toHexString(hashList.get(i));
String hash_ = Hex.toHexString( block.getHash() );
assertEquals(hash_, hash);
}
// testing: getListHashesStartWith(long, long)
block = blocks.get(7003);
hashList = indexedBlockStore.getListHashesStartWith(block.getNumber(), 100);
for (int i = 0; i < 100; ++i){
block = blocks.get(7003 + i);
String hash = Hex.toHexString(hashList.get(i));
String hash_ = Hex.toHexString( block.getHash() );
assertEquals(hash_, hash);
}
}
@Test // cache + leveldb + mapdb, save some load, flush to disk, and check it exist
public void test4() throws IOException {
BigInteger bi = new BigInteger(32, new Random());
String testDir = "test_db_" + bi;
SystemProperties.getDefault().setDataBaseDir(testDir);
RocksDbDataSource indexDB = new RocksDbDataSource("index");
indexDB.init(DbSettings.DEFAULT);
DbSource blocksDB = new RocksDbDataSource("blocks");
blocksDB.init(DbSettings.DEFAULT);
IndexedBlockStore indexedBlockStore = new IndexedBlockStore();
indexedBlockStore.init(indexDB, blocksDB);
BigInteger totalDiff = BigInteger.ZERO;
for (Block block : blocks){
totalDiff = totalDiff.add( block.getDifficultyBI() );
indexedBlockStore.saveBlock(block, totalDiff, true);
}
// testing: getTotalDifficulty()
// testing: getMaxNumber()
long bestIndex = blocks.get(blocks.size() - 1).getNumber();
assertEquals(bestIndex, indexedBlockStore.getMaxNumber());
assertEquals(totDifficulty, indexedBlockStore.getTotalDifficulty());
// testing: getBlockByHash(byte[])
Block block = blocks.get(50);
Block block_ = indexedBlockStore.getBlockByHash(block.getHash());
assertEquals(block.getNumber(), block_.getNumber());
block = blocks.get(150);
block_ = indexedBlockStore.getBlockByHash(block.getHash());
assertEquals(block.getNumber(), block_.getNumber());
block = blocks.get(0);
block_ = indexedBlockStore.getBlockByHash(block.getHash());
assertEquals(block.getNumber(), block_.getNumber());
block = blocks.get(8003);
block_ = indexedBlockStore.getBlockByHash(block.getHash());
assertEquals(block.getNumber(), block_.getNumber());
block_ = indexedBlockStore.getBlockByHash(Hex.decode("00112233"));
assertEquals(null, block_);
// testing: getChainBlockByNumber(long)
block = blocks.get(50);
block_ = indexedBlockStore.getChainBlockByNumber(block.getNumber());
assertEquals(block.getNumber(), block_.getNumber());
block = blocks.get(150);
block_ = indexedBlockStore.getChainBlockByNumber(block.getNumber());
assertEquals(block.getNumber(), block_.getNumber());
block = blocks.get(0);
block_ = indexedBlockStore.getChainBlockByNumber(block.getNumber());
assertEquals(block.getNumber(), block_.getNumber());
block = blocks.get(8003);
block_ = indexedBlockStore.getChainBlockByNumber(block.getNumber());
assertEquals(block.getNumber(), block_.getNumber());
block_ = indexedBlockStore.getChainBlockByNumber(10000);
assertEquals(null, block_);
// testing: getBlocksByNumber(long)
block = blocks.get(50);
block_ = indexedBlockStore.getBlocksByNumber(block.getNumber()).get(0);
assertEquals(block.getNumber(), block_.getNumber());
block = blocks.get(150);
block_ = indexedBlockStore.getBlocksByNumber(block.getNumber()).get(0);
assertEquals(block.getNumber(), block_.getNumber());
block = blocks.get(0);
block_ = indexedBlockStore.getBlocksByNumber(block.getNumber()).get(0);
assertEquals(block.getNumber(), block_.getNumber());
block = blocks.get(8003);
block_ = indexedBlockStore.getBlocksByNumber(block.getNumber()).get(0);
assertEquals(block.getNumber(), block_.getNumber());
int blocksNum = indexedBlockStore.getBlocksByNumber(10000).size();
assertEquals(0, blocksNum);
// testing: getListHashesEndWith(byte[], long)
block = blocks.get(8003);
List<byte[]> hashList = indexedBlockStore.getListHashesEndWith(block.getHash(), 100);
for (int i = 0; i < 100; ++i){
block = blocks.get(8003 - i);
String hash = Hex.toHexString(hashList.get(i));
String hash_ = Hex.toHexString( block.getHash() );
assertEquals(hash_, hash);
}
// testing: getListHashesStartWith(long, long)
block = blocks.get(7003);
hashList = indexedBlockStore.getListHashesStartWith(block.getNumber(), 100);
for (int i = 0; i < 100; ++i){
block = blocks.get(7003 + i);
String hash = Hex.toHexString(hashList.get(i));
String hash_ = Hex.toHexString( block.getHash() );
assertEquals(hash_, hash);
}
blocksDB.close();
indexDB.close();
// testing after: REOPEN
indexDB = new RocksDbDataSource("index");
indexDB.init(DbSettings.DEFAULT);
blocksDB = new RocksDbDataSource("blocks");
blocksDB.init(DbSettings.DEFAULT);
indexedBlockStore = new IndexedBlockStore();
indexedBlockStore.init(indexDB, blocksDB);
// testing: getListHashesStartWith(long, long)
block = blocks.get(7003);
hashList = indexedBlockStore.getListHashesStartWith(block.getNumber(), 100);
for (int i = 0; i < 100; ++i){
block = blocks.get(7003 + i);
String hash = Hex.toHexString(hashList.get(i));
String hash_ = Hex.toHexString( block.getHash() );
assertEquals(hash_, hash);
}
blocksDB.close();
indexDB.close();
FileUtil.recursiveDelete(testDir);
}
@Test // cache + leveldb + mapdb, save part to disk part to cache, and check it exist
public void test5() throws IOException {
BigInteger bi = new BigInteger(32, new Random());
String testDir = "test_db_" + bi;
SystemProperties.getDefault().setDataBaseDir(testDir);
RocksDbDataSource indexDB = new RocksDbDataSource("index");
indexDB.init(DbSettings.DEFAULT);
DbSource blocksDB = new RocksDbDataSource("blocks");
blocksDB.init(DbSettings.DEFAULT);
try {
IndexedBlockStore cache = new IndexedBlockStore();
cache.init(new HashMapDB<byte[]>(), new HashMapDB<byte[]>());
IndexedBlockStore indexedBlockStore = new IndexedBlockStore();
indexedBlockStore.init(indexDB, blocksDB);
BigInteger totalDiff = BigInteger.ZERO;
int preloadSize = blocks.size() / 2;
for (int i = 0; i < preloadSize; ++i){
Block block = blocks.get(i);
totalDiff = totalDiff.add( block.getDifficultyBI() );
indexedBlockStore.saveBlock(block, totalDiff, true);
}
indexedBlockStore.flush();
for (int i = preloadSize; i < blocks.size(); ++i){
Block block = blocks.get(i);
totalDiff = totalDiff.add( block.getDifficultyBI() );
indexedBlockStore.saveBlock(block, totalDiff, true);
}
// testing: getTotalDifficulty()
// testing: getMaxNumber()
long bestIndex = blocks.get(blocks.size() - 1).getNumber();
assertEquals(bestIndex, indexedBlockStore.getMaxNumber());
assertEquals(totDifficulty, indexedBlockStore.getTotalDifficulty());
// testing: getBlockByHash(byte[])
Block block = blocks.get(50);
Block block_ = indexedBlockStore.getBlockByHash(block.getHash());
assertEquals(block.getNumber(), block_.getNumber());
block = blocks.get(150);
block_ = indexedBlockStore.getBlockByHash(block.getHash());
assertEquals(block.getNumber(), block_.getNumber());
block = blocks.get(0);
block_ = indexedBlockStore.getBlockByHash(block.getHash());
assertEquals(block.getNumber(), block_.getNumber());
block = blocks.get(8003);
block_ = indexedBlockStore.getBlockByHash(block.getHash());
assertEquals(block.getNumber(), block_.getNumber());
block_ = indexedBlockStore.getBlockByHash(Hex.decode("00112233"));
assertEquals(null, block_);
// testing: getChainBlockByNumber(long)
block = blocks.get(50);
block_ = indexedBlockStore.getChainBlockByNumber(block.getNumber());
assertEquals(block.getNumber(), block_.getNumber());
block = blocks.get(150);
block_ = indexedBlockStore.getChainBlockByNumber(block.getNumber());
assertEquals(block.getNumber(), block_.getNumber());
block = blocks.get(0);
block_ = indexedBlockStore.getChainBlockByNumber(block.getNumber());
assertEquals(block.getNumber(), block_.getNumber());
block = blocks.get(8003);
block_ = indexedBlockStore.getChainBlockByNumber(block.getNumber());
assertEquals(block.getNumber(), block_.getNumber());
block_ = indexedBlockStore.getChainBlockByNumber(10000);
assertEquals(null, block_);
// testing: getBlocksByNumber(long)
block = blocks.get(50);
block_ = indexedBlockStore.getBlocksByNumber(block.getNumber()).get(0);
assertEquals(block.getNumber(), block_.getNumber());
block = blocks.get(150);
block_ = indexedBlockStore.getBlocksByNumber(block.getNumber()).get(0);
assertEquals(block.getNumber(), block_.getNumber());
block = blocks.get(0);
block_ = indexedBlockStore.getBlocksByNumber(block.getNumber()).get(0);
assertEquals(block.getNumber(), block_.getNumber());
block = blocks.get(8003);
block_ = indexedBlockStore.getBlocksByNumber(block.getNumber()).get(0);
assertEquals(block.getNumber(), block_.getNumber());
int blocksNum = indexedBlockStore.getBlocksByNumber(10000).size();
assertEquals(0, blocksNum);
// testing: getListHashesEndWith(byte[], long)
block = blocks.get(8003);
List<byte[]> hashList = indexedBlockStore.getListHashesEndWith(block.getHash(), 100);
for (int i = 0; i < 100; ++i){
block = blocks.get(8003 - i);
String hash = Hex.toHexString(hashList.get(i));
String hash_ = Hex.toHexString( block.getHash() );
assertEquals(hash_, hash);
}
// testing: getListHashesStartWith(long, long)
block = blocks.get(7003);
hashList = indexedBlockStore.getListHashesStartWith(block.getNumber(), 100);
for (int i = 0; i < 100; ++i){
block = blocks.get(7003 + i);
String hash = Hex.toHexString(hashList.get(i));
String hash_ = Hex.toHexString( block.getHash() );
assertEquals(hash_, hash);
}
indexedBlockStore.flush();
blocksDB.close();
indexDB.close();
// testing after: REOPEN
indexDB = new RocksDbDataSource("index");
indexDB.init(DbSettings.DEFAULT);
blocksDB = new RocksDbDataSource("blocks");
blocksDB.init(DbSettings.DEFAULT);
indexedBlockStore = new IndexedBlockStore();
indexedBlockStore.init(indexDB, blocksDB);
// testing: getListHashesStartWith(long, long)
block = blocks.get(7003);
hashList = indexedBlockStore.getListHashesStartWith(block.getNumber(), 100);
for (int i = 0; i < 100; ++i){
block = blocks.get(7003 + i);
String hash = Hex.toHexString(hashList.get(i));
String hash_ = Hex.toHexString( block.getHash() );
assertEquals(hash_, hash);
}
} finally {
blocksDB.close();
indexDB.close();
FileUtil.recursiveDelete(testDir);
}
}
@Test // cache + leveldb + mapdb, multi branch, total difficulty test
public void test6() throws IOException {
BigInteger bi = new BigInteger(32, new Random());
String testDir = "test_db_" + bi;
SystemProperties.getDefault().setDataBaseDir(testDir);
DbSource indexDB = new RocksDbDataSource("index");
indexDB.init(DbSettings.DEFAULT);
DbSource blocksDB = new RocksDbDataSource("blocks");
blocksDB.init(DbSettings.DEFAULT);
try {
IndexedBlockStore indexedBlockStore = new IndexedBlockStore();
indexedBlockStore.init(indexDB, blocksDB);
List<Block> bestLine = getRandomChain(Genesis.getInstance().getHash(), 1, 100);
indexedBlockStore.saveBlock(Genesis.getInstance(), Genesis.getInstance().getDifficultyBI(), true);
for (int i = 0; i < bestLine.size(); ++i){
BigInteger td = indexedBlockStore.getTotalDifficulty();
Block newBlock = bestLine.get(i);
td = td.add(newBlock.getDifficultyBI());
indexedBlockStore.saveBlock(newBlock, td, true);
}
byte[] forkParentHash = bestLine.get(60).getHash();
long forkParentNumber = bestLine.get(60).getNumber();
List<Block> forkLine = getRandomChain(forkParentHash, forkParentNumber + 1, 50);
for (int i = 0; i < forkLine.size(); ++i){
Block newBlock = forkLine.get(i);
Block parentBlock = indexedBlockStore.getBlockByHash(newBlock.getParentHash());
BigInteger td = indexedBlockStore.getTotalDifficultyForHash(parentBlock.getHash());
td = td.add(newBlock.getDifficultyBI());
indexedBlockStore.saveBlock(newBlock, td, false);
}
// calc all TDs
Map<ByteArrayWrapper, BigInteger> tDiffs = new HashMap<>();
BigInteger td = Genesis.getInstance().getDifficultyBI();
for (Block block : bestLine){
td = td.add(block.getDifficultyBI());
tDiffs.put(wrap(block.getHash()), td);
}
Map<ByteArrayWrapper, BigInteger> tForkDiffs = new HashMap<>();
Block block = forkLine.get(0);
td = tDiffs.get(wrap(block.getParentHash()));
for (Block currBlock : forkLine){
td = td.add(currBlock.getDifficultyBI());
tForkDiffs.put(wrap(currBlock.getHash()), td);
}
// Assert tds on bestLine
for ( ByteArrayWrapper hash : tDiffs.keySet()){
BigInteger currTD = tDiffs.get(hash);
BigInteger checkTd = indexedBlockStore.getTotalDifficultyForHash(hash.getData());
assertEquals(checkTd, currTD);
}
// Assert tds on forkLine
for ( ByteArrayWrapper hash : tForkDiffs.keySet()){
BigInteger currTD = tForkDiffs.get(hash);
BigInteger checkTd = indexedBlockStore.getTotalDifficultyForHash(hash.getData());
assertEquals(checkTd, currTD);
}
indexedBlockStore.flush();
// Assert tds on bestLine
for ( ByteArrayWrapper hash : tDiffs.keySet()){
BigInteger currTD = tDiffs.get(hash);
BigInteger checkTd = indexedBlockStore.getTotalDifficultyForHash(hash.getData());
assertEquals(checkTd, currTD);
}
// check total difficulty
BigInteger totalDifficulty = indexedBlockStore.getTotalDifficulty();
Block bestBlock = bestLine.get(bestLine.size() - 1);
BigInteger totalDifficulty_ = tDiffs.get(wrap(bestBlock.getHash()));
assertEquals(totalDifficulty_, totalDifficulty);
// Assert tds on forkLine
for ( ByteArrayWrapper hash : tForkDiffs.keySet()){
BigInteger currTD = tForkDiffs.get(hash);
BigInteger checkTd = indexedBlockStore.getTotalDifficultyForHash(hash.getData());
assertEquals(checkTd, currTD);
}
} finally {
blocksDB.close();
indexDB.close();
FileUtil.recursiveDelete(testDir);
}
}
@Test // cache + leveldb + mapdb, multi branch, total re-branch test
public void test7() throws IOException {
BigInteger bi = new BigInteger(32, new Random());
String testDir = "test_db_" + bi;
SystemProperties.getDefault().setDataBaseDir(testDir);
DbSource indexDB = new RocksDbDataSource("index");
indexDB.init(DbSettings.DEFAULT);
DbSource blocksDB = new RocksDbDataSource("blocks");
blocksDB.init(DbSettings.DEFAULT);
try {
IndexedBlockStore indexedBlockStore = new IndexedBlockStore();
indexedBlockStore.init(indexDB, blocksDB);
List<Block> bestLine = getRandomChain(Genesis.getInstance().getHash(), 1, 100);
indexedBlockStore.saveBlock(Genesis.getInstance(), Genesis.getInstance().getDifficultyBI(), true);
for (int i = 0; i < bestLine.size(); ++i){
BigInteger td = indexedBlockStore.getTotalDifficulty();
Block newBlock = bestLine.get(i);
td = td.add(newBlock.getDifficultyBI());
indexedBlockStore.saveBlock(newBlock, td, true);
}
byte[] forkParentHash = bestLine.get(60).getHash();
long forkParentNumber = bestLine.get(60).getNumber();
List<Block> forkLine = getRandomChain(forkParentHash, forkParentNumber + 1, 50);
for (int i = 0; i < forkLine.size(); ++i){
Block newBlock = forkLine.get(i);
Block parentBlock = indexedBlockStore.getBlockByHash(newBlock.getParentHash());
BigInteger td = indexedBlockStore.getTotalDifficultyForHash(parentBlock.getHash());
td = td.add(newBlock.getDifficultyBI());
indexedBlockStore.saveBlock(newBlock, td, false);
}
Block bestBlock = bestLine.get(bestLine.size() - 1);
Block forkBlock = forkLine.get(forkLine.size() - 1);
// check total difficulty
BigInteger totalDifficulty = indexedBlockStore.getTotalDifficulty();
BigInteger totalDifficulty_ = indexedBlockStore.getTotalDifficultyForHash( bestBlock.getHash() );
assertEquals(totalDifficulty_, totalDifficulty);
indexedBlockStore.reBranch(forkBlock);
// check total difficulty
totalDifficulty = indexedBlockStore.getTotalDifficulty();
totalDifficulty_ = indexedBlockStore.getTotalDifficultyForHash( forkBlock.getHash() );
assertEquals(totalDifficulty_, totalDifficulty);
} finally {
blocksDB.close();
indexDB.close();
FileUtil.recursiveDelete(testDir);
}
}
@Test // cache + leveldb + mapdb, multi branch, total re-branch test
public void test8() throws IOException {
BigInteger bi = new BigInteger(32, new Random());
String testDir = "test_db_" + bi;
SystemProperties.getDefault().setDataBaseDir(testDir);
DbSource indexDB = new RocksDbDataSource("index");
indexDB.init(DbSettings.DEFAULT);
DbSource blocksDB = new RocksDbDataSource("blocks");
blocksDB.init(DbSettings.DEFAULT);
try {
IndexedBlockStore indexedBlockStore = new IndexedBlockStore();
indexedBlockStore.init(indexDB, blocksDB);
List<Block> bestLine = getRandomChain(Genesis.getInstance().getHash(), 1, 100);
indexedBlockStore.saveBlock(Genesis.getInstance(), Genesis.getInstance().getDifficultyBI(), true);
for (int i = 0; i < bestLine.size(); ++i){
BigInteger td = indexedBlockStore.getTotalDifficulty();
Block newBlock = bestLine.get(i);
td = td.add(newBlock.getDifficultyBI());
indexedBlockStore.saveBlock(newBlock, td, true);
}
byte[] forkParentHash = bestLine.get(60).getHash();
long forkParentNumber = bestLine.get(60).getNumber();
List<Block> forkLine = getRandomChain(forkParentHash, forkParentNumber + 1, 10);
for (int i = 0; i < forkLine.size(); ++i){
Block newBlock = forkLine.get(i);
Block parentBlock = indexedBlockStore.getBlockByHash(newBlock.getParentHash());
BigInteger td = indexedBlockStore.getTotalDifficultyForHash(parentBlock.getHash());
td = td.add(newBlock.getDifficultyBI());
indexedBlockStore.saveBlock(newBlock, td, false);
}
Block bestBlock = bestLine.get(bestLine.size() - 1);
Block forkBlock = forkLine.get(forkLine.size() - 1);
assertTrue( indexedBlockStore.getBestBlock().getNumber() == 100);
// check total difficulty
BigInteger totalDifficulty = indexedBlockStore.getTotalDifficulty();
BigInteger totalDifficulty_ = indexedBlockStore.getTotalDifficultyForHash(bestBlock.getHash());
assertEquals(totalDifficulty_, totalDifficulty);
indexedBlockStore.reBranch(forkBlock);
assertTrue( indexedBlockStore.getBestBlock().getNumber() == 71);
// check total difficulty
totalDifficulty = indexedBlockStore.getTotalDifficulty();
totalDifficulty_ = indexedBlockStore.getTotalDifficultyForHash( forkBlock.getHash() );
assertEquals(totalDifficulty_, totalDifficulty);
// Assert that all fork moved to the main line
for (Block currBlock : forkLine){
Long number = currBlock.getNumber();
Block chainBlock = indexedBlockStore.getChainBlockByNumber(number);
assertEquals(currBlock.getShortHash(), chainBlock.getShortHash());
}
// Assert that all fork moved to the main line
// re-branch back to previous line and assert that
// all the block really moved
bestBlock = bestLine.get(bestLine.size() - 1);
indexedBlockStore.reBranch(bestBlock);
for (Block currBlock : bestLine){
Long number = currBlock.getNumber();
Block chainBlock = indexedBlockStore.getChainBlockByNumber(number);
assertEquals(currBlock.getShortHash(), chainBlock.getShortHash());
}
} finally {
blocksDB.close();
indexDB.close();
FileUtil.recursiveDelete(testDir);
}
}
@Test // test index merging during the flush
public void test9() {
IndexedBlockStore indexedBlockStore = new IndexedBlockStore();
indexedBlockStore.init(new HashMapDB<byte[]>(), new HashMapDB<byte[]>());
// blocks with the same block number
Block block1 = new Block(Hex.decode("f90202f901fda0ad0d51e8d64c364a7b77ef2fe252f3f4df0940c7cfa69cedc1fbd6ea66894936a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d493479414a3bc0f103706650a19c5d24e5c4cf1ea5af78ea0e0580f4fdd1e3ae8346efaa6b1018605361f6e2fb058580e31414c8cbf5b0d49a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b90100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008605065cf2c43a8303e52e832fefd8808455fcbe1b80a017247341fd5d2f1d384682fea9302065a95dbd3e4f8260dde88a386f3cb95be3880f3fc8d5e0c87378c0c0"));
Block block2 = new Block(Hex.decode("f90218f90213a0c63fc3626abc6f6ba695064e973126cccc6fd513d4f53485e11794a8855e8b2ba01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347941dcb8d1f0fcc8cbc8c2d76528e877f915e299fbea0ccb2ed2a8c585409fe5530d36320bc8c1406454b32a9e419e890ea49489e534aa056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b90100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008605079eb238d88303e52e832fefd8808455fcbe2596d583010103844765746885676f312e35856c696e7578a0a673a429161eb32e6d0887b2bce2b12b1edd6e4b4cf55371853cba13d57118bd88d44d3609c7e203c7c0c0"));
indexedBlockStore.saveBlock(block1, block1.getDifficultyBI(), true);
indexedBlockStore.flush();
indexedBlockStore.saveBlock(block2, block2.getDifficultyBI(), true);
indexedBlockStore.flush();
assertEquals(block1.getDifficultyBI(), indexedBlockStore.getTotalDifficultyForHash(block1.getHash()));
assertEquals(block2.getDifficultyBI(), indexedBlockStore.getTotalDifficultyForHash(block2.getHash()));
}
@Test
public void myTest() throws Exception {
// check that IndexedStore rebranch changes are persisted
StandaloneBlockchain bc = new StandaloneBlockchain().withGasPrice(1);
IndexedBlockStore ibs = (IndexedBlockStore) bc.getBlockchain().getBlockStore();
Block b1 = bc.createBlock();
Block b2 = bc.createBlock();
Block b2_ = bc.createForkBlock(b1);
Assert.assertTrue(bc.getBlockchain().getBestBlock().isEqual(b2));
Block b3_ = bc.createForkBlock(b2_);
Assert.assertTrue(bc.getBlockchain().getBestBlock().isEqual(b3_));
Block sb2 = bc.getBlockchain().getBlockStore().getChainBlockByNumber(2);
Block sb3 = bc.getBlockchain().getBlockStore().getChainBlockByNumber(3);
Assert.assertTrue(sb2.isEqual(b2_));
Assert.assertTrue(sb3.isEqual(b3_));
Block b4_ = bc.createBlock();
bc.getBlockchain().flush();
IndexedBlockStore ibs1 = new IndexedBlockStore();
ibs1.init(ibs.indexDS, ibs.blocksDS);
sb2 = ibs1.getChainBlockByNumber(2);
sb3 = ibs1.getChainBlockByNumber(3);
Block sb4 = ibs1.getChainBlockByNumber(4);
Assert.assertTrue(sb2.isEqual(b2_));
Assert.assertTrue(sb3.isEqual(b3_));
Assert.assertTrue(sb4.isEqual(b4_));
}
// todo: test this
// public byte[] getBlockHashByNumber(long blockNumber)
}
| 43,119
| 39.526316
| 1,127
|
java
|
ethereumj
|
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/db/TransactionStoreTest.java
|
/*
* Copyright (c) [2016] [ <ether.camp> ]
* This file is part of the ethereumJ library.
*
* The ethereumJ library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The ethereumJ library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the ethereumJ library. If not, see <http://www.gnu.org/licenses/>.
*/
package org.ethereum.db;
import org.ethereum.config.SystemProperties;
import org.ethereum.config.blockchain.FrontierConfig;
import org.ethereum.config.net.MainNetConfig;
import org.ethereum.core.Block;
import org.ethereum.core.Transaction;
import org.ethereum.core.TransactionInfo;
import org.ethereum.datasource.inmem.HashMapDB;
import org.ethereum.util.blockchain.SolidityContract;
import org.ethereum.util.blockchain.StandaloneBlockchain;
import org.ethereum.vm.DataWord;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import java.math.BigInteger;
import java.util.Arrays;
/**
* Created by Anton Nashatyrev on 08.04.2016.
*/
public class TransactionStoreTest {
@AfterClass
public static void cleanup() {
SystemProperties.resetToDefault();
}
@Test
public void simpleTest() {
String contractSrc =
"contract Adder {" +
" function add(int a, int b) returns (int) {return a + b;}" +
"}";
HashMapDB<byte[]> txDb = new HashMapDB<>();
StandaloneBlockchain bc = new StandaloneBlockchain();
bc.getBlockchain().withTransactionStore(new TransactionStore(txDb));
SolidityContract contract = bc.submitNewContract(contractSrc);
bc.createBlock();
contract.callFunction("add", 555, 222);
Block b2 = bc.createBlock();
contract.callFunction("add", 333, 333);
Block b3 = bc.createBlock();
Transaction tx1 = b2.getTransactionsList().get(0);
TransactionInfo tx1Info = bc.getBlockchain().getTransactionInfo(tx1.getHash());
byte[] executionResult = tx1Info.getReceipt().getExecutionResult();
Assert.assertArrayEquals(DataWord.of(777).getData(), executionResult);
System.out.println(txDb.keys().size());
bc.getBlockchain().flush();
System.out.println(txDb.keys().size());
TransactionStore txStore = new TransactionStore(txDb);
TransactionInfo tx1Info_ = txStore.get(tx1.getHash()).get(0);
executionResult = tx1Info_.getReceipt().getExecutionResult();
Assert.assertArrayEquals(DataWord.of(777).getData(), executionResult);
TransactionInfo highIndex = new TransactionInfo(tx1Info.getReceipt(), tx1Info.getBlockHash(), 255);
TransactionInfo highIndexCopy = new TransactionInfo(highIndex.getEncoded());
Assert.assertArrayEquals(highIndex.getBlockHash(), highIndexCopy.getBlockHash());
Assert.assertEquals(highIndex.getIndex(), highIndexCopy.getIndex());
}
@Test
public void forkTest() {
// check that TransactionInfo is always returned from the main chain for
// transaction which included into blocks from different forks
String contractSrc =
"contract Adder {" +
" int public lastResult;" +
" function add(int a, int b) returns (int) {lastResult = a + b; return lastResult; }" +
"}";
HashMapDB txDb = new HashMapDB();
StandaloneBlockchain bc = new StandaloneBlockchain();
TransactionStore transactionStore = new TransactionStore(txDb);
bc.getBlockchain().withTransactionStore(transactionStore);
SolidityContract contract = bc.submitNewContract(contractSrc);
Block b1 = bc.createBlock();
contract.callFunction("add", 555, 222);
Block b2 = bc.createBlock();
Transaction tx1 = b2.getTransactionsList().get(0);
TransactionInfo txInfo = bc.getBlockchain().getTransactionInfo(tx1.getHash());
Assert.assertTrue(Arrays.equals(txInfo.getBlockHash(), b2.getHash()));
Block b2_ = bc.createForkBlock(b1);
contract.callFunction("add", 555, 222); // tx with the same hash as before
Block b3_ = bc.createForkBlock(b2_);
TransactionInfo txInfo_ = bc.getBlockchain().getTransactionInfo(tx1.getHash());
Assert.assertTrue(Arrays.equals(txInfo_.getBlockHash(), b3_.getHash()));
Block b3 = bc.createForkBlock(b2);
Block b4 = bc.createForkBlock(b3);
txInfo = bc.getBlockchain().getTransactionInfo(tx1.getHash());
Assert.assertTrue(Arrays.equals(txInfo.getBlockHash(), b2.getHash()));
}
@Test
public void backwardCompatibleDbTest() {
// check that we can read previously saved entries (saved with legacy code)
HashMapDB txDb = new HashMapDB();
TransactionStore transactionStore = new TransactionStore(txDb);
StandaloneBlockchain bc = new StandaloneBlockchain();
bc.getBlockchain().withTransactionStore(transactionStore);
bc.sendEther(new byte[20], BigInteger.valueOf(1000));
Block b1 = bc.createBlock();
Transaction tx = b1.getTransactionsList().get(0);
TransactionInfo info = transactionStore.get(tx.getHash()).get(0);
HashMapDB<byte[]> txDb1 = new HashMapDB<>();
txDb1.put(tx.getHash(), info.getEncoded()); // legacy serialization
TransactionStore transactionStore1 = new TransactionStore(txDb1);
TransactionInfo info1 = transactionStore1.get(tx.getHash()).get(0);
Assert.assertArrayEquals(info1.getReceipt().getPostTxState(), info.getReceipt().getPostTxState());
}
}
| 6,060
| 42.292857
| 107
|
java
|
ethereumj
|
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/db/FlushDbManagerTest.java
|
/*
* Copyright (c) [2016] [ <ether.camp> ]
* This file is part of the ethereumJ library.
*
* The ethereumJ library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The ethereumJ library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the ethereumJ library. If not, see <http://www.gnu.org/licenses/>.
*/
package org.ethereum.db;
import org.ethereum.config.SystemProperties;
import org.ethereum.datasource.DbSource;
import org.ethereum.datasource.MemSizeEstimator;
import org.ethereum.datasource.WriteCache;
import org.ethereum.datasource.inmem.HashMapDB;
import org.junit.Assert;
import org.junit.Test;
import java.util.Collections;
import java.util.concurrent.CountDownLatch;
import static org.ethereum.datasource.MemSizeEstimator.ByteArrayEstimator;
import static org.ethereum.util.ByteUtil.intToBytes;
/**
* Created by Anton Nashatyrev on 23.12.2016.
*/
public class FlushDbManagerTest {
@Test
public void testConcurrentCommit() throws Throwable {
// check that FlushManager commit(Runnable) is performed atomically
final HashMapDB<byte[]> db1 = new HashMapDB<>();
final HashMapDB<byte[]> db2 = new HashMapDB<>();
final WriteCache<byte[], byte[]> cache1 = new WriteCache.BytesKey<>(db1, WriteCache.CacheType.SIMPLE);
cache1.withSizeEstimators(ByteArrayEstimator, ByteArrayEstimator);
final WriteCache<byte[], byte[]> cache2 = new WriteCache.BytesKey<>(db2, WriteCache.CacheType.SIMPLE);
cache2.withSizeEstimators(ByteArrayEstimator, ByteArrayEstimator);
final DbFlushManager dbFlushManager = new DbFlushManager(SystemProperties.getDefault(), Collections.<DbSource>emptySet(), null);
dbFlushManager.addCache(cache1);
dbFlushManager.addCache(cache2);
dbFlushManager.setSizeThreshold(1);
final CountDownLatch latch = new CountDownLatch(1);
final Throwable[] exception = new Throwable[1];
new Thread(() -> {
try {
for (int i = 0; i < 300; i++) {
final int i_ = i;
dbFlushManager.commit(() -> {
cache1.put(intToBytes(i_), intToBytes(i_));
try {
Thread.sleep(5);
} catch (InterruptedException e) {}
cache2.put(intToBytes(i_), intToBytes(i_));
});
}
} catch (Throwable e) {
exception[0] = e;
e.printStackTrace();
} finally {
latch.countDown();
}
}).start();
new Thread(() -> {
try {
while (true) {
dbFlushManager.commit();
Thread.sleep(5);
}
} catch (Exception e) {
exception[0] = e;
e.printStackTrace();
} finally {
latch.countDown();
}
}).start();
new Thread(() -> {
try {
int cnt = 0;
while (true) {
synchronized (dbFlushManager) {
for (; cnt < 300; cnt++) {
byte[] val1 = db1.get(intToBytes(cnt));
byte[] val2 = db2.get(intToBytes(cnt));
if (val1 == null) {
Assert.assertNull(val2);
break;
} else {
Assert.assertNotNull(val2);
}
}
}
}
} catch (Exception e) {
exception[0] = e;
e.printStackTrace();
} finally {
latch.countDown();
}
}).start();
latch.await();
if (exception[0] != null) throw exception[0];
}
}
| 4,439
| 34.806452
| 136
|
java
|
ethereumj
|
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/db/QuotientFilterTest.java
|
/*
* Copyright (c) [2016] [ <ether.camp> ]
* This file is part of the ethereumJ library.
*
* The ethereumJ library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The ethereumJ library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the ethereumJ library. If not, see <http://www.gnu.org/licenses/>.
*/
package org.ethereum.db;
import org.ethereum.datasource.QuotientFilter;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import static org.ethereum.crypto.HashUtil.sha3;
import static org.ethereum.util.ByteUtil.intToBytes;
/**
* Created by Anton Nashatyrev on 13.03.2017.
*/
public class QuotientFilterTest {
@Ignore
@Test
public void perfTest() {
QuotientFilter f = QuotientFilter.create(50_000_000, 100_000);
long s = System.currentTimeMillis();
for (int i = 0; i < 5_000_000; i++) {
f.insert(sha3(intToBytes(i)));
// inserting duplicate slows down significantly
if (i % 10 == 0) f.insert(sha3(intToBytes(0)));
if (i > 100_000 && i % 2 == 0) {
f.remove(sha3(intToBytes(i - 100_000)));
}
if (i % 10000 == 0) {
System.out.println(i + ": " + (System.currentTimeMillis() - s));
s = System.currentTimeMillis();
}
}
}
@Test
public void maxDuplicatesTest() {
QuotientFilter f = QuotientFilter.create(50_000_000, 1000).withMaxDuplicates(2);
f.insert(1);
Assert.assertTrue(f.maybeContains(1));
f.remove(1);
Assert.assertFalse(f.maybeContains(1));
f.insert(1);
f.insert(1);
f.insert(2);
Assert.assertTrue(f.maybeContains(2));
f.remove(2);
Assert.assertFalse(f.maybeContains(2));
f.remove(1);
f.remove(1);
Assert.assertTrue(f.maybeContains(1));
f.insert(3);
f.insert(3);
Assert.assertTrue(f.maybeContains(3));
f.remove(3);
f.remove(3);
Assert.assertTrue(f.maybeContains(3));
}
}
| 2,548
| 30.469136
| 88
|
java
|
ethereumj
|
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/db/RepositoryTest.java
|
/*
* Copyright (c) [2016] [ <ether.camp> ]
* This file is part of the ethereumJ library.
*
* The ethereumJ library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The ethereumJ library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the ethereumJ library. If not, see <http://www.gnu.org/licenses/>.
*/
package org.ethereum.db;
import org.ethereum.core.Genesis;
import org.ethereum.crypto.HashUtil;
import org.ethereum.core.Repository;
import org.ethereum.datasource.inmem.HashMapDB;
import org.ethereum.datasource.NoDeleteSource;
import org.ethereum.datasource.Source;
import org.ethereum.vm.DataWord;
import org.junit.Assert;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;
import org.spongycastle.util.encoders.Hex;
import java.math.BigInteger;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import static org.ethereum.util.ByteUtil.EMPTY_BYTE_ARRAY;
import static org.junit.Assert.*;
/**
* @author Roman Mandeleil
* @since 17.11.2014
*/
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class RepositoryTest {
@Test
public void test1() {
RepositoryRoot repository = new RepositoryRoot(new HashMapDB());
byte[] cow = Hex.decode("CD2A3D9F938E13CD947EC05ABC7FE734DF8DD826");
byte[] horse = Hex.decode("13978AEE95F38490E9769C39B2773ED763D9CD5F");
repository.increaseNonce(cow);
repository.increaseNonce(horse);
assertEquals(BigInteger.ONE, repository.getNonce(cow));
// assertEquals(BigInteger.ONE, repository.getNonce(horse));
System.out.println(repository.getTrieDump());
repository.increaseNonce(cow);
System.out.println(repository.getTrieDump());
repository.close();
}
@Test
public void test2() {
RepositoryRoot repository = new RepositoryRoot(new HashMapDB());
byte[] cow = Hex.decode("CD2A3D9F938E13CD947EC05ABC7FE734DF8DD826");
byte[] horse = Hex.decode("13978AEE95F38490E9769C39B2773ED763D9CD5F");
repository.addBalance(cow, BigInteger.TEN);
repository.addBalance(horse, BigInteger.ONE);
assertEquals(BigInteger.TEN, repository.getBalance(cow));
assertEquals(BigInteger.ONE, repository.getBalance(horse));
repository.close();
}
@Test
public void test3() {
RepositoryRoot repository = new RepositoryRoot(new HashMapDB());
byte[] cow = Hex.decode("CD2A3D9F938E13CD947EC05ABC7FE734DF8DD826");
byte[] horse = Hex.decode("13978AEE95F38490E9769C39B2773ED763D9CD5F");
byte[] cowCode = Hex.decode("A1A2A3");
byte[] horseCode = Hex.decode("B1B2B3");
repository.saveCode(cow, cowCode);
repository.saveCode(horse, horseCode);
assertArrayEquals(cowCode, repository.getCode(cow));
assertArrayEquals(horseCode, repository.getCode(horse));
repository.close();
}
@Test
public void test4() {
RepositoryRoot repository = new RepositoryRoot(new HashMapDB());
Repository track = repository.startTracking();
byte[] cow = Hex.decode("CD2A3D9F938E13CD947EC05ABC7FE734DF8DD826");
byte[] horse = Hex.decode("13978AEE95F38490E9769C39B2773ED763D9CD5F");
byte[] cowKey = Hex.decode("A1A2A3");
byte[] cowValue = Hex.decode("A4A5A6");
byte[] horseKey = Hex.decode("B1B2B3");
byte[] horseValue = Hex.decode("B4B5B6");
track.addStorageRow(cow, DataWord.of(cowKey), DataWord.of(cowValue));
track.addStorageRow(horse, DataWord.of(horseKey), DataWord.of(horseValue));
track.commit();
assertEquals(DataWord.of(cowValue), repository.getStorageValue(cow, DataWord.of(cowKey)));
assertEquals(DataWord.of(horseValue), repository.getStorageValue(horse, DataWord.of(horseKey)));
repository.close();
}
@Test
public void test5() {
RepositoryRoot repository = new RepositoryRoot(new HashMapDB());
Repository track = repository.startTracking();
byte[] cow = Hex.decode("CD2A3D9F938E13CD947EC05ABC7FE734DF8DD826");
byte[] horse = Hex.decode("13978AEE95F38490E9769C39B2773ED763D9CD5F");
track.increaseNonce(cow);
track.increaseNonce(cow);
track.increaseNonce(cow);
track.increaseNonce(cow);
track.increaseNonce(cow);
track.increaseNonce(cow);
track.increaseNonce(cow);
track.increaseNonce(cow);
track.increaseNonce(cow);
track.increaseNonce(cow);
track.increaseNonce(horse);
track.commit();
assertEquals(BigInteger.TEN, repository.getNonce(cow));
assertEquals(BigInteger.ONE, repository.getNonce(horse));
repository.close();
}
@Test
public void test6() {
RepositoryRoot repository = new RepositoryRoot(new HashMapDB());
Repository track = repository.startTracking();
byte[] cow = Hex.decode("CD2A3D9F938E13CD947EC05ABC7FE734DF8DD826");
byte[] horse = Hex.decode("13978AEE95F38490E9769C39B2773ED763D9CD5F");
track.increaseNonce(cow);
track.increaseNonce(cow);
track.increaseNonce(cow);
track.increaseNonce(cow);
track.increaseNonce(cow);
track.increaseNonce(cow);
track.increaseNonce(cow);
track.increaseNonce(cow);
track.increaseNonce(cow);
track.increaseNonce(cow);
track.increaseNonce(horse);
assertEquals(BigInteger.TEN, track.getNonce(cow));
assertEquals(BigInteger.ONE, track.getNonce(horse));
track.rollback();
assertEquals(BigInteger.ZERO, repository.getNonce(cow));
assertEquals(BigInteger.ZERO, repository.getNonce(horse));
repository.close();
}
@Test
public void test7() {
RepositoryRoot repository = new RepositoryRoot(new HashMapDB());
Repository track = repository.startTracking();
byte[] cow = Hex.decode("CD2A3D9F938E13CD947EC05ABC7FE734DF8DD826");
byte[] horse = Hex.decode("13978AEE95F38490E9769C39B2773ED763D9CD5F");
track.addBalance(cow, BigInteger.TEN);
track.addBalance(horse, BigInteger.ONE);
assertEquals(BigInteger.TEN, track.getBalance(cow));
assertEquals(BigInteger.ONE, track.getBalance(horse));
track.commit();
assertEquals(BigInteger.TEN, repository.getBalance(cow));
assertEquals(BigInteger.ONE, repository.getBalance(horse));
repository.close();
}
@Test
public void test8() {
RepositoryRoot repository = new RepositoryRoot(new HashMapDB());
Repository track = repository.startTracking();
byte[] cow = Hex.decode("CD2A3D9F938E13CD947EC05ABC7FE734DF8DD826");
byte[] horse = Hex.decode("13978AEE95F38490E9769C39B2773ED763D9CD5F");
track.addBalance(cow, BigInteger.TEN);
track.addBalance(horse, BigInteger.ONE);
assertEquals(BigInteger.TEN, track.getBalance(cow));
assertEquals(BigInteger.ONE, track.getBalance(horse));
track.rollback();
assertEquals(BigInteger.ZERO, repository.getBalance(cow));
assertEquals(BigInteger.ZERO, repository.getBalance(horse));
repository.close();
}
@Test
public void test7_1() {
RepositoryRoot repository = new RepositoryRoot(new HashMapDB());
Repository track1 = repository.startTracking();
byte[] cow = Hex.decode("CD2A3D9F938E13CD947EC05ABC7FE734DF8DD826");
byte[] horse = Hex.decode("13978AEE95F38490E9769C39B2773ED763D9CD5F");
track1.addBalance(cow, BigInteger.TEN);
track1.addBalance(horse, BigInteger.ONE);
assertEquals(BigInteger.TEN, track1.getBalance(cow));
assertEquals(BigInteger.ONE, track1.getBalance(horse));
Repository track2 = track1.startTracking();
assertEquals(BigInteger.TEN, track2.getBalance(cow));
assertEquals(BigInteger.ONE, track2.getBalance(horse));
track2.addBalance(cow, BigInteger.TEN);
track2.addBalance(cow, BigInteger.TEN);
track2.addBalance(cow, BigInteger.TEN);
track2.commit();
track1.commit();
assertEquals(new BigInteger("40"), repository.getBalance(cow));
assertEquals(BigInteger.ONE, repository.getBalance(horse));
repository.close();
}
@Test
public void test7_2() {
RepositoryRoot repository = new RepositoryRoot(new HashMapDB());
Repository track1 = repository.startTracking();
byte[] cow = Hex.decode("CD2A3D9F938E13CD947EC05ABC7FE734DF8DD826");
byte[] horse = Hex.decode("13978AEE95F38490E9769C39B2773ED763D9CD5F");
track1.addBalance(cow, BigInteger.TEN);
track1.addBalance(horse, BigInteger.ONE);
assertEquals(BigInteger.TEN, track1.getBalance(cow));
assertEquals(BigInteger.ONE, track1.getBalance(horse));
Repository track2 = track1.startTracking();
assertEquals(BigInteger.TEN, track2.getBalance(cow));
assertEquals(BigInteger.ONE, track2.getBalance(horse));
track2.addBalance(cow, BigInteger.TEN);
track2.addBalance(cow, BigInteger.TEN);
track2.addBalance(cow, BigInteger.TEN);
track2.commit();
track1.rollback();
assertEquals(BigInteger.ZERO, repository.getBalance(cow));
assertEquals(BigInteger.ZERO, repository.getBalance(horse));
repository.close();
}
@Test
public void test9() {
RepositoryRoot repository = new RepositoryRoot(new HashMapDB());
Repository track = repository.startTracking();
byte[] cow = Hex.decode("CD2A3D9F938E13CD947EC05ABC7FE734DF8DD826");
byte[] horse = Hex.decode("13978AEE95F38490E9769C39B2773ED763D9CD5F");
DataWord cowKey = DataWord.of(Hex.decode("A1A2A3"));
DataWord cowValue = DataWord.of(Hex.decode("A4A5A6"));
DataWord horseKey = DataWord.of(Hex.decode("B1B2B3"));
DataWord horseValue = DataWord.of(Hex.decode("B4B5B6"));
track.addStorageRow(cow, cowKey, cowValue);
track.addStorageRow(horse, horseKey, horseValue);
assertEquals(cowValue, track.getStorageValue(cow, cowKey));
assertEquals(horseValue, track.getStorageValue(horse, horseKey));
track.commit();
assertEquals(cowValue, repository.getStorageValue(cow, cowKey));
assertEquals(horseValue, repository.getStorageValue(horse, horseKey));
repository.close();
}
@Test
public void test10() {
RepositoryRoot repository = new RepositoryRoot(new HashMapDB());
Repository track = repository.startTracking();
byte[] cow = Hex.decode("CD2A3D9F938E13CD947EC05ABC7FE734DF8DD826");
byte[] horse = Hex.decode("13978AEE95F38490E9769C39B2773ED763D9CD5F");
DataWord cowKey = DataWord.of(Hex.decode("A1A2A3"));
DataWord cowValue = DataWord.of(Hex.decode("A4A5A6"));
DataWord horseKey = DataWord.of(Hex.decode("B1B2B3"));
DataWord horseValue = DataWord.of(Hex.decode("B4B5B6"));
track.addStorageRow(cow, cowKey, cowValue);
track.addStorageRow(horse, horseKey, horseValue);
assertEquals(cowValue, track.getStorageValue(cow, cowKey));
assertEquals(horseValue, track.getStorageValue(horse, horseKey));
track.rollback();
assertEquals(null, repository.getStorageValue(cow, cowKey));
assertEquals(null, repository.getStorageValue(horse, horseKey));
repository.close();
}
@Test
public void test11() {
RepositoryRoot repository = new RepositoryRoot(new HashMapDB());
Repository track = repository.startTracking();
byte[] cow = Hex.decode("CD2A3D9F938E13CD947EC05ABC7FE734DF8DD826");
byte[] horse = Hex.decode("13978AEE95F38490E9769C39B2773ED763D9CD5F");
byte[] cowCode = Hex.decode("A1A2A3");
byte[] horseCode = Hex.decode("B1B2B3");
track.saveCode(cow, cowCode);
track.saveCode(horse, horseCode);
assertArrayEquals(cowCode, track.getCode(cow));
assertArrayEquals(horseCode, track.getCode(horse));
track.commit();
assertArrayEquals(cowCode, repository.getCode(cow));
assertArrayEquals(horseCode, repository.getCode(horse));
repository.close();
}
@Test
public void test12() {
RepositoryRoot repository = new RepositoryRoot(new HashMapDB());
Repository track = repository.startTracking();
byte[] cow = Hex.decode("CD2A3D9F938E13CD947EC05ABC7FE734DF8DD826");
byte[] horse = Hex.decode("13978AEE95F38490E9769C39B2773ED763D9CD5F");
byte[] cowCode = Hex.decode("A1A2A3");
byte[] horseCode = Hex.decode("B1B2B3");
track.saveCode(cow, cowCode);
track.saveCode(horse, horseCode);
assertArrayEquals(cowCode, track.getCode(cow));
assertArrayEquals(horseCode, track.getCode(horse));
track.rollback();
assertArrayEquals(EMPTY_BYTE_ARRAY, repository.getCode(cow));
assertArrayEquals(EMPTY_BYTE_ARRAY, repository.getCode(horse));
repository.close();
}
@Test // Let's upload genesis pre-mine just like in the real world
public void test13() {
RepositoryRoot repository = new RepositoryRoot(new HashMapDB());
Repository track = repository.startTracking();
Genesis genesis = (Genesis)Genesis.getInstance();
Genesis.populateRepository(track, genesis);
track.commit();
assertArrayEquals(Genesis.getInstance().getStateRoot(), repository.getRoot());
repository.close();
}
@Test
public void test14() {
RepositoryRoot repository = new RepositoryRoot(new HashMapDB());
byte[] cow = Hex.decode("CD2A3D9F938E13CD947EC05ABC7FE734DF8DD826");
byte[] horse = Hex.decode("13978AEE95F38490E9769C39B2773ED763D9CD5F");
final BigInteger ELEVEN = BigInteger.TEN.add(BigInteger.ONE);
// changes level_1
Repository track1 = repository.startTracking();
track1.addBalance(cow, BigInteger.TEN);
track1.addBalance(horse, BigInteger.ONE);
assertEquals(BigInteger.TEN, track1.getBalance(cow));
assertEquals(BigInteger.ONE, track1.getBalance(horse));
// changes level_2
Repository track2 = track1.startTracking();
track2.addBalance(cow, BigInteger.ONE);
track2.addBalance(horse, BigInteger.TEN);
assertEquals(ELEVEN, track2.getBalance(cow));
assertEquals(ELEVEN, track2.getBalance(horse));
track2.commit();
track1.commit();
assertEquals(ELEVEN, repository.getBalance(cow));
assertEquals(ELEVEN, repository.getBalance(horse));
repository.close();
}
@Test
public void test15() {
RepositoryRoot repository = new RepositoryRoot(new HashMapDB());
byte[] cow = Hex.decode("CD2A3D9F938E13CD947EC05ABC7FE734DF8DD826");
byte[] horse = Hex.decode("13978AEE95F38490E9769C39B2773ED763D9CD5F");
final BigInteger ELEVEN = BigInteger.TEN.add(BigInteger.ONE);
// changes level_1
Repository track1 = repository.startTracking();
track1.addBalance(cow, BigInteger.TEN);
track1.addBalance(horse, BigInteger.ONE);
assertEquals(BigInteger.TEN, track1.getBalance(cow));
assertEquals(BigInteger.ONE, track1.getBalance(horse));
// changes level_2
Repository track2 = track1.startTracking();
track2.addBalance(cow, BigInteger.ONE);
track2.addBalance(horse, BigInteger.TEN);
assertEquals(ELEVEN, track2.getBalance(cow));
assertEquals(ELEVEN, track2.getBalance(horse));
track2.rollback();
track1.commit();
assertEquals(BigInteger.TEN, repository.getBalance(cow));
assertEquals(BigInteger.ONE, repository.getBalance(horse));
repository.close();
}
@Test
public void test16() {
RepositoryRoot repository = new RepositoryRoot(new HashMapDB());
byte[] cow = Hex.decode("CD2A3D9F938E13CD947EC05ABC7FE734DF8DD826");
byte[] horse = Hex.decode("13978AEE95F38490E9769C39B2773ED763D9CD5F");
byte[] cowKey1 = "key-c-1".getBytes();
byte[] cowValue1 = "val-c-1".getBytes();
byte[] horseKey1 = "key-h-1".getBytes();
byte[] horseValue1 = "val-h-1".getBytes();
byte[] cowKey2 = "key-c-2".getBytes();
byte[] cowValue2 = "val-c-2".getBytes();
byte[] horseKey2 = "key-h-2".getBytes();
byte[] horseValue2 = "val-h-2".getBytes();
// changes level_1
Repository track1 = repository.startTracking();
track1.addStorageRow(cow, DataWord.of(cowKey1), DataWord.of(cowValue1));
track1.addStorageRow(horse, DataWord.of(horseKey1), DataWord.of(horseValue1));
assertEquals(DataWord.of(cowValue1), track1.getStorageValue(cow, DataWord.of(cowKey1)));
assertEquals(DataWord.of(horseValue1), track1.getStorageValue(horse, DataWord.of(horseKey1)));
// changes level_2
Repository track2 = track1.startTracking();
track2.addStorageRow(cow, DataWord.of(cowKey2), DataWord.of(cowValue2));
track2.addStorageRow(horse, DataWord.of(horseKey2), DataWord.of(horseValue2));
assertEquals(DataWord.of(cowValue1), track2.getStorageValue(cow, DataWord.of(cowKey1)));
assertEquals(DataWord.of(horseValue1), track2.getStorageValue(horse, DataWord.of(horseKey1)));
assertEquals(DataWord.of(cowValue2), track2.getStorageValue(cow, DataWord.of(cowKey2)));
assertEquals(DataWord.of(horseValue2), track2.getStorageValue(horse, DataWord.of(horseKey2)));
track2.commit();
// leaving level_2
assertEquals(DataWord.of(cowValue1), track1.getStorageValue(cow, DataWord.of(cowKey1)));
assertEquals(DataWord.of(horseValue1), track1.getStorageValue(horse, DataWord.of(horseKey1)));
assertEquals(DataWord.of(cowValue2), track1.getStorageValue(cow, DataWord.of(cowKey2)));
assertEquals(DataWord.of(horseValue2), track1.getStorageValue(horse, DataWord.of(horseKey2)));
track1.commit();
// leaving level_1
assertEquals(DataWord.of(cowValue1), repository.getStorageValue(cow, DataWord.of(cowKey1)));
assertEquals(DataWord.of(horseValue1), repository.getStorageValue(horse, DataWord.of(horseKey1)));
assertEquals(DataWord.of(cowValue2), repository.getStorageValue(cow, DataWord.of(cowKey2)));
assertEquals(DataWord.of(horseValue2), repository.getStorageValue(horse, DataWord.of(horseKey2)));
repository.close();
}
@Test
public void test16_2() {
RepositoryRoot repository = new RepositoryRoot(new HashMapDB());
byte[] cow = Hex.decode("CD2A3D9F938E13CD947EC05ABC7FE734DF8DD826");
byte[] horse = Hex.decode("13978AEE95F38490E9769C39B2773ED763D9CD5F");
byte[] cowKey1 = "key-c-1".getBytes();
byte[] cowValue1 = "val-c-1".getBytes();
byte[] horseKey1 = "key-h-1".getBytes();
byte[] horseValue1 = "val-h-1".getBytes();
byte[] cowKey2 = "key-c-2".getBytes();
byte[] cowValue2 = "val-c-2".getBytes();
byte[] horseKey2 = "key-h-2".getBytes();
byte[] horseValue2 = "val-h-2".getBytes();
// changes level_1
Repository track1 = repository.startTracking();
// changes level_2
Repository track2 = track1.startTracking();
track2.addStorageRow(cow, DataWord.of(cowKey2), DataWord.of(cowValue2));
track2.addStorageRow(horse, DataWord.of(horseKey2), DataWord.of(horseValue2));
assertNull(track2.getStorageValue(cow, DataWord.of(cowKey1)));
assertNull(track2.getStorageValue(horse, DataWord.of(horseKey1)));
assertEquals(DataWord.of(cowValue2), track2.getStorageValue(cow, DataWord.of(cowKey2)));
assertEquals(DataWord.of(horseValue2), track2.getStorageValue(horse, DataWord.of(horseKey2)));
track2.commit();
// leaving level_2
assertNull(track1.getStorageValue(cow, DataWord.of(cowKey1)));
assertNull(track1.getStorageValue(horse, DataWord.of(horseKey1)));
assertEquals(DataWord.of(cowValue2), track1.getStorageValue(cow, DataWord.of(cowKey2)));
assertEquals(DataWord.of(horseValue2), track1.getStorageValue(horse, DataWord.of(horseKey2)));
track1.commit();
// leaving level_1
assertEquals(null, repository.getStorageValue(cow, DataWord.of(cowKey1)));
assertEquals(null, repository.getStorageValue(horse, DataWord.of(horseKey1)));
assertEquals(DataWord.of(cowValue2), repository.getStorageValue(cow, DataWord.of(cowKey2)));
assertEquals(DataWord.of(horseValue2), repository.getStorageValue(horse, DataWord.of(horseKey2)));
repository.close();
}
@Test
public void test16_3() {
RepositoryRoot repository = new RepositoryRoot(new HashMapDB());
byte[] cow = Hex.decode("CD2A3D9F938E13CD947EC05ABC7FE734DF8DD826");
byte[] horse = Hex.decode("13978AEE95F38490E9769C39B2773ED763D9CD5F");
byte[] cowKey1 = "key-c-1".getBytes();
byte[] cowValue1 = "val-c-1".getBytes();
byte[] horseKey1 = "key-h-1".getBytes();
byte[] horseValue1 = "val-h-1".getBytes();
byte[] cowKey2 = "key-c-2".getBytes();
byte[] cowValue2 = "val-c-2".getBytes();
byte[] horseKey2 = "key-h-2".getBytes();
byte[] horseValue2 = "val-h-2".getBytes();
// changes level_1
Repository track1 = repository.startTracking();
// changes level_2
Repository track2 = track1.startTracking();
track2.addStorageRow(cow, DataWord.of(cowKey2), DataWord.of(cowValue2));
track2.addStorageRow(horse, DataWord.of(horseKey2), DataWord.of(horseValue2));
assertNull(track2.getStorageValue(cow, DataWord.of(cowKey1)));
assertNull(track2.getStorageValue(horse, DataWord.of(horseKey1)));
assertEquals(DataWord.of(cowValue2), track2.getStorageValue(cow, DataWord.of(cowKey2)));
assertEquals(DataWord.of(horseValue2), track2.getStorageValue(horse, DataWord.of(horseKey2)));
track2.commit();
// leaving level_2
assertNull(track1.getStorageValue(cow, DataWord.of(cowKey1)));
assertNull(track1.getStorageValue(horse, DataWord.of(horseKey1)));
assertEquals(DataWord.of(cowValue2), track1.getStorageValue(cow, DataWord.of(cowKey2)));
assertEquals(DataWord.of(horseValue2), track1.getStorageValue(horse, DataWord.of(horseKey2)));
track1.rollback();
// leaving level_1
assertNull(repository.getStorageValue(cow, DataWord.of(cowKey1)));
assertNull(repository.getStorageValue(horse, DataWord.of(horseKey1)));
assertNull(repository.getStorageValue(cow, DataWord.of(cowKey2)));
assertNull(repository.getStorageValue(horse, DataWord.of(horseKey2)));
repository.close();
}
@Test
public void test16_4() {
RepositoryRoot repository = new RepositoryRoot(new HashMapDB());
byte[] cow = Hex.decode("CD2A3D9F938E13CD947EC05ABC7FE734DF8DD826");
byte[] horse = Hex.decode("13978AEE95F38490E9769C39B2773ED763D9CD5F");
byte[] cowKey1 = "key-c-1".getBytes();
byte[] cowValue1 = "val-c-1".getBytes();
byte[] horseKey1 = "key-h-1".getBytes();
byte[] horseValue1 = "val-h-1".getBytes();
byte[] cowKey2 = "key-c-2".getBytes();
byte[] cowValue2 = "val-c-2".getBytes();
byte[] horseKey2 = "key-h-2".getBytes();
byte[] horseValue2 = "val-h-2".getBytes();
Repository track = repository.startTracking();
track.addStorageRow(cow, DataWord.of(cowKey1), DataWord.of(cowValue1));
track.commit();
// changes level_1
Repository track1 = repository.startTracking();
// changes level_2
Repository track2 = track1.startTracking();
track2.addStorageRow(cow, DataWord.of(cowKey2), DataWord.of(cowValue2));
track2.commit();
// leaving level_2
track1.commit();
// leaving level_1
assertEquals(DataWord.of(cowValue1), track1.getStorageValue(cow, DataWord.of(cowKey1)));
assertEquals(DataWord.of(cowValue2), track1.getStorageValue(cow, DataWord.of(cowKey2)));
repository.close();
}
@Test
public void test16_5() {
RepositoryRoot repository = new RepositoryRoot(new HashMapDB());
byte[] cow = Hex.decode("CD2A3D9F938E13CD947EC05ABC7FE734DF8DD826");
byte[] horse = Hex.decode("13978AEE95F38490E9769C39B2773ED763D9CD5F");
byte[] cowKey1 = "key-c-1".getBytes();
byte[] cowValue1 = "val-c-1".getBytes();
byte[] horseKey1 = "key-h-1".getBytes();
byte[] horseValue1 = "val-h-1".getBytes();
byte[] cowKey2 = "key-c-2".getBytes();
byte[] cowValue2 = "val-c-2".getBytes();
byte[] horseKey2 = "key-h-2".getBytes();
byte[] horseValue2 = "val-h-2".getBytes();
// changes level_1
Repository track1 = repository.startTracking();
track1.addStorageRow(cow, DataWord.of(cowKey2), DataWord.of(cowValue2));
// changes level_2
Repository track2 = track1.startTracking();
assertEquals(DataWord.of(cowValue2), track1.getStorageValue(cow, DataWord.of(cowKey2)));
assertNull(track1.getStorageValue(cow, DataWord.of(cowKey1)));
track2.commit();
// leaving level_2
track1.commit();
// leaving level_1
assertEquals(DataWord.of(cowValue2), track1.getStorageValue(cow, DataWord.of(cowKey2)));
assertNull(track1.getStorageValue(cow, DataWord.of(cowKey1)));
repository.close();
}
@Test
public void test17() {
RepositoryRoot repository = new RepositoryRoot(new HashMapDB());
byte[] cow = Hex.decode("CD2A3D9F938E13CD947EC05ABC7FE734DF8DD826");
byte[] cowKey1 = "key-c-1".getBytes();
byte[] cowValue1 = "val-c-1".getBytes();
// changes level_1
Repository track1 = repository.startTracking();
// changes level_2
Repository track2 = track1.startTracking();
track2.addStorageRow(cow, DataWord.of(cowKey1), DataWord.of(cowValue1));
assertEquals(DataWord.of(cowValue1), track2.getStorageValue(cow, DataWord.of(cowKey1)));
track2.rollback();
// leaving level_2
track1.commit();
// leaving level_1
Assert.assertEquals(Hex.toHexString(HashUtil.EMPTY_TRIE_HASH), Hex.toHexString(repository.getRoot()));
repository.close();
}
@Test
public void test18() {
RepositoryRoot repository = new RepositoryRoot(new HashMapDB());
Repository repoTrack2 = repository.startTracking(); //track
byte[] cow = Hex.decode("CD2A3D9F938E13CD947EC05ABC7FE734DF8DD826");
byte[] horse = Hex.decode("13978AEE95F38490E9769C39B2773ED763D9CD5F");
byte[] pig = Hex.decode("F0B8C9D84DD2B877E0B952130B73E218106FEC04");
byte[] precompiled = Hex.decode("0000000000000000000000000000000000000002");
byte[] cowCode = Hex.decode("A1A2A3");
byte[] horseCode = Hex.decode("B1B2B3");
repository.saveCode(cow, cowCode);
repository.saveCode(horse, horseCode);
repository.delete(horse);
assertEquals(true, repoTrack2.isExist(cow));
assertEquals(false, repoTrack2.isExist(horse));
assertEquals(false, repoTrack2.isExist(pig));
assertEquals(false, repoTrack2.isExist(precompiled));
}
@Test
public void test19() {
RepositoryRoot repository = new RepositoryRoot(new HashMapDB());
Repository track = repository.startTracking();
byte[] cow = Hex.decode("CD2A3D9F938E13CD947EC05ABC7FE734DF8DD826");
byte[] horse = Hex.decode("13978AEE95F38490E9769C39B2773ED763D9CD5F");
DataWord cowKey1 = DataWord.of("c1");
DataWord cowVal1 = DataWord.of("c0a1");
DataWord cowVal0 = DataWord.of("c0a0");
DataWord horseKey1 = DataWord.of("e1");
DataWord horseVal1 = DataWord.of("c0a1");
DataWord horseVal0 = DataWord.of("c0a0");
track.addStorageRow(cow, cowKey1, cowVal0);
track.addStorageRow(horse, horseKey1, horseVal0);
track.commit();
Repository track2 = repository.startTracking(); //track
track2.addStorageRow(horse, horseKey1, horseVal0);
Repository track3 = track2.startTracking();
ContractDetails cowDetails = track3.getContractDetails(cow);
cowDetails.put(cowKey1, cowVal1);
ContractDetails horseDetails = track3.getContractDetails(horse);
horseDetails.put(horseKey1, horseVal1);
track3.commit();
track2.rollback();
ContractDetails cowDetailsOrigin = repository.getContractDetails(cow);
DataWord cowValOrin = cowDetailsOrigin.get(cowKey1);
ContractDetails horseDetailsOrigin = repository.getContractDetails(horse);
DataWord horseValOrin = horseDetailsOrigin.get(horseKey1);
assertEquals(cowVal0, cowValOrin);
assertEquals(horseVal0, horseValOrin);
}
@Test // testing for snapshot
public void test20() {
// MapDB stateDB = new MapDB();
Source<byte[], byte[]> stateDB = new NoDeleteSource<>(new HashMapDB<byte[]>());
RepositoryRoot repository = new RepositoryRoot(stateDB);
byte[] root = repository.getRoot();
byte[] cow = Hex.decode("CD2A3D9F938E13CD947EC05ABC7FE734DF8DD826");
byte[] horse = Hex.decode("13978AEE95F38490E9769C39B2773ED763D9CD5F");
DataWord cowKey1 = DataWord.of("c1");
DataWord cowKey2 = DataWord.of("c2");
DataWord cowVal1 = DataWord.of("c0a1");
DataWord cowVal0 = DataWord.of("c0a0");
DataWord horseKey1 = DataWord.of("e1");
DataWord horseKey2 = DataWord.of("e2");
DataWord horseVal1 = DataWord.of("c0a1");
DataWord horseVal0 = DataWord.of("c0a0");
Repository track2 = repository.startTracking(); //track
track2.addStorageRow(cow, cowKey1, cowVal1);
track2.addStorageRow(horse, horseKey1, horseVal1);
track2.commit();
repository.commit();
byte[] root2 = repository.getRoot();
track2 = repository.startTracking(); //track
track2.addStorageRow(cow, cowKey2, cowVal0);
track2.addStorageRow(horse, horseKey2, horseVal0);
track2.commit();
repository.commit();
byte[] root3 = repository.getRoot();
Repository snapshot = new RepositoryRoot(stateDB, root);
ContractDetails cowDetails = snapshot.getContractDetails(cow);
ContractDetails horseDetails = snapshot.getContractDetails(horse);
assertEquals(null, cowDetails.get(cowKey1) );
assertEquals(null, cowDetails.get(cowKey2) );
assertEquals(null, horseDetails.get(horseKey1) );
assertEquals(null, horseDetails.get(horseKey2) );
snapshot = new RepositoryRoot(stateDB, root2);
cowDetails = snapshot.getContractDetails(cow);
horseDetails = snapshot.getContractDetails(horse);
assertEquals(cowVal1, cowDetails.get(cowKey1));
assertEquals(null, cowDetails.get(cowKey2));
assertEquals(horseVal1, horseDetails.get(horseKey1) );
assertEquals(null, horseDetails.get(horseKey2) );
snapshot = new RepositoryRoot(stateDB, root3);
cowDetails = snapshot.getContractDetails(cow);
horseDetails = snapshot.getContractDetails(horse);
assertEquals(cowVal1, cowDetails.get(cowKey1));
assertEquals(cowVal0, cowDetails.get(cowKey2));
assertEquals(horseVal1, horseDetails.get(horseKey1) );
assertEquals(horseVal0, horseDetails.get(horseKey2) );
}
private boolean running = true;
@Test // testing for snapshot
public void testMultiThread() throws InterruptedException {
// Add logging line to {@link org.ethereum.datasource.WriteCache} in the beginning of flushImpl() method:
// System.out.printf("Flush start: %s%n", this);
// to increase chance of failing. Also increasing waiting time may be helpful.
final RepositoryImpl repository = new RepositoryRoot(new HashMapDB());
final byte[] cow = Hex.decode("CD2A3D9F938E13CD947EC05ABC7FE734DF8DD826");
final DataWord cowKey1 = DataWord.of("c1");
final DataWord cowKey2 = DataWord.of("c2");
final DataWord cowVal0 = DataWord.of("c0a0");
Repository track2 = repository.startTracking(); //track
track2.addStorageRow(cow, cowKey2, cowVal0);
track2.commit();
repository.flush();
ContractDetails cowDetails = repository.getContractDetails(cow);
assertEquals(cowVal0, cowDetails.get(cowKey2));
final CountDownLatch failSema = new CountDownLatch(1);
for (int i = 0; i < 10; ++i) {
new Thread(() -> {
try {
int cnt = 1;
while (running) {
Repository snap = repository.getSnapshotTo(repository.getRoot()).startTracking();
snap.addBalance(cow, BigInteger.TEN);
snap.addStorageRow(cow, cowKey1, DataWord.of(cnt));
snap.rollback();
cnt++;
}
} catch (Throwable e) {
e.printStackTrace();
failSema.countDown();
}
}).start();
}
new Thread(() -> {
int cnt = 1;
try {
while(running) {
Repository track21 = repository.startTracking(); //track
DataWord cVal = DataWord.of(cnt);
track21.addStorageRow(cow, cowKey1, cVal);
track21.addBalance(cow, BigInteger.ONE);
track21.commit();
repository.flush();
assertEquals(BigInteger.valueOf(cnt), repository.getBalance(cow));
assertEquals(cVal, repository.getStorageValue(cow, cowKey1));
assertEquals(cowVal0, repository.getStorageValue(cow, cowKey2));
cnt++;
}
} catch (Throwable e) {
e.printStackTrace();
try {
repository.addStorageRow(cow, cowKey1, DataWord.of(123));
} catch (Exception e1) {
e1.printStackTrace();
}
failSema.countDown();
}
}).start();
failSema.await(10, TimeUnit.SECONDS);
running = false;
if (failSema.getCount() == 0) {
throw new RuntimeException("Test failed.");
}
}
}
| 35,494
| 33.83317
| 113
|
java
|
ethereumj
|
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/db/SlowHashMapDb.java
|
/*
* Copyright (c) [2016] [ <ether.camp> ]
* This file is part of the ethereumJ library.
*
* The ethereumJ library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The ethereumJ library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the ethereumJ library. If not, see <http://www.gnu.org/licenses/>.
*/
package org.ethereum.db;
import org.ethereum.datasource.inmem.HashMapDB;
import java.util.Map;
/**
* Created by Anton Nashatyrev on 29.12.2016.
*/
public class SlowHashMapDb<V> extends HashMapDB<V> {
long delay = 1;
public SlowHashMapDb<V> withDelay(long delay) {
this.delay = delay;
return this;
}
@Override
public void put(byte[] key, V val) {
try {Thread.sleep(delay);} catch (InterruptedException e) {}
super.put(key, val);
}
@Override
public V get(byte[] key) {
try {Thread.sleep(delay);} catch (InterruptedException e) {}
return super.get(key);
}
@Override
public void delete(byte[] key) {
try {Thread.sleep(delay);} catch (InterruptedException e) {}
super.delete(key);
}
@Override
public boolean flush() {
try {Thread.sleep(delay);} catch (InterruptedException e) {}
return super.flush();
}
@Override
public void updateBatch(Map<byte[], V> rows) {
try {Thread.sleep(delay);} catch (InterruptedException e) {}
super.updateBatch(rows);
}
}
| 1,915
| 28.030303
| 80
|
java
|
ethereumj
|
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/db/prune/SegmentTest.java
|
package org.ethereum.db.prune;
import org.junit.Test;
import static org.ethereum.util.ByteUtil.intToBytes;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
/**
* @author Mikhail Kalinin
* @since 31.01.2018
*/
public class SegmentTest {
@Test
public void simpleTest() {
Segment s = new Segment(1, intToBytes(1), intToBytes(0));
assertEquals(Chain.NULL, s.main);
assertFalse(s.isComplete());
assertEquals(0, s.getMaxNumber());
assertEquals(0, s.size());
Segment.Tracker t = s.startTracking();
t.addMain(2, intToBytes(2), intToBytes(1));
t.commit();
assertTrue(s.isComplete());
assertEquals(2, s.getMaxNumber());
assertEquals(1, s.size());
t = s.startTracking();
t.addItem(2, intToBytes(21), intToBytes(1));
t.addItem(2, intToBytes(22), intToBytes(1));
t.addItem(3, intToBytes(3), intToBytes(2));
t.addMain(3, intToBytes(3), intToBytes(2)); // should process double adding
t.commit();
assertTrue(s.isComplete());
assertEquals(3, s.getMaxNumber());
assertEquals(2, s.size());
assertEquals(2, s.forks.size());
t = s.startTracking();
t.addItem(3, intToBytes(31), intToBytes(21));
t.commit();
assertFalse(s.isComplete());
assertEquals(3, s.getMaxNumber());
assertEquals(2, s.size());
assertEquals(2, s.forks.size());
}
@Test // short forks
public void testFork1() {
Segment s = new Segment(1, intToBytes(1), intToBytes(0));
s.startTracking()
.addItem(2, intToBytes(2), intToBytes(1))
.addMain(2, intToBytes(2), intToBytes(1))
.commit();
assertTrue(s.isComplete());
s.startTracking()
.addItem(3, intToBytes(31), intToBytes(2))
.addItem(3, intToBytes(32), intToBytes(2))
.addItem(3, intToBytes(3), intToBytes(2))
.addMain(3, intToBytes(3), intToBytes(2))
.commit();
assertFalse(s.isComplete());
assertEquals(2, s.size());
assertEquals(2, s.forks.size());
s.startTracking()
.addItem(4, intToBytes(41), intToBytes(31))
.addItem(4, intToBytes(4), intToBytes(3))
.addMain(4, intToBytes(4), intToBytes(3))
.commit();
assertFalse(s.isComplete());
assertEquals(3, s.size());
assertEquals(2, s.forks.size());
assertEquals(4, s.getMaxNumber());
s.startTracking()
.addItem(5, intToBytes(53), intToBytes(4))
.addItem(5, intToBytes(5), intToBytes(4))
.addMain(5, intToBytes(5), intToBytes(4))
.commit();
s.startTracking()
.addItem(6, intToBytes(6), intToBytes(5))
.addMain(6, intToBytes(6), intToBytes(5))
.commit();
assertTrue(s.isComplete());
assertEquals(5, s.size());
assertEquals(3, s.forks.size());
assertEquals(6, s.getMaxNumber());
}
@Test // long fork with short forks
public void testFork2() {
Segment s = new Segment(1, intToBytes(1), intToBytes(0));
s.startTracking()
.addItem(2, intToBytes(2), intToBytes(1))
.addMain(2, intToBytes(2), intToBytes(1))
.commit();
assertTrue(s.isComplete());
s.startTracking()
.addItem(3, intToBytes(30), intToBytes(2))
.addItem(3, intToBytes(31), intToBytes(2))
.addItem(3, intToBytes(3), intToBytes(2))
.addMain(3, intToBytes(3), intToBytes(2))
.commit();
assertFalse(s.isComplete());
assertEquals(2, s.size());
assertEquals(2, s.forks.size());
s.startTracking()
.addItem(4, intToBytes(40), intToBytes(30))
.addItem(4, intToBytes(41), intToBytes(31))
.addItem(4, intToBytes(42), intToBytes(3))
.addItem(4, intToBytes(4), intToBytes(3))
.addMain(4, intToBytes(4), intToBytes(3))
.commit();
assertFalse(s.isComplete());
assertEquals(3, s.size());
assertEquals(3, s.forks.size());
assertEquals(4, s.getMaxNumber());
s.startTracking()
.addItem(5, intToBytes(50), intToBytes(40))
.addItem(5, intToBytes(53), intToBytes(4))
.addItem(5, intToBytes(5), intToBytes(4))
.addMain(5, intToBytes(5), intToBytes(4))
.commit();
s.startTracking()
.addItem(6, intToBytes(60), intToBytes(50))
.addItem(6, intToBytes(6), intToBytes(5))
.addMain(6, intToBytes(6), intToBytes(5))
.commit();
assertFalse(s.isComplete());
assertEquals(5, s.size());
assertEquals(4, s.forks.size());
assertEquals(6, s.getMaxNumber());
s.startTracking()
.addItem(7, intToBytes(7), intToBytes(6))
.addMain(7, intToBytes(7), intToBytes(6))
.commit();
assertTrue(s.isComplete());
assertEquals(6, s.size());
assertEquals(4, s.forks.size());
assertEquals(7, s.getMaxNumber());
}
@Test // several branches started at fork block
public void testFork3() {
/*
2: 2 -> 3: 3 -> 4: 4 -> 5: 5 -> 6: 6 <-- Main
\
-> 3: 31 -> 4: 41
\ -> 5: 53
\ /
-> 4: 42 -> 5: 52
\
-> 5: 54
*/
Segment s = new Segment(1, intToBytes(1), intToBytes(0));
s.startTracking()
.addItem(2, intToBytes(2), intToBytes(1))
.addMain(2, intToBytes(2), intToBytes(1))
.commit();
s.startTracking()
.addItem(3, intToBytes(3), intToBytes(2))
.addItem(3, intToBytes(31), intToBytes(2))
.addMain(3, intToBytes(3), intToBytes(2))
.commit();
s.startTracking()
.addItem(4, intToBytes(4), intToBytes(3))
.addItem(4, intToBytes(41), intToBytes(31))
.addItem(4, intToBytes(42), intToBytes(31))
.addMain(4, intToBytes(4), intToBytes(3))
.commit();
s.startTracking()
.addItem(5, intToBytes(5), intToBytes(4))
.addItem(5, intToBytes(52), intToBytes(42))
.addItem(5, intToBytes(53), intToBytes(42))
.addItem(5, intToBytes(54), intToBytes(42))
.addMain(5, intToBytes(5), intToBytes(4))
.commit();
s.startTracking()
.addItem(6, intToBytes(6), intToBytes(5))
.addMain(6, intToBytes(6), intToBytes(5))
.commit();
Chain main = Chain.fromItems(
new ChainItem(2, intToBytes(2), intToBytes(1)),
new ChainItem(3, intToBytes(3), intToBytes(2)),
new ChainItem(4, intToBytes(4), intToBytes(3)),
new ChainItem(5, intToBytes(5), intToBytes(4)),
new ChainItem(6, intToBytes(6), intToBytes(5))
);
Chain fork1 = Chain.fromItems(
new ChainItem(3, intToBytes(31), intToBytes(2)),
new ChainItem(4, intToBytes(41), intToBytes(31))
);
Chain fork2 = Chain.fromItems(
new ChainItem(4, intToBytes(42), intToBytes(31)),
new ChainItem(5, intToBytes(52), intToBytes(42))
);
Chain fork3 = Chain.fromItems(
new ChainItem(5, intToBytes(53), intToBytes(42))
);
Chain fork4 = Chain.fromItems(
new ChainItem(5, intToBytes(54), intToBytes(42))
);
assertEquals(main, s.main);
assertEquals(4, s.forks.size());
assertEquals(fork1, s.forks.get(0));
assertEquals(fork2, s.forks.get(1));
assertEquals(fork3, s.forks.get(2));
assertEquals(fork4, s.forks.get(3));
}
}
| 8,382
| 32.802419
| 84
|
java
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.