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
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/tck/RunTck.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.tck; import org.ethereum.jsontestsuite.suite.*; import org.ethereum.jsontestsuite.suite.runners.StateTestRunner; import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; import org.json.simple.parser.ParseException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.IOException; import java.util.HashMap; import java.util.List; import java.util.Map; public class RunTck { private static Logger logger = LoggerFactory.getLogger("TCK-Test"); public static void main(String[] args) throws ParseException, IOException { if (args.length > 0){ if (args[0].equals("filerun")) { logger.info("TCK Running, file: " + args[1]); runTest(args[1]); } else if ((args[0].equals("content"))) { logger.debug("TCK Running, content: "); runContentTest(args[1].replaceAll("'", "\"")); } } else { logger.info("No test case specified"); } } public static void runContentTest(String content) throws ParseException, IOException { Map<String, Boolean> summary = new HashMap<>(); JSONParser parser = new JSONParser(); JSONObject testSuiteObj = (JSONObject) parser.parse(content); StateTestSuite stateTestSuite = new StateTestSuite(testSuiteObj.toJSONString()); Map<String, StateTestCase> testCases = stateTestSuite.getTestCases(); for (String testName : testCases.keySet()) { logger.info(" Test case: {}", testName); StateTestCase stateTestCase = testCases.get(testName); List<String> result = StateTestRunner.run(stateTestCase); if (!result.isEmpty()) summary.put(testName, false); else summary.put(testName, true); } logger.info("Summary: "); logger.info("========="); int fails = 0; int pass = 0; for (String key : summary.keySet()){ if (summary.get(key)) ++pass; else ++fails; String sumTest = String.format("%-60s:^%s", key, (summary.get(key) ? "OK" : "FAIL")). replace(' ', '.'). replace("^", " "); logger.info(sumTest); } logger.info(" - Total: Pass: {}, Failed: {} - ", pass, fails); if (fails > 0) System.exit(1); else System.exit(0); } public static void runTest(String name) throws ParseException, IOException { String testCaseJson = JSONReader.getFromLocal(name); runContentTest(testCaseJson); } }
3,455
31
97
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/util/RLPDump.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.util; import org.ethereum.crypto.ECKey; import org.junit.Test; import org.spongycastle.util.encoders.Hex; /** * Created by Anton Nashatyrev on 29.09.2015. */ public class RLPDump { @Test public void dumpTest() { System.out.println(Hex.toHexString(new ECKey().getPubKey())); String hexRlp = "f872f870845609a1ba64c0b8660480136e573eb81ac4a664f8f76e4887ba927f791a053ec5ff580b1037a8633320ca70f8ec0cdea59167acaa1debc07bc0a0b3a5b41bdf0cb4346c18ddbbd2cf222f54fed795dde94417d2e57f85a580d87238efc75394ca4a92cfe6eb9debcc3583c26fee8580"; System.out.println(dump(RLP.decode2(Hex.decode(hexRlp)), 0)); hexRlp = "f8d1f8cf845605846c3cc58479a94c49b8c0800b0b2d39d7c59778edb5166bfd0415c5e02417955ef4ef7f7d8c1dfc7f59a0141d97dd798bde6b972090390758b67457e93c2acb11ed4941d4443f87cedbc09c1b0476ca17f4f04da3d69cfb6470969f73d401ee7692293a00a2ff2d7f3fac87d43d85aed19c9e6ecbfe7e5f8268209477ffda58c7a481eec5c50abd313d10b6554e6e04a04fd93b9bf781d600f4ceb3060002ce1eddbbd51a9a902a970d9b41a9627141c0c52742b1179d83e17f1a273adf0a4a1d0346c68686a51428dd9a01"; System.out.println(dump(RLP.decode2(Hex.decode(hexRlp)), 0)); hexRlp = "dedd84560586f03cc58479a94c498e0c48656c6c6f205768697370657281bc"; System.out.println(dump(RLP.decode2(Hex.decode(hexRlp)), 0)); hexRlp = "dedd84560586f03cc58479a94c498e0c48656c6c6f205768697370657281bc"; System.out.println(dump(RLP.decode2(Hex.decode(hexRlp)), 0)); } public static String dump(RLPElement el, int indent) { String ret = ""; if (el instanceof RLPList) { ret = Utils.repeat(" ", indent) + "[\n"; for (RLPElement element : ((RLPList) el)) { ret += dump(element, indent + 1); } ret += Utils.repeat(" ", indent) + "]\n"; } else { ret += Utils.repeat(" ", indent) + (el.getRLPData() == null ? "<null>" : Hex.toHexString(el.getRLPData())) + "\n"; } return ret; } }
2,814
49.267857
442
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/util/CollectionUtilsTest.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.util; import org.junit.Test; import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.concurrent.atomic.AtomicInteger; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; public class CollectionUtilsTest { @Test public void test() { final List<Integer> input = Arrays.asList(2, 4, 6, 8, 10, 12, 14, 16, 18, 20); assertEquals(10, input.size()); List<Integer> resEqual = CollectionUtils.truncateRand(input, 10); assertArrayEquals(input.toArray(), resEqual.toArray()); List<Integer> resEqual2 = CollectionUtils.truncateRand(input, 20); assertArrayEquals(input.toArray(), resEqual2.toArray()); Set<Integer> excluded = new HashSet<>(); for (int i = 0; i < 1000; ++i) { List<Integer> resMinusOne = CollectionUtils.truncateRand(input, 9); Set<Integer> resMinusOneSet = new HashSet<>(resMinusOne); assertEquals(resMinusOne.size(), resMinusOneSet.size()); AtomicInteger exclusionCounter = new AtomicInteger(0); input.forEach(x -> { if(!resMinusOneSet.contains(x)) { excluded.add(x); exclusionCounter.getAndIncrement(); } }); assertEquals(1, exclusionCounter.get()); } assertEquals("Someday I'll fail due to the nature of random", 10, excluded.size()); Set<Integer> included = new HashSet<>(); for (int i = 0; i < 1000; ++i) { List<Integer> resOne = CollectionUtils.truncateRand(input, 1); included.add(resOne.get(0)); assertTrue(input.contains(resOne.get(0))); } assertEquals("Someday I'll fail due to the nature of random", 10, included.size()); assertEquals(3, CollectionUtils.truncateRand(input, 3).size()); } }
2,793
37.805556
91
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/util/ExecutorPipelineTest.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.util; import org.junit.Assert; import org.junit.Test; import java.util.ArrayList; import java.util.List; /** * Created by Anton Nashatyrev on 21.07.2016. */ public class ExecutorPipelineTest { @Test public void joinTest() throws InterruptedException { ExecutorPipeline<Integer, Integer> exec1 = new ExecutorPipeline<>(8, 100, true, integer -> { try { Thread.sleep(2); } catch (InterruptedException e) { throw new RuntimeException(e); } return integer; }, Throwable::printStackTrace); final List<Integer> consumed = new ArrayList<>(); ExecutorPipeline<Integer, Void> exec2 = exec1.add(1, 100, consumed::add); int cnt = 1000; for (int i = 0; i < cnt; i++) { exec1.push(i); } exec1.join(); Assert.assertEquals(cnt, consumed.size()); } }
1,747
30.214286
87
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/util/ByteUtilTest.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.util; import org.junit.Assert; import org.junit.Test; import org.spongycastle.util.BigIntegers; import org.spongycastle.util.encoders.Hex; import java.math.BigInteger; import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.List; import static org.junit.Assert.*; public class ByteUtilTest { @Test public void testAppendByte() { byte[] bytes = "tes".getBytes(); byte b = 0x74; Assert.assertArrayEquals("test".getBytes(), ByteUtil.appendByte(bytes, b)); } @Test public void testBigIntegerToBytes() { byte[] expecteds = new byte[]{(byte) 0xff, (byte) 0xec, 0x78}; BigInteger b = BigInteger.valueOf(16772216); byte[] actuals = ByteUtil.bigIntegerToBytes(b); assertArrayEquals(expecteds, actuals); } @Test public void testBigIntegerToBytesSign() { { BigInteger b = BigInteger.valueOf(-2); byte[] actuals = ByteUtil.bigIntegerToBytesSigned(b, 8); assertArrayEquals(Hex.decode("fffffffffffffffe"), actuals); } { BigInteger b = BigInteger.valueOf(2); byte[] actuals = ByteUtil.bigIntegerToBytesSigned(b, 8); assertArrayEquals(Hex.decode("0000000000000002"), actuals); } { BigInteger b = BigInteger.valueOf(0); byte[] actuals = ByteUtil.bigIntegerToBytesSigned(b, 8); assertArrayEquals(Hex.decode("0000000000000000"), actuals); } { BigInteger b = new BigInteger("eeeeeeeeeeeeee", 16); byte[] actuals = ByteUtil.bigIntegerToBytesSigned(b, 8); assertArrayEquals(Hex.decode("00eeeeeeeeeeeeee"), actuals); } { BigInteger b = new BigInteger("eeeeeeeeeeeeeeee", 16); byte[] actuals = ByteUtil.bigIntegerToBytesSigned(b, 8); assertArrayEquals(Hex.decode("eeeeeeeeeeeeeeee"), actuals); } } @Test public void testBigIntegerToBytesNegative() { byte[] expecteds = new byte[]{(byte) 0xff, 0x0, 0x13, (byte) 0x88}; BigInteger b = BigInteger.valueOf(-16772216); byte[] actuals = ByteUtil.bigIntegerToBytes(b); assertArrayEquals(expecteds, actuals); } @Test public void testBigIntegerToBytesZero() { byte[] expecteds = new byte[]{0x00}; BigInteger b = BigInteger.ZERO; byte[] actuals = ByteUtil.bigIntegerToBytes(b); assertArrayEquals(expecteds, actuals); } @Test public void testToHexString() { assertEquals("", ByteUtil.toHexString(null)); } @Test public void testCalcPacketLength() { byte[] test = new byte[]{0x0f, 0x10, 0x43}; byte[] expected = new byte[]{0x00, 0x00, 0x00, 0x03}; assertArrayEquals(expected, ByteUtil.calcPacketLength(test)); } @Test public void testByteArrayToInt() { assertEquals(0, ByteUtil.byteArrayToInt(null)); assertEquals(0, ByteUtil.byteArrayToInt(new byte[0])); // byte[] x = new byte[] { 5,1,7,0,8 }; // long start = System.currentTimeMillis(); // for (int i = 0; i < 100000000; i++) { // ByteArray.read32bit(x, 0); // } // long end = System.currentTimeMillis(); // System.out.println(end - start + "ms"); // // long start1 = System.currentTimeMillis(); // for (int i = 0; i < 100000000; i++) { // new BigInteger(1, x).intValue(); // } // long end1 = System.currentTimeMillis(); // System.out.println(end1 - start1 + "ms"); } @Test public void testNumBytes() { String test1 = "0"; String test2 = "1"; String test3 = "1000000000"; //3B9ACA00 int expected1 = 1; int expected2 = 1; int expected3 = 4; assertEquals(expected1, ByteUtil.numBytes(test1)); assertEquals(expected2, ByteUtil.numBytes(test2)); assertEquals(expected3, ByteUtil.numBytes(test3)); } @Test public void testStripLeadingZeroes() { byte[] test1 = null; byte[] test2 = new byte[]{}; byte[] test3 = new byte[]{0x00}; byte[] test4 = new byte[]{0x00, 0x01}; byte[] test5 = new byte[]{0x00, 0x00, 0x01}; byte[] expected1 = null; byte[] expected2 = new byte[]{0}; byte[] expected3 = new byte[]{0}; byte[] expected4 = new byte[]{0x01}; byte[] expected5 = new byte[]{0x01}; assertArrayEquals(expected1, ByteUtil.stripLeadingZeroes(test1)); assertArrayEquals(expected2, ByteUtil.stripLeadingZeroes(test2)); assertArrayEquals(expected3, ByteUtil.stripLeadingZeroes(test3)); assertArrayEquals(expected4, ByteUtil.stripLeadingZeroes(test4)); assertArrayEquals(expected5, ByteUtil.stripLeadingZeroes(test5)); } @Test public void testMatchingNibbleLength1() { // a larger than b byte[] a = new byte[]{0x00, 0x01}; byte[] b = new byte[]{0x00}; int result = ByteUtil.matchingNibbleLength(a, b); assertEquals(1, result); } @Test public void testMatchingNibbleLength2() { // b larger than a byte[] a = new byte[]{0x00}; byte[] b = new byte[]{0x00, 0x01}; int result = ByteUtil.matchingNibbleLength(a, b); assertEquals(1, result); } @Test public void testMatchingNibbleLength3() { // a and b the same length equal byte[] a = new byte[]{0x00}; byte[] b = new byte[]{0x00}; int result = ByteUtil.matchingNibbleLength(a, b); assertEquals(1, result); } @Test public void testMatchingNibbleLength4() { // a and b the same length not equal byte[] a = new byte[]{0x01}; byte[] b = new byte[]{0x00}; int result = ByteUtil.matchingNibbleLength(a, b); assertEquals(0, result); } @Test public void testNiceNiblesOutput_1() { byte[] test = {7, 0, 7, 5, 7, 0, 7, 0, 7, 9}; String result = "\\x07\\x00\\x07\\x05\\x07\\x00\\x07\\x00\\x07\\x09"; assertEquals(result, ByteUtil.nibblesToPrettyString(test)); } @Test public void testNiceNiblesOutput_2() { byte[] test = {7, 0, 7, 0xf, 7, 0, 0xa, 0, 7, 9}; String result = "\\x07\\x00\\x07\\x0f\\x07\\x00\\x0a\\x00\\x07\\x09"; assertEquals(result, ByteUtil.nibblesToPrettyString(test)); } @Test(expected = NullPointerException.class) public void testMatchingNibbleLength5() { // a == null byte[] a = null; byte[] b = new byte[]{0x00}; ByteUtil.matchingNibbleLength(a, b); } @Test(expected = NullPointerException.class) public void testMatchingNibbleLength6() { // b == null byte[] a = new byte[]{0x00}; byte[] b = null; ByteUtil.matchingNibbleLength(a, b); } @Test public void testMatchingNibbleLength7() { // a or b is empty byte[] a = new byte[0]; byte[] b = new byte[]{0x00}; int result = ByteUtil.matchingNibbleLength(a, b); assertEquals(0, result); } /** * This test shows the difference between iterating over, * and comparing byte[] vs BigInteger value. * * Results indicate that the former has ~15x better performance. * Therefore this is used in the Miner.mine() method. */ @Test public void testIncrementPerformance() { boolean testEnabled = false; if (testEnabled) { byte[] counter1 = new byte[4]; byte[] max = ByteBuffer.allocate(4).putInt(Integer.MAX_VALUE).array(); long start1 = System.currentTimeMillis(); while (ByteUtil.increment(counter1)) { if (FastByteComparisons.compareTo(counter1, 0, 4, max, 0, 4) == 0) { break; } } System.out.println(System.currentTimeMillis() - start1 + "ms to reach: " + Hex.toHexString(counter1)); BigInteger counter2 = BigInteger.ZERO; long start2 = System.currentTimeMillis(); while (true) { if (counter2.compareTo(BigInteger.valueOf(Integer.MAX_VALUE)) == 0) { break; } counter2 = counter2.add(BigInteger.ONE); } System.out.println(System.currentTimeMillis() - start2 + "ms to reach: " + Hex.toHexString(BigIntegers.asUnsignedByteArray(4, counter2))); } } @Test public void firstNonZeroByte_1() { byte[] data = Hex.decode("0000000000000000000000000000000000000000000000000000000000000000"); int result = ByteUtil.firstNonZeroByte(data); assertEquals(-1, result); } @Test public void firstNonZeroByte_2() { byte[] data = Hex.decode("0000000000000000000000000000000000000000000000000000000000332211"); int result = ByteUtil.firstNonZeroByte(data); assertEquals(29, result); } @Test public void firstNonZeroByte_3() { byte[] data = Hex.decode("2211009988776655443322110099887766554433221100998877665544332211"); int result = ByteUtil.firstNonZeroByte(data); assertEquals(0, result); } @Test public void setBitTest() { /* Set on */ byte[] data = ByteBuffer.allocate(4).putInt(0).array(); int posBit = 24; int expected = 16777216; int result = -1; byte[] ret = ByteUtil.setBit(data, posBit, 1); result = ByteUtil.byteArrayToInt(ret); assertTrue(expected == result); posBit = 25; expected = 50331648; ret = ByteUtil.setBit(data, posBit, 1); result = ByteUtil.byteArrayToInt(ret); assertTrue(expected == result); posBit = 2; expected = 50331652; ret = ByteUtil.setBit(data, posBit, 1); result = ByteUtil.byteArrayToInt(ret); assertTrue(expected == result); /* Set off */ posBit = 24; expected = 33554436; ret = ByteUtil.setBit(data, posBit, 0); result = ByteUtil.byteArrayToInt(ret); assertTrue(expected == result); posBit = 25; expected = 4; ret = ByteUtil.setBit(data, posBit, 0); result = ByteUtil.byteArrayToInt(ret); assertTrue(expected == result); posBit = 2; expected = 0; ret = ByteUtil.setBit(data, posBit, 0); result = ByteUtil.byteArrayToInt(ret); assertTrue(expected == result); } @Test public void getBitTest() { byte[] data = ByteBuffer.allocate(4).putInt(0).array(); ByteUtil.setBit(data, 24, 1); ByteUtil.setBit(data, 25, 1); ByteUtil.setBit(data, 2, 1); List<Integer> found = new ArrayList<>(); for (int i = 0; i < (data.length * 8); i++) { int res = ByteUtil.getBit(data, i); if (res == 1) if (i != 24 && i != 25 && i != 2) assertTrue(false); else found.add(i); else { if (i == 24 || i == 25 || i == 2) assertTrue(false); } } if (found.size() != 3) assertTrue(false); assertTrue(found.get(0) == 2); assertTrue(found.get(1) == 24); assertTrue(found.get(2) == 25); } @Test public void numToBytesTest() { byte[] bytes = ByteUtil.intToBytesNoLeadZeroes(-1); assertArrayEquals(bytes, Hex.decode("ffffffff")); bytes = ByteUtil.intToBytesNoLeadZeroes(1); assertArrayEquals(bytes, Hex.decode("01")); bytes = ByteUtil.intToBytesNoLeadZeroes(255); assertArrayEquals(bytes, Hex.decode("ff")); bytes = ByteUtil.intToBytesNoLeadZeroes(256); assertArrayEquals(bytes, Hex.decode("0100")); bytes = ByteUtil.intToBytesNoLeadZeroes(0); assertArrayEquals(bytes, new byte[0]); bytes = ByteUtil.intToBytes(-1); assertArrayEquals(bytes, Hex.decode("ffffffff")); bytes = ByteUtil.intToBytes(1); assertArrayEquals(bytes, Hex.decode("00000001")); bytes = ByteUtil.intToBytes(255); assertArrayEquals(bytes, Hex.decode("000000ff")); bytes = ByteUtil.intToBytes(256); assertArrayEquals(bytes, Hex.decode("00000100")); bytes = ByteUtil.intToBytes(0); assertArrayEquals(bytes, Hex.decode("00000000")); bytes = ByteUtil.longToBytesNoLeadZeroes(-1); assertArrayEquals(bytes, Hex.decode("ffffffffffffffff")); bytes = ByteUtil.longToBytesNoLeadZeroes(1); assertArrayEquals(bytes, Hex.decode("01")); bytes = ByteUtil.longToBytesNoLeadZeroes(255); assertArrayEquals(bytes, Hex.decode("ff")); bytes = ByteUtil.longToBytesNoLeadZeroes(1L << 32); assertArrayEquals(bytes, Hex.decode("0100000000")); bytes = ByteUtil.longToBytesNoLeadZeroes(0); assertArrayEquals(bytes, new byte[0]); bytes = ByteUtil.longToBytes(-1); assertArrayEquals(bytes, Hex.decode("ffffffffffffffff")); bytes = ByteUtil.longToBytes(1); assertArrayEquals(bytes, Hex.decode("0000000000000001")); bytes = ByteUtil.longToBytes(255); assertArrayEquals(bytes, Hex.decode("00000000000000ff")); bytes = ByteUtil.longToBytes(256); assertArrayEquals(bytes, Hex.decode("0000000000000100")); bytes = ByteUtil.longToBytes(0); assertArrayEquals(bytes, Hex.decode("0000000000000000")); } @Test public void testHexStringToBytes() { { String str = "0000"; byte[] actuals = ByteUtil.hexStringToBytes(str); byte[] expected = new byte[] {0, 0}; assertArrayEquals(expected, actuals); } { String str = "0x0000"; byte[] actuals = ByteUtil.hexStringToBytes(str); byte[] expected = new byte[] {0, 0}; assertArrayEquals(expected, actuals); } { String str = "0x45a6"; byte[] actuals = ByteUtil.hexStringToBytes(str); byte[] expected = new byte[] {69, -90}; assertArrayEquals(expected, actuals); } { String str = "1963093cee500c081443e1045c40264b670517af"; byte[] actuals = ByteUtil.hexStringToBytes(str); byte[] expected = Hex.decode(str); assertArrayEquals(expected, actuals); } { String str = "0x"; // Empty byte[] actuals = ByteUtil.hexStringToBytes(str); byte[] expected = new byte[] {}; assertArrayEquals(expected, actuals); } { String str = "0"; // Same as 0x00 byte[] actuals = ByteUtil.hexStringToBytes(str); byte[] expected = new byte[] {0}; assertArrayEquals(expected, actuals); } { String str = "0x00"; // This case shouldn't be empty array byte[] actuals = ByteUtil.hexStringToBytes(str); byte[] expected = new byte[] {0}; assertArrayEquals(expected, actuals); } { String str = "0xd"; // Should work with odd length, adding leading 0 byte[] actuals = ByteUtil.hexStringToBytes(str); byte[] expected = new byte[] {13}; assertArrayEquals(expected, actuals); } { String str = "0xd0d"; // Should work with odd length, adding leading 0 byte[] actuals = ByteUtil.hexStringToBytes(str); byte[] expected = new byte[] {13, 13}; assertArrayEquals(expected, actuals); } } @Test public void testIpConversion() { String ip1 = "0.0.0.0"; byte[] ip1Bytes = ByteUtil.hostToBytes(ip1); assertEquals(ip1, ByteUtil.bytesToIp(ip1Bytes)); String ip2 = "35.36.37.138"; byte[] ip2Bytes = ByteUtil.hostToBytes(ip2); assertEquals(ip2, ByteUtil.bytesToIp(ip2Bytes)); String ip3 = "255.255.255.255"; byte[] ip3Bytes = ByteUtil.hostToBytes(ip3); assertEquals(ip3, ByteUtil.bytesToIp(ip3Bytes)); // Fallback case String ip4 = "255.255.255.256"; byte[] ip4Bytes = ByteUtil.hostToBytes(ip4); assertEquals("0.0.0.0", ByteUtil.bytesToIp(ip4Bytes)); } @Test public void testNumberOfLeadingZeros() { int n0 = ByteUtil.numberOfLeadingZeros(new byte[0]); assertEquals(0, n0); int n1 = ByteUtil.numberOfLeadingZeros(Hex.decode("05")); assertEquals(5, n1); int n2 = ByteUtil.numberOfLeadingZeros(Hex.decode("01")); assertEquals(7, n2); int n3 = ByteUtil.numberOfLeadingZeros(Hex.decode("00")); assertEquals(8, n3); int n4 = ByteUtil.numberOfLeadingZeros(Hex.decode("ff")); assertEquals(0, n4); byte[] v1 = Hex.decode("1040"); int n5 = ByteUtil.numberOfLeadingZeros(v1); assertEquals(3, n5); // add leading zero bytes byte[] v2 = new byte[4]; System.arraycopy(v1, 0, v2, 2, v1.length); int n6 = ByteUtil.numberOfLeadingZeros(v2); assertEquals(19, n6); byte[] v3 = new byte[8]; int n7 = ByteUtil.numberOfLeadingZeros(v3); assertEquals(64, n7); } @Test public void nullArrayToNumber() { assertEquals(BigInteger.ZERO, ByteUtil.bytesToBigInteger(null)); assertEquals(0L, ByteUtil.byteArrayToLong(null)); assertEquals(0, ByteUtil.byteArrayToInt(null)); } }
18,488
32.924771
150
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/util/BIUtilTest.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.util; import org.junit.Assert; import org.junit.Test; import java.math.BigInteger; import static org.ethereum.util.BIUtil.*; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; /** * @author Mikhail Kalinin * @since 15.10.2015 */ public class BIUtilTest { @Test public void testIsIn20PercentRange() { assertTrue(isIn20PercentRange(BigInteger.valueOf(20000), BigInteger.valueOf(24000))); assertTrue(isIn20PercentRange(BigInteger.valueOf(24000), BigInteger.valueOf(20000))); assertFalse(isIn20PercentRange(BigInteger.valueOf(20000), BigInteger.valueOf(25000))); assertTrue(isIn20PercentRange(BigInteger.valueOf(20), BigInteger.valueOf(24))); assertTrue(isIn20PercentRange(BigInteger.valueOf(24), BigInteger.valueOf(20))); assertFalse(isIn20PercentRange(BigInteger.valueOf(20), BigInteger.valueOf(25))); assertTrue(isIn20PercentRange(BigInteger.ZERO, BigInteger.ZERO)); assertFalse(isIn20PercentRange(BigInteger.ZERO, BigInteger.ONE)); assertTrue(isIn20PercentRange(BigInteger.ONE, BigInteger.ZERO)); } @Test // test isIn20PercentRange public void test1() { assertFalse(isIn20PercentRange(BigInteger.ONE, BigInteger.valueOf(5))); assertTrue(isIn20PercentRange(BigInteger.valueOf(5), BigInteger.ONE)); assertTrue(isIn20PercentRange(BigInteger.valueOf(5), BigInteger.valueOf(6))); assertFalse(isIn20PercentRange(BigInteger.valueOf(5), BigInteger.valueOf(7))); } }
2,351
35.184615
94
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/util/ValueTest.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.util; import org.junit.Test; import org.spongycastle.util.encoders.Hex; import java.math.BigInteger; import java.util.Arrays; import static org.junit.Assert.*; public class ValueTest { @Test public void testCmp() { Value val1 = new Value("hello"); Value val2 = new Value("world"); assertFalse("Expected values not to be equal", val1.cmp(val2)); Value val3 = new Value("hello"); Value val4 = new Value("hello"); assertTrue("Expected values to be equal", val3.cmp(val4)); } @Test public void testTypes() { Value str = new Value("str"); assertEquals(str.asString(), "str"); Value num = new Value(1); assertEquals(num.asInt(), 1); Value inter = new Value(new Object[]{1}); Object[] interExp = new Object[]{1}; assertTrue(new Value(inter.asObj()).cmp(new Value(interExp))); Value byt = new Value(new byte[]{1, 2, 3, 4}); byte[] bytExp = new byte[]{1, 2, 3, 4}; assertTrue(Arrays.equals(byt.asBytes(), bytExp)); Value bigInt = new Value(BigInteger.valueOf(10)); BigInteger bigExp = BigInteger.valueOf(10); assertEquals(bigInt.asBigInt(), bigExp); } @Test public void longListRLPBug_1() { String testRlp = "f7808080d387206f72726563748a626574656c676575736580d387207870726573738a70726564696361626c658080808080808080808080"; Value val = Value.fromRlpEncoded(Hex.decode(testRlp)); assertEquals(testRlp, Hex.toHexString(val.encode())); } /** * Shouldn't fail with correct TrieNode CODE data * as opposed to Value.fromRlpEncoded */ @Test public void testToString() { Value val = new Value(Hex.decode("fe")); assertEquals("fe", val.toString()); assertEquals("fe", Hex.toHexString(val.asBytes())); } }
2,686
29.534091
140
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/util/MinMaxMapTest.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.util; import org.junit.Assert; import org.junit.Test; import static org.junit.Assert.*; /** * Created by Anton Nashatyrev on 08.12.2016. */ public class MinMaxMapTest { @Test public void test1() { MinMaxMap<Integer> map = new MinMaxMap<>(); assertNull(map.getMin()); assertNull(map.getMax()); map.clearAllAfter(100); map.clearAllBefore(100); map.put(100L, 100); assertEquals(100, map.getMin().longValue()); assertEquals(100, map.getMax().longValue()); map.clearAllAfter(100); assertEquals(1, map.size()); map.clearAllBefore(100); assertEquals(1, map.size()); map.clearAllBefore(101); assertEquals(0, map.size()); map.put(100L, 100); assertEquals(1, map.size()); map.clearAllAfter(99); assertEquals(0, map.size()); map.put(100L, 100); map.put(110L, 100); map.put(90L, 100); assertEquals(90, map.getMin().longValue()); assertEquals(110, map.getMax().longValue()); map.remove(100L); assertEquals(90, map.getMin().longValue()); assertEquals(110, map.getMax().longValue()); map.remove(110L); assertEquals(90, map.getMin().longValue()); assertEquals(90, map.getMax().longValue()); } }
2,145
30.558824
80
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/util/RlpTestData.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.util; import java.math.BigInteger; public class RlpTestData { /*********************************** * https://github.com/ethereum/tests/blob/master/rlptest.txt */ public static int test01 = 0; public static String result01 = "80"; public static String test02 = ""; public static String result02 = "80"; public static String test03 = "d"; public static String result03 = "64"; public static String test04 = "cat"; public static String result04 = "83636174"; public static String test05 = "dog"; public static String result05 = "83646f67"; public static String[] test06 = new String[]{"cat", "dog"}; public static String result06 = "c88363617483646f67"; public static String[] test07 = new String[]{"dog", "god", "cat"}; public static String result07 = "cc83646f6783676f6483636174"; public static int test08 = 1; public static String result08 = "01"; public static int test09 = 10; public static String result09 = "0a"; public static int test10 = 100; public static String result10 = "64"; public static int test11 = 1000; public static String result11 = "8203e8"; public static BigInteger test12 = new BigInteger("115792089237316195423570985008687907853269984665640564039457584007913129639935"); public static String result12 = "a0ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"; public static BigInteger test13 = new BigInteger("115792089237316195423570985008687907853269984665640564039457584007913129639936"); public static String result13 = "a1010000000000000000000000000000000000000000000000000000000000000000"; public static Object[] test14 = new Object[]{1, 2, new Object[]{}}; public static String result14 = "c30102c0"; public static Object[] expected14 = new Object[]{new byte[]{1}, new byte[]{2}, new Object[]{}}; public static Object[] test15 = new Object[]{new Object[]{new Object[]{}, new Object[]{}}, new Object[]{}}; public static String result15 = "c4c2c0c0c0"; public static Object[] test16 = new Object[]{"zw", new Object[]{4}, "wz"}; public static String result16 = "c8827a77c10482777a"; public static Object[] expected16 = new Object[]{new byte[]{122, 119}, new Object[]{new byte[]{4}}, new byte[]{119, 122}}; }
3,127
39.623377
135
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/util/HashUtilTest.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.util; import org.ethereum.crypto.HashUtil; import org.junit.Test; import org.spongycastle.util.encoders.Hex; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; public class HashUtilTest { @Test public void testSha256_EmptyString() { String expected1 = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"; String result1 = Hex.toHexString(HashUtil.sha256(new byte[0])); assertEquals(expected1, result1); } @Test public void testSha256_Test() { String expected2 = "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08"; String result2 = Hex.toHexString(HashUtil.sha256("test".getBytes())); assertEquals(expected2, result2); } @Test public void testSha256_Multiple() { String expected1 = "1b4f0e9851971998e732078544c96b36c3d01cedf7caa332359d6f1d83567014"; String result1 = Hex.toHexString(HashUtil.sha256("test1".getBytes())); assertEquals(expected1, result1); String expected2 = "60303ae22b998861bce3b28f33eec1be758a213c86c93c076dbe9f558c11c752"; String result2 = Hex.toHexString(HashUtil.sha256("test2".getBytes())); assertEquals(expected2, result2); } @Test public void testSha3_EmptyString() { String expected1 = "c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"; String result1 = Hex.toHexString(HashUtil.sha3(new byte[0])); assertEquals(expected1, result1); } @Test public void testSha3_Test() { String expected2 = "9c22ff5f21f0b81b113e63f7db6da94fedef11b2119b4088b89664fb9a3cb658"; String result2 = Hex.toHexString(HashUtil.sha3("test".getBytes())); assertEquals(expected2, result2); } @Test public void testSha3_Multiple() { String expected1 = "6d255fc3390ee6b41191da315958b7d6a1e5b17904cc7683558f98acc57977b4"; String result1 = Hex.toHexString(HashUtil.sha3("test1".getBytes())); assertEquals(expected1, result1); String expected2 = "4da432f1ecd4c0ac028ebde3a3f78510a21d54087b161590a63080d33b702b8d"; String result2 = Hex.toHexString(HashUtil.sha3("test2".getBytes())); assertEquals(expected2, result2); } @Test public void testRIPEMD160_EmptyString() { String expected1 = "9c1185a5c5e9fc54612808977ee8f548b2258d31"; String result1 = Hex.toHexString(HashUtil.ripemd160(new byte[0])); assertEquals(expected1, result1); } @Test public void testRIPEMD160_Test() { String expected2 = "5e52fee47e6b070565f74372468cdc699de89107"; String result2 = Hex.toHexString(HashUtil.ripemd160("test".getBytes())); assertEquals(expected2, result2); } @Test public void testRIPEMD160_Multiple() { String expected1 = "9295fac879006ff44812e43b83b515a06c2950aa"; String result1 = Hex.toHexString(HashUtil.ripemd160("test1".getBytes())); assertEquals(expected1, result1); String expected2 = "80b85ebf641abccdd26e327c5782353137a0a0af"; String result2 = Hex.toHexString(HashUtil.ripemd160("test2".getBytes())); assertEquals(expected2, result2); } @Test public void testCalcSaltAddress() { assertArrayEquals(Hex.decode("4D1A2e2bB4F88F0250f26Ffff098B0b30B26BF38"), HashUtil.calcSaltAddr( Hex.decode("0000000000000000000000000000000000000000"), Hex.decode("00"), Hex.decode("0000000000000000000000000000000000000000000000000000000000000000"))); assertArrayEquals(Hex.decode("B928f69Bb1D91Cd65274e3c79d8986362984fDA3"), HashUtil.calcSaltAddr( Hex.decode("deadbeef00000000000000000000000000000000"), Hex.decode("00"), Hex.decode("0000000000000000000000000000000000000000000000000000000000000000"))); assertArrayEquals(Hex.decode("D04116cDd17beBE565EB2422F2497E06cC1C9833"), HashUtil.calcSaltAddr( Hex.decode("deadbeef00000000000000000000000000000000"), Hex.decode("00"), Hex.decode("000000000000000000000000feed000000000000000000000000000000000000"))); assertArrayEquals(Hex.decode("70f2b2914A2a4b783FaEFb75f459A580616Fcb5e"), HashUtil.calcSaltAddr( Hex.decode("0000000000000000000000000000000000000000"), Hex.decode("deadbeef"), Hex.decode("0000000000000000000000000000000000000000000000000000000000000000"))); assertArrayEquals(Hex.decode("60f3f640a8508fC6a86d45DF051962668E1e8AC7"), HashUtil.calcSaltAddr( Hex.decode("00000000000000000000000000000000deadbeef"), Hex.decode("deadbeef"), Hex.decode("00000000000000000000000000000000000000000000000000000000cafebabe"))); assertArrayEquals(Hex.decode("1d8bfDC5D46DC4f61D6b6115972536eBE6A8854C"), HashUtil.calcSaltAddr( Hex.decode("00000000000000000000000000000000deadbeef"), Hex.decode("deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef"), Hex.decode("00000000000000000000000000000000000000000000000000000000cafebabe"))); assertArrayEquals(Hex.decode("E33C0C7F7df4809055C3ebA6c09CFe4BaF1BD9e0"), HashUtil.calcSaltAddr( Hex.decode("0000000000000000000000000000000000000000"), Hex.decode(""), Hex.decode("0000000000000000000000000000000000000000000000000000000000000000"))); } }
6,364
43.201389
119
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/util/RLPTest.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.util; import org.ethereum.core.Transaction; import org.ethereum.crypto.HashUtil; import com.cedarsoftware.util.DeepEquals; import org.ethereum.db.ByteArrayWrapper; import org.ethereum.net.client.Capability; import org.ethereum.net.p2p.HelloMessage; import org.ethereum.net.swarm.Util; import org.junit.Assert; import org.junit.Ignore; import org.junit.Test; import org.spongycastle.util.encoders.Hex; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectOutputStream; import java.io.Serializable; import java.math.BigInteger; import java.net.InetAddress; import java.net.UnknownHostException; import java.util.*; import static org.ethereum.util.ByteUtil.byteArrayToInt; import static org.ethereum.util.ByteUtil.wrap; import static org.ethereum.util.RLP.*; import static org.junit.Assert.*; import static org.ethereum.util.RlpTestData.*; public class RLPTest { @Test public void test1() throws UnknownHostException { String peersPacket = "F8 4E 11 F8 4B C5 36 81 " + "CC 0A 29 82 76 5F B8 40 D8 D6 0C 25 80 FA 79 5C " + "FC 03 13 EF DE BA 86 9D 21 94 E7 9E 7C B2 B5 22 " + "F7 82 FF A0 39 2C BB AB 8D 1B AC 30 12 08 B1 37 " + "E0 DE 49 98 33 4F 3B CF 73 FA 11 7E F2 13 F8 74 " + "17 08 9F EA F8 4C 21 B0"; byte[] payload = Hex.decode(peersPacket); byte[] ip = decodeIP4Bytes(payload, 5); assertEquals(InetAddress.getByAddress(ip).toString(), ("/54.204.10.41")); } @Test public void test2() throws UnknownHostException { String peersPacket = "F8 4E 11 F8 4B C5 36 81 " + "CC 0A 29 82 76 5F B8 40 D8 D6 0C 25 80 FA 79 5C " + "FC 03 13 EF DE BA 86 9D 21 94 E7 9E 7C B2 B5 22 " + "F7 82 FF A0 39 2C BB AB 8D 1B AC 30 12 08 B1 37 " + "E0 DE 49 98 33 4F 3B CF 73 FA 11 7E F2 13 F8 74 " + "17 08 9F EA F8 4C 21 B0"; byte[] payload = Hex.decode(peersPacket); int oneInt = decodeInt(payload, 11); assertEquals(oneInt, 30303); } @Test public void test3() throws UnknownHostException { String peersPacket = "F8 9A 11 F8 4B C5 36 81 " + "CC 0A 29 82 76 5F B8 40 D8 D6 0C 25 80 FA 79 5C " + "FC 03 13 EF DE BA 86 9D 21 94 E7 9E 7C B2 B5 22 " + "F7 82 FF A0 39 2C BB AB 8D 1B AC 30 12 08 B1 37 " + "E0 DE 49 98 33 4F 3B CF 73 FA 11 7E F2 13 F8 74 " + "17 08 9F EA F8 4C 21 B0 F8 4A C4 36 02 0A 29 " + "82 76 5F B8 40 D8 D6 0C 25 80 FA 79 5C FC 03 13 " + "EF DE BA 86 9D 21 94 E7 9E 7C B2 B5 22 F7 82 FF " + "A0 39 2C BB AB 8D 1B AC 30 12 08 B1 37 E0 DE 49 " + "98 33 4F 3B CF 73 FA 11 7E F2 13 F8 74 17 08 9F " + "EA F8 4C 21 B0 "; byte[] payload = Hex.decode(peersPacket); int nextIndex = 5; byte[] ip = decodeIP4Bytes(payload, nextIndex); assertEquals("/54.204.10.41", InetAddress.getByAddress(ip).toString()); nextIndex = getNextElementIndex(payload, nextIndex); int port = decodeInt(payload, nextIndex); assertEquals(30303, port); nextIndex = getNextElementIndex(payload, nextIndex); BigInteger peerId = decodeBigInteger(payload, nextIndex); BigInteger expectedPeerId = new BigInteger("11356629247358725515654715129711890958861491612873043044752814241820167155109073064559464053586837011802513611263556758124445676272172838679152022396871088"); assertEquals(expectedPeerId, peerId); nextIndex = getNextElementIndex(payload, nextIndex); nextIndex = getFirstListElement(payload, nextIndex); ip = decodeIP4Bytes(payload, nextIndex); assertEquals("/54.2.10.41", InetAddress.getByAddress(ip).toString()); nextIndex = getNextElementIndex(payload, nextIndex); port = decodeInt(payload, nextIndex); assertEquals(30303, port); nextIndex = getNextElementIndex(payload, nextIndex); peerId = decodeBigInteger(payload, nextIndex); expectedPeerId = new BigInteger("11356629247358725515654715129711890958861491612873043044752814241820167155109073064559464053586837011802513611263556758124445676272172838679152022396871088"); assertEquals(expectedPeerId, peerId); nextIndex = getNextElementIndex(payload, nextIndex); nextIndex = getFirstListElement(payload, nextIndex); assertEquals(-1, nextIndex); } @Test /** encode byte */ public void test4() { byte[] expected = {(byte) 0x80}; byte[] data = encodeByte((byte) 0); assertArrayEquals(expected, data); byte[] expected2 = {(byte) 0x78}; data = encodeByte((byte) 120); assertArrayEquals(expected2, data); byte[] expected3 = {(byte) 0x7F}; data = encodeByte((byte) 127); assertArrayEquals(expected3, data); } @Test /** encode short */ public void test5() { byte[] expected = {(byte) 0x80}; byte[] data = encodeShort((byte) 0); assertArrayEquals(expected, data); byte[] expected2 = {(byte) 0x78}; data = encodeShort((byte) 120); assertArrayEquals(expected2, data); byte[] expected3 = { (byte) 0x7F}; data = encodeShort((byte) 127); assertArrayEquals(expected3, data); byte[] expected4 = {(byte) 0x82, (byte) 0x76, (byte) 0x5F}; data = encodeShort((short) 30303); assertArrayEquals(expected4, data); byte[] expected5 = {(byte) 0x82, (byte) 0x4E, (byte) 0xEA}; data = encodeShort((short) 20202); assertArrayEquals(expected5, data); } @Test /** encode int */ public void testEncodeInt() { byte[] expected = {(byte) 0x80}; byte[] data = encodeInt(0); assertArrayEquals(expected, data); assertEquals(0, RLP.decodeInt(data, 0)); byte[] expected2 = {(byte) 0x78}; data = encodeInt(120); assertArrayEquals(expected2, data); assertEquals(120, RLP.decodeInt(data, 0)); byte[] expected3 = {(byte) 0x7F}; data = encodeInt(127); assertArrayEquals(expected3, data); assertEquals(127, RLP.decodeInt(data, 0)); assertEquals(256, RLP.decodeInt(RLP.encodeInt(256), 0)); assertEquals(255, RLP.decodeInt(RLP.encodeInt(255), 0)); assertEquals(127, RLP.decodeInt(RLP.encodeInt(127), 0)); assertEquals(128, RLP.decodeInt(RLP.encodeInt(128), 0)); data = RLP.encodeInt(1024); assertEquals(1024, RLP.decodeInt(data, 0)); byte[] expected4 = {(byte) 0x82, (byte) 0x76, (byte) 0x5F}; data = encodeInt(30303); assertArrayEquals(expected4, data); assertEquals(30303, RLP.decodeInt(data, 0)); byte[] expected5 = {(byte) 0x82, (byte) 0x4E, (byte) 0xEA}; data = encodeInt(20202); assertArrayEquals(expected5, data); assertEquals(20202, RLP.decodeInt(data, 0)); byte[] expected6 = {(byte) 0x83, 1, 0, 0}; data = encodeInt(65536); assertArrayEquals(expected6, data); assertEquals(65536, RLP.decodeInt(data, 0)); byte[] expected8 = {(byte) 0x84, (byte) 0x7F, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF}; data = encodeInt(Integer.MAX_VALUE); assertArrayEquals(expected8, data); assertEquals(Integer.MAX_VALUE, RLP.decodeInt(data, 0)); } @Test(expected = RuntimeException.class) public void incorrectZero() { RLP.decodeInt(new byte[]{0x00}, 0); } /** * NOTE: While negative numbers are not used in RLP, we usually use RLP * for encoding all data and sometime use -1 in primitive fields as null. * So, currently negative numbers encoding is allowed */ @Ignore @Test(expected = RuntimeException.class) public void cannotEncodeNegativeNumbers() { encodeInt(Integer.MIN_VALUE); } @Test public void testMaxNumerics() { int expected1 = Integer.MAX_VALUE; assertEquals(expected1, decodeInt(encodeInt(expected1), 0)); short expected2 = Short.MAX_VALUE; assertEquals(expected2, decodeShort(encodeShort(expected2), 0)); long expected3 = Long.MAX_VALUE; assertEquals(expected3, decodeLong(encodeBigInteger(BigInteger.valueOf(expected3)), 0)); } @Test /** encode BigInteger */ public void test6() { byte[] expected = new byte[]{(byte) 0x80}; byte[] data = encodeBigInteger(BigInteger.ZERO); assertArrayEquals(expected, data); } @Test /** encode string */ public void test7() { byte[] data = encodeString(""); assertArrayEquals(new byte[]{(byte) 0x80}, data); byte[] expected = {(byte) 0x90, (byte) 0x45, (byte) 0x74, (byte) 0x68, (byte) 0x65, (byte) 0x72, (byte) 0x65, (byte) 0x75, (byte) 0x6D, (byte) 0x4A, (byte) 0x20, (byte) 0x43, (byte) 0x6C, (byte) 0x69, (byte) 0x65, (byte) 0x6E, (byte) 0x74}; String test = "EthereumJ Client"; data = encodeString(test); assertArrayEquals(expected, data); String test2 = "Ethereum(++)/ZeroGox/v0.5.0/ncurses/Linux/g++"; byte[] expected2 = {(byte) 0xAD, (byte) 0x45, (byte) 0x74, (byte) 0x68, (byte) 0x65, (byte) 0x72, (byte) 0x65, (byte) 0x75, (byte) 0x6D, (byte) 0x28, (byte) 0x2B, (byte) 0x2B, (byte) 0x29, (byte) 0x2F, (byte) 0x5A, (byte) 0x65, (byte) 0x72, (byte) 0x6F, (byte) 0x47, (byte) 0x6F, (byte) 0x78, (byte) 0x2F, (byte) 0x76, (byte) 0x30, (byte) 0x2E, (byte) 0x35, (byte) 0x2E, (byte) 0x30, (byte) 0x2F, (byte) 0x6E, (byte) 0x63, (byte) 0x75, (byte) 0x72, (byte) 0x73, (byte) 0x65, (byte) 0x73, (byte) 0x2F, (byte) 0x4C, (byte) 0x69, (byte) 0x6E, (byte) 0x75, (byte) 0x78, (byte) 0x2F, (byte) 0x67, (byte) 0x2B, (byte) 0x2B}; data = encodeString(test2); assertArrayEquals(expected2, data); String test3 = "Ethereum(++)/ZeroGox/v0.5.0/ncurses/Linux/g++Ethereum(++)/ZeroGox/v0.5.0/ncurses/Linux/g++"; byte[] expected3 = {(byte) 0xB8, (byte) 0x5A, (byte) 0x45, (byte) 0x74, (byte) 0x68, (byte) 0x65, (byte) 0x72, (byte) 0x65, (byte) 0x75, (byte) 0x6D, (byte) 0x28, (byte) 0x2B, (byte) 0x2B, (byte) 0x29, (byte) 0x2F, (byte) 0x5A, (byte) 0x65, (byte) 0x72, (byte) 0x6F, (byte) 0x47, (byte) 0x6F, (byte) 0x78, (byte) 0x2F, (byte) 0x76, (byte) 0x30, (byte) 0x2E, (byte) 0x35, (byte) 0x2E, (byte) 0x30, (byte) 0x2F, (byte) 0x6E, (byte) 0x63, (byte) 0x75, (byte) 0x72, (byte) 0x73, (byte) 0x65, (byte) 0x73, (byte) 0x2F, (byte) 0x4C, (byte) 0x69, (byte) 0x6E, (byte) 0x75, (byte) 0x78, (byte) 0x2F, (byte) 0x67, (byte) 0x2B, (byte) 0x2B, (byte) 0x45, (byte) 0x74, (byte) 0x68, (byte) 0x65, (byte) 0x72, (byte) 0x65, (byte) 0x75, (byte) 0x6D, (byte) 0x28, (byte) 0x2B, (byte) 0x2B, (byte) 0x29, (byte) 0x2F, (byte) 0x5A, (byte) 0x65, (byte) 0x72, (byte) 0x6F, (byte) 0x47, (byte) 0x6F, (byte) 0x78, (byte) 0x2F, (byte) 0x76, (byte) 0x30, (byte) 0x2E, (byte) 0x35, (byte) 0x2E, (byte) 0x30, (byte) 0x2F, (byte) 0x6E, (byte) 0x63, (byte) 0x75, (byte) 0x72, (byte) 0x73, (byte) 0x65, (byte) 0x73, (byte) 0x2F, (byte) 0x4C, (byte) 0x69, (byte) 0x6E, (byte) 0x75, (byte) 0x78, (byte) 0x2F, (byte) 0x67, (byte) 0x2B, (byte) 0x2B}; data = encodeString(test3); assertArrayEquals(expected3, data); } @Test /** encode byte array */ public void test8() { String byteArr = "ce73660a06626c1b3fda7b18ef7ba3ce17b6bf604f9541d3c6c654b7ae88b239" + "407f659c78f419025d785727ed017b6add21952d7e12007373e321dbc31824ba"; byte[] byteArray = Hex.decode(byteArr); String expected = "b840" + byteArr; assertEquals(expected, Hex.toHexString(encodeElement(byteArray))); } @Test /** encode list */ public void test9() { byte[] actuals = encodeList(); assertArrayEquals(new byte[]{(byte) 0xc0}, actuals); } @Test /** encode null value */ public void testEncodeElementNull() { byte[] actuals = encodeElement(null); assertArrayEquals(new byte[]{(byte) 0x80}, actuals); } @Test /** encode single byte 0x00 */ public void testEncodeElementZero() { byte[] actuals = encodeElement(new byte[]{0x00}); assertArrayEquals(new byte[]{0x00}, actuals); } @Test /** encode single byte 0x01 */ public void testEncodeElementOne() { byte[] actuals = encodeElement(new byte[]{0x01}); assertArrayEquals(new byte[]{(byte) 0x01}, actuals); } @Test /** found bug encode list affects element value, hhh... not really at the end but keep the test */ public void test10() { /* 2 */ byte[] prevHash = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; prevHash = encodeElement(prevHash); /* 2 */ byte[] uncleList = HashUtil.sha3(encodeList(new byte[]{})); /* 3 */ byte[] coinbase = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; coinbase = encodeElement(coinbase); byte[] header = encodeList( prevHash, uncleList, coinbase); assertEquals("f856a000000000000000000000000000000000000000000000000000000000000000001dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347940000000000000000000000000000000000000000", Hex.toHexString(header)); } @Test public void test11() { // 2240089100000070 String tx = "F86E12F86B80881BC16D674EC8000094CD2A3D9F938E13CD947EC05ABC7FE734DF8DD8268609184E72A00064801BA0C52C114D4F5A3BA904A9B3036E5E118FE0DBB987FE3955DA20F2CD8F6C21AB9CA06BA4C2874299A55AD947DBC98A25EE895AABF6B625C26C435E84BFD70EDF2F69"; byte[] payload = Hex.decode(tx); RLPList rlpList = new RLPList(); fullTraverse(payload, 0, 0, payload.length, rlpList, Integer.MAX_VALUE); assertEquals(18, ByteUtil.byteArrayToInt(((RLPList) rlpList.get(0)).get(0).getRLPData())); assertEquals(9, ((RLPList) (((RLPList) rlpList.get(0)).get(1))).size()); } @Test public void test12() { String tx = "F86E12F86B80881BC16D674EC8000094CD2A3D9F938E13CD947EC05ABC7FE734DF8DD8268609184E72A00064801BA0C52C114D4F5A3BA904A9B3036E5E118FE0DBB987FE3955DA20F2CD8F6C21AB9CA06BA4C2874299A55AD947DBC98A25EE895AABF6B625C26C435E84BFD70EDF2F69"; byte[] payload = Hex.decode(tx); RLPList rlpList = decode2(payload); RLPList.recursivePrint(rlpList); // TODO: add some asserts in place of just printing the rlpList } @Test /* very long peers msg */ public void test13() { String peers = "f9 14 90 11 f8 4c c6 81 83 68 81 fc 04 82 76 5f b8 40 07 7e 53 7a 8b 36 73 e8 f1 b6 25 db cc " + "90 2e a7 d4 ce d9 40 2e 46 64 e8 73 67 95 12 cc 23 60 69 8e 53 42 56 52 a0 46 24 fc f7 8c db a1 a3 " + "23 30 87 a9 19 a3 4d 11 ae da ce ee b7 d8 33 fc bf 26 f8 4c c6 63 81 e7 58 81 af 82 76 5f b8 40 0a " + "b2 cd e8 3a 09 84 03 dd c2 ea 54 14 74 0d 8a 01 93 e4 49 c9 6e 11 24 19 96 7a bc 62 eb 17 cd ce d7 " + "7a e0 ab 07 5e 04 f7 dd dc d4 3f b9 04 8b e5 32 06 a0 40 62 0b de 26 cb 74 3f a3 12 31 9f f8 4d c7 " + "81 cf 81 db 45 81 9a 82 76 5f b8 40 19 c3 3d a7 03 1c ff 17 7e fa 84 2f aa 3d 31 bd 83 e1 76 4e c6 " + "10 f2 36 94 4a 9f 8a 21 c1 c5 1a 04 f4 7f 6b 5f c3 ef e6 5c af 36 94 43 63 5a fc 58 d8 f5 d4 e2 f1 " + "2a f9 ee ec 3c 6e 30 bf 0a 2b f8 4c c6 44 30 81 ad 81 a3 82 76 5f b8 40 1e 59 c2 82 08 12 94 80 84 " + "97 ae 7a 7e 97 67 98 c4 2b 8b cc e1 3c 9d 8b 0e cf 8a fe cd b5 df d4 ef a8 77 0f c0 d1 f7 de 63 c9 " + "16 40 e7 e8 b4 35 8c 9e 3e d0 f3 d6 c9 86 20 ad 7e a4 24 18 c9 ec f8 4b c5 1f 12 81 9e 48 82 76 5f " + "b8 40 1f 68 c0 75 c1 d8 7b c0 47 65 43 0f df b1 e5 d0 0f 1b 78 4e d6 be 72 1e 4c af f7 be b5 7b 4b " + "21 7b 95 da 19 b5 ec 66 04 58 68 b3 9a ac 2e 08 76 cf 80 f0 b6 8d 0f a2 0b db 90 36 be aa 70 61 ea " + "f8 4c c6 81 bf 81 ea 39 37 82 76 5f b8 40 21 78 0c 55 b4 7d b4 b1 14 67 b5 f5 5b 0b 55 5e 08 87 ce " + "36 fb d9 75 e2 24 b1 c7 0e ac 7a b8 e8 c2 db 37 f0 a4 8b 90 ff dd 5a 37 9a da 99 b6 a0 f6 42 9c 4a " + "53 c2 55 58 19 1a 68 26 36 ae f4 f2 f8 4c c6 44 30 81 ad 81 a3 82 76 5f b8 40 23 15 cb 7c f4 9b 8e " + "ab 21 2c 5a 45 79 0b 50 79 77 39 73 8f 5f 73 34 39 b1 90 11 97 37 ee 8c 09 bc 72 37 94 71 2a a8 2f " + "26 70 bc 58 1a b0 75 7e f2 31 37 ac 0f df 0f 8c 89 65 e7 dd 6b a7 9f 8c f8 4e c8 81 bf 81 b1 81 d1 " + "81 9f 82 76 5f b8 40 24 9a 36 41 e5 a8 d0 8e 41 a5 cf c8 da e1 1f 17 61 25 4f 4f d4 7d 9b 13 33 8d " + "b8 e6 e3 72 9e 6f 2a c9 ec 09 7a 5c 80 96 84 d6 2a 41 e6 df c2 ff f7 2d c3 db d9 7e a2 61 32 bb 97 " + "64 05 65 bb 0c f8 4a c4 55 41 7e 2d 82 76 5f b8 40 2a 38 ea 5d 9a 7e fd 7f ff c0 a8 1d 8e a7 ed 28 " + "31 1c 40 12 bb ab 14 07 c8 da d2 68 51 29 e0 42 17 27 34 a3 28 e8 90 7f 90 54 b8 22 5f e7 70 41 d8 " + "a4 86 a9 79 76 d2 83 72 42 ab 6c 8c 59 05 e4 f8 4c c6 81 83 68 81 fc 04 82 76 5f b8 40 32 4d d9 36 " + "38 4d 8c 0d de fd e0 4b a7 40 29 98 ab bd 63 d7 9c 0b f8 58 6b 3d d2 c7 db f6 c9 1e b8 0a 7b 6d e8 " + "f1 6a 50 04 4f 14 9c 7b 39 aa fb 9c 3a d7 f2 ca a4 03 55 aa b0 98 88 18 6f cc a2 f8 4c c6 44 30 81 " + "ad 81 a3 82 76 5f b8 40 39 42 45 c0 99 16 33 ed 06 0b af b9 64 68 53 d3 44 18 8b 80 4f e3 7e 25 a5 " + "bc ac 44 ed 44 3a 84 a6 8b 3a af 15 5e fe 48 61 e8 4b 4b 51 5f 9a 5d ec db d7 da e9 81 92 d7 a3 20 " + "a7 92 c7 d4 df af f8 4d c7 56 81 b7 81 e7 81 cd 82 76 5f b8 40 39 86 50 f6 7b 22 92 93 9d e3 4c 0e " + "ae b9 14 1f 94 84 a0 fb 17 3f a3 3f 81 a1 f7 31 5d 0e b7 7b de 3a 76 c3 86 36 fa e6 6f a1 4b f2 af " + "df d6 3e 60 ab d4 0e 29 b0 2a 91 4e 65 de 57 89 98 3f d4 f8 4c c6 44 81 b9 81 ea 40 82 76 5f b8 40 " + "3a 15 58 7a 1c 3a da bf 02 91 b3 07 f7 1b 2c 04 d1 98 aa e3 6b 83 49 95 d3 30 5d ff 42 f1 ab 86 f4 " + "83 ae 12 9e 92 03 fb c6 ef 21 87 c8 62 1e dd 18 f6 1d 53 ea a5 b5 87 ff de a4 d9 26 48 90 38 f8 4d " + "c7 81 cf 81 db 45 81 9a 82 76 5f b8 40 3b 14 62 04 0e a7 78 e3 f7 5e 65 ce 24 53 41 8a 66 2e 62 12 " + "c9 f6 5b 02 ea b5 8d 22 b2 87 e4 50 53 bd e5 eb f0 60 96 0c bf a0 d9 dc 85 bf 51 ba 7a a1 f2 ca a2 " + "c1 36 82 d9 32 77 64 1d 60 db eb f8 4c c6 6a 81 a8 0e 81 f9 82 76 5f b8 40 3e cc 97 ab 15 d2 2f 7b " + "9e df 19 c0 4c e3 b6 09 5f a2 50 42 14 00 2b 35 98 9c 6f 81 ee 4b 96 1c c2 a8 99 c4 94 15 c9 14 e3 " + "13 90 83 40 04 7d 1d 3b 25 d7 4f 5b 9c 85 a0 6a fa 26 59 a5 39 99 2e f8 4b c5 2e 04 81 c1 09 82 76 " + "5f b8 40 40 7c 22 00 3f 3b ba a6 cb eb 8e 4b 0a b7 07 30 73 fe ab 85 18 2b 40 55 25 f8 bd 28 32 55 " + "04 3d 71 35 18 f7 47 48 d9 2c 43 fb b9 9e cc 7c 3f ba b9 5d 59 80 06 51 3a a8 e5 9c 48 04 1c 8b 41 " + "c2 f8 4b c5 32 7e 56 81 c2 82 76 5f b8 40 40 8c 93 24 20 3b d8 26 2f ce 65 06 ba 59 dc dd 56 70 89 " + "b0 eb 9a 5b b1 83 47 7b ab bf 61 63 91 4a cd c7 f4 95 f8 96 4d 8a c1 2f e2 40 18 87 b8 cd 8d 97 c0 " + "c9 dc cf ad db b2 0a 3c 31 47 a7 89 f8 4a c4 26 6c 4f 68 82 76 5f b8 40 42 3e 40 04 da 2f a7 50 0b " + "c0 12 c0 67 4a a6 57 15 02 c5 3a a4 d9 1e fa 6e 2b 5c b1 e4 68 c4 62 ca 31 14 a2 e2 eb 09 65 b7 04 " + "4f 9c 95 75 96 5b 47 e4 7a 41 f1 3f 1a dc 03 a2 a4 b3 42 d7 12 8d f8 4b c5 40 81 e7 08 2d 82 76 5f " + "b8 40 42 83 93 75 27 2c 2f 3d ea db 28 08 5d 06 05 5e 35 31 35 c6 c8 d8 96 09 7a 1b c4 80 c4 88 4f " + "d1 60 45 18 cb df 73 1a c1 8f 09 84 b7 f0 21 48 e8 82 90 d1 3c 22 4d 82 46 43 14 e2 b5 96 2e 3f 89 " + "f8 4d c7 32 81 aa 81 d8 81 c8 82 76 5f b8 40 44 cf 19 44 6c a4 65 01 8e 4d e6 c6 0f c0 df 52 9e ba " + "25 02 92 ef 74 41 e1 db 59 84 1c 69 f0 22 f6 09 28 10 c9 a5 a7 f2 74 f2 f9 7c 4b d6 c7 6e ad c0 64 " + "c7 d6 59 7c ae b1 7e d8 7c b2 57 73 5f f8 4b c5 32 81 9c 5a 53 82 76 5f b8 40 46 1c 9b 54 e9 19 53 " + "c5 bb c3 1c 67 12 a9 17 38 2b e6 7d 60 f7 5e b7 f5 06 51 be a3 e5 94 d0 d1 9c 22 29 d8 f6 6a db 3f " + "20 3f 60 00 38 e7 cc 93 4d c9 27 87 fa c4 39 2b 9b fa 7c bc 78 6f d0 5b f8 4b c5 81 86 64 7d 29 82 " + "76 5f b8 40 48 35 3a 00 58 e2 64 48 d9 4e 59 33 6c ca 9d 28 a9 37 41 20 de f7 6c 4b cc fe e1 8b 01 " + "23 e5 91 92 39 3a 2e e3 04 4d 80 e0 ee cb b0 94 76 be 62 fd e1 e8 74 f9 3d 05 ea 5c 4a 9a 45 c0 6e " + "8f e1 f8 4b c5 4e 08 05 81 bb 82 76 5f b8 40 48 e8 95 09 49 d4 c0 0b cd bb e9 39 c5 bf 07 8f 2c bf " + "f1 08 84 af 16 60 b1 c3 22 b9 ca a3 ba 35 7b b4 15 7f c6 b0 03 9a f9 43 8d fe 51 ec 27 8a 47 fc d3 " + "b7 26 fa 0a 08 7d 4c 3c 01 a6 2f 33 5e f8 4a c6 58 45 81 c6 81 c6 07 b8 40 4a 02 55 fa 46 73 fa a3 " + "0f c5 ab fd 3c 55 0b fd bc 0d 3c 97 3d 35 f7 26 46 3a f8 1c 54 a0 32 81 cf ff 22 c5 f5 96 5b 38 ac " + "63 01 52 98 77 57 a3 17 82 47 85 49 c3 6f 7c 84 cb 44 36 ba 79 d6 d9 f8 4b c5 40 81 e7 08 2d 82 76 " + "5f b8 40 4c 75 47 ab 4d 54 1e 10 16 4c d3 74 1f 34 76 ed 19 4b 0a b9 a1 36 df ca c3 94 3f 97 35 8c " + "9b 05 14 14 27 36 ca 2f 17 0f 12 52 29 05 7b 47 32 44 a6 23 0b f5 47 1a d1 68 18 85 24 b2 b5 cd 8b " + "7b f8 4c c6 44 30 81 ad 81 a3 82 76 5f b8 40 4d 5e 48 75 d6 0e b4 ee af b6 b2 a7 d3 93 6e d3 c9 bc " + "58 ac aa de 6a 7f 3c 5f 25 59 8c 20 b3 64 f1 2b ea 2f b1 db 3b 2c 2e f6 47 85 a4 7d 6b 6b 5b 10 34 " + "27 cb ac 0c 88 b1 8f e9 2a 9f 53 93 f8 f8 4b c5 52 0c 81 e3 54 82 76 5f b8 40 4f d8 98 62 75 74 d3 " + "e8 6b 3f 5a 65 c3 ed c2 e5 da 84 53 59 26 e4 a2 88 20 b0 03 8b 19 63 6e 07 db 5e b0 04 d7 91 f8 04 " + "1a 00 6e 33 e1 08 e4 ec 53 54 99 d1 28 d8 d9 c5 ca f6 bb dc 22 04 f7 6a f8 4b c5 81 b4 20 2b 08 82 " + "76 5f b8 40 53 cc f2 5a b5 94 09 ec bb 90 3d 2e c3 a9 aa 2e b3 9d 7c c4 c7 db 7e 6f 68 fd 71 1a 7c " + "eb c6 06 21 6d e7 37 82 6d a4 20 93 e3 e6 52 1e e4 77 0e b2 d6 69 dc 4b f3 54 6c c7 57 c3 40 12 69 " + "6e ae f8 4c c6 6a 81 a8 0e 81 f9 82 76 5f b8 40 54 b3 93 15 69 91 39 87 80 50 2f a8 f4 14 13 79 bc " + "e2 69 31 be 87 ba 8e 0b 74 9b a9 05 a9 e9 76 e5 de 6d 39 c9 8c f0 48 f2 5c 3c bb b8 c7 f3 02 c4 e6 " + "04 ad 5b f7 2c db 06 10 0f 50 0d e3 a6 86 f8 4a c4 4c 67 37 47 82 76 5f b8 40 60 0a 77 fb 14 e7 92 " + "c0 c7 0d c4 ad e3 82 ed 60 43 62 b9 78 b1 9b 94 c4 ed 18 83 38 a1 79 5d 2d b4 5f 7f 22 3b 66 ba eb " + "a3 91 c5 9b 55 88 b4 4e ba f7 1c 7e b3 97 55 c2 72 29 c7 fd e6 41 be ce f8 4b c5 6d 2b 81 9a 42 82 " + "76 5f b8 40 69 dd 44 5f 67 c3 be f3 94 f9 54 9f da e1 62 3d bc 20 88 4a 62 fd 56 16 dd bb 49 f8 4b " + "a8 7e 14 7c b8 a5 0b a9 71 d7 30 c4 62 1d 0e b6 51 33 49 4e 94 fa 5e a2 e6 9c 66 1f 6b 12 e7 ed 2a " + "8d 4e f8 4b c5 18 09 3d 81 9b 82 76 5f b8 40 6b 5d 4c 35 ff d1 f5 a1 98 03 8a 90 83 4d 29 a1 b8 8b " + "e0 d5 ef ca 08 bc 8a 2d 58 81 18 0b 0b 41 6b e0 06 29 aa be 45 0a 50 82 8b 8d 1e e8 2d 98 f5 52 81 " + "87 ee 67 ed 6e 07 3b ce ef cd fb 2b c9 f8 4a c4 55 41 7e 2d 82 76 5f b8 40 6c bb 1e d5 36 dc 38 58 " + "c1 f0 63 42 9b d3 95 2a 5d 32 ef 8e 11 52 6c df e7 2f 41 fe a1 ac e9 60 18 7c 99 75 ab bc 23 78 35 " + "11 c0 0f 26 98 35 47 47 f9 05 aa ac 11 dc d2 b7 47 8b 3e af 32 7a c6 f8 4b c5 40 81 e7 08 2d 82 76 " + "5f b8 40 6e a2 8f 64 ea 1c c3 b6 57 25 44 fd 5b f7 43 b0 ea ab e0 17 f5 14 73 0c 89 7d a3 c7 7f 03 " + "c5 16 f1 e5 f3 1d 79 3b 4b ce 3c aa 1d ed 56 35 6d 20 b2 eb b5 5a 70 66 f4 1c 25 b7 c3 d5 66 14 e0 " + "6b f8 4a c4 55 41 7e 2d 82 76 5f b8 40 72 53 24 08 e8 be 6d 5e 2c 9f 65 0f b9 c9 f9 96 50 cc 1f a0 " + "62 a4 a4 f2 cf e4 e6 ae 69 cd d2 e8 b2 3e d1 4a fe 66 95 5c 23 fa 04 8f 3a 97 6e 3c e8 16 9e 50 5b " + "6a 89 cc 53 d4 fa c2 0c 2a 11 bf f8 4c c6 52 81 d9 48 81 a9 82 76 5f b8 40 7a ee a4 33 60 b9 36 8b " + "30 e7 f4 82 86 61 3f d1 e3 b0 20 7f b7 1f 03 08 d5 04 12 11 44 63 e7 7a b8 30 27 c0 d4 0c ad aa b8 " + "bb f6 12 fc 5b 69 67 fa 1c 40 73 29 d4 7e c6 1f b0 dc 3d a1 08 68 32 f8 4c c6 81 a6 81 93 53 4f 82 " + "76 5f b8 40 7b 3c dd e0 58 d5 b4 5d 8d b2 24 36 60 cf ea 02 e0 74 ec 21 31 14 c2 51 d7 c0 c3 2d 04 " + "03 bb 7a b4 77 13 d2 49 2f f6 c8 81 cf c2 aa c3 f5 2c b2 69 76 8c 89 68 f3 b6 b1 8b ac 97 22 d0 53 " + "31 f6 f8 4c c6 6a 81 a8 0e 81 f9 82 76 5f b8 40 87 ab 58 1b b9 7c 21 2a 2d a7 ef 0d 6e 10 5e 41 b5 " + "5e 4e 42 cb b6 a1 af 9a 76 1a 01 ca 8c 65 06 9a b4 b5 82 7e 32 2c f2 c5 f5 9e 7f 59 2b e2 a8 17 c4 " + "5a b6 41 f5 a9 dd 36 89 63 c7 3f 9e e6 88 f8 4c c6 52 81 d9 48 81 a9 82 76 5f b8 40 8c 66 0d bc 6d " + "3d b0 18 6a d1 0f 05 fd 4f 2f 06 43 77 8e c5 14 e8 45 2a 75 50 c6 30 da 21 17 1a 29 b1 bb 67 c2 e8 " + "e1 01 ea 1d b3 97 43 f3 e7 8c 4d 26 76 a1 3d 15 51 51 21 51 5f c3 8b 04 8f 37 f8 4c c6 63 81 e7 58 " + "81 af 82 76 5f b8 40 94 fe 3d 52 a2 89 4c ed c6 b1 54 24 15 6e b8 73 8a 84 41 dd 74 ba 9c ed 66 64 " + "ed 30 a3 32 a9 5b 57 4d 89 26 2e a3 67 fa 90 0a e9 70 6f b8 1a 40 82 87 bd de f3 a9 dd 9f f4 4e 3a " + "41 bc 09 0f dc f8 4d c7 81 d5 81 81 81 e6 0a 82 76 5f b8 40 95 21 14 f1 10 e8 ac 00 df ea 5f 05 0d " + "95 5e 76 4c 7c ba 8f b2 07 c0 5a 7a a5 ae 84 91 68 64 0a 2b 4e 31 43 91 fc 3a 76 79 5b 38 27 05 54 " + "62 63 9c ff 4a e2 d6 4a b8 0e 95 27 44 28 31 3e 36 6a f8 4c c6 58 45 81 c6 81 c6 82 76 5f b8 40 96 " + "f3 47 b0 96 ed 16 30 f4 74 b9 76 23 e4 5e 8d 47 1b 1d 43 c2 2f 59 96 07 c8 b2 e3 ed 0d 7b 79 05 d8 " + "55 4a d3 99 db d7 39 c7 61 26 40 44 24 d8 db 0d c7 d2 b0 47 c1 a3 28 ae 27 d4 09 06 c5 83 f8 4c c6 " + "81 83 68 81 fc 04 82 76 5f b8 40 9a 22 c8 fb 1b d8 bb d0 2f 0e 74 ed 9d 3d 55 b0 f5 b0 96 72 bc 43 " + "a2 d4 7b 1e d0 42 38 c1 c3 2b 6a 65 74 26 52 5b 15 51 82 36 e9 78 9b 54 6a 4a 07 2a 60 5e 13 73 fe " + "5b 99 6b ae dc 30 35 94 28 f8 4b c5 52 0c 81 e3 54 82 76 5f b8 40 9b 1a 3a 8d 77 1b 3d 94 9c a3 94 " + "a8 8e b5 dc 29 a9 53 b0 2c 81 f0 17 36 1f fc 0a fe 09 ab ce 30 69 17 1a 87 d4 74 52 36 87 fc c9 a9 " + "d3 2c c0 2c fa b4 13 22 56 fe aa bf e0 5f 7a c7 47 19 4e 88 f8 4b c5 42 81 d7 78 1c 82 76 5f b8 40 " + "9f a7 e5 5b 2d 98 f1 d7 44 c7 62 32 e4 fd a2 42 fe 9f d3 d5 74 3d 16 d3 ca d2 e5 48 a0 7c b5 af 06 " + "fe 60 eb ae b8 c6 09 50 28 17 92 34 dc dd d3 cd cf 1f cf e6 ed aa 2a 53 30 7f d1 03 da 4a f0 f8 4a " + "c4 55 41 7e 2d 82 76 5f b8 40 a0 1f 83 4e 9d 1a 61 3c 3c 74 7e 56 1c ac 19 cb 12 d8 79 c1 a5 74 20 " + "a4 9c 23 65 2b 8f 51 28 8c 8b 11 1a a3 88 89 98 b0 5e 32 7f 47 a2 35 c6 a4 a3 77 f8 88 e3 00 5a 2d " + "4b 03 ec b7 26 86 08 d3 f8 4c c6 44 30 81 ad 81 a3 82 7a 51 b8 40 a5 fd 77 c0 d4 32 fb fa 33 17 08 " + "49 14 c2 e8 a8 82 1e 4b a1 dc ba 44 96 1f f7 48 0e 6d b6 08 78 9c ab 62 91 41 63 60 ea 8c dc 26 b0 " + "d2 f0 87 7c 50 e8 9a 70 c1 bc f5 d6 dd 8b 18 2e 0a 9e 37 d3 f8 4d c7 81 88 81 a0 81 98 31 82 76 5f " + "b8 40 ae 31 bd 02 54 ee 7d 10 b8 0f c9 0e 74 ba 06 ba 76 11 87 df 31 38 a9 79 9d e5 82 8d 01 63 52 " + "4c 44 ba c7 d2 a9 b5 c4 1b e5 be 82 89 a1 72 36 1f 0b a9 04 10 c9 4f 57 9b f7 eb d2 8f 18 aa a1 cd " + "f8 4a c4 55 41 7e 2d 82 76 5f b8 40 ba 3d 21 67 72 cd c7 45 58 d2 54 56 24 a2 d6 2d cb cf d2 72 30 " + "57 30 c7 46 43 c7 a7 e8 19 af a6 cd d8 22 23 e2 b5 50 1e b6 d4 ea e5 db f2 1e 55 8c 76 8a ca ec 2c " + "1c a1 0e 74 c4 c8 7a 57 4b 53 f8 4a c4 55 41 7e 2d 82 76 5f b8 40 bd b4 9c 01 87 2d 91 bd 1e a9 90 " + "bd 2e df 16 c4 81 71 a6 06 7f 9a 6f 7f 48 bf b1 94 63 0b 5a e9 03 1b 5d c2 63 f5 9c 66 ad a4 44 cb " + "4e 6f 9d f6 2b 30 17 ce 61 2c ab 7b 53 da 08 d3 56 f7 8d 30 f8 4c c6 63 81 e7 58 81 af 82 76 5f b8 " + "40 c1 2b a9 1f 95 04 4d 78 ee d1 d3 a9 53 5e bd 64 71 52 44 18 13 5e eb 46 ad 5d 5c 6e cc 2f 51 68 " + "b4 ab 3a 06 2b b0 74 2a ea 65 ff ea 76 7f ab 8d cc 21 78 3c b2 9b f3 2e 2c d6 22 22 09 fa 71 fd f8 " + "4c c6 44 30 81 ad 81 a3 82 7a 51 b8 40 c2 e2 69 e6 4a a8 c9 be 2d 41 81 2a 48 af a2 34 6b d4 1a 1a " + "b2 e4 64 62 41 ae 3b 8d 0c cd 41 f2 d6 82 b1 5a 02 5f 75 9c 0d 95 5a 60 71 d4 e8 ea 7d 4d e3 97 d6 " + "e0 52 23 09 20 11 3b 6e b7 4c 09 f8 4a c4 4a 4f 17 77 82 76 5f b8 40 c3 03 b8 3f 6a 16 1f 99 67 36 " + "34 44 80 ae 9d 88 fd c1 d9 c6 75 bf ac a8 88 f7 0f 24 89 72 65 62 82 09 da 53 74 1e 03 c0 f6 59 21 " + "f6 8f 60 2d c9 f3 34 a3 c4 5b cb 92 af 85 44 a6 fb 11 9b d8 87 f8 4b c5 0c 81 fa 61 1a 82 76 5f b8 " + "40 c7 6e 7c 15 7b 77 35 51 11 53 d1 f9 50 81 a1 44 e0 88 a9 89 17 1f 3d 43 2c c5 d8 29 3e ce 9c fa " + "a4 83 c0 32 15 5d 7b 53 65 6a 6e 33 a3 d7 5c d0 62 4e 09 a2 f9 49 c1 56 09 3d ba a8 3f 11 11 f2 f8 " + "4b c5 52 0c 81 e3 54 82 76 5f b8 40 c7 d5 a3 69 1a 59 59 9d e3 33 48 9c bf 8a 47 a7 43 3e 92 c7 27 " + "06 e1 3d 94 ed 21 12 96 d3 5c 97 d8 35 7d 7e 07 b3 85 85 64 d7 26 8e d7 aa 09 7f 37 58 9c 27 77 0f " + "90 dd 0b 07 63 5b e3 f5 33 64 f8 4c c6 4e 09 81 92 81 b2 82 76 5f b8 40 c8 81 97 a8 2b 0a cf 0a 87 " + "24 94 d1 df ac 9d e8 46 da a7 de 08 b2 40 64 7a 96 ba 72 fb e0 8f d5 2b 55 c6 c9 45 14 a4 7e c5 1b " + "a4 9a 97 54 89 eb c9 38 3b 48 f5 e2 40 93 90 68 ce 58 36 ff 24 f1 f8 4b c5 81 b4 20 2b 08 82 76 5f " + "b8 40 c9 e0 39 d8 a8 b9 e4 35 be f2 f4 5f c7 cb 7e 78 87 16 e8 c7 af c1 ba cc 64 e1 24 6d 2a b5 06 " + "d3 60 73 79 2a e6 96 e4 1a d6 ba 0c 8a bd 2e c0 d5 45 b0 75 7f 94 a9 f3 53 82 80 e5 6d b5 f5 d8 ec " + "f8 4b c5 4e 68 81 a3 51 82 76 5f b8 40 ca 27 68 37 02 a8 e9 bf 32 01 65 6f f8 4a 60 d5 b1 dd 81 42 " + "73 99 3c f1 a0 25 b0 54 45 4e 40 d5 30 92 f4 85 18 ee 05 be ad 4f 18 02 1f 4f 54 0c 0b 7c 7d 26 eb " + "a5 0e a4 89 0b 9e 5e 49 a7 6c 5f f8 4a c4 55 41 7e 2d 82 76 5f b8 40 cb 72 be 9e 2e 5d 4a 1f 25 72 " + "96 c7 39 39 10 4e ce 80 31 32 15 26 5a f0 6b c7 ea f4 42 ab ff 4f 0b 48 fc fc 6f 43 f4 df 46 30 c7 " + "12 b5 e7 ef db 75 4a 86 e4 0c f2 02 16 6e b6 9e ea a6 ad 3a 2d f8 4a c4 36 48 1f 37 82 76 5f b8 40 " + "ce 73 66 0a 06 62 6c 1b 3f da 7b 18 ef 7b a3 ce 17 b6 bf 60 4f 95 41 d3 c6 c6 54 b7 ae 88 b2 39 40 " + "7f 65 9c 78 f4 19 02 5d 78 57 27 ed 01 7b 6a dd 21 95 2d 7e 12 00 73 73 e3 21 db c3 18 24 ba f8 4a " + "c4 55 41 7e 2d 82 76 5f b8 40 ce 73 f1 f1 f1 f1 6c 1b 3f da 7b 18 ef 7b a3 ce 17 b6 f1 f1 f1 f1 41 " + "d3 c6 c6 54 b7 ae 88 b2 39 40 7f f1 f1 f1 f1 19 02 5d 78 57 27 ed 01 7b 6a dd 21 f1 f1 f1 f1 00 00 " + "01 e3 21 db c3 18 24 ba f8 4c c6 81 bf 81 ea 39 37 82 76 5f b8 40 d2 30 30 60 35 99 b7 6f 64 0b 8f " + "7c 11 99 12 bb 04 66 e7 ee f3 38 cd 9d e5 67 d2 b6 df ba 81 72 8d b2 e9 8f 29 38 25 bb 00 a9 a6 ac " + "93 66 83 fc 82 c8 bc 38 7a df 3a 4a 5f e1 cc ca dd 1a 74 59 f8 4c c6 6b 81 aa 39 81 f7 82 76 5f b8 " + "40 e0 2b 18 fb a6 b8 87 fb 92 58 46 9c 3a f8 e4 45 cc 9a e2 b5 38 6c ac 5f 60 c4 17 0f 82 20 86 22 " + "4e 38 76 55 5c 74 5a 7e c8 ac 18 1c 7f 97 01 77 6d 94 a7 79 60 4e a1 26 51 de 5f 4a 74 8d 29 e1 f8 " + "4c c6 40 81 e7 0a 81 d0 82 76 5f b8 40 e3 11 15 a7 6f a7 fb 2e fd 3c fa f4 6a d0 0b 05 fc 34 98 e1 " + "ba f1 78 5d ff e6 ca 69 91 3d 25 65 31 d1 80 56 42 35 fd 3d 3c 10 40 9c d1 1f c2 59 cf 7c fd a9 b6 " + "bb 25 33 40 41 2d 82 87 8f 3b d3 f8 4b c5 41 5e 31 81 97 82 76 5f b8 40 e5 e8 d8 c2 d7 62 d2 1c a1 " + "e9 bc ee 8a dc 53 60 0f 2d 89 40 97 54 26 66 d6 b5 f4 1b 23 58 4b 07 f6 09 01 ab 40 9d df 91 e0 cd " + "25 62 da ff f2 cb 0f 22 1e b9 f1 15 6f 78 1a 5d 99 31 a0 2a 2e 07 f8 4a c4 55 41 7e 2d 82 76 5f b8 " + "40 ea 99 2c 13 68 7c 20 e7 90 a9 ff a6 df 8b 1a 16 86 88 e2 a8 87 36 5d 7a 50 21 86 fa 0d 62 20 e8 " + "3e 11 3a 1f e7 7d c0 68 9d 55 ba 2e 8a 83 aa 8e 20 42 18 f4 d8 e7 32 82 5b d7 80 cf 94 ed 5c c3 f8 " + "4b c5 56 7c 52 81 fe 82 76 5f b8 40 f6 15 5f 1a 60 14 3b 7d 9d 5d 1a 44 0d 7d 52 fe 68 09 f6 9e 0c " + "6f 1e 00 24 45 7e 0d 71 dd 88 ad e3 b1 3a aa 94 0c 89 ac 06 10 95 2b 48 bd 83 2c 42 e3 43 a1 3e 61 " + "ff db 06 01 0c ff c3 45 e0 53 f8 4c c6 63 81 e7 58 81 af 82 76 5f b8 40 fa 56 85 61 b7 d5 28 8d f7 " + "a5 06 c9 bc 1c 95 12 ab 39 6e 68 c4 6f 0e 62 c2 1d c1 aa 58 4b 84 4a 8a 7e 94 4f 69 71 30 36 65 fd " + "37 b1 38 d9 a5 f6 37 e6 72 ed b9 89 69 66 4c 4e 7f d1 c4 12 6d ef"; byte[] payload = Hex.decode(peers); RLPList rlpList = decode2(payload); RLPList.recursivePrint(rlpList); // TODO: add some asserts in place of just printing the rlpList } @Test /* very very very long blocks msg */ public void test14() { String blocksMsg = "f91c1c13f90150f8c4a07df3d35d4df0a56fcf1d6344d5315cb56b9bf83bb96ad17c7b96a9cd14133c5da01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a064afb6284fa35f26d7b2c5a26afaa5483072fbcb575221b34ce002a991b7a223a04a8abe6d802797dc80b497584f898c2d4fd561cc185828cfa1b92f6f38ee348e833fbfe484533f201c80a000000000000000000000000000000000000000000000000000cfccb5cfd4667cf887f8850380942d0aceee7e5ab874e22ccf8d1a649f59106d74e88609184e72a000822710a047617600000000000000000000000000000000000000000000000000000000001ca08691ab40e258de3c4f55c868c0c34e780e747158a1d96ca50186dfd3305abd78a042269c981d048a7b791aafc8f4e644232740c1a1cceb5b6d05568827a64c0664c0f8c8f8c4a0637c8a6cdb907fac6f752334ab79065bcc4e46cd4f4358dbc2a653544a20eb31a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a022a36c1a1e807e6afc22e6bb53a31111f56e7ee7dbb2ee571cefb152b514db4da01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fcfd784533f1cf980a0000000000000000000000000000000000000000000000000e153d743fa040b18c0c0f8c8f8c4a07b2536237cbf114a043b0f9b27c76f84ac160ea5b87b53e42c7e76148964d450a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a07a3be0ee10ece4b03097bf74aabac628aa0fae617377d30ab1b97376ee31f41aa01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fbfe884533f1ce880a0000000000000000000000000000000000000000000000000f3deea84969b6e95c0c0f8c8f8c4a0d2ae3f5dd931926de428d99611980e7cdd7c1b838273e43fcad1b94da987cfb8a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a00b5b11fcf4ee12c6812f9d01cf0dff07c72cd7e02e48b35682f67c595407be14a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833faffd84533f1ce280a00000000000000000000000000000000000000000000000005fcbc97b2eb8ffb3c0c0f8c8f8c4a094d615d3cb4b306d20985028c78f0c8413d509a75e8bb84eda95f734debad2a0a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a04b8fd1b98cf5758bd303ff86393eb6d944c1058124bddce5d4e04b5395254d5ea01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fbfec84533f1c7680a000000000000000000000000000000000000000000000000079fe3710116b32aac0c0f8c8f8c4a09424a07a0e4c05bb872906c40844a75b76f6517467b79c12fa9cc6d79ae09934a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a02dbe9ff9cbbc4c5a6ff26971f75b405891141f4e9bce3c2dc4200a305138e584a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fcfdf84533f1c3b80a0000000000000000000000000000000000000000000000000e0a6f8cf1d56031bc0c0f8c8f8c4a009aabea60cf7eaa9df4afdf4e1b5f3e684dab34fc9a9180a050085a4131ceedfa01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a0436da067f9683029e717edf92da46c3443e8c342974f47a563302a0678efe702a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fdfd684533f1bfc80a00000000000000000000000000000000000000000000000005bc88c041662ffdac0c0f8c8f8c4a0f8b104093483b7c0182e1bba2ce3340d14469d3a3ee7646821223a676c680ac1a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a0d482e71cde61190a33ca5aeb88b6b06276984e5a14253a98df232e8767167221a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fefd184533f1bce80a00000000000000000000000000000000000000000000000004aeb31823f6a1950c0c0f8c8f8c4a0dd1f0aba02c2bb3b5a2b6cb1cc907ea70912bd46dc7a78577f2cae6cdbcbe5f3a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a058ab6df33d7cbeb6a735a7e4ccf4f28143e6a1742e45dda8f8cf48af43cb66c0a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fffd084533f1b9f80a0000000000000000000000000000000000000000000000000577042b0858b510bc0c0f8c8f8c4a0a287bb7da30f04344976abe569bd719f69c1cbea65533e5311ca5862e6eaa504a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a07e0537009c23cb1152caf84a52272431f74b6140866b15805622b7bcb607cd42a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934783400fd384533f1b6180a000000000000000000000000000000000000000000000000083d31378a0993e1ac0c0f8c8f8c4a063483cff8fbd489e6ce273326d8dc1d54a31c67f936ca84bf500e5419d3e9805a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a07737d08564819d51f8f834a6ee4278c23a0c2f29a3f485b21002c1f24f04d8e4a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fffd484533f1b5780a0000000000000000000000000000000000000000000000000bb586fe6de016e14c0c0f8c8f8c4a0975c8ed0c9197b7c018e02e1c95f315acf82b25e4a812140f4515e8bc827650ca01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a0ad51229abead59e93c80db5ba160f0939bc49dcee65d1c081f6eb040ff1f571fa01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fefd984533f1b4e80a0000000000000000000000000000000000000000000000000548f02c6ceb26fd4c0c0f8c8f8c4a05844082e41f7c1f34485c7902afa0aa0979a6a849100fc553cd946f4a663929ca01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a01bc726443437c4c062be18d052278e4ef735b8fe84387c8a4fc85fb70d5078e0a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fffd884533f1b1080a0000000000000000000000000000000000000000000000000cc1e528f54f22bdac0c0f8c8f8c4a0ba06ba81c93faaf98ea2d83cbdc0788958d938b29a9eb2a92ffbd4a628b3d52ea01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a05053bfe1c0f1f0dd341c6df35e5a659989be041e8521027cc90f7605eb15fbb9a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fefdd84533f1b0380a0000000000000000000000000000000000000000000000000bcf9df2fec615ecac0c0f8c8f8c4a083732d997db15109e90464c24b7c959a78881d827c55a0d668a66a2736be5d87a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a054f4012cba33a2b80b0dca9dd52f56b2c588133bd71700863f8cb95127176634a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fffdc84533f1a4680a00000000000000000000000000000000000000000000000006920a1dc9d915d0ec0c0f8c8f8c4a052e2fba761c2d0643170ef041c017391e781190fe715ae87cdae8eee1d45d95ba01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a0ee2c82f77d7afd1f8dbe4f791df8477496c23e5504b9d66814172077f65f81f2a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fefe184533f1a3880a0000000000000000000000000000000000000000000000000ae86da9012398fc4c0c0f8c8f8c4a055703ba09544f386966b6d63bfc31033b761a4d1a6bb86b0cf49b4bb0526744ea01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a01684c03a675b53786f0077d1651c3d169a009b13a6ee2b5047be6dbbe6d957ffa01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fdfea84533f1a2f80a00000000000000000000000000000000000000000000000003247320d0eb639dfc0c0f8c8f8c4a05109a79b33d81f4ee4814b550fb0002f03368d67570f6d4e6105fce2874d8b72a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a0ae72e8c60a3dcfd53deecdb2790d18f0cc710f77cf2c1ed76e7da829bde619dca01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fcff784533f1a1d80a000000000000000000000000000000000000000000000000040e0bc9bc9bcf295c0c0f8c8f8c4a03961e4bbba5c95fad3db0cffa3a16b9106f9ea3e8957993eab576b683c22f416a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a0e9c6cf457bbe64d6bda67852a276cdbadb4f384a36d496e81801a496cfd9b7b5a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fdfee84533f19df80a0000000000000000000000000000000000000000000000000dbb3fd6c816776d8c0c0f8c8f8c4a06b8265a357cb3ad744e19f04eb15377f660c10c900cc352d24f9b09073a363d6a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a07ba07e1bc6a20ffa44ae6080d30982b9faa148faf6b1ec15e32d89ac853ac291a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fefe984533f198d80a00000000000000000000000000000000000000000000000005171325b6a2f17f1c0c0f8c8f8c4a0dcdc0347bb87ce72d49ac2e4e11f89069509b129a2536bf3d57c6bca30894032a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a0ca24447aa0cedb4b561c7810461eef19b16a827c27352e5e01f914e9d7c78247a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fffe884533f194680a0000000000000000000000000000000000000000000000000da4714cfed9d8bbcc0c0f8c8f8c4a047f2dd6c15ea4082b3e11e5cf6b925b27e51d9de68051a093e52ef465cffbb8ca01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a05a7206edddf50fcfeeaa97348a7112fc6edd0b5eacb44cf43d6a6c6b6609b459a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fefed84533f193e80a0000000000000000000000000000000000000000000000000ffafba4bf8dc944ec0c0f8c8f8c4a04d5ad6d860772145872f6660ecefcb0b0b2056e0aa3509a48bf4c175459e5121a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a00f4659d09bb2ced56e7fd9c4d3d90daca8b4f471307b7c4385fd34a41016b0b2a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fdff684533f192580a000000000000000000000000000000000000000000000000090620e5e59a39fe5c0c0f8c8f8c4a0c1725c58d1bf023af468e0088db3cf642ae097cf2c58c2ece2fc746980acc7e6a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a0be19a182ea1584050deb0a79abdc11be896ce8d00a282bcfaf9ffcd65fd64d6aa01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833feff184533f189080a000000000000000000000000000000000000000000000000076f17f4199bccd12c0c0f8c8f8c4a0bd521a20a18ca6ca7115065065a1aa20067ee580fb11e2963d1e3a681e8302afa01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a011be45633350e39475a1a07712ba72de4602d9eebf639ccd5422a389095ccaf1a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fdffa84533f187b80a00000000000000000000000000000000000000000000000000c71b81c4a4cb82cc0c0f8c8f8c4a07c6d2d56e9c87f1553e4d06705af61a7c19a6046d2c39f8ed1417988783d3b1da01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a012f5f0668063509e33a45a64eb6a072b2d84aa19f430f49f159be5008a786b2ea01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fd00684533f186080a0000000000000000000000000000000000000000000000000b3f962892cfec9e6c0c0f8c8f8c4a07154f0f8ecc7f791d22eec06ec86d87a44b2704f015b3d2cff3571a3d01ae0f6a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a079536abf8e163cf8aa97f0d52866d04363902d591fd7c36aa35fc983d45fefd6a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fdffd84533f182f80a0000000000000000000000000000000000000000000000000736716e42499890fc0c0f8c8f8c4a0bf2fb1ee988ac4e17eae221a24176649774333fab25b6fc96c6081527fb6f121a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a041578daae7bcccd4976340aeb19e4132d2fe4193a0d92f87744c82bfe113502fa01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fd00984533f182b80a00000000000000000000000000000000000000000000000001c62fa76645942c6c0c0f8c8f8c4a07f84873e2679d40458b9dda9900478a78871044e08f6b47dad659b9b60ff8d48a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a0597d3f4160770c0492333f90bad739dc05117d0e478a91f09573742e432904e8a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fe00184533f17f680a0000000000000000000000000000000000000000000000000e24d8b1140fb34d5c0c0f8c8f8c4a0fd77bd13a8cde1766537febe751a27a2a31310a04638a1afcd5e8ad3c5485453a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a0473b2b248d91010ba9aec2696ffc93c11c415ed132832be0fd0578f184862e13a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833feffc84533f17ca80a0000000000000000000000000000000000000000000000000fb5b65bac3f0d947c0c0f8c8f8c4a0518916dfb79c390bd7bff75712174512c2f96bec42a3f573355507ad1588ce0ca01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a08599d2ec9e95ec62f41a4975b655d8445d6767035f94eb235ed5ebea976fb9eaa01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347833fe00484533f17b880a0000000000000000000000000000000000000000000000000bc27f4b8a201476bc0c0f90319f8c4a0ab6b9a5613970faa771b12d449b2e9bb925ab7a369f0a4b86b286e9d540099cfa01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347943854aaf203ba5f8d49b1ec221329c7aebcf050d3a0990dc3b5acbee04124361d958fe51acb582593613fc290683940a0769549d3eda09bfe4817d274ea3eb8672e9fe848c3885b53bbbd1d7c26e6039f90fb96b942b0833ff00084533f16b780a000000000000000000000000000000000000000000000000077377adff6c227dbf9024ff89d80809400000000000000000000000000000000000000008609184e72a000822710b3606956330c0d630000003359366000530a0d630000003359602060005301356000533557604060005301600054630000000c5884336069571ca07f6eb94576346488c6253197bde6a7e59ddc36f2773672c849402aa9c402c3c4a06d254e662bf7450dd8d835160cbb053463fed0b53f2cdd7f3ea8731919c8e8ccf9010501809400000000000000000000000000000000000000008609184e72a000822710b85336630000002e59606956330c0d63000000155933ff33560d63000000275960003356576000335700630000005358600035560d630000003a590033560d63000000485960003356573360003557600035335700b84a7f4e616d65526567000000000000000000000000000000000000000000000000003057307f4e616d655265670000000000000000000000000000000000000000000000000057336069571ba04af15a0ec494aeac5b243c8a2690833faa74c0f73db1f439d521c49c381513e9a05802e64939be5a1f9d4d614038fbd5479538c48795614ef9c551477ecbdb49d2f8a6028094ccdeac59d35627b7de09332e819d5159e7bb72508609184e72a000822710b84000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002d0aceee7e5ab874e22ccf8d1a649f59106d74e81ba0d05887574456c6de8f7a0d172342c2cbdd4cf7afe15d9dbb8b75b748ba6791c9a01e87172a861f6c37b5a9e3a5d0d7393152a7fbe41530e5bb8ac8f35433e5931bc0"; byte[] payload = Hex.decode(blocksMsg); RLPList rlpList = decode2(payload); RLPList.recursivePrint(rlpList); // TODO: add some asserts in place of just printing the rlpList } @Test /* hello msg */ public void test15() { String helloMsg = "f8 91 80 0b 80 b8 46 45 74 68 65 72 65 75 6d 28 2b 2b 29 2f 5a 65 72 6f 47 6f 78 2e 70 72 " + "69 63 6b 6c 79 5f 6d 6f 72 73 65 2f 76 30 2e 34 2e 32 2f 52 65 6c 65 61 73 65 2d 57 69 6e 33 32 2f " + "57 69 6e 64 6f 77 73 2f 56 53 32 30 31 33 07 82 76 5f b8 40 ea 99 2c 13 68 7c 20 e7 90 a9 ff a6 df " + "8b 1a 16 86 88 e2 a8 87 36 5d 7a 50 21 86 fa 0d 62 20 e8 3e 11 3a 1f e7 7d c0 68 9d 55 ba 2e 8a 83 " + "aa 8e 20 42 18 f4 d8 e7 32 82 5b d7 80 cf 94 ed 5c c3"; byte[] payload = Hex.decode(helloMsg); RLPList rlpList = decode2(payload); RLPList.recursivePrint(rlpList); // TODO: add some asserts in place of just printing the rlpList } /************************************ * Test data from: https://github.com/ethereum/wiki/wiki/%5BEnglish%5D-RLP * * Using assertEquals(String, String) instead of assertArrayEquals to see the actual content when the test fails. */ @Test(expected = RuntimeException.class) public void testEncodeNull() { encode(null); } @Test public void testEncodeEmptyString() { String test = ""; String expected = "80"; byte[] encoderesult = encode(test); assertEquals(expected, Hex.toHexString(encoderesult)); String decodeResult = (String) decode(encoderesult, 0).getDecoded(); assertEquals(test, decodeResult); } @Test public void testEncodeShortString() { String test = "dog"; String expected = "83646f67"; byte[] encoderesult = encode(test); assertEquals(expected, Hex.toHexString(encoderesult)); byte[] decodeResult = (byte[]) decode(encoderesult, 0).getDecoded(); assertEquals(test, bytesToAscii(decodeResult)); } @Test public void testEncodeSingleCharacter() { String test = "d"; String expected = "64"; byte[] encoderesult = encode(test); assertEquals(expected, Hex.toHexString(encoderesult)); byte[] decodeResult = (byte[]) decode(encoderesult, 0).getDecoded(); assertEquals(test, bytesToAscii(decodeResult)); } @Test public void testEncodeLongString() { String test = "Lorem ipsum dolor sit amet, consectetur adipisicing elit"; // length = 56 String expected = "b8384c6f72656d20697073756d20646f6c6f722073697420616d65742c20636f6e7365637465747572206164697069736963696e6720656c6974"; byte[] encoderesult = encode(test); assertEquals(expected, Hex.toHexString(encoderesult)); byte[] decodeResult = (byte[]) decode(encoderesult, 0).getDecoded(); assertEquals(test, bytesToAscii(decodeResult)); } @Test public void testEncodeZero() { Integer test = 0; String expected = "80"; byte[] encoderesult = encode(test); assertEquals(expected, Hex.toHexString(encoderesult)); String decodeResult = (String) decode(encoderesult, 0).getDecoded(); assertEquals("", decodeResult); } @Test public void testEncodeSmallInteger() { Integer test = 15; String expected = "0f"; byte[] encoderesult = encode(test); assertEquals(expected, Hex.toHexString(encoderesult)); byte[] decodeResult = (byte[]) decode(encoderesult, 0).getDecoded(); int result = byteArrayToInt(decodeResult); assertEquals(test, Integer.valueOf(result)); } @Test public void testEncodeMediumInteger() { Integer test = 1000; String expected = "8203e8"; byte[] encoderesult = encode(test); assertEquals(expected, Hex.toHexString(encoderesult)); byte[] decodeResult = (byte[]) decode(encoderesult, 0).getDecoded(); int result = byteArrayToInt(decodeResult); assertEquals(test, Integer.valueOf(result)); test = 1024; expected = "820400"; encoderesult = encode(test); assertEquals(expected, Hex.toHexString(encoderesult)); decodeResult = (byte[]) decode(encoderesult, 0).getDecoded(); result = byteArrayToInt(decodeResult); assertEquals(test, Integer.valueOf(result)); } @Test public void testEncodeBigInteger() { BigInteger test = new BigInteger("100102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", 16); String expected = "a0100102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f"; byte[] encoderesult = encode(test); assertEquals(expected, Hex.toHexString(encoderesult)); byte[] decodeResult = (byte[]) decode(encoderesult, 0).getDecoded(); assertEquals(test, new BigInteger(1, decodeResult)); } @Test public void TestEncodeEmptyList() { Object[] test = new Object[0]; String expected = "c0"; byte[] encoderesult = encode(test); assertEquals(expected, Hex.toHexString(encoderesult)); Object[] decodeResult = (Object[]) decode(encoderesult, 0).getDecoded(); assertTrue(decodeResult.length == 0); } @Test public void testEncodeShortStringList() { String[] test = new String[]{"cat", "dog"}; String expected = "c88363617483646f67"; byte[] encoderesult = encode(test); assertEquals(expected, Hex.toHexString(encoderesult)); Object[] decodeResult = (Object[]) decode(encoderesult, 0).getDecoded(); assertEquals("cat", bytesToAscii((byte[]) decodeResult[0])); assertEquals("dog", bytesToAscii((byte[]) decodeResult[1])); test = new String[]{"dog", "god", "cat"}; expected = "cc83646f6783676f6483636174"; encoderesult = encode(test); assertEquals(expected, Hex.toHexString(encoderesult)); decodeResult = (Object[]) decode(encoderesult, 0).getDecoded(); assertEquals("dog", bytesToAscii((byte[]) decodeResult[0])); assertEquals("god", bytesToAscii((byte[]) decodeResult[1])); assertEquals("cat", bytesToAscii((byte[]) decodeResult[2])); } @Test public void testEncodeLongStringList() { String element1 = "cat"; String element2 = "Lorem ipsum dolor sit amet, consectetur adipisicing elit"; String[] test = new String[]{element1, element2}; String expected = "f83e83636174b8384c6f72656d20697073756d20646f6c6f722073697420616d65742c20636f6e7365637465747572206164697069736963696e6720656c6974"; byte[] encoderesult = encode(test); assertEquals(expected, Hex.toHexString(encoderesult)); Object[] decodeResult = (Object[]) decode(encoderesult, 0).getDecoded(); assertEquals(element1, bytesToAscii((byte[]) decodeResult[0])); assertEquals(element2, bytesToAscii((byte[]) decodeResult[1])); } //multilist: //in: [ 1, ["cat"], "dog", [ 2 ] ], //out: "cc01c48363617483646f67c102" //in: [ [ ["cat"], ["dog"] ], [ [1] [2] ], [] ], //out: "cdc88363617483646f67c20102c0" @Test public void testEncodeMultiList() { Object[] test = new Object[]{1, new Object[]{"cat"}, "dog", new Object[]{2}}; String expected = "cc01c48363617483646f67c102"; byte[] encoderesult = encode(test); assertEquals(expected, Hex.toHexString(encoderesult)); Object[] decodeResult = (Object[]) decode(encoderesult, 0).getDecoded(); assertEquals(1, byteArrayToInt((byte[]) decodeResult[0])); assertEquals("cat", bytesToAscii(((byte[]) ((Object[]) decodeResult[1])[0]))); assertEquals("dog", bytesToAscii((byte[]) decodeResult[2])); assertEquals(2, byteArrayToInt(((byte[]) ((Object[]) decodeResult[3])[0]))); test = new Object[]{new Object[]{"cat", "dog"}, new Object[]{1, 2}, new Object[]{}}; expected = "cdc88363617483646f67c20102c0"; encoderesult = encode(test); assertEquals(expected, Hex.toHexString(encoderesult)); decodeResult = (Object[]) decode(encoderesult, 0).getDecoded(); assertEquals("cat", bytesToAscii(((byte[]) ((Object[]) decodeResult[0])[0]))); assertEquals("dog", bytesToAscii(((byte[]) ((Object[]) decodeResult[0])[1]))); assertEquals(1, byteArrayToInt(((byte[]) ((Object[]) decodeResult[1])[0]))); assertEquals(2, byteArrayToInt(((byte[]) ((Object[]) decodeResult[1])[1]))); assertTrue((((Object[]) decodeResult[2]).length == 0)); } @Test public void testEncodeEmptyListOfList() { // list = [ [ [], [] ], [] ], Object[] test = new Object[]{new Object[]{new Object[]{}, new Object[]{}}, new Object[]{}}; String expected = "c4c2c0c0c0"; byte[] encoderesult = encode(test); assertEquals(expected, Hex.toHexString(encoderesult)); Object[] decodeResult = (Object[]) decode(encoderesult, 0).getDecoded(); assertTrue(decodeResult.length == 2); assertTrue(((Object[]) (decodeResult[0])).length == 2); assertTrue(((Object[]) (decodeResult[1])).length == 0); assertTrue(((Object[]) ((Object[]) (decodeResult[0]))[0]).length == 0); assertTrue(((Object[]) ((Object[]) (decodeResult[0]))[1]).length == 0); } //The set theoretical representation of two @Test public void testEncodeRepOfTwoListOfList() { //list: [ [], [[]], [ [], [[]] ] ] Object[] test = new Object[]{new Object[]{}, new Object[]{new Object[]{}}, new Object[]{new Object[]{}, new Object[]{new Object[]{}}}}; String expected = "c7c0c1c0c3c0c1c0"; byte[] encoderesult = encode(test); assertEquals(expected, Hex.toHexString(encoderesult)); Object[] decodeResult = (Object[]) decode(encoderesult, 0).getDecoded(); assertTrue(decodeResult.length == 3); assertTrue(((Object[]) (decodeResult[0])).length == 0); assertTrue(((Object[]) (decodeResult[1])).length == 1); assertTrue(((Object[]) (decodeResult[2])).length == 2); assertTrue(((Object[]) ((Object[]) (decodeResult[1]))[0]).length == 0); assertTrue(((Object[]) ((Object[]) (decodeResult[2]))[0]).length == 0); assertTrue(((Object[]) ((Object[]) (decodeResult[2]))[1]).length == 1); assertTrue(((Object[]) ((Object[]) ((Object[]) (decodeResult[2]))[1])[0]).length == 0); } @Test public void testRlpEncode() { assertEquals(result01, Hex.toHexString(encode(test01))); assertEquals(result02, Hex.toHexString(encode(test02))); assertEquals(result03, Hex.toHexString(encode(test03))); assertEquals(result04, Hex.toHexString(encode(test04))); assertEquals(result05, Hex.toHexString(encode(test05))); assertEquals(result06, Hex.toHexString(encode(test06))); assertEquals(result07, Hex.toHexString(encode(test07))); assertEquals(result08, Hex.toHexString(encode(test08))); assertEquals(result09, Hex.toHexString(encode(test09))); assertEquals(result10, Hex.toHexString(encode(test10))); assertEquals(result11, Hex.toHexString(encode(test11))); assertEquals(result12, Hex.toHexString(encode(test12))); assertEquals(result13, Hex.toHexString(encode(test13))); assertEquals(result14, Hex.toHexString(encode(test14))); assertEquals(result15, Hex.toHexString(encode(test15))); assertEquals(result16, Hex.toHexString(encode(test16))); } @Test public void testRlpDecode() { int pos = 0; String emptyString; byte[] decodedData; Object[] decodedList; emptyString = (String) decode(Hex.decode(result01), pos).getDecoded(); assertEquals("", emptyString); emptyString = (String) decode(Hex.decode(result02), pos).getDecoded(); assertEquals(test02, emptyString); decodedData = (byte[]) decode(Hex.decode(result03), pos).getDecoded(); assertEquals(test03, bytesToAscii(decodedData)); decodedData = (byte[]) decode(Hex.decode(result04), pos).getDecoded(); assertEquals(test04, bytesToAscii(decodedData)); decodedData = (byte[]) decode(Hex.decode(result05), pos).getDecoded(); assertEquals(test05, bytesToAscii(decodedData)); decodedList = (Object[]) decode(Hex.decode(result06), pos).getDecoded(); assertEquals(test06[0], bytesToAscii((byte[]) decodedList[0])); assertEquals(test06[1], bytesToAscii((byte[]) decodedList[1])); decodedList = (Object[]) decode(Hex.decode(result07), pos).getDecoded(); assertEquals(test07[0], bytesToAscii((byte[]) decodedList[0])); assertEquals(test07[1], bytesToAscii((byte[]) decodedList[1])); assertEquals(test07[2], bytesToAscii((byte[]) decodedList[2])); // 1 decodedData = (byte[]) decode(Hex.decode(result08), pos).getDecoded(); assertEquals(test08, byteArrayToInt(decodedData)); // 10 decodedData = (byte[]) decode(Hex.decode(result09), pos).getDecoded(); assertEquals(test09, byteArrayToInt(decodedData)); // 100 decodedData = (byte[]) decode(Hex.decode(result10), pos).getDecoded(); assertEquals(test10, byteArrayToInt(decodedData)); // 1000 decodedData = (byte[]) decode(Hex.decode(result11), pos).getDecoded(); assertEquals(test11, byteArrayToInt(decodedData)); decodedData = (byte[]) decode(Hex.decode(result12), pos).getDecoded(); assertTrue(test12.compareTo(new BigInteger(1, decodedData)) == 0); decodedData = (byte[]) decode(Hex.decode(result13), pos).getDecoded(); assertTrue(test13.compareTo(new BigInteger(1, decodedData)) == 0); // Need to test with different expected value, because decoding doesn't recognize types Object testObject1 = decode(Hex.decode(result14), pos).getDecoded(); assertTrue(DeepEquals.deepEquals(expected14, testObject1)); Object testObject2 = decode(Hex.decode(result15), pos).getDecoded(); assertTrue(DeepEquals.deepEquals(test15, testObject2)); // Need to test with different expected value, because decoding doesn't recognize types Object testObject3 = decode(Hex.decode(result16), pos).getDecoded(); assertTrue(DeepEquals.deepEquals(expected16, testObject3)); } @Test public void testEncodeLength() { // length < 56 int length = 1; int offset = 128; byte[] encodedLength = encodeLength(length, offset); String expected = "81"; assertEquals(expected, Hex.toHexString(encodedLength)); // 56 > length < 2^64 length = 56; offset = 192; encodedLength = encodeLength(length, offset); expected = "f838"; assertEquals(expected, Hex.toHexString(encodedLength)); } @Test @Ignore public void unsupportedLength() { int length = 56; int offset = 192; byte[] encodedLength; // length > 2^64 // TODO: Fix this test - when casting double to int, information gets lost since 'int' is max (2^31)-1 double maxLength = Math.pow(256, 8); try { encodedLength = encodeLength((int) maxLength, offset); System.out.println("length: " + length + ", offset: " + offset + ", encoded: " + Arrays.toString(encodedLength)); fail("Expecting RuntimeException: 'Input too long'"); } catch (RuntimeException e) { // Success! } } // Code from: http://stackoverflow.com/a/4785776/459349 private String bytesToAscii(byte[] b) { String hex = Hex.toHexString(b); StringBuilder output = new StringBuilder(); for (int i = 0; i < hex.length(); i += 2) { String str = hex.substring(i, i + 2); output.append((char) Integer.parseInt(str, 16)); } return output.toString(); } @Test public void performanceDecode() throws IOException { boolean performanceEnabled = false; if (performanceEnabled) { String blockRaw = "f8cbf8c7a00000000000000000000000000000000000000000000000000000000000000000a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347940000000000000000000000000000000000000000a02f4399b08efe68945c1cf90ffe85bbe3ce978959da753f9e649f034015b8817da00000000000000000000000000000000000000000000000000000000000000000834000008080830f4240808080a004994f67dc55b09e814ab7ffc8df3686b4afb2bb53e60eae97ef043fe03fb829c0c0"; byte[] payload = Hex.decode(blockRaw); final int ITERATIONS = 10000000; RLPList list = null; DecodeResult result = null; System.out.println("Starting " + ITERATIONS + " decoding iterations..."); long start1 = System.currentTimeMillis(); for (int i = 0; i < ITERATIONS; i++) { result = decode(payload, 0); } long end1 = System.currentTimeMillis(); long start2 = System.currentTimeMillis(); for (int i = 0; i < ITERATIONS; i++) { list = decode2(payload); } long end2 = System.currentTimeMillis(); System.out.println("Result RLP.decode()\t: " + (end1 - start1) + "ms and\t " + determineSize(result) + " bytes for each resulting object list"); System.out.println("Result RLP.decode2()\t: " + (end2 - start2) + "ms and\t " + determineSize(list) + " bytes for each resulting object list"); } else { System.out.println("Performance test for RLP.decode() disabled"); } } private int determineSize(Serializable ser) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(ser); oos.close(); return baos.size(); } @Test // found this with a bug - nice to keep public void encodeEdgeShortList() { String expectedOutput = "f7c0c0b4600160003556601359506301000000600035040f6018590060005660805460016080530160005760003560805760203560003557"; byte[] rlpKeysList = Hex.decode("c0"); byte[] rlpValuesList = Hex.decode("c0"); byte[] rlpCode = Hex.decode("b4600160003556601359506301000000600035040f6018590060005660805460016080530160005760003560805760203560003557"); byte[] output = encodeList(rlpKeysList, rlpValuesList, rlpCode); assertEquals(expectedOutput, Hex.toHexString(output)); } @Test public void encodeBigIntegerEdge_1() { BigInteger integer = new BigInteger("80", 10); byte[] encodedData = encodeBigInteger(integer); System.out.println(Hex.toHexString(encodedData)); } @Test public void testEncodeListHeader(){ byte[] header = encodeListHeader(10); String expected_1 = "ca"; assertEquals(expected_1, Hex.toHexString(header)); header = encodeListHeader(1000); String expected_2 = "f903e8"; assertEquals(expected_2, Hex.toHexString(header)); header = encodeListHeader(1000000000); String expected_3 = "fb3b9aca00"; assertEquals(expected_3, Hex.toHexString(header)); } @Test public void testEncodeSet_1(){ Set<ByteArrayWrapper> data = new HashSet<>(); ByteArrayWrapper element1 = new ByteArrayWrapper(Hex.decode("1111111111111111111111111111111111111111111111111111111111111111")); ByteArrayWrapper element2 = new ByteArrayWrapper(Hex.decode("2222222222222222222222222222222222222222222222222222222222222222")); data.add(element1); data.add(element2); byte[] setEncoded = encodeSet(data); RLPList list = (RLPList) decode2(setEncoded).get(0); byte[] element1_ = list.get(0).getRLPData(); byte[] element2_ = list.get(1).getRLPData(); assertTrue(data.contains(wrap(element1_))); assertTrue(data.contains(wrap(element2_))); } @Test public void testEncodeSet_2(){ Set<ByteArrayWrapper> data = new HashSet<>(); byte[] setEncoded = encodeSet(data); assertEquals("c0", Hex.toHexString(setEncoded)); } @Test public void testEncodeInt_7f(){ String result = Hex.toHexString(encodeInt(0x7f)); String expected = "7f"; assertEquals(expected, result); } @Test public void testEncodeInt_80(){ String result = Hex.toHexString(encodeInt(0x80)); String expected = "8180"; assertEquals(expected, result); } @Test public void testEncode_ED(){ String result = Hex.toHexString(encode(0xED)); String expected = "81ed"; assertEquals(expected, result); } @Test // capabilities: (eth:60, bzz:0, shh:2) public void testEncodeHelloMessageCap0(){ List<Capability> capabilities = new ArrayList<>(); capabilities.add(new Capability("eth", (byte) 0x60)); capabilities.add(new Capability("shh", (byte) 0x02)); capabilities.add(new Capability("bzz", (byte) 0x00)); HelloMessage helloMessage = new HelloMessage((byte)4, "Geth/v0.9.29-4182e20e/windows/go1.4.2", capabilities , 30303, "a52205ce10b39be86507e28f6c3dc08ab4c3e8250e062ec47c6b7fa13cf4a4312d68d6c340315ef953ada7e19d69123a1b902ea84ec00aa5386e5d550e6c550e"); byte[] rlp = helloMessage.getEncoded(); HelloMessage helloMessage_ = new HelloMessage(rlp); String eth = helloMessage_.getCapabilities().get(0).getName(); byte eth_60 = helloMessage_.getCapabilities().get(0).getVersion(); assertEquals("eth", eth); assertEquals(0x60, eth_60); String shh = helloMessage_.getCapabilities().get(1).getName(); byte shh_02 = helloMessage_.getCapabilities().get(1).getVersion(); assertEquals("shh", shh); assertEquals(0x02, shh_02); String bzz = helloMessage_.getCapabilities().get(2).getName(); byte bzz_00 = helloMessage_.getCapabilities().get(2).getVersion(); assertEquals("bzz", bzz); assertEquals(0x00, bzz_00); } @Test public void partialDataParseTest() { String hex = "000080c180000000000000000000000042699b1104e93abf0008be55f912c2ff"; RLPList el = (RLPList) decode2OneItem(Hex.decode(hex), 3); assertEquals(1, el.size()); assertEquals(0, Util.rlpDecodeInt(el.get(0))); } @Test public void shortStringRightBoundTest(){ String testString = "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"; //String of length 55 byte[] rlpEncoded = encode(testString); String res = new String((byte[])decode(rlpEncoded, 0).getDecoded()); assertEquals(testString, res); //Fails } @Test public void encodeDecodeBigInteger() { BigInteger expected = new BigInteger("9650128800487972697726795438087510101805200020100629942070155319087371611597658887860952245483247188023303607186148645071838189546969115967896446355306572"); byte[] encoded = encodeBigInteger(expected); BigInteger decoded = decodeBigInteger(encoded, 0); assertNotNull(decoded); assertEquals(expected, decoded); } @Test public void rlpEncodedLength() { // Sorry for my length: real world data, and it hurts! String rlpBombStr = "f906c83d29b5263f75d4059883dfaee37593f076fe42c254e0a9f247f62eafa00773636a33d5aa4bea5d520361874a8d34091c456a5fdf14fefd536eee06eb68bddba42ae34b81863a1d8a0fdb1167f6e104080e10ded0cd4f0b9f34179ab734135b58671a4a69dd649b10984dc6ad2ce1caebfc116526fe0903396ab89898a56e8384d4aa5061c77281a5d50640a4b6dd6de6b7f7574d0cfef68b67d3b66c0349bc5ea18cccd3904eb8425258e282ddf8b13bde46c99d219dc145056232510665b95760a735aa4166f58e8deefa02bc5923f420940b3b781cd3a8c06653a5f692de0f0080aa8810b44de96b0237f25162a31b96fb3cb0f1e2976ff3c2d69c565b39befb917560aa5d43f3a857ffe4cae451a3a175ccb92f25c9a89788ee6cf9275fd99eaa6fc29e9216ed5b931409e9cd1e8deb0423be72ce447ab8aa4ff39caee8f3a0cfecb62da5423954f2fa6fd14074c1e9dbce3b77ceaf96a0b31ae6c87d40523550158464fcaab748681f775b2ab1e09fff6db8739d4721824654ae3989ae7c35eb1a42021c43c77a040dfef6d91954f5b005c84cd60d7ab535d3f06c10c86bf6390111839a5ffc985a38941d840db64806d4181d42c572b54d90ea7b2fbad0c86550f48cca0d9a3aacfd436e1663836615c0a8e6a5ed1be1f75c7f98b43fd154fbffd9b2316d51691523eeb3fa52746499deddf65a8ccc7d0313370651004e719071947dab6b64a99ccebeabf66418b6265ff5d7ed7ecf6fac620ede69e48946b26205c7add1117952ea8199d4e42d592ed112c1341f4c1d9aeee0a03ac655ad02148cab6613c11c255c99c9eb1ed8609397f4e93a523a31d545055c4fe85baccf2a2903d6b64d2e4b6fb5cbc9029e9eee4a33e3ece51e42602c64a66ee1c6ce9d47911daf7b57c9272b6f96029c797081c1ca3f59f67ed1a0a4a612f86222ab2da812fd09cdcebe3fa2f33c07b9fb8435937091370ecdb028dd9446275eb063ea74149da4b72149187c786ee6839946f85e3d3d41786c2f5aec041f77e278320dc4e0f0618fa0c5e7352dd7a598581531e804e62b3be475d8a7e2cf3a5b05be36f33a9beef75a18a5d11d615e04b595ca649fadd30b8d52392bac5cdce0f2a524576ac155ffa05ba73d255a066d8feff1d105f29e0925" + "3d6b2f3fc02fcb4d0c604b8dadb2ee95d36b77320071fe2d6105c9bc7a940dcfc2b5e8571a8678f8e81c473698411ae217051d5dce243a10bd1494539f2bdbb4898a5b8655f9ae9a99b622cec42bdf87db58673461524c27754503ace9d0a90684ec165da55247cab70af1dc928cb134f2d4d1a876a7cf318c77feb14148419526ca63c152cd4e43f9f7138d6fe44c3c104c15e6d904abe262cea244e59bdde57bdbb2b04fc2baa65b01a3af31e0e8e65b9991a43faadcee218412c834dd2415de3cb4fbf0e549a97d0172a595b367e80a1dae0a233780788784f214d2fb15d79f71ce464fb5e4ad664114802069e6fe26e8f1440e30815dbf5f4b20676b95ec5bb23df3074ffa4bc53f375a4622acb4756c102cba940bcdba53cd944aa8dc18a12237ac2c8cbae62a6f7fb7cec617b7f65280ff9ef26c9e146ed2b7d22f28883e02a05378cc031f722185e423fc66ad150771fb29a1867a978190aa6bb556e6c15009b644a06622e6606a0cf00e9a2fe25a83f99e802eca63e05aa46a5c7f090d63a25b6344ec70c798e142573bfa56980eba687bd52423e2c04ed4a9a5b6b7419c5abcc178348059ec6ba9bb47a22285f67115193c3c98288517e4ce30e32d971c390169294f3bc22f9d5b534022875c77620b0fdd85fd65dead59537ebfe5b09d4442c45f75d9188f24eef00af41faa7072a984f988d47af751d2c933aea51855572cfdf197eac950759cc36d9be3d390c357d778d770f03801153442d80a98f8ed151c6f4de26f746b714ce829b02aab07fbeae1890f91a1d7e79ea253027ad443b5f0272782ffccfabda5e09c9ee4d238dd00553ebda0151af0811c009e97f1a2aef3fce30bfb66f8c8996cf10eedcf7735bb7686149a5459b07086db3e950828a55b84e371cb9e9bd2b17111a6fcc9612b77859c52f630983c483822832375c3a82aa918c7347a443a86fb2b27dd6daae0d1c35e759670f8108225187d5376633881179b0860d8b08de2019db85cdd39420748fc31695dd66f90e1c6d3b176b5f8b6ea35900e7d56ebf6485c241f2b7ebe4a0f253556d647f1a4e3a8f4e6aa21131253821df415694467d8ac6d20282fe93be23c6177e68d3f7860a75a238f741d5d589635190e12a4821eb8b4ca87e3e04ec33e760abaa5" + "ece16bded3f35b62d5a2675be82f7c4d9d5950a64ba5f74f71b150c71902fc6306244c55aa1482940e34dae3715ed655ab0eb1d806a15c39becfba6ad3e815ea9af9ecb8f88088cc31613ecb473844d8d249bacbfdfd30d20b4fe2f17ae9cbe54deba7c90cb6fe8cc3cfe0b1af675ec863d531d526773b8b3c830604d9469b03b9471e96ea20e2c07e747707e13719c1bf470c52470b946ea2aab55d69759c07adab0aebcecf49e1aee6524b9e89d56cf7ce3f49309ed8cfe3357e4da045fefeb6c38855c04d7f32f732177e3079430cdb19841692cbdd1ee639de071b44fe7332bf2257484410c3f2cb0a0d7e9ef63c9b1d7168ecd7675ea6f6744dd2f53e954f0e252903ad8038fdd488421d72748c804b2cb38b3d3b81a4ad883ec967b56115750aa079f0d17b7a8e584b4b39071ef0a5cfe74508793d7b5442e85b1a54aa5aaa290c8cd0c016049f56cf86b6e306a92c74cbf2f1f199e85ffaefadda74c1fb8ad1113451db02809eb8eb5e55eafe8cafaaa6af8f2a1504908648ab7df5dbeaac321c94829b80170ee823895c025ef0640b20df185d2be7c9cc62e9ee1f1ebeb39e1018238c97aa77522748492cca4e1a1ba9f25419a9d22b2ff88d3a57c0388446c35e43977553957630295b8879a09e9d4173040a2f9f8cbd747f54f84d23a50e50c820988719a4513f72f0f55a0facba02a6598d77843b988214409fa9bccf62b04ad5258723ab44147ddd9b9313aece089441e74bc16b9386059a8d25cf669bce89dd6cfaf656cc57f391e13d840471aede7b9a25edc4c457dcb7b9258d48ec34ac66c7d6a34c9a35504a072c93377b6059c95b523596c64fbdd89d1a54a56325557b6da120032d901e5b3a77b7839d48d8ae27eaac510ed593f36930d123d60ef0449ce9d2948006a6c10a86a2d1e4afce6b8a8150579cf45551eb40084bfa770f1f7d64963330d00d919f9412579a23258be909e40cd2046f7016d9d5469fd725cc85c08653295a3e92033ecd5e779d02779f3bd2dc17996ccde59c2e3b5cf90816ec25b8dc9ef265b193e37263a76286ff8f5e80f786d6e28093eb148d1dea41eb0b4efa587d24464d12e3364c93099b67edda466c7f1ed7f14dc2fc6dd25be918935fba1b5f342a27b825cbc7432c1a28f87dd3e4929" + "09c4de72b3fb415144fc866324e1986212c19952ee25f3cfa7508c1a3573b8a574fcb32d3d9039559e58402f4a031bc1c90149e7bb9f44a12f9d197957bdd485cf36d8c1fefeb89d07c0539d294cb972c8b064f6f9945542818f893cfe49c4702a3ac974a5fcca3052926530f6969b1964db848ffeda89697e3a94b75bd67a9854caf829fd89a27ff111f961f00adb3057bfd62b557befd52fd73e5b38f8989d1459232370f492faf800ef32fa33ce85af30189f09e99678cb64036c77ef38d07129892d31f618bc6d730de263e9fe830a206b45c302e18f196c18bc3813b2d02ddcab1e59264f8032efbb0e4e6668bdce2dbbe950edc8fc1939bb087497d73ff86f08a010649f443dc29ae61c5d30a957b5b756dcad08a155644c9154db0c9ccfa8b049fc824e85d8e048dca99d8830a0de961e7284f1326d4ae489621158c05fc684652c1bb01eec2f45185dfaa070370988f23d0d56b6b57205cc7aeb9d9f0ae639ca477d98f5abed88b7d7bb2d5c2d87c364436f3b41f63678189bf7e6e8569e39c8e5153330ea61720fd455f81f73a13f5063243fd499aee902dcc7daae3c62180fdde0ed06e8f050efd98fdf139931aac0a41098394122a7e55ff2a4adc9012a0e608c1964b752b8271b36c2a0b536c3088c4bc335987eb4b0aa5b785f7164f2e149db84abda8c2a86dd1dd8ebfbc998554fb11c3812c6853f050133bdde0bbb0053f5184ed7f6f4fd8fb53090b9d7a1366f37e6c64c13a8436b9a49e05952b5d7ed4d5f2197a683e77620087822bda700d823ee5fcc50a0886f056e3e14a9387b450b3b036ff559c7e00592f20a4998818cc64874100292580dad40f6f2b4274683f5f97dd145d86ea41c83a66b156337b0913c791e3380d11bb72b99f2b5668c4c21f97cdd80a890e4f94452c89e3b90de7e340646c984a80858b8d67c7adbf52a8dbb8441318acc878972d7499d9876678ca92d9689fba358aee8adeb9f3a9c007ec8022a0877419b1a7bca032a4e613e02e3f2db3ed5ceb32e7ec221decbc069802d8605ed6ee15974e7027053a4270fbc8bc27218b74b3c748a57c66083d5f86c11c5299d1bc4e361de4a84427c8bc7e0edb77acc843465738bffd9fa498ce4b1700ad463baefe0794f46494ccbea58e6b110ee996d4" + "e8d8d31700a51c075c4e5fbe316d897a9b05d3d7ac2827c38c65b5719f47e7b00ff29693abc71dcb06135c66693695cfda3a93b3be0b4022218c4c258ae3c5ca9a0664812dda00b283b7d4dbfd8595bc5e7ea43b3b5166be838b5fb2c25456d96a597bc3fcbf17fc144cf8ead03300b5c17746e968ce28a3a51d8e30585d79f944ace9b5fcf8d63a40aff7930d706fb00148b643fc2100b6df658402cb86b1974a87d783d3c1ae6fc1f826a93721bd4d97afb884872a52886d010c285e8b0aa8b03a4356e10adb6c6e7da5b6c6b9990a9a25a5ab66cf025b57f7802f9dbd017dea3ebc9211bd31aaadcb3799c7eaccebbc563a4fdf3a52d8267f79aac839511091a96658ad5407cbccfdbeede199a5aa5436f107fd353535565f83f01d99791a818d4fadf7043e7cead86013c32ecec835fe01d2684620ad1552d457905ec23ab33afe1db4f5c7d1286b1fad134c15581b601ebefe0153941d357e4f908c19acebea15d987b926317a36f430f0b7e3b0916945ac5cde2d82832b637eea29882e2335a197a86d41ac5e04268153cce0274a277c4d2583ed8fd363f0af7a47b00c1cca73c5d22993f94292783965cd45aeb9f5bf8326c5b72c240cddd25ca6fd23ab890fa184c9cfdf91f53c572492840f0875807c342f97a19bc37dc6135b5bfc94a6cdc4f470f44997a017a08a8651a10219ce1b38ec84faa7120a5bd062d1a09f4e4c1ac272787c13913c301d965c0ff785d5a3d76a36f340aecfe0a8c4fedc5a7a8e8b7521baa3f44a6e8f039badc4fc5e4cb8089a1b9f0f869ba28e8ab06d1c380f6dde280e003419c16130cb92a2874bf656568bd5d33006c0ea7d83ef02bc1289a2dc0aaed3eadc62203ad78b4441fd1dc3f8e9c5a2f5158d57585e922aa1974bb31ecb463febbe16a599b85ba58b3bb655a90076bfed63b7a830d94da5b0d4eccf43f9a780edbe8cd0b29dbb5fb664d1a4dca0711be820263e77eac37816a008538c53afa4da2550706b7d209ccad725638c1f0506b09d6fa4fa6933eb05753daeda1784619e8d6eb14f40e9a78e5e39344c6848e5f89972b5fed1a8adf6da9ea79865d05697e3c5549ec22f8232a8be10db284fa7255bf9162e6f558e1185cb1c49315dfcba2e91a64b66f0a535848719f9a52e7ce90194a" + "f802116d986d1cd6ad1cfccacf306a7aeb938bb557912fad996fdef76093f2be3bc866d9f7eeb9b73ef1f74d87de604b5660bbd2cfa5639e60efef2bff66ff5d8767849f9b4fd4eadd033d79fc15280640c77e2db6842d4d72a1e1fb6b4967fef5af8ada22f76f9daaf229996e53346917f24d91a3bc6e74fb2b984dac851d0bd3f91e8aa5bc5591c2dd37169675419da1f52fb03cc15b865a7a665ea69d67a07ff45cdda28fc6163284956e24e7ca343203d34a0657c5fda3c1abb4edd133e62380cf2f0604956502994eadc9ff5757712ecce133e79dca29623713c860befdc951df3d773dadd9c29eee4cc8c846b6315af9adcb29180e895dce80ace196c5a9f2bc8bdac1d89dffbdf1112a9d4227a61d9e56f7bf9840ed60eabdec8bcf4289b4a45b723a1aa3d8e0b9cccec4e24ded63ecd47ba4f54bb0eca4ed3a39a0e2e0a34edde4ac0fdebaf3f7539214e1cafbd5ef05f78ffadde765e339c716493f9c54368e23644dd55a48f78d1485f89e148c7ddeba4da9f6051919c17a1fd23d5eb17cd01083c3b01f2c54baaa577545a2707a1d5054ffe8c5f99b129a6cbe6c2d2f03d899d18ced4652360c55de7dddd2c0bb5b7dfbbc76cb6388cd797dde1a358859173e03ab1813d036689000236d7fb283378690502327e0bee1bc42154c4defda8d720d41240d2f544675a95b1e97d73a33bc4b77fd77411b4e29fdc1db1386ed23cff560be246a650d67b18186cff41840add42180ae5839f3611f2d3c9495436f89a284f9e919587d2e683d4293026a7c8a61463f8636ba8e8df590f5e3124fc676f62d7c82efda7289c07a9ed2d01215faa2c7aa946c536c83c270af271390bef9aa817d5ff6e8957b5439ccb6c4358d1ede77e313eb1a09422f7e08397c110ca736d03071765ab34acec0d6934c2a9c5646f7fcdd26071533b56ac40400ebd779a35cdbd9a040acc9255f2b51a0eb451f3ef48d3244c6b7308f085ccca25036cb9ab4286927289b7e889f3a6fd2676cfd7db57a4efddbe27d2306ff5475caaf5428662cff339d10710f9222547a102c7292fd884956389cf3f7deaf58f4b0708d94582716ffff919a8c4fcceaad206644a9a5205aab17c96791c9babcfde23c1c585692b77082cb64c43465655777f381507b8c001f4d3b" + "58cb054034bf168b7b339394fed8480c07548793d554b2e0ad8eea9a7ed9aab44099037c38f9d6cff2c0c193812528549712141390a5b76c3d685c3915b0283b437bdcfe2cc1d8a54671096c3746a63d88c4f91bbc908d9f53d308217b215a3c2067518d6b41b26d7f266efeecd3f5ad2a29ba0c2449176c4d7977d34ac6ab116c92b12664c7796c276929a247ab74f0c483e569340c1a039480f60c5be3834c8561876baeed5c0014a98b3be7e8e88c78c871c4dff690547a11951f48ea4a5cc71e587c7d390ce056b603d81c7c9ae77086b6a7752eb4bc71cb8f69fd2a99bc88204a0dded3f27cf66ef20f9b8ec5e7c95e8aef35a45d65ff87bc0e1b00c13f9d59ecdb784be53ead535d9439660d69a3a04b9f86193bff4f8c4fb6445e3e9b53f6705a8f0b452fb282e391e5c9699e27058de811b740055cdd9edfa95027e2793845ce8770256d52faf9ec66daffafa4b20c9ba99d4553b6dd9747002d319fdce446dfd8f74318bbc13140c13e19969c3581345df20eefd13beff252e52f506060c7d7df041d766d25e62fcf955555e1824519981cfdae25b32d8d7982a5cfc06e934a28eafa36d2484e878200c208c996adafc7b0ac2b729e483cbbf1414d2b944f7ae5c7205ff1091ef1761bf3686bfd82ce793bb49f7caa720ff48574a65e44b06370131546a2a31c3037655e9fe82312507655da910d1b300f3bdfb21eb7e941dfea0632db82541cecc20e6051db1ac67f874397afece22019ea7d0f9a5ee531524a28c9d58d8c3dbfef69959653c18d67e5ba6c96a197a88bfc10a3bfe27ed52181a885f1542e5928c7a860a6b3ef7e9fe3442588f3b5c3162fd1db84f03014f01d97adbfe32e4cf321bde42e9fc5c4ae3ad0547199e489dfe6fd1210b9c2aeb5cff545e3e4df835873af24df162e59fade2852c7093d53069bffefccc5a4193f0d8c75c6d2251e0cbf5beb30101a3e1928e4f8bf071774ca596241101521eb0099efb24ffaaf2f4f3c770022733d02a0ac2cf0a388052be1de2feb7f34e2ae50b7adeaa13de36ed49291e5e58275062f37d63aadaa9dcb1f2bc4a8885b503937385c6d6f2ba12548aba8187599543ebaf03d80620539d01f246d3aa7dd0ee09c7991818e4cbb852d0ee38faf5de5c4eb93208da8683167a" + "70db8d75da696009f512cc73c045ec8c83f52c30d43f70d6ab67bb0df52b9740713cc86400178f2676fa13b5e98a1434f4059efa8b40934407dca1f0c8e5b4917f9bdd3ef43d9ef5fea0064def162aecf5487a6a30700b7bf7463d30b889c79ff0b61fc8d4b3e83bb796fa26f68702dcf3b2fc9e68af55aeab57122bfa5120bff6da079ae588887825d03218eb61fee4bc341ddaf625f38df0d40b9484b3b57358c4f22a420f495df665049f452f834c14ad955d01d1275182ce9b00e8d6e2609d53a69b24afdfefe744d740f4c421feebd27ffe2d623e3b0fe773416080b8eb9e3f0555eaa233784e65ae1bfd6be5131e70e69d74b82ac7edb24883f7ecf61e202f8481003adff3ceef8f51ed588abf3a933d3e8c00965be4a838a16a7af178ed52db1d8b0ef672e41b7fe5314a840f6e6c959ced6076896ee108b129c6ec335fca5a6735b00bf3ecd7e075b0fbad86b03df6b36d5814ffcd0fc036ef51e541e5e24003d235454c04e36bce4efd3bc3e1e61ebb64ae968e30235c25a203647d7787afbfe08e02e07c807c8dc5a3ef4a762d4bafc5fe160de0773a3f36b79f3e770c8d5b49629e54e04d70dce38e7085376c8eeec5ec1f4ce17b8f6e1641c2a8e3ad3a41b870bd2cd6cc3d31955b5ef11826a87de34c6ff46f197c959f76872a0d0caefc01d05674e25660d2ebb0ab6002dd723c3c7e942550202d5ee70362ecd6ca3c6deb2687afdac4fc00ec86006be7263bde79e0bbcaefbb7258cbc48929e6f03292e730b666eb330173e66a659956a96393c2227ca5e77f53dcb752c768d1cac1f999a95e179c380fdfe6bfd78d7eeb19180472eb1bcbd020f88389842919ef7e8fdf881f92c3414f38d6399b112f8dbdd419756ba25d46f9e4fb155fce2fa5499cb5ff8b9e18615a4e3ee69eab740fde21413c3900a147d93f1b1a4fc182fb367a6e1c3d76257f49240f2ca7161a7d8b199682a292473455c8ef0deedf2dbfbc0d1d8ac26e5dc70cda86ea5d32efeec39b4de771c51c9bc8071c5f4afc5b4da02f423288aab4d7ed241f7105515a40072da7269a185b23cd2b45fe94561ea9f79422f789d55ba502aff3c8347a8ebebbfa1e36a855b483983d0c9ecb1ec56a80fbff8071d210b8154e7762958900e6210e9c03f5485f8acd4" + "0104ea7058ec2b9fc9a04d7312aa1be1763490fcc13b4ad5fe0986e5b197bb13b19f23afd13337f6a131b3c721c3a7931192a6d63fcf405eb91cc8da0132e570224d3e3961da91ca9f9ead72123d31f4612878c1904bdde965189cbd29f259acc29c8dbe21249bd3975be4160bfea9892b9d8488aa468be1f14a387e8813fdb31e95e37304c26b7b34d9487dd176d8f39d0256dff8f4f9ccf4781e1b0258a23cc177db203b936ff8ef6195ffe7a415d75dad20de2168e3a23ac154aabf2563ceaaba66ec094fd3a6e164fab210b0a9516a8bbb529b616d33e053429b91665b5f8572c13bfb268818564f7d65a0054d93a0936ede77e44adb6b6c5648c9f1283c1bf0b4f03083468866dc93241587c2f2bc5dc85023eb203d90a31008b314d46ce66cfaf08f862581807962d8e0dad923552c912d8970bef5d0d7c2ec22cf0fe560ce0e4d051fe5d49c5a840e87dbfb0bfcd1c4c4b0c462a6ba5d484387e8152e56eee062509f1a7f10faaf22b071b6bca71dc1b0b68a4c6db7197012f0fb4635e3388b0c70a4817fa02099c33f9b61ea30f31920bd6eea600c6f134c36da37c31818715fb0f799ece7ebe3fe224c6fd60b69c39eebd7c52f10ec597530e326ed10929a09afb2f181b47349f5a0efe72934134be837a6b88a8076478dd6fb09f3100c681e030782edc037738e70352bd2fecafc1c903ebe6db946b3ee557439e5bfe93714756594e1b03f483f1c1f45ee28c0b6c14a6c1ed4559528e7f033c0ce3c85b687492c9cc27ed9d89eb8bef94ad05cbc248051ddd80b82dc0a7d1bf9f31bb57963605f54bb0b7bb387267b896c32b63da9830e52b40055d2b8e30bad892542d0cdaee632264c7fceb6405618900deb789ebabf34488708a2f051a1244f7048be752ade19487252f37995850e08cd70e70f70481a6497494780aac0429728648618dd8f469760499fec7dbec04029852cc20a44843d42999b1f1078645227f5601425cb26ea627a842f036b9340a07bc4167275df84871f0a81783f362d4f588242807cabb8d1764fccf10c1652c9d650606a08e58c607d6cdc2790439413f5e6a3214c9394b62aae2e707e93230ff0837887c74165216454fccd225597f07e02e02914241ce625b6a316d85ce12ae08297939bb4cd544dc8c" + "3898aeecaf5aec056e26e8d78339c3ae9849cd16f76221d10efcce44031ac7bf9b394cbcd5e82ed20eb95f69d3d29753eadde982d9388522195329dac553b265a480167de3199fb7f738b05630beae3940d47505d2959d837eb77fee2638f8c1a877dcfb9e8bda427eccd2570a32b56d503b367f28181ad4efe96fa4bdbeec520a781894cd3adf0a112693095ddeaa28c7d13e9204c8ae1a5d3a082abe9718b6328972f0f2b2777fbe102398be3a373a99049b9ceb610856a70c8c3ce52e0be5453a4a5b27cdd971985735e97be51824efa45193e83d0746206c72579c1e49069a6647f27d8824e3a93d4a1d36e7adb85c3dde394abcf8dfcdfd3e9a713d7925f599f60ca92a60efd5c6748f7cec39f2093cbdf4df3b7a7ed7c9b536c1b4c6967f0da287393faf77f95f6130d89adadf92313d5888600798993e97acef5ea9cfd1bb2c516a13be76fcab70b7d23123abef3219fb1708e889bf128a4e3bf35e1ce4313bb81390cf0ec651a21c26141f53391497a373309247594c659ed2a5a577be5eed674c55f82d9630b5071a24b12dc271439ef441de5cbb7131c92e30c2865609ba8e439bb7ffb1854ebccf4cceb0893395da1a9ed7345d1c34bc4c26913a075ba782e9328367367a1fa950bdba7c77f92f12b4418b484732ae3dc2ba23835c1eccca73f14ec90bb60f273232ff1d11a1b976a9e9abbe0b44728b97bea3243e359efc148de860c1b71158815f2d5211304857e935d9886edf84df1125773b3706b095cf691a62fa35640955a88ac0d85b2825916fc1d513053e02ef34f567671cf3b2aebe360acefbc5439d948b1afd37b384cbc5a470616adc90f38ec6435e5c8539743666c3f51881784f4136cdadd7346ec51c844bc5299ee7a784685567f15be47eec7c927eef34903028013d4f39952cf358cf2f5cf74e56663bdc9ba42b665dbce45238ac6bee123b3e4a3fa5df678ec62adc11d456ed6705b186cb8ab0b0f5adca44ce4f2af6115b4163c6e15d5869ed3096ff29477e48282dfd8629a1abf1a14e9b58663e2788b44b72c4602cd3f31b6ef4579e254134781826eded5b486fb12f18283c5aefc5597b926bc37aa68bcf837022c32f537080b4fa863589fb699dc3af46118cb383f82161ec44cd739294db53e2555c6325" + "4da527c06020860b89638b7629398329e4a807c12e6f8fd8b820d084f76a429f925c668ca11658a0bbd02cd3bf206bc8fd1d9d65fbb6dde960ba47e29f9846cd0c238e301b97180af62bf92a3d2e9228fb0e454c4f228e5855041aca44f67c220077dcf9c76185d92f227e2a5556729b5a789f7509a07926661af8b27e256f2530ee8ba666ba62091f8e62ad90ec1d0c1c243915934a258997452fa685e0936104f6a436262446b1f01782e829fe0233208be23e2a3cbac7d9271ebc25af406051f423fd0638f387c0a7ef177226d31e5ce2303c49c07739614e1c3186808f491c265e193f2ffb80be13d68b6880ab00775a79209f265549bc298c47b0d7a18a1e991c6d46c901f285592521a18f8b71ced15c7d9cd1429ce7cc76a542588fd5f2982aeb31623ef952c7d25dfcca1a6dfa589d6682d34cb909b84d1e416b6488ea90e9e2ba58424ce0563244303b3724d6fcc55185512e96865b72d3aa30555c55f461ae6872f04e0f9154e3135ae2c360db83d54defecd603d45bf66ddfbb75745c7d71c15e86d10da758fe4816fb2340b58f41635f8ea4434a20d97c12477794553dd898607521b85fb51cf92b4916d7881348510f3fc790ac6387355f790beaabc031d97aa541f5bf74ba76e4e16e7f5e90f4683b96d7926810c02eff1ac90331a43d015ebbc2e739a400fbce42c2a40404b82d0fddaf63519d4ee3fd5054bbf8c77e877bc0078c6c63480b519e94a23ad5faa0462d9c698dc4ed589126868d519559b3e78c8b27eb31054c6a62ac368acd440951195ef38b4815eed6a27192aea4dbae3edc027350b093b80c971b74afd7883a64052473a68566f553b5d1c8c54151b2c7ae79db207dc2ec5645520153c28b65d3018c0fe582ad37dd1fbd8b821d4fc05300baac9cdf78da34b8081b5a1739c416ae5cd65210404daee2b78cc4e4bd5c0274c19690ba74e955692a4bbb4c3bfa1bf787dc6799e53eaed6dbbe55790f148e5b32124db6e74c50ae010e766280bb5484197c83249a6d42ccaeb5bedbffab8e1c89bc5763cc530c10fd092ed9391ffc853120c251602756c69f474062932dfe7904da46ebde76dc246c6149c4177d839f16d0522fa2e7a10398a333bbc709495782083af00633b53139557b0d1fcded46fd7c497721" + "f105790deb20c0bf0e4933556ed8cfbd5048994030810319b4f441e0fdc05a7d81f424170448cfc798a49fdaf5ca7e612080006962c7e526e048ff4ffd5ccc62ce25e2c6628ac2d9054144c8084b82674a4c662ccfdd2c5b0633f936c8b97b3e764b016a07c9f12d1e31bfd6d454921cdee91fca774b48c23948aa10cbd4e1c96a8025ca68e0811d064b628f5a0f7b080707f7753bae8dd0db46e3bafa4abe96165db416c7eae1cdd873a7852344bb6c914a0f2d0564577840d61c4cae084626d147f764594a237ae92d48ae551bbf11b0d2744ca4c5660b954a71ae6aa4d445e52e9b174115cc192d86d4caba4dcc966f26610a148cc971c8fe827056690fc61e4d409d4624f7b56d48cc02d7a902b30b773089194c254c30922f996d935204e582e6335d52ccf9df4c464c062d6087da48e92d9816c3304fc14de9b84f9a4abef183639369d7c2c873c66a1d0dcb9e6e4fb90fd0f7d22d29bbeedd9a3e76f0a1bf69503a4f09238f99d47301436bf12004921fdea2b8193c4e80413b48af266f9757e202291663286531d077418baf0bb7b69247bc032605dec2c9228bd61aa94181c52ffae1a42cb2feaf2c4474f05d07b4041043a1bebdd97a0dc42e644fb0f1ab2bb3850254154336fcf68c50661f3f9fa2a42038d51ae52fc898435513ed994654704ab8e925f867f32a40a351d642cbe40844b1b51e99d3858f8bfe387bdaba611f45a880926b77bcea7f2478c28fbb7a718fae9f72455347536b294b292a029a1eea4005517a8ec20e457f88f1bc7aa03c1bcffbbd95e69dd76077ad2c448a78b0207cfa8ef236a34626d4826af6d42d0a442246e51d8f34953e871fd04266218c3ce3140e444f8abd2922bd27e614a6f10609f5bfdab37e4c446159d41b8fe6732f13894123ee6d7ac3cb9e6d46ab0e0a377d932d1843018bd10112ed8f3a676046a23b0f2d44414fead4ac564118fbbebba4147a464d533eee347aee7e5e48998d51e242b362f73e465c10c4b38135ad531971db15ee5abc4c503c7a7d87edbb9f438acebcb228ac32d66b89c63d029b7dd46ac3d40d6fcc32304c90fae285c8d03256867d569877271b52a00395b42eb295a137326481917cc395e97303af4a85e2650c97f34a6a8569fc327cef2070d9869ac513827c" + "8683586aa2aa1122ea7ce939abb9f2f45869311dd8346864e81d1f15137c1b97dc8c137c40b5d428cb9567ed10cf0a9a5c7c65854524dba6a3623d3e26fe6ca69cdb5a20c07fb2e68228963d4d21970423b9fc43c0b9ccaa4e7e96efbf0bc5c31d0b504374f9645594eda6421f7ecc08880909f985ada2f524f6b9f9454ae4476d7edbfda7fcc993ef1edd55d65a90f02edfb8e0fe712cb06926a1e30894573b1009220292a2f312227149b322e0d4efd7cd9e21831cae7b334c6d75ca7175453ffb7e31c52e495f82dcce71f5e08026c470252073c84d266394c8eb7dcffd9493e4d3532b70697724ec5072768c78f7adbd58c9c6b266f3ab73bd30133d8fa9a6fb7eef9e64f631fad9d38aeb737b5042da8363bca07caf67fd2a63a79c8c328e725b788702c5a3908f4fc393f0f7ec5b5f3faafe"; byte[] rlpBomb = Hex.decode(rlpBombStr); boolean isProtected = false; try { RLPList res = RLP.decode2(rlpBomb); } catch (Exception ex) { // decode2 is protected! Throwable cause = ex; while (cause != null) { if (cause.getMessage().contains("Length") && cause.getMessage().contains("greater")) isProtected = true; cause = cause.getCause(); // To the next level } } assert isProtected; isProtected = false; try { Object decoded = RLP.decode(rlpBomb, 0).getDecoded(); } catch (Exception ex) { // decode is protected now too! Throwable cause = ex; while (cause != null) { if (cause.getMessage().contains("Length") && cause.getMessage().contains("greater")) isProtected = true; cause = cause.getCause(); // To the next level } } assert isProtected; } @Test public void testNestedListsBomb() { byte[] data = { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xd4, (byte)0xd4, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x08, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x04, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x21, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x01, (byte)0x00, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xc4, (byte)0xd4, (byte)0xd4, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xd1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x04, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xc4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0x0a, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x04, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x21, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xc4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0x0a, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xc4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0x0a, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x04, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x21, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xc4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0x0a, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x04, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xc4, (byte)0xd4, (byte)0xd4, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xd4, (byte)0xd4, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x01, (byte)0x00, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xc4, (byte)0xd4, (byte)0xd4, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xd1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xc1, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0x0a, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x80, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0xed, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0x00, (byte)0x00, (byte)0x21, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xc4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0x0a, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0xd4, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x04, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x21, (byte)0xd4, (byte)0xd4, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 }; boolean tooBigNestedFired = false; try { RLP.decode2(data); } catch (RuntimeException ex) { Throwable cause = ex; while (cause != null) { if (cause.getMessage().contains("max") && cause.getMessage().contains("depth")) tooBigNestedFired = true; cause = cause.getCause(); // To the next level } } assert tooBigNestedFired; } @Test public void testDepthLimit() { byte[] rlp = Hex.decode("f902fdf90217a09daf27b854a6e1272c2f3070f7729ba5f4891a9dc324c360a0ad32d1d62419f7a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934794790b8a3ce86e707ed0ed32bf89b3269692a23cc1a02b7e61e61837adb79b36eee4e1589b2c2140852bb105dc034d5cfa052c6ef5b8a0b36ebb69537e04d3bcd94a20bebcb12a8ef4715eb26fc1d19382392cc98db9b1a0c86bea989ed46040c5d1cbc39da108fb249bb9bf0804a5889e897f7e0c710864b90100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008606b539ecc193830a2acc832fefd882a410845668801a98d783010302844765746887676f312e352e31856c696e7578a0d82d30ce9d68e733738eee0c6f37c95968622878334f4f010e95acae000bb40188b34e28af786cc323f8e0f86f82d65e850ba43b740083015f9094ff45159c63fb01f45cd86767a020406f06faa8528820d3ff69fe230800801ba0d0ea8a650bf50b61b421e8275a79219988889c3e86460b323fb3d4d60bd80d3ca05a653410e7fd97786b3b503936127ece61ed3dcfabdbcbe8d7f06066f4a41687f86d822a3b850ba43b740082520894c47aaa860008be6f65b58c6c6e02a84e666efe318742087a56e84c00801ca0bc2b89b75b68e7ad8eb1db4de4aa550db79df3bd6430f2258fe55805ca7d7fe7a07d8b53c48f24788f21e3a26cfbd007cdab71a8ef7f28f6f6fae6ed4dcd4a0df1c0"); RLPElement rlpEl1 = RLP.decode2(rlp, 1); RLPElement rlpElLevel1 = ((RLPList) rlpEl1).get(0); assert !(rlpElLevel1 instanceof RLPList); RLPElement rlpEl2 = RLP.decode2(rlp, 2); RLPElement rlpEl2Level1 = ((RLPList) rlpEl2).get(0); assert rlpEl2Level1 instanceof RLPList; RLPElement txList = ((RLPList) rlpEl2Level1).get(1); assert !(txList instanceof RLPList); RLPElement rlpEl3 = RLP.decode2(rlp, 3); RLPElement rlpEl3Level1 = ((RLPList) rlpEl3).get(0); assert rlpEl3Level1 instanceof RLPList; RLPElement rlpEl3Level2 = ((RLPList) rlpEl3Level1).get(1); assert rlpEl3Level2 instanceof RLPList; RLPElement rlpEl3Level3 = ((RLPList) rlpEl3Level2).get(0); assert !(rlpEl3Level3 instanceof RLPList); Transaction tx = new Transaction(rlpEl3Level3.getRLPData()); assertArrayEquals(Hex.decode("3e15c330e00f3af7ceeeeb10c27237845a034399c151f8d69708fd3ee45c09c6"), tx.getHash()); } @Test public void testWrapUnwrap() { byte[] shortItemData = new byte[] {(byte) 0x81}; byte[] longItemData = new byte[57]; new Random().nextBytes(longItemData); byte[] nullArray = RLP.encodeElement(new byte[] {}); byte[] singleZero = RLP.encodeElement(new byte[] {0}); byte[] singleByte = RLP.encodeElement(new byte[] {1}); byte[] shortItem = RLP.encodeElement(shortItemData); byte[] longItem = RLP.encodeElement(longItemData); byte[] shortList = RLP.encodeList(shortItem, shortItem, shortItem); byte[] longList = RLP.encodeList(longItem, longItem, longItem); byte[] encoded = RLP.wrapList(nullArray, singleZero, singleByte, shortItem, longItem, shortList, longList, shortItemData, longItemData); RLPList decoded = RLP.unwrapList(encoded); assertArrayEquals(nullArray, decoded.get(0).getRLPData()); assertArrayEquals(singleZero, decoded.get(1).getRLPData()); assertArrayEquals(singleByte, decoded.get(2).getRLPData()); assertArrayEquals(shortItem, decoded.get(3).getRLPData()); assertArrayEquals(longItem, decoded.get(4).getRLPData()); assertArrayEquals(shortList, decoded.get(5).getRLPData()); assertArrayEquals(longList, decoded.get(6).getRLPData()); assertArrayEquals(shortItemData, decoded.get(7).getRLPData()); assertArrayEquals(longItemData, decoded.get(8).getRLPData()); } }
157,584
86.20808
14,428
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/util/CompactEncoderTest.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.util; import org.junit.Test; import static org.junit.Assert.assertArrayEquals; public class CompactEncoderTest { private final static byte T = 16; // terminator @Test public void testCompactEncodeOddCompact() { byte[] test = new byte[]{1, 2, 3, 4, 5}; byte[] expectedData = new byte[]{0x11, 0x23, 0x45}; assertArrayEquals("odd compact encode fail", expectedData, CompactEncoder.packNibbles(test)); } @Test public void testCompactEncodeEvenCompact() { byte[] test = new byte[]{0, 1, 2, 3, 4, 5}; byte[] expectedData = new byte[]{0x00, 0x01, 0x23, 0x45}; assertArrayEquals("even compact encode fail", expectedData, CompactEncoder.packNibbles(test)); } @Test public void testCompactEncodeEvenTerminated() { byte[] test = new byte[]{0, 15, 1, 12, 11, 8, T}; byte[] expectedData = new byte[]{0x20, 0x0f, 0x1c, (byte) 0xb8}; assertArrayEquals("even terminated compact encode fail", expectedData, CompactEncoder.packNibbles(test)); } @Test public void testCompactEncodeOddTerminated() { byte[] test = new byte[]{15, 1, 12, 11, 8, T}; byte[] expectedData = new byte[]{0x3f, 0x1c, (byte) 0xb8}; assertArrayEquals("odd terminated compact encode fail", expectedData, CompactEncoder.packNibbles(test)); } @Test public void testCompactDecodeOddCompact() { byte[] test = new byte[]{0x11, 0x23, 0x45}; byte[] expected = new byte[]{1, 2, 3, 4, 5}; assertArrayEquals("odd compact decode fail", expected, CompactEncoder.unpackToNibbles(test)); } @Test public void testCompactDecodeEvenCompact() { byte[] test = new byte[]{0x00, 0x01, 0x23, 0x45}; byte[] expected = new byte[]{0, 1, 2, 3, 4, 5}; assertArrayEquals("even compact decode fail", expected, CompactEncoder.unpackToNibbles(test)); } @Test public void testCompactDecodeEvenTerminated() { byte[] test = new byte[]{0x20, 0x0f, 0x1c, (byte) 0xb8}; byte[] expected = new byte[]{0, 15, 1, 12, 11, 8, T}; assertArrayEquals("even terminated compact decode fail", expected, CompactEncoder.unpackToNibbles(test)); } @Test public void testCompactDecodeOddTerminated() { byte[] test = new byte[]{0x3f, 0x1c, (byte) 0xb8}; byte[] expected = new byte[]{15, 1, 12, 11, 8, T}; assertArrayEquals("odd terminated compact decode fail", expected, CompactEncoder.unpackToNibbles(test)); } @Test public void testCompactHexEncode_1() { byte[] test = "stallion".getBytes(); byte[] result = new byte[]{7, 3, 7, 4, 6, 1, 6, 12, 6, 12, 6, 9, 6, 15, 6, 14, T}; assertArrayEquals(result, CompactEncoder.binToNibbles(test)); } @Test public void testCompactHexEncode_2() { byte[] test = "verb".getBytes(); byte[] result = new byte[]{7, 6, 6, 5, 7, 2, 6, 2, T}; assertArrayEquals(result, CompactEncoder.binToNibbles(test)); } @Test public void testCompactHexEncode_3() { byte[] test = "puppy".getBytes(); byte[] result = new byte[]{7, 0, 7, 5, 7, 0, 7, 0, 7, 9, T}; assertArrayEquals(result, CompactEncoder.binToNibbles(test)); } }
4,067
37.742857
113
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/util/UtilsTest.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.util; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.spongycastle.util.Arrays; import org.spongycastle.util.encoders.Hex; import java.math.BigInteger; import java.util.Locale; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; /** * @author Roman Mandeleil * @since 17.05.14 */ public class UtilsTest { private Locale defaultLocale; @Before public void setUp() throws Exception { defaultLocale = Locale.getDefault(); Locale.setDefault(Locale.US); } @After public void tearDown() throws Exception { Locale.setDefault(defaultLocale); } @Test public void testGetValueShortString1() { int aaa; String expected = "123\u00b7(10^24)"; String result = Utils.getValueShortString(new BigInteger("123456789123445654363653463")); assertEquals(expected, result); } @Test public void testGetValueShortString2() { String expected = "123\u00b7(10^3)"; String result = Utils.getValueShortString(new BigInteger("123456")); assertEquals(expected, result); } @Test public void testGetValueShortString3() { String expected = "1\u00b7(10^3)"; String result = Utils.getValueShortString(new BigInteger("1234")); assertEquals(expected, result); } @Test public void testGetValueShortString4() { String expected = "123\u00b7(10^0)"; String result = Utils.getValueShortString(new BigInteger("123")); assertEquals(expected, result); } @Test public void testGetValueShortString5() { byte[] decimal = Hex.decode("3913517ebd3c0c65000000"); String expected = "69\u00b7(10^24)"; String result = Utils.getValueShortString(new BigInteger(decimal)); assertEquals(expected, result); } @Test public void testAddressStringToBytes() { // valid address String HexStr = "6c386a4b26f73c802f34673f7248bb118f97424a"; byte[] expected = Hex.decode(HexStr); byte[] result = Utils.addressStringToBytes(HexStr); assertEquals(Arrays.areEqual(expected, result), true); // invalid address, we removed the last char so it cannot decode HexStr = "6c386a4b26f73c802f34673f7248bb118f97424"; expected = null; result = Utils.addressStringToBytes(HexStr); assertEquals(expected, result); // invalid address, longer than 20 bytes HexStr = new String(Hex.encode("I am longer than 20 bytes, i promise".getBytes())); expected = null; result = Utils.addressStringToBytes(HexStr); assertEquals(expected, result); // invalid address, shorter than 20 bytes HexStr = new String(Hex.encode("I am short".getBytes())); expected = null; result = Utils.addressStringToBytes(HexStr); assertEquals(expected, result); } @Test public void testIsHexEncoded() { assertTrue(Utils.isHexEncoded("AAA")); assertTrue(Utils.isHexEncoded("6c386a4b26f73c802f34673f7248bb118f97424a")); assertFalse(Utils.isHexEncoded(null)); assertFalse(Utils.isHexEncoded("I am not hex")); assertTrue(Utils.isHexEncoded("")); assertTrue(Utils.isHexEncoded( "6c386a4b26f73c802f34673f7248bb118f97424a" + "6c386a4b26f73c802f34673f7248bb118f97424a" + "6c386a4b26f73c802f34673f7248bb118f97424a" + "6c386a4b26f73c802f34673f7248bb118f97424a" + "6c386a4b26f73c802f34673f7248bb118f97424a" + "6c386a4b26f73c802f34673f7248bb118f97424a" + "6c386a4b26f73c802f34673f7248bb118f97424a")); } @Test public void testLongToTimePeriod() { assertEquals("2.99s", Utils.longToTimePeriod(3000 - 12)); assertEquals("1d21h", Utils.longToTimePeriod(45L * 3600 * 1000)); } }
4,865
32.102041
97
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/util/StandaloneBlockchainTest.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.util; import org.ethereum.config.SystemProperties; import org.ethereum.crypto.ECKey; import org.ethereum.solidity.compiler.CompilationResult; import org.ethereum.solidity.compiler.Solc; import org.ethereum.solidity.compiler.SolidityCompiler; import org.ethereum.util.blockchain.SolidityCallResult; import org.ethereum.util.blockchain.SolidityContract; import org.ethereum.util.blockchain.StandaloneBlockchain; import org.junit.AfterClass; import org.junit.Assert; import org.junit.Test; import org.spongycastle.util.encoders.Hex; import java.math.BigInteger; import static org.ethereum.util.blockchain.EtherUtil.Unit.ETHER; import static org.ethereum.util.blockchain.EtherUtil.convert; /** * Created by Anton Nashatyrev on 06.07.2016. */ public class StandaloneBlockchainTest { @AfterClass public static void cleanup() { SystemProperties.resetToDefault(); } @Test public void constructorTest() { StandaloneBlockchain sb = new StandaloneBlockchain().withAutoblock(true); SolidityContract a = sb.submitNewContract( "contract A {" + " uint public a;" + " uint public b;" + " function A(uint a_, uint b_) {a = a_; b = b_; }" + "}", "A", 555, 777 ); Assert.assertEquals(BigInteger.valueOf(555), a.callConstFunction("a")[0]); Assert.assertEquals(BigInteger.valueOf(777), a.callConstFunction("b")[0]); SolidityContract b = sb.submitNewContract( "contract A {" + " string public a;" + " uint public b;" + " function A(string a_, uint b_) {a = a_; b = b_; }" + "}", "A", "This string is longer than 32 bytes...", 777 ); Assert.assertEquals("This string is longer than 32 bytes...", b.callConstFunction("a")[0]); Assert.assertEquals(BigInteger.valueOf(777), b.callConstFunction("b")[0]); } @Test public void fixedSizeArrayTest() { StandaloneBlockchain sb = new StandaloneBlockchain().withAutoblock(true); { SolidityContract a = sb.submitNewContract( "contract A {" + " uint public a;" + " uint public b;" + " address public c;" + " address public d;" + " function f(uint[2] arr, address[2] arr2) {a = arr[0]; b = arr[1]; c = arr2[0]; d = arr2[1];}" + "}"); ECKey addr1 = new ECKey(); ECKey addr2 = new ECKey(); a.callFunction("f", new Integer[]{111, 222}, new byte[][] {addr1.getAddress(), addr2.getAddress()}); Assert.assertEquals(BigInteger.valueOf(111), a.callConstFunction("a")[0]); Assert.assertEquals(BigInteger.valueOf(222), a.callConstFunction("b")[0]); Assert.assertArrayEquals(addr1.getAddress(), (byte[])a.callConstFunction("c")[0]); Assert.assertArrayEquals(addr2.getAddress(), (byte[])a.callConstFunction("d")[0]); } { ECKey addr1 = new ECKey(); ECKey addr2 = new ECKey(); SolidityContract a = sb.submitNewContract( "contract A {" + " uint public a;" + " uint public b;" + " address public c;" + " address public d;" + " function A(uint[2] arr, address a1, address a2) {a = arr[0]; b = arr[1]; c = a1; d = a2;}" + "}", "A", new Integer[]{111, 222}, addr1.getAddress(), addr2.getAddress()); Assert.assertEquals(BigInteger.valueOf(111), a.callConstFunction("a")[0]); Assert.assertEquals(BigInteger.valueOf(222), a.callConstFunction("b")[0]); Assert.assertArrayEquals(addr1.getAddress(), (byte[]) a.callConstFunction("c")[0]); Assert.assertArrayEquals(addr2.getAddress(), (byte[]) a.callConstFunction("d")[0]); String a1 = "0x1111111111111111111111111111111111111111"; String a2 = "0x2222222222222222222222222222222222222222"; } } @Test public void encodeTest1() { StandaloneBlockchain sb = new StandaloneBlockchain().withAutoblock(true); SolidityContract a = sb.submitNewContract( "contract A {" + " int public a;" + " function f(int a_) {a = a_;}" + "}"); a.callFunction("f", "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); BigInteger r = (BigInteger) a.callConstFunction("a")[0]; System.out.println(r.toString(16)); Assert.assertEquals(new BigInteger(Hex.decode("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")), r); } @Test public void encodeTest2() { StandaloneBlockchain sb = new StandaloneBlockchain().withAutoblock(true); SolidityContract a = sb.submitNewContract( "contract A {" + " uint public a;" + " function f(uint a_) {a = a_;}" + "}"); a.callFunction("f", "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); BigInteger r = (BigInteger) a.callConstFunction("a")[0]; System.out.println(r.toString(16)); Assert.assertEquals(new BigInteger(1, Hex.decode("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")), r); } @Test public void invalidTxTest() { // check that invalid tx doesn't break implementation StandaloneBlockchain sb = new StandaloneBlockchain(); ECKey alice = sb.getSender(); ECKey bob = new ECKey(); sb.sendEther(bob.getAddress(), BigInteger.valueOf(1000)); sb.setSender(bob); sb.sendEther(alice.getAddress(), BigInteger.ONE); sb.setSender(alice); sb.sendEther(bob.getAddress(), BigInteger.valueOf(2000)); sb.createBlock(); } @Test public void initBalanceTest() { // check StandaloneBlockchain.withAccountBalance method StandaloneBlockchain sb = new StandaloneBlockchain(); ECKey alice = sb.getSender(); ECKey bob = new ECKey(); sb.withAccountBalance(bob.getAddress(), convert(123, ETHER)); BigInteger aliceInitBal = sb.getBlockchain().getRepository().getBalance(alice.getAddress()); BigInteger bobInitBal = sb.getBlockchain().getRepository().getBalance(bob.getAddress()); assert convert(123, ETHER).equals(bobInitBal); sb.setSender(bob); sb.sendEther(alice.getAddress(), BigInteger.ONE); sb.createBlock(); assert convert(123, ETHER).compareTo(sb.getBlockchain().getRepository().getBalance(bob.getAddress())) > 0; assert aliceInitBal.add(BigInteger.ONE).equals(sb.getBlockchain().getRepository().getBalance(alice.getAddress())); } @Test public void addContractWithMetadataEvent() throws Exception { String contract = "contract A {" + " event Event(uint aaa);" + " function f(uint a) {emit Event(a); }" + "}"; SolidityCompiler.Result result = SolidityCompiler.getInstance().compileSrc( contract.getBytes(), false, true, SolidityCompiler.Options.ABI, SolidityCompiler.Options.BIN); CompilationResult cresult = CompilationResult.parse(result.output); CompilationResult.ContractMetadata contractMetadata = new CompilationResult.ContractMetadata(); contractMetadata.abi = cresult.getContracts().get(0).abi; contractMetadata.bin = cresult.getContracts().get(0).bin; StandaloneBlockchain sb = new StandaloneBlockchain().withAutoblock(true); SolidityContract newContract = sb.submitNewContract(contractMetadata); SolidityCallResult res = newContract.callFunction("f", 123); Assert.assertEquals(1, res.getEvents().size()); Assert.assertEquals("Event", res.getEvents().get(0).function.name); Assert.assertEquals(BigInteger.valueOf(123), res.getEvents().get(0).args[0]); } }
9,216
44.181373
130
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/sync/ShortSyncTest.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.sync; import org.ethereum.config.NoAutoscan; 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.BlockHeader; import org.ethereum.core.Blockchain; import org.ethereum.core.TransactionReceipt; import org.ethereum.facade.Ethereum; import org.ethereum.facade.EthereumFactory; import org.ethereum.listener.EthereumListenerAdapter; import org.ethereum.net.eth.handler.Eth62; import org.ethereum.net.eth.handler.EthHandler; import org.ethereum.net.eth.message.*; import org.ethereum.net.message.Message; import org.ethereum.net.p2p.DisconnectMessage; import org.ethereum.net.rlpx.Node; import org.ethereum.net.server.Channel; import org.ethereum.util.blockchain.StandaloneBlockchain; import org.junit.*; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Scope; 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.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Random; import java.util.concurrent.CountDownLatch; import static java.util.concurrent.TimeUnit.SECONDS; import static org.ethereum.util.FileUtil.recursiveDelete; import static org.junit.Assert.fail; import static org.spongycastle.util.encoders.Hex.decode; /** * @author Mikhail Kalinin * @since 14.12.2015 */ @Ignore("Long network tests") public class ShortSyncTest { private static BigInteger minDifficultyBackup; private static Node nodeA; private static List<Block> mainB1B10; private static List<Block> forkB1B5B8_; private static Block b10; private static Block b8_; private Ethereum ethereumA; private Ethereum ethereumB; private EthHandler ethA; private String testDbA; private String testDbB; @BeforeClass public static void setup() throws IOException, URISyntaxException { SystemProperties.getDefault().setBlockchainConfig(StandaloneBlockchain.getEasyMiningConfig()); nodeA = new Node("enode://3973cb86d7bef9c96e5d589601d788370f9e24670dcba0480c0b3b1b0647d13d0f0fffed115dd2d4b5ca1929287839dcd4e77bdc724302b44ae48622a8766ee6@localhost:30334"); SysPropConfigA.props.overrideParams( "peer.listen.port", "30334", "peer.privateKey", "3ec771c31cac8c0dba77a69e503765701d3c2bb62435888d4ffa38fed60c445c", // nodeId: 3973cb86d7bef9c96e5d589601d788370f9e24670dcba0480c0b3b1b0647d13d0f0fffed115dd2d4b5ca1929287839dcd4e77bdc724302b44ae48622a8766ee6 "genesis", "genesis-light.json" ); SysPropConfigB.props.overrideParams( "peer.listen.port", "30335", "peer.privateKey", "6ef8da380c27cea8fdf7448340ea99e8e2268fc2950d79ed47cbf6f85dc977ec", "genesis", "genesis-light.json", "sync.enabled", "true" ); mainB1B10 = loadBlocks("sync/main-b1-b10.dmp"); forkB1B5B8_ = loadBlocks("sync/fork-b1-b5-b8_.dmp"); b10 = mainB1B10.get(mainB1B10.size() - 1); b8_ = forkB1B5B8_.get(forkB1B5B8_.size() - 1); } private static List<Block> loadBlocks(String path) throws URISyntaxException, IOException { URL url = ClassLoader.getSystemResource(path); File file = new File(url.toURI()); List<String> strData = Files.readAllLines(file.toPath(), StandardCharsets.UTF_8); List<Block> blocks = new ArrayList<>(strData.size()); for (String rlp : strData) { blocks.add(new Block(decode(rlp))); } return blocks; } @AfterClass public static void cleanup() { SystemProperties.getDefault().setBlockchainConfig(MainNetConfig.INSTANCE); } @Before public void setupTest() throws InterruptedException { testDbA = "test_db_" + new BigInteger(32, new Random()); testDbB = "test_db_" + new BigInteger(32, new Random()); SysPropConfigA.props.setDataBaseDir(testDbA); SysPropConfigB.props.setDataBaseDir(testDbB); } @After public void cleanupTest() { recursiveDelete(testDbA); recursiveDelete(testDbB); SysPropConfigA.eth62 = null; } // positive gap, A on main, B on main // expected: B downloads missed blocks from A => B on main @Test public void test1() throws InterruptedException { setupPeers(); // A == B == genesis Blockchain blockchainA = (Blockchain) ethereumA.getBlockchain(); for (Block b : mainB1B10) { blockchainA.tryToConnect(b); } // A == b10, B == genesis final CountDownLatch semaphore = new CountDownLatch(1); ethereumB.addListener(new EthereumListenerAdapter() { @Override public void onBlock(Block block, List<TransactionReceipt> receipts) { if (block.isEqual(b10)) { semaphore.countDown(); } } }); ethA.sendNewBlock(b10); semaphore.await(10, SECONDS); // check if B == b10 if(semaphore.getCount() > 0) { fail("PeerB bestBlock is incorrect"); } } // positive gap, A on fork, B on main // positive gap, A on fork, B on fork (same story) // expected: B downloads missed blocks from A => B on A's fork @Test public void test2() throws InterruptedException { setupPeers(); // A == B == genesis Blockchain blockchainA = (Blockchain) ethereumA.getBlockchain(); for (Block b : forkB1B5B8_) { blockchainA.tryToConnect(b); } // A == b8', B == genesis final CountDownLatch semaphore = new CountDownLatch(1); ethereumB.addListener(new EthereumListenerAdapter() { @Override public void onBlock(Block block, List<TransactionReceipt> receipts) { if (block.isEqual(b8_)) { semaphore.countDown(); } } }); ethA.sendNewBlock(b8_); semaphore.await(10, SECONDS); // check if B == b8' if(semaphore.getCount() > 0) { fail("PeerB bestBlock is incorrect"); } } // positive gap, A on main, B on fork // expected: B finds common ancestor and downloads missed blocks from A => B on main @Test public void test3() throws InterruptedException { setupPeers(); // A == B == genesis Blockchain blockchainA = (Blockchain) ethereumA.getBlockchain(); Blockchain blockchainB = (Blockchain) ethereumB.getBlockchain(); for (Block b : mainB1B10) { blockchainA.tryToConnect(b); } for (Block b : forkB1B5B8_) { blockchainB.tryToConnect(b); } // A == b10, B == b8' final CountDownLatch semaphore = new CountDownLatch(1); ethereumB.addListener(new EthereumListenerAdapter() { @Override public void onBlock(Block block, List<TransactionReceipt> receipts) { if (block.isEqual(b10)) { semaphore.countDown(); } } }); ethA.sendNewBlock(b10); semaphore.await(10, SECONDS); // check if B == b10 if(semaphore.getCount() > 0) { fail("PeerB bestBlock is incorrect"); } } // negative gap, A on main, B on main // expected: B skips A's block as already imported => B on main @Test public void test4() throws InterruptedException { setupPeers(); final Block b5 = mainB1B10.get(4); Block b9 = mainB1B10.get(8); // A == B == genesis Blockchain blockchainA = (Blockchain) ethereumA.getBlockchain(); Blockchain blockchainB = (Blockchain) ethereumB.getBlockchain(); for (Block b : mainB1B10) { blockchainA.tryToConnect(b); if (b.isEqual(b5)) break; } for (Block b : mainB1B10) { blockchainB.tryToConnect(b); if (b.isEqual(b9)) break; } // A == b5, B == b9 final CountDownLatch semaphore = new CountDownLatch(1); ethereumB.addListener(new EthereumListenerAdapter() { @Override public void onBlock(Block block, List<TransactionReceipt> receipts) { if (block.isEqual(b10)) { semaphore.countDown(); } } }); ethA.sendNewBlockHashes(b5); for (Block b : mainB1B10) { blockchainA.tryToConnect(b); } // A == b10 ethA.sendNewBlock(b10); semaphore.await(10, SECONDS); // check if B == b10 if(semaphore.getCount() > 0) { fail("PeerB bestBlock is incorrect"); } } // negative gap, A on fork, B on main // negative gap, A on fork, B on fork (same story) // expected: B downloads A's fork and imports it as NOT_BEST => B on its chain @Test public void test5() throws InterruptedException { setupPeers(); Block b9 = mainB1B10.get(8); // A == B == genesis Blockchain blockchainA = (Blockchain) ethereumA.getBlockchain(); Blockchain blockchainB = (Blockchain) ethereumB.getBlockchain(); for (Block b : forkB1B5B8_) { blockchainA.tryToConnect(b); } for (Block b : mainB1B10) { blockchainB.tryToConnect(b); if (b.isEqual(b9)) break; } // A == b8', B == b9 final CountDownLatch semaphore = new CountDownLatch(1); final CountDownLatch semaphoreB8_ = new CountDownLatch(1); ethereumB.addListener(new EthereumListenerAdapter() { @Override public void onBlock(Block block, List<TransactionReceipt> receipts) { if (block.isEqual(b10)) { semaphore.countDown(); } if (block.isEqual(b8_)) { semaphoreB8_.countDown(); } } }); ethA.sendNewBlockHashes(b8_); semaphoreB8_.await(10, SECONDS); if(semaphoreB8_.getCount() > 0) { fail("PeerB didn't import b8'"); } for (Block b : mainB1B10) { blockchainA.tryToConnect(b); } // A == b10 ethA.sendNewBlock(b10); semaphore.await(10, SECONDS); // check if B == b10 if(semaphore.getCount() > 0) { fail("PeerB bestBlock is incorrect"); } } // negative gap, A on main, B on fork // expected: B finds common ancestor and downloads A's blocks => B on main @Test public void test6() throws InterruptedException { setupPeers(); final Block b7 = mainB1B10.get(6); // A == B == genesis Blockchain blockchainA = (Blockchain) ethereumA.getBlockchain(); Blockchain blockchainB = (Blockchain) ethereumB.getBlockchain(); for (Block b : mainB1B10) { blockchainA.tryToConnect(b); if (b.isEqual(b7)) break; } for (Block b : forkB1B5B8_) { blockchainB.tryToConnect(b); } // A == b7, B == b8' final CountDownLatch semaphore = new CountDownLatch(1); final CountDownLatch semaphoreB7 = new CountDownLatch(1); ethereumB.addListener(new EthereumListenerAdapter() { @Override public void onBlock(Block block, List<TransactionReceipt> receipts) { if (block.isEqual(b7)) { semaphoreB7.countDown(); } if (block.isEqual(b10)) { semaphore.countDown(); } } }); ethA.sendNewBlockHashes(b7); semaphoreB7.await(10, SECONDS); // check if B == b7 if(semaphoreB7.getCount() > 0) { fail("PeerB didn't recover a gap"); } for (Block b : mainB1B10) { blockchainA.tryToConnect(b); } // A == b10 ethA.sendNewBlock(b10); semaphore.await(10, SECONDS); // check if B == b10 if(semaphore.getCount() > 0) { fail("PeerB bestBlock is incorrect"); } } // positive gap, A on fork, B on main // A does a re-branch to main // expected: B downloads main blocks from A => B on main @Test public void test7() throws InterruptedException { setupPeers(); Block b4 = mainB1B10.get(3); // A == B == genesis final Blockchain blockchainA = (Blockchain) ethereumA.getBlockchain(); Blockchain blockchainB = (Blockchain) ethereumB.getBlockchain(); for (Block b : forkB1B5B8_) { blockchainA.tryToConnect(b); } for (Block b : mainB1B10) { blockchainB.tryToConnect(b); if (b.isEqual(b4)) break; } // A == b8', B == b4 ethereumB.addListener(new EthereumListenerAdapter() { @Override public void onRecvMessage(Channel channel, Message message) { if (message instanceof NewBlockMessage) { // it's time to do a re-branch for (Block b : mainB1B10) { blockchainA.tryToConnect(b); } } } }); final CountDownLatch semaphore = new CountDownLatch(1); ethereumB.addListener(new EthereumListenerAdapter() { @Override public void onBlock(Block block, List<TransactionReceipt> receipts) { if (block.isEqual(b10)) { semaphore.countDown(); } } }); ethA.sendNewBlock(b8_); ethA.sendNewBlock(b10); semaphore.await(10, SECONDS); // check if B == b10 if(semaphore.getCount() > 0) { fail("PeerB bestBlock is incorrect"); } } // negative gap, A on fork, B on main // A does a re-branch to main // expected: B downloads A's fork and imports it as NOT_BEST => B on main @Test public void test8() throws InterruptedException { setupPeers(); final Block b7_ = forkB1B5B8_.get(6); Block b8 = mainB1B10.get(7); // A == B == genesis final Blockchain blockchainA = (Blockchain) ethereumA.getBlockchain(); Blockchain blockchainB = (Blockchain) ethereumB.getBlockchain(); for (Block b : forkB1B5B8_) { blockchainA.tryToConnect(b); if (b.isEqual(b7_)) break; } for (Block b : mainB1B10) { blockchainB.tryToConnect(b); if (b.isEqual(b8)) break; } // A == b7', B == b8 final CountDownLatch semaphore = new CountDownLatch(1); final CountDownLatch semaphoreB7_ = new CountDownLatch(1); ethereumB.addListener(new EthereumListenerAdapter() { @Override public void onBlock(Block block, List<TransactionReceipt> receipts) { if (block.isEqual(b7_)) { // it's time to do a re-branch for (Block b : mainB1B10) { blockchainA.tryToConnect(b); } semaphoreB7_.countDown(); } if (block.isEqual(b10)) { semaphore.countDown(); } } }); ethA.sendNewBlockHashes(b7_); semaphoreB7_.await(10, SECONDS); if(semaphoreB7_.getCount() > 0) { fail("PeerB didn't import b7'"); } ethA.sendNewBlock(b10); semaphore.await(10, SECONDS); // check if B == b10 if(semaphore.getCount() > 0) { fail("PeerB bestBlock is incorrect"); } } // positive gap, A on fork, B on main // A doesn't send common ancestor // expected: B drops A and all its blocks => B on main @Test public void test9() throws InterruptedException { // handler which don't send an ancestor SysPropConfigA.eth62 = new Eth62() { @Override protected void processGetBlockHeaders(GetBlockHeadersMessage msg) { // process init header request correctly if (msg.getMaxHeaders() == 1) { super.processGetBlockHeaders(msg); return; } List<BlockHeader> headers = new ArrayList<>(); for (int i = 7; i < mainB1B10.size(); i++) { headers.add(mainB1B10.get(i).getHeader()); } BlockHeadersMessage response = new BlockHeadersMessage(headers); sendMessage(response); } }; setupPeers(); Block b6 = mainB1B10.get(5); // A == B == genesis final Blockchain blockchainA = (Blockchain) ethereumA.getBlockchain(); Blockchain blockchainB = (Blockchain) ethereumB.getBlockchain(); for (Block b : forkB1B5B8_) { blockchainA.tryToConnect(b); } for (Block b : mainB1B10) { blockchainB.tryToConnect(b); if (b.isEqual(b6)) break; } // A == b8', B == b6 ethA.sendNewBlock(b8_); final CountDownLatch semaphoreDisconnect = new CountDownLatch(1); ethereumA.addListener(new EthereumListenerAdapter() { @Override public void onRecvMessage(Channel channel, Message message) { if (message instanceof DisconnectMessage) { semaphoreDisconnect.countDown(); } } }); semaphoreDisconnect.await(10, SECONDS); // check if peer was dropped if(semaphoreDisconnect.getCount() > 0) { fail("PeerA is not dropped"); } // back to usual handler SysPropConfigA.eth62 = null; for (Block b : mainB1B10) { blockchainA.tryToConnect(b); } final CountDownLatch semaphore = new CountDownLatch(1); ethereumB.addListener(new EthereumListenerAdapter() { @Override public void onBlock(Block block, List<TransactionReceipt> receipts) { if (block.isEqual(b10)) { semaphore.countDown(); } } }); final CountDownLatch semaphoreConnect = new CountDownLatch(1); ethereumB.addListener(new EthereumListenerAdapter() { @Override public void onPeerAddedToSyncPool(Channel peer) { semaphoreConnect.countDown(); } }); ethereumB.connect(nodeA); // await connection semaphoreConnect.await(10, SECONDS); if(semaphoreConnect.getCount() > 0) { fail("PeerB is not able to connect to PeerA"); } ethA.sendNewBlock(b10); semaphore.await(10, SECONDS); // check if B == b10 if(semaphore.getCount() > 0) { fail("PeerB bestBlock is incorrect"); } } // negative gap, A on fork, B on main // A doesn't send the gap block in ancestor response // expected: B drops A and all its blocks => B on main @Test public void test10() throws InterruptedException { // handler which don't send a gap block SysPropConfigA.eth62 = new Eth62() { @Override protected void processGetBlockHeaders(GetBlockHeadersMessage msg) { if (msg.getMaxHeaders() == 1) { super.processGetBlockHeaders(msg); return; } List<BlockHeader> headers = new ArrayList<>(); for (int i = 0; i < forkB1B5B8_.size() - 1; i++) { headers.add(forkB1B5B8_.get(i).getHeader()); } BlockHeadersMessage response = new BlockHeadersMessage(headers); sendMessage(response); } }; setupPeers(); Block b9 = mainB1B10.get(8); // A == B == genesis final Blockchain blockchainA = (Blockchain) ethereumA.getBlockchain(); Blockchain blockchainB = (Blockchain) ethereumB.getBlockchain(); for (Block b : forkB1B5B8_) { blockchainA.tryToConnect(b); } for (Block b : mainB1B10) { blockchainB.tryToConnect(b); if (b.isEqual(b9)) break; } // A == b8', B == b9 ethA.sendNewBlockHashes(b8_); final CountDownLatch semaphoreDisconnect = new CountDownLatch(1); ethereumA.addListener(new EthereumListenerAdapter() { @Override public void onRecvMessage(Channel channel, Message message) { if (message instanceof DisconnectMessage) { semaphoreDisconnect.countDown(); } } }); semaphoreDisconnect.await(10, SECONDS); // check if peer was dropped if(semaphoreDisconnect.getCount() > 0) { fail("PeerA is not dropped"); } // back to usual handler SysPropConfigA.eth62 = null; final CountDownLatch semaphore = new CountDownLatch(1); ethereumB.addListener(new EthereumListenerAdapter() { @Override public void onBlock(Block block, List<TransactionReceipt> receipts) { if (block.isEqual(b10)) { semaphore.countDown(); } } }); final CountDownLatch semaphoreConnect = new CountDownLatch(1); ethereumB.addListener(new EthereumListenerAdapter() { @Override public void onPeerAddedToSyncPool(Channel peer) { semaphoreConnect.countDown(); } }); ethereumB.connect(nodeA); // await connection semaphoreConnect.await(10, SECONDS); if(semaphoreConnect.getCount() > 0) { fail("PeerB is not able to connect to PeerA"); } for (Block b : mainB1B10) { blockchainA.tryToConnect(b); } // A == b10 ethA.sendNewBlock(b10); semaphore.await(10, SECONDS); // check if B == b10 if(semaphore.getCount() > 0) { fail("PeerB bestBlock is incorrect"); } } // A sends block with low TD to B // expected: B skips this block @Test public void test11() throws InterruptedException { Block b5 = mainB1B10.get(4); final Block b6_ = forkB1B5B8_.get(5); setupPeers(); // A == B == genesis Blockchain blockchainA = (Blockchain) ethereumA.getBlockchain(); final Blockchain blockchainB = (Blockchain) ethereumB.getBlockchain(); for (Block b : forkB1B5B8_) { blockchainA.tryToConnect(b); } for (Block b : mainB1B10) { blockchainB.tryToConnect(b); if (b.isEqual(b5)) break; } // A == b8', B == b5 final CountDownLatch semaphore1 = new CountDownLatch(1); final CountDownLatch semaphore2 = new CountDownLatch(1); ethereumB.addListener(new EthereumListenerAdapter() { @Override public void onBlock(Block block, List<TransactionReceipt> receipts) { if (block.isEqual(b6_)) { if (semaphore1.getCount() > 0) { semaphore1.countDown(); } else { semaphore2.countDown(); } } } }); ethA.sendNewBlock(b6_); semaphore1.await(10, SECONDS); if(semaphore1.getCount() > 0) { fail("PeerB doesn't accept block with higher TD"); } for (Block b : mainB1B10) { blockchainB.tryToConnect(b); } // B == b10 ethA.sendNewBlock(b6_); semaphore2.await(5, SECONDS); // check if B skips b6' if(semaphore2.getCount() == 0) { fail("PeerB doesn't skip block with lower TD"); } } // bodies validation: A doesn't send bodies corresponding to headers which were sent previously // expected: B drops A @Test public void test12() throws InterruptedException { SysPropConfigA.eth62 = new Eth62() { @Override protected void processGetBlockBodies(GetBlockBodiesMessage msg) { List<byte[]> bodies = Arrays.asList( mainB1B10.get(0).getEncodedBody() ); BlockBodiesMessage response = new BlockBodiesMessage(bodies); sendMessage(response); } }; setupPeers(); Blockchain blockchainA = (Blockchain) ethereumA.getBlockchain(); for (Block b : mainB1B10) { blockchainA.tryToConnect(b); } // A == b10, B == genesis final CountDownLatch semaphoreDisconnect = new CountDownLatch(1); ethereumA.addListener(new EthereumListenerAdapter() { @Override public void onRecvMessage(Channel channel, Message message) { if (message instanceof DisconnectMessage) { semaphoreDisconnect.countDown(); } } }); ethA.sendNewBlock(b10); semaphoreDisconnect.await(10, SECONDS); // check if peer was dropped if(semaphoreDisconnect.getCount() > 0) { fail("PeerA is not dropped"); } } // bodies validation: headers order is incorrect in the response, reverse = true // expected: B drops A @Test public void test13() throws InterruptedException { Block b9 = mainB1B10.get(8); SysPropConfigA.eth62 = new Eth62() { @Override protected void processGetBlockHeaders(GetBlockHeadersMessage msg) { if (msg.getMaxHeaders() == 1) { super.processGetBlockHeaders(msg); return; } List<BlockHeader> headers = Arrays.asList( forkB1B5B8_.get(7).getHeader(), forkB1B5B8_.get(6).getHeader(), forkB1B5B8_.get(4).getHeader(), forkB1B5B8_.get(5).getHeader() ); BlockHeadersMessage response = new BlockHeadersMessage(headers); sendMessage(response); } }; setupPeers(); Blockchain blockchainA = (Blockchain) ethereumA.getBlockchain(); Blockchain blockchainB = (Blockchain) ethereumB.getBlockchain(); for (Block b : forkB1B5B8_) { blockchainA.tryToConnect(b); } for (Block b : mainB1B10) { blockchainB.tryToConnect(b); if (b.isEqual(b9)) break; } // A == b8', B == b10 final CountDownLatch semaphoreDisconnect = new CountDownLatch(1); ethereumA.addListener(new EthereumListenerAdapter() { @Override public void onRecvMessage(Channel channel, Message message) { if (message instanceof DisconnectMessage) { semaphoreDisconnect.countDown(); } } }); ethA.sendNewBlockHashes(b8_); semaphoreDisconnect.await(10, SECONDS); // check if peer was dropped if(semaphoreDisconnect.getCount() > 0) { fail("PeerA is not dropped"); } } // bodies validation: ancestor's parent hash and header's hash does not match, reverse = true // expected: B drops A @Test public void test14() throws InterruptedException { Block b9 = mainB1B10.get(8); SysPropConfigA.eth62 = new Eth62() { @Override protected void processGetBlockHeaders(GetBlockHeadersMessage msg) { if (msg.getMaxHeaders() == 1) { super.processGetBlockHeaders(msg); return; } List<BlockHeader> headers = Arrays.asList( forkB1B5B8_.get(7).getHeader(), forkB1B5B8_.get(6).getHeader(), new BlockHeader(new byte[32], new byte[32], new byte[32], new byte[32], new byte[32], 6, new byte[] {0}, 0, 0, new byte[0], new byte[0], new byte[0]), forkB1B5B8_.get(4).getHeader() ); BlockHeadersMessage response = new BlockHeadersMessage(headers); sendMessage(response); } }; setupPeers(); Blockchain blockchainA = (Blockchain) ethereumA.getBlockchain(); Blockchain blockchainB = (Blockchain) ethereumB.getBlockchain(); for (Block b : forkB1B5B8_) { blockchainA.tryToConnect(b); } for (Block b : mainB1B10) { blockchainB.tryToConnect(b); if (b.isEqual(b9)) break; } // A == b8', B == b10 final CountDownLatch semaphoreDisconnect = new CountDownLatch(1); ethereumA.addListener(new EthereumListenerAdapter() { @Override public void onRecvMessage(Channel channel, Message message) { if (message instanceof DisconnectMessage) { semaphoreDisconnect.countDown(); } } }); ethA.sendNewBlockHashes(b8_); semaphoreDisconnect.await(10, SECONDS); // check if peer was dropped if(semaphoreDisconnect.getCount() > 0) { fail("PeerA is not dropped"); } } private void setupPeers() throws InterruptedException { ethereumA = EthereumFactory.createEthereum(SysPropConfigA.props, SysPropConfigA.class); ethereumB = EthereumFactory.createEthereum(SysPropConfigB.props, SysPropConfigB.class); ethereumA.addListener(new EthereumListenerAdapter() { @Override public void onEthStatusUpdated(Channel channel, StatusMessage statusMessage) { ethA = (EthHandler) channel.getEthHandler(); } }); final CountDownLatch semaphore = new CountDownLatch(1); ethereumB.addListener(new EthereumListenerAdapter() { @Override public void onPeerAddedToSyncPool(Channel peer) { semaphore.countDown(); } }); ethereumB.connect(nodeA); semaphore.await(10, SECONDS); if(semaphore.getCount() > 0) { fail("Failed to set up peers"); } } @Configuration @NoAutoscan public static class SysPropConfigA { static SystemProperties props = new SystemProperties(); static Eth62 eth62 = null; @Bean public SystemProperties systemProperties() { return props; } @Bean @Scope("prototype") public Eth62 eth62() throws IllegalAccessException, InstantiationException { if (eth62 != null) return eth62; return new Eth62(); } } @Configuration @NoAutoscan public static class SysPropConfigB { static SystemProperties props = new SystemProperties(); @Bean public SystemProperties systemProperties() { return props; } } }
32,742
29.17788
181
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/sync/SyncQueueImplTest.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.sync; import org.ethereum.TestUtils; import org.ethereum.core.Block; import org.ethereum.core.BlockHeader; import org.ethereum.core.BlockHeaderWrapper; import org.ethereum.crypto.HashUtil; import org.ethereum.db.ByteArrayWrapper; import org.ethereum.util.FastByteComparisons; import org.ethereum.validator.DependentBlockHeaderRule; import org.junit.Assert; import org.junit.Test; import java.util.*; import java.util.stream.Collectors; import static org.ethereum.crypto.HashUtil.randomPeerId; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; /** * Created by Anton Nashatyrev on 30.05.2016. */ public class SyncQueueImplTest { byte[] peer0 = new byte[32]; private static final int DEFAULT_REQUEST_LEN = 192; @Test public void test1() { List<Block> randomChain = TestUtils.getRandomChain(new byte[32], 0, 1024); SyncQueueImpl syncQueue = new SyncQueueImpl(randomChain.subList(0, 32)); SyncQueueIfc.HeadersRequest headersRequest = syncQueue.requestHeaders(DEFAULT_REQUEST_LEN, 1, Integer.MAX_VALUE).iterator().next(); System.out.println(headersRequest); syncQueue.addHeaders(createHeadersFromBlocks(TestUtils.getRandomChain(randomChain.get(16).getHash(), 17, 64), peer0)); syncQueue.addHeaders(createHeadersFromBlocks(randomChain.subList(32, 1024), peer0)); } @Test public void test2() { List<Block> randomChain = TestUtils.getRandomChain(new byte[32], 0, 1024); Peer[] peers = new Peer[10]; peers[0] = new Peer(randomChain); for (int i = 1; i < peers.length; i++) { peers[i] = new Peer(TestUtils.getRandomChain(TestUtils.randomBytes(32), 1, 1024)); } } @Test public void testHeadersSplit() { // 1, 2, 3, 4, 5 SyncQueueImpl.HeadersRequestImpl headersRequest = new SyncQueueImpl.HeadersRequestImpl(1, 5, false); List<SyncQueueIfc.HeadersRequest> requests = headersRequest.split(2); assert requests.size() == 3; // 1, 2 assert requests.get(0).getStart() == 1; assert requests.get(0).getCount() == 2; // 3, 4 assert requests.get(1).getStart() == 3; assert requests.get(1).getCount() == 2; // 5 assert requests.get(2).getStart() == 5; assert requests.get(2).getCount() == 1; } @Test public void testReverseHeaders1() { List<Block> randomChain = TestUtils.getRandomChain(new byte[32], 0, 699); List<Block> randomChain1 = TestUtils.getRandomChain(new byte[32], 0, 699); Peer[] peers = new Peer[]{new Peer(randomChain), new Peer(randomChain, false), new Peer(randomChain1)}; SyncQueueReverseImpl syncQueue = new SyncQueueReverseImpl(randomChain.get(randomChain.size() - 1).getHash(), true); List<BlockHeaderWrapper> result = new ArrayList<>(); int peerIdx = 1; Random rnd = new Random(); int cnt = 0; while (cnt < 1000) { System.out.println("Cnt: " + cnt++); Collection<SyncQueueIfc.HeadersRequest> headersRequests = syncQueue.requestHeaders(20, 5, Integer.MAX_VALUE); if (headersRequests == null) break; for (SyncQueueIfc.HeadersRequest request : headersRequests) { System.out.println("Req: " + request); List<BlockHeader> headers = rnd.nextBoolean() ? peers[peerIdx].getHeaders(request) : peers[peerIdx].getRandomHeaders(10); // List<BlockHeader> headers = peers[0].getHeaders(request); peerIdx = (peerIdx + 1) % peers.length; List<BlockHeaderWrapper> ret = syncQueue.addHeaders(createHeadersFromHeaders(headers, peer0)); result.addAll(ret); System.out.println("Result length: " + result.size()); } } List<BlockHeaderWrapper> extraHeaders = syncQueue.addHeaders(createHeadersFromHeaders(peers[0].getRandomHeaders(10), peer0)); assert extraHeaders.isEmpty(); assert cnt != 1000; assert result.size() == randomChain.size() - 1; for (int i = 0; i < result.size() - 1; i++) { assert Arrays.equals(result.get(i + 1).getHash(), result.get(i).getHeader().getParentHash()); } assert Arrays.equals(randomChain.get(0).getHash(), result.get(result.size() - 1).getHeader().getParentHash()); } @Test public void testReverseHeaders2() { List<Block> randomChain = TestUtils.getRandomChain(new byte[32], 0, 194); Peer[] peers = new Peer[]{new Peer(randomChain), new Peer(randomChain)}; SyncQueueReverseImpl syncQueue = new SyncQueueReverseImpl(randomChain.get(randomChain.size() - 1).getHash(), true); List<BlockHeaderWrapper> result = new ArrayList<>(); int peerIdx = 1; int cnt = 0; while (cnt < 100) { System.out.println("Cnt: " + cnt++); Collection<SyncQueueIfc.HeadersRequest> headersRequests = syncQueue.requestHeaders(192, 10, Integer.MAX_VALUE); if (headersRequests == null) break; for (SyncQueueIfc.HeadersRequest request : headersRequests) { System.out.println("Req: " + request); List<BlockHeader> headers = peers[peerIdx].getHeaders(request); // Removing genesis header, which we will not get from real peers Iterator<BlockHeader> it = headers.iterator(); while (it.hasNext()) { if (FastByteComparisons.equal(it.next().getHash(), randomChain.get(0).getHash())) it.remove(); } peerIdx = (peerIdx + 1) % 2; List<BlockHeaderWrapper> ret = syncQueue.addHeaders(createHeadersFromHeaders(headers, peer0)); result.addAll(ret); System.out.println("Result length: " + result.size()); } } assert cnt != 100; assert result.size() == randomChain.size() - 1; // - genesis for (int i = 0; i < result.size() - 1; i++) { assert Arrays.equals(result.get(i + 1).getHash(), result.get(i).getHeader().getParentHash()); } assert Arrays.equals(randomChain.get(0).getHash(), result.get(result.size() - 1).getHeader().getParentHash()); } @Test // a copy of testReverseHeaders2 with #addHeadersAndValidate() instead #addHeaders(), // makes sure that nothing is broken public void testReverseHeaders3() { List<Block> randomChain = TestUtils.getRandomChain(new byte[32], 0, 194); Peer[] peers = new Peer[]{new Peer(randomChain), new Peer(randomChain)}; SyncQueueReverseImpl syncQueue = new SyncQueueReverseImpl(randomChain.get(randomChain.size() - 1).getHash(), true); List<BlockHeaderWrapper> result = new ArrayList<>(); int peerIdx = 1; int cnt = 0; while (cnt < 100) { System.out.println("Cnt: " + cnt++); Collection<SyncQueueIfc.HeadersRequest> headersRequests = syncQueue.requestHeaders(192, 10, Integer.MAX_VALUE); if (headersRequests == null) break; for (SyncQueueIfc.HeadersRequest request : headersRequests) { System.out.println("Req: " + request); List<BlockHeader> headers = peers[peerIdx].getHeaders(request); // Removing genesis header, which we will not get from real peers Iterator<BlockHeader> it = headers.iterator(); while (it.hasNext()) { if (FastByteComparisons.equal(it.next().getHash(), randomChain.get(0).getHash())) it.remove(); } peerIdx = (peerIdx + 1) % 2; SyncQueueIfc.ValidatedHeaders ret = syncQueue.addHeadersAndValidate(createHeadersFromHeaders(headers, peer0)); assert ret.isValid(); result.addAll(ret.getHeaders()); System.out.println("Result length: " + result.size()); } } assert cnt != 100; assert result.size() == randomChain.size() - 1; // - genesis for (int i = 0; i < result.size() - 1; i++) { assert Arrays.equals(result.get(i + 1).getHash(), result.get(i).getHeader().getParentHash()); } assert Arrays.equals(randomChain.get(0).getHash(), result.get(result.size() - 1).getHeader().getParentHash()); } @Test public void testLongLongestChain() { List<Block> randomChain = TestUtils.getRandomAltChain(new byte[32], 0, 10500, 3); SyncQueueImpl syncQueue = new SyncQueueImpl(randomChain); assert syncQueue.getLongestChain().size() == 10500; } @Test public void testWideLongestChain() { List<Block> randomChain = TestUtils.getRandomAltChain(new byte[32], 0, 100, 100); SyncQueueImpl syncQueue = new SyncQueueImpl(randomChain); assert syncQueue.getLongestChain().size() == 100; } @Test public void testGapedLongestChain() { List<Block> randomChain = TestUtils.getRandomAltChain(new byte[32], 0, 100, 5); Iterator<Block> it = randomChain.iterator(); while (it.hasNext()) { if (it.next().getHeader().getNumber() == 15) it.remove(); } SyncQueueImpl syncQueue = new SyncQueueImpl(randomChain); assert syncQueue.getLongestChain().size() == 15; // 0 .. 14 } @Test public void testFirstBlockGapedLongestChain() { List<Block> randomChain = TestUtils.getRandomAltChain(new byte[32], 0, 100, 5); Iterator<Block> it = randomChain.iterator(); while (it.hasNext()) { if (it.next().getHeader().getNumber() == 1) it.remove(); } SyncQueueImpl syncQueue = new SyncQueueImpl(randomChain); assert syncQueue.getLongestChain().size() == 1; // 0 } @Test(expected = AssertionError.class) public void testZeroBlockGapedLongestChain() { List<Block> randomChain = TestUtils.getRandomAltChain(new byte[32], 0, 100, 5); Iterator<Block> it = randomChain.iterator(); while (it.hasNext()) { if (it.next().getHeader().getNumber() == 0) it.remove(); } SyncQueueImpl syncQueue = new SyncQueueImpl(randomChain); syncQueue.getLongestChain().size(); } @Test public void testNoParentGapeLongestChain() { List<Block> randomChain = TestUtils.getRandomAltChain(new byte[32], 0, 100, 5); // Moving #15 blocks to the end to be sure it didn't trick SyncQueue Iterator<Block> it = randomChain.iterator(); List<Block> blockSaver = new ArrayList<>(); while (it.hasNext()) { Block block = it.next(); if (block.getHeader().getNumber() == 15) { blockSaver.add(block); it.remove(); } } randomChain.addAll(blockSaver); SyncQueueImpl syncQueue = new SyncQueueImpl(randomChain); // We still have linked chain assert syncQueue.getLongestChain().size() == 100; List<Block> randomChain2 = TestUtils.getRandomAltChain(new byte[32], 0, 100, 5); Iterator<Block> it2 = randomChain2.iterator(); List<Block> blockSaver2 = new ArrayList<>(); while (it2.hasNext()) { Block block = it2.next(); if (block.getHeader().getNumber() == 15) { blockSaver2.add(block); } } // Removing #15 blocks for (int i = 0; i < 5; ++i) { randomChain.remove(randomChain.size() - 1); } // Adding wrong #15 blocks assert blockSaver2.size() == 5; randomChain.addAll(blockSaver2); assert new SyncQueueImpl(randomChain).getLongestChain().size() == 15; // 0 .. 14 } @Test public void testValidateChain() { List<Block> randomChain = TestUtils.getRandomChain(new byte[32], 0, 100); SyncQueueImpl queue = new SyncQueueImpl(randomChain); byte[] nodeId = randomPeerId(); List<Block> chain = TestUtils.getRandomChain(randomChain.get(randomChain.size() - 1).getHash(), 100, SyncQueueImpl.MAX_CHAIN_LEN - 100 - 1); queue.addHeaders(createHeadersFromBlocks(chain, nodeId)); List<SyncQueueImpl.HeaderElement> longestChain = queue.getLongestChain(); // no validator is set assertEquals(SyncQueueIfc.ValidatedHeaders.Empty, queue.validateChain(longestChain)); chain = TestUtils.getRandomChain(chain.get(chain.size() - 1).getHash(), SyncQueueImpl.MAX_CHAIN_LEN - 1, SyncQueueImpl.MAX_CHAIN_LEN); queue.addHeaders(createHeadersFromBlocks(chain, nodeId)); chain = TestUtils.getRandomChain(chain.get(chain.size() - 1).getHash(), 2 * SyncQueueImpl.MAX_CHAIN_LEN - 1, SyncQueueImpl.MAX_CHAIN_LEN); // the chain is invalid queue.withParentHeaderValidator(RedRule); SyncQueueIfc.ValidatedHeaders ret = queue.addHeadersAndValidate(createHeadersFromBlocks(chain, nodeId)); assertFalse(ret.isValid()); assertArrayEquals(nodeId, ret.getNodeId()); // the chain is valid queue.withParentHeaderValidator(GreenRule); ret = queue.addHeadersAndValidate(createHeadersFromBlocks(chain, nodeId)); assertEquals(SyncQueueIfc.ValidatedHeaders.Empty, ret); } @Test public void testEraseChain() { List<Block> randomChain = TestUtils.getRandomChain(new byte[32], 0, 1024); SyncQueueImpl queue = new SyncQueueImpl(randomChain); List<Block> chain1 = TestUtils.getRandomChain(randomChain.get(randomChain.size() - 1).getHash(), 1024, SyncQueueImpl.MAX_CHAIN_LEN / 2); queue.addHeaders(createHeadersFromBlocks(chain1, randomPeerId())); List<Block> chain2 = TestUtils.getRandomChain(randomChain.get(randomChain.size() - 1).getHash(), 1024, SyncQueueImpl.MAX_CHAIN_LEN / 2 - 1); queue.addHeaders(createHeadersFromBlocks(chain2, randomPeerId())); List<SyncQueueImpl.HeaderElement> longestChain = queue.getLongestChain(); long maxNum = longestChain.get(longestChain.size() - 1).header.getNumber(); assertEquals(1024 + SyncQueueImpl.MAX_CHAIN_LEN / 2 - 1, maxNum); assertEquals(1024 + SyncQueueImpl.MAX_CHAIN_LEN / 2 - 1, queue.getHeadersCount()); List<Block> chain3 = TestUtils.getRandomChain(chain1.get(chain1.size() - 1).getHash(), 1024 + SyncQueueImpl.MAX_CHAIN_LEN / 2, SyncQueueImpl.MAX_CHAIN_LEN / 10); // the chain is invalid and must be erased queue.withParentHeaderValidator(new DependentBlockHeaderRule() { @Override public boolean validate(BlockHeader header, BlockHeader dependency) { // chain2 should become best after erasing return header.getNumber() < chain2.get(chain2.size() - 2).getNumber(); } }); queue.addHeadersAndValidate(createHeadersFromBlocks(chain3, randomPeerId())); longestChain = queue.getLongestChain(); assertEquals(maxNum - 1, queue.getHeadersCount()); assertEquals(chain2.get(chain2.size() - 1).getHeader(), longestChain.get(longestChain.size() - 1).header.getHeader()); } public void test2Impl(List<Block> mainChain, List<Block> initChain, Peer[] peers) { List<Block> randomChain = TestUtils.getRandomChain(new byte[32], 0, 1024); final Block[] maxExportedBlock = new Block[] {randomChain.get(31)}; final Map<ByteArrayWrapper, Block> exportedBlocks = new HashMap<>(); for (Block block : randomChain.subList(0, 32)) { exportedBlocks.put(new ByteArrayWrapper(block.getHash()), block); } SyncQueueImpl syncQueue = new SyncQueueImpl(randomChain.subList(0, 32)) { @Override protected void exportNewBlock(Block block) { exportedBlocks.put(new ByteArrayWrapper(block.getHash()), block); if (!exportedBlocks.containsKey(new ByteArrayWrapper(block.getParentHash()))) { throw new RuntimeException("No parent for " + block); } if (block.getNumber() > maxExportedBlock[0].getNumber()) { maxExportedBlock[0] = block; } } }; Random rnd = new Random(); int i = 0; for (; i < 1000; i++) { SyncQueueIfc.HeadersRequest headersRequest = syncQueue.requestHeaders(DEFAULT_REQUEST_LEN, 1, Integer.MAX_VALUE).iterator().next(); List<BlockHeader> headers = peers[rnd.nextInt(peers.length)].getHeaders(headersRequest.getStart(), headersRequest.getCount(), headersRequest.isReverse()); syncQueue.addHeaders(createHeadersFromHeaders(headers, peer0)); SyncQueueIfc.BlocksRequest blocksRequest = syncQueue.requestBlocks(rnd.nextInt(128 + 1)); List<Block> blocks = peers[rnd.nextInt(peers.length)].getBlocks(blocksRequest.getBlockHeaders()); syncQueue.addBlocks(blocks); if (maxExportedBlock[0].getNumber() == randomChain.get(randomChain.size() - 1).getNumber()) { break; } } if (i == 1000) throw new RuntimeException("Exported only till block: " + maxExportedBlock[0]); } private static class Peer { Map<ByteArrayWrapper, Block> blocks = new HashMap<>(); List<Block> chain; boolean returnGenesis; public Peer(List<Block> chain) { this(chain, true); } public Peer(List<Block> chain, boolean returnGenesis) { this.returnGenesis = returnGenesis; this.chain = chain; for (Block block : chain) { blocks.put(new ByteArrayWrapper(block.getHash()), block); } } public List<BlockHeader> getHeaders(long startBlockNum, int count, boolean reverse) { return getHeaders(startBlockNum, count, reverse, 0); } public List<BlockHeader> getHeaders(SyncQueueIfc.HeadersRequest req) { if (req.getHash() == null) { return getHeaders(req.getStart(), req.getCount(), req.isReverse(), req.getStep()); } else { Block block = blocks.get(new ByteArrayWrapper(req.getHash())); if (block == null) return Collections.emptyList(); return getHeaders(block.getNumber(), req.getCount(), req.isReverse(), req.getStep()); } } public List<BlockHeader> getRandomHeaders(int count) { List<BlockHeader> ret = new ArrayList<>(); Random rnd = new Random(); for (int i = 0; i < count; i++) { ret.add(chain.get(rnd.nextInt(chain.size())).getHeader()); } return ret; } public List<BlockHeader> getHeaders(long startBlockNum, int count, boolean reverse, int step) { step = step == 0 ? 1 : step; List<BlockHeader> ret = new ArrayList<>(); int i = (int) startBlockNum; for(; count-- > 0 && i >= (returnGenesis ? 0 : 1) && i <= chain.get(chain.size() - 1).getNumber(); i += reverse ? -step : step) { ret.add(chain.get(i).getHeader()); } // step = step == 0 ? 1 : step; // // if (reverse) { // startBlockNum = startBlockNum - (count - 1 ) * step; // } // // startBlockNum = Math.max(startBlockNum, chain.get(0).getNumber()); // startBlockNum = Math.min(startBlockNum, chain.get(chain.size() - 1).getNumber()); // long endBlockNum = startBlockNum + (count - 1) * step; // endBlockNum = Math.max(endBlockNum, chain.get(0).getNumber()); // endBlockNum = Math.min(endBlockNum, chain.get(chain.size() - 1).getNumber()); // List<BlockHeader> ret = new ArrayList<>(); // int startIdx = (int) (startBlockNum - chain.get(0).getNumber()); // for (int i = startIdx; i < startIdx + (endBlockNum - startBlockNum + 1); i+=step) { // ret.add(chain.get(i).getHeader()); // } return ret; } public List<Block> getBlocks(Collection<BlockHeaderWrapper> hashes) { List<Block> ret = new ArrayList<>(); for (BlockHeaderWrapper hash : hashes) { Block block = blocks.get(new ByteArrayWrapper(hash.getHash())); if (block != null) ret.add(block); } return ret; } } private List<BlockHeaderWrapper> createHeadersFromHeaders(List<BlockHeader> headers, byte[] peer) { List<BlockHeaderWrapper> ret = new ArrayList<>(); for (BlockHeader header : headers) { ret.add(new BlockHeaderWrapper(header, peer)); } return ret; } private List<BlockHeaderWrapper> createHeadersFromBlocks(List<Block> blocks, byte[] peer) { List<BlockHeaderWrapper> ret = new ArrayList<>(); for (Block block : blocks) { ret.add(new BlockHeaderWrapper(block.getHeader(), peer)); } return ret; } static final DependentBlockHeaderRule RedRule = new DependentBlockHeaderRule() { @Override public boolean validate(BlockHeader header, BlockHeader dependency) { return false; } }; static final DependentBlockHeaderRule GreenRule = new DependentBlockHeaderRule() { @Override public boolean validate(BlockHeader header, BlockHeader dependency) { return true; } }; }
22,633
42.61079
166
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/sync/BlockTxForwardTest.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.sync; import ch.qos.logback.classic.Level; import com.typesafe.config.ConfigFactory; import org.ethereum.config.SystemProperties; import org.ethereum.core.Block; import org.ethereum.core.BlockIdentifier; import org.ethereum.core.BlockSummary; import org.ethereum.core.Transaction; import org.ethereum.core.TransactionReceipt; import org.ethereum.crypto.ECKey; import org.ethereum.facade.Ethereum; import org.ethereum.facade.EthereumFactory; import org.ethereum.listener.EthereumListener; import org.ethereum.listener.EthereumListenerAdapter; import org.ethereum.mine.Ethash; import org.ethereum.mine.MinerListener; import org.ethereum.net.eth.message.EthMessage; import org.ethereum.net.eth.message.EthMessageCodes; import org.ethereum.net.eth.message.NewBlockHashesMessage; import org.ethereum.net.eth.message.NewBlockMessage; import org.ethereum.net.eth.message.StatusMessage; import org.ethereum.net.eth.message.TransactionsMessage; import org.ethereum.net.message.Message; import org.ethereum.net.rlpx.Node; import org.ethereum.net.server.Channel; import org.ethereum.util.ByteUtil; 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.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import javax.annotation.PostConstruct; import java.util.Collections; import java.util.HashMap; import java.util.Hashtable; import java.util.List; import java.util.Map; import java.util.Vector; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ThreadFactory; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; /** * Long running test * * 3 peers: A <-> B <-> C where A is miner, C is issuing txs, and B should forward Txs/Blocks */ @Ignore public class BlockTxForwardTest { static final Logger testLogger = LoggerFactory.getLogger("TestLogger"); public BlockTxForwardTest() { ch.qos.logback.classic.Logger root = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME); root.setLevel(Level.INFO); } private static class BasicSample implements Runnable { static final Logger sLogger = LoggerFactory.getLogger("sample"); private String loggerName; public Logger logger; @Autowired protected Ethereum ethereum; @Autowired protected SystemProperties config; // Spring config class which add this sample class as a bean to the components collections // and make it possible for autowiring other components private static class Config { @Bean public BasicSample basicSample() { return new BasicSample(); } } public static void main(String[] args) throws Exception { sLogger.info("Starting EthereumJ!"); // Based on Config class the BasicSample would be created by Spring // and its springInit() method would be called as an entry point EthereumFactory.createEthereum(Config.class); } public BasicSample() { this("sample"); } /** * logger name can be passed if more than one EthereumJ instance is created * in a single JVM to distinguish logging output from different instances */ public BasicSample(String loggerName) { this.loggerName = loggerName; } /** * The method is called after all EthereumJ instances are created */ @PostConstruct private void springInit() { logger = LoggerFactory.getLogger(loggerName); // adding the main EthereumJ callback to be notified on different kind of events ethereum.addListener(listener); logger.info("Sample component created. Listening for ethereum events..."); // starting lifecycle tracking method run() new Thread(this, "SampleWorkThread").start(); } /** * The method tracks step-by-step the instance lifecycle from node discovery till sync completion. * At the end the method onSyncDone() is called which might be overridden by a sample subclass * to start making other things with the Ethereum network */ public void run() { try { logger.info("Sample worker thread started."); if (!config.peerDiscovery()) { logger.info("Peer discovery disabled. We should actively connect to another peers or wait for incoming connections"); } waitForSync(); onSyncDone(); } catch (Exception e) { logger.error("Error occurred in Sample: ", e); } } /** * Waits until the whole blockchain sync is complete */ private void waitForSync() throws Exception { logger.info("Waiting for the whole blockchain sync (will take up to several hours for the whole chain)..."); while(true) { Thread.sleep(10000); if (synced) { logger.info("[v] Sync complete! The best block: " + bestBlock.getShortDescr()); syncComplete = true; return; } } } /** * Is called when the whole blockchain sync is complete */ public void onSyncDone() throws Exception { logger.info("Monitoring new blocks in real-time..."); } protected Map<Node, StatusMessage> ethNodes = new Hashtable<>(); protected List<Node> syncPeers = new Vector<>(); protected Block bestBlock = null; boolean synced = false; boolean syncComplete = false; /** * The main EthereumJ callback. */ EthereumListener listener = new EthereumListenerAdapter() { @Override public void onSyncDone(SyncState state) { synced = true; } @Override public void onEthStatusUpdated(Channel channel, StatusMessage statusMessage) { ethNodes.put(channel.getNode(), statusMessage); } @Override public void onPeerAddedToSyncPool(Channel peer) { syncPeers.add(peer.getNode()); } @Override public void onBlock(Block block, List<TransactionReceipt> receipts) { bestBlock = block; if (syncComplete) { logger.info("New block: " + block.getShortDescr()); } } }; } /** * Spring configuration class for the Miner peer (A) */ private static class MinerConfig { private final String config = // no need for discovery in that small network "peer.discovery.enabled = false \n" + "peer.listen.port = 30335 \n" + // need to have different nodeId's for the peers "peer.privateKey = 6ef8da380c27cea8fdf7448340ea99e8e2268fc2950d79ed47cbf6f85dc977ec \n" + // our private net ID "peer.networkId = 555 \n" + // we have no peers to sync with "sync.enabled = false \n" + // genesis with a lower initial difficulty and some predefined known funded accounts "genesis = sample-genesis.json \n" + // two peers need to have separate database dirs "database.dir = sampleDB-1 \n" + "keyvalue.datasource = leveldb \n" + // when more than 1 miner exist on the network extraData helps to identify the block creator "mine.extraDataHex = cccccccccccccccccccc \n" + "mine.cpuMineThreads = 2 \n" + "cache.flush.blocks = 1"; @Bean public MinerNode node() { return new MinerNode(); } /** * Instead of supplying properties via config file for the peer * we are substituting the corresponding bean which returns required * config for this instance. */ @Bean public SystemProperties systemProperties() { SystemProperties props = new SystemProperties(); props.overrideParams(ConfigFactory.parseString(config.replaceAll("'", "\""))); return props; } } /** * Miner bean, which just start a miner upon creation and prints miner events */ static class MinerNode extends BasicSample implements MinerListener{ public MinerNode() { // peers need different loggers super("sampleMiner"); } // overriding run() method since we don't need to wait for any discovery, // networking or sync events @Override public void run() { if (config.isMineFullDataset()) { logger.info("Generating Full Dataset (may take up to 10 min if not cached)..."); // calling this just for indication of the dataset generation // basically this is not required Ethash ethash = Ethash.getForBlock(config, ethereum.getBlockchain().getBestBlock().getNumber()); ethash.getFullDataset(); logger.info("Full dataset generated (loaded)."); } ethereum.getBlockMiner().addListener(this); ethereum.getBlockMiner().startMining(); } @Override public void miningStarted() { logger.info("Miner started"); } @Override public void miningStopped() { logger.info("Miner stopped"); } @Override public void blockMiningStarted(Block block) { logger.info("Start mining block: " + block.getShortDescr()); } @Override public void blockMined(Block block) { logger.info("Block mined! : \n" + block); } @Override public void blockMiningCanceled(Block block) { logger.info("Cancel mining block: " + block.getShortDescr()); } } /** * Spring configuration class for the Regular peer (B) * It will see nodes A and C, which is not connected directly and proves that tx's from (C) reaches miner (A) * and new blocks both A and C */ private static class RegularConfig { private final String config = // no discovery: we are connecting directly to the generator and miner peers "peer.discovery.enabled = false \n" + "peer.listen.port = 30339 \n" + "peer.privateKey = 1f0bbd4ffd61128a7d150c07d3f5b7dcd078359cd708ada8b60e4b9ffd90b3f5 \n" + "peer.networkId = 555 \n" + // actively connecting to the miner and tx generator "peer.active = [" + // miner " { url = 'enode://26ba1aadaf59d7607ad7f437146927d79e80312f026cfa635c6b2ccf2c5d3521f5812ca2beb3b295b14f97110e6448c1c7ff68f14c5328d43a3c62b44143e9b1@localhost:30335' }, \n" + // tx generator " { url = 'enode://3973cb86d7bef9c96e5d589601d788370f9e24670dcba0480c0b3b1b0647d13d0f0fffed115dd2d4b5ca1929287839dcd4e77bdc724302b44ae48622a8766ee6@localhost:30336' } \n" + "] \n" + "sync.enabled = true \n" + // all peers in the same network need to use the same genesis block "genesis = sample-genesis.json \n" + // two peers need to have separate database dirs "database.dir = sampleDB-2 \n" + "keyvalue.datasource = leveldb \n"; @Bean public RegularNode node() { return new RegularNode(); } /** * Instead of supplying properties via config file for the peer * we are substituting the corresponding bean which returns required * config for this instance. */ @Bean public SystemProperties systemProperties() { SystemProperties props = new SystemProperties(); props.overrideParams(ConfigFactory.parseString(config.replaceAll("'", "\""))); return props; } } /** * This node doing nothing special, but by default as any other node will resend txs and new blocks */ static class RegularNode extends BasicSample { public RegularNode() { // peers need different loggers super("sampleNode"); } } /** * Spring configuration class for the TX-sender peer (C) */ private static class GeneratorConfig { private final String config = // no discovery: forwarder will connect to us "peer.discovery.enabled = false \n" + "peer.listen.port = 30336 \n" + "peer.privateKey = 3ec771c31cac8c0dba77a69e503765701d3c2bb62435888d4ffa38fed60c445c \n" + "peer.networkId = 555 \n" + "sync.enabled = true \n" + // all peers in the same network need to use the same genesis block "genesis = sample-genesis.json \n" + // two peers need to have separate database dirs "database.dir = sampleDB-3 \n" + "keyvalue.datasource = leveldb \n"; @Bean public GeneratorNode node() { return new GeneratorNode(); } /** * Instead of supplying properties via config file for the peer * we are substituting the corresponding bean which returns required * config for this instance. */ @Bean public SystemProperties systemProperties() { SystemProperties props = new SystemProperties(); props.overrideParams(ConfigFactory.parseString(config.replaceAll("'", "\""))); return props; } } /** * The tx generator node in the network which connects to the regular * waits for the sync and starts submitting transactions. * Those transactions should be included into mined blocks and the peer * should receive those blocks back */ static class GeneratorNode extends BasicSample { public GeneratorNode() { // peers need different loggers super("txSenderNode"); } @Override public void onSyncDone() { new Thread(() -> { try { generateTransactions(); } catch (Exception e) { logger.error("Error generating tx: ", e); } }).start(); } /** * Generate one simple value transfer transaction each 7 seconds. * Thus blocks will include one, several and none transactions */ private void generateTransactions() throws Exception{ logger.info("Start generating transactions..."); // the sender which some coins from the genesis ECKey senderKey = ECKey.fromPrivate(Hex.decode("6ef8da380c27cea8fdf7448340ea99e8e2268fc2950d79ed47cbf6f85dc977ec")); byte[] receiverAddr = Hex.decode("5db10750e8caff27f906b41c71b3471057dd2004"); for (int i = ethereum.getRepository().getNonce(senderKey.getAddress()).intValue(), j = 0; j < 20000; i++, j++) { { if (stopTxGeneration.get()) break; Transaction tx = new Transaction(ByteUtil.intToBytesNoLeadZeroes(i), ByteUtil.longToBytesNoLeadZeroes(50_000_000_000L), ByteUtil.longToBytesNoLeadZeroes(0xfffff), receiverAddr, new byte[]{77}, new byte[0]); tx.sign(senderKey); logger.info("<== Submitting tx: " + tx); ethereum.submitTransaction(tx); } Thread.sleep(7000); } } } private final static Map<String, Boolean> blocks = Collections.synchronizedMap(new HashMap<String, Boolean>()); private final static Map<String, Boolean> txs = Collections.synchronizedMap(new HashMap<String, Boolean>()); private final static AtomicInteger fatalErrors = new AtomicInteger(0); private final static AtomicBoolean stopTxGeneration = new AtomicBoolean(false); private final static long MAX_RUN_MINUTES = 360L; // Actually there will be several blocks mined after, it's a very soft shutdown private final static int STOP_ON_BLOCK = 100; private static ScheduledExecutorService statTimer = Executors.newSingleThreadScheduledExecutor(r -> new Thread(r, "StatTimer")); private boolean logStats() { testLogger.info("---------====---------"); int arrivedBlocks = 0; for (Boolean arrived : blocks.values()) { if (arrived) arrivedBlocks++; } testLogger.info("Arrived blocks / Total: {}/{}", arrivedBlocks, blocks.size()); int arrivedTxs = 0; for (Boolean arrived : txs.values()) { if (arrived) arrivedTxs++; } testLogger.info("Arrived txs / Total: {}/{}", arrivedTxs, txs.size()); testLogger.info("fatalErrors: {}", fatalErrors); testLogger.info("---------====---------"); return fatalErrors.get() == 0 && blocks.size() == arrivedBlocks && txs.size() == arrivedTxs; } /** * Creating 3 EthereumJ instances with different config classes * 1st - Miner node, no sync * 2nd - Regular node, synced with both Miner and Generator * 3rd - Generator node, sync is on, but can see only 2nd node * We want to check that blocks mined on Miner will reach Generator and * txs from Generator will reach Miner node */ @Test public void testTest() throws Exception { statTimer.scheduleAtFixedRate(() -> { try { logStats(); if (fatalErrors.get() > 0 || blocks.size() >= STOP_ON_BLOCK) { statTimer.shutdownNow(); } } catch (Throwable t) { testLogger.error("Unhandled exception", t); } }, 0, 15, TimeUnit.SECONDS); testLogger.info("Starting EthereumJ miner instance!"); Ethereum miner = EthereumFactory.createEthereum(MinerConfig.class); miner.addListener(new EthereumListenerAdapter() { @Override public void onBlock(BlockSummary blockSummary) { if (blockSummary.getBlock().getNumber() != 0L) { blocks.put(Hex.toHexString(blockSummary.getBlock().getHash()), Boolean.FALSE); } } @Override public void onRecvMessage(Channel channel, Message message) { super.onRecvMessage(channel, message); if (!(message instanceof EthMessage)) return; switch (((EthMessage) message).getCommand()) { case NEW_BLOCK_HASHES: testLogger.error("Received new block hash message at miner: {}", message.toString()); fatalErrors.incrementAndGet(); break; case NEW_BLOCK: testLogger.error("Received new block message at miner: {}", message.toString()); fatalErrors.incrementAndGet(); break; case TRANSACTIONS: TransactionsMessage msgCopy = new TransactionsMessage(message.getEncoded()); for (Transaction transaction : msgCopy.getTransactions()) { if (txs.put(Hex.toHexString(transaction.getHash()), Boolean.TRUE) == null) { testLogger.error("Received strange transaction at miner: {}", transaction); fatalErrors.incrementAndGet(); }; } break; default: break; } } }); testLogger.info("Starting EthereumJ regular instance!"); EthereumFactory.createEthereum(RegularConfig.class); testLogger.info("Starting EthereumJ txSender instance!"); Ethereum txGenerator = EthereumFactory.createEthereum(GeneratorConfig.class); txGenerator.addListener(new EthereumListenerAdapter() { @Override public void onRecvMessage(Channel channel, Message message) { super.onRecvMessage(channel, message); if (!(message instanceof EthMessage)) return; switch (((EthMessage) message).getCommand()) { case NEW_BLOCK_HASHES: testLogger.info("Received new block hash message at generator: {}", message.toString()); NewBlockHashesMessage msgCopy = new NewBlockHashesMessage(message.getEncoded()); for (BlockIdentifier identifier : msgCopy.getBlockIdentifiers()) { if (blocks.put(Hex.toHexString(identifier.getHash()), Boolean.TRUE) == null) { testLogger.error("Received strange block: {}", identifier); fatalErrors.incrementAndGet(); }; } break; case NEW_BLOCK: testLogger.info("Received new block message at generator: {}", message.toString()); NewBlockMessage msgCopy2 = new NewBlockMessage(message.getEncoded()); Block block = msgCopy2.getBlock(); if (blocks.put(Hex.toHexString(block.getHash()), Boolean.TRUE) == null) { testLogger.error("Received strange block: {}", block); fatalErrors.incrementAndGet(); }; break; case BLOCK_BODIES: testLogger.info("Received block bodies message at generator: {}", message.toString()); break; case TRANSACTIONS: testLogger.warn("Received new transaction message at generator: {}, " + "allowed only after disconnect.", message.toString()); break; default: break; } } @Override public void onSendMessage(Channel channel, Message message) { super.onSendMessage(channel, message); if (!(message instanceof EthMessage)) return; if (((EthMessage) message).getCommand().equals(EthMessageCodes.TRANSACTIONS)) { TransactionsMessage msgCopy = new TransactionsMessage(message.getEncoded()); for (Transaction transaction : msgCopy.getTransactions()) { Transaction copyTransaction = new Transaction(transaction.getEncoded()); txs.put(Hex.toHexString(copyTransaction.getHash()), Boolean.FALSE); }; } } }); if(statTimer.awaitTermination(MAX_RUN_MINUTES, TimeUnit.MINUTES)) { logStats(); // Stop generating new txs stopTxGeneration.set(true); Thread.sleep(60000); // Stop miner miner.getBlockMiner().stopMining(); // Wait to be sure that last mined blocks will reach Generator Thread.sleep(60000); // Checking stats if (!logStats()) assert false; } } }
25,015
39.478964
192
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/sync/LongSyncTest.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.sync; import org.ethereum.config.NoAutoscan; import org.ethereum.config.SystemProperties; import org.ethereum.config.blockchain.FrontierConfig; import org.ethereum.config.net.MainNetConfig; import org.ethereum.core.*; import org.ethereum.facade.Ethereum; import org.ethereum.facade.EthereumFactory; import org.ethereum.listener.EthereumListenerAdapter; import org.ethereum.net.eth.handler.Eth62; import org.ethereum.net.eth.handler.EthHandler; import org.ethereum.net.eth.message.*; import org.ethereum.net.message.Message; import org.ethereum.net.p2p.DisconnectMessage; import org.ethereum.net.rlpx.Node; import org.ethereum.net.server.Channel; import org.ethereum.util.blockchain.StandaloneBlockchain; import org.junit.*; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Scope; 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 java.util.concurrent.CountDownLatch; import static java.util.concurrent.TimeUnit.SECONDS; import static org.ethereum.util.FileUtil.recursiveDelete; import static org.junit.Assert.fail; import static org.spongycastle.util.encoders.Hex.decode; /** * @author Mikhail Kalinin * @since 14.12.2015 */ @Ignore("Long network tests") public class LongSyncTest { private static Node nodeA; private static List<Block> mainB1B10; private static Block b10; private Ethereum ethereumA; private Ethereum ethereumB; private EthHandler ethA; private String testDbA; private String testDbB; @BeforeClass public static void setup() throws IOException, URISyntaxException { nodeA = new Node("enode://3973cb86d7bef9c96e5d589601d788370f9e24670dcba0480c0b3b1b0647d13d0f0fffed115dd2d4b5ca1929287839dcd4e77bdc724302b44ae48622a8766ee6@localhost:30334"); SysPropConfigA.props.overrideParams( "peer.listen.port", "30334", "peer.privateKey", "3ec771c31cac8c0dba77a69e503765701d3c2bb62435888d4ffa38fed60c445c", // nodeId: 3973cb86d7bef9c96e5d589601d788370f9e24670dcba0480c0b3b1b0647d13d0f0fffed115dd2d4b5ca1929287839dcd4e77bdc724302b44ae48622a8766ee6 "genesis", "genesis-light-old.json" ); SysPropConfigA.props.setBlockchainConfig(StandaloneBlockchain.getEasyMiningConfig()); SysPropConfigB.props.overrideParams( "peer.listen.port", "30335", "peer.privateKey", "6ef8da380c27cea8fdf7448340ea99e8e2268fc2950d79ed47cbf6f85dc977ec", "genesis", "genesis-light-old.json", "sync.enabled", "true", "sync.max.hashes.ask", "3", "sync.max.blocks.ask", "2" ); SysPropConfigB.props.setBlockchainConfig(StandaloneBlockchain.getEasyMiningConfig()); /* 1 => ed1b6f07d738ad92c5bdc3b98fe25afea9c863dd351711776d9ce1ffb9e3d276 2 => 43808666b662d131c6cff336a0d13608767ead9c9d5f181e95caa3597f3faf14 3 => 1b5c231211f500bc73148dc9d9bdb9de2265465ba441a0db1790ba4b3f5f3e9c 4 => db517e04399dbf5a65caf6b2572b3966c8f98a1d29b1e50dc8db51e54c15d83d 5 => c42d6dbaa756eda7f4244a3507670d764232bd7068d43e6d8ef680c6920132f6 6 => 604c92e8d16dafb64134210d521fcc85aec27452e75aedf708ac72d8240585d3 7 => 3f51b0471eb345b1c5f3c6628e69744358ff81d3f64a3744bbb2edf2adbb0ebc 8 => 62cfd04e29d941954e68ac8ca18ef5cd78b19809eaed860ae72589ebad53a21d 9 => d32fc8e151f158d52fe0be6cba6d0b5c20793a00c4ad0d32db8ccd9269199a29 10 => 22d8c1d909eb142ea0d69d0a38711874f98d6eef1bc669836da36f6b557e9564 */ mainB1B10 = loadBlocks("sync/main-b1-b10.dmp"); b10 = mainB1B10.get(mainB1B10.size() - 1); } private static List<Block> loadBlocks(String path) throws URISyntaxException, IOException { URL url = ClassLoader.getSystemResource(path); File file = new File(url.toURI()); List<String> strData = Files.readAllLines(file.toPath(), StandardCharsets.UTF_8); List<Block> blocks = new ArrayList<>(strData.size()); for (String rlp : strData) { blocks.add(new Block(decode(rlp))); } return blocks; } @AfterClass public static void cleanup() { SystemProperties.resetToDefault(); } @Before public void setupTest() throws InterruptedException { testDbA = "test_db_" + new BigInteger(32, new Random()); testDbB = "test_db_" + new BigInteger(32, new Random()); SysPropConfigA.props.setDataBaseDir(testDbA); SysPropConfigB.props.setDataBaseDir(testDbB); } @After public void cleanupTest() { recursiveDelete(testDbA); recursiveDelete(testDbB); SysPropConfigA.eth62 = null; } // general case, A has imported 10 blocks // expected: B downloads blocks from A => B synced @Test public void test1() throws InterruptedException { setupPeers(); // A == b10, B == genesis final CountDownLatch semaphore = new CountDownLatch(1); ethereumB.addListener(new EthereumListenerAdapter() { @Override public void onBlock(Block block, List<TransactionReceipt> receipts) { if (block.isEqual(b10)) { semaphore.countDown(); } } }); semaphore.await(40, SECONDS); // check if B == b10 if(semaphore.getCount() > 0) { fail("PeerB bestBlock is incorrect"); } } // bodies validation: A doesn't send bodies for blocks lower than its best block // expected: B drops A @Test public void test2() throws InterruptedException { SysPropConfigA.eth62 = new Eth62() { @Override protected void processGetBlockBodies(GetBlockBodiesMessage msg) { List<byte[]> bodies = Arrays.asList( mainB1B10.get(0).getEncodedBody() ); BlockBodiesMessage response = new BlockBodiesMessage(bodies); sendMessage(response); } }; setupPeers(); // A == b10, B == genesis final CountDownLatch semaphoreDisconnect = new CountDownLatch(1); ethereumA.addListener(new EthereumListenerAdapter() { @Override public void onRecvMessage(Channel channel, Message message) { if (message instanceof DisconnectMessage) { semaphoreDisconnect.countDown(); } } }); semaphoreDisconnect.await(10, SECONDS); // check if peer was dropped if(semaphoreDisconnect.getCount() > 0) { fail("PeerA is not dropped"); } } // headers validation: headers count in A respond more than requested limit // expected: B drops A @Test public void test3() throws InterruptedException { SysPropConfigA.eth62 = new Eth62() { @Override protected void processGetBlockHeaders(GetBlockHeadersMessage msg) { if (Arrays.equals(msg.getBlockIdentifier().getHash(), b10.getHash())) { super.processGetBlockHeaders(msg); return; } List<BlockHeader> headers = Arrays.asList( mainB1B10.get(0).getHeader(), mainB1B10.get(1).getHeader(), mainB1B10.get(2).getHeader(), mainB1B10.get(3).getHeader() ); BlockHeadersMessage response = new BlockHeadersMessage(headers); sendMessage(response); } }; setupPeers(); // A == b10, B == genesis final CountDownLatch semaphoreDisconnect = new CountDownLatch(1); ethereumA.addListener(new EthereumListenerAdapter() { @Override public void onRecvMessage(Channel channel, Message message) { if (message instanceof DisconnectMessage) { semaphoreDisconnect.countDown(); } } }); semaphoreDisconnect.await(10, SECONDS); // check if peer was dropped if(semaphoreDisconnect.getCount() > 0) { fail("PeerA is not dropped"); } } // headers validation: A sends empty response // expected: B drops A @Test public void test4() throws InterruptedException { SysPropConfigA.eth62 = new Eth62() { @Override protected void processGetBlockHeaders(GetBlockHeadersMessage msg) { if (Arrays.equals(msg.getBlockIdentifier().getHash(), b10.getHash())) { super.processGetBlockHeaders(msg); return; } List<BlockHeader> headers = Collections.emptyList(); BlockHeadersMessage response = new BlockHeadersMessage(headers); sendMessage(response); } }; setupPeers(); // A == b10, B == genesis final CountDownLatch semaphoreDisconnect = new CountDownLatch(1); ethereumA.addListener(new EthereumListenerAdapter() { @Override public void onRecvMessage(Channel channel, Message message) { if (message instanceof DisconnectMessage) { semaphoreDisconnect.countDown(); } } }); semaphoreDisconnect.await(10, SECONDS); // check if peer was dropped if(semaphoreDisconnect.getCount() > 0) { fail("PeerA is not dropped"); } } // headers validation: first header in response doesn't meet expectations // expected: B drops A @Test public void test5() throws InterruptedException { SysPropConfigA.eth62 = new Eth62() { @Override protected void processGetBlockHeaders(GetBlockHeadersMessage msg) { if (Arrays.equals(msg.getBlockIdentifier().getHash(), b10.getHash())) { super.processGetBlockHeaders(msg); return; } List<BlockHeader> headers = Arrays.asList( mainB1B10.get(1).getHeader(), mainB1B10.get(2).getHeader(), mainB1B10.get(3).getHeader() ); BlockHeadersMessage response = new BlockHeadersMessage(headers); sendMessage(response); } }; setupPeers(); // A == b10, B == genesis final CountDownLatch semaphoreDisconnect = new CountDownLatch(1); ethereumA.addListener(new EthereumListenerAdapter() { @Override public void onRecvMessage(Channel channel, Message message) { if (message instanceof DisconnectMessage) { semaphoreDisconnect.countDown(); } } }); semaphoreDisconnect.await(10, SECONDS); // check if peer was dropped if(semaphoreDisconnect.getCount() > 0) { fail("PeerA is not dropped"); } } // headers validation: first header in response doesn't meet expectations - second story // expected: B drops A @Test public void test6() throws InterruptedException { SysPropConfigA.eth62 = new Eth62() { @Override protected void processGetBlockHeaders(GetBlockHeadersMessage msg) { List<BlockHeader> headers = Collections.singletonList( mainB1B10.get(1).getHeader() ); BlockHeadersMessage response = new BlockHeadersMessage(headers); sendMessage(response); } }; ethereumA = EthereumFactory.createEthereum(SysPropConfigA.props, SysPropConfigA.class); Blockchain blockchainA = (Blockchain) ethereumA.getBlockchain(); for (Block b : mainB1B10) { blockchainA.tryToConnect(b); } // A == b10 ethereumB = EthereumFactory.createEthereum(SysPropConfigB.props, SysPropConfigB.class); ethereumB.connect(nodeA); // A == b10, B == genesis final CountDownLatch semaphoreDisconnect = new CountDownLatch(1); ethereumA.addListener(new EthereumListenerAdapter() { @Override public void onRecvMessage(Channel channel, Message message) { if (message instanceof DisconnectMessage) { semaphoreDisconnect.countDown(); } } }); semaphoreDisconnect.await(10, SECONDS); // check if peer was dropped if(semaphoreDisconnect.getCount() > 0) { fail("PeerA is not dropped"); } } // headers validation: headers order is incorrect, reverse = false // expected: B drops A @Test public void test7() throws InterruptedException { SysPropConfigA.eth62 = new Eth62() { @Override protected void processGetBlockHeaders(GetBlockHeadersMessage msg) { if (Arrays.equals(msg.getBlockIdentifier().getHash(), b10.getHash())) { super.processGetBlockHeaders(msg); return; } List<BlockHeader> headers = Arrays.asList( mainB1B10.get(0).getHeader(), mainB1B10.get(2).getHeader(), mainB1B10.get(1).getHeader() ); BlockHeadersMessage response = new BlockHeadersMessage(headers); sendMessage(response); } }; setupPeers(); // A == b10, B == genesis final CountDownLatch semaphoreDisconnect = new CountDownLatch(1); ethereumA.addListener(new EthereumListenerAdapter() { @Override public void onRecvMessage(Channel channel, Message message) { if (message instanceof DisconnectMessage) { semaphoreDisconnect.countDown(); } } }); semaphoreDisconnect.await(10, SECONDS); // check if peer was dropped if(semaphoreDisconnect.getCount() > 0) { fail("PeerA is not dropped"); } } // headers validation: ancestor's parent hash and header's hash does not match, reverse = false // expected: B drops A @Test public void test8() throws InterruptedException { SysPropConfigA.eth62 = new Eth62() { @Override protected void processGetBlockHeaders(GetBlockHeadersMessage msg) { if (Arrays.equals(msg.getBlockIdentifier().getHash(), b10.getHash())) { super.processGetBlockHeaders(msg); return; } List<BlockHeader> headers = Arrays.asList( mainB1B10.get(0).getHeader(), new BlockHeader(new byte[32], new byte[32], new byte[32], new byte[32], new byte[32], 2, new byte[] {0}, 0, 0, new byte[0], new byte[0], new byte[0]), mainB1B10.get(2).getHeader() ); BlockHeadersMessage response = new BlockHeadersMessage(headers); sendMessage(response); } }; setupPeers(); // A == b10, B == genesis final CountDownLatch semaphoreDisconnect = new CountDownLatch(1); ethereumA.addListener(new EthereumListenerAdapter() { @Override public void onRecvMessage(Channel channel, Message message) { if (message instanceof DisconnectMessage) { semaphoreDisconnect.countDown(); } } }); semaphoreDisconnect.await(10, SECONDS); // check if peer was dropped if(semaphoreDisconnect.getCount() > 0) { fail("PeerA is not dropped"); } } private void setupPeers() throws InterruptedException { setupPeers(b10); } private void setupPeers(Block best) throws InterruptedException { ethereumA = EthereumFactory.createEthereum(SysPropConfigA.class); Blockchain blockchainA = (Blockchain) ethereumA.getBlockchain(); for (Block b : mainB1B10) { ImportResult result = blockchainA.tryToConnect(b); Assert.assertEquals(result, ImportResult.IMPORTED_BEST); if (b.equals(best)) break; } // A == best ethereumB = EthereumFactory.createEthereum(SysPropConfigB.props, SysPropConfigB.class); ethereumA.addListener(new EthereumListenerAdapter() { @Override public void onEthStatusUpdated(Channel channel, StatusMessage statusMessage) { ethA = (EthHandler) channel.getEthHandler(); } }); final CountDownLatch semaphore = new CountDownLatch(1); ethereumB.addListener(new EthereumListenerAdapter() { @Override public void onPeerAddedToSyncPool(Channel peer) { semaphore.countDown(); } }); ethereumB.connect(nodeA); semaphore.await(10, SECONDS); if(semaphore.getCount() > 0) { fail("Failed to set up peers"); } } @Configuration @NoAutoscan public static class SysPropConfigA { static SystemProperties props = new SystemProperties(); static Eth62 eth62 = null; @Bean public SystemProperties systemProperties() { return props; } @Bean @Scope("prototype") public Eth62 eth62() throws IllegalAccessException, InstantiationException { if (eth62 != null) return eth62; return new Eth62(); } } @Configuration @NoAutoscan public static class SysPropConfigB { static SystemProperties props = new SystemProperties(); @Bean public SystemProperties systemProperties() { return props; } } }
19,273
32.003425
181
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/solidity/SolidityTypeTest.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.solidity; import static org.junit.Assert.assertEquals; import java.math.BigInteger; import org.junit.Test; import org.spongycastle.util.encoders.Hex; /** * Created by Maximilian Schmidt on 25.09.2018. */ public class SolidityTypeTest { @Test public void ensureUnsignedInteger_isDecodedWithCorrectSignum() { byte[] bigNumberByteArray = { -13, -75, 19, 86, -119, 67, 112, -4, 118, -86, 98, -46, 103, -42, -126, 63, -60, -15, -87, 57, 43, 11, -17, -52, 0, 3, -65, 14, -67, -40, 65, 119 }; SolidityType testObject = new SolidityType.UnsignedIntType("uint256"); Object decode = testObject.decode(bigNumberByteArray); assertEquals(decode.getClass(), BigInteger.class); BigInteger actualBigInteger = (BigInteger) decode; BigInteger expectedBigInteger = new BigInteger(Hex.toHexString(bigNumberByteArray), 16); assertEquals(expectedBigInteger, actualBigInteger); } @Test public void ensureSignedInteger_isDecoded() { byte[] bigNumberByteArray = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 127, -1, -1, -1, -1, -1, -1, -1 }; SolidityType testObject = new SolidityType.IntType("int256"); Object decode = testObject.decode(bigNumberByteArray); assertEquals(decode.getClass(), BigInteger.class); BigInteger actualBigInteger = (BigInteger) decode; BigInteger expectedBigInteger = new BigInteger(bigNumberByteArray); assertEquals(expectedBigInteger, actualBigInteger); } }
2,382
43.12963
150
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/solidity/CompilerTest.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.solidity; import org.ethereum.core.CallTransaction; import org.ethereum.solidity.compiler.CompilationResult; import org.ethereum.solidity.compiler.SolidityCompiler; import org.junit.Assert; import org.junit.Test; import java.io.IOException; import java.nio.file.Path; import java.nio.file.Paths; import java.util.Collections; import static org.ethereum.solidity.compiler.SolidityCompiler.Options.*; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.StringContains.containsString; /** * Created by Anton Nashatyrev on 03.03.2016. */ public class CompilerTest { @Test public void solc_getVersion_shouldWork() throws IOException { final String version = SolidityCompiler.runGetVersionOutput(); // ##### May produce 2 lines: //solc, the solidity compiler commandline interface //Version: 0.4.7+commit.822622cf.mod.Darwin.appleclang System.out.println(version); assertThat(version, containsString("Version:")); } @Test public void simpleTest() throws IOException { String contract = "pragma solidity ^0.4.7;\n" + "\n" + "contract a {\n" + "\n" + " mapping(address => string) private mailbox;\n" + "\n" + " event Mailed(address from, string message);\n" + " event Read(address from, string message);\n" + "\n" + "}"; SolidityCompiler.Result res = SolidityCompiler.compile( contract.getBytes(), true, ABI, BIN, INTERFACE, METADATA); System.out.println("Out: '" + res.output + "'"); System.out.println("Err: '" + res.errors + "'"); CompilationResult result = CompilationResult.parse(res.output); if (result.getContract("a") != null) System.out.println(result.getContract("a").bin); else Assert.fail(); } @Test public void defaultFuncTest() throws IOException { String contractSrc = "pragma solidity ^0.4.7;\n" + "contract a {" + " function() {throw;}" + "}"; SolidityCompiler.Result res = SolidityCompiler.compile( contractSrc.getBytes(), true, ABI, BIN, INTERFACE, METADATA); System.out.println("Out: '" + res.output + "'"); System.out.println("Err: '" + res.errors + "'"); CompilationResult result = CompilationResult.parse(res.output); CompilationResult.ContractMetadata a = result.getContract("a"); CallTransaction.Contract contract = new CallTransaction.Contract(a.abi); System.out.print(contract.functions[0].toString()); } @Test public void compileFilesTest() throws IOException { Path source = Paths.get("src","test","resources","solidity","file1.sol"); SolidityCompiler.Result res = SolidityCompiler.compile(source.toFile(), true, ABI, BIN, INTERFACE, METADATA); System.out.println("Out: '" + res.output + "'"); System.out.println("Err: '" + res.errors + "'"); CompilationResult result = CompilationResult.parse(res.output); Assert.assertEquals("test1", result.getContractName()); Assert.assertEquals(source.toAbsolutePath(), result.getContractPath()); CompilationResult.ContractMetadata a = result.getContract(source, "test1"); CallTransaction.Contract contract = new CallTransaction.Contract(a.abi); System.out.print(contract.functions[0].toString()); } @Test public void compileFilesWithImportTest() throws IOException { Path source = Paths.get("src","test","resources","solidity","file2.sol"); SolidityCompiler.Result res = SolidityCompiler.compile(source.toFile(), true, ABI, BIN, INTERFACE, METADATA); System.out.println("Out: '" + res.output + "'"); System.out.println("Err: '" + res.errors + "'"); CompilationResult result = CompilationResult.parse(res.output); CompilationResult.ContractMetadata a = result.getContract(source, "test2"); CallTransaction.Contract contract = new CallTransaction.Contract(a.abi); System.out.print(contract.functions[0].toString()); } @Test public void compileFilesWithImportFromParentFileTest() throws IOException { Path source = Paths.get("src","test","resources","solidity","foo","file3.sol"); SolidityCompiler.Option allowPathsOption = new SolidityCompiler.Options.AllowPaths(Collections.singletonList(source.getParent().getParent().toFile())); SolidityCompiler.Result res = SolidityCompiler.compile(source.toFile(), true, ABI, BIN, INTERFACE, METADATA, allowPathsOption); System.out.println("Out: '" + res.output + "'"); System.out.println("Err: '" + res.errors + "'"); CompilationResult result = CompilationResult.parse(res.output); Assert.assertEquals(2, result.getContractKeys().size()); Assert.assertEquals(result.getContract("test3"), result.getContract(source,"test3")); Assert.assertNotNull(result.getContract("test1")); CompilationResult.ContractMetadata a = result.getContract(source, "test3"); CallTransaction.Contract contract = new CallTransaction.Contract(a.abi); System.out.print(contract.functions[0].toString()); } @Test public void compileFilesWithImportFromParentStringTest() throws IOException { Path source = Paths.get("src","test","resources","solidity","foo","file3.sol"); SolidityCompiler.Option allowPathsOption = new SolidityCompiler.Options.AllowPaths(Collections.singletonList(source.getParent().getParent().toAbsolutePath().toString())); SolidityCompiler.Result res = SolidityCompiler.compile(source.toFile(), true, ABI, BIN, INTERFACE, METADATA, allowPathsOption); System.out.println("Out: '" + res.output + "'"); System.out.println("Err: '" + res.errors + "'"); CompilationResult result = CompilationResult.parse(res.output); CompilationResult.ContractMetadata a = result.getContract(source, "test3"); CallTransaction.Contract contract = new CallTransaction.Contract(a.abi); System.out.print(contract.functions[0].toString()); } @Test public void compileFilesWithImportFromParentPathTest() throws IOException { Path source = Paths.get("src","test","resources","solidity","foo","file3.sol"); SolidityCompiler.Option allowPathsOption = new SolidityCompiler.Options.AllowPaths(Collections.singletonList(source.getParent().getParent())); SolidityCompiler.Result res = SolidityCompiler.compile(source.toFile(), true, ABI, BIN, INTERFACE, METADATA, allowPathsOption); System.out.println("Out: '" + res.output + "'"); System.out.println("Err: '" + res.errors + "'"); CompilationResult result = CompilationResult.parse(res.output); CompilationResult.ContractMetadata a = result.getContract("test3"); CallTransaction.Contract contract = new CallTransaction.Contract(a.abi); System.out.print(contract.functions[0].toString()); } public static void main(String[] args) throws Exception { new CompilerTest().simpleTest(); } }
8,167
44.127072
178
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/solidity/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.solidity; import static junit.framework.TestCase.assertEquals; import static org.junit.Assert.assertTrue; import org.ethereum.solidity.Abi.Entry; import org.ethereum.solidity.Abi.Entry.Type; import org.junit.Test; import java.io.IOException; public class AbiTest { @Test public void simpleTest() throws IOException { String contractAbi = "[{" + "\"name\":\"simpleFunction\"," + "\"constant\":true," + "\"payable\":true," + "\"type\":\"function\"," + "\"inputs\": [{\"name\":\"_in\", \"type\":\"bytes32\"}]," + "\"outputs\":[{\"name\":\"_out\",\"type\":\"bytes32\"}]}]"; Abi abi = Abi.fromJson(contractAbi); assertEquals(abi.size(), 1); Entry onlyFunc = abi.get(0); assertEquals(onlyFunc.type, Type.function); assertEquals(onlyFunc.inputs.size(), 1); assertEquals(onlyFunc.outputs.size(), 1); assertTrue(onlyFunc.payable); assertTrue(onlyFunc.constant); } @Test public void simpleLegacyTest() throws IOException { String contractAbi = "[{" + "\"name\":\"simpleFunction\"," + "\"constant\":true," + "\"type\":\"function\"," + "\"inputs\": [{\"name\":\"_in\", \"type\":\"bytes32\"}]," + "\"outputs\":[{\"name\":\"_out\",\"type\":\"bytes32\"}]}]"; Abi abi = Abi.fromJson(contractAbi); assertEquals(abi.size(), 1); Entry onlyFunc = abi.get(0); assertEquals(onlyFunc.type, Type.function); assertEquals(onlyFunc.inputs.size(), 1); assertEquals(onlyFunc.outputs.size(), 1); assertTrue(onlyFunc.constant); } }
2,558
35.042254
80
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/trie/TrieTest.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.trie; import org.ethereum.core.AccountState; import org.ethereum.crypto.HashUtil; import org.ethereum.datasource.*; import org.ethereum.datasource.inmem.HashMapDB; import org.ethereum.datasource.inmem.HashMapDBSimple; import org.ethereum.util.Value; import org.json.simple.JSONArray; import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; import org.json.simple.parser.ParseException; import org.junit.After; 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 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 org.ethereum.crypto.HashUtil.EMPTY_TRIE_HASH; import static org.ethereum.crypto.HashUtil.sha3; import static org.ethereum.util.ByteUtil.intToBytes; import static org.junit.Assert.*; import static org.junit.Assert.assertEquals; public class TrieTest { private static final Logger logger = LoggerFactory.getLogger("test"); private static String LONG_STRING = "1234567890abcdefghijklmnopqrstuvwxxzABCEFGHIJKLMNOPQRSTUVWXYZ"; private static String ROOT_HASH_EMPTY = Hex.toHexString(EMPTY_TRIE_HASH); private static String c = "c"; private static String ca = "ca"; private static String cat = "cat"; private static String dog = "dog"; private static String doge = "doge"; private static String test = "test"; private static String dude = "dude"; public class NoDoubleDeleteMapDB extends HashMapDB<byte[]> { @Override public synchronized void delete(byte[] key) { if (storage.get(key) == null) { throw new RuntimeException("Trying delete non-existing entry: " + Hex.toHexString(key)); } super.delete(key); } public NoDoubleDeleteMapDB getDb() {return this;} }; public class TrieCache extends SourceCodec<byte[], Value, byte[], byte[]> { public TrieCache() { super(new NoDoubleDeleteMapDB(), new Serializers.Identity<byte[]>(), Serializers.TrieNodeSerializer); } public NoDoubleDeleteMapDB getDb() {return (NoDoubleDeleteMapDB) getSource();} } // public TrieCache mockDb = new TrieCache(); // public TrieCache mockDb_2 = new TrieCache(); public NoDoubleDeleteMapDB mockDb = new NoDoubleDeleteMapDB(); public NoDoubleDeleteMapDB mockDb_2 = new NoDoubleDeleteMapDB(); // ROOT: [ '\x16', A ] // A: [ '', '', '', '', B, '', '', '', C, '', '', '', '', '', '', '', '' ] // B: [ '\x00\x6f', D ] // D: [ '', '', '', '', '', '', E, '', '', '', '', '', '', '', '', '', 'verb' ] // E: [ '\x17', F ] // F: [ '', '', '', '', '', '', G, '', '', '', '', '', '', '', '', '', 'puppy' ] // G: [ '\x35', 'coin' ] // C: [ '\x20\x6f\x72\x73\x65', 'stallion' ] @After public void closeMockDb() throws IOException { } private static Serializer<String, byte[]> STR_SERIALIZER = new Serializer<String, byte[]>() { public byte[] serialize(String object) {return object == null ? null : object.getBytes();} public String deserialize(byte[] stream) {return stream == null ? null : new String(stream);} }; // private static class StringTrie extends SourceCodec<String, String, byte[], byte[]> { // public StringTrie(Source<byte[], Value> src) { // this(src, null); // } // public StringTrie(Source<byte[], Value> src, byte[] root) { // super(new TrieImpl(new NoDeleteSource<>(src), root), STR_SERIALIZER, STR_SERIALIZER); // } // // public byte[] getRootHash() { // return ((TrieImpl) getSource()).getRootHash(); // } // // public String getTrieDump() { // return ((TrieImpl) getSource()).getTrieDump(); // } // // @Override // public boolean equals(Object obj) { // return getSource().equals(((StringTrie) obj).getSource()); // } // } private static class StringTrie extends SourceCodec<String, String, byte[], byte[]> { public StringTrie(Source<byte[], byte[]> src) { this(src, null); } public StringTrie(Source<byte[], byte[]> src, byte[] root) { super(new TrieImpl(new NoDeleteSource<>(src), root), STR_SERIALIZER, STR_SERIALIZER); } public byte[] getRootHash() { return ((TrieImpl) getSource()).getRootHash(); } public String getTrieDump() { return ((TrieImpl) getSource()).dumpTrie(); } public String dumpStructure() { return ((TrieImpl) getSource()).dumpStructure(); } @Override public String get(String s) { String ret = super.get(s); return ret == null ? "" : ret; } @Override public void put(String s, String val) { if (val == null || val.isEmpty()) { super.delete(s); } else { super.put(s, val); } } @Override public boolean equals(Object obj) { return getSource().equals(((StringTrie) obj).getSource()); } } @Test public void testEmptyKey() { Source<String, String> trie = new StringTrie(mockDb, null); trie.put("", dog); assertEquals(dog, new String(trie.get(""))); } @Test public void testInsertShortString() { StringTrie trie = new StringTrie(mockDb); trie.put(cat, dog); assertEquals(dog, new String(trie.get(cat))); } @Test public void testInsertLongString() { StringTrie trie = new StringTrie(mockDb); trie.put(cat, LONG_STRING); assertEquals(LONG_STRING, new String(trie.get(cat))); } @Test public void testInsertMultipleItems1() { StringTrie trie = new StringTrie(mockDb); trie.put(ca, dude); assertEquals(dude, new String(trie.get(ca))); trie.put(cat, dog); assertEquals(dog, new String(trie.get(cat))); trie.put(dog, test); assertEquals(test, new String(trie.get(dog))); trie.put(doge, LONG_STRING); assertEquals(LONG_STRING, new String(trie.get(doge))); trie.put(test, LONG_STRING); assertEquals(LONG_STRING, new String(trie.get(test))); // Test if everything is still there assertEquals(dude, new String(trie.get(ca))); assertEquals(dog, new String(trie.get(cat))); assertEquals(test, new String(trie.get(dog))); assertEquals(LONG_STRING, new String(trie.get(doge))); assertEquals(LONG_STRING, new String(trie.get(test))); } @Test public void testInsertMultipleItems2() { StringTrie trie = new StringTrie(mockDb); trie.put(cat, dog); assertEquals(dog, trie.get(cat)); System.out.println(trie.getTrieDump()); trie.put(ca, dude); assertEquals(dude, trie.get(ca)); System.out.println(trie.getTrieDump()); trie.put(doge, LONG_STRING); assertEquals(LONG_STRING, trie.get(doge)); System.out.println(trie.getTrieDump()); trie.put(dog, test); assertEquals(test, trie.get(dog)); trie.put(test, LONG_STRING); assertEquals(LONG_STRING, trie.get(test)); // Test if everything is still there assertEquals(dog, trie.get(cat)); assertEquals(dude, trie.get(ca)); assertEquals(LONG_STRING, trie.get(doge)); assertEquals(test, trie.get(dog)); assertEquals(LONG_STRING, trie.get(test)); System.out.println(trie.getTrieDump()); TrieImpl trieNew = new TrieImpl(mockDb.getDb(), trie.getRootHash()); assertEquals(dog, new String(trieNew.get(cat.getBytes()))); assertEquals(dude, new String(trieNew.get(ca.getBytes()))); assertEquals(LONG_STRING, new String(trieNew.get(doge.getBytes()))); assertEquals(test, new String(trieNew.get(dog.getBytes()))); assertEquals(LONG_STRING, new String(trieNew.get(test.getBytes()))); } @Test public void newImplTest() { HashMapDBSimple<byte[]> db = new HashMapDBSimple<>(); TrieImpl btrie = new TrieImpl(db, null); Source<String, String> trie = new SourceCodec<>(btrie, STR_SERIALIZER, STR_SERIALIZER); trie.put("cat", "dog"); trie.put("ca", "dude"); assertEquals(trie.get("cat"), "dog"); assertEquals(trie.get("ca"), "dude"); trie.put(doge, LONG_STRING); System.out.println(btrie.dumpStructure()); System.out.println(btrie.dumpTrie()); assertEquals(LONG_STRING, trie.get(doge)); assertEquals(dog, trie.get(cat)); trie.put(dog, test); assertEquals(test, trie.get(dog)); assertEquals(dog, trie.get(cat)); trie.put(test, LONG_STRING); assertEquals(LONG_STRING, trie.get(test)); System.out.println(btrie.dumpStructure()); System.out.println(btrie.dumpTrie()); assertEquals(dog, trie.get(cat)); assertEquals(dude, trie.get(ca)); assertEquals(LONG_STRING, trie.get(doge)); assertEquals(test, trie.get(dog)); assertEquals(LONG_STRING, trie.get(test)); } @Test public void testUpdateShortToShortString() { StringTrie trie = new StringTrie(mockDb); trie.put(cat, dog); assertEquals(dog, new String(trie.get(cat))); trie.put(cat, dog + "1"); assertEquals(dog + "1", new String(trie.get(cat))); } @Test public void testUpdateLongToLongString() { StringTrie trie = new StringTrie(mockDb); trie.put(cat, LONG_STRING); assertEquals(LONG_STRING, new String(trie.get(cat))); trie.put(cat, LONG_STRING + "1"); assertEquals(LONG_STRING + "1", new String(trie.get(cat))); } @Test public void testUpdateShortToLongString() { StringTrie trie = new StringTrie(mockDb); trie.put(cat, dog); assertEquals(dog, new String(trie.get(cat))); trie.put(cat, LONG_STRING + "1"); assertEquals(LONG_STRING + "1", new String(trie.get(cat))); } @Test public void testUpdateLongToShortString() { StringTrie trie = new StringTrie(mockDb); trie.put(cat, LONG_STRING); assertEquals(LONG_STRING, new String(trie.get(cat))); trie.put(cat, dog + "1"); assertEquals(dog + "1", new String(trie.get(cat))); } @Test public void testDeleteShortString1() { String ROOT_HASH_BEFORE = "a9539c810cc2e8fa20785bdd78ec36cc1dab4b41f0d531e80a5e5fd25c3037ee"; String ROOT_HASH_AFTER = "fc5120b4a711bca1f5bb54769525b11b3fb9a8d6ac0b8bf08cbb248770521758"; StringTrie trie = new StringTrie(mockDb); trie.put(cat, dog); assertEquals(dog, new String(trie.get(cat))); trie.put(ca, dude); assertEquals(dude, new String(trie.get(ca))); assertEquals(ROOT_HASH_BEFORE, Hex.toHexString(trie.getRootHash())); trie.delete(ca); assertEquals("", new String(trie.get(ca))); assertEquals(ROOT_HASH_AFTER, Hex.toHexString(trie.getRootHash())); } @Test public void testDeleteShortString2() { String ROOT_HASH_BEFORE = "a9539c810cc2e8fa20785bdd78ec36cc1dab4b41f0d531e80a5e5fd25c3037ee"; String ROOT_HASH_AFTER = "b25e1b5be78dbadf6c4e817c6d170bbb47e9916f8f6cc4607c5f3819ce98497b"; StringTrie trie = new StringTrie(mockDb); trie.put(ca, dude); assertEquals(dude, new String(trie.get(ca))); trie.put(cat, dog); assertEquals(dog, new String(trie.get(cat))); assertEquals(ROOT_HASH_BEFORE, Hex.toHexString(trie.getRootHash())); trie.delete(cat); assertEquals("", new String(trie.get(cat))); assertEquals(ROOT_HASH_AFTER, Hex.toHexString(trie.getRootHash())); } @Test public void testDeleteShortString3() { String ROOT_HASH_BEFORE = "778ab82a7e8236ea2ff7bb9cfa46688e7241c1fd445bf2941416881a6ee192eb"; String ROOT_HASH_AFTER = "05875807b8f3e735188d2479add82f96dee4db5aff00dc63f07a7e27d0deab65"; StringTrie trie = new StringTrie(mockDb); trie.put(cat, dude); assertEquals(dude, new String(trie.get(cat))); trie.put(dog, test); assertEquals(test, new String(trie.get(dog))); assertEquals(ROOT_HASH_BEFORE, Hex.toHexString(trie.getRootHash())); trie.delete(dog); assertEquals("", new String(trie.get(dog))); assertEquals(ROOT_HASH_AFTER, Hex.toHexString(trie.getRootHash())); } @Test public void testDeleteLongString1() { String ROOT_HASH_BEFORE = "318961a1c8f3724286e8e80d312352f01450bc4892c165cc7614e1c2e5a0012a"; String ROOT_HASH_AFTER = "63356ecf33b083e244122fca7a9b128cc7620d438d5d62e4f8b5168f1fb0527b"; StringTrie trie = new StringTrie(mockDb); trie.put(cat, LONG_STRING); assertEquals(LONG_STRING, new String(trie.get(cat))); trie.put(dog, LONG_STRING); assertEquals(LONG_STRING, new String(trie.get(dog))); assertEquals(ROOT_HASH_BEFORE, Hex.toHexString(trie.getRootHash())); trie.delete(dog); assertEquals("", new String(trie.get(dog))); assertEquals(ROOT_HASH_AFTER, Hex.toHexString(trie.getRootHash())); } @Test public void testDeleteLongString2() { String ROOT_HASH_BEFORE = "e020de34ca26f8d373ff2c0a8ac3a4cb9032bfa7a194c68330b7ac3584a1d388"; String ROOT_HASH_AFTER = "334511f0c4897677b782d13a6fa1e58e18de6b24879d57ced430bad5ac831cb2"; StringTrie trie = new StringTrie(mockDb); trie.put(ca, LONG_STRING); assertEquals(LONG_STRING, new String(trie.get(ca))); trie.put(cat, LONG_STRING); assertEquals(LONG_STRING, new String(trie.get(cat))); assertEquals(ROOT_HASH_BEFORE, Hex.toHexString(trie.getRootHash())); trie.delete(cat); assertEquals("", new String(trie.get(cat))); assertEquals(ROOT_HASH_AFTER, Hex.toHexString(trie.getRootHash())); } @Test public void testDeleteLongString3() { String ROOT_HASH_BEFORE = "e020de34ca26f8d373ff2c0a8ac3a4cb9032bfa7a194c68330b7ac3584a1d388"; String ROOT_HASH_AFTER = "63356ecf33b083e244122fca7a9b128cc7620d438d5d62e4f8b5168f1fb0527b"; StringTrie trie = new StringTrie(mockDb); trie.put(cat, LONG_STRING); assertEquals(LONG_STRING, new String(trie.get(cat))); trie.put(ca, LONG_STRING); assertEquals(LONG_STRING, new String(trie.get(ca))); assertEquals(ROOT_HASH_BEFORE, Hex.toHexString(trie.getRootHash())); trie.delete(ca); assertEquals("", new String(trie.get(ca))); assertEquals(ROOT_HASH_AFTER, Hex.toHexString(trie.getRootHash())); } @Test public void testDeleteCompletellyDiferentItems() { TrieImpl trie = new TrieImpl(mockDb); String val_1 = "1000000000000000000000000000000000000000000000000000000000000000"; String val_2 = "2000000000000000000000000000000000000000000000000000000000000000"; String val_3 = "3000000000000000000000000000000000000000000000000000000000000000"; trie.put(Hex.decode(val_1), Hex.decode(val_1)); trie.put(Hex.decode(val_2), Hex.decode(val_2)); String root1 = Hex.toHexString(trie.getRootHash()); trie.put(Hex.decode(val_3), Hex.decode(val_3)); trie.delete(Hex.decode(val_3)); String root1_ = Hex.toHexString(trie.getRootHash()); Assert.assertEquals(root1, root1_); } @Test public void testDeleteMultipleItems1() { String ROOT_HASH_BEFORE = "3a784eddf1936515f0313b073f99e3bd65c38689021d24855f62a9601ea41717"; String ROOT_HASH_AFTER1 = "60a2e75cfa153c4af2783bd6cb48fd6bed84c6381bc2c8f02792c046b46c0653"; String ROOT_HASH_AFTER2 = "a84739b4762ddf15e3acc4e6957e5ab2bbfaaef00fe9d436a7369c6f058ec90d"; StringTrie trie = new StringTrie(mockDb); trie.put(cat, dog); assertEquals(dog, new String(trie.get(cat))); trie.put(ca, dude); assertEquals(dude, new String(trie.get(ca))); trie.put(doge, LONG_STRING); assertEquals(LONG_STRING, new String(trie.get(doge))); trie.put(dog, test); assertEquals(test, new String(trie.get(dog))); trie.put(test, LONG_STRING); assertEquals(LONG_STRING, new String(trie.get(test))); assertEquals(ROOT_HASH_BEFORE, Hex.toHexString(trie.getRootHash())); System.out.println(trie.dumpStructure()); trie.delete(dog); System.out.println(trie.dumpStructure()); assertEquals("", trie.get(dog)); assertEquals(ROOT_HASH_AFTER1, Hex.toHexString(trie.getRootHash())); trie.delete(test); System.out.println(trie.dumpStructure()); assertEquals("", trie.get(test)); assertEquals(ROOT_HASH_AFTER2, Hex.toHexString(trie.getRootHash())); } @Test public void testDeleteMultipleItems2() { String ROOT_HASH_BEFORE = "cf1ed2b6c4b6558f70ef0ecf76bfbee96af785cb5d5e7bfc37f9804ad8d0fb56"; String ROOT_HASH_AFTER1 = "f586af4a476ba853fca8cea1fbde27cd17d537d18f64269fe09b02aa7fe55a9e"; String ROOT_HASH_AFTER2 = "c59fdc16a80b11cc2f7a8b107bb0c954c0d8059e49c760ec3660eea64053ac91"; StringTrie trie = new StringTrie(mockDb); trie.put(c, LONG_STRING); assertEquals(LONG_STRING, new String(trie.get(c))); trie.put(ca, LONG_STRING); assertEquals(LONG_STRING, new String(trie.get(ca))); trie.put(cat, LONG_STRING); assertEquals(LONG_STRING, new String(trie.get(cat))); assertEquals(ROOT_HASH_BEFORE, Hex.toHexString(trie.getRootHash())); trie.delete(ca); assertEquals("", new String(trie.get(ca))); assertEquals(ROOT_HASH_AFTER1, Hex.toHexString(trie.getRootHash())); trie.delete(cat); assertEquals("", new String(trie.get(cat))); assertEquals(ROOT_HASH_AFTER2, Hex.toHexString(trie.getRootHash())); } @Test public void testMassiveDelete() { TrieImpl trie = new TrieImpl(mockDb); byte[] rootHash1 = null; for (int i = 0; i < 11000; i++) { trie.put(HashUtil.sha3(intToBytes(i)), HashUtil.sha3(intToBytes(i + 1000000))); if (i == 10000) { rootHash1 = trie.getRootHash(); } } for (int i = 10001; i < 11000; i++) { trie.delete(HashUtil.sha3(intToBytes(i))); } byte[] rootHash2 = trie.getRootHash(); assertArrayEquals(rootHash1, rootHash2); } @Test public void testDeleteAll() { String ROOT_HASH_BEFORE = "a84739b4762ddf15e3acc4e6957e5ab2bbfaaef00fe9d436a7369c6f058ec90d"; StringTrie trie = new StringTrie(mockDb); assertEquals(ROOT_HASH_EMPTY, Hex.toHexString(trie.getRootHash())); trie.put(ca, dude); trie.put(cat, dog); trie.put(doge, LONG_STRING); assertEquals(ROOT_HASH_BEFORE, Hex.toHexString(trie.getRootHash())); trie.delete(ca); trie.delete(cat); trie.delete(doge); assertEquals(ROOT_HASH_EMPTY, Hex.toHexString(trie.getRootHash())); } @Test public void testTrieEquals() { StringTrie trie1 = new StringTrie(mockDb); StringTrie trie2 = new StringTrie(mockDb); trie1.put(doge, LONG_STRING); trie2.put(doge, LONG_STRING); assertTrue("Expected tries to be equal", trie1.equals(trie2)); assertEquals(Hex.toHexString(trie1.getRootHash()), Hex.toHexString(trie2.getRootHash())); trie1.put(dog, LONG_STRING); trie2.put(cat, LONG_STRING); assertFalse("Expected tries not to be equal", trie1.equals(trie2)); assertNotEquals(Hex.toHexString(trie1.getRootHash()), Hex.toHexString(trie2.getRootHash())); } // Using tests from: https://github.com/ethereum/tests/blob/master/trietest.json @Test public void testSingleItem() { StringTrie trie = new StringTrie(mockDb); trie.put("A", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); assertEquals("d23786fb4a010da3ce639d66d5e904a11dbc02746d1ce25029e53290cabf28ab", Hex.toHexString(trie.getRootHash())); } @Test public void testDogs() { StringTrie trie = new StringTrie(mockDb); trie.put("doe", "reindeer"); assertEquals("11a0327cfcc5b7689b6b6d727e1f5f8846c1137caaa9fc871ba31b7cce1b703e", Hex.toHexString(trie.getRootHash())); trie.put("dog", "puppy"); assertEquals("05ae693aac2107336a79309e0c60b24a7aac6aa3edecaef593921500d33c63c4", Hex.toHexString(trie.getRootHash())); trie.put("dogglesworth", "cat"); assertEquals("8aad789dff2f538bca5d8ea56e8abe10f4c7ba3a5dea95fea4cd6e7c3a1168d3", Hex.toHexString(trie.getRootHash())); } @Test public void testPuppy() { StringTrie trie = new StringTrie(mockDb); trie.put("do", "verb"); trie.put("doge", "coin"); trie.put("horse", "stallion"); trie.put("dog", "puppy"); assertEquals("5991bb8c6514148a29db676a14ac506cd2cd5775ace63c30a4fe457715e9ac84", Hex.toHexString(trie.getRootHash())); } @Test public void testEmptyValues() { StringTrie trie = new StringTrie(mockDb); trie.put("do", "verb"); trie.put("ether", "wookiedoo"); trie.put("horse", "stallion"); trie.put("shaman", "horse"); trie.put("doge", "coin"); trie.put("ether", ""); trie.put("dog", "puppy"); trie.put("shaman", ""); assertEquals("5991bb8c6514148a29db676a14ac506cd2cd5775ace63c30a4fe457715e9ac84", Hex.toHexString(trie.getRootHash())); } @Test public void testFoo() { StringTrie trie = new StringTrie(mockDb); trie.put("foo", "bar"); trie.put("food", "bat"); trie.put("food", "bass"); assertEquals("17beaa1648bafa633cda809c90c04af50fc8aed3cb40d16efbddee6fdf63c4c3", Hex.toHexString(trie.getRootHash())); } @Test public void testSmallValues() { StringTrie trie = new StringTrie(mockDb); trie.put("be", "e"); trie.put("dog", "puppy"); trie.put("bed", "d"); assertEquals("3f67c7a47520f79faa29255d2d3c084a7a6df0453116ed7232ff10277a8be68b", Hex.toHexString(trie.getRootHash())); } @Test public void testTesty() { StringTrie trie = new StringTrie(mockDb); trie.put("test", "test"); assertEquals("85d106d4edff3b7a4889e91251d0a87d7c17a1dda648ebdba8c6060825be23b8", Hex.toHexString(trie.getRootHash())); trie.put("te", "testy"); assertEquals("8452568af70d8d140f58d941338542f645fcca50094b20f3c3d8c3df49337928", Hex.toHexString(trie.getRootHash())); } private final String randomDictionary = "spinneries, archipenko, prepotency, herniotomy, preexpress, relaxative, insolvably, debonnaire, apophysate, virtuality, cavalryman, utilizable, diagenesis, vitascopic, governessy, abranchial, cyanogenic, gratulated, signalment, predicable, subquality, crystalize, prosaicism, oenologist, repressive, impanelled, cockneyism, bordelaise, compigne, konstantin, predicated, unsublimed, hydrophane, phycomyces, capitalise, slippingly, untithable, unburnable, deoxidizer, misteacher, precorrect, disclaimer, solidified, neuraxitis, caravaning, betelgeuse, underprice, uninclosed, acrogynous, reirrigate, dazzlingly, chaffiness, corybantes, intumesced, intentness, superexert, abstrusely, astounding, pilgrimage, posttarsal, prayerless, nomologist, semibelted, frithstool, unstinging, ecalcarate, amputating, megascopic, graphalloy, platteland, adjacently, mingrelian, valentinus, appendical, unaccurate, coriaceous, waterworks, sympathize, doorkeeper, overguilty, flaggingly, admonitory, aeriferous, normocytic, parnellism, catafalque, odontiasis, apprentice, adulterous, mechanisma, wilderness, undivorced, reinterred, effleurage, pretrochal, phytogenic, swirlingly, herbarized, unresolved, classifier, diosmosing, microphage, consecrate, astarboard, predefying, predriving, lettergram, ungranular, overdozing, conferring, unfavorite, peacockish, coinciding, erythraeum, freeholder, zygophoric, imbitterer, centroidal, appendixes, grayfishes, enological, indiscreet, broadcloth, divulgated, anglophobe, stoopingly, bibliophil, laryngitis, separatist, estivating, bellarmine, greasiness, typhlology, xanthation, mortifying, endeavorer, aviatrices, unequalise, metastatic, leftwinger, apologizer, quatrefoil, nonfouling, bitartrate, outchiding, undeported, poussetted, haemolysis, asantehene, montgomery, unjoinable, cedarhurst, unfastener, nonvacuums, beauregard, animalized, polyphides, cannizzaro, gelatinoid, apologised, unscripted, tracheidal, subdiscoid, gravelling, variegated, interabang, inoperable, immortelle, laestrygon, duplicatus, proscience, deoxidised, manfulness, channelize, nondefense, ectomorphy, unimpelled, headwaiter, hexaemeric, derivation, prelexical, limitarian, nonionized, prorefugee, invariably, patronizer, paraplegia, redivision, occupative, unfaceable, hypomnesia, psalterium, doctorfish, gentlefolk, overrefine, heptastich, desirously, clarabelle, uneuphonic, autotelism, firewarden, timberjack, fumigation, drainpipes, spathulate, novelvelle, bicorporal, grisliness, unhesitant, supergiant, unpatented, womanpower, toastiness, multichord, paramnesia, undertrick, contrarily, neurogenic, gunmanship, settlement, brookville, gradualism, unossified, villanovan, ecospecies, organising, buckhannon, prefulfill, johnsonese, unforegone, unwrathful, dunderhead, erceldoune, unwadeable, refunction, understuff, swaggering, freckliest, telemachus, groundsill, outslidden, bolsheviks, recognizer, hemangioma, tarantella, muhammedan, talebearer, relocation, preemption, chachalaca, septuagint, ubiquitous, plexiglass, humoresque, biliverdin, tetraploid, capitoline, summerwood, undilating, undetested, meningitic, petrolatum, phytotoxic, adiphenine, flashlight, protectory, inwreathed, rawishness, tendrillar, hastefully, bananaquit, anarthrous, unbedimmed, herborized, decenniums, deprecated, karyotypic, squalidity, pomiferous, petroglyph, actinomere, peninsular, trigonally, androgenic, resistance, unassuming, frithstool, documental, eunuchised, interphone, thymbraeus, confirmand, expurgated, vegetation, myographic, plasmagene, spindrying, unlackeyed, foreknower, mythically, albescence, rebudgeted, implicitly, unmonastic, torricelli, mortarless, labialized, phenacaine, radiometry, sluggishly, understood, wiretapper, jacobitely, unbetrayed, stadholder, directress, emissaries, corelation, sensualize, uncurbable, permillage, tentacular, thriftless, demoralize, preimagine, iconoclast, acrobatism, firewarden, transpired, bluethroat, wanderjahr, groundable, pedestrian, unulcerous, preearthly, freelanced, sculleries, avengingly, visigothic, preharmony, bressummer, acceptable, unfoolable, predivider, overseeing, arcosolium, piriformis, needlecord, homebodies, sulphation, phantasmic, unsensible, unpackaged, isopiestic, cytophagic, butterlike, frizzliest, winklehawk, necrophile, mesothorax, cuchulainn, unrentable, untangible, unshifting, unfeasible, poetastric, extermined, gaillardia, nonpendent, harborside, pigsticker, infanthood, underrower, easterling, jockeyship, housebreak, horologium, undepicted, dysacousma, incurrable, editorship, unrelented, peritricha, interchaff, frothiness, underplant, proafrican, squareness, enigmatise, reconciled, nonnumeral, nonevident, hamantasch, victualing, watercolor, schrdinger, understand, butlerlike, hemiglobin, yankeeland"; @Test public void testMasiveUpdate() { boolean massiveUpdateTestEnabled = false; if (massiveUpdateTestEnabled) { List<String> randomWords = Arrays.asList(randomDictionary.split(",")); HashMap<String, String> testerMap = new HashMap<>(); StringTrie trie = new StringTrie(mockDb); Random generator = new Random(); // Random insertion for (int i = 0; i < 100000; ++i) { int randomIndex1 = generator.nextInt(randomWords.size()); int randomIndex2 = generator.nextInt(randomWords.size()); String word1 = randomWords.get(randomIndex1).trim(); String word2 = randomWords.get(randomIndex2).trim(); trie.put(word1, word2); testerMap.put(word1, word2); } int half = testerMap.size() / 2; for (int r = 0; r < half; ++r) { int randomIndex = generator.nextInt(randomWords.size()); String word1 = randomWords.get(randomIndex).trim(); testerMap.remove(word1); trie.delete(word1); } // Assert the result now Iterator<String> keys = testerMap.keySet().iterator(); while (keys.hasNext()) { String mapWord1 = keys.next(); String mapWord2 = testerMap.get(mapWord1); String treeWord2 = new String(trie.get(mapWord1)); Assert.assertEquals(mapWord2, treeWord2); } } } @Test public void testMassiveDeterministicUpdate() throws IOException, URISyntaxException { // should be root: cfd77c0fcb037adefce1f4e2eb94381456a4746379d2896bb8f309c620436d30 URL massiveUpload_1 = ClassLoader .getSystemResource("trie/massive-upload.dmp"); File file = new File(massiveUpload_1.toURI()); List<String> strData = Files.readAllLines(file.toPath(), StandardCharsets.UTF_8); // *** Part - 1 *** // 1. load the data from massive-upload.dmp // which includes deletes/upadtes (5000 operations) StringTrie trieSingle = new StringTrie(mockDb_2); for (String aStrData : strData) { String[] keyVal = aStrData.split("="); if (keyVal[0].equals("*")) trieSingle.delete(keyVal[1].trim()); else trieSingle.put(keyVal[0].trim(), keyVal[1].trim()); } System.out.println("root_1: => " + Hex.toHexString(trieSingle.getRootHash())); // *** Part - 2 *** // pre. we use the same data from massive-upload.dmp // which includes deletes/upadtes (100000 operations) // 1. part of the data loaded // 2. the trie cache sync to the db // 3. the rest of the data loaded with part of the trie not in the cache StringTrie trie = new StringTrie(mockDb); for (int i = 0; i < 2000; ++i) { String[] keyVal = strData.get(i).split("="); if (keyVal[0].equals("*")) trie.delete(keyVal[1].trim()); else trie.put(keyVal[0].trim(), keyVal[1].trim()); } StringTrie trie2 = new StringTrie(mockDb, trie.getRootHash()); for (int i = 2000; i < strData.size(); ++i) { String[] keyVal = strData.get(i).split("="); if (keyVal[0].equals("*")) trie2.delete(keyVal[1].trim()); else trie2.put(keyVal[0].trim(), keyVal[1].trim()); } System.out.println("root_2: => " + Hex.toHexString(trie2.getRootHash())); assertArrayEquals(trieSingle.getRootHash(), trie2.getRootHash()); } @Test // tests saving keys to the file // public void testMasiveUpdateFromDB() { boolean massiveUpdateFromDBEnabled = false; if (massiveUpdateFromDBEnabled) { List<String> randomWords = Arrays.asList(randomDictionary.split(",")); Map<String, String> testerMap = new HashMap<>(); StringTrie trie = new StringTrie(mockDb); Random generator = new Random(); // Random insertion for (int i = 0; i < 50000; ++i) { int randomIndex1 = generator.nextInt(randomWords.size()); int randomIndex2 = generator.nextInt(randomWords.size()); String word1 = randomWords.get(randomIndex1).trim(); String word2 = randomWords.get(randomIndex2).trim(); trie.put(word1, word2); testerMap.put(word1, word2); } // trie.cleanCache(); // trie.sync(); // Assert the result now Iterator<String> keys = testerMap.keySet().iterator(); while (keys.hasNext()) { String mapWord1 = keys.next(); String mapWord2 = testerMap.get(mapWord1); String treeWord2 = new String(trie.get(mapWord1)); Assert.assertEquals(mapWord2, treeWord2); } TrieImpl trie2 = new TrieImpl(mockDb, trie.getRootHash()); // Assert the result now keys = testerMap.keySet().iterator(); while (keys.hasNext()) { String mapWord1 = keys.next(); String mapWord2 = testerMap.get(mapWord1); String treeWord2 = new String(trie2.get(mapWord1.getBytes())); Assert.assertEquals(mapWord2, treeWord2); } } } @Test public void testRollbackTrie() throws URISyntaxException, IOException { StringTrie trieSingle = new StringTrie(mockDb); URL massiveUpload_1 = ClassLoader .getSystemResource("trie/massive-upload.dmp"); File file = new File(massiveUpload_1.toURI()); List<String> strData = Files.readAllLines(file.toPath(), StandardCharsets.UTF_8); List<byte[]> roots = new ArrayList<>(); Map<String, String> trieDumps = new HashMap<>(); for (int i = 0; i < 100; ++i) { String[] keyVal = strData.get(i).split("="); if (keyVal[0].equals("*")) trieSingle.delete(keyVal[1].trim()); else trieSingle.put(keyVal[0].trim(), keyVal[1].trim()); byte[] hash = trieSingle.getRootHash(); roots.add(hash); String key = Hex.toHexString(hash); String dump = trieSingle.getTrieDump(); trieDumps.put(key, dump); } // compare all 100 rollback dumps and // the originaly saved dumps for (int i = 1; i < roots.size(); ++i) { byte[] root = roots.get(i); logger.info("rollback over root : {}", Hex.toHexString(root)); trieSingle = new StringTrie(mockDb, root); String currDump = trieSingle.getTrieDump(); String originDump = trieDumps.get(Hex.toHexString(root)); Assert.assertEquals(currDump, originDump); } } @Test public void testGetFromRootNode() { StringTrie trie1 = new StringTrie(mockDb); trie1.put(cat, LONG_STRING); TrieImpl trie2 = new TrieImpl(mockDb, trie1.getRootHash()); assertEquals(LONG_STRING, new String(trie2.get(cat.getBytes()))); } /* 0x7645b9fbf1b51e6b980801fafe6bbc22d2ebe218 0x517eaccda568f3fa24915fed8add49d3b743b3764c0bc495b19a47c54dbc3d62 0x 0x1 0x0000000000000000000000000000000000000000000000000000000000000010 0x947e70f9460402290a3e487dae01f610a1a8218fda 0x0000000000000000000000000000000000000000000000000000000000000014 0x40 0x0000000000000000000000000000000000000000000000000000000000000016 0x94412e0c4f0102f3f0ac63f0a125bce36ca75d4e0d 0x0000000000000000000000000000000000000000000000000000000000000017 0x01 */ @Test public void storageHashCalc_1() { byte[] key1 = Hex.decode("0000000000000000000000000000000000000000000000000000000000000010"); byte[] key2 = Hex.decode("0000000000000000000000000000000000000000000000000000000000000014"); byte[] key3 = Hex.decode("0000000000000000000000000000000000000000000000000000000000000016"); byte[] key4 = Hex.decode("0000000000000000000000000000000000000000000000000000000000000017"); byte[] val1 = Hex.decode("947e70f9460402290a3e487dae01f610a1a8218fda"); byte[] val2 = Hex.decode("40"); byte[] val3 = Hex.decode("94412e0c4f0102f3f0ac63f0a125bce36ca75d4e0d"); byte[] val4 = Hex.decode("01"); TrieImpl storage = new TrieImpl(); storage.put(key1, val1); storage.put(key2, val2); storage.put(key3, val3); storage.put(key4, val4); String hash = Hex.toHexString(storage.getRootHash()); System.out.println(hash); Assert.assertEquals("517eaccda568f3fa24915fed8add49d3b743b3764c0bc495b19a47c54dbc3d62", hash); } @Test public void testFromDump_1() throws URISyntaxException, IOException, ParseException { // LOAD: real dump from real state run URL dbDump = ClassLoader .getSystemResource("dbdump/dbdump.json"); File dbDumpFile = new File(dbDump.toURI()); byte[] testData = Files.readAllBytes(dbDumpFile.toPath()); String testSrc = new String(testData); JSONParser parser = new JSONParser(); JSONArray dbDumpJSONArray = (JSONArray) parser.parse(testSrc); // KeyValueDataSource keyValueDataSource = new LevelDbDataSource("testState"); // keyValueDataSource.init(); HashMapDB<byte[]> dataSource = new HashMapDB<>(); for (Object aDbDumpJSONArray : dbDumpJSONArray) { JSONObject obj = (JSONObject) aDbDumpJSONArray; byte[] key = Hex.decode(obj.get("key").toString()); byte[] val = Hex.decode(obj.get("val").toString()); dataSource.put(key, val); } // TEST: load trie out of this run up to block#33 byte[] rootNode = Hex.decode("bb690805d24882bc7ccae6fc0f80ac146274d5b81c6a6e9c882cd9b0a649c9c7"); TrieImpl trie = new TrieImpl(dataSource, rootNode); // first key added in genesis byte[] val1 = trie.get(Hex.decode("51ba59315b3a95761d0863b05ccc7a7f54703d99")); AccountState accountState1 = new AccountState(val1); assertEquals(BigInteger.valueOf(2).pow(200), accountState1.getBalance()); assertEquals("c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470", Hex.toHexString(accountState1.getCodeHash())); assertEquals(BigInteger.ZERO, accountState1.getNonce()); assertEquals(null, accountState1.getStateRoot()); // last key added up to block#33 byte[] val2 = trie.get(Hex.decode("a39c2067eb45bc878818946d0f05a836b3da44fa")); AccountState accountState2 = new AccountState(val2); assertEquals(new BigInteger("1500000000000000000"), accountState2.getBalance()); assertEquals("c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470", Hex.toHexString(accountState2.getCodeHash())); assertEquals(BigInteger.ZERO, accountState2.getNonce()); assertEquals(null, accountState2.getStateRoot()); // keyValueDataSource.close(); } @Test // update the trie with blog key/val // each time dump the entire trie public void testSample_1() { StringTrie trie = new StringTrie(mockDb); trie.put("dog", "puppy"); String dmp = trie.getTrieDump(); System.out.println(dmp); System.out.println(); Assert.assertEquals("ed6e08740e4a267eca9d4740f71f573e9aabbcc739b16a2fa6c1baed5ec21278", Hex.toHexString(trie.getRootHash())); trie.put("do", "verb"); dmp = trie.getTrieDump(); System.out.println(dmp); System.out.println(); Assert.assertEquals("779db3986dd4f38416bfde49750ef7b13c6ecb3e2221620bcad9267e94604d36", Hex.toHexString(trie.getRootHash())); trie.put("doggiestan", "aeswome_place"); dmp = trie.getTrieDump(); System.out.println(dmp); System.out.println(); Assert.assertEquals("8bd5544747b4c44d1274aa99a6293065fe319b3230e800203317e4c75a770099", Hex.toHexString(trie.getRootHash())); } @Test public void testSecureTrie(){ Trie trie = new SecureTrie(mockDb); byte[] k1 = "do".getBytes(); byte[] v1 = "verb".getBytes(); byte[] k2 = "ether".getBytes(); byte[] v2 = "wookiedoo".getBytes(); byte[] k3 = "horse".getBytes(); byte[] v3 = "stallion".getBytes(); byte[] k4 = "shaman".getBytes(); byte[] v4 = "horse".getBytes(); byte[] k5 = "doge".getBytes(); byte[] v5 = "coin".getBytes(); byte[] k6 = "ether".getBytes(); byte[] v6 = "".getBytes(); byte[] k7 = "dog".getBytes(); byte[] v7 = "puppy".getBytes(); byte[] k8 = "shaman".getBytes(); byte[] v8 = "".getBytes(); trie.put(k1, v1); trie.put(k2, v2); trie.put(k3, v3); trie.put(k4, v4); trie.put(k5, v5); trie.put(k6, v6); trie.put(k7, v7); trie.put(k8, v8); byte[] root = trie.getRootHash(); logger.info("root: " + Hex.toHexString(root)); Assert.assertEquals("29b235a58c3c25ab83010c327d5932bcf05324b7d6b1185e650798034783ca9d",Hex.toHexString(root)); } // this case relates to a bug which led us to conflict on Morden network (block #486248) // first part of the new Value was converted to String by #asString() during key deletion // and some lines after String.getBytes() returned byte array which differed to array before converting @Test public void testBugFix() throws ParseException, IOException, URISyntaxException { Map<String, String> dataMap = new HashMap<>(); dataMap.put("6e929251b981389774af84a07585724c432e2db487381810719c3dd913192ae2", "00000000000000000000000000000000000000000000000000000000000000be"); dataMap.put("6e92718d00dae27b2a96f6853a0bf11ded08bc658b2e75904ca0344df5aff9ae", "00000000000000000000000000000000000000000000002f0000000000000000"); TrieImpl trie = new TrieImpl(); for (Map.Entry<String, String> e : dataMap.entrySet()) { trie.put(Hex.decode(e.getKey()), Hex.decode(e.getValue())); } assertArrayEquals(trie.get(Hex.decode("6e929251b981389774af84a07585724c432e2db487381810719c3dd913192ae2")), Hex.decode("00000000000000000000000000000000000000000000000000000000000000be")); assertArrayEquals(trie.get(Hex.decode("6e92718d00dae27b2a96f6853a0bf11ded08bc658b2e75904ca0344df5aff9ae")), Hex.decode("00000000000000000000000000000000000000000000002f0000000000000000")); trie.delete(Hex.decode("6e9286c946c6dd1f5d97f35683732dc8a70dc511133a43d416892f527dfcd243")); assertArrayEquals(trie.get(Hex.decode("6e929251b981389774af84a07585724c432e2db487381810719c3dd913192ae2")), Hex.decode("00000000000000000000000000000000000000000000000000000000000000be")); assertArrayEquals(trie.get(Hex.decode("6e92718d00dae27b2a96f6853a0bf11ded08bc658b2e75904ca0344df5aff9ae")), Hex.decode("00000000000000000000000000000000000000000000002f0000000000000000")); } @Test public void testBugFix2() throws ParseException, IOException, URISyntaxException { Source<byte[], byte[]> src = new HashMapDB<>(); // Create trie: root -> BranchNode (..., NodeValue (less than 32 bytes), ...) TrieImpl trie = new TrieImpl(src); trie.put(Hex.decode("0000000000000000000000000000000000000000000000000000000000000011"), Hex.decode("11")); trie.put(Hex.decode("0000000000000000000000000000000000000000000000000000000000000022"), Hex.decode("22")); trie.flush(); // Reset trie to refresh the nodes trie = new TrieImpl(src, trie.getRootHash()); // Update trie: root -> dirty BranchNode (..., NodeValue (less than 32 bytes), ..., dirty NodeValue, ...) trie.put(Hex.decode("0000000000000000000000000000000000000000000000000000000000000033"), Hex.decode("33")); // BUG: // In that case NodeValue (encoded as plain RLP list) isn't dirty // while both rlp and hash fields are null, Node has been initialized with parsedRLP only // Therefore any subsequent call to BranchNode.encode() fails with NPE // FIX: // Supply Node initialization with raw rlp value assertEquals("36e350d9a1d9c02d5bc4539a05e51890784ea5d2b675a0b26725dbbdadb4d6e2", Hex.toHexString(trie.getRootHash())); } @Test public void testBugFix3() throws ParseException, IOException, URISyntaxException { HashMapDB<byte[]> src = new HashMapDB<>(); // Scenario: // create trie with subtrie: ... -> kvNodeNode -> BranchNode() -> kvNodeValue1, kvNodeValue2 // remove kvNodeValue2, in that way kvNodeNode and kvNodeValue1 are going to be merged in a new kvNodeValue3 // BUG: kvNodeNode is not deleted from storage after the merge TrieImpl trie = new TrieImpl(src); trie.put(Hex.decode("0000000000000000000000000000000000000000000000000000000000011133"), Hex.decode("0000000000000000000000000000000000000000000000000000000000000033")); trie.put(Hex.decode("0000000000000000000000000000000000000000000000000000000000021244"), Hex.decode("0000000000000000000000000000000000000000000000000000000000000044")); trie.put(Hex.decode("0000000000000000000000000000000000000000000000000000000000011255"), Hex.decode("0000000000000000000000000000000000000000000000000000000000000055")); trie.flush(); trie.delete(Hex.decode("0000000000000000000000000000000000000000000000000000000000011255")); assertFalse(src.getStorage().containsKey(Hex.decode("5152f9274abb8e61f3956ccd08d31e38bfa2913afd23bc13b5e7bb709ce7f603"))); } @Ignore @Test public void perfTestGet() { HashMapDBSimple<byte[]> db = new HashMapDBSimple<>(); TrieCache trieCache = new TrieCache(); TrieImpl trie = new TrieImpl(db); byte[][] keys = new byte[100000][]; System.out.println("Filling trie..."); for (int i = 0; i < 100_000; i++) { byte[] k = sha3(intToBytes(i)); trie.put(k, k); if (i < keys.length) { keys[i] = k; } } // Trie trie1 = new TrieImpl(new ReadCache.BytesKey<>(trieCache), trie.getRootHash()); // Trie trie1 = new TrieImpl(trieCache.getDb(), trie.getRootHash()); System.out.println("Benching..."); while (true) { long s = System.nanoTime(); for (int j = 0; j < 5; j++) { for (int k = 0; k < 100; k++) { // Trie trie1 = new TrieImpl(new ReadCache.BytesKey<>(trieCache), trie.getRootHash()); // Trie trie1 = new TrieImpl(trieCache.getDb(), trie.getRootHash()); for (int i = 0; i < 1000; i++) { Trie trie1 = new TrieImpl(trieCache.getDb(), trie.getRootHash()); // Trie trie1 = new TrieImpl(trieCache, trie.getRootHash()); trie1.get(keys[k * 100 + i]); } } } System.out.println((System.nanoTime() - s) / 1_000_000 + " ms"); } } @Ignore @Test public void perfTestRoot() { while(true) { HashMapDB<byte[]> db = new HashMapDB<>(); TrieCache trieCache = new TrieCache(); // TrieImpl trie = new TrieImpl(trieCache); TrieImpl trie = new TrieImpl(db, null); trie.setAsync(true); // System.out.println("Filling trie..."); long s = System.nanoTime(); for (int i = 0; i < 200_000; i++) { byte[] k = sha3(intToBytes(i)); trie.put(k, new byte[512]); } long s1 = System.nanoTime(); // System.out.println("Calculating root..."); System.out.println(Hex.toHexString(trie.getRootHash())); System.out.println((System.nanoTime() - s) / 1_000_000 + " ms, root: " + (System.nanoTime() - s1) / 1_000_000 + " ms"); } } }
49,209
40.076795
4,843
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/vm/BytecodeCompiler.java
/* * Copyright (c) [2018] [ <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.vm; import org.ethereum.vm.OpCode; import org.spongycastle.util.encoders.Hex; import java.util.ArrayList; import java.util.List; public class BytecodeCompiler { public byte[] compile(String code) { return compile(code.split("\\s+")); } private byte[] compile(String[] tokens) { List<Byte> bytecodes = new ArrayList<>(); int ntokens = tokens.length; for (int i = 0; i < ntokens; i++) { String token = tokens[i].trim().toUpperCase(); if (token.isEmpty()) continue; if (isHexadecimal(token)) compileHexadecimal(token, bytecodes); else bytecodes.add(OpCode.byteVal(token)); } int nbytes = bytecodes.size(); byte[] bytes = new byte[nbytes]; for (int k = 0; k < nbytes; k++) bytes[k] = bytecodes.get(k).byteValue(); return bytes; } private static boolean isHexadecimal(String token) { return token.startsWith("0X"); } private static void compileHexadecimal(String token, List<Byte> bytecodes) { byte[] bytes = Hex.decode(token.substring(2)); for (int k = 0; k < bytes.length; k++) bytecodes.add(bytes[k]); } }
2,076
30
80
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/vm/VMArithmeticOpTest.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.vm; import org.ethereum.vm.program.Program; import org.junit.Ignore; import org.junit.Test; import org.spongycastle.util.encoders.Hex; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; /** * Simple tests for VM Arithmetic Operations */ public class VMArithmeticOpTest extends VMBaseOpTest { @Test // ADD OP mal public void testADD_1() { VM vm = new VM(); program = new Program(compile("PUSH1 0x02 PUSH1 0x02 ADD"), invoke); String s_expected_1 = "0000000000000000000000000000000000000000000000000000000000000004"; vm.step(program); vm.step(program); vm.step(program); DataWord item1 = program.stackPop(); assertEquals(s_expected_1, Hex.toHexString(item1.getData()).toUpperCase()); } @Test // ADD OP public void testADD_2() { VM vm = new VM(); program = new Program(compile("PUSH2 0x1002 PUSH1 0x02 ADD"), invoke); String s_expected_1 = "0000000000000000000000000000000000000000000000000000000000001004"; vm.step(program); vm.step(program); vm.step(program); DataWord item1 = program.stackPop(); assertEquals(s_expected_1, Hex.toHexString(item1.getData()).toUpperCase()); } @Test // ADD OP public void testADD_3() { VM vm = new VM(); program = new Program(compile("PUSH2 0x1002 PUSH6 0x123456789009 ADD"), invoke); String s_expected_1 = "000000000000000000000000000000000000000000000000000012345678A00B"; vm.step(program); vm.step(program); vm.step(program); DataWord item1 = program.stackPop(); assertEquals(s_expected_1, Hex.toHexString(item1.getData()).toUpperCase()); } @Test(expected = Program.StackTooSmallException.class) // ADD OP mal public void testADD_4() { VM vm = new VM(); program = new Program(compile("PUSH2 0x1234 ADD"), invoke); try { vm.step(program); vm.step(program); } finally { assertTrue(program.isStopped()); } } @Test // ADDMOD OP mal public void testADDMOD_1() { VM vm = new VM(); program = new Program(compile("PUSH1 0x02 PUSH1 0x02 PUSH1 0x03 ADDMOD"), invoke); String s_expected_1 = "0000000000000000000000000000000000000000000000000000000000000001"; vm.step(program); vm.step(program); vm.step(program); vm.step(program); DataWord item1 = program.stackPop(); assertTrue(program.isStopped()); assertEquals(s_expected_1, Hex.toHexString(item1.getData()).toUpperCase()); } @Test // ADDMOD OP public void testADDMOD_2() { VM vm = new VM(); program = new Program(compile("PUSH2 0x1000 PUSH1 0x02 PUSH2 0x1002 ADDMOD PUSH1 0x00"), invoke); String s_expected_1 = "0000000000000000000000000000000000000000000000000000000000000004"; vm.step(program); vm.step(program); vm.step(program); vm.step(program); DataWord item1 = program.stackPop(); assertFalse(program.isStopped()); assertEquals(s_expected_1, Hex.toHexString(item1.getData()).toUpperCase()); } @Test // ADDMOD OP public void testADDMOD_3() { VM vm = new VM(); program = new Program(compile("PUSH2 0x1002 PUSH6 0x123456789009 PUSH1 0x02 ADDMOD"), invoke); String s_expected_1 = "000000000000000000000000000000000000000000000000000000000000093B"; vm.step(program); vm.step(program); vm.step(program); vm.step(program); DataWord item1 = program.stackPop(); assertTrue(program.isStopped()); assertEquals(s_expected_1, Hex.toHexString(item1.getData()).toUpperCase()); } @Test(expected = Program.StackTooSmallException.class) // ADDMOD OP mal public void testADDMOD_4() { VM vm = new VM(); program = new Program(compile("PUSH2 0x1234 ADDMOD"), invoke); try { vm.step(program); vm.step(program); } finally { assertTrue(program.isStopped()); } } @Test // MUL OP public void testMUL_1() { VM vm = new VM(); program = new Program(compile("PUSH1 0x03 PUSH1 0x02 MUL"), invoke); String s_expected_1 = "0000000000000000000000000000000000000000000000000000000000000006"; vm.step(program); vm.step(program); vm.step(program); DataWord item1 = program.stackPop(); assertEquals(s_expected_1, Hex.toHexString(item1.getData()).toUpperCase()); } @Test // MUL OP public void testMUL_2() { VM vm = new VM(); program = new Program(compile("PUSH3 0x222222 PUSH1 0x03 MUL"), invoke); String s_expected_1 = "0000000000000000000000000000000000000000000000000000000000666666"; vm.step(program); vm.step(program); vm.step(program); DataWord item1 = program.stackPop(); assertEquals(s_expected_1, Hex.toHexString(item1.getData()).toUpperCase()); } @Test // MUL OP public void testMUL_3() { VM vm = new VM(); program = new Program(compile("PUSH3 0x222222 PUSH3 0x333333 MUL"), invoke); String s_expected_1 = "000000000000000000000000000000000000000000000000000006D3A05F92C6"; vm.step(program); vm.step(program); vm.step(program); DataWord item1 = program.stackPop(); assertEquals(s_expected_1, Hex.toHexString(item1.getData()).toUpperCase()); } @Test(expected = Program.StackTooSmallException.class) // MUL OP mal public void testMUL_4() { VM vm = new VM(); program = new Program(compile("PUSH1 0x01 MUL"), invoke); try { vm.step(program); vm.step(program); } finally { assertTrue(program.isStopped()); } } @Test // MULMOD OP public void testMULMOD_1() { VM vm = new VM(); program = new Program(compile("PUSH1 0x03 PUSH1 0x02 PUSH1 0x04 MULMOD"), invoke); String s_expected_1 = "0000000000000000000000000000000000000000000000000000000000000002"; vm.step(program); vm.step(program); vm.step(program); vm.step(program); DataWord item1 = program.stackPop(); assertEquals(s_expected_1, Hex.toHexString(item1.getData()).toUpperCase()); } @Test // MULMOD OP public void testMULMOD_2() { VM vm = new VM(); program = new Program(compile("PUSH3 0x222222 PUSH1 0x03 PUSH1 0x04 MULMOD"), invoke); String s_expected_1 = "000000000000000000000000000000000000000000000000000000000000000C"; vm.step(program); vm.step(program); vm.step(program); vm.step(program); DataWord item1 = program.stackPop(); assertEquals(s_expected_1, Hex.toHexString(item1.getData()).toUpperCase()); } @Test // MULMOD OP public void testMULMOD_3() { VM vm = new VM(); program = new Program(compile("PUSH3 0x222222 PUSH3 0x333333 PUSH3 0x444444 MULMOD"), invoke); String s_expected_1 = "0000000000000000000000000000000000000000000000000000000000000000"; vm.step(program); vm.step(program); vm.step(program); vm.step(program); DataWord item1 = program.stackPop(); assertEquals(s_expected_1, Hex.toHexString(item1.getData()).toUpperCase()); } @Test(expected = Program.StackTooSmallException.class) // MULMOD OP mal public void testMULMOD_4() { VM vm = new VM(); program = new Program(compile("PUSH1 0x01 MULMOD"), invoke); try { vm.step(program); vm.step(program); } finally { assertTrue(program.isStopped()); } } @Test // DIV OP public void testDIV_1() { VM vm = new VM(); program = new Program(compile("PUSH1 0x02 PUSH1 0x04 DIV"), invoke); String s_expected_1 = "0000000000000000000000000000000000000000000000000000000000000002"; vm.step(program); vm.step(program); vm.step(program); DataWord item1 = program.stackPop(); assertEquals(s_expected_1, Hex.toHexString(item1.getData()).toUpperCase()); } @Test // DIV OP public void testDIV_2() { VM vm = new VM(); program = new Program(compile("PUSH1 0x33 PUSH1 0x99 DIV"), invoke); String s_expected_1 = "0000000000000000000000000000000000000000000000000000000000000003"; vm.step(program); vm.step(program); vm.step(program); DataWord item1 = program.stackPop(); assertEquals(s_expected_1, Hex.toHexString(item1.getData()).toUpperCase()); } @Test // DIV OP public void testDIV_3() { VM vm = new VM(); program = new Program(compile("PUSH1 0x22 PUSH1 0x99 DIV"), invoke); String s_expected_1 = "0000000000000000000000000000000000000000000000000000000000000004"; vm.step(program); vm.step(program); vm.step(program); DataWord item1 = program.stackPop(); assertEquals(s_expected_1, Hex.toHexString(item1.getData()).toUpperCase()); } @Test // DIV OP public void testDIV_4() { VM vm = new VM(); program = new Program(compile("PUSH1 0x15 PUSH1 0x99 DIV"), invoke); String s_expected_1 = "0000000000000000000000000000000000000000000000000000000000000007"; vm.step(program); vm.step(program); vm.step(program); DataWord item1 = program.stackPop(); assertEquals(s_expected_1, Hex.toHexString(item1.getData()).toUpperCase()); } @Test // DIV OP public void testDIV_5() { VM vm = new VM(); program = new Program(compile("PUSH1 0x04 PUSH1 0x07 DIV"), invoke); String s_expected_1 = "0000000000000000000000000000000000000000000000000000000000000001"; vm.step(program); vm.step(program); vm.step(program); DataWord item1 = program.stackPop(); assertEquals(s_expected_1, Hex.toHexString(item1.getData()).toUpperCase()); } @Test(expected = Program.StackTooSmallException.class) // DIV OP public void testDIV_6() { VM vm = new VM(); program = new Program(compile("PUSH1 0x07 DIV"), invoke); try { vm.step(program); vm.step(program); } finally { assertTrue(program.isStopped()); } } @Test // SDIV OP public void testSDIV_1() { VM vm = new VM(); program = new Program(compile("PUSH2 0x03E8 PUSH32 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC18 SDIV"), invoke); String s_expected_1 = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"; vm.step(program); vm.step(program); vm.step(program); DataWord item1 = program.stackPop(); assertEquals(s_expected_1, Hex.toHexString(item1.getData()).toUpperCase()); } @Test // SDIV OP public void testSDIV_2() { VM vm = new VM(); program = new Program(compile("PUSH1 0xFF PUSH1 0xFF SDIV"), invoke); String s_expected_1 = "0000000000000000000000000000000000000000000000000000000000000001"; vm.step(program); vm.step(program); vm.step(program); DataWord item1 = program.stackPop(); assertEquals(s_expected_1, Hex.toHexString(item1.getData()).toUpperCase()); } @Test // SDIV OP public void testSDIV_3() { VM vm = new VM(); program = new Program(compile("PUSH1 0x00 PUSH1 0xFF SDIV"), invoke); String s_expected_1 = "0000000000000000000000000000000000000000000000000000000000000000"; vm.step(program); vm.step(program); vm.step(program); DataWord item1 = program.stackPop(); assertEquals(s_expected_1, Hex.toHexString(item1.getData()).toUpperCase()); } @Test(expected = Program.StackTooSmallException.class) // SDIV OP mal public void testSDIV_4() { VM vm = new VM(); program = new Program(compile("PUSH1 0xFF SDIV"), invoke); try { vm.step(program); vm.step(program); } finally { assertTrue(program.isStopped()); } } @Test // SUB OP public void testSUB_1() { VM vm = new VM(); program = new Program(compile("PUSH1 0x04 PUSH1 0x06 SUB"), invoke); String s_expected_1 = "0000000000000000000000000000000000000000000000000000000000000002"; vm.step(program); vm.step(program); vm.step(program); DataWord item1 = program.stackPop(); assertEquals(s_expected_1, Hex.toHexString(item1.getData()).toUpperCase()); } @Test // SUB OP public void testSUB_2() { VM vm = new VM(); program = new Program(compile("PUSH2 0x4444 PUSH2 0x6666 SUB"), invoke); String s_expected_1 = "0000000000000000000000000000000000000000000000000000000000002222"; vm.step(program); vm.step(program); vm.step(program); DataWord item1 = program.stackPop(); assertEquals(s_expected_1, Hex.toHexString(item1.getData()).toUpperCase()); } @Test // SUB OP public void testSUB_3() { VM vm = new VM(); program = new Program(compile("PUSH2 0x4444 PUSH4 0x99996666 SUB"), invoke); String s_expected_1 = "0000000000000000000000000000000000000000000000000000000099992222"; vm.step(program); vm.step(program); vm.step(program); DataWord item1 = program.stackPop(); assertEquals(s_expected_1, Hex.toHexString(item1.getData()).toUpperCase()); } @Test(expected = Program.StackTooSmallException.class) // SUB OP mal public void testSUB_4() { VM vm = new VM(); program = new Program(compile("PUSH4 0x99996666 SUB"), invoke); try { vm.step(program); vm.step(program); } finally { assertTrue(program.isStopped()); } } @Ignore //TODO #POC9 @Test // EXP OP public void testEXP_1() { VM vm = new VM(); program = new Program(compile("PUSH1 0x03 PUSH1 0x02 EXP"), invoke); String s_expected_1 = "0000000000000000000000000000000000000000000000000000000000000008"; vm.step(program); vm.step(program); vm.step(program); DataWord item1 = program.stackPop(); long gas = program.getResult().getGasUsed(); assertEquals(s_expected_1, Hex.toHexString(item1.getData()).toUpperCase()); assertEquals(4, gas); } @Ignore //TODO #POC9 @Test // EXP OP public void testEXP_2() { VM vm = new VM(); program = new Program(compile("PUSH1 0x00 PUSH3 0x123456 EXP"), invoke); String s_expected_1 = "0000000000000000000000000000000000000000000000000000000000000001"; vm.step(program); vm.step(program); vm.step(program); DataWord item1 = program.stackPop(); long gas = program.getResult().getGasUsed(); assertEquals(s_expected_1, Hex.toHexString(item1.getData()).toUpperCase()); assertEquals(3, gas); } @Ignore //TODO #POC9 @Test // EXP OP public void testEXP_3() { VM vm = new VM(); program = new Program(compile("PUSH2 0x1122 PUSH1 0x01 EXP"), invoke); String s_expected_1 = "0000000000000000000000000000000000000000000000000000000000000001"; vm.step(program); vm.step(program); vm.step(program); DataWord item1 = program.stackPop(); long gas = program.getResult().getGasUsed(); assertEquals(s_expected_1, Hex.toHexString(item1.getData()).toUpperCase()); assertEquals(5, gas); } @Test(expected = Program.StackTooSmallException.class) // EXP OP mal public void testEXP_4() { VM vm = new VM(); program = new Program(compile("PUSH3 0x123456 EXP"), invoke); try { vm.step(program); vm.step(program); } finally { assertTrue(program.isStopped()); } } @Test // MOD OP public void testMOD_1() { VM vm = new VM(); program = new Program(compile("PUSH1 0x03 PUSH1 0x04 MOD"), invoke); String s_expected_1 = "0000000000000000000000000000000000000000000000000000000000000001"; vm.step(program); vm.step(program); vm.step(program); DataWord item1 = program.stackPop(); assertEquals(s_expected_1, Hex.toHexString(item1.getData()).toUpperCase()); } @Test // MOD OP public void testMOD_2() { VM vm = new VM(); program = new Program(compile("PUSH2 0x012C PUSH2 0x01F4 MOD"), invoke); String s_expected_1 = "00000000000000000000000000000000000000000000000000000000000000C8"; vm.step(program); vm.step(program); vm.step(program); DataWord item1 = program.stackPop(); assertEquals(s_expected_1, Hex.toHexString(item1.getData()).toUpperCase()); } @Test // MOD OP public void testMOD_3() { VM vm = new VM(); program = new Program(compile("PUSH1 0x04 PUSH1 0x02 MOD"), invoke); String s_expected_1 = "0000000000000000000000000000000000000000000000000000000000000002"; vm.step(program); vm.step(program); vm.step(program); DataWord item1 = program.stackPop(); assertEquals(s_expected_1, Hex.toHexString(item1.getData()).toUpperCase()); } @Test(expected = Program.StackTooSmallException.class) // MOD OP mal public void testMOD_4() { VM vm = new VM(); program = new Program(compile("PUSH1 0x04 MOD"), invoke); try { vm.step(program); vm.step(program); vm.step(program); } finally { assertTrue(program.isStopped()); } } @Test // SMOD OP public void testSMOD_1() { VM vm = new VM(); program = new Program(compile("PUSH1 0x03 PUSH1 0x04 SMOD"), invoke); String s_expected_1 = "0000000000000000000000000000000000000000000000000000000000000001"; vm.step(program); vm.step(program); vm.step(program); DataWord item1 = program.stackPop(); assertEquals(s_expected_1, Hex.toHexString(item1.getData()).toUpperCase()); } @Test // SMOD OP public void testSMOD_2() { VM vm = new VM(); program = new Program(compile("PUSH32 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE2 " + // -30 "PUSH32 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF56 " + // -170 "SMOD"), invoke); String s_expected_1 = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEC"; vm.step(program); vm.step(program); vm.step(program); DataWord item1 = program.stackPop(); assertEquals(s_expected_1, Hex.toHexString(item1.getData()).toUpperCase()); } @Test // SMOD OP public void testSMOD_3() { VM vm = new VM(); program = new Program(compile("PUSH32 0x000000000000000000000000000000000000000000000000000000000000001E " + // 30 "PUSH32 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF56 " + // -170 "SMOD"), invoke); String s_expected_1 = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEC"; vm.step(program); vm.step(program); vm.step(program); DataWord item1 = program.stackPop(); assertEquals(s_expected_1, Hex.toHexString(item1.getData()).toUpperCase()); } @Test(expected = Program.StackTooSmallException.class) // SMOD OP mal public void testSMOD_4() { VM vm = new VM(); program = new Program(compile("PUSH32 0x000000000000000000000000000000000000000000000000000000000000001E " + // 30 "SMOD"), invoke); try { vm.step(program); vm.step(program); } finally { assertTrue(program.isStopped()); } } }
21,110
30.937973
142
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/vm/VMEnvOpTest.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.vm; import org.ethereum.vm.program.Program; import org.junit.Ignore; import org.junit.Test; import org.spongycastle.util.encoders.Hex; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; /** * Simple tests for VM Environmental Information */ public class VMEnvOpTest extends VMBaseOpTest { @Ignore //TODO #POC9 @Test // CODECOPY OP public void testCODECOPY_1() { VM vm = new VM(); program = new Program(compile("PUSH1 0x03 PUSH1 0x07 PUSH1 0x00 CODECOPY SLT CALLVALUE JUMP"), invoke); String m_expected_1 = "1234560000000000000000000000000000000000000000000000000000000000"; vm.step(program); vm.step(program); vm.step(program); vm.step(program); long gas = program.getResult().getGasUsed(); assertEquals(m_expected_1, Hex.toHexString(program.getMemory()).toUpperCase()); assertEquals(6, gas); } @Ignore //TODO #POC9 @Test // CODECOPY OP public void testCODECOPY_2() { VM vm = new VM(); program = new Program(compile ("PUSH1 0x5E PUSH1 0x07 PUSH1 0x00 CODECOPY PUSH1 0x00 PUSH1 0x5f SSTORE PUSH1 0x14 PUSH1 0x00 SLOAD PUSH1 0x1e PUSH1 0x20 SLOAD PUSH4 0xabcddcba PUSH1 0x40 SLOAD JUMPDEST MLOAD PUSH1 0x20 ADD PUSH1 0x0a MSTORE SLOAD MLOAD PUSH1 0x40 ADD PUSH1 0x14 MSTORE SLOAD MLOAD PUSH1 0x60 ADD PUSH1 0x1e MSTORE SLOAD MLOAD PUSH1 0x80 ADD PUSH1 0x28 MSTORE SLOAD PUSH1 0xa0 MSTORE SLOAD PUSH1 0x16 PUSH1 0x48 PUSH1 0x00 CODECOPY PUSH1 0x16 PUSH1 0x00 CALLCODE PUSH1 0x00 PUSH1 0x3f SSTORE PUSH2 0x03e7 JUMP PUSH1 0x00 SLOAD PUSH1 0x00 MSTORE8 PUSH1 0x20 MUL CALLDATALOAD PUSH1 0x20 SLOAD"), invoke); String m_expected_1 = "6000605F556014600054601E60205463ABCDDCBA6040545B51602001600A5254516040016014525451606001601E5254516080016028525460A052546016604860003960166000F26000603F556103E756600054600053602002356020540000"; vm.step(program); vm.step(program); vm.step(program); vm.step(program); long gas = program.getResult().getGasUsed(); assertEquals(m_expected_1, Hex.toHexString(program.getMemory()).toUpperCase()); assertEquals(10, gas); } @Ignore //TODO #POC9 @Test // CODECOPY OP public void testCODECOPY_3() { // cost for that: // 94 - data copied // 95 - new bytes allocated VM vm = new VM(); program = new Program(Hex.decode ("605E60076000396000605f556014600054601e60205463abcddcba6040545b51602001600a5254516040016014525451606001601e5254516080016028525460a052546016604860003960166000f26000603f556103e75660005460005360200235"), invoke); vm.step(program); vm.step(program); vm.step(program); vm.step(program); assertEquals(10, program.getResult().getGasUsed()); } @Ignore //TODO #POC9 @Test // CODECOPY OP public void testCODECOPY_4() { VM vm = new VM(); program = new Program(Hex.decode ("605E60076000396000605f556014600054601e60205463abcddcba6040545b51602001600a5254516040016014525451606001601e5254516080016028525460a052546016604860003960166000f26000603f556103e756600054600053602002351234"), invoke); vm.step(program); vm.step(program); vm.step(program); vm.step(program); assertEquals(10, program.getResult().getGasUsed()); } @Test // CODECOPY OP public void testCODECOPY_5() { VM vm = new VM(); program = new Program(Hex.decode ("611234600054615566602054607060006020396000605f556014600054601e60205463abcddcba6040545b51602001600a5254516040016014525451606001601e5254516080016028525460a052546016604860003960166000f26000603f556103e756600054600053602002351234"), invoke); vm.step(program); vm.step(program); vm.step(program); vm.step(program); vm.step(program); vm.step(program); vm.step(program); vm.step(program); vm.step(program); vm.step(program); assertFalse(program.isStopped()); } @Test(expected = Program.StackTooSmallException.class) // CODECOPY OP mal public void testCODECOPY_6() { VM vm = new VM(); program = new Program(Hex.decode ("605E6007396000605f556014600054601e60205463abcddcba6040545b51602001600a5254516040016014525451606001601e5254516080016028525460a052546016604860003960166000f26000603f556103e756600054600053602002351234"), invoke); try { vm.step(program); vm.step(program); vm.step(program); } finally { assertTrue(program.isStopped()); } } @Test // EXTCODECOPY OP public void testEXTCODECOPY_1() { VM vm = new VM(); program = new Program(Hex.decode("60036007600073471FD3AD3E9EEADEEC4608B92D16CE6B500704CC3C123456"), invoke); String m_expected_1 = "6000600000000000000000000000000000000000000000000000000000000000"; vm.step(program); vm.step(program); vm.step(program); vm.step(program); vm.step(program); assertEquals(m_expected_1, Hex.toHexString(program.getMemory()).toUpperCase()); } @Test // EXTCODECOPY OP public void testEXTCODECOPY_2() { VM vm = new VM(); program = new Program(Hex.decode ("603E6007600073471FD3AD3E9EEADEEC4608B92D16CE6B500704CC3C6000605f556014600054601e60205463abcddcba6040545b51602001600a5254516040016014525451606001601e5254516080016028525460a052546016604860003960166000f26000603f556103e75660005460005360200235602054"), invoke); String m_expected_1 = "6000605F556014600054601E60205463ABCDDCBA6040545B51602001600A5254516040016014525451606001601E5254516080016028525460A0525460160000"; vm.step(program); vm.step(program); vm.step(program); vm.step(program); vm.step(program); assertEquals(m_expected_1, Hex.toHexString(program.getMemory()).toUpperCase()); } @Test // EXTCODECOPY OP public void testEXTCODECOPY_3() { VM vm = new VM(); program = new Program(Hex.decode ("605E6007600073471FD3AD3E9EEADEEC4608B92D16CE6B500704CC3C6000605f556014600054601e60205463abcddcba6040545b51602001600a5254516040016014525451606001601e5254516080016028525460a052546016604860003960166000f26000603f556103e75660005460005360200235"), invoke); String m_expected_1 = "6000605F556014600054601E60205463ABCDDCBA6040545B51602001600A5254516040016014525451606001601E5254516080016028525460A052546016604860003960166000F26000603F556103E756600054600053602002350000000000"; vm.step(program); vm.step(program); vm.step(program); vm.step(program); vm.step(program); assertEquals(m_expected_1, Hex.toHexString(program.getMemory()).toUpperCase()); } @Test // EXTCODECOPY OP public void testEXTCODECOPY_4() { VM vm = new VM(); program = new Program(Hex.decode ("611234600054615566602054603E6000602073471FD3AD3E9EEADEEC4608B92D16CE6B500704CC3C6000605f556014600054601e60205463abcddcba6040545b51602001600a5254516040016014525451606001601e5254516080016028525460a052546016604860003960166000f26000603f556103e756600054600053602002351234"), invoke); vm.step(program); vm.step(program); vm.step(program); vm.step(program); vm.step(program); vm.step(program); vm.step(program); vm.step(program); vm.step(program); vm.step(program); vm.step(program); assertFalse(program.isStopped()); } @Test(expected = Program.StackTooSmallException.class) // EXTCODECOPY OP mal public void testEXTCODECOPY_5() { VM vm = new VM(); program = new Program(Hex.decode("605E600773471FD3AD3E9EEADEEC4608B92D16CE6B500704CC3C"), invoke); try { vm.step(program); vm.step(program); vm.step(program); vm.step(program); } finally { assertTrue(program.isStopped()); } } @Test // CODESIZE OP public void testCODESIZE_1() { VM vm = new VM(); program = new Program(Hex.decode ("385E60076000396000605f556014600054601e60205463abcddcba6040545b51602001600a5254516040016014525451606001601e5254516080016028525460a052546016604860003960166000f26000603f556103e75660005460005360200235"), invoke); String s_expected_1 = "0000000000000000000000000000000000000000000000000000000000000062"; vm.step(program); DataWord item1 = program.stackPop(); assertEquals(s_expected_1, Hex.toHexString(item1.getData()).toUpperCase()); } @Ignore // todo: test is not testing EXTCODESIZE @Test // EXTCODESIZE OP public void testEXTCODESIZE_1() { VM vm = new VM(); program = new Program(Hex.decode ("73471FD3AD3E9EEADEEC4608B92D16CE6B500704CC395E60076000396000605f556014600054601e60205463abcddcba6040545b51602001600a5254516040016014525451606001601e5254516080016028525460a052546016604860003960166000f26000603f556103e75660005460005360200235"), invoke); // Push address on the stack and perform EXTCODECOPY String s_expected_1 = "000000000000000000000000471FD3AD3E9EEADEEC4608B92D16CE6B500704CC"; vm.step(program); DataWord item1 = program.stackPop(); assertEquals(s_expected_1, Hex.toHexString(item1.getData()).toUpperCase()); } }
10,966
37.079861
604
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/vm/VMBaseOpTest.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.vm; import org.ethereum.vm.program.Program; import org.ethereum.vm.program.invoke.ProgramInvokeMockImpl; import org.junit.After; import org.junit.Before; import org.junit.FixMethodOrder; import org.junit.runners.MethodSorters; /** * Base Op test structure * Use {@link #compile(String)} with VM code to compile it, * then new Program(compiledCode) to run */ @FixMethodOrder(MethodSorters.NAME_ASCENDING) public abstract class VMBaseOpTest { protected ProgramInvokeMockImpl invoke; protected Program program; @Before public void setup() { invoke = new ProgramInvokeMockImpl(); } @After public void tearDown() { invoke.getRepository().close(); } protected byte[] compile(String code) { return new BytecodeCompiler().compile(code); } }
1,620
29.018519
80
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/vm/VMMemoryOpTest.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.vm; import org.ethereum.config.SystemProperties; import org.ethereum.config.blockchain.ConstantinopleConfig; import org.ethereum.config.blockchain.DaoHFConfig; import org.ethereum.core.Repository; import org.ethereum.vm.program.Program; import org.junit.Test; import org.spongycastle.util.encoders.Hex; import static org.ethereum.util.ByteUtil.oneByteToHexString; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertTrue; /** * Simple tests for VM Memory, Storage and Flow Operations */ public class VMMemoryOpTest extends VMBaseOpTest { private static final SystemProperties constantinopleConfig = new SystemProperties(){{ setBlockchainConfig(new ConstantinopleConfig(new DaoHFConfig())); }}; @Test // PUSH1 OP public void testPUSH1() { VM vm = new VM(); program = new Program(compile("PUSH1 0xa0"), invoke); String expected = "00000000000000000000000000000000000000000000000000000000000000A0"; program.fullTrace(); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // PUSH2 OP public void testPUSH2() { VM vm = new VM(); program = new Program(compile("PUSH2 0xa0b0"), invoke); String expected = "000000000000000000000000000000000000000000000000000000000000A0B0"; program.fullTrace(); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // PUSH3 OP public void testPUSH3() { VM vm = new VM(); program = new Program(compile("PUSH3 0xA0B0C0"), invoke); String expected = "0000000000000000000000000000000000000000000000000000000000A0B0C0"; program.fullTrace(); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // PUSH4 OP public void testPUSH4() { VM vm = new VM(); program = new Program(compile("PUSH4 0xA0B0C0D0"), invoke); String expected = "00000000000000000000000000000000000000000000000000000000A0B0C0D0"; program.fullTrace(); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // PUSH5 OP public void testPUSH5() { VM vm = new VM(); program = new Program(compile("PUSH5 0xA0B0C0D0E0"), invoke); String expected = "000000000000000000000000000000000000000000000000000000A0B0C0D0E0"; program.fullTrace(); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // PUSH6 OP public void testPUSH6() { VM vm = new VM(); program = new Program(compile("PUSH6 0xA0B0C0D0E0F0"), invoke); String expected = "0000000000000000000000000000000000000000000000000000A0B0C0D0E0F0"; program.fullTrace(); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // PUSH7 OP public void testPUSH7() { VM vm = new VM(); program = new Program(compile("PUSH7 0xA0B0C0D0E0F0A1"), invoke); String expected = "00000000000000000000000000000000000000000000000000A0B0C0D0E0F0A1"; program.fullTrace(); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // PUSH8 OP public void testPUSH8() { VM vm = new VM(); program = new Program(compile("PUSH8 0xA0B0C0D0E0F0A1B1"), invoke); String expected = "000000000000000000000000000000000000000000000000A0B0C0D0E0F0A1B1"; program.fullTrace(); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // PUSH9 OP public void testPUSH9() { VM vm = new VM(); program = new Program(compile("PUSH9 0xA0B0C0D0E0F0A1B1C1"), invoke); String expected = "0000000000000000000000000000000000000000000000A0B0C0D0E0F0A1B1C1"; program.fullTrace(); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // PUSH10 OP public void testPUSH10() { VM vm = new VM(); program = new Program(compile("PUSH10 0xA0B0C0D0E0F0A1B1C1D1"), invoke); String expected = "00000000000000000000000000000000000000000000A0B0C0D0E0F0A1B1C1D1"; program.fullTrace(); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // PUSH11 OP public void testPUSH11() { VM vm = new VM(); program = new Program(compile("PUSH11 0xA0B0C0D0E0F0A1B1C1D1E1"), invoke); String expected = "000000000000000000000000000000000000000000A0B0C0D0E0F0A1B1C1D1E1"; program.fullTrace(); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // PUSH12 OP public void testPUSH12() { VM vm = new VM(); program = new Program(compile("PUSH12 0xA0B0C0D0E0F0A1B1C1D1E1F1"), invoke); String expected = "0000000000000000000000000000000000000000A0B0C0D0E0F0A1B1C1D1E1F1"; program.fullTrace(); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // PUSH13 OP public void testPUSH13() { VM vm = new VM(); program = new Program(compile("PUSH13 0xA0B0C0D0E0F0A1B1C1D1E1F1A2"), invoke); String expected = "00000000000000000000000000000000000000A0B0C0D0E0F0A1B1C1D1E1F1A2"; program.fullTrace(); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // PUSH14 OP public void testPUSH14() { VM vm = new VM(); program = new Program(compile("PUSH14 0xA0B0C0D0E0F0A1B1C1D1E1F1A2B2"), invoke); String expected = "000000000000000000000000000000000000A0B0C0D0E0F0A1B1C1D1E1F1A2B2"; program.fullTrace(); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // PUSH15 OP public void testPUSH15() { VM vm = new VM(); program = new Program(compile("PUSH15 0xA0B0C0D0E0F0A1B1C1D1E1F1A2B2C2"), invoke); String expected = "0000000000000000000000000000000000A0B0C0D0E0F0A1B1C1D1E1F1A2B2C2"; program.fullTrace(); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // PUSH16 OP public void testPUSH16() { VM vm = new VM(); program = new Program(compile("PUSH16 0xA0B0C0D0E0F0A1B1C1D1E1F1A2B2C2D2"), invoke); String expected = "00000000000000000000000000000000A0B0C0D0E0F0A1B1C1D1E1F1A2B2C2D2"; program.fullTrace(); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // PUSH17 OP public void testPUSH17() { VM vm = new VM(); program = new Program(compile("PUSH17 0xA0B0C0D0E0F0A1B1C1D1E1F1A2B2C2D2E2"), invoke); String expected = "000000000000000000000000000000A0B0C0D0E0F0A1B1C1D1E1F1A2B2C2D2E2"; program.fullTrace(); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // PUSH18 OP public void testPUSH18() { VM vm = new VM(); program = new Program(compile("PUSH18 0xA0B0C0D0E0F0A1B1C1D1E1F1A2B2C2D2E2F2"), invoke); String expected = "0000000000000000000000000000A0B0C0D0E0F0A1B1C1D1E1F1A2B2C2D2E2F2"; program.fullTrace(); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // PUSH19 OP public void testPUSH19() { VM vm = new VM(); program = new Program(compile("PUSH19 0xA0B0C0D0E0F0A1B1C1D1E1F1A2B2C2D2E2F2A3"), invoke); String expected = "00000000000000000000000000A0B0C0D0E0F0A1B1C1D1E1F1A2B2C2D2E2F2A3"; program.fullTrace(); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // PUSH20 OP public void testPUSH20() { VM vm = new VM(); program = new Program(compile("PUSH20 0xA0B0C0D0E0F0A1B1C1D1E1F1A2B2C2D2E2F2A3B3"), invoke); String expected = "000000000000000000000000A0B0C0D0E0F0A1B1C1D1E1F1A2B2C2D2E2F2A3B3"; program.fullTrace(); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // PUSH21 OP public void testPUSH21() { VM vm = new VM(); program = new Program(compile("PUSH21 0xA0B0C0D0E0F0A1B1C1D1E1F1A2B2C2D2E2F2A3B3C3"), invoke); String expected = "0000000000000000000000A0B0C0D0E0F0A1B1C1D1E1F1A2B2C2D2E2F2A3B3C3"; program.fullTrace(); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // PUSH22 OP public void testPUSH22() { VM vm = new VM(); program = new Program(compile("PUSH22 0xA0B0C0D0E0F0A1B1C1D1E1F1A2B2C2D2E2F2A3B3C3D3"), invoke); String expected = "00000000000000000000A0B0C0D0E0F0A1B1C1D1E1F1A2B2C2D2E2F2A3B3C3D3"; program.fullTrace(); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // PUSH23 OP public void testPUSH23() { VM vm = new VM(); program = new Program(compile("PUSH23 0xA0B0C0D0E0F0A1B1C1D1E1F1A2B2C2D2E2F2A3B3C3D3E3"), invoke); String expected = "000000000000000000A0B0C0D0E0F0A1B1C1D1E1F1A2B2C2D2E2F2A3B3C3D3E3"; program.fullTrace(); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // PUSH24 OP public void testPUSH24() { VM vm = new VM(); program = new Program(compile("PUSH24 0xA0B0C0D0E0F0A1B1C1D1E1F1A2B2C2D2E2F2A3B3C3D3E3F3"), invoke); String expected = "0000000000000000A0B0C0D0E0F0A1B1C1D1E1F1A2B2C2D2E2F2A3B3C3D3E3F3"; program.fullTrace(); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // PUSH25 OP public void testPUSH25() { VM vm = new VM(); program = new Program(compile("PUSH25 0xA0B0C0D0E0F0A1B1C1D1E1F1A2B2C2D2E2F2A3B3C3D3E3F3A4"), invoke); String expected = "00000000000000A0B0C0D0E0F0A1B1C1D1E1F1A2B2C2D2E2F2A3B3C3D3E3F3A4"; program.fullTrace(); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // PUSH26 OP public void testPUSH26() { VM vm = new VM(); program = new Program(compile("PUSH26 0xA0B0C0D0E0F0A1B1C1D1E1F1A2B2C2D2E2F2A3B3C3D3E3F3A4B4"), invoke); String expected = "000000000000A0B0C0D0E0F0A1B1C1D1E1F1A2B2C2D2E2F2A3B3C3D3E3F3A4B4"; program.fullTrace(); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // PUSH27 OP public void testPUSH27() { VM vm = new VM(); program = new Program(compile("PUSH27 0xA0B0C0D0E0F0A1B1C1D1E1F1A2B2C2D2E2F2A3B3C3D3E3F3A4B4C4"), invoke); String expected = "0000000000A0B0C0D0E0F0A1B1C1D1E1F1A2B2C2D2E2F2A3B3C3D3E3F3A4B4C4"; program.fullTrace(); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // PUSH28 OP public void testPUSH28() { VM vm = new VM(); program = new Program(compile("PUSH28 0xA0B0C0D0E0F0A1B1C1D1E1F1A2B2C2D2E2F2A3B3C3D3E3F3A4B4C4D4"), invoke); String expected = "00000000A0B0C0D0E0F0A1B1C1D1E1F1A2B2C2D2E2F2A3B3C3D3E3F3A4B4C4D4"; program.fullTrace(); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // PUSH29 OP public void testPUSH29() { VM vm = new VM(); program = new Program(compile("PUSH29 0xA0B0C0D0E0F0A1B1C1D1E1F1A2B2C2D2E2F2A3B3C3D3E3F3A4B4C4D4E4"), invoke); String expected = "000000A0B0C0D0E0F0A1B1C1D1E1F1A2B2C2D2E2F2A3B3C3D3E3F3A4B4C4D4E4"; program.fullTrace(); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // PUSH30 OP public void testPUSH30() { VM vm = new VM(); program = new Program(compile("PUSH30 0xA0B0C0D0E0F0A1B1C1D1E1F1A2B2C2D2E2F2A3B3C3D3E3F3A4B4C4D4E4F4"), invoke); String expected = "0000A0B0C0D0E0F0A1B1C1D1E1F1A2B2C2D2E2F2A3B3C3D3E3F3A4B4C4D4E4F4"; program.fullTrace(); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // PUSH31 OP public void testPUSH31() { VM vm = new VM(); program = new Program(compile("PUSH31 0xA0B0C0D0E0F0A1B1C1D1E1F1A2B2C2D2E2F2A3B3C3D3E3F3A4B4C4D4E4F4A1"), invoke); String expected = "00A0B0C0D0E0F0A1B1C1D1E1F1A2B2C2D2E2F2A3B3C3D3E3F3A4B4C4D4E4F4A1"; program.fullTrace(); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // PUSH32 OP public void testPUSH32() { VM vm = new VM(); program = new Program(compile("PUSH32 0xA0B0C0D0E0F0A1B1C1D1E1F1A2B2C2D2E2F2A3B3C3D3E3F3A4B4C4D4E4F4A1B1"), invoke); String expected = "A0B0C0D0E0F0A1B1C1D1E1F1A2B2C2D2E2F2A3B3C3D3E3F3A4B4C4D4E4F4A1B1"; program.fullTrace(); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // PUSHN OP not enough data public void testPUSHN_1() { VM vm = new VM(); program = new Program(compile("PUSH2 0xAA"), invoke); String expected = "000000000000000000000000000000000000000000000000000000000000AA00"; program.fullTrace(); vm.step(program); assertTrue(program.isStopped()); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // PUSHN OP not enough data public void testPUSHN_2() { VM vm = new VM(); program = new Program(compile("PUSH32 0xAABB"), invoke); String expected = "AABB000000000000000000000000000000000000000000000000000000000000"; program.fullTrace(); vm.step(program); assertTrue(program.isStopped()); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // POP OP public void testPOP_1() { VM vm = new VM(); program = new Program(compile("PUSH2 0x0000 PUSH1 0x01 PUSH3 0x000002 POP"), invoke); String expected = "0000000000000000000000000000000000000000000000000000000000000001"; vm.step(program); vm.step(program); vm.step(program); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // POP OP public void testPOP_2() { VM vm = new VM(); program = new Program(compile("PUSH2 0x0000 PUSH1 0x01 PUSH3 0x000002 POP POP"), invoke); String expected = "0000000000000000000000000000000000000000000000000000000000000000"; vm.step(program); vm.step(program); vm.step(program); vm.step(program); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test(expected = Program.StackTooSmallException.class) // POP OP mal data public void testPOP_3() { VM vm = new VM(); program = new Program(compile("PUSH2 0x0000 PUSH1 0x01 PUSH3 0x000002 POP POP POP POP"), invoke); try { vm.step(program); vm.step(program); vm.step(program); vm.step(program); vm.step(program); vm.step(program); vm.step(program); } finally { assertTrue(program.isStopped()); } } @Test // DUP1...DUP16 OP public void testDUPS() { for (int i = 1; i < 17; i++) { testDUPN_1(i); } } /** * Generic test function for DUP1-16 * * @param n in DUPn */ private void testDUPN_1(int n) { VM vm = new VM(); String programCode = ""; for (int i = 0; i < n; i++) { programCode += "PUSH1 0x" + (12 + i) + " "; } programCode += "DUP" + n; program = new Program(compile(programCode), invoke); String expected = "0000000000000000000000000000000000000000000000000000000000000012"; int expectedLen = n + 1; for (int i = 0; i < expectedLen; i++) { vm.step(program); } assertEquals(expectedLen, program.getStack().toArray().length); assertEquals(expected, Hex.toHexString(program.stackPop().getData()).toUpperCase()); for (int i = 0; i < expectedLen - 2; i++) { assertNotEquals(expected, Hex.toHexString(program.stackPop().getData()).toUpperCase()); } assertEquals(expected, Hex.toHexString(program.stackPop().getData()).toUpperCase()); } @Test(expected = Program.StackTooSmallException.class) // DUPN OP mal data public void testDUPN_2() { VM vm = new VM(); program = new Program(compile("DUP1"), invoke); try { vm.step(program); } finally { assertTrue(program.isStopped()); } } @Test // SWAP1...SWAP16 OP public void testSWAPS() { for (int i = 1; i < 17; ++i) { testSWAPN_1(i); } } /** * Generic test function for SWAP1-16 * * @param n in SWAPn */ private void testSWAPN_1(int n) { VM vm = new VM(); String programCode = ""; String top = DataWord.of(0x10 + n).toString(); for (int i = n; i > -1; --i) { programCode += "PUSH1 0x" + oneByteToHexString((byte) (0x10 + i)) + " "; } programCode += "SWAP" + n; program = new Program(compile(programCode), invoke); for (int i = 0; i < n + 2; ++i) { vm.step(program); } assertEquals(n + 1, program.getStack().toArray().length); assertEquals(top, Hex.toHexString(program.stackPop().getData())); } @Test(expected = Program.StackTooSmallException.class) // SWAPN OP mal data public void testSWAPN_2() { VM vm = new VM(); program = new Program(compile("SWAP1"), invoke); try { vm.step(program); } finally { assertTrue(program.isStopped()); } } @Test // MSTORE OP public void testMSTORE_1() { VM vm = new VM(); program = new Program(compile("PUSH2 0x1234 PUSH1 0x00 MSTORE"), invoke); String expected = "0000000000000000000000000000000000000000000000000000000000001234"; vm.step(program); vm.step(program); vm.step(program); assertEquals(expected, Hex.toHexString(program.getMemory())); } @Test // MSTORE OP public void testMSTORE_2() { VM vm = new VM(); program = new Program(compile("PUSH2 0x1234 PUSH1 0x00 MSTORE PUSH2 0x5566 PUSH1 0x20 MSTORE"), invoke); String expected = "0000000000000000000000000000000000000000000000000000000000001234" + "0000000000000000000000000000000000000000000000000000000000005566"; vm.step(program); vm.step(program); vm.step(program); vm.step(program); vm.step(program); vm.step(program); assertEquals(expected, Hex.toHexString(program.getMemory())); } @Test // MSTORE OP public void testMSTORE_3() { VM vm = new VM(); program = new Program(compile("PUSH2 0x1234 PUSH1 0x00 MSTORE PUSH2 0x5566 PUSH1 0x20 MSTORE PUSH2 0x8888 PUSH1 0x00 MSTORE"), invoke); String expected = "0000000000000000000000000000000000000000000000000000000000008888" + "0000000000000000000000000000000000000000000000000000000000005566"; vm.step(program); vm.step(program); vm.step(program); vm.step(program); vm.step(program); vm.step(program); vm.step(program); vm.step(program); vm.step(program); assertEquals(expected, Hex.toHexString(program.getMemory())); } @Test // MSTORE OP public void testMSTORE_4() { VM vm = new VM(); program = new Program(compile("PUSH2 0x1234 PUSH1 0xA0 MSTORE"), invoke); String expected = "" + "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000001234"; vm.step(program); vm.step(program); vm.step(program); assertEquals(expected, Hex.toHexString(program.getMemory())); } @Test(expected = Program.StackTooSmallException.class) // MSTORE OP public void testMSTORE_5() { VM vm = new VM(); program = new Program(compile("PUSH2 0x1234 MSTORE"), invoke); try { vm.step(program); vm.step(program); } finally { assertTrue(program.isStopped()); } } @Test // MLOAD OP public void testMLOAD_1() { VM vm = new VM(); program = new Program(compile("PUSH1 0x00 MLOAD"), invoke); String m_expected = "0000000000000000000000000000000000000000000000000000000000000000"; String s_expected = "0000000000000000000000000000000000000000000000000000000000000000"; vm.step(program); vm.step(program); assertEquals(m_expected, Hex.toHexString(program.getMemory())); assertEquals(s_expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // MLOAD OP public void testMLOAD_2() { VM vm = new VM(); program = new Program(compile("PUSH1 0x22 MLOAD"), invoke); String m_expected = "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000"; String s_expected = "0000000000000000000000000000000000000000000000000000000000000000"; vm.step(program); vm.step(program); assertEquals(m_expected, Hex.toHexString(program.getMemory()).toUpperCase()); assertEquals(s_expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // MLOAD OP public void testMLOAD_3() { VM vm = new VM(); program = new Program(compile("PUSH1 0x20 MLOAD"), invoke); String m_expected = "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000"; String s_expected = "0000000000000000000000000000000000000000000000000000000000000000"; vm.step(program); vm.step(program); assertEquals(m_expected, Hex.toHexString(program.getMemory())); assertEquals(s_expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // MLOAD OP public void testMLOAD_4() { VM vm = new VM(); program = new Program(compile("PUSH2 0x1234 PUSH1 0x20 MSTORE PUSH1 0x20 MLOAD"), invoke); String m_expected = "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000001234"; String s_expected = "0000000000000000000000000000000000000000000000000000000000001234"; vm.step(program); vm.step(program); vm.step(program); vm.step(program); vm.step(program); assertEquals(m_expected, Hex.toHexString(program.getMemory())); assertEquals(s_expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // MLOAD OP public void testMLOAD_5() { VM vm = new VM(); program = new Program(compile("PUSH2 0x1234 PUSH1 0x20 MSTORE PUSH1 0x1F MLOAD"), invoke); String m_expected = "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000001234"; String s_expected = "0000000000000000000000000000000000000000000000000000000000000012"; vm.step(program); vm.step(program); vm.step(program); vm.step(program); vm.step(program); assertEquals(m_expected, Hex.toHexString(program.getMemory())); assertEquals(s_expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test(expected = Program.StackTooSmallException.class) // MLOAD OP mal data public void testMLOAD_6() { VM vm = new VM(); program = new Program(compile("MLOAD"), invoke); try { vm.step(program); } finally { assertTrue(program.isStopped()); } } @Test // MSTORE8 OP public void testMSTORE8_1() { VM vm = new VM(); program = new Program(compile("PUSH1 0x11 PUSH1 0x00 MSTORE8"), invoke); String m_expected = "1100000000000000000000000000000000000000000000000000000000000000"; vm.step(program); vm.step(program); vm.step(program); assertEquals(m_expected, Hex.toHexString(program.getMemory())); } @Test // MSTORE8 OP public void testMSTORE8_2() { VM vm = new VM(); program = new Program(compile("PUSH1 0x22 PUSH1 0x01 MSTORE8"), invoke); String m_expected = "0022000000000000000000000000000000000000000000000000000000000000"; vm.step(program); vm.step(program); vm.step(program); assertEquals(m_expected, Hex.toHexString(program.getMemory())); } @Test // MSTORE8 OP public void testMSTORE8_3() { VM vm = new VM(); program = new Program(compile("PUSH1 0x22 PUSH1 0x21 MSTORE8"), invoke); String m_expected = "0000000000000000000000000000000000000000000000000000000000000000" + "0022000000000000000000000000000000000000000000000000000000000000"; vm.step(program); vm.step(program); vm.step(program); assertEquals(m_expected, Hex.toHexString(program.getMemory())); } @Test(expected = Program.StackTooSmallException.class) // MSTORE8 OP mal public void testMSTORE8_4() { VM vm = new VM(); program = new Program(compile("PUSH1 0x22 MSTORE8"), invoke); try { vm.step(program); vm.step(program); } finally { assertTrue(program.isStopped()); } } @Test // SSTORE OP public void testSSTORE_1() { VM vm = new VM(); program = new Program(compile("PUSH1 0x22 PUSH1 0xAA SSTORE"), invoke); String s_expected_key = "00000000000000000000000000000000000000000000000000000000000000AA"; String s_expected_val = "0000000000000000000000000000000000000000000000000000000000000022"; vm.step(program); vm.step(program); vm.step(program); DataWord key = DataWord.of(Hex.decode(s_expected_key)); DataWord val = program.getStorage().getStorageValue(invoke.getOwnerAddress() .getNoLeadZeroesData(), key); assertEquals(s_expected_val, Hex.toHexString(val.getData()).toUpperCase()); } @Test // SSTORE OP public void testSSTORE_2() { VM vm = new VM(); program = new Program(compile("PUSH1 0x22 PUSH1 0xAA SSTORE PUSH1 0x22 PUSH1 0xBB SSTORE"), invoke); String s_expected_key = "00000000000000000000000000000000000000000000000000000000000000BB"; String s_expected_val = "0000000000000000000000000000000000000000000000000000000000000022"; vm.step(program); vm.step(program); vm.step(program); vm.step(program); vm.step(program); vm.step(program); Repository repository = program.getStorage(); DataWord key = DataWord.of(Hex.decode(s_expected_key)); DataWord val = repository.getStorageValue(invoke.getOwnerAddress().getNoLeadZeroesData(), key); assertEquals(s_expected_val, Hex.toHexString(val.getData()).toUpperCase()); } @Test(expected = Program.StackTooSmallException.class) // SSTORE OP public void testSSTORE_3() { VM vm = new VM(); program = new Program(compile("PUSH1 0x22 SSTORE"), invoke); try { vm.step(program); vm.step(program); } finally { assertTrue(program.isStopped()); } } @Test // SSTORE EIP1283 public void testSSTORE_NET_1() { VM vm = new VM(); program = new Program(Hex.decode("60006000556000600055"), invoke, constantinopleConfig); while (!program.isStopped()) vm.step(program); assertEquals(412, program.getResult().getGasUsed()); assertEquals(0, program.getResult().getFutureRefund()); } @Test // SSTORE EIP1283 public void testSSTORE_NET_2() { VM vm = new VM(); program = new Program(Hex.decode("60006000556001600055"), invoke, constantinopleConfig); while (!program.isStopped()) vm.step(program); assertEquals(20212, program.getResult().getGasUsed()); assertEquals(0, program.getResult().getFutureRefund()); } @Test // SSTORE EIP1283 public void testSSTORE_NET_3() { VM vm = new VM(); program = new Program(Hex.decode("60016000556000600055"), invoke, constantinopleConfig); while (!program.isStopped()) vm.step(program); assertEquals(20212, program.getResult().getGasUsed()); assertEquals(19800, program.getResult().getFutureRefund()); } @Test // SSTORE EIP1283 public void testSSTORE_NET_4() { VM vm = new VM(); program = new Program(Hex.decode("60016000556002600055"), invoke, constantinopleConfig); while (!program.isStopped()) vm.step(program); assertEquals(20212, program.getResult().getGasUsed()); assertEquals(0, program.getResult().getFutureRefund()); } @Test // SSTORE EIP1283 public void testSSTORE_NET_5() { VM vm = new VM(); program = new Program(Hex.decode("60016000556001600055"), invoke, constantinopleConfig); while (!program.isStopped()) vm.step(program); assertEquals(20212, program.getResult().getGasUsed()); assertEquals(0, program.getResult().getFutureRefund()); } @Test // SSTORE EIP1283 public void testSSTORE_NET_6() { VM vm = new VM(); setStorageToOne(vm); program = new Program(Hex.decode("60006000556000600055"), invoke, constantinopleConfig); while (!program.isStopped()) vm.step(program); assertEquals(5212, program.getResult().getGasUsed()); assertEquals(15000, program.getResult().getFutureRefund()); } /** * Sets Storage row on "cow" address: * 0: 1 */ private void setStorageToOne(VM vm) { // Sets storage value to 1 and commits program = new Program(Hex.decode("60006000556001600055"), invoke, constantinopleConfig); while (!program.isStopped()) vm.step(program); invoke.getRepository().commit(); invoke.setOrigRepository(invoke.getRepository()); } @Test // SSTORE EIP1283 public void testSSTORE_NET_7() { VM vm = new VM(); setStorageToOne(vm); program = new Program(Hex.decode("60006000556001600055"), invoke, constantinopleConfig); while (!program.isStopped()) vm.step(program); assertEquals(5212, program.getResult().getGasUsed()); assertEquals(4800, program.getResult().getFutureRefund()); } @Test // SSTORE EIP1283 public void testSSTORE_NET_8() { VM vm = new VM(); setStorageToOne(vm); program = new Program(Hex.decode("60006000556002600055"), invoke, constantinopleConfig); while (!program.isStopped()) vm.step(program); assertEquals(5212, program.getResult().getGasUsed()); assertEquals(0, program.getResult().getFutureRefund()); } @Test // SSTORE EIP1283 public void testSSTORE_NET_9() { VM vm = new VM(); setStorageToOne(vm); program = new Program(Hex.decode("60026000556000600055"), invoke, constantinopleConfig); while (!program.isStopped()) vm.step(program); assertEquals(5212, program.getResult().getGasUsed()); assertEquals(15000, program.getResult().getFutureRefund()); } @Test // SSTORE EIP1283 public void testSSTORE_NET_10() { VM vm = new VM(); setStorageToOne(vm); program = new Program(Hex.decode("60026000556003600055"), invoke, constantinopleConfig); while (!program.isStopped()) vm.step(program); assertEquals(5212, program.getResult().getGasUsed()); assertEquals(0, program.getResult().getFutureRefund()); } @Test // SSTORE EIP1283 public void testSSTORE_NET_11() { VM vm = new VM(); setStorageToOne(vm); program = new Program(Hex.decode("60026000556001600055"), invoke, constantinopleConfig); while (!program.isStopped()) vm.step(program); assertEquals(5212, program.getResult().getGasUsed()); assertEquals(4800, program.getResult().getFutureRefund()); } @Test // SSTORE EIP1283 public void testSSTORE_NET_12() { VM vm = new VM(); setStorageToOne(vm); program = new Program(Hex.decode("60026000556002600055"), invoke, constantinopleConfig); while (!program.isStopped()) vm.step(program); assertEquals(5212, program.getResult().getGasUsed()); assertEquals(0, program.getResult().getFutureRefund()); } @Test // SSTORE EIP1283 public void testSSTORE_NET_13() { VM vm = new VM(); setStorageToOne(vm); program = new Program(Hex.decode("60016000556000600055"), invoke, constantinopleConfig); while (!program.isStopped()) vm.step(program); assertEquals(5212, program.getResult().getGasUsed()); assertEquals(15000, program.getResult().getFutureRefund()); } @Test // SSTORE EIP1283 public void testSSTORE_NET_14() { VM vm = new VM(); setStorageToOne(vm); program = new Program(Hex.decode("60016000556002600055"), invoke, constantinopleConfig); while (!program.isStopped()) vm.step(program); assertEquals(5212, program.getResult().getGasUsed()); assertEquals(0, program.getResult().getFutureRefund()); } @Test // SSTORE EIP1283 public void testSSTORE_NET_15() { VM vm = new VM(); setStorageToOne(vm); program = new Program(Hex.decode("60016000556001600055"), invoke, constantinopleConfig); while (!program.isStopped()) vm.step(program); assertEquals(412, program.getResult().getGasUsed()); assertEquals(0, program.getResult().getFutureRefund()); } @Test // SSTORE EIP1283 public void testSSTORE_NET_16() { VM vm = new VM(); program = new Program(Hex.decode("600160005560006000556001600055"), invoke, constantinopleConfig); while (!program.isStopped()) vm.step(program); assertEquals(40218, program.getResult().getGasUsed()); assertEquals(19800, program.getResult().getFutureRefund()); } @Test // SSTORE EIP1283 public void testSSTORE_NET_17() { VM vm = new VM(); setStorageToOne(vm); program = new Program(Hex.decode("600060005560016000556000600055"), invoke, constantinopleConfig); while (!program.isStopped()) vm.step(program); assertEquals(10218, program.getResult().getGasUsed()); assertEquals(19800, program.getResult().getFutureRefund()); } @Test // SLOAD OP public void testSLOAD_1() { VM vm = new VM(); program = new Program(compile("PUSH1 0xAA SLOAD"), invoke); String s_expected = "0000000000000000000000000000000000000000000000000000000000000000"; vm.step(program); vm.step(program); assertEquals(s_expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // SLOAD OP public void testSLOAD_2() { VM vm = new VM(); program = new Program(compile("PUSH1 0x22 PUSH1 0xAA SSTORE PUSH1 0xAA SLOAD"), invoke); String s_expected = "0000000000000000000000000000000000000000000000000000000000000022"; vm.step(program); vm.step(program); vm.step(program); vm.step(program); vm.step(program); assertEquals(s_expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // SLOAD OP public void testSLOAD_3() { VM vm = new VM(); program = new Program(compile("PUSH1 0x22 PUSH1 0xAA SSTORE PUSH1 0x33 PUSH1 0xCC SSTORE PUSH1 0xCC SLOAD"), invoke); String s_expected = "0000000000000000000000000000000000000000000000000000000000000033"; vm.step(program); vm.step(program); vm.step(program); vm.step(program); vm.step(program); vm.step(program); vm.step(program); vm.step(program); assertEquals(s_expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test(expected = Program.StackTooSmallException.class) // SLOAD OP public void testSLOAD_4() { VM vm = new VM(); program = new Program(compile("SLOAD"), invoke); try { vm.step(program); } finally { assertTrue(program.isStopped()); } } @Test // PC OP public void testPC_1() { VM vm = new VM(); program = new Program(compile("PC"), invoke); String s_expected = "0000000000000000000000000000000000000000000000000000000000000000"; vm.step(program); assertEquals(s_expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // PC OP public void testPC_2() { VM vm = new VM(); program = new Program(compile("PUSH1 0x22 PUSH1 0xAA MSTORE PUSH1 0xAA SLOAD PC"), invoke); String s_expected = "0000000000000000000000000000000000000000000000000000000000000008"; vm.step(program); vm.step(program); vm.step(program); vm.step(program); vm.step(program); vm.step(program); assertEquals(s_expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test(expected = Program.BadJumpDestinationException.class) // JUMP OP mal data public void testJUMP_1() { VM vm = new VM(); program = new Program(compile("PUSH1 0xAA PUSH1 0xBB PUSH1 0x0E JUMP PUSH1 0xCC PUSH1 0xDD PUSH1 0xEE JUMPDEST PUSH1 0xFF"), invoke); String s_expected = "00000000000000000000000000000000000000000000000000000000000000FF"; vm.step(program); vm.step(program); vm.step(program); vm.step(program); vm.step(program); assertEquals(s_expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test(expected = Program.BadJumpDestinationException.class) // JUMP OP mal data public void testJUMP_2() { VM vm = new VM(); program = new Program(compile("PUSH1 0x0C PUSH1 0x0C SWAP1 JUMP PUSH1 0xCC PUSH1 0xDD PUSH1 0xEE PUSH1 0xFF"), invoke); try { vm.step(program); vm.step(program); vm.step(program); vm.step(program); vm.step(program); } finally { assertTrue(program.isStopped()); } } @Test // JUMPI OP public void testJUMPI_1() { VM vm = new VM(); program = new Program(compile("PUSH1 0x01 PUSH1 0x05 JUMPI JUMPDEST PUSH1 0xCC"), invoke); String s_expected = "00000000000000000000000000000000000000000000000000000000000000CC"; vm.step(program); vm.step(program); vm.step(program); vm.step(program); vm.step(program); assertEquals(s_expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // JUMPI OP public void testJUMPI_2() { VM vm = new VM(); program = new Program(compile("PUSH4 0x00000000 PUSH1 0x44 JUMPI PUSH1 0xCC PUSH1 0xDD"), invoke); String s_expected_1 = "00000000000000000000000000000000000000000000000000000000000000DD"; String s_expected_2 = "00000000000000000000000000000000000000000000000000000000000000CC"; vm.step(program); vm.step(program); vm.step(program); vm.step(program); vm.step(program); DataWord item1 = program.stackPop(); DataWord item2 = program.stackPop(); assertEquals(s_expected_1, Hex.toHexString(item1.getData()).toUpperCase()); assertEquals(s_expected_2, Hex.toHexString(item2.getData()).toUpperCase()); } @Test(expected = Program.StackTooSmallException.class) // JUMPI OP mal public void testJUMPI_3() { VM vm = new VM(); program = new Program(compile("PUSH1 0x01 JUMPI"), invoke); try { vm.step(program); vm.step(program); } finally { assertTrue(program.isStopped()); } } @Test(expected = Program.BadJumpDestinationException.class) // JUMPI OP mal public void testJUMPI_4() { VM vm = new VM(); program = new Program(compile("PUSH1 0x01 PUSH1 0x22 SWAP1 SWAP1 JUMPI"), invoke); try { vm.step(program); vm.step(program); vm.step(program); vm.step(program); vm.step(program); } finally { assertTrue(program.isStopped()); } } @Test(expected = Program.BadJumpDestinationException.class) // JUMP OP mal data public void testJUMPDEST_1() { VM vm = new VM(); program = new Program(compile("PUSH1 0x23 PUSH1 0x08 JUMP PUSH1 0x01 JUMPDEST PUSH1 0x02 SSTORE"), invoke); String s_expected_key = "0000000000000000000000000000000000000000000000000000000000000002"; String s_expected_val = "0000000000000000000000000000000000000000000000000000000000000023"; vm.step(program); vm.step(program); vm.step(program); vm.step(program); vm.step(program); DataWord key = DataWord.of(Hex.decode(s_expected_key)); DataWord val = program.getStorage().getStorageValue(invoke.getOwnerAddress() .getNoLeadZeroesData(), key); assertTrue(program.isStopped()); assertEquals(s_expected_val, Hex.toHexString(val.getData()).toUpperCase()); } @Test // JUMPDEST OP for JUMPI public void testJUMPDEST_2() { VM vm = new VM(); program = new Program(compile("PUSH1 0x23 PUSH1 0x01 PUSH1 0x09 JUMPI PUSH1 0x01 JUMPDEST PUSH1 0x02 SSTORE"), invoke); String s_expected_key = "0000000000000000000000000000000000000000000000000000000000000002"; String s_expected_val = "0000000000000000000000000000000000000000000000000000000000000023"; vm.step(program); vm.step(program); vm.step(program); vm.step(program); vm.step(program); vm.step(program); vm.step(program); DataWord key = DataWord.of(Hex.decode(s_expected_key)); DataWord val = program.getStorage().getStorageValue(invoke.getOwnerAddress() .getNoLeadZeroesData(), key); assertTrue(program.isStopped()); assertEquals(s_expected_val, Hex.toHexString(val.getData()).toUpperCase()); } @Test // MSIZE OP public void testMSIZE_1() { VM vm = new VM(); program = new Program(compile("MSIZE"), invoke); String s_expected_1 = "0000000000000000000000000000000000000000000000000000000000000000"; vm.step(program); DataWord item1 = program.stackPop(); assertEquals(s_expected_1, Hex.toHexString(item1.getData()).toUpperCase()); } @Test // MSIZE OP public void testMSIZE_2() { VM vm = new VM(); program = new Program(compile("PUSH1 0x20 PUSH1 0x30 MSTORE MSIZE"), invoke); String s_expected_1 = "0000000000000000000000000000000000000000000000000000000000000060"; vm.step(program); vm.step(program); vm.step(program); vm.step(program); DataWord item1 = program.stackPop(); assertEquals(s_expected_1, Hex.toHexString(item1.getData()).toUpperCase()); } }
47,343
31.673568
143
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/vm/ProgramMemoryTest.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.vm; import org.ethereum.util.ByteUtil; import org.ethereum.vm.program.Program; import org.ethereum.vm.program.invoke.ProgramInvokeMockImpl; import org.junit.Before; import org.junit.Ignore; import org.junit.Test; import java.nio.ByteBuffer; import static org.junit.Assert.*; public class ProgramMemoryTest { ProgramInvokeMockImpl pi = new ProgramInvokeMockImpl(); Program program; ByteBuffer memory; @Before public void createProgram() { program = new Program(ByteUtil.EMPTY_BYTE_ARRAY, pi); } @Test public void testGetMemSize() { byte[] memory = new byte[64]; program.initMem(memory); assertEquals(64, program.getMemSize()); } @Test @Ignore public void testMemorySave() { fail("Not yet implemented"); } @Test @Ignore public void testMemoryLoad() { fail("Not yet implemented"); } @Test public void testMemoryChunk1() { program.initMem(new byte[64]); int offset = 128; int size = 32; program.memoryChunk(offset, size); assertEquals(160, program.getMemSize()); } @Test // size 0 doesn't increase memory public void testMemoryChunk2() { program.initMem(new byte[64]); int offset = 96; int size = 0; program.memoryChunk(offset, size); assertEquals(64, program.getMemSize()); } @Test public void testAllocateMemory1() { program.initMem(new byte[64]); int offset = 32; int size = 32; program.allocateMemory(offset, size); assertEquals(64, program.getMemSize()); } @Test public void testAllocateMemory2() { // memory.limit() > offset, == size // memory.limit() < offset + size program.initMem(new byte[64]); int offset = 32; int size = 64; program.allocateMemory(offset, size); assertEquals(96, program.getMemSize()); } @Test public void testAllocateMemory3() { // memory.limit() > offset, > size program.initMem(new byte[64]); int offset = 0; int size = 32; program.allocateMemory(offset, size); assertEquals(64, program.getMemSize()); } @Test public void testAllocateMemory4() { program.initMem(new byte[64]); int offset = 0; int size = 64; program.allocateMemory(offset, size); assertEquals(64, program.getMemSize()); } @Test public void testAllocateMemory5() { program.initMem(new byte[64]); int offset = 0; int size = 0; program.allocateMemory(offset, size); assertEquals(64, program.getMemSize()); } @Test public void testAllocateMemory6() { // memory.limit() == offset, > size program.initMem(new byte[64]); int offset = 64; int size = 32; program.allocateMemory(offset, size); assertEquals(96, program.getMemSize()); } @Test public void testAllocateMemory7() { // memory.limit() == offset - size program.initMem(new byte[64]); int offset = 96; int size = 32; program.allocateMemory(offset, size); assertEquals(128, program.getMemSize()); } @Test public void testAllocateMemory8() { program.initMem(new byte[64]); int offset = 0; int size = 96; program.allocateMemory(offset, size); assertEquals(96, program.getMemSize()); } @Test public void testAllocateMemory9() { // memory.limit() < offset, > size // memory.limit() < offset - size program.initMem(new byte[64]); int offset = 96; int size = 0; program.allocateMemory(offset, size); assertEquals(64, program.getMemSize()); } /************************************************/ @Test public void testAllocateMemory10() { // memory = null, offset > size int offset = 32; int size = 0; program.allocateMemory(offset, size); assertEquals(0, program.getMemSize()); } @Test public void testAllocateMemory11() { // memory = null, offset < size int offset = 0; int size = 32; program.allocateMemory(offset, size); assertEquals(32, program.getMemSize()); } @Test public void testAllocateMemory12() { // memory.limit() < offset, < size program.initMem(new byte[64]); int offset = 64; int size = 96; program.allocateMemory(offset, size); assertEquals(160, program.getMemSize()); } @Test public void testAllocateMemory13() { // memory.limit() > offset, < size program.initMem(new byte[64]); int offset = 32; int size = 128; program.allocateMemory(offset, size); assertEquals(160, program.getMemSize()); } @Test public void testAllocateMemory14() { // memory.limit() < offset, == size program.initMem(new byte[64]); int offset = 96; int size = 64; program.allocateMemory(offset, size); assertEquals(160, program.getMemSize()); } @Test public void testAllocateMemory15() { // memory.limit() == offset, < size program.initMem(new byte[64]); int offset = 64; int size = 96; program.allocateMemory(offset, size); assertEquals(160, program.getMemSize()); } @Test public void testAllocateMemory16() { // memory.limit() == offset, == size // memory.limit() > offset - size program.initMem(new byte[64]); int offset = 64; int size = 64; program.allocateMemory(offset, size); assertEquals(128, program.getMemSize()); } @Test public void testAllocateMemory17() { // memory.limit() > offset + size program.initMem(new byte[96]); int offset = 32; int size = 32; program.allocateMemory(offset, size); assertEquals(96, program.getMemSize()); } @Test public void testAllocateMemoryUnrounded1() { // memory unrounded program.initMem(new byte[64]); int offset = 64; int size = 32; program.allocateMemory(offset, size); assertEquals(96, program.getMemSize()); } @Test public void testAllocateMemoryUnrounded2() { // offset unrounded program.initMem(new byte[64]); int offset = 16; int size = 32; program.allocateMemory(offset, size); assertEquals(64, program.getMemSize()); } @Test public void testAllocateMemoryUnrounded3() { // size unrounded program.initMem(new byte[64]); int offset = 64; int size = 16; program.allocateMemory(offset, size); assertEquals(96, program.getMemSize()); } @Test public void testAllocateMemoryUnrounded4() { // memory + offset unrounded program.initMem(new byte[64]); int offset = 16; int size = 32; program.allocateMemory(offset, size); assertEquals(64, program.getMemSize()); } @Test public void testAllocateMemoryUnrounded5() { // memory + size unrounded program.initMem(new byte[64]); int offset = 32; int size = 16; program.allocateMemory(offset, size); assertEquals(64, program.getMemSize()); } @Test public void testAllocateMemoryUnrounded6() { // offset + size unrounded program.initMem(new byte[32]); int offset = 16; int size = 16; program.allocateMemory(offset, size); assertEquals(32, program.getMemSize()); } @Test public void testAllocateMemoryUnrounded7() { // memory + offset + size unrounded program.initMem(new byte[32]); int offset = 16; int size = 16; program.allocateMemory(offset, size); assertEquals(32, program.getMemSize()); } @Test public void testEmptyInsert() { int offset = 32; int size = 0; program.memorySave(offset, size, new byte[] {0x01}); assertEquals(0, program.getMemSize()); } }
9,126
25.002849
80
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/vm/DataWordTest.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.vm; import org.junit.Test; import org.spongycastle.util.encoders.Hex; import java.math.BigInteger; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; public class DataWordTest { @Test public void testAddPerformance() { boolean enabled = false; if (enabled) { byte[] one = new byte[]{0x01, 0x31, 0x54, 0x41, 0x01, 0x31, 0x54, 0x41, 0x01, 0x31, 0x54, 0x41, 0x01, 0x31, 0x54, 0x41, 0x01, 0x31, 0x54, 0x41, 0x01, 0x31, 0x54, 0x41, 0x01, 0x31, 0x54, 0x41, 0x01, 0x31, 0x54, 0x41}; // Random value int ITERATIONS = 10000000; long now1 = System.currentTimeMillis(); for (int i = 0; i < ITERATIONS; i++) { DataWord x = DataWord.of(one); x = x.add(x); } System.out.println("Add1: " + (System.currentTimeMillis() - now1) + "ms"); long now2 = System.currentTimeMillis(); for (int i = 0; i < ITERATIONS; i++) { DataWord x = DataWord.of(one); x = x.add2(x); } System.out.println("Add2: " + (System.currentTimeMillis() - now2) + "ms"); } else { System.out.println("ADD performance test is disabled."); } } @Test public void testAdd2() { byte[] two = new byte[32]; two[31] = (byte) 0xff; // 0x000000000000000000000000000000000000000000000000000000000000ff DataWord x = DataWord.of(two); x = x.add(DataWord.of(two)); System.out.println(Hex.toHexString(x.getData())); DataWord y = DataWord.of(two); y = y.add2(DataWord.of(two)); System.out.println(Hex.toHexString(y.getData())); } @Test public void testAdd3() { byte[] three = new byte[32]; for (int i = 0; i < three.length; i++) { three[i] = (byte) 0xff; } DataWord x = DataWord.of(three); x = x.add(DataWord.of(three)); assertEquals(32, x.getData().length); System.out.println(Hex.toHexString(x.getData())); // FAIL // DataWord y = DataWord.of(three); // y.add2(DataWord.of(three)); // System.out.println(Hex.toHexString(y.getData())); } @Test public void testMod() { String expected = "000000000000000000000000000000000000000000000000000000000000001a"; byte[] one = new byte[32]; one[31] = 0x1e; // 0x000000000000000000000000000000000000000000000000000000000000001e byte[] two = new byte[32]; for (int i = 0; i < two.length; i++) { two[i] = (byte) 0xff; } two[31] = 0x56; // 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff56 DataWord x = DataWord.of(one);// System.out.println(x.value()); DataWord y = DataWord.of(two);// System.out.println(y.value()); DataWord actual = y.mod(x); assertEquals(32, y.getData().length); assertEquals(expected, Hex.toHexString(actual.getData())); } @Test public void testMul() { byte[] one = new byte[32]; one[31] = 0x1; // 0x0000000000000000000000000000000000000000000000000000000000000001 byte[] two = new byte[32]; two[11] = 0x1; // 0x0000000000000000000000010000000000000000000000000000000000000000 DataWord x = DataWord.of(one);// System.out.println(x.value()); DataWord y = DataWord.of(two);// System.out.println(y.value()); x = x.mul(y); assertEquals(32, y.getData().length); assertEquals("0000000000000000000000010000000000000000000000000000000000000000", Hex.toHexString(y.getData())); } @Test public void testMulOverflow() { byte[] one = new byte[32]; one[30] = 0x1; // 0x0000000000000000000000000000000000000000000000000000000000000100 byte[] two = new byte[32]; two[0] = 0x1; // 0x1000000000000000000000000000000000000000000000000000000000000000 DataWord x = DataWord.of(one);// System.out.println(x.value()); DataWord y = DataWord.of(two);// System.out.println(y.value()); x = x.mul(y); assertEquals(32, y.getData().length); assertEquals("0100000000000000000000000000000000000000000000000000000000000000", Hex.toHexString(y.getData())); } @Test public void testDiv() { byte[] one = new byte[32]; one[30] = 0x01; one[31] = 0x2c; // 0x000000000000000000000000000000000000000000000000000000000000012c byte[] two = new byte[32]; two[31] = 0x0f; // 0x000000000000000000000000000000000000000000000000000000000000000f DataWord x = DataWord.of(one); DataWord y = DataWord.of(two); DataWord actual = x.div(y); assertEquals(32, x.getData().length); assertEquals("0000000000000000000000000000000000000000000000000000000000000014", Hex.toHexString(actual.getData())); } @Test public void testDivZero() { byte[] one = new byte[32]; one[30] = 0x05; // 0x0000000000000000000000000000000000000000000000000000000000000500 byte[] two = new byte[32]; DataWord x = DataWord.of(one); DataWord y = DataWord.of(two); DataWord actual = x.div(y); assertEquals(32, actual.getData().length); assertTrue(actual.isZero()); } @Test public void testSDivNegative() { // one is -300 as 256-bit signed integer: byte[] one = Hex.decode("fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed4"); byte[] two = new byte[32]; two[31] = 0x0f; DataWord x = DataWord.of(one); DataWord y = DataWord.of(two); DataWord actual = x.sDiv(y); assertEquals(32, x.getData().length); assertEquals("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec", actual.toString()); } @Test public void testPow() { BigInteger x = BigInteger.valueOf(Integer.MAX_VALUE); BigInteger y = BigInteger.valueOf(1000); BigInteger result1 = x.modPow(x, y); BigInteger result2 = pow(x, y); System.out.println(result1); System.out.println(result2); } @Test public void testSignExtend1() { DataWord x = DataWord.of(Hex.decode("f2")); byte k = 0; String expected = "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff2"; DataWord signExtend = x.signExtend(k); System.out.println(signExtend.toString()); assertEquals(expected, signExtend.toString()); } @Test public void testSignExtend2() { DataWord x = DataWord.of(Hex.decode("f2")); byte k = 1; String expected = "00000000000000000000000000000000000000000000000000000000000000f2"; x = x.signExtend(k); System.out.println(x.toString()); assertEquals(expected, x.toString()); } @Test public void testSignExtend3() { byte k = 1; DataWord x = DataWord.of(Hex.decode("0f00ab")); String expected = "00000000000000000000000000000000000000000000000000000000000000ab"; DataWord signExtend = x.signExtend(k); System.out.println(signExtend.toString()); assertEquals(expected, signExtend.toString()); } @Test public void testSignExtend4() { byte k = 1; DataWord x = DataWord.of(Hex.decode("ffff")); String expected = "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"; DataWord signExtend = x.signExtend(k); System.out.println(signExtend.toString()); assertEquals(expected, signExtend.toString()); } @Test public void testSignExtend5() { byte k = 3; DataWord x = DataWord.of(Hex.decode("ffffffff")); String expected = "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"; DataWord signExtend = x.signExtend(k); System.out.println(signExtend.toString()); assertEquals(expected, signExtend.toString()); } @Test public void testSignExtend6() { byte k = 3; DataWord x = DataWord.of(Hex.decode("ab02345678")); String expected = "0000000000000000000000000000000000000000000000000000000002345678"; DataWord signExtend = x.signExtend(k); System.out.println(signExtend.toString()); assertEquals(expected, signExtend.toString()); } @Test public void testSignExtend7() { byte k = 3; DataWord x = DataWord.of(Hex.decode("ab82345678")); String expected = "ffffffffffffffffffffffffffffffffffffffffffffffffffffffff82345678"; DataWord signExtend = x.signExtend(k); System.out.println(signExtend.toString()); assertEquals(expected, signExtend.toString()); } @Test public void testSignExtend8() { byte k = 30; DataWord x = DataWord.of(Hex.decode("ff34567882345678823456788234567882345678823456788234567882345678")); String expected = "0034567882345678823456788234567882345678823456788234567882345678"; DataWord signExtend = x.signExtend(k); System.out.println(signExtend.toString()); assertEquals(expected, signExtend.toString()); } @Test(expected = IndexOutOfBoundsException.class) public void testSignExtendException1() { byte k = -1; DataWord x = DataWord.ZERO; x.signExtend(k); // should throw an exception } @Test(expected = IndexOutOfBoundsException.class) public void testSignExtendException2() { byte k = 32; DataWord x = DataWord.ZERO; x.signExtend(k); // should throw an exception } @Test public void testAddModOverflow() { testAddMod("9999999999999999999999999999999999999999999999999999999999999999", "8888888888888888888888888888888888888888888888888888888888888888", "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); testAddMod("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); } void testAddMod(String v1, String v2, String v3) { DataWord dv1 = DataWord.of(Hex.decode(v1)); DataWord dv2 = DataWord.of(Hex.decode(v2)); DataWord dv3 = DataWord.of(Hex.decode(v3)); BigInteger bv1 = new BigInteger(v1, 16); BigInteger bv2 = new BigInteger(v2, 16); BigInteger bv3 = new BigInteger(v3, 16); DataWord actual = dv1.addmod(dv2, dv3); BigInteger br = bv1.add(bv2).mod(bv3); assertEquals(actual.value(), br); } @Test public void testMulMod1() { DataWord wr = DataWord.of(Hex.decode("9999999999999999999999999999999999999999999999999999999999999999")); DataWord w1 = DataWord.of(Hex.decode("01")); DataWord w2 = DataWord.of(Hex.decode("9999999999999999999999999999999999999999999999999999999999999998")); DataWord actual = wr.mulmod(w1, w2); assertEquals(32, actual.getData().length); assertEquals("0000000000000000000000000000000000000000000000000000000000000001", Hex.toHexString(actual.getData())); } @Test public void testMulMod2() { DataWord wr = DataWord.of(Hex.decode("9999999999999999999999999999999999999999999999999999999999999999")); DataWord w1 = DataWord.of(Hex.decode("01")); DataWord w2 = DataWord.of(Hex.decode("9999999999999999999999999999999999999999999999999999999999999999")); DataWord actual = wr.mulmod(w1, w2); assertEquals(32, actual.getData().length); assertTrue(actual.isZero()); } @Test public void testMulModZero() { DataWord wr = DataWord.of(Hex.decode("00")); DataWord w1 = DataWord.of(Hex.decode("9999999999999999999999999999999999999999999999999999999999999999")); DataWord w2 = DataWord.of(Hex.decode("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")); wr = wr.mulmod(w1, w2); assertEquals(32, wr.getData().length); assertTrue(wr.isZero()); } @Test public void testMulModZeroWord1() { DataWord wr = DataWord.of(Hex.decode("9999999999999999999999999999999999999999999999999999999999999999")); DataWord w1 = DataWord.of(Hex.decode("00")); DataWord w2 = DataWord.of(Hex.decode("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")); DataWord actual = wr.mulmod(w1, w2); assertEquals(32, wr.getData().length); assertTrue(actual.isZero()); } @Test public void testMulModZeroWord2() { DataWord wr = DataWord.of(Hex.decode("9999999999999999999999999999999999999999999999999999999999999999")); DataWord w1 = DataWord.of(Hex.decode("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")); DataWord w2 = DataWord.of(Hex.decode("00")); DataWord actual = wr.mulmod(w1, w2); assertEquals(32, wr.getData().length); assertTrue(actual.isZero()); } @Test public void testMulModOverflow() { DataWord wr = DataWord.of(Hex.decode("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")); DataWord w1 = DataWord.of(Hex.decode("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")); DataWord w2 = DataWord.of(Hex.decode("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")); DataWord actual = wr.mulmod(w1, w2); assertEquals(32, wr.getData().length); assertTrue(actual.isZero()); } public static BigInteger pow(BigInteger x, BigInteger y) { if (y.compareTo(BigInteger.ZERO) < 0) throw new IllegalArgumentException(); BigInteger z = x; // z will successively become x^2, x^4, x^8, x^16, // x^32... BigInteger result = BigInteger.ONE; byte[] bytes = y.toByteArray(); for (int i = bytes.length - 1; i >= 0; i--) { byte bits = bytes[i]; for (int j = 0; j < 8; j++) { if ((bits & 1) != 0) result = result.multiply(z); // short cut out if there are no more bits to handle: if ((bits >>= 1) == 0 && i == 0) return result; z = z.multiply(z); } } return result; } }
15,367
34.410138
124
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/vm/MemoryTest.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.vm; import org.ethereum.vm.program.Memory; import org.junit.Test; import org.spongycastle.util.encoders.Hex; import java.util.Arrays; import static java.lang.Math.ceil; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; public class MemoryTest { private static final int WORD_SIZE = 32; private static final int CHUNK_SIZE = 1024; @Test public void testExtend() { checkMemoryExtend(0); checkMemoryExtend(1); checkMemoryExtend(WORD_SIZE); checkMemoryExtend(WORD_SIZE * 2); checkMemoryExtend(CHUNK_SIZE - 1); checkMemoryExtend(CHUNK_SIZE); checkMemoryExtend(CHUNK_SIZE + 1); checkMemoryExtend(2000); } private static void checkMemoryExtend(int dataSize) { Memory memory = new Memory(); memory.extend(0, dataSize); assertEquals(calcSize(dataSize, CHUNK_SIZE), memory.internalSize()); assertEquals(calcSize(dataSize, WORD_SIZE), memory.size()); } private static int calcSize(int dataSize, int chunkSize) { return (int) ceil((double) dataSize / chunkSize) * chunkSize; } @Test public void memorySave_1() { Memory memoryBuffer = new Memory(); byte[] data = {1, 1, 1, 1}; memoryBuffer.write(0, data, data.length, false); assertTrue(1 == memoryBuffer.getChunks().size()); byte[] chunk = memoryBuffer.getChunks().get(0); assertTrue(chunk[0] == 1); assertTrue(chunk[1] == 1); assertTrue(chunk[2] == 1); assertTrue(chunk[3] == 1); assertTrue(chunk[4] == 0); assertTrue(memoryBuffer.size() == 32); } @Test public void memorySave_2() { Memory memoryBuffer = new Memory(); byte[] data = Hex.decode("0101010101010101010101010101010101010101010101010101010101010101"); memoryBuffer.write(0, data, data.length, false); assertTrue(1 == memoryBuffer.getChunks().size()); byte[] chunk = memoryBuffer.getChunks().get(0); assertTrue(chunk[0] == 1); assertTrue(chunk[1] == 1); assertTrue(chunk[30] == 1); assertTrue(chunk[31] == 1); assertTrue(chunk[32] == 0); assertTrue(memoryBuffer.size() == 32); } @Test public void memorySave_3() { Memory memoryBuffer = new Memory(); byte[] data = Hex.decode("010101010101010101010101010101010101010101010101010101010101010101"); memoryBuffer.write(0, data, data.length, false); assertTrue(1 == memoryBuffer.getChunks().size()); byte[] chunk = memoryBuffer.getChunks().get(0); assertTrue(chunk[0] == 1); assertTrue(chunk[1] == 1); assertTrue(chunk[30] == 1); assertTrue(chunk[31] == 1); assertTrue(chunk[32] == 1); assertTrue(chunk[33] == 0); assertTrue(memoryBuffer.size() == 64); } @Test public void memorySave_4() { Memory memoryBuffer = new Memory(); byte[] data = new byte[1024]; Arrays.fill(data, (byte) 1); memoryBuffer.write(0, data, data.length, false); assertTrue(1 == memoryBuffer.getChunks().size()); byte[] chunk = memoryBuffer.getChunks().get(0); assertTrue(chunk[0] == 1); assertTrue(chunk[1] == 1); assertTrue(chunk[1022] == 1); assertTrue(chunk[1023] == 1); assertTrue(memoryBuffer.size() == 1024); } @Test public void memorySave_5() { Memory memoryBuffer = new Memory(); byte[] data = new byte[1025]; Arrays.fill(data, (byte) 1); memoryBuffer.write(0, data, data.length, false); assertTrue(2 == memoryBuffer.getChunks().size()); byte[] chunk1 = memoryBuffer.getChunks().get(0); assertTrue(chunk1[0] == 1); assertTrue(chunk1[1] == 1); assertTrue(chunk1[1022] == 1); assertTrue(chunk1[1023] == 1); byte[] chunk2 = memoryBuffer.getChunks().get(1); assertTrue(chunk2[0] == 1); assertTrue(chunk2[1] == 0); assertTrue(memoryBuffer.size() == 1056); } @Test public void memorySave_6() { Memory memoryBuffer = new Memory(); byte[] data1 = new byte[1024]; Arrays.fill(data1, (byte) 1); byte[] data2 = new byte[1024]; Arrays.fill(data2, (byte) 2); memoryBuffer.write(0, data1, data1.length, false); memoryBuffer.write(1024, data2, data2.length, false); assertTrue(2 == memoryBuffer.getChunks().size()); byte[] chunk1 = memoryBuffer.getChunks().get(0); assertTrue(chunk1[0] == 1); assertTrue(chunk1[1] == 1); assertTrue(chunk1[1022] == 1); assertTrue(chunk1[1023] == 1); byte[] chunk2 = memoryBuffer.getChunks().get(1); assertTrue(chunk2[0] == 2); assertTrue(chunk2[1] == 2); assertTrue(chunk2[1022] == 2); assertTrue(chunk2[1023] == 2); assertTrue(memoryBuffer.size() == 2048); } @Test public void memorySave_7() { Memory memoryBuffer = new Memory(); byte[] data1 = new byte[1024]; Arrays.fill(data1, (byte) 1); byte[] data2 = new byte[1024]; Arrays.fill(data2, (byte) 2); byte[] data3 = new byte[1]; Arrays.fill(data3, (byte) 3); memoryBuffer.write(0, data1, data1.length, false); memoryBuffer.write(1024, data2, data2.length, false); memoryBuffer.write(2048, data3, data3.length, false); assertTrue(3 == memoryBuffer.getChunks().size()); byte[] chunk1 = memoryBuffer.getChunks().get(0); assertTrue(chunk1[0] == 1); assertTrue(chunk1[1] == 1); assertTrue(chunk1[1022] == 1); assertTrue(chunk1[1023] == 1); byte[] chunk2 = memoryBuffer.getChunks().get(1); assertTrue(chunk2[0] == 2); assertTrue(chunk2[1] == 2); assertTrue(chunk2[1022] == 2); assertTrue(chunk2[1023] == 2); byte[] chunk3 = memoryBuffer.getChunks().get(2); assertTrue(chunk3[0] == 3); assertTrue(memoryBuffer.size() == 2080); } @Test public void memorySave_8() { Memory memoryBuffer = new Memory(); byte[] data1 = new byte[128]; Arrays.fill(data1, (byte) 1); memoryBuffer.extendAndWrite(0, 256, data1); int ones = 0; int zeroes = 0; for (int i = 0; i < memoryBuffer.size(); ++i){ if (memoryBuffer.readByte(i) == 1) ++ones; if (memoryBuffer.readByte(i) == 0) ++zeroes; } assertTrue(ones == zeroes); assertTrue(256 == memoryBuffer.size()); } @Test public void memoryLoad_1() { Memory memoryBuffer = new Memory(); DataWord value = memoryBuffer.readWord(100); assertTrue(value.intValue() == 0); assertTrue(memoryBuffer.getChunks().size() == 1); assertTrue(memoryBuffer.size() == 32 * 5); } @Test public void memoryLoad_2() { Memory memoryBuffer = new Memory(); DataWord value = memoryBuffer.readWord(2015); assertTrue(value.intValue() == 0); assertTrue(memoryBuffer.getChunks().size() == 2); assertTrue(memoryBuffer.size() == 2048); } @Test public void memoryLoad_3() { Memory memoryBuffer = new Memory(); DataWord value = memoryBuffer.readWord(2016); assertTrue(value.intValue() == 0); assertTrue(memoryBuffer.getChunks().size() == 2); assertTrue(memoryBuffer.size() == 2048); } @Test public void memoryLoad_4() { Memory memoryBuffer = new Memory(); DataWord value = memoryBuffer.readWord(2017); assertTrue(value.intValue() == 0); assertTrue(memoryBuffer.getChunks().size() == 3); assertTrue(memoryBuffer.size() == 2080); } @Test public void memoryLoad_5() { Memory memoryBuffer = new Memory(); byte[] data1 = new byte[1024]; Arrays.fill(data1, (byte) 1); byte[] data2 = new byte[1024]; Arrays.fill(data2, (byte) 2); memoryBuffer.write(0, data1, data1.length, false); memoryBuffer.write(1024, data2, data2.length, false); assertTrue(memoryBuffer.getChunks().size() == 2); assertTrue(memoryBuffer.size() == 2048); DataWord val1 = memoryBuffer.readWord(0x3df); DataWord val2 = memoryBuffer.readWord(0x3e0); DataWord val3 = memoryBuffer.readWord(0x3e1); assertArrayEquals( Hex.decode("0101010101010101010101010101010101010101010101010101010101010101"), val1.getData()); assertArrayEquals( Hex.decode("0101010101010101010101010101010101010101010101010101010101010101"), val2.getData()); assertArrayEquals( Hex.decode("0101010101010101010101010101010101010101010101010101010101010102"), val3.getData()); assertTrue(memoryBuffer.size() == 2048); } @Test public void memoryChunk_1(){ Memory memoryBuffer = new Memory(); byte[] data1 = new byte[32]; Arrays.fill(data1, (byte) 1); byte[] data2 = new byte[32]; Arrays.fill(data2, (byte) 2); memoryBuffer.write(0, data1, data1.length, false); memoryBuffer.write(32, data2, data2.length, false); byte[] data = memoryBuffer.read(0, 64); assertArrayEquals( Hex.decode("0101010101010101010101010101010101010101010101010101010101010101" + "0202020202020202020202020202020202020202020202020202020202020202"), data ); assertEquals(64, memoryBuffer.size()); } @Test public void memoryChunk_2(){ Memory memoryBuffer = new Memory(); byte[] data1 = new byte[32]; Arrays.fill(data1, (byte) 1); memoryBuffer.write(0, data1, data1.length, false); assertTrue(32 == memoryBuffer.size()); byte[] data = memoryBuffer.read(0, 64); assertArrayEquals( Hex.decode("0101010101010101010101010101010101010101010101010101010101010101" + "0000000000000000000000000000000000000000000000000000000000000000"), data ); assertEquals(64, memoryBuffer.size()); } @Test public void memoryChunk_3(){ Memory memoryBuffer = new Memory(); byte[] data1 = new byte[1024]; Arrays.fill(data1, (byte) 1); byte[] data2 = new byte[1024]; Arrays.fill(data2, (byte) 2); memoryBuffer.write(0, data1, data1.length, false); memoryBuffer.write(1024, data2, data2.length, false); byte[] data = memoryBuffer.read(0, 2048); int ones = 0; int twos = 0; for (int i = 0; i < data.length; ++i){ if (data[i] == 1) ++ones; if (data[i] == 2) ++twos; } assertTrue(ones == twos); assertTrue(2048 == memoryBuffer.size()); } @Test public void memoryChunk_4(){ Memory memoryBuffer = new Memory(); byte[] data1 = new byte[1024]; Arrays.fill(data1, (byte) 1); byte[] data2 = new byte[1024]; Arrays.fill(data2, (byte) 2); memoryBuffer.write(0, data1, data1.length, false); memoryBuffer.write(1024, data2, data2.length, false); byte[] data = memoryBuffer.read(0, 2049); int ones = 0; int twos = 0; int zero = 0; for (int i = 0; i < data.length; ++i){ if (data[i] == 1) ++ones; if (data[i] == 2) ++twos; if (data[i] == 0) ++zero; } assertTrue(zero == 1); assertTrue(ones == twos); assertTrue(2080 == memoryBuffer.size()); } @Test public void memoryWriteLimited_1(){ Memory memoryBuffer = new Memory(); memoryBuffer.extend(0, 3072); byte[] data1 = new byte[6272]; Arrays.fill(data1, (byte) 1); memoryBuffer.write(2720, data1, data1.length, true); byte lastZero = memoryBuffer.readByte(2719); byte firstOne = memoryBuffer.readByte(2721); assertTrue(memoryBuffer.size() == 3072); assertTrue(lastZero == 0); assertTrue(firstOne == 1); byte[] data = memoryBuffer.read(2720, 352); int ones = 0; int zero = 0; for (int i = 0; i < data.length; ++i){ if (data[i] == 1) ++ones; if (data[i] == 0) ++zero; } assertTrue(ones == data.length); assertTrue(zero == 0); } @Test public void memoryWriteLimited_2(){ Memory memoryBuffer = new Memory(); memoryBuffer.extend(0, 3072); byte[] data1 = new byte[6272]; Arrays.fill(data1, (byte) 1); memoryBuffer.write(2720, data1, 300, true); byte lastZero = memoryBuffer.readByte(2719); byte firstOne = memoryBuffer.readByte(2721); assertTrue(memoryBuffer.size() == 3072); assertTrue(lastZero == 0); assertTrue(firstOne == 1); byte[] data = memoryBuffer.read(2720, 352); int ones = 0; int zero = 0; for (int i = 0; i < data.length; ++i){ if (data[i] == 1) ++ones; if (data[i] == 0) ++zero; } assertTrue(ones == 300); assertTrue(zero == 52); } @Test public void memoryWriteLimited_3(){ Memory memoryBuffer = new Memory(); memoryBuffer.extend(0, 128); byte[] data1 = new byte[20]; Arrays.fill(data1, (byte) 1); memoryBuffer.write(10, data1, 40, true); byte lastZero = memoryBuffer.readByte(9); byte firstOne = memoryBuffer.readByte(10); assertTrue(memoryBuffer.size() == 128); assertTrue(lastZero == 0); assertTrue(firstOne == 1); byte[] data = memoryBuffer.read(10, 30); int ones = 0; int zero = 0; for (int i = 0; i < data.length; ++i){ if (data[i] == 1) ++ones; if (data[i] == 0) ++zero; } assertTrue(ones == 20); assertTrue(zero == 10); } }
15,054
27.245779
103
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/vm/VMBitOpTest.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.vm; import org.ethereum.config.SystemProperties; import org.ethereum.config.blockchain.ConstantinopleConfig; import org.ethereum.config.blockchain.DaoHFConfig; import org.ethereum.vm.program.Program; import org.junit.Test; import org.spongycastle.util.encoders.Hex; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; /** * Simple tests for VM Bitwise Logic & Comparison Operations */ public class VMBitOpTest extends VMBaseOpTest { private static final SystemProperties constantinopleConfig = new SystemProperties(){{ setBlockchainConfig(new ConstantinopleConfig(new DaoHFConfig())); }}; @Test // AND OP public void testAND_1() { VM vm = new VM(); program = new Program(compile("PUSH1 0x0A PUSH1 0x0A AND"), invoke); String expected = "000000000000000000000000000000000000000000000000000000000000000A"; vm.step(program); vm.step(program); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // AND OP public void testAND_2() { VM vm = new VM(); program = new Program(compile("PUSH1 0xC0 PUSH1 0x0A AND"), invoke); String expected = "0000000000000000000000000000000000000000000000000000000000000000"; vm.step(program); vm.step(program); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test(expected = RuntimeException.class) // AND OP mal data public void testAND_3() { VM vm = new VM(); program = new Program(compile("PUSH1 0xC0 AND"), invoke); try { vm.step(program); vm.step(program); vm.step(program); } finally { assertTrue(program.isStopped()); } } @Test // OR OP public void testOR_1() { VM vm = new VM(); program = new Program(compile("PUSH1 0xF0 PUSH1 0x0F OR"), invoke); String expected = "00000000000000000000000000000000000000000000000000000000000000FF"; vm.step(program); vm.step(program); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // OR OP public void testOR_2() { VM vm = new VM(); program = new Program(compile("PUSH1 0xC3 PUSH1 0x3C OR"), invoke); String expected = "00000000000000000000000000000000000000000000000000000000000000FF"; vm.step(program); vm.step(program); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test(expected = RuntimeException.class) // OR OP mal data public void testOR_3() { VM vm = new VM(); program = new Program(compile("PUSH1 0xC0 OR"), invoke); try { vm.step(program); vm.step(program); vm.step(program); } finally { assertTrue(program.isStopped()); } } @Test // XOR OP public void testXOR_1() { VM vm = new VM(); program = new Program(compile("PUSH1 0xFF PUSH1 0xFF XOR"), invoke); String expected = "0000000000000000000000000000000000000000000000000000000000000000"; vm.step(program); vm.step(program); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // XOR OP public void testXOR_2() { VM vm = new VM(); program = new Program(compile("PUSH1 0x0F PUSH1 0xF0 XOR"), invoke); String expected = "00000000000000000000000000000000000000000000000000000000000000FF"; vm.step(program); vm.step(program); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test(expected = RuntimeException.class) // XOR OP mal data public void testXOR_3() { VM vm = new VM(); program = new Program(compile("PUSH1 0xC0 XOR"), invoke); try { vm.step(program); vm.step(program); vm.step(program); } finally { assertTrue(program.isStopped()); } } @Test // BYTE OP public void testBYTE_1() { VM vm = new VM(); program = new Program(compile("PUSH6 0xAABBCCDDEEFF PUSH1 0x1E BYTE"), invoke); String expected = "00000000000000000000000000000000000000000000000000000000000000EE"; vm.step(program); vm.step(program); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // BYTE OP public void testBYTE_2() { VM vm = new VM(); program = new Program(compile("PUSH6 0xAABBCCDDEEFF PUSH1 0x20 BYTE"), invoke); String expected = "0000000000000000000000000000000000000000000000000000000000000000"; vm.step(program); vm.step(program); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // BYTE OP public void testBYTE_3() { VM vm = new VM(); program = new Program(compile("PUSH6 0xAABBCCDDEE3A PUSH1 0x1F BYTE"), invoke); String expected = "000000000000000000000000000000000000000000000000000000000000003A"; vm.step(program); vm.step(program); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test(expected = Program.StackTooSmallException.class) // BYTE OP mal data public void testBYTE_4() { VM vm = new VM(); program = new Program(compile("PUSH6 0xAABBCCDDEE3A BYTE"), invoke); try { vm.step(program); vm.step(program); vm.step(program); } finally { assertTrue(program.isStopped()); } } @Test // SHL OP public void testSHL_1() { VM vm = new VM(); program = new Program(compile("PUSH32 0x0000000000000000000000000000000000000000000000000000000000000001 PUSH1 0x00 SHL"), invoke, constantinopleConfig); String expected = "0000000000000000000000000000000000000000000000000000000000000001"; vm.step(program); vm.step(program); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // SHL OP public void testSHL_2() { VM vm = new VM(); program = new Program(compile("PUSH32 0x0000000000000000000000000000000000000000000000000000000000000001 PUSH1 0x01 SHL"), invoke, constantinopleConfig); String expected = "0000000000000000000000000000000000000000000000000000000000000002"; vm.step(program); vm.step(program); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // SHL OP public void testSHL_3() { VM vm = new VM(); program = new Program(compile("PUSH32 0x0000000000000000000000000000000000000000000000000000000000000001 PUSH1 0xff SHL"), invoke, constantinopleConfig); String expected = "8000000000000000000000000000000000000000000000000000000000000000"; vm.step(program); vm.step(program); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // SHL OP public void testSHL_4() { VM vm = new VM(); program = new Program(compile("PUSH32 0x0000000000000000000000000000000000000000000000000000000000000001 PUSH2 0x0100 SHL"), invoke, constantinopleConfig); String expected = "0000000000000000000000000000000000000000000000000000000000000000"; vm.step(program); vm.step(program); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // SHL OP public void testSHL_5() { VM vm = new VM(); program = new Program(compile("PUSH32 0x0000000000000000000000000000000000000000000000000000000000000001 PUSH2 0x0101 SHL"), invoke, constantinopleConfig); String expected = "0000000000000000000000000000000000000000000000000000000000000000"; vm.step(program); vm.step(program); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // SHL OP public void testSHL_6() { VM vm = new VM(); program = new Program(compile("PUSH32 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff PUSH1 0x00 SHL"), invoke, constantinopleConfig); String expected = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"; vm.step(program); vm.step(program); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // SHL OP public void testSHL_7() { VM vm = new VM(); program = new Program(compile("PUSH32 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff PUSH1 0x01 SHL"), invoke, constantinopleConfig); String expected = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE"; vm.step(program); vm.step(program); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // SHL OP public void testSHL_8() { VM vm = new VM(); program = new Program(compile("PUSH32 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff PUSH1 0xff SHL"), invoke, constantinopleConfig); String expected = "8000000000000000000000000000000000000000000000000000000000000000"; vm.step(program); vm.step(program); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // SHL OP public void testSHL_9() { VM vm = new VM(); program = new Program(compile("PUSH32 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff PUSH2 0x0100 SHL"), invoke, constantinopleConfig); String expected = "0000000000000000000000000000000000000000000000000000000000000000"; vm.step(program); vm.step(program); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // SHL OP public void testSHL_10() { VM vm = new VM(); program = new Program(compile("PUSH32 0x0000000000000000000000000000000000000000000000000000000000000000 PUSH1 0x01 SHL"), invoke, constantinopleConfig); String expected = "0000000000000000000000000000000000000000000000000000000000000000"; vm.step(program); vm.step(program); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // SHL OP public void testSHL_11() { VM vm = new VM(); program = new Program(compile("PUSH32 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff PUSH1 0x01 SHL"), invoke, constantinopleConfig); String expected = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE"; vm.step(program); vm.step(program); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // SHR OP public void testSHR_1() { VM vm = new VM(); program = new Program(compile("PUSH32 0x0000000000000000000000000000000000000000000000000000000000000001 PUSH1 0x00 SHR"), invoke, constantinopleConfig); String expected = "0000000000000000000000000000000000000000000000000000000000000001"; vm.step(program); vm.step(program); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // SHR OP public void testSHR_2() { VM vm = new VM(); program = new Program(compile("PUSH32 0x0000000000000000000000000000000000000000000000000000000000000001 PUSH1 0x01 SHR"), invoke, constantinopleConfig); String expected = "0000000000000000000000000000000000000000000000000000000000000000"; vm.step(program); vm.step(program); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // SHR OP public void testSHR_3() { VM vm = new VM(); program = new Program(compile("PUSH32 0x8000000000000000000000000000000000000000000000000000000000000000 PUSH1 0x01 SHR"), invoke, constantinopleConfig); String expected = "4000000000000000000000000000000000000000000000000000000000000000"; vm.step(program); vm.step(program); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // SHR OP public void testSHR_4() { VM vm = new VM(); program = new Program(compile("PUSH32 0x8000000000000000000000000000000000000000000000000000000000000000 PUSH1 0xff SHR"), invoke, constantinopleConfig); String expected = "0000000000000000000000000000000000000000000000000000000000000001"; vm.step(program); vm.step(program); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // SHR OP public void testSHR_5() { VM vm = new VM(); program = new Program(compile("PUSH32 0x8000000000000000000000000000000000000000000000000000000000000000 PUSH2 0x0100 SHR"), invoke, constantinopleConfig); String expected = "0000000000000000000000000000000000000000000000000000000000000000"; vm.step(program); vm.step(program); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // SHR OP public void testSHR_6() { VM vm = new VM(); program = new Program(compile("PUSH32 0x8000000000000000000000000000000000000000000000000000000000000000 PUSH2 0x0101 SHR"), invoke, constantinopleConfig); String expected = "0000000000000000000000000000000000000000000000000000000000000000"; vm.step(program); vm.step(program); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // SHR OP public void testSHR_7() { VM vm = new VM(); program = new Program(compile("PUSH32 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff PUSH1 0x00 SHR"), invoke, constantinopleConfig); String expected = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"; vm.step(program); vm.step(program); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // SHR OP public void testSHR_8() { VM vm = new VM(); program = new Program(compile("PUSH32 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff PUSH1 0x01 SHR"), invoke, constantinopleConfig); String expected = "7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"; vm.step(program); vm.step(program); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // SHR OP public void testSHR_9() { VM vm = new VM(); program = new Program(compile("PUSH32 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff PUSH1 0xff SHR"), invoke, constantinopleConfig); String expected = "0000000000000000000000000000000000000000000000000000000000000001"; vm.step(program); vm.step(program); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // SHR OP public void testSHR_10() { VM vm = new VM(); program = new Program(compile("PUSH32 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff PUSH2 0x0100 SHR"), invoke, constantinopleConfig); String expected = "0000000000000000000000000000000000000000000000000000000000000000"; vm.step(program); vm.step(program); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // SHR OP public void testSHR_11() { VM vm = new VM(); program = new Program(compile("PUSH32 0x0000000000000000000000000000000000000000000000000000000000000000 PUSH1 0x01 SHR"), invoke, constantinopleConfig); String expected = "0000000000000000000000000000000000000000000000000000000000000000"; vm.step(program); vm.step(program); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // SAR OP public void testSAR_1() { VM vm = new VM(); program = new Program(compile("PUSH32 0x0000000000000000000000000000000000000000000000000000000000000001 PUSH1 0x00 SAR"), invoke, constantinopleConfig); String expected = "0000000000000000000000000000000000000000000000000000000000000001"; vm.step(program); vm.step(program); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // SAR OP public void testSAR_2() { VM vm = new VM(); program = new Program(compile("PUSH32 0x0000000000000000000000000000000000000000000000000000000000000001 PUSH1 0x01 SAR"), invoke, constantinopleConfig); String expected = "0000000000000000000000000000000000000000000000000000000000000000"; vm.step(program); vm.step(program); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // SAR OP public void testSAR_3() { VM vm = new VM(); program = new Program(compile("PUSH32 0x8000000000000000000000000000000000000000000000000000000000000000 PUSH1 0x01 SAR"), invoke, constantinopleConfig); String expected = "C000000000000000000000000000000000000000000000000000000000000000"; vm.step(program); vm.step(program); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // SAR OP public void testSAR_4() { VM vm = new VM(); program = new Program(compile("PUSH32 0x8000000000000000000000000000000000000000000000000000000000000000 PUSH1 0xff SAR"), invoke, constantinopleConfig); String expected = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"; vm.step(program); vm.step(program); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // SAR OP public void testSAR_5() { VM vm = new VM(); program = new Program(compile("PUSH32 0x8000000000000000000000000000000000000000000000000000000000000000 PUSH2 0x0100 SAR"), invoke, constantinopleConfig); String expected = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"; vm.step(program); vm.step(program); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // SAR OP public void testSAR_6() { VM vm = new VM(); program = new Program(compile("PUSH32 0x8000000000000000000000000000000000000000000000000000000000000000 PUSH2 0x0101 SAR"), invoke, constantinopleConfig); String expected = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"; vm.step(program); vm.step(program); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // SAR OP public void testSAR_7() { VM vm = new VM(); program = new Program(compile("PUSH32 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff PUSH1 0x00 SAR"), invoke, constantinopleConfig); String expected = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"; vm.step(program); vm.step(program); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // SAR OP public void testSAR_8() { VM vm = new VM(); program = new Program(compile("PUSH32 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff PUSH1 0x01 SAR"), invoke, constantinopleConfig); String expected = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"; vm.step(program); vm.step(program); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // SAR OP public void testSAR_9() { VM vm = new VM(); program = new Program(compile("PUSH32 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff PUSH1 0xff SAR"), invoke, constantinopleConfig); String expected = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"; vm.step(program); vm.step(program); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // SAR OP public void testSAR_10() { VM vm = new VM(); program = new Program(compile("PUSH32 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff PUSH2 0x0100 SAR"), invoke, constantinopleConfig); String expected = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"; vm.step(program); vm.step(program); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // SAR OP public void testSAR_11() { VM vm = new VM(); program = new Program(compile("PUSH32 0x0000000000000000000000000000000000000000000000000000000000000000 PUSH1 0x01 SAR"), invoke, constantinopleConfig); String expected = "0000000000000000000000000000000000000000000000000000000000000000"; vm.step(program); vm.step(program); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // SAR OP public void testSAR_12() { VM vm = new VM(); program = new Program(compile("PUSH32 0x4000000000000000000000000000000000000000000000000000000000000000 PUSH1 0xfe SAR"), invoke, constantinopleConfig); String expected = "0000000000000000000000000000000000000000000000000000000000000001"; vm.step(program); vm.step(program); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // SAR OP public void testSAR_13() { VM vm = new VM(); program = new Program(compile("PUSH32 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff PUSH1 0xf8 SAR"), invoke, constantinopleConfig); String expected = "000000000000000000000000000000000000000000000000000000000000007F"; vm.step(program); vm.step(program); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // SAR OP public void testSAR_14() { VM vm = new VM(); program = new Program(compile("PUSH32 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff PUSH1 0xfe SAR"), invoke, constantinopleConfig); String expected = "0000000000000000000000000000000000000000000000000000000000000001"; vm.step(program); vm.step(program); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // SAR OP public void testSAR_15() { VM vm = new VM(); program = new Program(compile("PUSH32 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff PUSH1 0xff SAR"), invoke, constantinopleConfig); String expected = "0000000000000000000000000000000000000000000000000000000000000000"; vm.step(program); vm.step(program); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // SAR OP public void testSAR_16() { VM vm = new VM(); program = new Program(compile("PUSH32 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff PUSH2 0x0100 SAR"), invoke, constantinopleConfig); String expected = "0000000000000000000000000000000000000000000000000000000000000000"; vm.step(program); vm.step(program); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // ISZERO OP public void testISZERO_1() { VM vm = new VM(); program = new Program(compile("PUSH1 0x00 ISZERO"), invoke); String expected = "0000000000000000000000000000000000000000000000000000000000000001"; vm.step(program); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // ISZERO OP public void testISZERO_2() { VM vm = new VM(); program = new Program(compile("PUSH1 0x2A ISZERO"), invoke); String expected = "0000000000000000000000000000000000000000000000000000000000000000"; vm.step(program); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test(expected = Program.StackTooSmallException.class) // ISZERO OP mal data public void testISZERO_3() { VM vm = new VM(); program = new Program(compile("ISZERO"), invoke); try { vm.step(program); vm.step(program); vm.step(program); } finally { assertTrue(program.isStopped()); } } @Test // EQ OP public void testEQ_1() { VM vm = new VM(); program = new Program(compile("PUSH1 0x2A PUSH1 0x2A EQ"), invoke); String expected = "0000000000000000000000000000000000000000000000000000000000000001"; vm.step(program); vm.step(program); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // EQ OP public void testEQ_2() { VM vm = new VM(); program = new Program(compile("PUSH3 0x2A3B4C PUSH3 0x2A3B4C EQ"), invoke); String expected = "0000000000000000000000000000000000000000000000000000000000000001"; vm.step(program); vm.step(program); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // EQ OP public void testEQ_3() { VM vm = new VM(); program = new Program(compile("PUSH3 0x2A3B5C PUSH3 0x2A3B4C EQ"), invoke); String expected = "0000000000000000000000000000000000000000000000000000000000000000"; vm.step(program); vm.step(program); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test(expected = Program.StackTooSmallException.class) // EQ OP mal data public void testEQ_4() { VM vm = new VM(); program = new Program(compile("PUSH3 0x2A3B4C EQ"), invoke); try { vm.step(program); vm.step(program); vm.step(program); } finally { assertTrue(program.isStopped()); } } @Test // GT OP public void testGT_1() { VM vm = new VM(); program = new Program(compile("PUSH1 0x01 PUSH1 0x02 GT"), invoke); String expected = "0000000000000000000000000000000000000000000000000000000000000001"; vm.step(program); vm.step(program); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // GT OP public void testGT_2() { VM vm = new VM(); program = new Program(compile("PUSH1 0x01 PUSH2 0x0F00 GT"), invoke); String expected = "0000000000000000000000000000000000000000000000000000000000000001"; vm.step(program); vm.step(program); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // GT OP public void testGT_3() { VM vm = new VM(); program = new Program(compile("PUSH4 0x01020304 PUSH2 0x0F00 GT"), invoke); String expected = "0000000000000000000000000000000000000000000000000000000000000000"; vm.step(program); vm.step(program); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test(expected = Program.StackTooSmallException.class) // GT OP mal data public void testGT_4() { VM vm = new VM(); program = new Program(compile("PUSH3 0x2A3B4C GT"), invoke); try { vm.step(program); vm.step(program); vm.step(program); } finally { assertTrue(program.isStopped()); } } @Test // SGT OP public void testSGT_1() { VM vm = new VM(); program = new Program(compile("PUSH1 0x01 PUSH1 0x02 SGT"), invoke); String expected = "0000000000000000000000000000000000000000000000000000000000000001"; vm.step(program); vm.step(program); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // SGT OP public void testSGT_2() { VM vm = new VM(); program = new Program(compile("PUSH32 0x000000000000000000000000000000000000000000000000000000000000001E " + // 30 "PUSH32 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF56 " + // -170 "SGT"), invoke); String expected = "0000000000000000000000000000000000000000000000000000000000000000"; vm.step(program); vm.step(program); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // SGT OP public void testSGT_3() { VM vm = new VM(); program = new Program(compile("PUSH32 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF56 " + // -170 "PUSH32 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF57 " + // -169 "SGT"), invoke); String expected = "0000000000000000000000000000000000000000000000000000000000000001"; vm.step(program); vm.step(program); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test(expected = Program.StackTooSmallException.class) // SGT OP mal public void testSGT_4() { VM vm = new VM(); program = new Program(compile("PUSH32 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF56 " + // -170 "SGT"), invoke); try { vm.step(program); vm.step(program); vm.step(program); } finally { assertTrue(program.isStopped()); } } @Test // LT OP public void testLT_1() { VM vm = new VM(); program = new Program(compile("PUSH1 0x01 PUSH1 0x02 LT"), invoke); String expected = "0000000000000000000000000000000000000000000000000000000000000000"; vm.step(program); vm.step(program); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // LT OP public void testLT_2() { VM vm = new VM(); program = new Program(compile("PUSH1 0x01 PUSH2 0x0F00 LT"), invoke); String expected = "0000000000000000000000000000000000000000000000000000000000000000"; vm.step(program); vm.step(program); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // LT OP public void testLT_3() { VM vm = new VM(); program = new Program(compile("PUSH4 0x01020304 PUSH2 0x0F00 LT"), invoke); String expected = "0000000000000000000000000000000000000000000000000000000000000001"; vm.step(program); vm.step(program); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test(expected = Program.StackTooSmallException.class) // LT OP mal data public void testLT_4() { VM vm = new VM(); program = new Program(compile("PUSH3 0x2A3B4C LT"), invoke); try { vm.step(program); vm.step(program); vm.step(program); } finally { assertTrue(program.isStopped()); } } @Test // SLT OP public void testSLT_1() { VM vm = new VM(); program = new Program(compile("PUSH1 0x01 PUSH1 0x02 SLT"), invoke); String expected = "0000000000000000000000000000000000000000000000000000000000000000"; vm.step(program); vm.step(program); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // SLT OP public void testSLT_2() { VM vm = new VM(); program = new Program(compile("PUSH32 0x000000000000000000000000000000000000000000000000000000000000001E " + // 30 "PUSH32 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF56 " + // -170 "SLT"), invoke); String expected = "0000000000000000000000000000000000000000000000000000000000000001"; vm.step(program); vm.step(program); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // SLT OP public void testSLT_3() { VM vm = new VM(); program = new Program(compile("PUSH32 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF56 " + // -170 "PUSH32 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF57 " + // -169 "SLT"), invoke); String expected = "0000000000000000000000000000000000000000000000000000000000000000"; vm.step(program); vm.step(program); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test(expected = Program.StackTooSmallException.class) // SLT OP mal public void testSLT_4() { VM vm = new VM(); program = new Program(compile("PUSH32 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF56 " + // -170 "SLT"), invoke); try { vm.step(program); vm.step(program); vm.step(program); } finally { assertTrue(program.isStopped()); } } @Test // NOT OP public void testNOT_1() { VM vm = new VM(); program = new Program(compile("PUSH1 0x01 NOT"), invoke); String expected = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE"; vm.step(program); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test // NOT OP public void testNOT_2() { VM vm = new VM(); program = new Program(compile("PUSH2 0xA003 NOT"), invoke); String expected = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5FFC"; vm.step(program); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } @Test(expected = Program.StackTooSmallException.class) // BNOT OP public void testBNOT_4() { VM vm = new VM(); program = new Program(compile("NOT"), invoke); try { vm.step(program); vm.step(program); } finally { assertTrue(program.isStopped()); } } @Test // NOT OP test from real failure public void testNOT_5() { VM vm = new VM(); program = new Program(compile("PUSH1 0x00 NOT"), invoke); String expected = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"; vm.step(program); vm.step(program); assertEquals(expected, Hex.toHexString(program.getStack().peek().getData()).toUpperCase()); } }
38,937
33.15614
163
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/vm/PrecompiledContractTest.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.vm; import org.ethereum.config.BlockchainConfig; import org.ethereum.config.SystemProperties; import org.ethereum.config.blockchain.ByzantiumConfig; import org.ethereum.config.blockchain.DaoHFConfig; import org.ethereum.config.blockchain.Eip160HFConfig; import org.ethereum.config.blockchain.HomesteadConfig; import org.ethereum.util.ByteUtil; import org.ethereum.vm.PrecompiledContracts.PrecompiledContract; import org.junit.Test; import org.spongycastle.util.encoders.Hex; import java.math.BigInteger; import static org.ethereum.util.ByteUtil.EMPTY_BYTE_ARRAY; import static org.ethereum.util.ByteUtil.bytesToBigInteger; import static org.junit.Assert.*; /** * @author Roman Mandeleil */ public class PrecompiledContractTest { BlockchainConfig eip160Config = new Eip160HFConfig(new DaoHFConfig(new HomesteadConfig(), 0)); BlockchainConfig byzantiumConfig = new ByzantiumConfig(new DaoHFConfig(new HomesteadConfig(), 0)); @Test public void identityTest1() { DataWord addr = DataWord.of("0000000000000000000000000000000000000000000000000000000000000004"); PrecompiledContract contract = PrecompiledContracts.getContractForAddress(addr, eip160Config); byte[] data = Hex.decode("112233445566"); byte[] expected = Hex.decode("112233445566"); byte[] result = contract.execute(data).getRight(); assertArrayEquals(expected, result); } @Test public void sha256Test1() { DataWord addr = DataWord.of("0000000000000000000000000000000000000000000000000000000000000002"); PrecompiledContract contract = PrecompiledContracts.getContractForAddress(addr, eip160Config); byte[] data = null; String expected = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"; byte[] result = contract.execute(data).getRight(); assertEquals(expected, Hex.toHexString(result)); } @Test public void sha256Test2() { DataWord addr = DataWord.of("0000000000000000000000000000000000000000000000000000000000000002"); PrecompiledContract contract = PrecompiledContracts.getContractForAddress(addr, eip160Config); byte[] data = ByteUtil.EMPTY_BYTE_ARRAY; String expected = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"; byte[] result = contract.execute(data).getRight(); assertEquals(expected, Hex.toHexString(result)); } @Test public void sha256Test3() { DataWord addr = DataWord.of("0000000000000000000000000000000000000000000000000000000000000002"); PrecompiledContract contract = PrecompiledContracts.getContractForAddress(addr, eip160Config); byte[] data = Hex.decode("112233"); String expected = "49ee2bf93aac3b1fb4117e59095e07abe555c3383b38d608da37680a406096e8"; byte[] result = contract.execute(data).getRight(); assertEquals(expected, Hex.toHexString(result)); } @Test public void Ripempd160Test1() { DataWord addr = DataWord.of("0000000000000000000000000000000000000000000000000000000000000003"); PrecompiledContract contract = PrecompiledContracts.getContractForAddress(addr, eip160Config); byte[] data = Hex.decode("0000000000000000000000000000000000000000000000000000000000000001"); String expected = "000000000000000000000000ae387fcfeb723c3f5964509af111cf5a67f30661"; byte[] result = contract.execute(data).getRight(); assertEquals(expected, Hex.toHexString(result)); } @Test public void ecRecoverTest1() { byte[] data = Hex.decode("18c547e4f7b0f325ad1e56f57e26c745b09a3e503d86e00e5255ff7f715d3d1c000000000000000000000000000000000000000000000000000000000000001c73b1693892219d736caba55bdb67216e485557ea6b6af75f37096c9aa6a5a75feeb940b1d03b21e36b0e47e79769f095fe2ab855bd91e3a38756b7d75a9c4549"); DataWord addr = DataWord.of("0000000000000000000000000000000000000000000000000000000000000001"); PrecompiledContract contract = PrecompiledContracts.getContractForAddress(addr, eip160Config); String expected = "000000000000000000000000ae387fcfeb723c3f5964509af111cf5a67f30661"; byte[] result = contract.execute(data).getRight(); System.out.println(Hex.toHexString(result)); } @Test public void modExpTest() { DataWord addr = DataWord.of("0000000000000000000000000000000000000000000000000000000000000005"); PrecompiledContract contract = PrecompiledContracts.getContractForAddress(addr, eip160Config); assertNull(contract); contract = PrecompiledContracts.getContractForAddress(addr, byzantiumConfig); assertNotNull(contract); byte[] data1 = Hex.decode( "0000000000000000000000000000000000000000000000000000000000000001" + "0000000000000000000000000000000000000000000000000000000000000020" + "0000000000000000000000000000000000000000000000000000000000000020" + "03" + "fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2e" + "fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"); assertEquals(13056, contract.getGasForData(data1)); byte[] res1 = contract.execute(data1).getRight(); assertEquals(32, res1.length); assertEquals(BigInteger.ONE, bytesToBigInteger(res1)); byte[] data2 = Hex.decode( "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000020" + "0000000000000000000000000000000000000000000000000000000000000020" + "fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2e" + "fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"); assertEquals(13056, contract.getGasForData(data2)); byte[] res2 = contract.execute(data2).getRight(); assertEquals(32, res2.length); assertEquals(BigInteger.ZERO, bytesToBigInteger(res2)); byte[] data3 = Hex.decode( "0000000000000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000020" + "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" + "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe" + "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd"); // hardly imagine this value could be a real one assertEquals(3_674_950_435_109_146_392L, contract.getGasForData(data3)); byte[] data4 = Hex.decode( "0000000000000000000000000000000000000000000000000000000000000001" + "0000000000000000000000000000000000000000000000000000000000000002" + "0000000000000000000000000000000000000000000000000000000000000020" + "03" + "ffff" + "8000000000000000000000000000000000000000000000000000000000000000" + "07"); // "07" should be ignored by data parser assertEquals(768, contract.getGasForData(data4)); byte[] res4 = contract.execute(data4).getRight(); assertEquals(32, res4.length); assertEquals(new BigInteger("26689440342447178617115869845918039756797228267049433585260346420242739014315"), bytesToBigInteger(res4)); byte[] data5 = Hex.decode( "0000000000000000000000000000000000000000000000000000000000000001" + "0000000000000000000000000000000000000000000000000000000000000002" + "0000000000000000000000000000000000000000000000000000000000000020" + "03" + "ffff" + "80"); // "80" should be parsed as "8000000000000000000000000000000000000000000000000000000000000000" // cause call data is infinitely right-padded with zero bytes assertEquals(768, contract.getGasForData(data5)); byte[] res5 = contract.execute(data5).getRight(); assertEquals(32, res5.length); assertEquals(new BigInteger("26689440342447178617115869845918039756797228267049433585260346420242739014315"), bytesToBigInteger(res5)); // check overflow handling in gas calculation byte[] data6 = Hex.decode( "0000000000000000000000000000000000000000000000000000000000000020" + "0000000000000000000000000000000020000000000000000000000000000000" + "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" + "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe" + "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd" + "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd"); assertEquals(Long.MAX_VALUE, contract.getGasForData(data6)); // check rubbish data byte[] data7 = Hex.decode( "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" + "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" + "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" + "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe" + "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd" + "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd"); assertEquals(Long.MAX_VALUE, contract.getGasForData(data7)); // check empty data byte[] data8 = new byte[0]; assertEquals(0, contract.getGasForData(data8)); byte[] res8 = contract.execute(data8).getRight(); assertArrayEquals(EMPTY_BYTE_ARRAY, res8); assertEquals(0, contract.getGasForData(null)); assertArrayEquals(EMPTY_BYTE_ARRAY, contract.execute(null).getRight()); // nagydani-1-square byte[] data9 = Hex.decode("000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000040e09ad9675465c53a109fac66a445c91b292d2bb2c5268addb30cd82f80fcb0033ff97c80a5fc6f39193ae969c6ede6710a6b7ac27078a06d90ef1c72e5c85fb502fc9e1f6beb81516545975218075ec2af118cd8798df6e08a147c60fd6095ac2bb02c2908cf4dd7c81f11c289e4bce98f3553768f392a80ce22bf5c4f4a248c6b"); byte[] res9 = contract.execute(data9).getRight(); assertArrayEquals(Hex.decode("60008f1614cc01dcfb6bfb09c625cf90b47d4468db81b5f8b7a39d42f332eab9b2da8f2d95311648a8f243f4bb13cfb3d8f7f2a3c014122ebb3ed41b02783adc"), res9); // nagydani-1-qube byte[] data10 = Hex.decode("000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000040e09ad9675465c53a109fac66a445c91b292d2bb2c5268addb30cd82f80fcb0033ff97c80a5fc6f39193ae969c6ede6710a6b7ac27078a06d90ef1c72e5c85fb503fc9e1f6beb81516545975218075ec2af118cd8798df6e08a147c60fd6095ac2bb02c2908cf4dd7c81f11c289e4bce98f3553768f392a80ce22bf5c4f4a248c6b"); byte[] res10 = contract.execute(data10).getRight(); assertArrayEquals(Hex.decode("4834a46ba565db27903b1c720c9d593e84e4cbd6ad2e64b31885d944f68cd801f92225a8961c952ddf2797fa4701b330c85c4b363798100b921a1a22a46a7fec"), res10); // nagydani-1-pow0x10001 byte[] data11 = Hex.decode("000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000040e09ad9675465c53a109fac66a445c91b292d2bb2c5268addb30cd82f80fcb0033ff97c80a5fc6f39193ae969c6ede6710a6b7ac27078a06d90ef1c72e5c85fb5010001fc9e1f6beb81516545975218075ec2af118cd8798df6e08a147c60fd6095ac2bb02c2908cf4dd7c81f11c289e4bce98f3553768f392a80ce22bf5c4f4a248c6b"); byte[] res11 = contract.execute(data11).getRight(); assertArrayEquals(Hex.decode("c36d804180c35d4426b57b50c5bfcca5c01856d104564cd513b461d3c8b8409128a5573e416d0ebe38f5f736766d9dc27143e4da981dfa4d67f7dc474cbee6d2"), res11); // nagydani-2-square byte[] data12 = Hex.decode("000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000080cad7d991a00047dd54d3399b6b0b937c718abddef7917c75b6681f40cc15e2be0003657d8d4c34167b2f0bbbca0ccaa407c2a6a07d50f1517a8f22979ce12a81dcaf707cc0cebfc0ce2ee84ee7f77c38b9281b9822a8d3de62784c089c9b18dcb9a2a5eecbede90ea788a862a9ddd9d609c2c52972d63e289e28f6a590ffbf5102e6d893b80aeed5e6e9ce9afa8a5d5675c93a32ac05554cb20e9951b2c140e3ef4e433068cf0fb73bc9f33af1853f64aa27a0028cbf570d7ac9048eae5dc7b28c87c31e5810f1e7fa2cda6adf9f1076dbc1ec1238560071e7efc4e9565c49be9e7656951985860a558a754594115830bcdb421f741408346dd5997bb01c287087"); byte[] res12 = contract.execute(data12).getRight(); assertArrayEquals(Hex.decode("981dd99c3b113fae3e3eaa9435c0dc96779a23c12a53d1084b4f67b0b053a27560f627b873e3f16ad78f28c94f14b6392def26e4d8896c5e3c984e50fa0b3aa44f1da78b913187c6128baa9340b1e9c9a0fd02cb78885e72576da4a8f7e5a113e173a7a2889fde9d407bd9f06eb05bc8fc7b4229377a32941a02bf4edcc06d70"), res12); // nagydani-2-qube byte[] data13 = Hex.decode("000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000080cad7d991a00047dd54d3399b6b0b937c718abddef7917c75b6681f40cc15e2be0003657d8d4c34167b2f0bbbca0ccaa407c2a6a07d50f1517a8f22979ce12a81dcaf707cc0cebfc0ce2ee84ee7f77c38b9281b9822a8d3de62784c089c9b18dcb9a2a5eecbede90ea788a862a9ddd9d609c2c52972d63e289e28f6a590ffbf5103e6d893b80aeed5e6e9ce9afa8a5d5675c93a32ac05554cb20e9951b2c140e3ef4e433068cf0fb73bc9f33af1853f64aa27a0028cbf570d7ac9048eae5dc7b28c87c31e5810f1e7fa2cda6adf9f1076dbc1ec1238560071e7efc4e9565c49be9e7656951985860a558a754594115830bcdb421f741408346dd5997bb01c287087"); byte[] res13 = contract.execute(data13).getRight(); assertArrayEquals(Hex.decode("d89ceb68c32da4f6364978d62aaa40d7b09b59ec61eb3c0159c87ec3a91037f7dc6967594e530a69d049b64adfa39c8fa208ea970cfe4b7bcd359d345744405afe1cbf761647e32b3184c7fbe87cee8c6c7ff3b378faba6c68b83b6889cb40f1603ee68c56b4c03d48c595c826c041112dc941878f8c5be828154afd4a16311f"), res13); // nagydani-2-pow0x10001 byte[] data14 = Hex.decode("000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000080cad7d991a00047dd54d3399b6b0b937c718abddef7917c75b6681f40cc15e2be0003657d8d4c34167b2f0bbbca0ccaa407c2a6a07d50f1517a8f22979ce12a81dcaf707cc0cebfc0ce2ee84ee7f77c38b9281b9822a8d3de62784c089c9b18dcb9a2a5eecbede90ea788a862a9ddd9d609c2c52972d63e289e28f6a590ffbf51010001e6d893b80aeed5e6e9ce9afa8a5d5675c93a32ac05554cb20e9951b2c140e3ef4e433068cf0fb73bc9f33af1853f64aa27a0028cbf570d7ac9048eae5dc7b28c87c31e5810f1e7fa2cda6adf9f1076dbc1ec1238560071e7efc4e9565c49be9e7656951985860a558a754594115830bcdb421f741408346dd5997bb01c287087"); byte[] res14 = contract.execute(data14).getRight(); assertArrayEquals(Hex.decode("ad85e8ef13fd1dd46eae44af8b91ad1ccae5b7a1c92944f92a19f21b0b658139e0cabe9c1f679507c2de354bf2c91ebd965d1e633978a830d517d2f6f8dd5fd58065d58559de7e2334a878f8ec6992d9b9e77430d4764e863d77c0f87beede8f2f7f2ab2e7222f85cc9d98b8467f4bb72e87ef2882423ebdb6daf02dddac6db2"), res14); // nagydani-3-square byte[] data15 = Hex.decode("000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000100c9130579f243e12451760976261416413742bd7c91d39ae087f46794062b8c239f2a74abf3918605a0e046a7890e049475ba7fbb78f5de6490bd22a710cc04d30088179a919d86c2da62cf37f59d8f258d2310d94c24891be2d7eeafaa32a8cb4b0cfe5f475ed778f45907dc8916a73f03635f233f7a77a00a3ec9ca6761a5bbd558a2318ecd0caa1c5016691523e7e1fa267dd35e70c66e84380bdcf7c0582f540174e572c41f81e93da0b757dff0b0fe23eb03aa19af0bdec3afb474216febaacb8d0381e631802683182b0fe72c28392539850650b70509f54980241dc175191a35d967288b532a7a8223ce2440d010615f70df269501944d4ec16fe4a3cb02d7a85909174757835187cb52e71934e6c07ef43b4c46fc30bbcd0bc72913068267c54a4aabebb493922492820babdeb7dc9b1558fcf7bd82c37c82d3147e455b623ab0efa752fe0b3a67ca6e4d126639e645a0bf417568adbb2a6a4eef62fa1fa29b2a5a43bebea1f82193a7dd98eb483d09bb595af1fa9c97c7f41f5649d976aee3e5e59e2329b43b13bea228d4a93f16ba139ccb511de521ffe747aa2eca664f7c9e33da59075cc335afcd2bf3ae09765f01ab5a7c3e3938ec168b74724b5074247d200d9970382f683d6059b94dbc336603d1dfee714e4b447ac2fa1d99ecb4961da2854e03795ed758220312d101e1e3d87d5313a6d052aebde75110363d"); byte[] res15 = contract.execute(data15).getRight(); assertArrayEquals(Hex.decode("affc7507ea6d84751ec6b3f0d7b99dbcc263f33330e450d1b3ff0bc3d0874320bf4edd57debd587306988157958cb3cfd369cc0c9c198706f635c9e0f15d047df5cb44d03e2727f26b083c4ad8485080e1293f171c1ed52aef5993a5815c35108e848c951cf1e334490b4a539a139e57b68f44fee583306f5b85ffa57206b3ee5660458858534e5386b9584af3c7f67806e84c189d695e5eb96e1272d06ec2df5dc5fabc6e94b793718c60c36be0a4d031fc84cd658aa72294b2e16fc240aef70cb9e591248e38bd49c5a554d1afa01f38dab72733092f7555334bbef6c8c430119840492380aa95fa025dcf699f0a39669d812b0c6946b6091e6e235337b6f8"), res15); // nagydani-3-qube byte[] data16 = Hex.decode("000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000100c9130579f243e12451760976261416413742bd7c91d39ae087f46794062b8c239f2a74abf3918605a0e046a7890e049475ba7fbb78f5de6490bd22a710cc04d30088179a919d86c2da62cf37f59d8f258d2310d94c24891be2d7eeafaa32a8cb4b0cfe5f475ed778f45907dc8916a73f03635f233f7a77a00a3ec9ca6761a5bbd558a2318ecd0caa1c5016691523e7e1fa267dd35e70c66e84380bdcf7c0582f540174e572c41f81e93da0b757dff0b0fe23eb03aa19af0bdec3afb474216febaacb8d0381e631802683182b0fe72c28392539850650b70509f54980241dc175191a35d967288b532a7a8223ce2440d010615f70df269501944d4ec16fe4a3cb03d7a85909174757835187cb52e71934e6c07ef43b4c46fc30bbcd0bc72913068267c54a4aabebb493922492820babdeb7dc9b1558fcf7bd82c37c82d3147e455b623ab0efa752fe0b3a67ca6e4d126639e645a0bf417568adbb2a6a4eef62fa1fa29b2a5a43bebea1f82193a7dd98eb483d09bb595af1fa9c97c7f41f5649d976aee3e5e59e2329b43b13bea228d4a93f16ba139ccb511de521ffe747aa2eca664f7c9e33da59075cc335afcd2bf3ae09765f01ab5a7c3e3938ec168b74724b5074247d200d9970382f683d6059b94dbc336603d1dfee714e4b447ac2fa1d99ecb4961da2854e03795ed758220312d101e1e3d87d5313a6d052aebde75110363d"); byte[] res16 = contract.execute(data16).getRight(); assertArrayEquals(Hex.decode("1b280ecd6a6bf906b806d527c2a831e23b238f89da48449003a88ac3ac7150d6a5e9e6b3be4054c7da11dd1e470ec29a606f5115801b5bf53bc1900271d7c3ff3cd5ed790d1c219a9800437a689f2388ba1a11d68f6a8e5b74e9a3b1fac6ee85fc6afbac599f93c391f5dc82a759e3c6c0ab45ce3f5d25d9b0c1bf94cf701ea6466fc9a478dacc5754e593172b5111eeba88557048bceae401337cd4c1182ad9f700852bc8c99933a193f0b94cf1aedbefc48be3bc93ef5cb276d7c2d5462ac8bb0c8fe8923a1db2afe1c6b90d59c534994a6a633f0ead1d638fdc293486bb634ff2c8ec9e7297c04241a61c37e3ae95b11d53343d4ba2b4cc33d2cfa7eb705e"), res16); // nagydani-3-pow0x10001 byte[] data17 = Hex.decode("000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000100c9130579f243e12451760976261416413742bd7c91d39ae087f46794062b8c239f2a74abf3918605a0e046a7890e049475ba7fbb78f5de6490bd22a710cc04d30088179a919d86c2da62cf37f59d8f258d2310d94c24891be2d7eeafaa32a8cb4b0cfe5f475ed778f45907dc8916a73f03635f233f7a77a00a3ec9ca6761a5bbd558a2318ecd0caa1c5016691523e7e1fa267dd35e70c66e84380bdcf7c0582f540174e572c41f81e93da0b757dff0b0fe23eb03aa19af0bdec3afb474216febaacb8d0381e631802683182b0fe72c28392539850650b70509f54980241dc175191a35d967288b532a7a8223ce2440d010615f70df269501944d4ec16fe4a3cb010001d7a85909174757835187cb52e71934e6c07ef43b4c46fc30bbcd0bc72913068267c54a4aabebb493922492820babdeb7dc9b1558fcf7bd82c37c82d3147e455b623ab0efa752fe0b3a67ca6e4d126639e645a0bf417568adbb2a6a4eef62fa1fa29b2a5a43bebea1f82193a7dd98eb483d09bb595af1fa9c97c7f41f5649d976aee3e5e59e2329b43b13bea228d4a93f16ba139ccb511de521ffe747aa2eca664f7c9e33da59075cc335afcd2bf3ae09765f01ab5a7c3e3938ec168b74724b5074247d200d9970382f683d6059b94dbc336603d1dfee714e4b447ac2fa1d99ecb4961da2854e03795ed758220312d101e1e3d87d5313a6d052aebde75110363d"); byte[] res17 = contract.execute(data17).getRight(); assertArrayEquals(Hex.decode("37843d7c67920b5f177372fa56e2a09117df585f81df8b300fba245b1175f488c99476019857198ed459ed8d9799c377330e49f4180c4bf8e8f66240c64f65ede93d601f957b95b83efdee1e1bfde74169ff77002eaf078c71815a9220c80b2e3b3ff22c2f358111d816ebf83c2999026b6de50bfc711ff68705d2f40b753424aefc9f70f08d908b5a20276ad613b4ab4309a3ea72f0c17ea9df6b3367d44fb3acab11c333909e02e81ea2ed404a712d3ea96bba87461720e2d98723e7acd0520ac1a5212dbedcd8dc0c1abf61d4719e319ff4758a774790b8d463cdfe131d1b2dcfee52d002694e98e720cb6ae7ccea353bc503269ba35f0f63bf8d7b672a76"), res17); // nagydani-4-square byte[] data18 = Hex.decode("000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000200db34d0e438249c0ed685c949cc28776a05094e1c48691dc3f2dca5fc3356d2a0663bd376e4712839917eb9a19c670407e2c377a2de385a3ff3b52104f7f1f4e0c7bf7717fb913896693dc5edbb65b760ef1b00e42e9d8f9af17352385e1cd742c9b006c0f669995cb0bb21d28c0aced2892267637b6470d8cee0ab27fc5d42658f6e88240c31d6774aa60a7ebd25cd48b56d0da11209f1928e61005c6eb709f3e8e0aaf8d9b10f7d7e296d772264dc76897ccdddadc91efa91c1903b7232a9e4c3b941917b99a3bc0c26497dedc897c25750af60237aa67934a26a2bc491db3dcc677491944bc1f51d3e5d76b8d846a62db03dedd61ff508f91a56d71028125035c3a44cbb041497c83bf3e4ae2a9613a401cc721c547a2afa3b16a2969933d3626ed6d8a7428648f74122fd3f2a02a20758f7f693892c8fd798b39abac01d18506c45e71432639e9f9505719ee822f62ccbf47f6850f096ff77b5afaf4be7d772025791717dbe5abf9b3f40cff7d7aab6f67e38f62faf510747276e20a42127e7500c444f9ed92baf65ade9e836845e39c4316d9dce5f8e2c8083e2c0acbb95296e05e51aab13b6b8f53f06c9c4276e12b0671133218cc3ea907da3bd9a367096d9202128d14846cc2e20d56fc8473ecb07cecbfb8086919f3971926e7045b853d85a69d026195c70f9f7a823536e2a8f4b3e12e94d9b53a934353451094b8102df3143a0057457d75e8c708b6337a6f5a4fd1a06727acf9fb93e2993c62f3378b37d56c85e7b1e00f0145ebf8e4095bd723166293c60b6ac1252291ef65823c9e040ddad14969b3b340a4ef714db093a587c37766d68b8d6b5016e741587e7e6bf7e763b44f0247e64bae30f994d248bfd20541a333e5b225ef6a61199e301738b1e688f70ec1d7fb892c183c95dc543c3e12adf8a5e8b9ca9d04f9445cced3ab256f29e998e69efaa633a7b60e1db5a867924ccab0a171d9d6e1098dfa15acde9553de599eaa56490c8f411e4985111f3d40bddfc5e301edb01547b01a886550a61158f7e2033c59707789bf7c854181d0c2e2a42a93cf09209747d7082e147eb8544de25c3eb14f2e35559ea0c0f5877f2f3fc92132c0ae9da4e45b2f6c866a224ea6d1f28c05320e287750fbc647368d41116e528014cc1852e5531d53e4af938374daba6cee4baa821ed07117253bb3601ddd00d59a3d7fb2ef1f5a2fbba7c429f0cf9a5b3462410fd833a69118f8be9c559b1000cc608fd877fb43f8e65c2d1302622b944462579056874b387208d90623fcdaf93920ca7a9e4ba64ea208758222ad868501cc2c345e2d3a5ea2a17e5069248138c8a79c0251185d29ee73e5afab5354769142d2bf0cb6712727aa6bf84a6245fcdae66e4938d84d1b9dd09a884818622080ff5f98942fb20acd7e0c916c2d5ea7ce6f7e173315384518f"); byte[] res18 = contract.execute(data18).getRight(); assertArrayEquals(Hex.decode("8a5aea5f50dcc03dc7a7a272b5aeebc040554dbc1ffe36753c4fc75f7ed5f6c2cc0de3a922bf96c78bf0643a73025ad21f45a4a5cadd717612c511ab2bff1190fe5f1ae05ba9f8fe3624de1de2a817da6072ddcdb933b50216811dbe6a9ca79d3a3c6b3a476b079fd0d05f04fb154e2dd3e5cb83b148a006f2bcbf0042efb2ae7b916ea81b27aac25c3bf9a8b6d35440062ad8eae34a83f3ffa2cc7b40346b62174a4422584f72f95316f6b2bee9ff232ba9739301c97c99a9ded26c45d72676eb856ad6ecc81d36a6de36d7f9dafafee11baa43a4b0d5e4ecffa7b9b7dcefd58c397dd373e6db4acd2b2c02717712e6289bed7c813b670c4a0c6735aa7f3b0f1ce556eae9fcc94b501b2c8781ba50a8c6220e8246371c3c7359fe4ef9da786ca7d98256754ca4e496be0a9174bedbecb384bdf470779186d6a833f068d2838a88d90ef3ad48ff963b67c39cc5a3ee123baf7bf3125f64e77af7f30e105d72c4b9b5b237ed251e4c122c6d8c1405e736299c3afd6db16a28c6a9cfa68241e53de4cd388271fe534a6a9b0dbea6171d170db1b89858468885d08fecbd54c8e471c3e25d48e97ba450b96d0d87e00ac732aaa0d3ce4309c1064bd8a4c0808a97e0143e43a24cfa847635125cd41c13e0574487963e9d725c01375db99c31da67b4cf65eff555f0c0ac416c727ff8d438ad7c42030551d68c2e7adda0abb1ca7c10"), res18); // nagydani-4-qube byte[] data19 = Hex.decode("000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000200db34d0e438249c0ed685c949cc28776a05094e1c48691dc3f2dca5fc3356d2a0663bd376e4712839917eb9a19c670407e2c377a2de385a3ff3b52104f7f1f4e0c7bf7717fb913896693dc5edbb65b760ef1b00e42e9d8f9af17352385e1cd742c9b006c0f669995cb0bb21d28c0aced2892267637b6470d8cee0ab27fc5d42658f6e88240c31d6774aa60a7ebd25cd48b56d0da11209f1928e61005c6eb709f3e8e0aaf8d9b10f7d7e296d772264dc76897ccdddadc91efa91c1903b7232a9e4c3b941917b99a3bc0c26497dedc897c25750af60237aa67934a26a2bc491db3dcc677491944bc1f51d3e5d76b8d846a62db03dedd61ff508f91a56d71028125035c3a44cbb041497c83bf3e4ae2a9613a401cc721c547a2afa3b16a2969933d3626ed6d8a7428648f74122fd3f2a02a20758f7f693892c8fd798b39abac01d18506c45e71432639e9f9505719ee822f62ccbf47f6850f096ff77b5afaf4be7d772025791717dbe5abf9b3f40cff7d7aab6f67e38f62faf510747276e20a42127e7500c444f9ed92baf65ade9e836845e39c4316d9dce5f8e2c8083e2c0acbb95296e05e51aab13b6b8f53f06c9c4276e12b0671133218cc3ea907da3bd9a367096d9202128d14846cc2e20d56fc8473ecb07cecbfb8086919f3971926e7045b853d85a69d026195c70f9f7a823536e2a8f4b3e12e94d9b53a934353451094b8103df3143a0057457d75e8c708b6337a6f5a4fd1a06727acf9fb93e2993c62f3378b37d56c85e7b1e00f0145ebf8e4095bd723166293c60b6ac1252291ef65823c9e040ddad14969b3b340a4ef714db093a587c37766d68b8d6b5016e741587e7e6bf7e763b44f0247e64bae30f994d248bfd20541a333e5b225ef6a61199e301738b1e688f70ec1d7fb892c183c95dc543c3e12adf8a5e8b9ca9d04f9445cced3ab256f29e998e69efaa633a7b60e1db5a867924ccab0a171d9d6e1098dfa15acde9553de599eaa56490c8f411e4985111f3d40bddfc5e301edb01547b01a886550a61158f7e2033c59707789bf7c854181d0c2e2a42a93cf09209747d7082e147eb8544de25c3eb14f2e35559ea0c0f5877f2f3fc92132c0ae9da4e45b2f6c866a224ea6d1f28c05320e287750fbc647368d41116e528014cc1852e5531d53e4af938374daba6cee4baa821ed07117253bb3601ddd00d59a3d7fb2ef1f5a2fbba7c429f0cf9a5b3462410fd833a69118f8be9c559b1000cc608fd877fb43f8e65c2d1302622b944462579056874b387208d90623fcdaf93920ca7a9e4ba64ea208758222ad868501cc2c345e2d3a5ea2a17e5069248138c8a79c0251185d29ee73e5afab5354769142d2bf0cb6712727aa6bf84a6245fcdae66e4938d84d1b9dd09a884818622080ff5f98942fb20acd7e0c916c2d5ea7ce6f7e173315384518f"); byte[] res19 = contract.execute(data19).getRight(); assertArrayEquals(Hex.decode("5a2664252aba2d6e19d9600da582cdd1f09d7a890ac48e6b8da15ae7c6ff1856fc67a841ac2314d283ffa3ca81a0ecf7c27d89ef91a5a893297928f5da0245c99645676b481b7e20a566ee6a4f2481942bee191deec5544600bb2441fd0fb19e2ee7d801ad8911c6b7750affec367a4b29a22942c0f5f4744a4e77a8b654da2a82571037099e9c6d930794efe5cdca73c7b6c0844e386bdca8ea01b3d7807146bb81365e2cdc6475f8c23e0ff84463126189dc9789f72bbce2e3d2d114d728a272f1345122de23df54c922ec7a16e5c2a8f84da8871482bd258c20a7c09bbcd64c7a96a51029bbfe848736a6ba7bf9d931a9b7de0bcaf3635034d4958b20ae9ab3a95a147b0421dd5f7ebff46c971010ebfc4adbbe0ad94d5498c853e7142c450d8c71de4b2f84edbf8acd2e16d00c8115b150b1c30e553dbb82635e781379fe2a56360420ff7e9f70cc64c00aba7e26ed13c7c19622865ae07248daced36416080f35f8cc157a857ed70ea4f347f17d1bee80fa038abd6e39b1ba06b97264388b21364f7c56e192d4b62d9b161405f32ab1e2594e86243e56fcf2cb30d21adef15b9940f91af681da24328c883d892670c6aa47940867a81830a82b82716895db810df1b834640abefb7db2092dd92912cb9a735175bc447be40a503cf22dfe565b4ed7a3293ca0dfd63a507430b323ee248ec82e843b673c97ad730728cebc"), res19); // nagydani-4-pow0x10001 byte[] data20 = Hex.decode("000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000200db34d0e438249c0ed685c949cc28776a05094e1c48691dc3f2dca5fc3356d2a0663bd376e4712839917eb9a19c670407e2c377a2de385a3ff3b52104f7f1f4e0c7bf7717fb913896693dc5edbb65b760ef1b00e42e9d8f9af17352385e1cd742c9b006c0f669995cb0bb21d28c0aced2892267637b6470d8cee0ab27fc5d42658f6e88240c31d6774aa60a7ebd25cd48b56d0da11209f1928e61005c6eb709f3e8e0aaf8d9b10f7d7e296d772264dc76897ccdddadc91efa91c1903b7232a9e4c3b941917b99a3bc0c26497dedc897c25750af60237aa67934a26a2bc491db3dcc677491944bc1f51d3e5d76b8d846a62db03dedd61ff508f91a56d71028125035c3a44cbb041497c83bf3e4ae2a9613a401cc721c547a2afa3b16a2969933d3626ed6d8a7428648f74122fd3f2a02a20758f7f693892c8fd798b39abac01d18506c45e71432639e9f9505719ee822f62ccbf47f6850f096ff77b5afaf4be7d772025791717dbe5abf9b3f40cff7d7aab6f67e38f62faf510747276e20a42127e7500c444f9ed92baf65ade9e836845e39c4316d9dce5f8e2c8083e2c0acbb95296e05e51aab13b6b8f53f06c9c4276e12b0671133218cc3ea907da3bd9a367096d9202128d14846cc2e20d56fc8473ecb07cecbfb8086919f3971926e7045b853d85a69d026195c70f9f7a823536e2a8f4b3e12e94d9b53a934353451094b81010001df3143a0057457d75e8c708b6337a6f5a4fd1a06727acf9fb93e2993c62f3378b37d56c85e7b1e00f0145ebf8e4095bd723166293c60b6ac1252291ef65823c9e040ddad14969b3b340a4ef714db093a587c37766d68b8d6b5016e741587e7e6bf7e763b44f0247e64bae30f994d248bfd20541a333e5b225ef6a61199e301738b1e688f70ec1d7fb892c183c95dc543c3e12adf8a5e8b9ca9d04f9445cced3ab256f29e998e69efaa633a7b60e1db5a867924ccab0a171d9d6e1098dfa15acde9553de599eaa56490c8f411e4985111f3d40bddfc5e301edb01547b01a886550a61158f7e2033c59707789bf7c854181d0c2e2a42a93cf09209747d7082e147eb8544de25c3eb14f2e35559ea0c0f5877f2f3fc92132c0ae9da4e45b2f6c866a224ea6d1f28c05320e287750fbc647368d41116e528014cc1852e5531d53e4af938374daba6cee4baa821ed07117253bb3601ddd00d59a3d7fb2ef1f5a2fbba7c429f0cf9a5b3462410fd833a69118f8be9c559b1000cc608fd877fb43f8e65c2d1302622b944462579056874b387208d90623fcdaf93920ca7a9e4ba64ea208758222ad868501cc2c345e2d3a5ea2a17e5069248138c8a79c0251185d29ee73e5afab5354769142d2bf0cb6712727aa6bf84a6245fcdae66e4938d84d1b9dd09a884818622080ff5f98942fb20acd7e0c916c2d5ea7ce6f7e173315384518f"); byte[] res20 = contract.execute(data20).getRight(); assertArrayEquals(Hex.decode("bed8b970c4a34849fc6926b08e40e20b21c15ed68d18f228904878d4370b56322d0da5789da0318768a374758e6375bfe4641fca5285ec7171828922160f48f5ca7efbfee4d5148612c38ad683ae4e3c3a053d2b7c098cf2b34f2cb19146eadd53c86b2d7ccf3d83b2c370bfb840913ee3879b1057a6b4e07e110b6bcd5e958bc71a14798c91d518cc70abee264b0d25a4110962a764b364ac0b0dd1ee8abc8426d775ec0f22b7e47b32576afaf1b5a48f64573ed1c5c29f50ab412188d9685307323d990802b81dacc06c6e05a1e901830ba9fcc67688dc29c5e27bde0a6e845ca925f5454b6fb3747edfaa2a5820838fb759eadf57f7cb5cec57fc213ddd8a4298fa079c3c0f472b07fb15aa6a7f0a3780bd296ff6a62e58ef443870b02260bd4fd2bbc98255674b8e1f1f9f8d33c7170b0ebbea4523b695911abbf26e41885344823bd0587115fdd83b721a4e8457a31c9a84b3d3520a07e0e35df7f48e5a9d534d0ec7feef1ff74de6a11e7f93eab95175b6ce22c68d78a642ad642837897ec11349205d8593ac19300207572c38d29ca5dfa03bc14cdbc32153c80e5cc3e739403d34c75915e49beb43094cc6dcafb3665b305ddec9286934ae66ec6b777ca528728c851318eb0f207b39f1caaf96db6eeead6b55ed08f451939314577d42bcc9f97c0b52d0234f88fd07e4c1d7780fdebc025cfffcb572cb27a8c33963"), res20); // nagydani-5-square byte[] data21 = Hex.decode("000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000400c5a1611f8be90071a43db23cc2fe01871cc4c0e8ab5743f6378e4fef77f7f6db0095c0727e20225beb665645403453e325ad5f9aeb9ba99bf3c148f63f9c07cf4fe8847ad5242d6b7d4499f93bd47056ddab8f7dee878fc2314f344dbee2a7c41a5d3db91eff372c730c2fdd3a141a4b61999e36d549b9870cf2f4e632c4d5df5f024f81c028000073a0ed8847cfb0593d36a47142f578f05ccbe28c0c06aeb1b1da027794c48db880278f79ba78ae64eedfea3c07d10e0562668d839749dc95f40467d15cf65b9cfc52c7c4bcef1cda3596dd52631aac942f146c7cebd46065131699ce8385b0db1874336747ee020a5698a3d1a1082665721e769567f579830f9d259cec1a836845109c21cf6b25da572512bf3c42fd4b96e43895589042ab60dd41f497db96aec102087fe784165bb45f942859268fd2ff6c012d9d00c02ba83eace047cc5f7b2c392c2955c58a49f0338d6fc58749c9db2155522ac17914ec216ad87f12e0ee95574613942fa615898c4d9e8a3be68cd6afa4e7a003dedbdf8edfee31162b174f965b20ae752ad89c967b3068b6f722c16b354456ba8e280f987c08e0a52d40a2e8f3a59b94d590aeef01879eb7a90b3ee7d772c839c85519cbeaddc0c193ec4874a463b53fcaea3271d80ebfb39b33489365fc039ae549a17a9ff898eea2f4cb27b8dbee4c17b998438575b2b8d107e4a0d66ba7fca85b41a58a8d51f191a35c856dfbe8aef2b00048a694bbccff832d23c8ca7a7ff0b6c0b3011d00b97c86c0628444d267c951d9e4fb8f83e154b8f74fb51aa16535e498235c5597dac9606ed0be3173a3836baa4e7d756ffe1e2879b415d3846bccd538c05b847785699aefde3e305decb600cd8fb0e7d8de5efc26971a6ad4e6d7a2d91474f1023a0ac4b78dc937da0ce607a45974d2cac1c33a2631ff7fe6144a3b2e5cf98b531a9627dea92c1dc82204d09db0439b6a11dd64b484e1263aa45fd9539b6020b55e3baece3986a8bffc1003406348f5c61265099ed43a766ee4f93f5f9c5abbc32a0fd3ac2b35b87f9ec26037d88275bd7dd0a54474995ee34ed3727f3f97c48db544b1980193a4b76a8a3ddab3591ce527f16d91882e67f0103b5cda53f7da54d489fc4ac08b6ab358a5a04aa9daa16219d50bd672a7cb804ed769d218807544e5993f1c27427104b349906a0b654df0bf69328afd3013fbe430155339c39f236df5557bf92f1ded7ff609a8502f49064ec3d1dbfb6c15d3a4c11a4f8acd12278cbf68acd5709463d12e3338a6eddb8c112f199645e23154a8e60879d2a654e3ed9296aa28f134168619691cd2c6b9e2eba4438381676173fc63c2588a3c5910dc149cf3760f0aa9fa9c3f5faa9162b0bf1aac9dd32b706a60ef53cbdb394b6b40222b5bc80eea82ba8958386672564cae3794f977871ab62337cf02e30049201ec12937e7ce79d0f55d9c810e20acf52212aca1d3888949e0e4830aad88d804161230eb89d4d329cc83570fe257217d2119134048dd2ed167646975fc7d77136919a049ea74cf08ddd2b896890bb24a0ba18094a22baa351bf29ad96c66bbb1a598f2ca391749620e62d61c3561a7d3653ccc8892c7b99baaf76bf836e2991cb06d6bc0514568ff0d1ec8bb4b3d6984f5eaefb17d3ea2893722375d3ddb8e389a8eef7d7d198f8e687d6a513983df906099f9a2d23f4f9dec6f8ef2f11fc0a21fac45353b94e00486f5e17d386af42502d09db33cf0cf28310e049c07e88682aeeb00cb833c5174266e62407a57583f1f88b304b7c6e0c84bbe1c0fd423072d37a5bd0aacf764229e5c7cd02473460ba3645cd8e8ae144065bf02d0dd238593d8e230354f67e0b2f23012c23274f80e3ee31e35e2606a4a3f31d94ab755e6d163cff52cbb36b6d0cc67ffc512aeed1dce4d7a0d70ce82f2baba12e8d514dc92a056f994adfb17b5b9712bd5186f27a2fda1f7039c5df2c8587fdc62f5627580c13234b55be4df3056050e2d1ef3218f0dd66cb05265fe1acfb0989d8213f2c19d1735a7cf3fa65d88dad5af52dc2bba22b7abf46c3bc77b5091baab9e8f0ddc4d5e581037de91a9f8dcbc69309be29cc815cf19a20a7585b8b3073edf51fc9baeb3e509b97fa4ecfd621e0fd57bd61cac1b895c03248ff12bdbc57509250df3517e8a3fe1d776836b34ab352b973d932ef708b14f7418f9eceb1d87667e61e3e758649cb083f01b133d37ab2f5afa96d6c84bcacf4efc3851ad308c1e7d9113624fce29fab460ab9d2a48d92cdb281103a5250ad44cb2ff6e67ac670c02fdafb3e0f1353953d6d7d5646ca1568dea55275a050ec501b7c6250444f7219f1ba7521ba3b93d089727ca5f3bbe0d6c1300b423377004954c5628fdb65770b18ced5c9b23a4a5a6d6ef25fe01b4ce278de0bcc4ed86e28a0a68818ffa40970128cf2c38740e80037984428c1bd5113f40ff47512ee6f4e4d8f9b8e8e1b3040d2928d003bd1c1329dc885302fbce9fa81c23b4dc49c7c82d29b52957847898676c89aa5d32b5b0e1c0d5a2b79a19d67562f407f19425687971a957375879d90c5f57c857136c17106c9ab1b99d80e69c8c954ed386493368884b55c939b8d64d26f643e800c56f90c01079d7c534e3b2b7ae352cefd3016da55f6a85eb803b85e2304915fd2001f77c74e28746293c46e4f5f0fd49cf988aafd0026b8e7a3bab2da5cdce1ea26c2e29ec03f4807fac432662b2d6c060be1c7be0e5489de69d0a6e03a4b9117f9244b34a0f1ecba89884f781c6320412413a00c4980287409a2a78c2cd7e65cecebbe4ec1c28cac4dd95f6998e78fc6f1392384331c9436aa10e10e2bf8ad2c4eafbcf276aa7bae64b74428911b3269c749338b0fc5075ad"); byte[] res21 = contract.execute(data21).getRight(); assertArrayEquals(Hex.decode("d61fe4e3f32ac260915b5b03b78a86d11bfc41d973fce5b0cc59035cf8289a8a2e3878ea15fa46565b0d806e2f85b53873ea20ed653869b688adf83f3ef444535bf91598ff7e80f334fb782539b92f39f55310cc4b35349ab7b278346eda9bc37c0d8acd3557fae38197f412f8d9e57ce6a76b7205c23564cab06e5615be7c6f05c3d05ec690cba91da5e89d55b152ff8dd2157dc5458190025cf94b1ad98f7cbe64e9482faba95e6b33844afc640892872b44a9932096508f4a782a4805323808f23e54b6ff9b841dbfa87db3505ae4f687972c18ea0f0d0af89d36c1c2a5b14560c153c3fee406f5cf15cfd1c0bb45d767426d465f2f14c158495069d0c5955a00150707862ecaae30624ebacdd8ac33e4e6aab3ff90b6ba445a84689386b9e945d01823a65874444316e83767290fcff630d2477f49d5d8ffdd200e08ee1274270f86ed14c687895f6caf5ce528bd970c20d2408a9ba66216324c6a011ac4999098362dbd98a038129a2d40c8da6ab88318aa3046cb660327cc44236d9e5d2163bd0959062195c51ed93d0088b6f92051fc99050ece2538749165976233697ab4b610385366e5ce0b02ad6b61c168ecfbedcdf74278a38de340fd7a5fead8e588e294795f9b011e2e60377a89e25c90e145397cdeabc60fd32444a6b7642a611a83c464d8b8976666351b4865c37b02e6dc21dbcdf5f930341707b618cc0f03c3122646b3385c9df9f2ec730eec9d49e7dfc9153b6e6289da8c4f0ebea9ccc1b751948e3bb7171c9e4d57423b0eeeb79095c030cb52677b3f7e0b45c30f645391f3f9c957afa549c4e0b2465b03c67993cd200b1af01035962edbc4c9e89b31c82ac121987d6529dafdeef67a132dc04b6dc68e77f22862040b75e2ceb9ff16da0fca534e6db7bd12fa7b7f51b6c08c1e23dfcdb7acbd2da0b51c87ffbced065a612e9b1c8bba9b7e2d8d7a2f04fcc4aaf355b60d764879a76b5e16762d5f2f55d585d0c8e82df6940960cddfb72c91dfa71f6b4e1c6ca25dfc39a878e998a663c04fe29d5e83b9586d047b4d7ff70a9f0d44f127e7d741685ca75f11629128d916a0ffef4be586a30c4b70389cc746e84ebf177c01ee8a4511cfbb9d1ecf7f7b33c7dd8177896e10bbc82f838dcd6db7ac67de62bf46b6a640fb580c5d1d2708f3862e3d2b645d0d18e49ef088053e3a220adc0e033c2afcfe61c90e32151152eb3caaf746c5e377d541cafc6cbb0cc0fa48b5caf1728f2e1957f5addfc234f1a9d89e40d49356c9172d0561a695fce6dab1d412321bbf407f63766ffd7b6b3d79bcfa07991c5a9709849c1008689e3b47c50d613980bec239fb64185249d055b30375ccb4354d71fe4d05648fbf6c80634dfc3575f2f24abb714c1e4c95e8896763bf4316e954c7ad19e5780ab7a040ca6fb9271f90a8b22ae738daf6cb"), res21); // nagydani-5-qube byte[] data22 = Hex.decode("000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000400c5a1611f8be90071a43db23cc2fe01871cc4c0e8ab5743f6378e4fef77f7f6db0095c0727e20225beb665645403453e325ad5f9aeb9ba99bf3c148f63f9c07cf4fe8847ad5242d6b7d4499f93bd47056ddab8f7dee878fc2314f344dbee2a7c41a5d3db91eff372c730c2fdd3a141a4b61999e36d549b9870cf2f4e632c4d5df5f024f81c028000073a0ed8847cfb0593d36a47142f578f05ccbe28c0c06aeb1b1da027794c48db880278f79ba78ae64eedfea3c07d10e0562668d839749dc95f40467d15cf65b9cfc52c7c4bcef1cda3596dd52631aac942f146c7cebd46065131699ce8385b0db1874336747ee020a5698a3d1a1082665721e769567f579830f9d259cec1a836845109c21cf6b25da572512bf3c42fd4b96e43895589042ab60dd41f497db96aec102087fe784165bb45f942859268fd2ff6c012d9d00c02ba83eace047cc5f7b2c392c2955c58a49f0338d6fc58749c9db2155522ac17914ec216ad87f12e0ee95574613942fa615898c4d9e8a3be68cd6afa4e7a003dedbdf8edfee31162b174f965b20ae752ad89c967b3068b6f722c16b354456ba8e280f987c08e0a52d40a2e8f3a59b94d590aeef01879eb7a90b3ee7d772c839c85519cbeaddc0c193ec4874a463b53fcaea3271d80ebfb39b33489365fc039ae549a17a9ff898eea2f4cb27b8dbee4c17b998438575b2b8d107e4a0d66ba7fca85b41a58a8d51f191a35c856dfbe8aef2b00048a694bbccff832d23c8ca7a7ff0b6c0b3011d00b97c86c0628444d267c951d9e4fb8f83e154b8f74fb51aa16535e498235c5597dac9606ed0be3173a3836baa4e7d756ffe1e2879b415d3846bccd538c05b847785699aefde3e305decb600cd8fb0e7d8de5efc26971a6ad4e6d7a2d91474f1023a0ac4b78dc937da0ce607a45974d2cac1c33a2631ff7fe6144a3b2e5cf98b531a9627dea92c1dc82204d09db0439b6a11dd64b484e1263aa45fd9539b6020b55e3baece3986a8bffc1003406348f5c61265099ed43a766ee4f93f5f9c5abbc32a0fd3ac2b35b87f9ec26037d88275bd7dd0a54474995ee34ed3727f3f97c48db544b1980193a4b76a8a3ddab3591ce527f16d91882e67f0103b5cda53f7da54d489fc4ac08b6ab358a5a04aa9daa16219d50bd672a7cb804ed769d218807544e5993f1c27427104b349906a0b654df0bf69328afd3013fbe430155339c39f236df5557bf92f1ded7ff609a8502f49064ec3d1dbfb6c15d3a4c11a4f8acd12278cbf68acd5709463d12e3338a6eddb8c112f199645e23154a8e60879d2a654e3ed9296aa28f134168619691cd2c6b9e2eba4438381676173fc63c2588a3c5910dc149cf3760f0aa9fa9c3f5faa9162b0bf1aac9dd32b706a60ef53cbdb394b6b40222b5bc80eea82ba8958386672564cae3794f977871ab62337cf03e30049201ec12937e7ce79d0f55d9c810e20acf52212aca1d3888949e0e4830aad88d804161230eb89d4d329cc83570fe257217d2119134048dd2ed167646975fc7d77136919a049ea74cf08ddd2b896890bb24a0ba18094a22baa351bf29ad96c66bbb1a598f2ca391749620e62d61c3561a7d3653ccc8892c7b99baaf76bf836e2991cb06d6bc0514568ff0d1ec8bb4b3d6984f5eaefb17d3ea2893722375d3ddb8e389a8eef7d7d198f8e687d6a513983df906099f9a2d23f4f9dec6f8ef2f11fc0a21fac45353b94e00486f5e17d386af42502d09db33cf0cf28310e049c07e88682aeeb00cb833c5174266e62407a57583f1f88b304b7c6e0c84bbe1c0fd423072d37a5bd0aacf764229e5c7cd02473460ba3645cd8e8ae144065bf02d0dd238593d8e230354f67e0b2f23012c23274f80e3ee31e35e2606a4a3f31d94ab755e6d163cff52cbb36b6d0cc67ffc512aeed1dce4d7a0d70ce82f2baba12e8d514dc92a056f994adfb17b5b9712bd5186f27a2fda1f7039c5df2c8587fdc62f5627580c13234b55be4df3056050e2d1ef3218f0dd66cb05265fe1acfb0989d8213f2c19d1735a7cf3fa65d88dad5af52dc2bba22b7abf46c3bc77b5091baab9e8f0ddc4d5e581037de91a9f8dcbc69309be29cc815cf19a20a7585b8b3073edf51fc9baeb3e509b97fa4ecfd621e0fd57bd61cac1b895c03248ff12bdbc57509250df3517e8a3fe1d776836b34ab352b973d932ef708b14f7418f9eceb1d87667e61e3e758649cb083f01b133d37ab2f5afa96d6c84bcacf4efc3851ad308c1e7d9113624fce29fab460ab9d2a48d92cdb281103a5250ad44cb2ff6e67ac670c02fdafb3e0f1353953d6d7d5646ca1568dea55275a050ec501b7c6250444f7219f1ba7521ba3b93d089727ca5f3bbe0d6c1300b423377004954c5628fdb65770b18ced5c9b23a4a5a6d6ef25fe01b4ce278de0bcc4ed86e28a0a68818ffa40970128cf2c38740e80037984428c1bd5113f40ff47512ee6f4e4d8f9b8e8e1b3040d2928d003bd1c1329dc885302fbce9fa81c23b4dc49c7c82d29b52957847898676c89aa5d32b5b0e1c0d5a2b79a19d67562f407f19425687971a957375879d90c5f57c857136c17106c9ab1b99d80e69c8c954ed386493368884b55c939b8d64d26f643e800c56f90c01079d7c534e3b2b7ae352cefd3016da55f6a85eb803b85e2304915fd2001f77c74e28746293c46e4f5f0fd49cf988aafd0026b8e7a3bab2da5cdce1ea26c2e29ec03f4807fac432662b2d6c060be1c7be0e5489de69d0a6e03a4b9117f9244b34a0f1ecba89884f781c6320412413a00c4980287409a2a78c2cd7e65cecebbe4ec1c28cac4dd95f6998e78fc6f1392384331c9436aa10e10e2bf8ad2c4eafbcf276aa7bae64b74428911b3269c749338b0fc5075ad"); byte[] res22 = contract.execute(data22).getRight(); assertArrayEquals(Hex.decode("5f9c70ec884926a89461056ad20ac4c30155e817f807e4d3f5bb743d789c83386762435c3627773fa77da5144451f2a8aad8adba88e0b669f5377c5e9bad70e45c86fe952b613f015a9953b8a5de5eaee4566acf98d41e327d93a35bd5cef4607d025e58951167957df4ff9b1627649d3943805472e5e293d3efb687cfd1e503faafeb2840a3e3b3f85d016051a58e1c9498aab72e63b748d834b31eb05d85dcde65e27834e266b85c75cc4ec0135135e0601cb93eeeb6e0010c8ceb65c4c319623c5e573a2c8c9fbbf7df68a930beb412d3f4dfd146175484f45d7afaa0d2e60684af9b34730f7c8438465ad3e1d0c3237336722f2aa51095bd5759f4b8ab4dda111b684aa3dac62a761722e7ae43495b7709933512c81c4e3c9133a51f7ce9f2b51fcec064f65779666960b4e45df3900f54311f5613e8012dd1b8efd359eda31a778264c72aa8bb419d862734d769076bce2810011989a45374e5c5d8729fec21427f0bf397eacbb4220f603cf463a4b0c94efd858ffd9768cd60d6ce68d755e0fbad007ce5c2223d70c7018345a102e4ab3c60a13a9e7794303156d4c2063e919f2153c13961fb324c80b240742f47773a7a8e25b3e3fb19b00ce839346c6eb3c732fbc6b888df0b1fe0a3d07b053a2e9402c267b2d62f794d8a2840526e3ade15ce2264496ccd7519571dfde47f7a4bb16292241c20b2be59f3f8fb4f6383f232d838c5a22d8c95b6834d9d2ca493f5a505ebe8899503b0e8f9b19e6e2dd81c1628b80016d02097e0134de51054c4e7674824d4d758760fc52377d2cad145e259aa2ffaf54139e1a66b1e0c1c191e32ac59474c6b526f5b3ba07d3e5ec286eddf531fcd5292869be58c9f22ef91026159f7cf9d05ef66b4299f4da48cc1635bf2243051d342d378a22c83390553e873713c0454ce5f3234397111ac3fe3207b86f0ed9fc025c81903e1748103692074f83824fda6341be4f95ff00b0a9a208c267e12fa01825054cc0513629bf3dbb56dc5b90d4316f87654a8be18227978ea0a8a522760cad620d0d14fd38920fb7321314062914275a5f99f677145a6979b156bd82ecd36f23f8e1273cc2759ecc0b2c69d94dad5211d1bed939dd87ed9e07b91d49713a6e16ade0a98aea789f04994e318e4ff2c8a188cd8d43aeb52c6daa3bc29b4af50ea82a247c5cd67b573b34cbadcc0a376d3bbd530d50367b42705d870f2e27a8197ef46070528bfe408360faa2ebb8bf76e9f388572842bcb119f4d84ee34ae31f5cc594f23705a49197b181fb78ed1ec99499c690f843a4d0cf2e226d118e9372271054fbabdcc5c92ae9fefaef0589cd0e722eaf30c1703ec4289c7fd81beaa8a455ccee5298e31e2080c10c366a6fcf56f7d13582ad0bcad037c612b710fc595b70fbefaaca23623b60c6c39b11beb8e5843b6b3dac60f"), res22); // nagydani-5-pow0x10001 byte[] data23 = Hex.decode("000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000400c5a1611f8be90071a43db23cc2fe01871cc4c0e8ab5743f6378e4fef77f7f6db0095c0727e20225beb665645403453e325ad5f9aeb9ba99bf3c148f63f9c07cf4fe8847ad5242d6b7d4499f93bd47056ddab8f7dee878fc2314f344dbee2a7c41a5d3db91eff372c730c2fdd3a141a4b61999e36d549b9870cf2f4e632c4d5df5f024f81c028000073a0ed8847cfb0593d36a47142f578f05ccbe28c0c06aeb1b1da027794c48db880278f79ba78ae64eedfea3c07d10e0562668d839749dc95f40467d15cf65b9cfc52c7c4bcef1cda3596dd52631aac942f146c7cebd46065131699ce8385b0db1874336747ee020a5698a3d1a1082665721e769567f579830f9d259cec1a836845109c21cf6b25da572512bf3c42fd4b96e43895589042ab60dd41f497db96aec102087fe784165bb45f942859268fd2ff6c012d9d00c02ba83eace047cc5f7b2c392c2955c58a49f0338d6fc58749c9db2155522ac17914ec216ad87f12e0ee95574613942fa615898c4d9e8a3be68cd6afa4e7a003dedbdf8edfee31162b174f965b20ae752ad89c967b3068b6f722c16b354456ba8e280f987c08e0a52d40a2e8f3a59b94d590aeef01879eb7a90b3ee7d772c839c85519cbeaddc0c193ec4874a463b53fcaea3271d80ebfb39b33489365fc039ae549a17a9ff898eea2f4cb27b8dbee4c17b998438575b2b8d107e4a0d66ba7fca85b41a58a8d51f191a35c856dfbe8aef2b00048a694bbccff832d23c8ca7a7ff0b6c0b3011d00b97c86c0628444d267c951d9e4fb8f83e154b8f74fb51aa16535e498235c5597dac9606ed0be3173a3836baa4e7d756ffe1e2879b415d3846bccd538c05b847785699aefde3e305decb600cd8fb0e7d8de5efc26971a6ad4e6d7a2d91474f1023a0ac4b78dc937da0ce607a45974d2cac1c33a2631ff7fe6144a3b2e5cf98b531a9627dea92c1dc82204d09db0439b6a11dd64b484e1263aa45fd9539b6020b55e3baece3986a8bffc1003406348f5c61265099ed43a766ee4f93f5f9c5abbc32a0fd3ac2b35b87f9ec26037d88275bd7dd0a54474995ee34ed3727f3f97c48db544b1980193a4b76a8a3ddab3591ce527f16d91882e67f0103b5cda53f7da54d489fc4ac08b6ab358a5a04aa9daa16219d50bd672a7cb804ed769d218807544e5993f1c27427104b349906a0b654df0bf69328afd3013fbe430155339c39f236df5557bf92f1ded7ff609a8502f49064ec3d1dbfb6c15d3a4c11a4f8acd12278cbf68acd5709463d12e3338a6eddb8c112f199645e23154a8e60879d2a654e3ed9296aa28f134168619691cd2c6b9e2eba4438381676173fc63c2588a3c5910dc149cf3760f0aa9fa9c3f5faa9162b0bf1aac9dd32b706a60ef53cbdb394b6b40222b5bc80eea82ba8958386672564cae3794f977871ab62337cf010001e30049201ec12937e7ce79d0f55d9c810e20acf52212aca1d3888949e0e4830aad88d804161230eb89d4d329cc83570fe257217d2119134048dd2ed167646975fc7d77136919a049ea74cf08ddd2b896890bb24a0ba18094a22baa351bf29ad96c66bbb1a598f2ca391749620e62d61c3561a7d3653ccc8892c7b99baaf76bf836e2991cb06d6bc0514568ff0d1ec8bb4b3d6984f5eaefb17d3ea2893722375d3ddb8e389a8eef7d7d198f8e687d6a513983df906099f9a2d23f4f9dec6f8ef2f11fc0a21fac45353b94e00486f5e17d386af42502d09db33cf0cf28310e049c07e88682aeeb00cb833c5174266e62407a57583f1f88b304b7c6e0c84bbe1c0fd423072d37a5bd0aacf764229e5c7cd02473460ba3645cd8e8ae144065bf02d0dd238593d8e230354f67e0b2f23012c23274f80e3ee31e35e2606a4a3f31d94ab755e6d163cff52cbb36b6d0cc67ffc512aeed1dce4d7a0d70ce82f2baba12e8d514dc92a056f994adfb17b5b9712bd5186f27a2fda1f7039c5df2c8587fdc62f5627580c13234b55be4df3056050e2d1ef3218f0dd66cb05265fe1acfb0989d8213f2c19d1735a7cf3fa65d88dad5af52dc2bba22b7abf46c3bc77b5091baab9e8f0ddc4d5e581037de91a9f8dcbc69309be29cc815cf19a20a7585b8b3073edf51fc9baeb3e509b97fa4ecfd621e0fd57bd61cac1b895c03248ff12bdbc57509250df3517e8a3fe1d776836b34ab352b973d932ef708b14f7418f9eceb1d87667e61e3e758649cb083f01b133d37ab2f5afa96d6c84bcacf4efc3851ad308c1e7d9113624fce29fab460ab9d2a48d92cdb281103a5250ad44cb2ff6e67ac670c02fdafb3e0f1353953d6d7d5646ca1568dea55275a050ec501b7c6250444f7219f1ba7521ba3b93d089727ca5f3bbe0d6c1300b423377004954c5628fdb65770b18ced5c9b23a4a5a6d6ef25fe01b4ce278de0bcc4ed86e28a0a68818ffa40970128cf2c38740e80037984428c1bd5113f40ff47512ee6f4e4d8f9b8e8e1b3040d2928d003bd1c1329dc885302fbce9fa81c23b4dc49c7c82d29b52957847898676c89aa5d32b5b0e1c0d5a2b79a19d67562f407f19425687971a957375879d90c5f57c857136c17106c9ab1b99d80e69c8c954ed386493368884b55c939b8d64d26f643e800c56f90c01079d7c534e3b2b7ae352cefd3016da55f6a85eb803b85e2304915fd2001f77c74e28746293c46e4f5f0fd49cf988aafd0026b8e7a3bab2da5cdce1ea26c2e29ec03f4807fac432662b2d6c060be1c7be0e5489de69d0a6e03a4b9117f9244b34a0f1ecba89884f781c6320412413a00c4980287409a2a78c2cd7e65cecebbe4ec1c28cac4dd95f6998e78fc6f1392384331c9436aa10e10e2bf8ad2c4eafbcf276aa7bae64b74428911b3269c749338b0fc5075ad"); byte[] res23 = contract.execute(data23).getRight(); assertArrayEquals(Hex.decode("5a0eb2bdf0ac1cae8e586689fa16cd4b07dfdedaec8a110ea1fdb059dd5253231b6132987598dfc6e11f86780428982d50cf68f67ae452622c3b336b537ef3298ca645e8f89ee39a26758206a5a3f6409afc709582f95274b57b71fae5c6b74619ae6f089a5393c5b79235d9caf699d23d88fb873f78379690ad8405e34c19f5257d596580c7a6a7206a3712825afe630c76b31cdb4a23e7f0632e10f14f4e282c81a66451a26f8df2a352b5b9f607a7198449d1b926e27036810368e691a74b91c61afa73d9d3b99453e7c8b50fd4f09c039a2f2feb5c419206694c31b92df1d9586140cb3417b38d0c503c7b508cc2ed12e813a1c795e9829eb39ee78eeaf360a169b491a1d4e419574e712402de9d48d54c1ae5e03739b7156615e8267e1fb0a897f067afd11fb33f6e24182d7aaaaa18fe5bc1982f20d6b871e5a398f0f6f718181d31ec225cfa9a0a70124ed9a70031bdf0c1c7829f708b6e17d50419ef361cf77d99c85f44607186c8d683106b8bd38a49b5d0fb503b397a83388c5678dcfcc737499d84512690701ed621a6f0172aecf037184ddf0f2453e4053024018e5ab2e30d6d5363b56e8b41509317c99042f517247474ab3abc848e00a07f69c254f46f2a05cf6ed84e5cc906a518fdcfdf2c61ce731f24c5264f1a25fc04934dc28aec112134dd523f70115074ca34e3807aa4cb925147f3a0ce152d323bd8c675ace446d0fd1ae30c4b57f0eb2c23884bc18f0964c0114796c5b6d080c3d89175665fbf63a6381a6a9da39ad070b645c8bb1779506da14439a9f5b5d481954764ea114fac688930bc68534d403cff4210673b6a6ff7ae416b7cd41404c3d3f282fcd193b86d0f54d0006c2a503b40d5c3930da980565b8f9630e9493a79d1c03e74e5f93ac8e4dc1a901ec5e3b3e57049124c7b72ea345aa359e782285d9e6a5c144a378111dd02c40855ff9c2be9b48425cb0b2fd62dc8678fd151121cf26a65e917d65d8e0dacfae108eb5508b601fb8ffa370be1f9a8b749a2d12eeab81f41079de87e2d777994fa4d28188c579ad327f9957fb7bdecec5c680844dd43cb57cf87aeb763c003e65011f73f8c63442df39a92b946a6bd968a1c1e4d5fa7d88476a68bd8e20e5b70a99259c7d3f85fb1b65cd2e93972e6264e74ebf289b8b6979b9b68a85cd5b360c1987f87235c3c845d62489e33acf85d53fa3561fe3a3aee18924588d9c6eba4edb7a4d106b31173e42929f6f0c48c80ce6a72d54eca7c0fe870068b7a7c89c63cdda593f5b32d3cb4ea8a32c39f00ab449155757172d66763ed9527019d6de6c9f2416aa6203f4d11c9ebee1e1d3845099e55504446448027212616167eb36035726daa7698b075286f5379cd3e93cb3e0cf4f9cb8d017facbb5550ed32d5ec5400ae57e47e2bf78d1eaeff9480cc765ceff39db500"), res23); } }
52,416
164.876582
4,333
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/vm/VMOpTest.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.vm; import org.ethereum.core.Repository; import org.ethereum.vm.program.Program; import org.ethereum.vm.program.Program.BadJumpDestinationException; import org.ethereum.vm.program.Program.StackTooSmallException; import org.junit.*; import org.spongycastle.util.encoders.Hex; import java.util.List; import static org.ethereum.util.ByteUtil.oneByteToHexString; import static org.junit.Assert.*; /** * @author Roman Mandeleil * @since 01.06.2014 */ public class VMOpTest extends VMBaseOpTest { @Test // LOG0 OP public void tesLog0() { VM vm = new VM(); program = new Program(compile("PUSH2 0x1234 PUSH1 0x00 MSTORE PUSH1 0x20 PUSH1 0x00 LOG0"), invoke); vm.step(program); vm.step(program); vm.step(program); vm.step(program); vm.step(program); vm.step(program); List<LogInfo> logInfoList = program.getResult().getLogInfoList(); LogInfo logInfo = logInfoList.get(0); assertEquals("cd2a3d9f938e13cd947ec05abc7fe734df8dd826", Hex.toHexString(logInfo.getAddress())); assertEquals(0, logInfo.getTopics().size()); assertEquals("0000000000000000000000000000000000000000000000000000000000001234", Hex.toHexString(logInfo .getData())); } @Test // LOG1 OP public void tesLog1() { VM vm = new VM(); program = new Program(compile("PUSH2 0x1234 PUSH1 0x00 MSTORE PUSH2 0x9999 PUSH1 0x20 PUSH1 0x00 LOG1"), invoke); vm.step(program); vm.step(program); vm.step(program); vm.step(program); vm.step(program); vm.step(program); vm.step(program); List<LogInfo> logInfoList = program.getResult().getLogInfoList(); LogInfo logInfo = logInfoList.get(0); assertEquals("cd2a3d9f938e13cd947ec05abc7fe734df8dd826", Hex.toHexString(logInfo.getAddress())); assertEquals(1, logInfo.getTopics().size()); assertEquals("0000000000000000000000000000000000000000000000000000000000001234", Hex.toHexString(logInfo .getData())); } @Test // LOG2 OP public void tesLog2() { VM vm = new VM(); program = new Program(compile("PUSH2 0x1234 PUSH1 0x00 MSTORE PUSH2 0x9999 PUSH2 0x6666 PUSH1 0x20 PUSH1 0x00 LOG2"), invoke); vm.step(program); vm.step(program); vm.step(program); vm.step(program); vm.step(program); vm.step(program); vm.step(program); vm.step(program); List<LogInfo> logInfoList = program.getResult().getLogInfoList(); LogInfo logInfo = logInfoList.get(0); assertEquals("cd2a3d9f938e13cd947ec05abc7fe734df8dd826", Hex.toHexString(logInfo.getAddress())); assertEquals(2, logInfo.getTopics().size()); assertEquals("0000000000000000000000000000000000000000000000000000000000001234", Hex.toHexString(logInfo .getData())); } @Test // LOG3 OP public void tesLog3() { VM vm = new VM(); program = new Program(compile("PUSH2 0x1234 PUSH1 0x00 MSTORE PUSH2 0x9999 PUSH2 0x6666 PUSH2 0x3333 PUSH1 0x20 PUSH1 0x00 LOG3"), invoke); vm.step(program); vm.step(program); vm.step(program); vm.step(program); vm.step(program); vm.step(program); vm.step(program); vm.step(program); vm.step(program); List<LogInfo> logInfoList = program.getResult().getLogInfoList(); LogInfo logInfo = logInfoList.get(0); assertEquals("cd2a3d9f938e13cd947ec05abc7fe734df8dd826", Hex.toHexString(logInfo.getAddress())); assertEquals(3, logInfo.getTopics().size()); assertEquals("0000000000000000000000000000000000000000000000000000000000001234", Hex.toHexString(logInfo .getData())); } @Test // LOG4 OP public void tesLog4() { VM vm = new VM(); program = new Program(compile("PUSH2 0x1234 PUSH1 0x00 MSTORE PUSH2 0x9999 PUSH2 0x6666 PUSH2 0x3333 PUSH2 0x5555 PUSH1 0x20 PUSH1 0x00 LOG4"), invoke); vm.step(program); vm.step(program); vm.step(program); vm.step(program); vm.step(program); vm.step(program); vm.step(program); vm.step(program); vm.step(program); vm.step(program); List<LogInfo> logInfoList = program.getResult().getLogInfoList(); LogInfo logInfo = logInfoList.get(0); assertEquals("cd2a3d9f938e13cd947ec05abc7fe734df8dd826", Hex.toHexString(logInfo.getAddress())); assertEquals(4, logInfo.getTopics().size()); assertEquals("0000000000000000000000000000000000000000000000000000000000001234", Hex.toHexString(logInfo .getData())); } @Test // STOP OP public void testSTOP_1() { VM vm = new VM(); program = new Program(compile("PUSH1 0x20 PUSH1 0x30 PUSH1 0x10 PUSH1 0x30 PUSH1 0x11 PUSH1 0x23 STOP"), invoke); int expectedSteps = 7; int i = 0; while (!program.isStopped()) { vm.step(program); ++i; } assertEquals(expectedSteps, i); } @Test // RETURN OP public void testRETURN_1() { VM vm = new VM(); program = new Program(compile("PUSH2 0x1234 PUSH1 0x00 MSTORE PUSH1 0x20 PUSH1 0x00 RETURN"), invoke); String s_expected_1 = "0000000000000000000000000000000000000000000000000000000000001234"; vm.step(program); vm.step(program); vm.step(program); vm.step(program); vm.step(program); vm.step(program); assertEquals(s_expected_1, Hex.toHexString(program.getResult().getHReturn()).toUpperCase()); assertTrue(program.isStopped()); } @Test // RETURN OP public void testRETURN_2() { VM vm = new VM(); program = new Program(compile("PUSH2 0x1234 PUSH1 0x00 MSTORE PUSH1 0x20 PUSH1 0x1F RETURN"), invoke); String s_expected_1 = "3400000000000000000000000000000000000000000000000000000000000000"; vm.step(program); vm.step(program); vm.step(program); vm.step(program); vm.step(program); vm.step(program); assertEquals(s_expected_1, Hex.toHexString(program.getResult().getHReturn()).toUpperCase()); assertTrue(program.isStopped()); } @Test // RETURN OP public void testRETURN_3() { VM vm = new VM(); program = new Program(compile ("PUSH32 0xA0B0C0D0E0F0A1B1C1D1E1F1A2B2C2D2E2F2A3B3C3D3E3F3A4B4C4D4E4F4A1B1 PUSH1 0x00 MSTORE PUSH1 0x20 PUSH1 0x00 RETURN"), invoke); String s_expected_1 = "A0B0C0D0E0F0A1B1C1D1E1F1A2B2C2D2E2F2A3B3C3D3E3F3A4B4C4D4E4F4A1B1"; vm.step(program); vm.step(program); vm.step(program); vm.step(program); vm.step(program); vm.step(program); assertEquals(s_expected_1, Hex.toHexString(program.getResult().getHReturn()).toUpperCase()); assertTrue(program.isStopped()); } @Test // RETURN OP public void testRETURN_4() { VM vm = new VM(); program = new Program(compile ("PUSH32 0xA0B0C0D0E0F0A1B1C1D1E1F1A2B2C2D2E2F2A3B3C3D3E3F3A4B4C4D4E4F4A1B1 PUSH1 0x00 MSTORE PUSH1 0x20 PUSH1 0x10 RETURN"), invoke); String s_expected_1 = "E2F2A3B3C3D3E3F3A4B4C4D4E4F4A1B100000000000000000000000000000000"; vm.step(program); vm.step(program); vm.step(program); vm.step(program); vm.step(program); vm.step(program); assertEquals(s_expected_1, Hex.toHexString(program.getResult().getHReturn()).toUpperCase()); assertTrue(program.isStopped()); } @Test public void regression1Test() { // testing that we are working fine with unknown 0xFE bytecode produced by Serpent compiler String code2 = "60006116bf537c01000000000000000000000000000000000000000000000000000000006000350463b041b2858114156101c257600435604052780100000000000000000000000000000000000000000000000060606060599059016000905260028152604051816020015260008160400152809050205404606052606051151561008f57600060a052602060a0f35b66040000000000015460c052600760e0525b60605178010000000000000000000000000000000000000000000000006060606059905901600090526002815260c05181602001526000816040015280905020540413156101b0575b60e05160050a60605178010000000000000000000000000000000000000000000000006060606059905901600090526002815260c05181602001526000816040015280905020540403121561014457600060e05113610147565b60005b1561015a57600160e0510360e0526100ea565b7c010000000000000000000000000000000000000000000000000000000060e05160200260020a6060606059905901600090526002815260c051816020015260018160400152809050205402045460c0526100a1565b60405160c05114610160526020610160f35b63720f60f58114156102435760043561018052601c60445990590160009052016305215b2f601c820352790100000000000000000000000000000000000000000000000000600482015260206101c0602483600061018051602d5a03f1506101c05190506604000000000003556604000000000003546101e05260206101e0f35b63b8c48f8c8114156104325760043560c05260243561020052604435610220526000660400000000000254141515610286576000610240526020610240f3610292565b60016604000000000002555b60c0516604000000000001556060606059905901600090526002815260c051816020015260008160400152809050205461026052610260610200518060181a82538060191a600183015380601a1a600283015380601b1a600383015380601c1a600483015380601d1a600583015380601e1a600683015380601f1a60078301535050610260516060606059905901600090526002815260c05181602001526000816040015280905020556060606059905901600090526002815260c051816020015260008160400152809050205461030052601061030001610220518060101a82538060111a60018301538060121a60028301538060131a60038301538060141a60048301538060151a60058301538060161a60068301538060171a60078301538060181a60088301538060191a600983015380601a1a600a83015380601b1a600b83015380601c1a600c83015380601d1a600d83015380601e1a600e83015380601f1a600f8301535050610300516060606059905901600090526002815260c051816020015260008160400152809050205560016103a05260206103a0f35b632b861629811415610eed57365990590160009052366004823760043560208201016103e0525060483580601f1a6104405380601e1a6001610440015380601d1a6002610440015380601c1a6003610440015380601b1a6004610440015380601a1a600561044001538060191a600661044001538060181a600761044001538060171a600861044001538060161a600961044001538060151a600a61044001538060141a600b61044001538060131a600c61044001538060121a600d61044001538060111a600e61044001538060101a600f610440015380600f1a6010610440015380600e1a6011610440015380600d1a6012610440015380600c1a6013610440015380600b1a6014610440015380600a1a601561044001538060091a601661044001538060081a601761044001538060071a601861044001538060061a601961044001538060051a601a61044001538060041a601b61044001538060031a601c61044001538060021a601d61044001538060011a601e61044001538060001a601f6104400153506104405161040052700100000000000000000000000000000000700100000000000000000000000000000000606060605990590160009052600281526104005181602001526000816040015280905020540204610460526104605161061b57005b6103e05160208103516020599059016000905260208183856000600287604801f15080519050905090506104a0526020599059016000905260208160206104a0600060026068f1508051905080601f1a6105605380601e1a6001610560015380601d1a6002610560015380601c1a6003610560015380601b1a6004610560015380601a1a600561056001538060191a600661056001538060181a600761056001538060171a600861056001538060161a600961056001538060151a600a61056001538060141a600b61056001538060131a600c61056001538060121a600d61056001538060111a600e61056001538060101a600f610560015380600f1a6010610560015380600e1a6011610560015380600d1a6012610560015380600c1a6013610560015380600b1a6014610560015380600a1a601561056001538060091a601661056001538060081a601761056001538060071a601861056001538060061a601961056001538060051a601a61056001538060041a601b61056001538060031a601c61056001538060021a601d61056001538060011a601e61056001538060001a601f6105600153506105605160c0527001000000000000000000000000000000007001000000000000000000000000000000006060606059905901600090526002815260c05181602001526000816040015280905020540204610580526000610580511415156108345760006105c05260206105c0f35b608c3563010000008160031a02620100008260021a026101008360011a028360001a01010190506105e05263010000006105e051046106405262ffffff6105e0511661066052600361064051036101000a610660510261062052600060c05113156108a6576106205160c051126108a9565b60005b15610ee05760c05160c05160c051660400000000000054556060606059905901600090526002815260c0518160200152600081604001528090502054610680526008610680016604000000000000548060181a82538060191a600183015380601a1a600283015380601b1a600383015380601c1a600483015380601d1a600583015380601e1a600683015380601f1a60078301535050610680516060606059905901600090526002815260c05181602001526000816040015280905020556001660400000000000054016604000000000000556060606059905901600090526002815260c051816020015260008160400152809050205461072052610720600178010000000000000000000000000000000000000000000000006060606059905901600090526002815261040051816020015260008160400152809050205404018060181a82538060191a600183015380601a1a600283015380601b1a600383015380601c1a600483015380601d1a600583015380601e1a600683015380601f1a60078301535050610720516060606059905901600090526002815260c051816020015260008160400152809050205560006107e052780100000000000000000000000000000000000000000000000068010000000000000000606060605990590160009052600281526104005181602001526000816040015280905020540204610800526107e06108005180601c1a825380601d1a600183015380601e1a600283015380601f1a600383015350506001610880525b6008610880511215610c07576108805160050a6108a05260016108a05178010000000000000000000000000000000000000000000000006060606059905901600090526002815260c051816020015260008160400152809050205404071415610b7957610880516004026107e0016108005180601c1a825380601d1a600183015380601e1a600283015380601f1a60038301535050610bf7565b610880516004026107e0017c01000000000000000000000000000000000000000000000000000000006108805160200260020a60606060599059016000905260028152610400518160200152600181604001528090502054020480601c1a825380601d1a600183015380601e1a600283015380601f1a600383015350505b6001610880510161088052610adf565b6107e0516060606059905901600090526002815260c051816020015260018160400152809050205550506080608059905901600090526002815260c051816020015260028160400152600081606001528090502060005b6002811215610c8057806020026103e051015182820155600181019050610c5e565b700100000000000000000000000000000000600003816020026103e051015116828201555050610620517bffff000000000000000000000000000000000000000000000000000005610a00526060606059905901600090526002815260c0518160200152600081604001528090502054610a20526010610a2001610a005161046051018060101a82538060111a60018301538060121a60028301538060131a60038301538060141a60048301538060151a60058301538060161a60068301538060171a60078301538060181a60088301538060191a600983015380601a1a600a83015380601b1a600b83015380601c1a600c83015380601d1a600d83015380601e1a600e83015380601f1a600f8301535050610a20516060606059905901600090526002815260c05181602001526000816040015280905020557001000000000000000000000000000000007001000000000000000000000000000000006060606059905901600090526002815260c051816020015260008160400152809050205402046105805266040000000000025461058051121515610e965760c05166040000000000015561058051660400000000000255601c606459905901600090520163c86a90fe601c8203526103e860048201523260248201526020610ae06044836000660400000000000354602d5a03f150610ae051905015610e95576103e8660400000000000454016604000000000004555b5b78010000000000000000000000000000000000000000000000006060606059905901600090526002815260c051816020015260008160400152809050205404610b00526020610b00f35b6000610b40526020610b40f35b63c6605beb811415611294573659905901600090523660048237600435610b6052602435610b80526044356020820101610ba0526064356040525067016345785d8a00003412151515610f47576000610bc0526020610bc0f35b601c6044599059016000905201633d73b705601c82035260405160048201526020610be0602483600030602d5a03f150610be05190508015610f895780610fc1565b601c604459905901600090520163b041b285601c82035260405160048201526020610c20602483600030602d5a03f150610c20519050155b905015610fd5576000610c40526020610c40f35b6060601c61014c59905901600090520163b7129afb601c820352610b60516004820152610b80516024820152610ba05160208103516020026020018360448401526020820360a4840152806101088401528084019350505081600401599059016000905260648160648460006004601cf161104c57fe5b6064810192506101088201518080858260a487015160006004600a8705601201f161107357fe5b508084019350508083036020610d008284600030602d5a03f150610d00519050905090509050610c60526080608059905901600090526002815260405181602001526002816040015260008160600152809050207c010000000000000000000000000000000000000000000000000000000060028201540464010000000060018301540201610d805250610d805180601f1a610de05380601e1a6001610de0015380601d1a6002610de0015380601c1a6003610de0015380601b1a6004610de0015380601a1a6005610de001538060191a6006610de001538060181a6007610de001538060171a6008610de001538060161a6009610de001538060151a600a610de001538060141a600b610de001538060131a600c610de001538060121a600d610de001538060111a600e610de001538060101a600f610de0015380600f1a6010610de0015380600e1a6011610de0015380600d1a6012610de0015380600c1a6013610de0015380600b1a6014610de0015380600a1a6015610de001538060091a6016610de001538060081a6017610de001538060071a6018610de001538060061a6019610de001538060051a601a610de001538060041a601b610de001538060031a601c610de001538060021a601d610de001538060011a601e610de001538060001a601f610de0015350610de051610d4052610d4051610c60511415611286576001610e00526020610e00f3611293565b6000610e20526020610e20f35b5b638f6b104c8114156115195736599059016000905236600482376004356020820101610e4052602435610b6052604435610b80526064356020820101610ba05260843560405260a435610e60525060016080601c6101ac59905901600090520163c6605beb601c820352610b60516004820152610b80516024820152610ba05160208103516020026020018360448401526020820360c48401528061014884015280840193505050604051606482015281600401599059016000905260848160848460006004601ff161136357fe5b6084810192506101488201518080858260c487015160006004600a8705601201f161138a57fe5b508084019350508083036020610e80828434306123555a03f150610e8051905090509050905014156114b3576040601c60ec59905901600090520163f0cf1ff4601c820352610e40516020601f6020830351010460200260200183600484015260208203604484015280608884015280840193505050610b60516024820152816004015990590160009052604481604484600060046018f161142857fe5b604481019250608882015180808582604487015160006004600a8705601201f161144e57fe5b508084019350508083036020610ec082846000610e6051602d5a03f150610ec0519050905090509050610ea0526040599059016000905260018152610ea051602082015260208101905033602082035160200282a150610ea051610f20526020610f20f35b604059905901600090526001815261270f600003602082015260208101905033602082035160200282a150604059905901600090526001815261270f6000036020820152602081019050610e6051602082035160200282a1506000610f80526020610f80f35b6309dd0e8181141561153957660400000000000154610fa0526020610fa0f35b630239487281141561159557780100000000000000000000000000000000000000000000000060606060599059016000905260028152660400000000000154816020015260008160400152809050205404610fc0526020610fc0f35b6361b919a68114156116045770010000000000000000000000000000000070010000000000000000000000000000000060606060599059016000905260028152660400000000000154816020015260008160400152809050205402046110005261100051611040526020611040f35b63a7cc63c28114156118b55766040000000000015460c0527001000000000000000000000000000000007001000000000000000000000000000000006060606059905901600090526002815260c05181602001526000816040015280905020540204611060526000610880525b600a610880511215611853576080608059905901600090526002815260c05181602001526002816040015260008160600152809050207c0100000000000000000000000000000000000000000000000000000000600182015404640100000000825402016110c052506110c05180601f1a6111205380601e1a6001611120015380601d1a6002611120015380601c1a6003611120015380601b1a6004611120015380601a1a600561112001538060191a600661112001538060181a600761112001538060171a600861112001538060161a600961112001538060151a600a61112001538060141a600b61112001538060131a600c61112001538060121a600d61112001538060111a600e61112001538060101a600f611120015380600f1a6010611120015380600e1a6011611120015380600d1a6012611120015380600c1a6013611120015380600b1a6014611120015380600a1a601561112001538060091a601661112001538060081a601761112001538060071a601861112001538060061a601961112001538060051a601a61112001538060041a601b61112001538060031a601c61112001538060021a601d61112001538060011a601e61112001538060001a601f6111200153506111205160c0526001610880510161088052611671565b7001000000000000000000000000000000007001000000000000000000000000000000006060606059905901600090526002815260c0518160200152600081604001528090502054020461114052611140516110605103611180526020611180f35b63b7129afb811415611e35573659905901600090523660048237600435610b6052602435610b80526044356020820101610ba05250610b60516111a0526020610ba05103516111c0526000610880525b6111c051610880511215611e0c5761088051602002610ba05101516111e0526002610b805107611200526001611200511415611950576111e051611220526111a0516112405261196e565b600061120051141561196d576111a051611220526111e051611240525b5b604059905901600090526112205180601f1a6112805380601e1a6001611280015380601d1a6002611280015380601c1a6003611280015380601b1a6004611280015380601a1a600561128001538060191a600661128001538060181a600761128001538060171a600861128001538060161a600961128001538060151a600a61128001538060141a600b61128001538060131a600c61128001538060121a600d61128001538060111a600e61128001538060101a600f611280015380600f1a6010611280015380600e1a6011611280015380600d1a6012611280015380600c1a6013611280015380600b1a6014611280015380600a1a601561128001538060091a601661128001538060081a601761128001538060071a601861128001538060061a601961128001538060051a601a61128001538060041a601b61128001538060031a601c61128001538060021a601d61128001538060011a601e61128001538060001a601f6112800153506112805181526112405180601f1a6112e05380601e1a60016112e0015380601d1a60026112e0015380601c1a60036112e0015380601b1a60046112e0015380601a1a60056112e001538060191a60066112e001538060181a60076112e001538060171a60086112e001538060161a60096112e001538060151a600a6112e001538060141a600b6112e001538060131a600c6112e001538060121a600d6112e001538060111a600e6112e001538060101a600f6112e0015380600f1a60106112e0015380600e1a60116112e0015380600d1a60126112e0015380600c1a60136112e0015380600b1a60146112e0015380600a1a60156112e001538060091a60166112e001538060081a60176112e001538060071a60186112e001538060061a60196112e001538060051a601a6112e001538060041a601b6112e001538060031a601c6112e001538060021a601d6112e001538060011a601e6112e001538060001a601f6112e00153506112e051602082015260205990590160009052602081604084600060026088f1508051905061130052602059905901600090526020816020611300600060026068f1508051905080601f1a6113805380601e1a6001611380015380601d1a6002611380015380601c1a6003611380015380601b1a6004611380015380601a1a600561138001538060191a600661138001538060181a600761138001538060171a600861138001538060161a600961138001538060151a600a61138001538060141a600b61138001538060131a600c61138001538060121a600d61138001538060111a600e61138001538060101a600f611380015380600f1a6010611380015380600e1a6011611380015380600d1a6012611380015380600c1a6013611380015380600b1a6014611380015380600a1a601561138001538060091a601661138001538060081a601761138001538060071a601861138001538060061a601961138001538060051a601a61138001538060041a601b61138001538060031a601c61138001538060021a601d61138001538060011a601e61138001538060001a601f6113800153506113805190506111a0526002610b805105610b80526001610880510161088052611905565b6111a0511515611e265760016000036113a05260206113a0f35b6111a0516113c05260206113c0f35b633d73b7058114156120625760043560405266040000000000015460c0526000610880525b60066108805112156120555760c0516040511415611e7f5760016113e05260206113e0f35b6080608059905901600090526002815260c05181602001526002816040015260008160600152809050207c01000000000000000000000000000000000000000000000000000000006001820154046401000000008254020161142052506114205180601f1a6114805380601e1a6001611480015380601d1a6002611480015380601c1a6003611480015380601b1a6004611480015380601a1a600561148001538060191a600661148001538060181a600761148001538060171a600861148001538060161a600961148001538060151a600a61148001538060141a600b61148001538060131a600c61148001538060121a600d61148001538060111a600e61148001538060101a600f611480015380600f1a6010611480015380600e1a6011611480015380600d1a6012611480015380600c1a6013611480015380600b1a6014611480015380600a1a601561148001538060091a601661148001538060081a601761148001538060071a601861148001538060061a601961148001538060051a601a61148001538060041a601b61148001538060031a601c61148001538060021a601d61148001538060011a601e61148001538060001a601f6114800153506114805160c0526001610880510161088052611e5a565b60006114a05260206114a0f35b6391cf0e96811415612105576004356114c052601c60845990590160009052016367eae672601c8203523360048201526114c051602482015230604482015260206114e06064836000660400000000000354602d5a03f1506114e051905015612104576604000000000004546114c05130310205611500526114c0516604000000000004540366040000000000045560006000600060006115005133611388f1505b5b6313f955e18114156122985736599059016000905236600482376004356020820101611520526024356115405250605061156052600061158052611560516115a0526000610880525b611540516108805112156122895761158051806115a051038080602001599059016000905281815260208101905090508180828286611520510160006004600a8705601201f161219a57fe5b50809050905090506115c0526020601c608c599059016000905201632b861629601c8203526115c0516020601f6020830351010460200260200183600484015260208203602484015280604884015280840193505050816004015990590160009052602481602484600060046015f161220f57fe5b602481019250604882015180808582602487015160006004600a8705601201f161223557fe5b5080840193505080830360206116808284600030602d5a03f150611680519050905090509050610ea05261156051611580510161158052611560516115a051016115a052600161088051016108805261214e565b610ea0516116a05260206116a0f35b50"; String result = Program.stringifyMultiline(Hex.decode(code2)); } @Test public void regression2Test() { // testing that we are working fine with unknown 0xFE bytecode produced by Serpent compiler String code2 = "6060604052604051602080603f8339016040526060805190602001505b806000600050819055505b50600a8060356000396000f30060606040526008565b000000000000000000000000000000000000000000000000000000000000000021"; String result = Program.stringifyMultiline(Hex.decode(code2)); assertTrue(result.contains("00000000000000000000000000000000")); // detecting bynary data in bytecode } } // TODO: add gas expeted and calculated to all test cases // TODO: considering: G_TXDATA + G_TRANSACTION /** * TODO: * * 22) CREATE: * 23) CALL: * * **/ /** contract creation (gas usage) ----------------------------- G_TRANSACTION = (500) 60016000546006601160003960066000f261778e600054 (115) PUSH1 6001 (1) PUSH1 6000 (1) MSTORE 54 (1 + 1) PUSH1 6006 (1) PUSH1 6011 (1) PUSH1 6000 (1) CODECOPY 39 (1) PUSH1 6006 (1) PUSH1 6000 (1) RETURN f2 (1) 61778e600054 */
27,685
90.072368
17,742
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/vm/BytecodeCompilerTest.java
/* * Copyright (c) [2018] [ <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.vm; import org.junit.Assert; import org.junit.Test; public class BytecodeCompilerTest { @Test public void compileSimpleOpcode() { BytecodeCompiler compiler = new BytecodeCompiler(); byte[] result = compiler.compile("ADD"); Assert.assertNotNull(result); Assert.assertEquals(1, result.length); Assert.assertEquals(1, result[0]); } @Test public void compileSimpleOpcodeWithSpaces() { BytecodeCompiler compiler = new BytecodeCompiler(); byte[] result = compiler.compile(" ADD "); Assert.assertNotNull(result); Assert.assertEquals(1, result.length); Assert.assertEquals(1, result[0]); } @Test public void compileTwoOpcodes() { BytecodeCompiler compiler = new BytecodeCompiler(); byte[] result = compiler.compile("ADD SUB"); Assert.assertNotNull(result); Assert.assertEquals(2, result.length); Assert.assertEquals(1, result[0]); Assert.assertEquals(3, result[1]); } @Test public void compileFourOpcodes() { BytecodeCompiler compiler = new BytecodeCompiler(); byte[] result = compiler.compile("ADD MUL SUB DIV"); Assert.assertNotNull(result); Assert.assertEquals(4, result.length); Assert.assertEquals(1, result[0]); Assert.assertEquals(2, result[1]); Assert.assertEquals(3, result[2]); Assert.assertEquals(4, result[3]); } @Test public void compileHexadecimalValueOneByte() { BytecodeCompiler compiler = new BytecodeCompiler(); byte[] result = compiler.compile("0x01"); Assert.assertNotNull(result); Assert.assertEquals(1, result.length); Assert.assertEquals(1, result[0]); } @Test public void compileHexadecimalValueTwoByte() { BytecodeCompiler compiler = new BytecodeCompiler(); byte[] result = compiler.compile("0x0102"); Assert.assertNotNull(result); Assert.assertEquals(2, result.length); Assert.assertEquals(1, result[0]); Assert.assertEquals(2, result[1]); } @Test public void compileSimpleOpcodeInLowerCase() { BytecodeCompiler compiler = new BytecodeCompiler(); byte[] result = compiler.compile("add"); Assert.assertNotNull(result); Assert.assertEquals(1, result.length); Assert.assertEquals(1, result[0]); } @Test public void compileSimpleOpcodeInMixedCase() { BytecodeCompiler compiler = new BytecodeCompiler(); byte[] result = compiler.compile("Add"); Assert.assertNotNull(result); Assert.assertEquals(1, result.length); Assert.assertEquals(1, result[0]); } }
3,558
29.418803
80
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/vm/VMCustomTest.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.vm; import org.ethereum.vm.program.Program; import org.ethereum.vm.program.Program.OutOfGasException; import org.ethereum.vm.program.Program.StackTooSmallException; import org.ethereum.vm.program.invoke.ProgramInvokeMockImpl; import org.junit.After; import org.junit.Before; import org.junit.Ignore; import org.junit.FixMethodOrder; import org.junit.Test; import org.junit.runners.MethodSorters; import org.spongycastle.util.encoders.Hex; import java.math.BigInteger; import static org.junit.Assert.*; /** * @author Roman Mandeleil * @since 01.06.2014 */ @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class VMCustomTest { private ProgramInvokeMockImpl invoke; private Program program; @Before public void setup() { byte[] ownerAddress = Hex.decode("77045E71A7A2C50903D88E564CD72FAB11E82051"); byte[] msgData = Hex.decode("00000000000000000000000000000000000000000000000000000000000000A1" + "00000000000000000000000000000000000000000000000000000000000000B1"); invoke = new ProgramInvokeMockImpl(msgData); invoke.setOwnerAddress(ownerAddress); invoke.getRepository().createAccount(ownerAddress); invoke.getRepository().addBalance(ownerAddress, BigInteger.valueOf(1000L)); } @After public void tearDown() { invoke.getRepository().close(); } @Test // CALLDATASIZE OP public void testCALLDATASIZE_1() { VM vm = new VM(); program = new Program(Hex.decode("36"), invoke); String s_expected_1 = "0000000000000000000000000000000000000000000000000000000000000040"; vm.step(program); DataWord item1 = program.stackPop(); assertEquals(s_expected_1, Hex.toHexString(item1.getData()).toUpperCase()); } @Test // CALLDATALOAD OP public void testCALLDATALOAD_1() { VM vm = new VM(); program = new Program(Hex.decode("600035"), invoke); String s_expected_1 = "00000000000000000000000000000000000000000000000000000000000000A1"; vm.step(program); vm.step(program); DataWord item1 = program.stackPop(); assertEquals(s_expected_1, Hex.toHexString(item1.getData()).toUpperCase()); } @Test // CALLDATALOAD OP public void testCALLDATALOAD_2() { VM vm = new VM(); program = new Program(Hex.decode("600235"), invoke); String s_expected_1 = "0000000000000000000000000000000000000000000000000000000000A10000"; vm.step(program); vm.step(program); DataWord item1 = program.stackPop(); assertEquals(s_expected_1, Hex.toHexString(item1.getData()).toUpperCase()); } @Test // CALLDATALOAD OP public void testCALLDATALOAD_3() { VM vm = new VM(); program = new Program(Hex.decode("602035"), invoke); String s_expected_1 = "00000000000000000000000000000000000000000000000000000000000000B1"; vm.step(program); vm.step(program); DataWord item1 = program.stackPop(); assertEquals(s_expected_1, Hex.toHexString(item1.getData()).toUpperCase()); } @Test // CALLDATALOAD OP public void testCALLDATALOAD_4() { VM vm = new VM(); program = new Program(Hex.decode("602335"), invoke); String s_expected_1 = "00000000000000000000000000000000000000000000000000000000B1000000"; vm.step(program); vm.step(program); DataWord item1 = program.stackPop(); assertEquals(s_expected_1, Hex.toHexString(item1.getData()).toUpperCase()); } @Test // CALLDATALOAD OP public void testCALLDATALOAD_5() { VM vm = new VM(); program = new Program(Hex.decode("603F35"), invoke); String s_expected_1 = "B100000000000000000000000000000000000000000000000000000000000000"; vm.step(program); vm.step(program); DataWord item1 = program.stackPop(); assertEquals(s_expected_1, Hex.toHexString(item1.getData()).toUpperCase()); } @Test(expected = RuntimeException.class) // CALLDATALOAD OP mal public void testCALLDATALOAD_6() { VM vm = new VM(); program = new Program(Hex.decode("35"), invoke); try { vm.step(program); } finally { assertTrue(program.isStopped()); } } @Test // CALLDATACOPY OP public void testCALLDATACOPY_1() { VM vm = new VM(); program = new Program(Hex.decode("60206000600037"), invoke); String m_expected = "00000000000000000000000000000000000000000000000000000000000000A1"; vm.step(program); vm.step(program); vm.step(program); vm.step(program); assertEquals(m_expected, Hex.toHexString(program.getMemory()).toUpperCase()); } @Test // CALLDATACOPY OP public void testCALLDATACOPY_2() { VM vm = new VM(); program = new Program(Hex.decode("60406000600037"), invoke); String m_expected = "00000000000000000000000000000000000000000000000000000000000000A1" + "00000000000000000000000000000000000000000000000000000000000000B1"; vm.step(program); vm.step(program); vm.step(program); vm.step(program); assertEquals(m_expected, Hex.toHexString(program.getMemory()).toUpperCase()); } @Test // CALLDATACOPY OP public void testCALLDATACOPY_3() { VM vm = new VM(); program = new Program(Hex.decode("60406004600037"), invoke); String m_expected = "000000000000000000000000000000000000000000000000000000A100000000" + "000000000000000000000000000000000000000000000000000000B100000000"; vm.step(program); vm.step(program); vm.step(program); vm.step(program); assertEquals(m_expected, Hex.toHexString(program.getMemory()).toUpperCase()); } @Test // CALLDATACOPY OP public void testCALLDATACOPY_4() { VM vm = new VM(); program = new Program(Hex.decode("60406000600437"), invoke); String m_expected = "0000000000000000000000000000000000000000000000000000000000000000" + "000000A100000000000000000000000000000000000000000000000000000000" + "000000B100000000000000000000000000000000000000000000000000000000"; vm.step(program); vm.step(program); vm.step(program); vm.step(program); assertEquals(m_expected, Hex.toHexString(program.getMemory()).toUpperCase()); } @Test // CALLDATACOPY OP public void testCALLDATACOPY_5() { VM vm = new VM(); program = new Program(Hex.decode("60406000600437"), invoke); String m_expected = "0000000000000000000000000000000000000000000000000000000000000000" + "000000A100000000000000000000000000000000000000000000000000000000" + "000000B100000000000000000000000000000000000000000000000000000000"; vm.step(program); vm.step(program); vm.step(program); vm.step(program); assertEquals(m_expected, Hex.toHexString(program.getMemory()).toUpperCase()); } @Test(expected = StackTooSmallException.class) // CALLDATACOPY OP mal public void testCALLDATACOPY_6() { VM vm = new VM(); program = new Program(Hex.decode("6040600037"), invoke); try { vm.step(program); vm.step(program); vm.step(program); } finally { assertTrue(program.isStopped()); } } @Test(expected = OutOfGasException.class) // CALLDATACOPY OP mal public void testCALLDATACOPY_7() { VM vm = new VM(); program = new Program(Hex.decode("6020600073CC0929EB16730E7C14FEFC63006AC2D794C5795637"), invoke); try { vm.step(program); vm.step(program); vm.step(program); vm.step(program); } finally { assertTrue(program.isStopped()); } } @Test // ADDRESS OP public void testADDRESS_1() { VM vm = new VM(); program = new Program(Hex.decode("30"), invoke); String s_expected_1 = "00000000000000000000000077045E71A7A2C50903D88E564CD72FAB11E82051"; vm.step(program); DataWord item1 = program.stackPop(); program.getStorage().close(); assertEquals(s_expected_1, Hex.toHexString(item1.getData()).toUpperCase()); } @Test // BALANCE OP public void testBALANCE_1() { VM vm = new VM(); program = new Program(Hex.decode("3031"), invoke); String s_expected_1 = "00000000000000000000000000000000000000000000000000000000000003E8"; vm.step(program); vm.step(program); DataWord item1 = program.stackPop(); assertEquals(s_expected_1, Hex.toHexString(item1.getData()).toUpperCase()); } @Test // ORIGIN OP public void testORIGIN_1() { VM vm = new VM(); program = new Program(Hex.decode("32"), invoke); String s_expected_1 = "00000000000000000000000013978AEE95F38490E9769C39B2773ED763D9CD5F"; vm.step(program); DataWord item1 = program.stackPop(); assertEquals(s_expected_1, Hex.toHexString(item1.getData()).toUpperCase()); } @Test // CALLER OP public void testCALLER_1() { VM vm = new VM(); program = new Program(Hex.decode("33"), invoke); String s_expected_1 = "000000000000000000000000885F93EED577F2FC341EBB9A5C9B2CE4465D96C4"; vm.step(program); DataWord item1 = program.stackPop(); assertEquals(s_expected_1, Hex.toHexString(item1.getData()).toUpperCase()); } @Test // CALLVALUE OP public void testCALLVALUE_1() { VM vm = new VM(); program = new Program(Hex.decode("34"), invoke); String s_expected_1 = "0000000000000000000000000000000000000000000000000DE0B6B3A7640000"; vm.step(program); DataWord item1 = program.stackPop(); assertEquals(s_expected_1, Hex.toHexString(item1.getData()).toUpperCase()); } @Test // SHA3 OP public void testSHA3_1() { VM vm = new VM(); program = new Program(Hex.decode("60016000536001600020"), invoke); String s_expected_1 = "5FE7F977E71DBA2EA1A68E21057BEEBB9BE2AC30C6410AA38D4F3FBE41DCFFD2"; vm.step(program); vm.step(program); vm.step(program); vm.step(program); vm.step(program); vm.step(program); DataWord item1 = program.stackPop(); assertEquals(s_expected_1, Hex.toHexString(item1.getData()).toUpperCase()); } @Test // SHA3 OP public void testSHA3_2() { VM vm = new VM(); program = new Program(Hex.decode("6102016000526002601E20"), invoke); String s_expected_1 = "114A3FE82A0219FCC31ABD15617966A125F12B0FD3409105FC83B487A9D82DE4"; vm.step(program); vm.step(program); vm.step(program); vm.step(program); vm.step(program); vm.step(program); DataWord item1 = program.stackPop(); assertEquals(s_expected_1, Hex.toHexString(item1.getData()).toUpperCase()); } @Test(expected = StackTooSmallException.class) // SHA3 OP mal public void testSHA3_3() { VM vm = new VM(); program = new Program(Hex.decode("610201600052600220"), invoke); try { vm.step(program); vm.step(program); vm.step(program); vm.step(program); vm.step(program); } finally { assertTrue(program.isStopped()); } } @Test // BLOCKHASH OP public void testBLOCKHASH_1() { VM vm = new VM(); program = new Program(Hex.decode("600140"), invoke); String s_expected_1 = "C89EFDAA54C0F20C7ADF612882DF0950F5A951637E0307CDCB4C672F298B8BC6"; vm.step(program); vm.step(program); DataWord item1 = program.stackPop(); assertEquals(s_expected_1, Hex.toHexString(item1.getData()).toUpperCase()); } @Test // COINBASE OP public void testCOINBASE_1() { VM vm = new VM(); program = new Program(Hex.decode("41"), invoke); String s_expected_1 = "000000000000000000000000E559DE5527492BCB42EC68D07DF0742A98EC3F1E"; vm.step(program); DataWord item1 = program.stackPop(); assertEquals(s_expected_1, Hex.toHexString(item1.getData()).toUpperCase()); } @Test // TIMESTAMP OP public void testTIMESTAMP_1() { VM vm = new VM(); program = new Program(Hex.decode("42"), invoke); String s_expected_1 = "000000000000000000000000000000000000000000000000000000005387FE24"; vm.step(program); DataWord item1 = program.stackPop(); assertEquals(s_expected_1, Hex.toHexString(item1.getData()).toUpperCase()); } @Test // NUMBER OP public void testNUMBER_1() { VM vm = new VM(); program = new Program(Hex.decode("43"), invoke); String s_expected_1 = "0000000000000000000000000000000000000000000000000000000000000021"; vm.step(program); DataWord item1 = program.stackPop(); assertEquals(s_expected_1, Hex.toHexString(item1.getData()).toUpperCase()); } @Test // DIFFICULTY OP public void testDIFFICULTY_1() { VM vm = new VM(); program = new Program(Hex.decode("44"), invoke); String s_expected_1 = "00000000000000000000000000000000000000000000000000000000003ED290"; vm.step(program); DataWord item1 = program.stackPop(); assertEquals(s_expected_1, Hex.toHexString(item1.getData()).toUpperCase()); } @Test // GASPRICE OP public void testGASPRICE_1() { VM vm = new VM(); program = new Program(Hex.decode("3A"), invoke); String s_expected_1 = "000000000000000000000000000000000000000000000000000009184E72A000"; vm.step(program); DataWord item1 = program.stackPop(); assertEquals(s_expected_1, Hex.toHexString(item1.getData()).toUpperCase()); } @Ignore //TODO #POC9 @Test // GAS OP public void testGAS_1() { VM vm = new VM(); program = new Program(Hex.decode("5A"), invoke); String s_expected_1 = "00000000000000000000000000000000000000000000000000000000000F423F"; vm.step(program); DataWord item1 = program.stackPop(); assertEquals(s_expected_1, Hex.toHexString(item1.getData()).toUpperCase()); } @Test // GASLIMIT OP public void testGASLIMIT_1() { VM vm = new VM(); program = new Program(Hex.decode("45"), invoke); String s_expected_1 = "00000000000000000000000000000000000000000000000000000000000F4240"; vm.step(program); DataWord item1 = program.stackPop(); assertEquals(s_expected_1, Hex.toHexString(item1.getData()).toUpperCase()); } @Test(expected = Program.IllegalOperationException.class) // INVALID OP public void testINVALID_1() { VM vm = new VM(); program = new Program(Hex.decode("60012F6002"), invoke); String s_expected_1 = "0000000000000000000000000000000000000000000000000000000000000001"; try { vm.step(program); vm.step(program); } finally { assertTrue(program.isStopped()); DataWord item1 = program.stackPop(); assertEquals(s_expected_1, Hex.toHexString(item1.getData()).toUpperCase()); } } /* TEST CASE LIST END */ } // TODO: add gas expeted and calculated to all test cases // TODO: considering: G_TXDATA + G_TRANSACTION /** * TODO: * * 22) CREATE: * 23) CALL: * * **/ /** contract creation (gas usage) ----------------------------- G_TRANSACTION = (500) 60016000546006601160003960066000f261778e600054 (115) PUSH1 6001 (1) PUSH1 6000 (1) MSTORE 54 (1 + 1) PUSH1 6006 (1) PUSH1 6011 (1) PUSH1 6000 (1) CODECOPY 39 (1) PUSH1 6006 (1) PUSH1 6000 (1) RETURN f2 (1) 61778e600054 */
17,339
28.691781
104
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/vm/VMComplexTest.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.vm; import org.ethereum.config.SystemProperties; import org.ethereum.core.AccountState; import org.ethereum.crypto.HashUtil; import org.ethereum.core.Repository; import org.ethereum.vm.program.Program; import org.ethereum.vm.program.invoke.ProgramInvokeMockImpl; import org.junit.FixMethodOrder; import org.junit.Ignore; import org.junit.Test; import org.junit.runners.MethodSorters; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.spongycastle.util.encoders.Hex; import java.math.BigInteger; import static org.junit.Assert.assertEquals; /** * @author Roman Mandeleil * @since 16.06.2014 */ @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class VMComplexTest { private static Logger logger = LoggerFactory.getLogger("TCK-Test"); @Ignore //TODO #POC9 @Test // contract call recursive public void test1() { /** * #The code will run * ------------------ a = contract.storage[999] if a > 0: contract.storage[999] = a - 1 # call to contract: 77045e71a7a2c50903d88e564cd72fab11e82051 send((tx.gas / 10 * 8), 0x77045e71a7a2c50903d88e564cd72fab11e82051, 0) else: stop */ int expectedGas = 436; DataWord key1 = DataWord.of(999); DataWord value1 = DataWord.of(3); // Set contract into Database String callerAddr = "cd2a3d9f938e13cd947ec05abc7fe734df8dd826"; String contractAddr = "77045e71a7a2c50903d88e564cd72fab11e82051"; String code = "6103e75460005260006000511115630000004c576001600051036103e755600060006000600060007377045e71a7a2c50903d88e564cd72fab11e820516008600a5a0402f1630000004c00565b00"; byte[] contractAddrB = Hex.decode(contractAddr); byte[] callerAddrB = Hex.decode(callerAddr); byte[] codeB = Hex.decode(code); byte[] codeKey = HashUtil.sha3(codeB); AccountState accountState = new AccountState(SystemProperties.getDefault()) .withCodeHash(codeKey); ProgramInvokeMockImpl pi = new ProgramInvokeMockImpl(); pi.setOwnerAddress(contractAddrB); Repository repository = pi.getRepository(); repository.createAccount(callerAddrB); repository.addBalance(callerAddrB, new BigInteger("100000000000000000000")); repository.createAccount(contractAddrB); repository.saveCode(contractAddrB, codeB); repository.addStorageRow(contractAddrB, key1, value1); // Play the program VM vm = new VM(); Program program = new Program(codeB, pi); try { while (!program.isStopped()) vm.step(program); } catch (RuntimeException e) { program.setRuntimeFailure(e); } System.out.println(); System.out.println("============ Results ============"); BigInteger balance = repository.getBalance(callerAddrB); System.out.println("*** Used gas: " + program.getResult().getGasUsed()); System.out.println("*** Contract Balance: " + balance); // todo: assert caller balance after contract exec repository.close(); assertEquals(expectedGas, program.getResult().getGasUsed()); } @Ignore //TODO #POC9 @Test // contractB call contractA with data to storage public void test2() { /** * #The code will run * ------------------ contract A: 77045e71a7a2c50903d88e564cd72fab11e82051 --------------- a = msg.data[0] b = msg.data[1] contract.storage[a] contract.storage[b] contract B: 83c5541a6c8d2dbad642f385d8d06ca9b6c731ee ----------- a = msg((tx.gas / 10 * 8), 0x77045e71a7a2c50903d88e564cd72fab11e82051, 0, [11, 22, 33], 3, 6) */ long expectedVal_1 = 11; long expectedVal_2 = 22; // Set contract into Database String callerAddr = "cd2a3d9f938e13cd947ec05abc7fe734df8dd826"; String contractA_addr = "77045e71a7a2c50903d88e564cd72fab11e82051"; String contractB_addr = "83c5541a6c8d2dbad642f385d8d06ca9b6c731ee"; String code_a = "60006020023560005260016020023560205260005160005560205160015500"; String code_b = "6000601f5360e05960e05952600060c05901536060596020015980602001600b9052806040016016905280606001602190526080905260007377045e71a7a2c50903d88e564cd72fab11e820516103e8f1602060000260a00160200151600052"; byte[] caller_addr_bytes = Hex.decode(callerAddr); byte[] contractA_addr_bytes = Hex.decode(contractA_addr); byte[] codeA = Hex.decode(code_a); byte[] contractB_addr_bytes = Hex.decode(contractB_addr); byte[] codeB = Hex.decode(code_b); ProgramInvokeMockImpl pi = new ProgramInvokeMockImpl(); pi.setOwnerAddress(contractB_addr_bytes); Repository repository = pi.getRepository(); repository.createAccount(contractA_addr_bytes); repository.saveCode(contractA_addr_bytes, codeA); repository.createAccount(contractB_addr_bytes); repository.saveCode(contractB_addr_bytes, codeB); repository.createAccount(caller_addr_bytes); repository.addBalance(caller_addr_bytes, new BigInteger("100000000000000000000")); // ****************** // // Play the program // // ****************** // VM vm = new VM(); Program program = new Program(codeB, pi); try { while (!program.isStopped()) vm.step(program); } catch (RuntimeException e) { program.setRuntimeFailure(e); } System.out.println(); System.out.println("============ Results ============"); System.out.println("*** Used gas: " + program.getResult().getGasUsed()); DataWord value_1 = repository.getStorageValue(contractA_addr_bytes, DataWord.of(00)); DataWord value_2 = repository.getStorageValue(contractA_addr_bytes, DataWord.of(01)); repository.close(); assertEquals(expectedVal_1, value_1.longValue()); assertEquals(expectedVal_2, value_2.longValue()); // TODO: check that the value pushed after exec is 1 } @Ignore @Test // contractB call contractA with return expectation public void test3() { /** * #The code will run * ------------------ contract A: 77045e71a7a2c50903d88e564cd72fab11e82051 --------------- a = 11 b = 22 c = 33 d = 44 e = 55 f = 66 [asm 192 0 RETURN asm] contract B: 83c5541a6c8d2dbad642f385d8d06ca9b6c731ee ----------- a = msg((tx.gas / 10 * 8), 0x77045e71a7a2c50903d88e564cd72fab11e82051, 0, [11, 22, 33], 3, 6) */ long expectedVal_1 = 11; long expectedVal_2 = 22; long expectedVal_3 = 33; long expectedVal_4 = 44; long expectedVal_5 = 55; long expectedVal_6 = 66; // Set contract into Database byte[] caller_addr_bytes = Hex.decode("cd2a3d9f938e13cd947ec05abc7fe734df8dd826"); byte[] contractA_addr_bytes = Hex.decode("77045e71a7a2c50903d88e564cd72fab11e82051"); byte[] contractB_addr_bytes = Hex.decode("83c5541a6c8d2dbad642f385d8d06ca9b6c731ee"); byte[] codeA = Hex.decode("600b60005260166020526021604052602c6060526037608052604260a05260c06000f2"); byte[] codeB = Hex.decode("6000601f5360e05960e05952600060c05901536060596020015980602001600b9052806040016016905280606001602190526080905260007377045e71a7a2c50903d88e564cd72fab11e820516103e8f1602060000260a00160200151600052"); ProgramInvokeMockImpl pi = new ProgramInvokeMockImpl(); pi.setOwnerAddress(contractB_addr_bytes); Repository repository = pi.getRepository(); repository.createAccount(contractA_addr_bytes); repository.saveCode(contractA_addr_bytes, codeA); repository.createAccount(contractB_addr_bytes); repository.saveCode(contractB_addr_bytes, codeB); repository.createAccount(caller_addr_bytes); repository.addBalance(caller_addr_bytes, new BigInteger("100000000000000000000")); // ****************** // // Play the program // // ****************** // VM vm = new VM(); Program program = new Program(codeB, pi); try { while (!program.isStopped()) vm.step(program); } catch (RuntimeException e) { program.setRuntimeFailure(e); } System.out.println(); System.out.println("============ Results ============"); System.out.println("*** Used gas: " + program.getResult().getGasUsed()); DataWord value1 = program.memoryLoad(DataWord.of(32)); DataWord value2 = program.memoryLoad(DataWord.of(64)); DataWord value3 = program.memoryLoad(DataWord.of(96)); DataWord value4 = program.memoryLoad(DataWord.of(128)); DataWord value5 = program.memoryLoad(DataWord.of(160)); DataWord value6 = program.memoryLoad(DataWord.of(192)); repository.close(); assertEquals(expectedVal_1, value1.longValue()); assertEquals(expectedVal_2, value2.longValue()); assertEquals(expectedVal_3, value3.longValue()); assertEquals(expectedVal_4, value4.longValue()); assertEquals(expectedVal_5, value5.longValue()); assertEquals(expectedVal_6, value6.longValue()); // TODO: check that the value pushed after exec is 1 } @Test // CREATE magic public void test4() { /** * #The code will run * ------------------ contract A: 77045e71a7a2c50903d88e564cd72fab11e82051 ----------- a = 0x7f60c860005461012c6020540000000000000000000000000000000000000000 b = 0x0060005460206000f20000000000000000000000000000000000000000000000 create(100, 0 41) contract B: (the contract to be created the addr will be defined to: 8e45367623a2865132d9bf875d5cfa31b9a0cd94) ----------- a = 200 b = 300 */ // Set contract into Database byte[] caller_addr_bytes = Hex.decode("cd2a3d9f938e13cd947ec05abc7fe734df8dd826"); byte[] contractA_addr_bytes = Hex.decode("77045e71a7a2c50903d88e564cd72fab11e82051"); byte[] codeA = Hex.decode("7f7f60c860005461012c602054000000000000" + "00000000000000000000000000006000547e60" + "005460206000f2000000000000000000000000" + "0000000000000000000000602054602960006064f0"); ProgramInvokeMockImpl pi = new ProgramInvokeMockImpl(); pi.setOwnerAddress(contractA_addr_bytes); Repository repository = pi.getRepository(); repository.createAccount(contractA_addr_bytes); repository.saveCode(contractA_addr_bytes, codeA); repository.createAccount(caller_addr_bytes); // ****************** // // Play the program // // ****************** // VM vm = new VM(); Program program = new Program(codeA, pi); try { while (!program.isStopped()) vm.step(program); } catch (RuntimeException e) { program.setRuntimeFailure(e); } logger.info("============ Results ============"); System.out.println("*** Used gas: " + program.getResult().getGasUsed()); // TODO: check that the value pushed after exec is the new address repository.close(); } @Test // CALL contract with too much gas @Ignore public void test5() { // TODO CALL contract with gas > gasRemaining && gas > Long.MAX_VALUE } @Ignore @Test // contractB call itself with code from contractA public void test6() { /** * #The code will run * ------------------ contract A: 945304eb96065b2a98b57a48a06ae28d285a71b5 --------------- PUSH1 0 CALLDATALOAD SLOAD NOT PUSH1 9 JUMPI STOP PUSH1 32 CALLDATALOAD PUSH1 0 CALLDATALOAD SSTORE contract B: 0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6 ----------- { (MSTORE 0 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff) (MSTORE 32 0xaaffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffaa) [[ 0 ]] (CALLSTATELESS 1000000 0x945304eb96065b2a98b57a48a06ae28d285a71b5 23 0 64 64 0) } */ // Set contract into Database byte[] caller_addr_bytes = Hex.decode("cd1722f3947def4cf144679da39c4c32bdc35681"); byte[] contractA_addr_bytes = Hex.decode("945304eb96065b2a98b57a48a06ae28d285a71b5"); byte[] contractB_addr_bytes = Hex.decode("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6"); byte[] codeA = Hex.decode("60003554156009570060203560003555"); byte[] codeB = Hex.decode("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6000527faaffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffaa6020526000604060406000601773945304eb96065b2a98b57a48a06ae28d285a71b5620f4240f3600055"); ProgramInvokeMockImpl pi = new ProgramInvokeMockImpl(); pi.setOwnerAddress(contractB_addr_bytes); pi.setGasLimit(10000000000000l); Repository repository = pi.getRepository(); repository.createAccount(contractA_addr_bytes); repository.saveCode(contractA_addr_bytes, codeA); repository.addBalance(contractA_addr_bytes, BigInteger.valueOf(23)); repository.createAccount(contractB_addr_bytes); repository.saveCode(contractB_addr_bytes, codeB); repository.addBalance(contractB_addr_bytes, new BigInteger("1000000000000000000")); repository.createAccount(caller_addr_bytes); repository.addBalance(caller_addr_bytes, new BigInteger("100000000000000000000")); // ****************** // // Play the program // // ****************** // VM vm = new VM(); Program program = new Program(codeB, pi); try { while (!program.isStopped()) vm.step(program); } catch (RuntimeException e) { program.setRuntimeFailure(e); } System.out.println(); System.out.println("============ Results ============"); System.out.println("*** Used gas: " + program.getResult().getGasUsed()); DataWord memValue1 = program.memoryLoad(DataWord.of(0)); DataWord memValue2 = program.memoryLoad(DataWord.of(32)); DataWord storeValue1 = repository.getStorageValue(contractB_addr_bytes, DataWord.of(00)); repository.close(); assertEquals("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", memValue1.toString()); assertEquals("aaffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffaa", memValue2.toString()); assertEquals("0x1", storeValue1.shortHex()); // TODO: check that the value pushed after exec is 1 } }
16,177
35.03118
260
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/vm/program/InternalTransactionTest.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.vm.program; import org.ethereum.vm.DataWord; import org.junit.Test; import java.util.Random; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; public class InternalTransactionTest { @Test public void testRlpEncoding() { byte[] parentHash = randomBytes(32); int deep = Integer.MAX_VALUE; int index = Integer.MAX_VALUE; byte[] nonce = randomBytes(2); DataWord gasPrice = DataWord.ZERO; DataWord gasLimit = DataWord.ZERO; byte[] sendAddress = randomBytes(20); byte[] receiveAddress = randomBytes(20); byte[] value = randomBytes(2); byte[] data = randomBytes(128); String note = "transaction note"; byte[] encoded = new InternalTransaction(parentHash, deep, index, nonce, gasPrice, gasLimit, sendAddress, receiveAddress, value, data, note).getEncoded(); InternalTransaction tx = new InternalTransaction(encoded); assertEquals(deep, tx.getDeep()); assertEquals(index, tx.getIndex()); assertArrayEquals(parentHash, tx.getParentHash()); assertArrayEquals(nonce, tx.getNonce()); assertArrayEquals(gasPrice.getData(), tx.getGasPrice()); assertArrayEquals(gasLimit.getData(), tx.getGasLimit()); assertArrayEquals(sendAddress, tx.getSender()); assertArrayEquals(receiveAddress, tx.getReceiveAddress()); assertArrayEquals(value, tx.getValue()); assertArrayEquals(data, tx.getData()); assertEquals(note, tx.getNote()); } private static byte[] randomBytes(int len) { byte[] bytes = new byte[len]; new Random().nextBytes(bytes); return bytes; } }
2,533
36.820896
162
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/jsontestsuite/GitHubStateTest.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.jsontestsuite; import org.ethereum.config.SystemProperties; import org.ethereum.config.net.MainNetConfig; import org.ethereum.jsontestsuite.suite.GeneralStateTestSuite; import org.junit.*; import org.junit.runners.MethodSorters; import java.io.IOException; import java.util.*; @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class GitHubStateTest { static String commitSHA = "253e99861fe406c7b1daf3d6a0c40906e8a8fd8f"; static String treeSHA = "51fd8f9969ff488917f0832c57ece01f66516db2"; // https://github.com/ethereum/tests/tree/develop/GeneralStateTests/ static GitHubJSONTestSuite.Network[] targetNets = { GitHubJSONTestSuite.Network.Frontier, GitHubJSONTestSuite.Network.Homestead, GitHubJSONTestSuite.Network.EIP150, GitHubJSONTestSuite.Network.EIP158, GitHubJSONTestSuite.Network.Byzantium, GitHubJSONTestSuite.Network.Constantinople }; static GeneralStateTestSuite suite; @BeforeClass public static void setup() throws IOException { suite = new GeneralStateTestSuite(treeSHA, commitSHA, targetNets); SystemProperties.getDefault().setRecordInternalTransactionsData(false); } @AfterClass public static void clean() { SystemProperties.getDefault().setBlockchainConfig(MainNetConfig.INSTANCE); SystemProperties.getDefault().setRecordInternalTransactionsData(true); } @Ignore @Test // this method is mostly for hands-on convenient testing // omit GeneralStateTestSuite initialization when use this method // it reduces impact on GitHub API public void stSingleTest() throws IOException { GeneralStateTestSuite.runSingle( "stPreCompiledContracts2/modexpRandomInput.json", commitSHA, GitHubJSONTestSuite.Network.Byzantium); } @Test public void stAttackTest() throws IOException { suite.runAll("stAttackTest"); } @Test public void stCallCodes() throws IOException { suite.runAll("stCallCodes"); } @Test public void stExample() throws IOException { suite.runAll("stExample"); } @Test public void stCallDelegateCodesCallCodeHomestead() throws IOException { suite.runAll("stCallDelegateCodesCallCodeHomestead"); } @Test public void stCallDelegateCodesHomestead() throws IOException { suite.runAll("stCallDelegateCodesHomestead"); } @Test public void stChangedEIP150() throws IOException { suite.runAll("stChangedEIP150"); } @Test public void stCallCreateCallCodeTest() throws IOException { Set<String> excluded = new HashSet<>(); excluded.add("CallRecursiveBombPreCall"); // Max Gas value is pending to be < 2^63 suite.runAll("stCallCreateCallCodeTest", excluded); } @Test public void stDelegatecallTestHomestead() throws IOException { suite.runAll("stDelegatecallTestHomestead"); } @Test public void stEIP150Specific() throws IOException { suite.runAll("stEIP150Specific"); } @Test public void stEIP150singleCodeGasPrices() throws IOException { suite.runAll("stEIP150singleCodeGasPrices"); } @Test public void stEIP158Specific() throws IOException { suite.runAll("stEIP158Specific"); } @Test public void stHomesteadSpecific() throws IOException { suite.runAll("stHomesteadSpecific"); } @Test public void stInitCodeTest() throws IOException { suite.runAll("stInitCodeTest"); } @Test public void stLogTests() throws IOException { suite.runAll("stLogTests"); } @Test public void stMemExpandingEIP150Calls() throws IOException { suite.runAll("stMemExpandingEIP150Calls"); } @Test public void stPreCompiledContracts() throws IOException { suite.runAll("stPreCompiledContracts"); } @Test public void stPreCompiledContracts2() throws IOException { suite.runAll("stPreCompiledContracts2"); } @Test public void stMemoryStressTest() throws IOException { Set<String> excluded = new HashSet<>(); excluded.add("mload32bitBound_return2");// The test extends memory to 4Gb which can't be handled with Java arrays excluded.add("mload32bitBound_return"); // The test extends memory to 4Gb which can't be handled with Java arrays excluded.add("mload32bitBound_Msize"); // The test extends memory to 4Gb which can't be handled with Java arrays suite.runAll("stMemoryStressTest", excluded); } @Test public void stMemoryTest() throws IOException { suite.runAll("stMemoryTest"); } @Test public void stQuadraticComplexityTest() throws IOException { // leaving only Homestead version since the test runs too long suite.runAll("stQuadraticComplexityTest", GitHubJSONTestSuite.Network.Homestead); } @Test public void stSolidityTest() throws IOException { suite.runAll("stSolidityTest"); } @Test public void stRecursiveCreate() throws IOException { suite.runAll("stRecursiveCreate"); } @Test public void stRefundTest() throws IOException { suite.runAll("stRefundTest"); } @Test public void stReturnDataTest() throws IOException { suite.runAll("stReturnDataTest"); } @Test public void stRevertTest() throws IOException { suite.runAll("stRevertTest"); } @Test public void stSpecialTest() throws IOException { suite.runAll("stSpecialTest"); } @Test public void stStackTests() throws IOException { suite.runAll("stStackTests"); } @Test public void stStaticCall() throws IOException { suite.runAll("stStaticCall"); } @Test public void stSystemOperationsTest() throws IOException { suite.runAll("stSystemOperationsTest"); } @Test public void stTransactionTest() throws IOException { // TODO enable when zero sig Txes comes in suite.runAll("stTransactionTest", new HashSet<>(Arrays.asList( "zeroSigTransactionCreate", "zeroSigTransactionCreatePrice0", "zeroSigTransacrionCreatePrice0", "zeroSigTransaction", "zeroSigTransaction0Price", "zeroSigTransactionInvChainID", "zeroSigTransactionInvNonce", "zeroSigTransactionInvNonce2", "zeroSigTransactionOOG", "zeroSigTransactionOrigin", "zeroSigTransactionToZero", "zeroSigTransactionToZero2" ))); } @Test public void stTransitionTest() throws IOException { suite.runAll("stTransitionTest"); } @Test public void stWalletTest() throws IOException { suite.runAll("stWalletTest"); } @Test public void stZeroCallsRevert() throws IOException { suite.runAll("stZeroCallsRevert"); } @Test public void stCreateTest() throws IOException { suite.runAll("stCreateTest"); } @Test public void stZeroCallsTest() throws IOException { suite.runAll("stZeroCallsTest"); } @Test public void stZeroKnowledge() throws IOException { suite.runAll("stZeroKnowledge"); } @Test public void stZeroKnowledge2() throws IOException { suite.runAll("stZeroKnowledge2"); } @Test public void stCodeSizeLimit() throws IOException { suite.runAll("stCodeSizeLimit"); } @Test public void stRandom() throws IOException { suite.runAll("stRandom"); } @Test public void stRandom2() throws IOException { suite.runAll("stRandom2"); } @Test public void stBadOpcode() throws IOException { suite.runAll("stBadOpcode"); } @Test public void stNonZeroCallsTest() throws IOException { suite.runAll("stNonZeroCallsTest"); } @Test public void stCodeCopyTest() throws IOException { suite.runAll("stCodeCopyTest"); } @Test public void stExtCodeHashTest() throws IOException { suite.runAll("stExtCodeHash"); } @Test public void stShiftTest() throws IOException { suite.runAll("stShift"); } @Test public void stCreate2Test() throws IOException { suite.runAll("stCreate2"); } @Test public void stSstoreTest() throws IOException { suite.runAll("stSStoreTest"); } }
9,388
27.800613
140
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/jsontestsuite/GitHubPowTest.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.jsontestsuite; import org.ethereum.core.BlockHeader; import org.ethereum.jsontestsuite.suite.EthashTestCase; import org.ethereum.jsontestsuite.suite.EthashTestSuite; import org.ethereum.jsontestsuite.suite.JSONReader; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.IOException; import static org.junit.Assert.assertArrayEquals; /** * @author Mikhail Kalinin * @since 03.09.2015 */ public class GitHubPowTest { private static final Logger logger = LoggerFactory.getLogger("TCK-Test"); public String shacommit = "253e99861fe406c7b1daf3d6a0c40906e8a8fd8f"; @Test public void runEthashTest() throws IOException { String json = JSONReader.loadJSONFromCommit("PoWTests/ethash_tests.json", shacommit); EthashTestSuite testSuite = new EthashTestSuite(json); for (EthashTestCase testCase : testSuite.getTestCases()) { logger.info("Running {}\n", testCase.getName()); BlockHeader header = testCase.getBlockHeader(); assertArrayEquals(testCase.getResultBytes(), header.calcPowValue()); } } }
1,944
31.966102
93
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/jsontestsuite/GitHubJSONTestSuite.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.jsontestsuite; import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.ObjectMapper; import org.ethereum.config.BlockchainNetConfig; import org.ethereum.config.SystemProperties; import org.ethereum.config.blockchain.*; import org.ethereum.config.net.BaseNetConfig; import org.ethereum.config.net.MainNetConfig; import org.ethereum.core.BlockHeader; import org.ethereum.jsontestsuite.suite.*; import org.ethereum.jsontestsuite.suite.runners.TransactionTestRunner; import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; import org.json.simple.parser.ParseException; import org.junit.Assert; import org.junit.Assume; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.IOException; import java.util.*; import static org.junit.Assert.assertEquals; /** * Test file specific for tests maintained in the GitHub repository * by the Ethereum DEV team. <br/> * * @see <a href="https://github.com/ethereum/tests/">https://github.com/ethereum/tests/</a> */ public class GitHubJSONTestSuite { private static Logger logger = LoggerFactory.getLogger("TCK-Test"); protected static void runGitHubJsonVMTest(String json, String testName) throws ParseException { Assume.assumeFalse("Online test is not available", json.isEmpty()); JSONParser parser = new JSONParser(); JSONObject testSuiteObj = (JSONObject) parser.parse(json); TestSuite testSuite = new TestSuite(testSuiteObj); Iterator<TestCase> testIterator = testSuite.iterator(); for (TestCase testCase : testSuite.getAllTests()) { String prefix = " "; if (testName.equals(testCase.getName())) prefix = " => "; logger.info(prefix + testCase.getName()); } while (testIterator.hasNext()) { TestCase testCase = testIterator.next(); if (testName.equals((testCase.getName()))) { TestRunner runner = new TestRunner(); List<String> result = runner.runTestCase(testCase); Assert.assertTrue(result.isEmpty()); return; } } } public static void runGitHubJsonVMTest(String json) throws ParseException { Assume.assumeFalse("Online test is not available", json.isEmpty()); JSONParser parser = new JSONParser(); JSONObject testSuiteObj = (JSONObject) parser.parse(json); TestSuite testSuite = new TestSuite(testSuiteObj); Iterator<TestCase> testIterator = testSuite.iterator(); while (testIterator.hasNext()) { TestCase testCase = testIterator.next(); TestRunner runner = new TestRunner(); List<String> result = runner.runTestCase(testCase); try { Assert.assertTrue(result.isEmpty()); } catch (AssertionError e) { System.out.println(String.format("Error on running testcase %s : %s", testCase.getName(), result.get(0))); throw e; } } } protected static void runGitHubJsonSingleBlockTest(String json, String testName) throws ParseException, IOException { BlockTestSuite testSuite = new BlockTestSuite(json); Set<String> testCollection = testSuite.getTestCases().keySet(); for (String testCase : testCollection) { if (testCase.equals(testName)) logger.info(" => " + testCase); else logger.info(" " + testCase); } runSingleBlockTest(testSuite, testName); } protected static void runGitHubJsonBlockTest(String json, Set<String> excluded) throws ParseException, IOException { Assume.assumeFalse("Online test is not available", json.isEmpty()); BlockTestSuite testSuite = new BlockTestSuite(json); Set<String> testCases = testSuite.getTestCases().keySet(); Map<String, Boolean> summary = new HashMap<>(); for (String testCase : testCases) if ( excluded.contains(testCase)) logger.info(" [X] " + testCase); else logger.info(" " + testCase); for (String testName : testCases) { if ( excluded.contains(testName)) { logger.info(" Not running: " + testName); continue; } List<String> result = runSingleBlockTest(testSuite, testName); if (!result.isEmpty()) summary.put(testName, false); else summary.put(testName, true); } logger.info(""); logger.info(""); logger.info("Summary: "); logger.info("========="); int fails = 0; int pass = 0; for (String key : summary.keySet()){ if (summary.get(key)) ++pass; else ++fails; String sumTest = String.format("%-60s:^%s", key, (summary.get(key) ? "OK" : "FAIL")). replace(' ', '.'). replace("^", " "); logger.info(sumTest); } logger.info(" - Total: Pass: {}, Failed: {} - ", pass, fails); Assert.assertTrue(fails == 0); } protected static void runGitHubJsonBlockTest(String json) throws ParseException, IOException { Set<String> excluded = new HashSet<>(); runGitHubJsonBlockTest(json, excluded); } private static List<String> runSingleBlockTest(BlockTestSuite testSuite, String testName){ BlockTestCase blockTestCase = testSuite.getTestCases().get(testName); TestRunner runner = new TestRunner(); logger.info("\n\n ***************** Running test: {} ***************************** \n\n", testName); List<String> result = runner.runTestCase(blockTestCase); logger.info("--------- POST Validation---------"); if (!result.isEmpty()) for (String single : result) logger.info(single); return result; } public static void runGitHubJsonTransactionTest(String json) throws IOException { TransactionTestSuite transactionTestSuite = new TransactionTestSuite(json); Map<String, TransactionTestCase> testCases = transactionTestSuite.getTestCases(); Map<String, Boolean> summary = new HashMap<>(); Set<String> testNames = transactionTestSuite.getTestCases().keySet(); for (String testName : testNames){ String output = String.format("* running: %s *", testName); String line = output.replaceAll(".", "*"); logger.info(line); logger.info(output); logger.info(line); logger.info("==> Running test case: {}", testName); List<String> result = TransactionTestRunner.run(testCases.get(testName)); if (!result.isEmpty()) summary.put(testName, false); else summary.put(testName, true); } logger.info("Summary: "); logger.info("========="); int fails = 0; int pass = 0; for (String key : summary.keySet()){ if (summary.get(key)) ++pass; else ++fails; String sumTest = String.format("%-60s:^%s", key, (summary.get(key) ? "OK" : "FAIL")). replace(' ', '.'). replace("^", " "); logger.info(sumTest); } logger.info(" - Total: Pass: {}, Failed: {} - ", pass, fails); Assert.assertTrue(fails == 0); } static void runDifficultyTest(BlockchainNetConfig config, String file, String commitSHA) throws IOException { String json = JSONReader.loadJSONFromCommit(file, commitSHA); DifficultyTestSuite testSuite = new DifficultyTestSuite(json); SystemProperties.getDefault().setBlockchainConfig(config); try { for (DifficultyTestCase testCase : testSuite.getTestCases()) { logger.info("Running {}\n", testCase.getName()); BlockHeader current = testCase.getCurrent(); BlockHeader parent = testCase.getParent(); assertEquals(testCase.getExpectedDifficulty(), current.calcDifficulty (SystemProperties.getDefault().getBlockchainConfig(), parent)); } } finally { SystemProperties.getDefault().setBlockchainConfig(MainNetConfig.INSTANCE); } } static void runCryptoTest(String file, String commitSHA) throws IOException { String json = JSONReader.loadJSONFromCommit(file, commitSHA); ObjectMapper mapper = new ObjectMapper(); JavaType type = mapper.getTypeFactory(). constructMapType(HashMap.class, String.class, CryptoTestCase.class); HashMap<String , CryptoTestCase> testSuite = mapper.readValue(json, type); for (String key : testSuite.keySet()){ logger.info("executing: " + key); testSuite.get(key).execute(); } } static void runTrieTest(String file, String commitSHA, boolean secure) throws IOException { String json = JSONReader.loadJSONFromCommit(file, commitSHA); TrieTestSuite testSuite = new TrieTestSuite(json); for (TrieTestCase testCase : testSuite.getTestCases()) { logger.info("Running {}\n", testCase.getName()); String expectedRoot = testCase.getRoot(); String actualRoot = testCase.calculateRoot(secure); assertEquals(expectedRoot, actualRoot); } } static void runABITest(String file, String commitSHA) throws IOException { String json = JSONReader.loadJSONFromCommit(file, commitSHA); ABITestSuite testSuite = new ABITestSuite(json); for (ABITestCase testCase : testSuite.getTestCases()) { logger.info("Running {}\n", testCase.getName()); String expected = testCase.getResult(); String actual = testCase.getEncoded(); assertEquals(expected, actual); } } public enum Network { Frontier, Homestead, EIP150, EIP158, Byzantium, Constantinople, ConstantinopleFix, // Transition networks FrontierToHomesteadAt5, HomesteadToDaoAt5, HomesteadToEIP150At5, EIP158ToByzantiumAt5, ByzantiumToConstantinopleAt5, ByzantiumToConstantinopleFixAt5; public BlockchainNetConfig getConfig() { switch (this) { case Frontier: return new FrontierConfig(); case Homestead: return new HomesteadConfig(); case EIP150: return new Eip150HFConfig(new DaoHFConfig()); case EIP158: return new Eip160HFConfig(new DaoHFConfig()); case Byzantium: return new ByzantiumConfig(new DaoHFConfig()); case Constantinople: return new ConstantinopleConfig(new DaoHFConfig()); case ConstantinopleFix: return new PetersburgConfig(new DaoHFConfig()); case FrontierToHomesteadAt5: return new BaseNetConfig() {{ add(0, new FrontierConfig()); add(5, new HomesteadConfig()); }}; case HomesteadToDaoAt5: return new BaseNetConfig() {{ add(0, new HomesteadConfig()); add(5, new DaoHFConfig(new HomesteadConfig(), 5)); }}; case HomesteadToEIP150At5: return new BaseNetConfig() {{ add(0, new HomesteadConfig()); add(5, new Eip150HFConfig(new HomesteadConfig())); }}; case EIP158ToByzantiumAt5: return new BaseNetConfig() {{ add(0, new Eip160HFConfig(new HomesteadConfig())); add(5, new ByzantiumConfig(new HomesteadConfig())); }}; case ByzantiumToConstantinopleAt5: return new BaseNetConfig() {{ add(0, new ByzantiumConfig(new HomesteadConfig())); add(5, new ConstantinopleConfig(new HomesteadConfig())); }}; case ByzantiumToConstantinopleFixAt5: return new BaseNetConfig() {{ add(0, new ByzantiumConfig(new HomesteadConfig())); add(5, new PetersburgConfig(new HomesteadConfig())); }}; default: throw new IllegalArgumentException("Unknown network value: " + this.name()); } } } }
13,392
34.431217
122
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/jsontestsuite/GitHubBlockStateTest.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.jsontestsuite; import org.ethereum.config.SystemProperties; import org.ethereum.config.net.MainNetConfig; import org.ethereum.jsontestsuite.suite.BlockchainTestSuite; import org.ethereum.jsontestsuite.suite.GeneralStateTestSuite; import org.junit.*; import org.junit.runners.MethodSorters; import java.io.IOException; import java.util.Arrays; import java.util.HashSet; import java.util.Set; @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class GitHubBlockStateTest { static String commitSHA = "253e99861fe406c7b1daf3d6a0c40906e8a8fd8f"; static String treeSHA = "724427f69f5573ed0f504a534b3ecbcd3070fa28"; // https://github.com/ethereum/tests/tree/develop/BlockchainTests/GeneralStateTests/ static GitHubJSONTestSuite.Network[] targetNets = { GitHubJSONTestSuite.Network.Frontier, GitHubJSONTestSuite.Network.Homestead, GitHubJSONTestSuite.Network.EIP150, GitHubJSONTestSuite.Network.EIP158, GitHubJSONTestSuite.Network.Byzantium, GitHubJSONTestSuite.Network.Constantinople }; static BlockchainTestSuite suite; @BeforeClass public static void setup() throws IOException { suite = new BlockchainTestSuite(treeSHA, commitSHA, targetNets); suite.setSubDir("GeneralStateTests/"); SystemProperties.getDefault().setRecordInternalTransactionsData(false); } @AfterClass public static void clean() { SystemProperties.getDefault().setBlockchainConfig(MainNetConfig.INSTANCE); SystemProperties.getDefault().setRecordInternalTransactionsData(true); } @Test @Ignore // this method is mostly for hands-on convenient testing // using this method turn off initializing of BlockchainTestSuite to avoid unnecessary GitHub API hits public void bcStSingle() throws IOException { BlockchainTestSuite.runSingle( "GeneralStateTests/stRandom/randomStatetest642_d0g0v0.json", commitSHA, GitHubJSONTestSuite.Network.Byzantium); } @Test public void bcStAttackTest() throws IOException { suite.runAll("stAttackTest"); } @Test public void bcStCallCodes() throws IOException { suite.runAll("stCallCodes"); } @Test public void bcStExample() throws IOException { suite.runAll("stExample"); } @Test public void bcStCallDelegateCodesCallCodeHomestead() throws IOException { suite.runAll("stCallDelegateCodesCallCodeHomestead"); } @Test public void bcStCallDelegateCodesHomestead() throws IOException { suite.runAll("stCallDelegateCodesHomestead"); } @Test public void bcStChangedEIP150() throws IOException { suite.runAll("stChangedEIP150"); } @Test public void bcStCallCreateCallCodeTest() throws IOException { suite.runAll("stCallCreateCallCodeTest"); } @Test public void bcStDelegatecallTestHomestead() throws IOException { suite.runAll("stDelegatecallTestHomestead"); } @Test public void bcStEIP150Specific() throws IOException { suite.runAll("stEIP150Specific"); } @Test public void bcStEIP150singleCodeGasPrices() throws IOException { suite.runAll("stEIP150singleCodeGasPrices"); } @Test public void bcStEIP158Specific() throws IOException { suite.runAll("stEIP158Specific"); } @Test public void bcStHomesteadSpecific() throws IOException { suite.runAll("stHomesteadSpecific"); } @Test public void bcStInitCodeTest() throws IOException { suite.runAll("stInitCodeTest"); } @Test public void bcStLogTests() throws IOException { suite.runAll("stLogTests"); } @Test public void bcStMemExpandingEIP150Calls() throws IOException { suite.runAll("stMemExpandingEIP150Calls"); } @Test public void bcStPreCompiledContracts() throws IOException { suite.runAll("stPreCompiledContracts"); } @Test public void bcStPreCompiledContracts2() throws IOException { suite.runAll("stPreCompiledContracts2"); } @Test public void bcStMemoryStressTest() throws IOException { Set<String> excluded = new HashSet<>(); excluded.add("mload32bitBound_return2");// The test extends memory to 4Gb which can't be handled with Java arrays excluded.add("mload32bitBound_return"); // The test extends memory to 4Gb which can't be handled with Java arrays excluded.add("mload32bitBound_Msize"); // The test extends memory to 4Gb which can't be handled with Java arrays suite.runAll("stMemoryStressTest", excluded); } @Test public void bcStMemoryTest() throws IOException { suite.runAll("stMemoryTest"); } @Test public void bcStQuadraticComplexityTest() throws IOException { // leaving only Homestead version since the test runs too long suite.runAll("stQuadraticComplexityTest", GitHubJSONTestSuite.Network.Homestead); } @Test public void bcStSolidityTest() throws IOException { suite.runAll("stSolidityTest"); } @Test public void bcStRecursiveCreate() throws IOException { suite.runAll("stRecursiveCreate"); } @Test public void bcStRefundTest() throws IOException { suite.runAll("stRefundTest"); } @Test public void bcStReturnDataTest() throws IOException { suite.runAll("stReturnDataTest"); } @Test public void bcStRevertTest() throws IOException { suite.runAll("stRevertTest"); } @Test public void bcStSpecialTest() throws IOException { suite.runAll("stSpecialTest"); } @Test public void bcStStackTests() throws IOException { suite.runAll("stStackTests"); } @Test public void bcStStaticCall() throws IOException { suite.runAll("stStaticCall"); } @Test public void bcStSystemOperationsTest() throws IOException { suite.runAll("stSystemOperationsTest"); } @Test public void bcStTransactionTest() throws IOException { // TODO enable when zero sig Txes comes in suite.runAll("stTransactionTest", new HashSet<>(Arrays.asList( "zeroSigTransacrionCreate", "zeroSigTransacrionCreatePrice0", "zeroSigTransaction", "zeroSigTransaction0Price", "zeroSigTransactionInvChainID", "zeroSigTransactionInvNonce", "zeroSigTransactionInvNonce2", "zeroSigTransactionOOG", "zeroSigTransactionOrigin", "zeroSigTransactionToZero", "zeroSigTransactionToZero2" ))); } @Test public void bcStTransitionTest() throws IOException { suite.runAll("stTransitionTest"); } @Test public void bcStWalletTest() throws IOException { suite.runAll("stWalletTest"); } @Test public void bcStZeroCallsRevert() throws IOException { suite.runAll("stZeroCallsRevert"); } @Test public void bcStCreateTest() throws IOException { suite.runAll("stCreateTest"); } @Test public void bcStZeroCallsTest() throws IOException { suite.runAll("stZeroCallsTest"); } @Test public void bcStZeroKnowledge() throws IOException { suite.runAll("stZeroKnowledge"); } @Test public void bcStZeroKnowledge2() throws IOException { suite.runAll("stZeroKnowledge2"); } @Test public void bcStCodeSizeLimit() throws IOException { suite.runAll("stCodeSizeLimit"); } @Test public void bcStRandom() throws IOException { suite.runAll("stRandom"); } @Test public void bcStRandom2() throws IOException { suite.runAll("stRandom2"); } @Test public void stBadOpcode() throws IOException { suite.runAll("stBadOpcode"); } @Test public void stNonZeroCallsTest() throws IOException { suite.runAll("stNonZeroCallsTest"); } @Test public void stCodeCopyTest() throws IOException { suite.runAll("stCodeCopyTest"); } @Test public void stExtCodeHash() throws IOException { suite.runAll("stExtCodeHash"); } @Test public void stShiftTest() throws IOException { suite.runAll("stShift"); } @Test public void stCreate2Test() throws IOException { suite.runAll("stCreate2"); } @Test public void stSstoreTest() throws IOException { suite.runAll("stSStoreTest"); } }
9,449
28.166667
156
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/jsontestsuite/GitHubTransactionTest.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.jsontestsuite; import org.ethereum.config.SystemProperties; import org.ethereum.config.net.MainNetConfig; import org.ethereum.jsontestsuite.suite.TxTestSuite; import org.json.simple.parser.ParseException; import org.junit.*; import org.junit.runners.MethodSorters; import java.io.IOException; import java.util.Arrays; import java.util.HashSet; @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class GitHubTransactionTest { static String commitSHA = "253e99861fe406c7b1daf3d6a0c40906e8a8fd8f"; static String treeSHA = "8c0d8131cb772b572862f0d88e778830bfddb006"; // https://github.com/ethereum/tests/tree/develop/TransactionTests/ static TxTestSuite suite; @BeforeClass public static void setup() throws IOException { suite = new TxTestSuite(treeSHA, commitSHA); SystemProperties.getDefault().setBlockchainConfig(new MainNetConfig()); } @After public void recover() { SystemProperties.getDefault().setBlockchainConfig(new MainNetConfig()); } @Test public void ttAddress() throws IOException, ParseException { suite.runAll("ttAddress"); } @Test public void ttData() throws IOException, ParseException { suite.run("ttData", new HashSet<>(Arrays.asList( "String10MbData" // too big to run it each time ))); } @Test public void ttGasLimit() throws IOException, ParseException { suite.runAll("ttGasLimit"); } @Test public void ttGasPrice() throws IOException, ParseException { suite.runAll("ttGasPrice"); } @Test public void ttNonce() throws IOException, ParseException { suite.runAll("ttNonce"); } @Test public void ttRSValue() throws IOException, ParseException { suite.runAll("ttRSValue"); } @Test public void ttVValue() throws IOException, ParseException { suite.runAll("ttVValue"); } @Test public void ttSignature() throws IOException, ParseException { suite.runAll("ttSignature"); } @Test public void ttValue() throws IOException, ParseException { suite.runAll("ttValue"); } @Test public void ttWrongRLP() throws IOException, ParseException { suite.runAll("ttWrongRLP"); } }
3,094
29.343137
140
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/jsontestsuite/GitHubBasicTest.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.jsontestsuite; import org.ethereum.config.blockchain.*; import org.ethereum.config.net.MainNetConfig; import org.ethereum.config.net.RopstenNetConfig; import org.json.simple.parser.ParseException; import org.junit.FixMethodOrder; import org.junit.Ignore; import org.junit.Test; import org.junit.runners.MethodSorters; import java.io.IOException; import static org.ethereum.jsontestsuite.GitHubJSONTestSuite.runCryptoTest; import static org.ethereum.jsontestsuite.GitHubJSONTestSuite.runDifficultyTest; /** * @author Mikhail Kalinin * @since 02.09.2015 */ @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class GitHubBasicTest { String commitSHA = "253e99861fe406c7b1daf3d6a0c40906e8a8fd8f"; @Test public void btCrypto() throws IOException { runCryptoTest("BasicTests/crypto.json", commitSHA); } @Test public void btDifficulty() throws IOException, ParseException { runDifficultyTest(MainNetConfig.INSTANCE, "BasicTests/difficulty.json", commitSHA); } @Test public void btDifficultyByzantium() throws IOException, ParseException { runDifficultyTest(new ByzantiumConfig(new DaoHFConfig()), "BasicTests/difficultyByzantium.json", commitSHA); } @Test public void btDifficultyConstantinople() throws IOException, ParseException { runDifficultyTest(new ConstantinopleConfig(new DaoHFConfig()), "BasicTests/difficultyConstantinople.json", commitSHA); } @Test @Ignore // due to CPP minimumDifficulty issue public void btDifficultyCustomHomestead() throws IOException, ParseException { runDifficultyTest(new HomesteadConfig(), "BasicTests/difficultyCustomHomestead.json", commitSHA); } @Test @Ignore // due to CPP minimumDifficulty issue public void btDifficultyCustomMainNetwork() throws IOException, ParseException { runDifficultyTest(MainNetConfig.INSTANCE, "BasicTests/difficultyCustomMainNetwork.json", commitSHA); } @Test public void btDifficultyFrontier() throws IOException, ParseException { runDifficultyTest(new FrontierConfig(), "BasicTests/difficultyFrontier.json", commitSHA); } @Test public void btDifficultyHomestead() throws IOException, ParseException { runDifficultyTest(new HomesteadConfig(), "BasicTests/difficultyHomestead.json", commitSHA); } @Test public void btDifficultyMainNetwork() throws IOException, ParseException { runDifficultyTest(MainNetConfig.INSTANCE, "BasicTests/difficultyMainNetwork.json", commitSHA); } @Test @Ignore("Disable Ropsten until tests are updated with correct difficulty") public void btDifficultyRopsten() throws IOException, ParseException { runDifficultyTest(new RopstenNetConfig(), "BasicTests/difficultyRopsten.json", commitSHA); } }
3,630
36.822917
126
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/jsontestsuite/GitHubRLPTest.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.jsontestsuite; import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.ObjectMapper; import org.ethereum.jsontestsuite.suite.JSONReader; import org.ethereum.jsontestsuite.suite.RLPTestCase; import org.json.simple.parser.ParseException; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.FixMethodOrder; import org.junit.Test; import org.junit.runners.MethodSorters; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.IOException; import java.util.*; @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class GitHubRLPTest { private static final Logger logger = LoggerFactory.getLogger("TCK-Test"); private static Map<String , RLPTestCase> TEST_SUITE = new HashMap<>(); private static String commitSHA = "develop"; @BeforeClass public static void init() throws ParseException, IOException { logger.info(" Initializing RLP tests..."); ObjectMapper mapper = new ObjectMapper(); JavaType type = mapper.getTypeFactory(). constructMapType(HashMap.class, String.class, RLPTestCase.class); List<String> files = Arrays.asList( "RLPTests/rlptest.json", "RLPTests/invalidRLPTest.json", "RLPTests/RandomRLPTests/example.json" ); List<String> jsons = JSONReader.loadJSONsFromCommit(files, commitSHA); for (String json : jsons) { Map<String, RLPTestCase> cases = mapper.readValue(json, type); TEST_SUITE.putAll(cases); } } @Test public void rlpEncodeTest() throws Exception { logger.info(" Testing RLP encoding..."); for (String key : TEST_SUITE.keySet()) { logger.info(" " + key); RLPTestCase testCase = TEST_SUITE.get(key); testCase.doEncode(); Assert.assertEquals(testCase.getExpected(), testCase.getComputed()); } } @Test public void rlpDecodeTest() throws Exception { logger.info(" Testing RLP decoding..."); Set<String> excluded = new HashSet<>(); for (String key : TEST_SUITE.keySet()) { if ( excluded.contains(key)) { logger.info("[X] " + key); continue; } else { logger.info(" " + key); } RLPTestCase testCase = TEST_SUITE.get(key); testCase.doDecode(); Assert.assertEquals(testCase.getExpected(), testCase.getComputed()); } } }
3,374
33.438776
81
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/jsontestsuite/GithubTrieTest.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.jsontestsuite; import org.junit.FixMethodOrder; import org.junit.Test; import org.junit.runners.MethodSorters; import java.io.IOException; import static org.ethereum.jsontestsuite.GitHubJSONTestSuite.runTrieTest; /** * @author Mikhail Kalinin * @since 28.09.2017 */ @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class GithubTrieTest { String commitSHA = "253e99861fe406c7b1daf3d6a0c40906e8a8fd8f"; @Test public void hexEncodedSecureTrieTest() throws IOException { runTrieTest("TrieTests/hex_encoded_securetrie_test.json", commitSHA, true); } @Test public void trieAnyOrder() throws IOException { runTrieTest("TrieTests/trieanyorder.json", commitSHA, false); } @Test public void trieAnyOrderSecureTrie() throws IOException { runTrieTest("TrieTests/trieanyorder_secureTrie.json", commitSHA, true); } @Test public void trieTest() throws IOException { runTrieTest("TrieTests/trietest.json", commitSHA, false); } @Test public void trieTestSecureTrie() throws IOException { runTrieTest("TrieTests/trietest_secureTrie.json", commitSHA, true); } }
1,975
30.870968
83
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/jsontestsuite/GitHubTestNetTest.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.jsontestsuite; import org.ethereum.jsontestsuite.GitHubJSONTestSuite.Network; import org.ethereum.jsontestsuite.suite.BlockchainTestSuite; import org.junit.*; import org.junit.runners.MethodSorters; import java.io.IOException; @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class GitHubTestNetTest { static String commitSHA = "725dbc73a54649e22a00330bd0f4d6699a5060e5"; static String treeSHA = "36528084e10bf993fdb20cc304f3421c7324c2a4"; // https://github.com/ethereum/tests/tree/develop/BlockchainTests/TransitionTests static BlockchainTestSuite suite; @BeforeClass public static void setup() throws IOException { suite = new BlockchainTestSuite(treeSHA, commitSHA); suite.setSubDir("TransitionTests/"); } @Test @Ignore // this method is mostly for hands-on convenient testing // using this method turn off initializing of BlockchainTestSuite to avoid unnecessary GitHub API hits public void bcTransitionSingle() throws IOException { BlockchainTestSuite.runSingle( "TransitionTests/bcHomesteadToDao/DaoTransactions.json", commitSHA); } @Test public void bcFrontierToHomestead() throws IOException { suite.runAll("bcFrontierToHomestead", GitHubJSONTestSuite.Network.FrontierToHomesteadAt5); } @Test public void bcHomesteadToDao() throws IOException { suite.runAll("bcHomesteadToDao", GitHubJSONTestSuite.Network.HomesteadToDaoAt5); } @Test public void bcHomesteadToEIP150() throws IOException { suite.runAll("bcHomesteadToEIP150", GitHubJSONTestSuite.Network.HomesteadToEIP150At5); } @Test public void bcEIP158ToByzantium() throws IOException { suite.runAll("bcEIP158ToByzantium", GitHubJSONTestSuite.Network.EIP158ToByzantiumAt5); } @Test public void byzantiumToConstantinople() throws IOException { suite.runAll("bcByzantiumToConstantinople", GitHubJSONTestSuite.Network.ByzantiumToConstantinopleFixAt5); } }
2,828
36.72
153
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/jsontestsuite/GithubABITest.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.jsontestsuite; import org.junit.FixMethodOrder; import org.junit.Test; import org.junit.runners.MethodSorters; import java.io.IOException; import static org.ethereum.jsontestsuite.GitHubJSONTestSuite.runABITest; /** * @author Mikhail Kalinin * @since 28.09.2017 */ @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class GithubABITest { String commitSHA = "253e99861fe406c7b1daf3d6a0c40906e8a8fd8f"; @Test public void basicAbiTests() throws IOException { runABITest("ABITests/basic_abi_tests.json", commitSHA); } }
1,362
31.452381
80
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/jsontestsuite/GitHubVMTest.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.jsontestsuite; import org.ethereum.config.SystemProperties; import org.ethereum.config.net.MainNetConfig; import org.ethereum.jsontestsuite.suite.VMTestSuite; import org.json.simple.parser.ParseException; import org.junit.*; import org.junit.runners.MethodSorters; import java.io.IOException; @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class GitHubVMTest { static String commitSHA = "253e99861fe406c7b1daf3d6a0c40906e8a8fd8f"; static String treeSHA = "d909a11b8315a81eaf610f457205025fb1284cc8"; // https://github.com/ethereum/tests/tree/develop/VMTests/ static VMTestSuite suite; @BeforeClass public static void setup() throws IOException { suite = new VMTestSuite(treeSHA, commitSHA); } @After public void recover() { SystemProperties.getDefault().setBlockchainConfig(new MainNetConfig()); } @Test public void vmArithmeticTest() throws ParseException { suite.runAll("vmArithmeticTest"); } @Test public void vmBitwiseLogicOperation() throws ParseException { suite.runAll("vmBitwiseLogicOperation"); } @Test public void vmBlockInfoTest() throws ParseException { suite.runAll("vmBlockInfoTest"); } @Test public void vmEnvironmentalInfo() throws ParseException { suite.runAll("vmEnvironmentalInfo"); } @Test public void vmIOandFlowOperations() throws ParseException { suite.runAll("vmIOandFlowOperations"); } @Test public void vmLogTest() throws ParseException { suite.runAll("vmLogTest"); } @Ignore // we pass it, but it's too long to run it each build @Test public void vmPerformance() throws ParseException { suite.runAll("vmPerformance"); } @Test public void vmPushDupSwapTest() throws ParseException { suite.runAll("vmPushDupSwapTest"); } @Test public void vmRandomTest() throws ParseException { suite.runAll("vmRandomTest"); } @Test public void vmSha3Test() throws ParseException { suite.runAll("vmSha3Test"); } @Test public void vmSystemOperations() throws ParseException { suite.runAll("vmSystemOperations"); } @Test public void vmTests() throws ParseException { suite.runAll("vmTests"); } }
3,134
28.027778
131
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/jsontestsuite/GitHubBlockTest.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.jsontestsuite; import org.ethereum.jsontestsuite.suite.BlockchainTestSuite; import org.junit.BeforeClass; import org.junit.FixMethodOrder; import org.junit.Ignore; import org.junit.Test; import org.junit.runners.MethodSorters; import java.io.IOException; import java.util.Arrays; import java.util.HashSet; @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class GitHubBlockTest { static String commitSHA = "253e99861fe406c7b1daf3d6a0c40906e8a8fd8f"; static String treeSHA = "6c32ebcbce50112966427e18788069b9f7cbe285"; // https://github.com/ethereum/tests/tree/develop/BlockchainTests/ static GitHubJSONTestSuite.Network[] targetNets = { GitHubJSONTestSuite.Network.Frontier, GitHubJSONTestSuite.Network.Homestead, GitHubJSONTestSuite.Network.EIP150, GitHubJSONTestSuite.Network.EIP158, GitHubJSONTestSuite.Network.Byzantium, GitHubJSONTestSuite.Network.Constantinople }; static BlockchainTestSuite suite; @BeforeClass public static void setup() throws IOException { suite = new BlockchainTestSuite(treeSHA, commitSHA, targetNets); } @Ignore @Test // this method is mostly for hands-on convenient testing // do not initialize BlockchainTestSuite to avoid unnecessary GitHub API hits public void bcSingleTest() throws IOException { BlockchainTestSuite.runSingle( "bcWalletTest/wallet2outOf3txs2.json", commitSHA, GitHubJSONTestSuite.Network.Byzantium); } @Test public void bcBlockGasLimitTest() throws IOException { suite.runAll("bcBlockGasLimitTest"); } @Test public void bcExploitTest() throws IOException { suite.runAll("bcExploitTest", new HashSet<>(Arrays.asList( "SuicideIssue" // it was checked once, but it's too heavy to hit it each time ))); } @Test public void bcForgedTest() throws IOException { suite.runAll("bcForgedTest"); } @Test public void bcForkStressTest() throws IOException { suite.runAll("bcForkStressTest"); } @Test public void bcGasPricerTest() throws IOException { suite.runAll("bcGasPricerTest"); } @Test public void bcInvalidHeaderTest() throws IOException { suite.runAll("bcInvalidHeaderTest"); } @Test public void bcMultiChainTest() throws IOException { suite.runAll("bcMultiChainTest"); } @Test public void bcRandomBlockhashTest() throws IOException { suite.runAll("bcRandomBlockhashTest"); } @Test public void bcStateTests() throws IOException { suite.runAll("bcStateTests"); } @Test public void bcTotalDifficultyTest() throws IOException { suite.runAll("bcTotalDifficultyTest"); } @Test public void bcUncleHeaderValidity() throws IOException { suite.runAll("bcUncleHeaderValidity"); } @Test public void bcUncleTest() throws IOException { suite.runAll("bcUncleTest"); } @Test public void bcValidBlockTest() throws IOException { suite.runAll("bcValidBlockTest"); } @Test public void bcWalletTest() throws IOException { suite.runAll("bcWalletTest"); } }
4,082
29.470149
138
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/jsontestsuite/suite/BlockTestSuite.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.jsontestsuite.suite; import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.ObjectMapper; import org.ethereum.jsontestsuite.GitHubJSONTestSuite; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.IOException; import java.util.*; public class BlockTestSuite { private Logger logger = LoggerFactory.getLogger("TCK-Test"); Map<String, BlockTestCase> testCases = new HashMap<>(); public BlockTestSuite(String json) throws IOException { ObjectMapper mapper = new ObjectMapper(); JavaType type = mapper.getTypeFactory(). constructMapType(HashMap.class, String.class, BlockTestCase.class); testCases = new ObjectMapper().readValue(json, type); } public Map<String, BlockTestCase> getTestCases() { return testCases; } public Map<String, BlockTestCase> getTestCases(GitHubJSONTestSuite.Network[] networks) { Set<GitHubJSONTestSuite.Network> nets = new HashSet<>(Arrays.asList(networks)); Map<String, BlockTestCase> filtered = new HashMap<>(); for (Map.Entry<String, BlockTestCase> testCase : testCases.entrySet()) { if (nets.contains(testCase.getValue().getNetwork())) { filtered.put(testCase.getKey(), testCase.getValue()); } } return filtered; } @Override public String toString() { return "BlockTestSuite{" + "testCases=" + testCases + '}'; } }
2,328
32.753623
92
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/jsontestsuite/suite/TestRunner.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.jsontestsuite.suite; import org.ethereum.config.CommonConfig; import org.ethereum.config.SystemProperties; import org.ethereum.core.Block; import org.ethereum.core.BlockchainImpl; import org.ethereum.core.ImportResult; import org.ethereum.core.PendingStateImpl; import org.ethereum.core.Repository; import org.ethereum.datasource.inmem.HashMapDB; import org.ethereum.db.*; import org.ethereum.jsontestsuite.suite.builder.BlockBuilder; import org.ethereum.jsontestsuite.suite.builder.RepositoryBuilder; import org.ethereum.jsontestsuite.suite.model.BlockTck; import org.ethereum.jsontestsuite.suite.validators.BlockHeaderValidator; import org.ethereum.jsontestsuite.suite.validators.RepositoryValidator; import org.ethereum.listener.EthereumListenerAdapter; import org.ethereum.util.ByteUtil; import org.ethereum.validator.DependentBlockHeaderRuleAdapter; import org.ethereum.vm.DataWord; import org.ethereum.vm.LogInfo; import org.ethereum.vm.VM; import org.ethereum.vm.program.Program; import org.ethereum.vm.program.invoke.ProgramInvoke; import org.ethereum.vm.program.invoke.ProgramInvokeFactoryImpl; import org.ethereum.vm.program.invoke.ProgramInvokeImpl; import org.ethereum.vm.trace.ProgramTrace; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.spongycastle.util.encoders.Hex; import java.math.BigInteger; import java.util.ArrayList; import java.util.Arrays; import java.util.Iterator; import java.util.List; import java.util.Map; import static org.ethereum.crypto.HashUtil.shortHash; import static org.ethereum.util.ByteUtil.EMPTY_BYTE_ARRAY; import static org.ethereum.vm.VMUtils.saveProgramTraceFile; /** * @author Roman Mandeleil * @since 02.07.2014 */ public class TestRunner { private Logger logger = LoggerFactory.getLogger("TCK-Test"); private ProgramTrace trace = null; private boolean setNewStateRoot; private String bestStateRoot; public List<String> runTestSuite(TestSuite testSuite) { Iterator<TestCase> testIterator = testSuite.iterator(); List<String> resultCollector = new ArrayList<>(); while (testIterator.hasNext()) { TestCase testCase = testIterator.next(); TestRunner runner = new TestRunner(); List<String> result = runner.runTestCase(testCase); resultCollector.addAll(result); } return resultCollector; } public List<String> runTestCase(BlockTestCase testCase) { /* 1 */ // Create genesis + init pre state Block genesis = BlockBuilder.build(testCase.getGenesisBlockHeader(), null, null); Repository repository = RepositoryBuilder.build(testCase.getPre()); IndexedBlockStore blockStore = new IndexedBlockStore(); blockStore.init(new HashMapDB<byte[]>(), new HashMapDB<byte[]>()); blockStore.saveBlock(genesis, genesis.getDifficultyBI(), true); ProgramInvokeFactoryImpl programInvokeFactory = new ProgramInvokeFactoryImpl(); BlockchainImpl blockchain = new BlockchainImpl(blockStore, repository) .withParentBlockHeaderValidator(CommonConfig.getDefault().parentHeaderValidator()); blockchain.byTest = true; PendingStateImpl pendingState = new PendingStateImpl(new EthereumListenerAdapter()); blockchain.setBestBlock(genesis); blockchain.setTotalDifficulty(genesis.getDifficultyBI()); blockchain.setParentHeaderValidator(new CommonConfig().parentHeaderValidator()); blockchain.setProgramInvokeFactory(programInvokeFactory); blockchain.setPendingState(pendingState); pendingState.setBlockchain(blockchain); /* 2 */ // Create block traffic list List<Block> blockTraffic = new ArrayList<>(); for (BlockTck blockTck : testCase.getBlocks()) { Block block = BlockBuilder.build(blockTck.getBlockHeader(), blockTck.getTransactions(), blockTck.getUncleHeaders()); setNewStateRoot = !((blockTck.getTransactions() == null) && (blockTck.getUncleHeaders() == null) && (blockTck.getBlockHeader() == null)); Block tBlock = null; try { byte[] rlp = Utils.parseData(blockTck.getRlp()); tBlock = new Block(rlp); ArrayList<String> outputSummary = BlockHeaderValidator.valid(tBlock.getHeader(), block.getHeader()); if (!outputSummary.isEmpty()){ for (String output : outputSummary) logger.error("{}", output); } blockTraffic.add(tBlock); } catch (Exception e) { System.out.println("*** Exception"); } } /* 3 */ // Inject blocks to the blockchain execution for (Block block : blockTraffic) { ImportResult importResult = blockchain.tryToConnect(block); logger.debug("{} ~ {} difficulty: {} ::: {}", block.getShortHash(), shortHash(block.getParentHash()), block.getDifficultyBI(), importResult.toString()); } repository = blockchain.getRepository(); //Check state root matches last valid block List<String> results = new ArrayList<>(); String currRoot = Hex.toHexString(repository.getRoot()); byte[] bestHash = Hex.decode(testCase.getLastblockhash().startsWith("0x") ? testCase.getLastblockhash().substring(2) : testCase.getLastblockhash()); String finalRoot = null; if (blockStore.getBlockByHash(bestHash) != null) { finalRoot = Hex.toHexString(blockStore.getBlockByHash(bestHash).getStateRoot()); } if (!currRoot.equals(finalRoot)){ String formattedString = String.format("Root hash doesn't match best: expected: %s current: %s", finalRoot, currRoot); results.add(formattedString); } Repository postRepository = RepositoryBuilder.build(testCase.getPostState()); List<String> repoResults = RepositoryValidator.valid(repository, postRepository); results.addAll(repoResults); return results; } public List<String> runTestCase(TestCase testCase) { logger.info("\n***"); logger.info(" Running test case: [" + testCase.getName() + "]"); logger.info("***\n"); List<String> results = new ArrayList<>(); logger.info("--------- PRE ---------"); IterableTestRepository testRepository = new IterableTestRepository(new RepositoryRoot(new HashMapDB<byte[]>())); testRepository.environmental = true; Repository repository = loadRepository(testRepository, testCase.getPre()); try { /* 2. Create ProgramInvoke - Env/Exec */ Env env = testCase.getEnv(); Exec exec = testCase.getExec(); Logs logs = testCase.getLogs(); byte[] address = exec.getAddress(); byte[] origin = exec.getOrigin(); byte[] caller = exec.getCaller(); byte[] balance = ByteUtil.bigIntegerToBytes(repository.getBalance(exec.getAddress())); byte[] gasPrice = exec.getGasPrice(); byte[] gas = exec.getGas(); byte[] callValue = exec.getValue(); byte[] msgData = exec.getData(); byte[] lastHash = env.getPreviousHash(); byte[] coinbase = env.getCurrentCoinbase(); long timestamp = ByteUtil.byteArrayToLong(env.getCurrentTimestamp()); long number = ByteUtil.byteArrayToLong(env.getCurrentNumber()); byte[] difficulty = env.getCurrentDifficulty(); byte[] gaslimit = env.getCurrentGasLimit(); // Origin and caller need to exist in order to be able to execute if (repository.getAccountState(origin) == null) repository.createAccount(origin); if (repository.getAccountState(caller) == null) repository.createAccount(caller); ProgramInvoke programInvoke = new ProgramInvokeImpl(address, origin, caller, balance, gasPrice, gas, callValue, msgData, lastHash, coinbase, timestamp, number, difficulty, gaslimit, repository, repository.clone(), new BlockStoreDummy(), true); /* 3. Create Program - exec.code */ /* 4. run VM */ VM vm = new VM(); Program program = new Program(exec.getCode(), programInvoke); boolean vmDidThrowAnEception = false; RuntimeException e = null; try { while (!program.isStopped()) vm.step(program); } catch (RuntimeException ex) { vmDidThrowAnEception = true; e = ex; } String content = program.getTrace().asJsonString(true); saveProgramTraceFile(SystemProperties.getDefault(), testCase.getName(), content); if (testCase.getPost() == null) { if (!vmDidThrowAnEception) { String output = "VM was expected to throw an exception"; logger.info(output); results.add(output); } else logger.info("VM did throw an exception: " + e.toString()); } else { if (vmDidThrowAnEception) { String output = "VM threw an unexpected exception: " + e.toString(); logger.info(output, e); results.add(output); return results; } this.trace = program.getTrace(); logger.info("--------- POST --------"); /* 5. Assert Post values */ if (testCase.getPost() != null) { for (ByteArrayWrapper key : testCase.getPost().keySet()) { AccountState accountState = testCase.getPost().get(key); long expectedNonce = accountState.getNonceLong(); BigInteger expectedBalance = accountState.getBigIntegerBalance(); byte[] expectedCode = accountState.getCode(); boolean accountExist = (null != repository.getAccountState(key.getData())); if (!accountExist) { String output = String.format("The expected account does not exist. key: [ %s ]", Hex.toHexString(key.getData())); logger.info(output); results.add(output); continue; } long actualNonce = repository.getNonce(key.getData()).longValue(); BigInteger actualBalance = repository.getBalance(key.getData()); byte[] actualCode = repository.getCode(key.getData()); if (actualCode == null) actualCode = "".getBytes(); if (expectedNonce != actualNonce) { String output = String.format("The nonce result is different. key: [ %s ], expectedNonce: [ %d ] is actualNonce: [ %d ] ", Hex.toHexString(key.getData()), expectedNonce, actualNonce); logger.info(output); results.add(output); } if (!expectedBalance.equals(actualBalance)) { String output = String.format("The balance result is different. key: [ %s ], expectedBalance: [ %s ] is actualBalance: [ %s ] ", Hex.toHexString(key.getData()), expectedBalance.toString(), actualBalance.toString()); logger.info(output); results.add(output); } if (!Arrays.equals(expectedCode, actualCode)) { String output = String.format("The code result is different. account: [ %s ], expectedCode: [ %s ] is actualCode: [ %s ] ", Hex.toHexString(key.getData()), Hex.toHexString(expectedCode), Hex.toHexString(actualCode)); logger.info(output); results.add(output); } // assert storage Map<DataWord, DataWord> storage = accountState.getStorage(); for (DataWord storageKey : storage.keySet()) { byte[] expectedStValue = storage.get(storageKey).getData(); ContractDetails contractDetails = program.getStorage().getContractDetails(accountState.getAddress()); if (contractDetails == null) { String output = String.format("Storage raw doesn't exist: key [ %s ], expectedValue: [ %s ]", Hex.toHexString(storageKey.getData()), Hex.toHexString(expectedStValue) ); logger.info(output); results.add(output); continue; } Map<DataWord, DataWord> testStorage = contractDetails.getStorage(); DataWord actualValue = testStorage.get(DataWord.of(storageKey.getData())); if (actualValue == null || !Arrays.equals(expectedStValue, actualValue.getData())) { String output = String.format("Storage value different: key [ %s ], expectedValue: [ %s ], actualValue: [ %s ]", Hex.toHexString(storageKey.getData()), Hex.toHexString(expectedStValue), actualValue == null ? "" : Hex.toHexString(actualValue.getNoLeadZeroesData())); logger.info(output); results.add(output); } } /* asset logs */ List<LogInfo> logResult = program.getResult().getLogInfoList(); List<String> logResults = logs.compareToReal(logResult); results.addAll(logResults); } } // TODO: assert that you have no extra accounts in the repository // TODO: -> basically the deleted by suicide should be deleted // TODO: -> and no unexpected created List<org.ethereum.vm.CallCreate> resultCallCreates = program.getResult().getCallCreateList(); // assert call creates for (int i = 0; i < testCase.getCallCreateList().size(); ++i) { org.ethereum.vm.CallCreate resultCallCreate = null; if (resultCallCreates != null && resultCallCreates.size() > i) { resultCallCreate = resultCallCreates.get(i); } CallCreate expectedCallCreate = testCase.getCallCreateList().get(i); if (resultCallCreate == null && expectedCallCreate != null) { String output = String.format("Missing call/create invoke: to: [ %s ], data: [ %s ], gas: [ %s ], value: [ %s ]", Hex.toHexString(expectedCallCreate.getDestination()), Hex.toHexString(expectedCallCreate.getData()), Hex.toHexString(expectedCallCreate.getGasLimit()), Hex.toHexString(expectedCallCreate.getValue())); logger.info(output); results.add(output); continue; } boolean assertDestination = Arrays.equals( expectedCallCreate.getDestination(), resultCallCreate.getDestination()); if (!assertDestination) { String output = String.format("Call/Create destination is different. Expected: [ %s ], result: [ %s ]", Hex.toHexString(expectedCallCreate.getDestination()), Hex.toHexString(resultCallCreate.getDestination())); logger.info(output); results.add(output); } boolean assertData = Arrays.equals( expectedCallCreate.getData(), resultCallCreate.getData()); if (!assertData) { String output = String.format("Call/Create data is different. Expected: [ %s ], result: [ %s ]", Hex.toHexString(expectedCallCreate.getData()), Hex.toHexString(resultCallCreate.getData())); logger.info(output); results.add(output); } boolean assertGasLimit = Arrays.equals( expectedCallCreate.getGasLimit(), resultCallCreate.getGasLimit()); if (!assertGasLimit) { String output = String.format("Call/Create gasLimit is different. Expected: [ %s ], result: [ %s ]", Hex.toHexString(expectedCallCreate.getGasLimit()), Hex.toHexString(resultCallCreate.getGasLimit())); logger.info(output); results.add(output); } boolean assertValue = Arrays.equals( expectedCallCreate.getValue(), resultCallCreate.getValue()); if (!assertValue) { String output = String.format("Call/Create value is different. Expected: [ %s ], result: [ %s ]", Hex.toHexString(expectedCallCreate.getValue()), Hex.toHexString(resultCallCreate.getValue())); logger.info(output); results.add(output); } } // assert out byte[] expectedHReturn = testCase.getOut(); byte[] actualHReturn = EMPTY_BYTE_ARRAY; if (program.getResult().getHReturn() != null) { actualHReturn = program.getResult().getHReturn(); } if (!Arrays.equals(expectedHReturn, actualHReturn)) { String output = String.format("HReturn is different. Expected hReturn: [ %s ], actual hReturn: [ %s ]", Hex.toHexString(expectedHReturn), Hex.toHexString(actualHReturn)); logger.info(output); results.add(output); } // assert gas BigInteger expectedGas = new BigInteger(1, testCase.getGas()); BigInteger actualGas = new BigInteger(1, gas).subtract(BigInteger.valueOf(program.getResult().getGasUsed())); if (!expectedGas.equals(actualGas)) { String output = String.format("Gas remaining is different. Expected gas remaining: [ %s ], actual gas remaining: [ %s ]", expectedGas.toString(), actualGas.toString()); logger.info(output); results.add(output); } /* * end of if(testCase.getPost().size() == 0) */ } return results; } finally { // repository.close(); } } public org.ethereum.core.Transaction createTransaction(Transaction tx) { byte[] nonceBytes = ByteUtil.longToBytes(tx.nonce); byte[] gasPriceBytes = ByteUtil.longToBytes(tx.gasPrice); byte[] gasBytes = tx.gasLimit; byte[] valueBytes = ByteUtil.longToBytes(tx.value); byte[] toAddr = tx.getTo(); byte[] data = tx.getData(); org.ethereum.core.Transaction transaction = new org.ethereum.core.Transaction( nonceBytes, gasPriceBytes, gasBytes, toAddr, valueBytes, data); return transaction; } public Repository loadRepository(Repository track, Map<ByteArrayWrapper, AccountState> pre) { /* 1. Store pre-exist accounts - Pre */ for (ByteArrayWrapper key : pre.keySet()) { AccountState accountState = pre.get(key); byte[] addr = key.getData(); track.addBalance(addr, new BigInteger(1, accountState.getBalance())); track.setNonce(key.getData(), new BigInteger(1, accountState.getNonce())); track.saveCode(addr, accountState.getCode()); for (DataWord storageKey : accountState.getStorage().keySet()) { track.addStorageRow(addr, storageKey, accountState.getStorage().get(storageKey)); } } return track; } public ProgramTrace getTrace() { return trace; } }
23,339
42.954802
149
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/jsontestsuite/suite/TrieTestCase.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.jsontestsuite.suite; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import org.ethereum.datasource.NoDeleteSource; import org.ethereum.datasource.inmem.HashMapDB; import org.ethereum.trie.SecureTrie; import org.ethereum.trie.Trie; import org.ethereum.trie.TrieImpl; import org.spongycastle.util.encoders.Hex; import java.util.List; import java.util.Map; import static org.ethereum.jsontestsuite.suite.Utils.parseData; /** * @author Mikhail Kalinin * @since 28.09.2017 */ @JsonIgnoreProperties(ignoreUnknown = true) public class TrieTestCase { @JsonIgnore String name; Object in; String root; public String getName() { return name; } public void setName(String name) { this.name = name; } public Object getIn() { return in; } public void setIn(Object in) { this.in = in; } public String getRoot() { return root; } public void setRoot(String root) { this.root = root; } @SuppressWarnings("unchecked") public String calculateRoot(boolean secure) { Trie<byte[]> trie; if (secure) { trie = new SecureTrie(new NoDeleteSource<>(new HashMapDB<byte[]>())); } else { trie = new TrieImpl(new NoDeleteSource<>(new HashMapDB<byte[]>())); } if (in instanceof Map) { for (Map.Entry<String, String> e : ((Map<String, String>)in).entrySet()) { byte[] key = e.getKey().startsWith("0x") ? parseData(e.getKey()) : e.getKey().getBytes(); byte[] value = null; if (e.getValue() != null) { value = e.getValue().startsWith("0x") ? parseData(e.getValue()) : e.getValue().getBytes(); } trie.put(key, value); } } else if (in instanceof List) { for (List<String> pair : ((List<List<String>>)in)) { byte[] key = pair.get(0).startsWith("0x") ? parseData(pair.get(0)) : pair.get(0).getBytes(); byte[] value = null; if (pair.get(1) != null) { value = pair.get(1).startsWith("0x") ? parseData(pair.get(1)) : pair.get(1).getBytes(); } trie.put(key, value); } } else { throw new IllegalArgumentException("Not supported format of Trie testcase"); } return "0x" + Hex.toHexString(trie.getRootHash()); } @Override public String toString() { return "TrieTestCase{" + "name='" + name + '\'' + ", in=" + in + ", root='" + root + '\'' + '}'; } }
3,574
27.830645
110
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/jsontestsuite/suite/IterableTestRepository.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.jsontestsuite.suite; import org.ethereum.core.AccountState; import org.ethereum.core.Block; import org.ethereum.core.Repository; import org.ethereum.db.ByteArrayWrapper; import org.ethereum.db.ContractDetails; import org.ethereum.util.ByteArrayMap; import org.ethereum.util.ByteArraySet; import org.ethereum.vm.DataWord; import javax.annotation.Nullable; import java.math.BigInteger; import java.util.*; /** * Created by Anton Nashatyrev on 01.12.2016. */ public class IterableTestRepository implements Repository { Repository src; Set<byte[]> accounts = new ByteArraySet(); Map<byte[], Set<DataWord>> storageKeys = new ByteArrayMap<>(); boolean environmental; private IterableTestRepository(Repository src, IterableTestRepository parent) { this.src = src; if (parent != null) { this.accounts = parent.accounts; this.storageKeys = parent.storageKeys; this.environmental = parent.environmental; } } public IterableTestRepository(Repository src) { this(src, null); } void addAccount(byte[] addr) { accounts.add(addr); } private void addStorageKey(byte[] acct, DataWord key) { addAccount(acct); Set<DataWord> keys = storageKeys.get(acct); if (keys == null) { keys = new HashSet<>(); storageKeys.put(acct, keys); } keys.add(key); } @Override public Repository startTracking() { return new IterableTestRepository(src.startTracking(), this); } @Override public Repository getSnapshotTo(byte[] root) { return new IterableTestRepository(src.getSnapshotTo(root), this); } @Override public Repository clone() { return new IterableTestRepository(src.clone(), this); } @Override public AccountState createAccount(byte[] addr) { addAccount(addr); return src.createAccount(addr); } @Override public boolean isExist(byte[] addr) { return src.isExist(addr); } @Override public AccountState getAccountState(byte[] addr) { return src.getAccountState(addr); } @Override public void delete(byte[] addr) { addAccount(addr); src.delete(addr); } @Override public BigInteger increaseNonce(byte[] addr) { addAccount(addr); return src.increaseNonce(addr); } @Override public BigInteger setNonce(byte[] addr, BigInteger nonce) { return src.setNonce(addr, nonce); } @Override public BigInteger getNonce(byte[] addr) { return src.getNonce(addr); } @Override public ContractDetails getContractDetails(byte[] addr) { return new IterableContractDetails(src.getContractDetails(addr)); } @Override public boolean hasContractDetails(byte[] addr) { return src.hasContractDetails(addr); } @Override public void saveCode(byte[] addr, byte[] code) { addAccount(addr); src.saveCode(addr, code); } @Override public byte[] getCode(byte[] addr) { if (environmental) { if (!src.isExist(addr)) { createAccount(addr); } } return src.getCode(addr); } @Override public byte[] getCodeHash(byte[] addr) { return src.getCodeHash(addr); } @Override public void addStorageRow(byte[] addr, DataWord key, DataWord value) { addStorageKey(addr, key); src.addStorageRow(addr, key, value); } @Override public DataWord getStorageValue(byte[] addr, DataWord key) { return src.getStorageValue(addr, key); } @Override public BigInteger getBalance(byte[] addr) { if (environmental) { if (!src.isExist(addr)) { createAccount(addr); } } return src.getBalance(addr); } @Override public BigInteger addBalance(byte[] addr, BigInteger value) { addAccount(addr); return src.addBalance(addr, value); } @Override public Set<byte[]> getAccountsKeys() { Set<byte[]> ret = new ByteArraySet(); for (byte[] account : accounts) { if (isExist(account)) { ret.add(account); } } return ret; } @Override public void dumpState(Block block, long gasUsed, int txNumber, byte[] txHash) { src.dumpState(block, gasUsed, txNumber, txHash); } @Override public void flush() { src.flush(); } @Override public void flushNoReconnect() { src.flushNoReconnect(); } @Override public void commit() { src.commit(); } @Override public void rollback() { src.rollback(); } @Override public void syncToRoot(byte[] root) { src.syncToRoot(root); } @Override public boolean isClosed() { return src.isClosed(); } @Override public void close() { src.close(); } @Override public void reset() { src.reset(); } @Override public void updateBatch(HashMap<ByteArrayWrapper, AccountState> accountStates, HashMap<ByteArrayWrapper, ContractDetails> contractDetailes) { src.updateBatch(accountStates, contractDetailes); for (ByteArrayWrapper wrapper : accountStates.keySet()) { addAccount(wrapper.getData()); } for (Map.Entry<ByteArrayWrapper, ContractDetails> entry : contractDetailes.entrySet()) { for (DataWord key : entry.getValue().getStorageKeys()) { addStorageKey(entry.getKey().getData(), key); } } } @Override public byte[] getRoot() { return src.getRoot(); } @Override public void loadAccount(byte[] addr, HashMap<ByteArrayWrapper, AccountState> cacheAccounts, HashMap<ByteArrayWrapper, ContractDetails> cacheDetails) { src.loadAccount(addr, cacheAccounts, cacheDetails); } @Override public int getStorageSize(byte[] addr) { return src.getStorageSize(addr); } @Override public Set<DataWord> getStorageKeys(byte[] addr) { return src.getStorageKeys(addr); } @Override public Map<DataWord, DataWord> getStorage(byte[] addr, @Nullable Collection<DataWord> keys) { return src.getStorage(addr, keys); } private class IterableContractDetails implements ContractDetails { ContractDetails src; public IterableContractDetails(ContractDetails src) { this.src = src; } @Override public void put(DataWord key, DataWord value) { addStorageKey(getAddress(), key); src.put(key, value); } @Override public DataWord get(DataWord key) { return src.get(key); } @Override public byte[] getCode() { return src.getCode(); } @Override public byte[] getCode(byte[] codeHash) { return src.getCode(codeHash); } @Override public void setCode(byte[] code) { addAccount(getAddress()); src.setCode(code); } @Override public byte[] getStorageHash() { return src.getStorageHash(); } @Override public void decode(byte[] rlpCode) { src.decode(rlpCode); } @Override public void setDirty(boolean dirty) { src.setDirty(dirty); } @Override public void setDeleted(boolean deleted) { src.setDeleted(deleted); } @Override public boolean isDirty() { return src.isDirty(); } @Override public boolean isDeleted() { return src.isDeleted(); } @Override public byte[] getEncoded() { return src.getEncoded(); } @Override public int getStorageSize() { Set<DataWord> set = storageKeys.get(getAddress()); return set == null ? 0 : set.size(); } @Override public Set<DataWord> getStorageKeys() { return getStorage().keySet(); } @Override public void deleteStorage() { Set<DataWord> keys = getStorageKeys(); for (DataWord key: keys) { put(key, DataWord.ZERO); } } @Override public Map<DataWord, DataWord> getStorage(@Nullable Collection<DataWord> keys) { throw new RuntimeException(); } @Override public Map<DataWord, DataWord> getStorage() { Map<DataWord, DataWord> ret = new HashMap<>(); Set<DataWord> set = storageKeys.get(getAddress()); if (set == null) return Collections.emptyMap(); for (DataWord key : set) { DataWord val = get(key); if (val != null && !val.isZero()) { ret.put(key, get(key)); } } return ret; } @Override public void setStorage(List<DataWord> storageKeys, List<DataWord> storageValues) { src.setStorage(storageKeys, storageValues); } @Override public void setStorage(Map<DataWord, DataWord> storage) { src.setStorage(storage); } @Override public byte[] getAddress() { return src.getAddress(); } @Override public void setAddress(byte[] address) { src.setAddress(address); } @Override public ContractDetails clone() { return new IterableContractDetails(src.clone()); } @Override public String toString() { return src.toString(); } @Override public void syncStorage() { src.syncStorage(); } @Override public ContractDetails getSnapshotTo(byte[] hash) { return new IterableContractDetails(src.getSnapshotTo(hash)); } } }
11,007
24.840376
154
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/jsontestsuite/suite/JSONReader.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.jsontestsuite.suite; import org.ethereum.config.SystemProperties; import org.ethereum.util.FileUtil; import org.json.simple.JSONArray; import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; import org.json.simple.parser.ParseException; import java.io.*; import java.net.HttpURLConnection; import java.net.URL; import java.nio.file.Files; import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; import java.util.concurrent.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class JSONReader { private static Logger logger = LoggerFactory.getLogger("TCK-Test"); static ExecutorService threadPool; private static int MAX_RETRIES = 3; public static List<String> loadJSONsFromCommit(List<String> filenames, final String shacommit) { int threads = 16; if (threadPool == null) { threadPool = Executors.newFixedThreadPool(threads); } List<Future<String>> retF = new ArrayList<>(); for (final String filename : filenames) { Future<String> f = threadPool.submit(() -> loadJSONFromCommit(filename, shacommit)); retF.add(f); } List<String> ret = new ArrayList<>(); for (Future<String> f : retF) { try { ret.add(f.get()); } catch (InterruptedException | ExecutionException e) { throw new RuntimeException(String.format("Failed to retrieve %d files from commit %s", filenames.size(), shacommit), e); } } return ret; } public static String loadJSONFromCommit(String filename, String shacommit) throws IOException { String json = ""; if (!SystemProperties.getDefault().githubTestsLoadLocal()) json = getFromUrl("https://raw.githubusercontent.com/ethereum/tests/" + shacommit + "/" + filename); if (!json.isEmpty()) json = json.replaceAll("//", "data"); return json.isEmpty() ? getFromLocal(filename) : json; } public static String getFromLocal(String filename) throws IOException { filename = SystemProperties.getDefault().githubTestsPath() + System.getProperty("file.separator") + filename.replaceAll("/", System.getProperty("file.separator")); logger.info("Loading local file: {}", filename); return new String(Files.readAllBytes(Paths.get(filename))); } public static String getFromUrl(String urlToRead) { String result = null; for (int i = 0; i < MAX_RETRIES; ++i) { try { result = getFromUrlImpl(urlToRead); break; } catch (Exception ex) { logger.debug(String.format("Failed to retrieve %s, retry %d/%d", urlToRead, (i + 1), MAX_RETRIES), ex); if (i < (MAX_RETRIES - 1)) { try { Thread.sleep(2000); // adding delay after fail } catch (InterruptedException e) { } } } } if (result == null) throw new RuntimeException(String.format("Failed to retrieve file from url %s", urlToRead)); return result; } private static String getFromUrlImpl(String urlToRead) throws Exception { URL url; HttpURLConnection conn; BufferedReader rd; StringBuilder result = new StringBuilder(); String line; try { url = new URL(urlToRead); conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("GET"); conn.setDoOutput(true); conn.connect(); InputStream in = conn.getInputStream(); rd = new BufferedReader(new InputStreamReader(in), 819200); logger.info("Loading remote file: " + urlToRead); while ((line = rd.readLine()) != null) { result.append(line); } rd.close(); } catch (Throwable e) { logger.debug("Failed to retrieve file.", e); throw e; } return result.toString(); } public static List<String> listJsonBlobsForTreeSha(String sha, String testRoot) throws IOException { if (SystemProperties.getDefault().githubTestsLoadLocal()) { String path = SystemProperties.getDefault().githubTestsPath() + System.getProperty("file.separator") + testRoot.replaceAll("/", ""); List<String> files = FileUtil.recursiveList(path); List<String> jsons = new ArrayList<>(); for (String f : files) { if (f.endsWith(".json")) jsons.add( f.replace(path + System.getProperty("file.separator"), "") .replaceAll(System.getProperty("file.separator"), "/")); } return jsons; } String result = getFromUrl("https://api.github.com/repos/ethereum/tests/git/trees/" + sha + "?recursive=1"); JSONParser parser = new JSONParser(); JSONObject testSuiteObj = null; List<String> blobs = new ArrayList<>(); try { testSuiteObj = (JSONObject) parser.parse(result); JSONArray tree = (JSONArray)testSuiteObj.get("tree"); for (Object oEntry : tree) { JSONObject entry = (JSONObject) oEntry; String type = (String) entry.get("type"); String path = (String) entry.get("path"); if (!type.equals("blob")) continue; if (!path.endsWith(".json")) continue; blobs.add((String) entry.get("path")); } } catch (ParseException e) { e.printStackTrace(); } return blobs; } }
6,670
34.484043
120
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/jsontestsuite/suite/TrieTestSuite.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.jsontestsuite.suite; import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.ObjectMapper; import java.io.IOException; import java.util.*; /** * @author Mikhail Kalinin * @since 28.09.2017 */ public class TrieTestSuite { List<TrieTestCase> testCases = new ArrayList<>(); public TrieTestSuite(String json) throws IOException { ObjectMapper mapper = new ObjectMapper(); JavaType type = mapper.getTypeFactory(). constructMapType(HashMap.class, String.class, TrieTestCase.class); Map<String, TrieTestCase> caseMap = new ObjectMapper().readValue(json, type); for (Map.Entry<String, TrieTestCase> e : caseMap.entrySet()) { e.getValue().setName(e.getKey()); testCases.add(e.getValue()); } testCases.sort(Comparator.comparing(TrieTestCase::getName)); } public List<TrieTestCase> getTestCases() { return testCases; } @Override public String toString() { return "TrieTestSuite{" + "testCases=" + testCases + '}'; } }
1,929
31.166667
85
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/jsontestsuite/suite/Helper.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.jsontestsuite.suite; import org.ethereum.util.ByteUtil; import org.json.simple.JSONArray; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.spongycastle.util.encoders.Hex; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.math.BigInteger; import java.util.regex.Pattern; /** * @author Roman Mandeleil * @since 28.06.2014 */ public class Helper { private static Logger logger = LoggerFactory.getLogger("misc"); public static byte[] parseDataArray(JSONArray valArray) { // value can be: // 1. 324234 number // 2. "0xAB3F23A" - hex string // 3. "239472398472" - big number ByteArrayOutputStream bos = new ByteArrayOutputStream(); for (Object val : valArray) { if (val instanceof String) { // Hex num boolean hexVal = Pattern.matches("0[xX][0-9a-fA-F]+", val.toString()); if (hexVal) { String number = ((String) val).substring(2); if (number.length() % 2 == 1) number = "0" + number; byte[] data = Hex.decode(number); try { bos.write(data); } catch (IOException e) { logger.error("should not happen", e); } } else { // BigInt num boolean isNumeric = Pattern.matches("[0-9a-fA-F]+", val.toString()); if (!isNumeric) throw new Error("Wrong test case JSON format"); else { BigInteger value = new BigInteger(val.toString()); try { bos.write(value.toByteArray()); } catch (IOException e) { logger.error("should not happen", e); } } } } else if (val instanceof Long) { // Simple long byte[] data = ByteUtil.bigIntegerToBytes(BigInteger.valueOf((Long) val)); try { bos.write(data); } catch (IOException e) { logger.error("should not happen", e); } } else { throw new Error("Wrong test case JSON format"); } } return bos.toByteArray(); } }
3,270
32.721649
89
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/jsontestsuite/suite/ContractDetailsCacheImpl.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.jsontestsuite.suite; import org.ethereum.db.ContractDetails; import org.ethereum.trie.SecureTrie; import org.ethereum.util.RLP; import org.ethereum.vm.DataWord; import java.util.*; import static java.util.Collections.unmodifiableMap; /** * @author Roman Mandeleil * @since 24.06.2014 */ public class ContractDetailsCacheImpl extends AbstractContractDetails { private Map<DataWord, DataWord> storage = new HashMap<>(); ContractDetails origContract; public ContractDetailsCacheImpl(ContractDetails origContract) { this.origContract = origContract; if (origContract != null) { if (origContract instanceof AbstractContractDetails) { setCodes(((AbstractContractDetails) this.origContract).getCodes()); } else { setCode(origContract.getCode()); } } } @Override public void put(DataWord key, DataWord value) { storage.put(key, value); this.setDirty(true); } @Override public DataWord get(DataWord key) { DataWord value = storage.get(key); if (value == null) { if (origContract == null) return null; value = origContract.get(key); storage.put(key, value == null ? DataWord.ZERO : value); } if (value == null || value.isZero()) return null; else return value; } @Override public byte[] getStorageHash() { // todo: unsupported SecureTrie storageTrie = new SecureTrie((byte[]) null); for (DataWord key : storage.keySet()) { DataWord value = storage.get(key); storageTrie.put(key.getData(), RLP.encodeElement(value.getNoLeadZeroesData())); } return storageTrie.getRootHash(); } @Override public void decode(byte[] rlpCode) { throw new RuntimeException("Not supported by this implementation."); } @Override public byte[] getEncoded() { throw new RuntimeException("Not supported by this implementation."); } @Override public Map<DataWord, DataWord> getStorage() { return unmodifiableMap(storage); } @Override public Map<DataWord, DataWord> getStorage(Collection<DataWord> keys) { if (keys == null) return getStorage(); Map<DataWord, DataWord> result = new HashMap<>(); for (DataWord key : keys) { result.put(key, storage.get(key)); } return unmodifiableMap(result); } @Override public int getStorageSize() { return (origContract == null) ? storage.size() : origContract.getStorageSize(); } @Override public Set<DataWord> getStorageKeys() { return (origContract == null) ? storage.keySet() : origContract.getStorageKeys(); } @Override public void setStorage(List<DataWord> storageKeys, List<DataWord> storageValues) { for (int i = 0; i < storageKeys.size(); ++i){ DataWord key = storageKeys.get(i); DataWord value = storageValues.get(i); if (value.isZero()) storage.put(key, null); } } @Override public void setStorage(Map<DataWord, DataWord> storage) { this.storage = storage; } @Override public byte[] getAddress() { return (origContract == null) ? null : origContract.getAddress(); } @Override public void setAddress(byte[] address) { if (origContract != null) origContract.setAddress(address); } @Override public ContractDetails clone() { ContractDetailsCacheImpl contractDetails = new ContractDetailsCacheImpl(origContract); Object storageClone = ((HashMap<DataWord, DataWord>)storage).clone(); contractDetails.setCode(this.getCode()); contractDetails.setStorage( (HashMap<DataWord, DataWord>) storageClone); return contractDetails; } @Override public void syncStorage() { if (origContract != null) origContract.syncStorage(); } public void commit(){ if (origContract == null) return; for (DataWord key : storage.keySet()) { origContract.put(key, storage.get(key)); } if (origContract instanceof AbstractContractDetails) { ((AbstractContractDetails) origContract).appendCodes(getCodes()); } else { origContract.setCode(getCode()); } origContract.setDirty(this.isDirty() || origContract.isDirty()); } @Override public ContractDetails getSnapshotTo(byte[] hash) { throw new UnsupportedOperationException("No snapshot option during cache state"); } }
5,595
27.406091
94
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/jsontestsuite/suite/AccountState.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.jsontestsuite.suite; import org.ethereum.util.ByteUtil; import org.ethereum.vm.DataWord; import org.json.simple.JSONObject; import org.spongycastle.util.encoders.Hex; import java.math.BigInteger; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; /** * @author Roman Mandeleil * @since 28.06.2014 */ public class AccountState { byte[] address; byte[] balance; byte[] code; byte[] nonce; Map<DataWord, DataWord> storage = new HashMap<>(); public AccountState(byte[] address, JSONObject accountState) { this.address = address; String balance = accountState.get("balance").toString(); String code = (String) accountState.get("code"); String nonce = accountState.get("nonce").toString(); JSONObject store = (JSONObject) accountState.get("storage"); this.balance = TestCase.toBigInt(balance).toByteArray(); if (code != null && code.length() > 2) this.code = Hex.decode(code.substring(2)); else this.code = ByteUtil.EMPTY_BYTE_ARRAY; this.nonce = TestCase.toBigInt(nonce).toByteArray(); int size = store.keySet().size(); Object[] keys = store.keySet().toArray(); for (int i = 0; i < size; ++i) { String keyS = keys[i].toString(); String valS = store.get(keys[i]).toString(); byte[] key = Utils.parseData(keyS); byte[] value = Utils.parseData(valS); storage.put(DataWord.of(key), DataWord.of(value)); } } public byte[] getAddress() { return address; } public byte[] getBalance() { return balance; } public BigInteger getBigIntegerBalance() { return new BigInteger(balance); } public byte[] getCode() { return code; } public byte[] getNonce() { return nonce; } public long getNonceLong() { return new BigInteger(nonce).longValue(); } public Map<DataWord, DataWord> getStorage() { return storage; } public List<String> compareToReal(org.ethereum.core.AccountState state, ContractDetailsImpl details) { List<String> results = new ArrayList<>(); BigInteger expectedBalance = new BigInteger(1, this.getBalance()); if (!state.getBalance().equals(expectedBalance)) { String formattedString = String.format("Account: %s: has unexpected balance, expected balance: %s found balance: %s", Hex.toHexString(this.address), expectedBalance.toString(), state.getBalance().toString()); results.add(formattedString); } BigInteger expectedNonce = new BigInteger(1, this.getNonce()); if (!state.getNonce().equals(expectedNonce)) { state.getNonce(); this.getNonce(); String formattedString = String.format("Account: %s: has unexpected nonce, expected nonce: %s found nonce: %s", Hex.toHexString(this.address), expectedNonce.toString(), state.getNonce().toString()); results.add(formattedString); } if (!Arrays.equals(details.getCode(), this.getCode())) { String formattedString = String.format("Account: %s: has unexpected nonce, expected nonce: %s found nonce: %s", Hex.toHexString(this.address), Hex.toHexString(this.getCode()), Hex.toHexString(details.getCode())); results.add(formattedString); } // compare storage Set<DataWord> keys = details.getStorage().keySet(); Set<DataWord> expectedKeys = this.getStorage().keySet(); Set<DataWord> checked = new HashSet<>(); for (DataWord key : keys) { DataWord value = details.getStorage().get(key); DataWord expectedValue = this.getStorage().get(key); if (expectedValue == null) { String formattedString = String.format("Account: %s: has unexpected storage data: %s = %s", Hex.toHexString(this.address), key.toString(), value.toString()); results.add(formattedString); continue; } if (!expectedValue.equals(value)) { String formattedString = String.format("Account: %s: has unexpected value, for key: %s , expectedValue: %s real value: %s", Hex.toHexString(this.address), key.toString(), expectedValue.toString(), value.toString()); results.add(formattedString); continue; } checked.add(key); } for (DataWord key : expectedKeys) { if (!checked.contains(key)) { String formattedString = String.format("Account: %s: doesn't exist expected storage key: %s", Hex.toHexString(this.address), key.toString()); results.add(formattedString); } } return results; } @Override public String toString() { return "AccountState{" + "address=" + Hex.toHexString(address) + ", balance=" + Hex.toHexString(balance) + ", code=" + Hex.toHexString(code) + ", nonce=" + Hex.toHexString(nonce) + ", storage=" + storage + '}'; } }
6,337
31.670103
139
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/jsontestsuite/suite/StateTestData.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.jsontestsuite.suite; import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.ObjectMapper; import org.ethereum.jsontestsuite.GitHubJSONTestSuite; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; /** * @author Mikhail Kalinin * @since 09.08.2017 */ public class StateTestData { Map<String, StateTestDataEntry> testData; public StateTestData(String json) throws IOException { ObjectMapper mapper = new ObjectMapper(); JavaType type = mapper.getTypeFactory(). constructMapType(HashMap.class, String.class, StateTestDataEntry.class); testData = new ObjectMapper().readValue(json, type); } public List<StateTestCase> getTestCases(GitHubJSONTestSuite.Network network) { List<StateTestCase> cases = new ArrayList<>(); for (Map.Entry<String, StateTestDataEntry> e : testData.entrySet()) { List<StateTestCase> testCases = e.getValue().getTestCases(network); for (int i = 0; i < testCases.size(); i++) { StateTestCase testCase = testCases.get(i); testCase.setName(String.format("%s_%s%s", e.getKey(), network.name(), testCases.size() > 1 ? "_" + String.valueOf(i + 1) : "")); } cases.addAll(testCases); } return cases; } }
2,243
33.523077
88
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/jsontestsuite/suite/ContractDetailsImpl.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.jsontestsuite.suite; import org.ethereum.config.CommonConfig; import org.ethereum.config.SystemProperties; import org.ethereum.datasource.DbSource; import org.ethereum.datasource.Source; import org.ethereum.db.ByteArrayWrapper; import org.ethereum.db.ContractDetails; import org.ethereum.trie.SecureTrie; import org.ethereum.util.*; import org.ethereum.vm.DataWord; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; import java.util.*; import static org.ethereum.crypto.HashUtil.EMPTY_TRIE_HASH; import static org.ethereum.crypto.HashUtil.sha3; import static org.ethereum.util.ByteUtil.*; /** * @author Roman Mandeleil * @since 24.06.2014 */ @Component @Scope("prototype") public class ContractDetailsImpl extends AbstractContractDetails { private static final Logger logger = LoggerFactory.getLogger("general"); CommonConfig commonConfig = CommonConfig.getDefault(); SystemProperties config = SystemProperties.getDefault(); DbSource dataSource; private byte[] address = EMPTY_BYTE_ARRAY; private Set<ByteArrayWrapper> keys = new HashSet<>(); private SecureTrie storageTrie = new SecureTrie((byte[]) null); boolean externalStorage; private DbSource externalStorageDataSource; /** Tests only **/ public ContractDetailsImpl() { } private ContractDetailsImpl(byte[] address, SecureTrie storageTrie, Map<ByteArrayWrapper, byte[]> codes) { this.address = address; this.storageTrie = storageTrie; setCodes(codes); } private void addKey(byte[] key) { keys.add(wrap(key)); } private void removeKey(byte[] key) { // keys.remove(wrap(key)); // TODO: we can't remove keys , because of fork branching } @Override public void put(DataWord key, DataWord value) { if (value.equals(DataWord.ZERO)) { storageTrie.delete(key.getData()); removeKey(key.getData()); } else { storageTrie.put(key.getData(), RLP.encodeElement(value.getNoLeadZeroesData())); addKey(key.getData()); } this.setDirty(true); } @Override public DataWord get(DataWord key) { DataWord result = null; byte[] data = storageTrie.get(key.getData()); if (data.length > 0) { byte[] dataDecoded = RLP.decode2(data).get(0).getRLPData(); result = DataWord.of(dataDecoded); } return result; } @Override public byte[] getStorageHash() { return storageTrie.getRootHash(); } @Override public void decode(byte[] rlpCode) { throw new RuntimeException("Not supported"); } @Override public byte[] getEncoded() { throw new RuntimeException("Not supported"); } @Override public Map<DataWord, DataWord> getStorage(Collection<DataWord> keys) { Map<DataWord, DataWord> storage = new HashMap<>(); if (keys == null) { for (ByteArrayWrapper keyBytes : this.keys) { DataWord key = DataWord.of(keyBytes); DataWord value = get(key); // we check if the value is not null, // cause we keep all historical keys if (value != null) storage.put(key, value); } } else { for (DataWord key : keys) { DataWord value = get(key); // we check if the value is not null, // cause we keep all historical keys if (value != null) storage.put(key, value); } } return storage; } @Override public Map<DataWord, DataWord> getStorage() { return getStorage(null); } @Override public int getStorageSize() { return keys.size(); } @Override public Set<DataWord> getStorageKeys() { Set<DataWord> result = new HashSet<>(); for (ByteArrayWrapper key : keys) { result.add(DataWord.of(key)); } return result; } @Override public void setStorage(List<DataWord> storageKeys, List<DataWord> storageValues) { for (int i = 0; i < storageKeys.size(); ++i) put(storageKeys.get(i), storageValues.get(i)); } @Override public void setStorage(Map<DataWord, DataWord> storage) { for (DataWord key : storage.keySet()) { put(key, storage.get(key)); } } @Override public byte[] getAddress() { return address; } @Override public void setAddress(byte[] address) { this.address = address; } public SecureTrie getStorageTrie() { return storageTrie; } @Override public void syncStorage() { } @Override public ContractDetails clone() { // FIXME: clone is not working now !!! // FIXME: should be fixed // storageTrie.getRoot(); return new ContractDetailsImpl(address, null, getCodes()); } @Override public ContractDetails getSnapshotTo(byte[] hash){ Source<byte[], byte[]> cache = this.storageTrie.getCache(); SecureTrie snapStorage = wrap(hash).equals(wrap(EMPTY_TRIE_HASH)) ? new SecureTrie(cache, "".getBytes()): new SecureTrie(cache, hash); ContractDetailsImpl details = new ContractDetailsImpl(this.address, snapStorage, getCodes()); details.externalStorage = this.externalStorage; details.externalStorageDataSource = this.externalStorageDataSource; details.keys = this.keys; details.config = config; details.commonConfig = commonConfig; details.dataSource = dataSource; return details; } }
6,652
27.676724
110
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/jsontestsuite/suite/Utils.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.jsontestsuite.suite; import org.ethereum.util.ByteUtil; import org.spongycastle.util.encoders.Hex; import java.math.BigInteger; import static org.ethereum.util.ByteUtil.EMPTY_BYTE_ARRAY; import static org.ethereum.util.Utils.unifiedNumericToBigInteger; /** * @author Roman Mandeleil * @since 15.12.2014 */ public class Utils { public static byte[] parseVarData(String data){ if (data == null || data.isEmpty()) return EMPTY_BYTE_ARRAY; byte[] bytes; if (data.startsWith("0x")) { data = data.substring(2); if (data.isEmpty()) return EMPTY_BYTE_ARRAY; if (data.length() % 2 == 1) data = "0" + data; bytes = Hex.decode(data); } else { bytes = parseNumericData(data); } if (ByteUtil.firstNonZeroByte(bytes) == -1) { return EMPTY_BYTE_ARRAY; } else { return bytes; } } public static byte[] parseData(String data) { if (data == null) return EMPTY_BYTE_ARRAY; if (data.startsWith("0x")) data = data.substring(2); if (data.length() % 2 != 0) data = "0" + data; return Hex.decode(data); } public static byte[] parseNumericData(String data){ if (data == null || data.isEmpty()) return EMPTY_BYTE_ARRAY; byte[] dataB = unifiedNumericToBigInteger(data).toByteArray(); return ByteUtil.stripLeadingZeroes(dataB); } public static long parseLong(String data) { boolean hex = data.startsWith("0x"); if (hex) data = data.substring(2); if (data.isEmpty()) return 0; return new BigInteger(data, hex ? 16 : 10).longValue(); } public static byte parseByte(String data) { if (data.startsWith("0x")) { data = data.substring(2); return data.isEmpty() ? 0 : Byte.parseByte(data, 16); } else return data.isEmpty() ? 0 : Byte.parseByte(data); } public static String parseUnidentifiedBase(String number) { if (number.startsWith("0x")) number = new BigInteger(number.substring(2), 16).toString(10); return number; } }
2,982
30.734043
80
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/jsontestsuite/suite/DifficultyTestSuite.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.jsontestsuite.suite; import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.ObjectMapper; import java.io.IOException; import java.util.*; /** * @author Mikhail Kalinin * @since 02.09.2015 */ public class DifficultyTestSuite { List<DifficultyTestCase> testCases = new ArrayList<>(); public DifficultyTestSuite(String json) throws IOException { ObjectMapper mapper = new ObjectMapper(); JavaType type = mapper.getTypeFactory(). constructMapType(HashMap.class, String.class, DifficultyTestCase.class); Map<String, DifficultyTestCase> caseMap = new ObjectMapper().readValue(json, type); for (Map.Entry<String, DifficultyTestCase> e : caseMap.entrySet()) { e.getValue().setName(e.getKey()); testCases.add(e.getValue()); } testCases.sort(Comparator.comparing(DifficultyTestCase::getName)); } public List<DifficultyTestCase> getTestCases() { return testCases; } @Override public String toString() { return "DifficultyTestSuite{" + "testCases=" + testCases + '}'; } }
1,983
32.066667
91
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/jsontestsuite/suite/VMTestSuite.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.jsontestsuite.suite; import org.ethereum.jsontestsuite.GitHubJSONTestSuite; import org.json.simple.parser.ParseException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.IOException; import java.util.*; import static org.ethereum.jsontestsuite.GitHubJSONTestSuite.runGitHubJsonVMTest; import static org.ethereum.jsontestsuite.suite.JSONReader.listJsonBlobsForTreeSha; import static org.ethereum.jsontestsuite.suite.JSONReader.loadJSONFromCommit; import static org.ethereum.jsontestsuite.suite.JSONReader.loadJSONsFromCommit; /** * @author Mikhail Kalinin * @since 08.09.2017 */ public class VMTestSuite { private static Logger logger = LoggerFactory.getLogger("TCK-Test"); private static final String TEST_ROOT = "VMTests/"; String commitSHA; List<String> files; public VMTestSuite(String treeSHA, String commitSHA) throws IOException { files = listJsonBlobsForTreeSha(treeSHA, TEST_ROOT); this.commitSHA = commitSHA; } public void runAll(String testCaseRoot) throws ParseException { run(testCaseRoot, Collections.<String>emptySet()); } public void run(String testCaseRoot, Set<String> excluded) throws ParseException { List<String> testCaseFiles = new ArrayList<>(); for (String file : files) { if (file.startsWith(testCaseRoot + "/")) testCaseFiles.add(file); } Set<String> toExclude = new HashSet<>(); for (String file : testCaseFiles) { String fileName = file.substring(file.lastIndexOf('/') + 1, file.lastIndexOf(".json")); if (excluded.contains(fileName)) { logger.info(" [X] " + file); toExclude.add(file); } else { logger.info(" " + file); } } testCaseFiles.removeAll(toExclude); if (testCaseFiles.isEmpty()) return; List<String> filenames = new ArrayList<>(); for (String file : testCaseFiles) { filenames.add(TEST_ROOT + file); } List<String> jsons = loadJSONsFromCommit(filenames, commitSHA); for (String json : jsons) { runGitHubJsonVMTest(json); } } public static void runSingle(String commitSHA, String file) throws ParseException, IOException { logger.info(" " + file); String json = loadJSONFromCommit(TEST_ROOT + file, commitSHA); runGitHubJsonVMTest(json); } }
3,282
33.925532
100
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/jsontestsuite/suite/GeneralStateTestSuite.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.jsontestsuite.suite; import org.ethereum.jsontestsuite.GitHubJSONTestSuite; import org.ethereum.jsontestsuite.suite.runners.StateTestRunner; import org.junit.Assert; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.IOException; import java.util.*; import static org.ethereum.jsontestsuite.suite.JSONReader.listJsonBlobsForTreeSha; import static org.ethereum.jsontestsuite.suite.JSONReader.loadJSONFromCommit; import static org.ethereum.jsontestsuite.suite.JSONReader.loadJSONsFromCommit; /** * @author Mikhail Kalinin * @since 11.08.2017 */ public class GeneralStateTestSuite { private static Logger logger = LoggerFactory.getLogger("TCK-Test"); private static final String STATE_TEST_ROOT = "GeneralStateTests/"; String commitSHA; List<String> files; GitHubJSONTestSuite.Network[] networks; public GeneralStateTestSuite(String treeSHA, String commitSHA, GitHubJSONTestSuite.Network[] networks) throws IOException { files = listJsonBlobsForTreeSha(treeSHA, STATE_TEST_ROOT); this.commitSHA = commitSHA; this.networks = networks; } private static void run(List<String> checkFiles, String commitSHA, GitHubJSONTestSuite.Network[] networks) throws IOException { if (checkFiles.isEmpty()) return; List<StateTestData> suites = new ArrayList<>(); List<String> filenames = new ArrayList<>(); for (String file : checkFiles) { filenames.add(STATE_TEST_ROOT + file); } List<String> jsons = loadJSONsFromCommit(filenames, commitSHA); for (String json : jsons) { suites.add(new StateTestData(json)); } List<StateTestCase> testCases = new ArrayList<>(); for (GitHubJSONTestSuite.Network network : networks) { for (StateTestData suite : suites) { testCases.addAll(suite.getTestCases(network)); } } Map<String, Boolean> summary = new HashMap<>(); for (StateTestCase testCase : testCases) { String output = String.format("* running: %s *", testCase.getName()); String line = output.replaceAll(".", "*"); logger.info(line); logger.info(output); logger.info(line); List<String> result = StateTestRunner.run(testCase); if (!result.isEmpty()) summary.put(testCase.getName(), false); else summary.put(testCase.getName(), true); } logger.info("Summary: "); logger.info("========="); int fails = 0; int pass = 0; for (String key : summary.keySet()){ if (summary.get(key)) ++pass; else ++fails; String sumTest = String.format("%-60s:^%s", key, (summary.get(key) ? "OK" : "FAIL")). replace(' ', '.'). replace("^", " "); logger.info(sumTest); } logger.info(" - Total: Pass: {}, Failed: {} - ", pass, fails); Assert.assertTrue(fails == 0); } public void runAll(String testCaseRoot, Set<String> excludedCases, GitHubJSONTestSuite.Network[] networks) throws IOException { List<String> testCaseFiles = new ArrayList<>(); for (String file : files) { if (file.startsWith(testCaseRoot + "/")) testCaseFiles.add(file); } Set<String> toExclude = new HashSet<>(); for (String file : testCaseFiles) { String fileName = file.substring(file.lastIndexOf('/') + 1, file.lastIndexOf(".json")); if (excludedCases.contains(fileName)) { logger.info(" [X] " + file); toExclude.add(file); } else { logger.info(" " + file); } } testCaseFiles.removeAll(toExclude); run(testCaseFiles, commitSHA, networks); } public void runAll(String testCaseRoot) throws IOException { runAll(testCaseRoot, Collections.<String>emptySet(), networks); } public void runAll(String testCaseRoot, Set<String> excludedCases) throws IOException { runAll(testCaseRoot, excludedCases, networks); } public void runAll(String testCaseRoot, GitHubJSONTestSuite.Network network) throws IOException { runAll(testCaseRoot, Collections.<String>emptySet(), new GitHubJSONTestSuite.Network[]{network}); } public static void runSingle(String testFile, String commitSHA, GitHubJSONTestSuite.Network network) throws IOException { logger.info(" " + testFile); run(Collections.singletonList(testFile), commitSHA, new GitHubJSONTestSuite.Network[] { network }); } }
5,593
35.090323
131
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/jsontestsuite/suite/EnvTestRepository.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.jsontestsuite.suite; import org.ethereum.core.*; import org.ethereum.db.RepositoryImpl; import java.math.BigInteger; /** * Repository for running GitHubVMTest. * The slightly modified behavior from original impl: * it creates empty account whenever it 'touched': getCode() or getBalance() * Created by Anton Nashatyrev on 03.11.2016. */ public class EnvTestRepository extends IterableTestRepository { public EnvTestRepository(Repository src) { super(src); } public BigInteger setNonce(byte[] addr, BigInteger nonce) { if (!(src instanceof RepositoryImpl)) throw new RuntimeException("Not supported"); return ((RepositoryImpl) src).setNonce(addr, nonce); } @Override public byte[] getCode(byte[] addr) { addAccount(addr); return src.getCode(addr); } @Override public BigInteger getBalance(byte[] addr) { addAccount(addr); return src.getBalance(addr); } }
1,774
31.272727
90
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/jsontestsuite/suite/ABITestCase.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.jsontestsuite.suite; import com.fasterxml.jackson.annotation.JsonIgnore; import org.ethereum.core.CallTransaction; import org.spongycastle.util.encoders.Hex; import java.util.List; /** * @author Mikhail Kalinin * @since 28.09.2017 */ public class ABITestCase { @JsonIgnore String name; List<Object> args; String[] types; String result; public String getName() { return name; } public void setName(String name) { this.name = name; } public List<Object> getArgs() { return args; } public void setArgs(List<Object> args) { this.args = args; } public String[] getTypes() { return types; } public void setTypes(String[] types) { this.types = types; } public String getResult() { return result; } public void setResult(String result) { this.result = result; } public String getEncoded() { CallTransaction.Function f = CallTransaction.Function.fromSignature("test", types); byte[] encoded = f.encodeArguments(args.toArray()); return Hex.toHexString(encoded); } @Override public String toString() { return "ABITestCase{" + "name='" + name + '\'' + ", args=" + args + ", types=" + types + ", result='" + result + '\'' + '}'; } }
2,231
24.078652
91
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/jsontestsuite/suite/CallCreate.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.jsontestsuite.suite; import org.ethereum.util.ByteUtil; import org.json.simple.JSONObject; import org.spongycastle.util.encoders.Hex; /** * @author Roman Mandeleil * @since 28.06.2014 */ public class CallCreate { private final byte[] data; private final byte[] destination; private final byte[] gasLimit; private final byte[] value; /* e.g. "data" : [ ], "destination" : "cd1722f3947def4cf144679da39c4c32bdc35681", "gasLimit" : 9792, "value" : 74 */ public CallCreate(JSONObject callCreateJSON) { String data = callCreateJSON.get("data").toString(); String destination = callCreateJSON.get("destination").toString(); String gasLimit = callCreateJSON.get("gasLimit").toString(); String value = callCreateJSON.get("value").toString(); if (data != null && data.length() > 2) this.data = Utils.parseData(data); else this.data = ByteUtil.EMPTY_BYTE_ARRAY; this.destination = Utils.parseData(destination); this.gasLimit = ByteUtil.bigIntegerToBytes(TestCase.toBigInt(gasLimit)); this.value = ByteUtil.bigIntegerToBytes(TestCase.toBigInt(value)); } public byte[] getData() { return data; } public byte[] getDestination() { return destination; } public byte[] getGasLimit() { return gasLimit; } public byte[] getValue() { return value; } @Override public String toString() { return "CallCreate{" + "data=" + Hex.toHexString(data) + ", destination=" + Hex.toHexString(destination) + ", gasLimit=" + Hex.toHexString(gasLimit) + ", value=" + Hex.toHexString(value) + '}'; } }
2,626
28.852273
80
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/jsontestsuite/suite/EthashTestSuite.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.jsontestsuite.suite; import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.ObjectMapper; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; /** * @author Mikhail Kalinin * @since 03.09.2015 */ public class EthashTestSuite { List<EthashTestCase> testCases = new ArrayList<>(); public EthashTestSuite(String json) throws IOException { ObjectMapper mapper = new ObjectMapper(); JavaType type = mapper.getTypeFactory(). constructMapType(HashMap.class, String.class, EthashTestCase.class); Map<String, EthashTestCase> caseMap = new ObjectMapper().readValue(json, type); for (Map.Entry<String, EthashTestCase> e : caseMap.entrySet()) { e.getValue().setName(e.getKey()); testCases.add(e.getValue()); } } public List<EthashTestCase> getTestCases() { return testCases; } @Override public String toString() { return "EthashTestSuite{" + "testCases=" + testCases + '}'; } }
1,954
31.04918
87
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/jsontestsuite/suite/Env.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.jsontestsuite.suite; import org.json.simple.JSONObject; import org.spongycastle.util.BigIntegers; import org.spongycastle.util.encoders.Hex; /** * @author Roman Mandeleil * @since 28.06.2014 */ public class Env { private final byte[] currentCoinbase; private final byte[] currentDifficulty; private final byte[] currentGasLimit; private final byte[] currentNumber; private final byte[] currentTimestamp; private final byte[] previousHash; public Env(byte[] currentCoinbase, byte[] currentDifficulty, byte[] currentGasLimit, byte[] currentNumber, byte[] currentTimestamp, byte[] previousHash) { this.currentCoinbase = currentCoinbase; this.currentDifficulty = currentDifficulty; this.currentGasLimit = currentGasLimit; this.currentNumber = currentNumber; this.currentTimestamp = currentTimestamp; this.previousHash = previousHash; } /* e.g: "currentCoinbase" : "2adc25665018aa1fe0e6bc666dac8fc2697ff9ba", "currentDifficulty" : "256", "currentGasLimit" : "1000000", "currentNumber" : "0", "currentTimestamp" : 1, "previousHash" : "5e20a0453cecd065ea59c37ac63e079ee08998b6045136a8ce6635c7912ec0b6" */ public Env(JSONObject env) { String coinbase = env.get("currentCoinbase").toString(); String difficulty = env.get("currentDifficulty").toString(); String timestamp = env.get("currentTimestamp").toString(); String number = env.get("currentNumber").toString(); String gasLimit = Utils.parseUnidentifiedBase(env.get("currentGasLimit").toString()); Object previousHash = env.get("previousHash"); String prevHash = previousHash == null ? "" : previousHash.toString(); this.currentCoinbase = Utils.parseData(coinbase); this.currentDifficulty = BigIntegers.asUnsignedByteArray(TestCase.toBigInt(difficulty) ); this.currentGasLimit = BigIntegers.asUnsignedByteArray(TestCase.toBigInt(gasLimit)); this.currentNumber = TestCase.toBigInt(number).toByteArray(); this.currentTimestamp = TestCase.toBigInt(timestamp).toByteArray(); this.previousHash = Utils.parseData(prevHash); } public byte[] getCurrentCoinbase() { return currentCoinbase; } public byte[] getCurrentDifficulty() { return currentDifficulty; } public byte[] getCurrentGasLimit() { return currentGasLimit; } public byte[] getCurrentNumber() { return currentNumber; } public byte[] getCurrentTimestamp() { return currentTimestamp; } public byte[] getPreviousHash() { return previousHash; } @Override public String toString() { return "Env{" + "currentCoinbase=" + Hex.toHexString(currentCoinbase) + ", currentDifficulty=" + Hex.toHexString(currentDifficulty) + ", currentGasLimit=" + Hex.toHexString(currentGasLimit) + ", currentNumber=" + Hex.toHexString(currentNumber) + ", currentTimestamp=" + Hex.toHexString(currentTimestamp) + ", previousHash=" + Hex.toHexString(previousHash) + '}'; } }
4,172
35.605263
103
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/jsontestsuite/suite/TxTestSuite.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.jsontestsuite.suite; import org.json.simple.parser.ParseException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.IOException; import java.util.*; import static org.ethereum.jsontestsuite.GitHubJSONTestSuite.runGitHubJsonTransactionTest; import static org.ethereum.jsontestsuite.GitHubJSONTestSuite.runGitHubJsonVMTest; import static org.ethereum.jsontestsuite.suite.JSONReader.listJsonBlobsForTreeSha; import static org.ethereum.jsontestsuite.suite.JSONReader.loadJSONFromCommit; import static org.ethereum.jsontestsuite.suite.JSONReader.loadJSONsFromCommit; /** * @author Mikhail Kalinin * @since 11.09.2017 */ public class TxTestSuite { private static Logger logger = LoggerFactory.getLogger("TCK-Test"); private static final String TEST_ROOT = "TransactionTests/"; String commitSHA; List<String> files; public TxTestSuite(String treeSHA, String commitSHA) throws IOException { files = listJsonBlobsForTreeSha(treeSHA, TEST_ROOT); this.commitSHA = commitSHA; } public void runAll(String testCaseRoot) throws ParseException, IOException { run(testCaseRoot, Collections.<String>emptySet()); } public void run(String testCaseRoot, Set<String> excluded) throws ParseException, IOException { List<String> testCaseFiles = new ArrayList<>(); for (String file : files) { if (file.startsWith(testCaseRoot + "/")) testCaseFiles.add(file); } Set<String> toExclude = new HashSet<>(); for (String file : testCaseFiles) { String fileName = file.substring(file.lastIndexOf('/') + 1, file.lastIndexOf(".json")); if (excluded.contains(fileName)) { logger.info(" [X] " + file); toExclude.add(file); } else { logger.info(" " + file); } } testCaseFiles.removeAll(toExclude); if (testCaseFiles.isEmpty()) return; List<String> filenames = new ArrayList<>(); for (String file : testCaseFiles) { filenames.add(TEST_ROOT + file); } List<String> jsons = loadJSONsFromCommit(filenames, commitSHA); for (String json : jsons) { runGitHubJsonTransactionTest(json); } } public static void runSingle(String commitSHA, String file) throws ParseException, IOException { logger.info(" " + file); String json = loadJSONFromCommit(TEST_ROOT + file, commitSHA); runGitHubJsonTransactionTest(json); } }
3,371
34.87234
100
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/jsontestsuite/suite/CryptoTestCase.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.jsontestsuite.suite; import org.ethereum.crypto.ECIESCoder; import org.ethereum.crypto.ECKey; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.spongycastle.util.encoders.Hex; import java.math.BigInteger; /** * @author Roman Mandeleil * @since 08.02.2015 */ public class CryptoTestCase { private static Logger logger = LoggerFactory.getLogger("TCK-Test"); private String decryption_type = ""; private String key = ""; private String cipher = ""; private String payload = ""; public CryptoTestCase(){ } public void execute(){ byte[] key = Hex.decode(this.key); byte[] cipher = Hex.decode(this.cipher); ECKey ecKey = ECKey.fromPrivate(key); byte[] resultPayload = new byte[0]; if (decryption_type.equals("aes_ctr")) resultPayload = ecKey.decryptAES(cipher); if (decryption_type.equals("ecies_sec1_altered")) try { resultPayload = ECIESCoder.decrypt(new BigInteger(Hex.toHexString(key), 16), cipher); } catch (Throwable e) {e.printStackTrace();} if (!Hex.toHexString(resultPayload).equals(payload)){ String error = String.format("payload should be: %s, but got that result: %s ", payload, Hex.toHexString(resultPayload)); logger.info(error); System.exit(-1); } } public String getDecryption_type() { return decryption_type; } public void setDecryption_type(String decryption_type) { this.decryption_type = decryption_type; } public String getKey() { return key; } public void setKey(String key) { this.key = key; } public String getCipher() { return cipher; } public void setCipher(String cipher) { this.cipher = cipher; } public String getPayload() { return payload; } public void setPayload(String payload) { this.payload = payload; } @Override public String toString() { return "CryptoTestCase{" + "decryption_type='" + decryption_type + '\'' + ", key='" + key + '\'' + ", cipher='" + cipher + '\'' + ", payload='" + payload + '\'' + '}'; } }
3,137
26.526316
101
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/jsontestsuite/suite/AbstractContractDetails.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.jsontestsuite.suite; import org.ethereum.db.ByteArrayWrapper; import org.ethereum.db.ContractDetails; import org.ethereum.vm.DataWord; import org.spongycastle.util.encoders.Hex; import java.util.HashMap; import java.util.Map; import java.util.Set; import static org.ethereum.crypto.HashUtil.sha3; import static org.ethereum.crypto.HashUtil.EMPTY_DATA_HASH; import static org.ethereum.util.ByteUtil.EMPTY_BYTE_ARRAY; /** * Common functionality for ContractDetails implementations * * Created by Anton Nashatyrev on 24.03.2016. */ public abstract class AbstractContractDetails implements ContractDetails { private boolean dirty = false; private boolean deleted = false; private Map<ByteArrayWrapper, byte[]> codes = new HashMap<>(); @Override public byte[] getCode() { return codes.size() == 0 ? EMPTY_BYTE_ARRAY : codes.values().iterator().next(); } @Override public byte[] getCode(byte[] codeHash) { if (java.util.Arrays.equals(codeHash, EMPTY_DATA_HASH)) return EMPTY_BYTE_ARRAY; byte[] code = codes.get(new ByteArrayWrapper(codeHash)); return code == null ? EMPTY_BYTE_ARRAY : code; } @Override public void setCode(byte[] code) { if (code == null) return; codes.put(new ByteArrayWrapper(sha3(code)), code); setDirty(true); } protected Map<ByteArrayWrapper, byte[]> getCodes() { return codes; } protected void setCodes(Map<ByteArrayWrapper, byte[]> codes) { this.codes = new HashMap<>(codes); } protected void appendCodes(Map<ByteArrayWrapper, byte[]> codes) { this.codes.putAll(codes); } @Override public void setDirty(boolean dirty) { this.dirty = dirty; } @Override public boolean isDirty() { return dirty; } @Override public void setDeleted(boolean deleted) { this.deleted = deleted; } @Override public boolean isDeleted() { return deleted; } public abstract ContractDetails clone(); @Override public void deleteStorage() { Set<DataWord> keys = getStorageKeys(); for (DataWord key: keys) { put(key, DataWord.ZERO); } } @Override public String toString() { String ret = " Code: " + (codes.size() < 2 ? Hex.toHexString(getCode()) : codes.size() + " versions" ) + "\n"; ret += " Storage: " + getStorage().toString(); return ret; } }
3,303
27.982456
119
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/jsontestsuite/suite/TestSuite.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.jsontestsuite.suite; import org.json.simple.JSONObject; import org.json.simple.parser.ParseException; import java.util.ArrayList; import java.util.Iterator; import java.util.List; /** * @author Roman Mandeleil * @since 10.07.2014 */ public class TestSuite { List<TestCase> testList = new ArrayList<>(); public TestSuite(JSONObject testCaseJSONObj) throws ParseException { for (Object key : testCaseJSONObj.keySet()) { Object testCaseJSON = testCaseJSONObj.get(key); TestCase testCase = new TestCase(key.toString(), (JSONObject) testCaseJSON); testList.add(testCase); } } public List<TestCase> getAllTests(){ return testList; } public Iterator<TestCase> iterator() { return testList.iterator(); } }
1,617
29.528302
88
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/jsontestsuite/suite/BlockTestCase.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.jsontestsuite.suite; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import org.ethereum.config.BlockchainNetConfig; import org.ethereum.jsontestsuite.GitHubJSONTestSuite; import org.ethereum.jsontestsuite.suite.model.AccountTck; import org.ethereum.jsontestsuite.suite.model.BlockHeaderTck; import org.ethereum.jsontestsuite.suite.model.BlockTck; import java.util.List; import java.util.Map; @JsonIgnoreProperties(ignoreUnknown = true) public class BlockTestCase { private String acomment; private List<BlockTck> blocks; private BlockHeaderTck genesisBlockHeader; private String genesisRLP; private Map<String, AccountTck> pre; private Map<String, AccountTck> postState; private String lastblockhash; private int noBlockChainHistory; private GitHubJSONTestSuite.Network network; private SealEngine sealEngine = SealEngine.Ethash; public BlockTestCase() { } public String getLastblockhash() { return lastblockhash; } public void setLastblockhash(String lastblockhash) { this.lastblockhash = lastblockhash; } public List<BlockTck> getBlocks() { return blocks; } public void setBlocks(List<BlockTck> blocks) { this.blocks = blocks; } public BlockHeaderTck getGenesisBlockHeader() { return genesisBlockHeader; } public void setGenesisBlockHeader(BlockHeaderTck genesisBlockHeader) { this.genesisBlockHeader = genesisBlockHeader; } public Map<String, AccountTck> getPre() { return pre; } public String getGenesisRLP() { return genesisRLP; } public void setPre(Map<String, AccountTck> pre) { this.pre = pre; } public Map<String, AccountTck> getPostState() { return postState; } public void setPostState(Map<String, AccountTck> postState) { this.postState = postState; } public int getNoBlockChainHistory() { return noBlockChainHistory; } public void setNoBlockChainHistory(int noBlockChainHistory) { this.noBlockChainHistory = noBlockChainHistory; } public String getAcomment() { return acomment; } public void setAcomment(String acomment) { this.acomment = acomment; } public GitHubJSONTestSuite.Network getNetwork() { return network; } public void setNetwork(GitHubJSONTestSuite.Network network) { this.network = network; } public BlockchainNetConfig getConfig() { return network.getConfig(); } public SealEngine getSealEngine() { return sealEngine; } public void setSealEngine(SealEngine sealEngine) { this.sealEngine = sealEngine; } @Override public String toString() { return "BlockTestCase{" + "blocks=" + blocks + ", genesisBlockHeader=" + genesisBlockHeader + ", pre=" + pre + '}'; } enum SealEngine { NoProof, // blocks in the test should not be checked for difficulty Ethash } }
3,913
26.758865
80
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/jsontestsuite/suite/StateTestDataEntry.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.jsontestsuite.suite; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import org.ethereum.jsontestsuite.GitHubJSONTestSuite; import org.ethereum.jsontestsuite.suite.model.AccountTck; import org.ethereum.jsontestsuite.suite.model.EnvTck; import org.ethereum.jsontestsuite.suite.model.PostDataTck; import org.ethereum.jsontestsuite.suite.model.TransactionDataTck; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; /** * @author Mikhail Kalinin * @since 09.08.2017 */ @JsonIgnoreProperties(ignoreUnknown = true) public class StateTestDataEntry { EnvTck env; Map<String, AccountTck> pre; Map<String, List<PostDataTck>> post; TransactionDataTck transaction; public EnvTck getEnv() { return env; } public void setEnv(EnvTck env) { this.env = env; } public Map<String, AccountTck> getPre() { return pre; } public void setPre(Map<String, AccountTck> pre) { this.pre = pre; } public Map<String, List<PostDataTck>> getPost() { return post; } public void setPost(Map<String, List<PostDataTck>> post) { this.post = post; } public TransactionDataTck getTransaction() { return transaction; } public void setTransaction(TransactionDataTck transaction) { this.transaction = transaction; } public List<StateTestCase> getTestCases(GitHubJSONTestSuite.Network network) { List<PostDataTck> postData = post.get(network.name()); if (postData == null) return Collections.emptyList(); List<StateTestCase> testCases = new ArrayList<>(); for (PostDataTck data : postData) { StateTestCase testCase = new StateTestCase(); testCase.setEnv(env); testCase.setPre(pre); if (data.getLogs() != null) { testCase.setLogs(data.getLogs()); } else { testCase.setLogs(new Logs("0x")); } if (data.getHash() != null) { testCase.setPostStateRoot(data.getHash().startsWith("0x") ? data.getHash().substring(2) : data.getHash()); } testCase.setTransaction(transaction.getTransaction(data.getIndexes())); testCase.setNetwork(network); testCases.add(testCase); } return testCases; } }
3,215
29.923077
122
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/jsontestsuite/suite/ABITestSuite.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.jsontestsuite.suite; import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.ObjectMapper; import java.io.IOException; import java.util.*; /** * @author Mikhail Kalinin * @since 28.09.2017 */ public class ABITestSuite { List<ABITestCase> testCases = new ArrayList<>(); public ABITestSuite(String json) throws IOException { ObjectMapper mapper = new ObjectMapper(); JavaType type = mapper.getTypeFactory(). constructMapType(HashMap.class, String.class, ABITestCase.class); Map<String, ABITestCase> caseMap = new ObjectMapper().readValue(json, type); for (Map.Entry<String, ABITestCase> e : caseMap.entrySet()) { e.getValue().setName(e.getKey()); testCases.add(e.getValue()); } testCases.sort(Comparator.comparing(ABITestCase::getName)); } public List<ABITestCase> getTestCases() { return testCases; } @Override public String toString() { return "ABITestSuite{" + "testCases=" + testCases + '}'; } }
1,920
31.016667
84
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/jsontestsuite/suite/TransactionTestSuite.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.jsontestsuite.suite; import com.fasterxml.jackson.databind.ObjectMapper; import org.ethereum.jsontestsuite.GitHubJSONTestSuite; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.IOException; import java.util.HashMap; import java.util.Map; public class TransactionTestSuite { private Logger logger = LoggerFactory.getLogger("TCK-Test"); Map<String, TransactionTestCase> testCases = new HashMap<>(); public TransactionTestSuite(String json) throws IOException { Map<String, TransactionTestCase> testCases = new HashMap<>(); Map<String, Object> jsonData = (Map<String, Object>) new ObjectMapper().readValue(json, Object.class); for (Map.Entry<String, Object> currentCase : jsonData.entrySet()) { String namePrefix = currentCase.getKey() + "_"; Map<String, TransactionTestCase> currentCases = new HashMap<>(); Map<String, Object> networksEtc = (Map<String, Object>) currentCase.getValue(); String rlp = null; for (Map.Entry<String, Object> currentField : networksEtc.entrySet()) { String currentKey = currentField.getKey(); GitHubJSONTestSuite.Network maybeNetwork = null; try { maybeNetwork = GitHubJSONTestSuite.Network.valueOf(currentKey); } catch (IllegalArgumentException ex) { // just not filling maybeNetwork } if (maybeNetwork != null) { TransactionTestCase txCase = new TransactionTestCase(); txCase.setNetwork(maybeNetwork); Map<String, Object> txCaseMap = (Map<String, Object>) currentField.getValue(); for (String key : txCaseMap.keySet()) { if (key.equals("hash")) { txCase.setExpectedHash((String) txCaseMap.get(key)); } else if (key.equals("sender")) { txCase.setExpectedRlp((String) txCaseMap.get(key)); } else { String error = String.format("Expected transaction is not fully parsed, key \"%s\" missed!", key); throw new RuntimeException(error); } } currentCases.put(namePrefix + currentKey, txCase); } else if (currentKey.equals("rlp")) { rlp = (String) currentField.getValue(); } else if (currentKey.equals("_info")) { // legal key, just skip } else { String error = String.format("Transaction test case is not fully parsed, key \"%s\" missed!", currentKey); throw new RuntimeException(error); } } for (TransactionTestCase testCase : currentCases.values()) { testCase.setRlp(rlp); } testCases.putAll(currentCases); } this.testCases = testCases; } public Map<String, TransactionTestCase> getTestCases() { return testCases; } @Override public String toString() { return "TransactionTestSuite{" + "testCases=" + testCases + '}'; } }
4,147
40.89899
126
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/jsontestsuite/suite/DifficultyTestCase.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.jsontestsuite.suite; import com.fasterxml.jackson.annotation.JsonIgnore; import org.ethereum.core.BlockHeader; import java.math.BigInteger; import static org.ethereum.jsontestsuite.suite.Utils.parseData; import static org.ethereum.util.ByteUtil.EMPTY_BYTE_ARRAY; /** * @author Mikhail Kalinin * @since 02.09.2015 */ public class DifficultyTestCase { @JsonIgnore private String name; // Test data private String parentTimestamp; private String parentDifficulty; private String currentTimestamp; private String currentBlockNumber; private String currentDifficulty; private String parentUncles; public String getName() { return name; } public void setName(String name) { this.name = name; } public String getParentTimestamp() { return parentTimestamp; } public void setParentTimestamp(String parentTimestamp) { this.parentTimestamp = parentTimestamp; } public String getParentDifficulty() { return parentDifficulty; } public void setParentDifficulty(String parentDifficulty) { this.parentDifficulty = parentDifficulty; } public String getCurrentTimestamp() { return currentTimestamp; } public void setCurrentTimestamp(String currentTimestamp) { this.currentTimestamp = currentTimestamp; } public String getCurrentBlockNumber() { return currentBlockNumber; } public void setCurrentBlockNumber(String currentBlockNumber) { this.currentBlockNumber = currentBlockNumber; } public String getCurrentDifficulty() { return currentDifficulty; } public void setCurrentDifficulty(String currentDifficulty) { this.currentDifficulty = currentDifficulty; } public String getParentUncles() { return parentUncles; } public void setParentUncles(String parentUncles) { this.parentUncles = parentUncles; } public BlockHeader getCurrent() { return new BlockHeader( EMPTY_BYTE_ARRAY, EMPTY_BYTE_ARRAY, EMPTY_BYTE_ARRAY, EMPTY_BYTE_ARRAY, EMPTY_BYTE_ARRAY, Utils.parseLong(currentBlockNumber), new byte[] {0}, 0, Utils.parseLong(currentTimestamp), EMPTY_BYTE_ARRAY, EMPTY_BYTE_ARRAY, EMPTY_BYTE_ARRAY ); } public BlockHeader getParent() { return new BlockHeader( EMPTY_BYTE_ARRAY, parseData(parentUncles), EMPTY_BYTE_ARRAY, EMPTY_BYTE_ARRAY, Utils.parseNumericData(parentDifficulty), Utils.parseLong(currentBlockNumber) - 1, new byte[] {0}, 0, Utils.parseLong(parentTimestamp), EMPTY_BYTE_ARRAY, EMPTY_BYTE_ARRAY, EMPTY_BYTE_ARRAY ); } public BigInteger getExpectedDifficulty() { return new BigInteger(1, Utils.parseNumericData(currentDifficulty)); } @Override public String toString() { return "DifficultyTestCase{" + "name='" + name + '\'' + ", parentTimestamp='" + parentTimestamp + '\'' + ", parentDifficulty='" + parentDifficulty + '\'' + ", currentTimestamp='" + currentTimestamp + '\'' + ", currentBlockNumber='" + currentBlockNumber + '\'' + ", currentDifficulty='" + currentDifficulty + '\'' + '}'; } }
4,225
30.073529
105
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/jsontestsuite/suite/TestProgramInvokeFactory.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.jsontestsuite.suite; import org.ethereum.core.Block; import org.ethereum.core.Transaction; import org.ethereum.db.BlockStore; import org.ethereum.core.Repository; import org.ethereum.util.ByteUtil; import org.ethereum.vm.DataWord; import org.ethereum.vm.program.Program; import org.ethereum.vm.program.invoke.ProgramInvoke; import org.ethereum.vm.program.invoke.ProgramInvokeFactory; import org.ethereum.vm.program.invoke.ProgramInvokeImpl; import java.math.BigInteger; /** * @author Roman Mandeleil * @since 19.12.2014 */ public class TestProgramInvokeFactory implements ProgramInvokeFactory { private final Env env; public TestProgramInvokeFactory(Env env) { this.env = env; } @Override public ProgramInvoke createProgramInvoke(Transaction tx, Block block, Repository repository, Repository origRepository, BlockStore blockStore) { return generalInvoke(tx, repository, origRepository, blockStore); } @Override public ProgramInvoke createProgramInvoke(Program program, DataWord toAddress, DataWord callerAddress, DataWord inValue, DataWord inGas, BigInteger balanceInt, byte[] dataIn, Repository repository, Repository origRepository, BlockStore blockStore, boolean isStaticCall, boolean byTestingSuite) { return null; } private ProgramInvoke generalInvoke(Transaction tx, Repository repository, Repository origRepository, BlockStore blockStore) { /*** ADDRESS op ***/ // YP: Get address of currently executing account. byte[] address = tx.isContractCreation() ? tx.getContractAddress() : tx.getReceiveAddress(); /*** ORIGIN op ***/ // YP: This is the sender of original transaction; it is never a contract. byte[] origin = tx.getSender(); /*** CALLER op ***/ // YP: This is the address of the account that is directly responsible for this execution. byte[] caller = tx.getSender(); /*** BALANCE op ***/ byte[] balance = repository.getBalance(address).toByteArray(); /*** GASPRICE op ***/ byte[] gasPrice = tx.getGasPrice(); /*** GAS op ***/ byte[] gas = tx.getGasLimit(); /*** CALLVALUE op ***/ byte[] callValue = tx.getValue() == null ? new byte[]{0} : tx.getValue(); /*** CALLDATALOAD op ***/ /*** CALLDATACOPY op ***/ /*** CALLDATASIZE op ***/ byte[] data = tx.isContractCreation() ? ByteUtil.EMPTY_BYTE_ARRAY :( tx.getData() == null ? ByteUtil.EMPTY_BYTE_ARRAY : tx.getData() ); // byte[] data = tx.getData() == null ? ByteUtil.EMPTY_BYTE_ARRAY : tx.getData() ; /*** PREVHASH op ***/ byte[] lastHash = env.getPreviousHash(); /*** COINBASE op ***/ byte[] coinbase = env.getCurrentCoinbase(); /*** TIMESTAMP op ***/ long timestamp = ByteUtil.byteArrayToLong(env.getCurrentTimestamp()); /*** NUMBER op ***/ long number = ByteUtil.byteArrayToLong(env.getCurrentNumber()); /*** DIFFICULTY op ***/ byte[] difficulty = env.getCurrentDifficulty(); /*** GASLIMIT op ***/ byte[] gaslimit = env.getCurrentGasLimit(); return new ProgramInvokeImpl(address, origin, caller, balance, gasPrice, gas, callValue, data, lastHash, coinbase, timestamp, number, difficulty, gaslimit, repository, origRepository, blockStore); } }
4,615
37.789916
143
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/jsontestsuite/suite/Exec.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.jsontestsuite.suite; import org.ethereum.util.ByteUtil; import org.json.simple.JSONObject; import org.spongycastle.util.encoders.Hex; /** * @author Roman Mandeleil * @since 28.06.2014 */ public class Exec { private final byte[] address; private final byte[] caller; private final byte[] data; private final byte[] code; private final byte[] gas; private final byte[] gasPrice; private final byte[] origin; private final byte[] value; /* e.g: "address" : "0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6", "caller" : "cd1722f3947def4cf144679da39c4c32bdc35681", "data" : [ ], "code" : [ 96,0,96,0,96,0,96,0,96,74,51,96,200,92,3,241 ], "gas" : 10000, "gasPrice" : 100000000000000, "origin" : "cd1722f3947def4cf144679da39c4c32bdc35681", "value" : 1000000000000000000 */ public Exec(JSONObject exec) { String address = exec.get("address").toString(); String caller = exec.get("caller").toString(); String code = exec.get("code").toString(); String data = exec.get("data").toString(); String gas = exec.get("gas").toString(); String gasPrice = exec.get("gasPrice").toString(); String origin = exec.get("origin").toString(); String value = exec.get("value").toString(); this.address = Utils.parseData(address); this.caller = Utils.parseData(caller); if (code != null && code.length() > 2) this.code = Utils.parseData(code); else this.code = ByteUtil.EMPTY_BYTE_ARRAY; if (data != null && data.length() > 2) this.data = Utils.parseData(data); else this.data = ByteUtil.EMPTY_BYTE_ARRAY; this.gas = ByteUtil.bigIntegerToBytes(TestCase.toBigInt(gas)); this.gasPrice = ByteUtil.bigIntegerToBytes(TestCase.toBigInt(gasPrice)); this.origin = Utils.parseData(origin); this.value = ByteUtil.bigIntegerToBytes(TestCase.toBigInt(value)); } public byte[] getAddress() { return address; } public byte[] getCaller() { return caller; } public byte[] getData() { return data; } public byte[] getCode() { return code; } public byte[] getGas() { return gas; } public byte[] getGasPrice() { return gasPrice; } public byte[] getOrigin() { return origin; } public byte[] getValue() { return value; } @Override public String toString() { return "Exec{" + "address=" + Hex.toHexString(address) + ", caller=" + Hex.toHexString(caller) + ", data=" + Hex.toHexString(data) + ", code=" + Hex.toHexString(data) + ", gas=" + Hex.toHexString(gas) + ", gasPrice=" + Hex.toHexString(gasPrice) + ", origin=" + Hex.toHexString(origin) + ", value=" + Hex.toHexString(value) + '}'; } }
3,925
27.244604
80
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/jsontestsuite/suite/EthashTestCase.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.jsontestsuite.suite; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; import org.ethereum.core.BlockHeader; import org.ethereum.util.RLP; import org.ethereum.util.RLPList; import static org.spongycastle.util.encoders.Hex.decode; /** * @author Mikhail Kalinin * @since 03.09.2015 */ public class EthashTestCase { @JsonIgnore private String name; private String nonce; private String mixHash; private String header; private String seed; private String result; @JsonProperty("cache_size") private String cacheSize; @JsonProperty("full_size") private String fullSize; @JsonProperty("header_hash") private String headerHash; @JsonProperty("cache_hash") private String cacheHash; public String getName() { return name; } public void setName(String name) { this.name = name; } public String getNonce() { return nonce; } public void setNonce(String nonce) { this.nonce = nonce; } public String getMixHash() { return mixHash; } public void setMixHash(String mixHash) { this.mixHash = mixHash; } public String getHeader() { return header; } public void setHeader(String header) { this.header = header; } public String getSeed() { return seed; } public void setSeed(String seed) { this.seed = seed; } public String getResult() { return result; } public void setResult(String result) { this.result = result; } public String getCacheSize() { return cacheSize; } public void setCacheSize(String cacheSize) { this.cacheSize = cacheSize; } public String getFullSize() { return fullSize; } public void setFullSize(String fullSize) { this.fullSize = fullSize; } public String getHeaderHash() { return headerHash; } public void setHeaderHash(String headerHash) { this.headerHash = headerHash; } public String getCacheHash() { return cacheHash; } public void setCacheHash(String cacheHash) { this.cacheHash = cacheHash; } public BlockHeader getBlockHeader() { RLPList rlp = RLP.decode2(decode(header)); return new BlockHeader((RLPList) rlp.get(0)); } public byte[] getResultBytes() { return decode(result); } @Override public String toString() { return "EthashTestCase{" + "name='" + name + '\'' + ", header='" + header + '\'' + ", result='" + result + '\'' + '}'; } }
3,557
22.103896
80
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/jsontestsuite/suite/RLPTestCase.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.jsontestsuite.suite; import org.ethereum.util.ByteUtil; import org.ethereum.util.RLP; import org.ethereum.util.RLPElement; import org.ethereum.util.RLPList; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.spongycastle.util.encoders.Hex; import java.math.BigInteger; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; import java.util.Vector; public class RLPTestCase { private static Logger logger = LoggerFactory.getLogger("rlp"); private Object in; private String out; private List<String> computed = new ArrayList<>(); private List<String> expected = new ArrayList<>(); public Object getIn() { return in; } public void setIn(Object in) { this.in = in; } public String getOut() { return out; } public void setOut(String out) { this.out = out; } public List<String> getComputed() { return computed; } public List<String> getExpected() { return expected; } public void doEncode() { if ("INVALID".equals(in) || "VALID".equals(in)) { return; } byte[] in = buildRLP(this.in); String expected = parseOut(); String computed = Hex.toHexString(in); this.computed.add(computed); this.expected.add(expected); } public void doDecode() { String out = parseOut(); try { RLPList list = RLP.decode2(Hex.decode(out)); checkRLPAgainstJson(list.get(0), in); } catch (Exception e) { if (!"INVALID".equals(in)){ throw e; } } } private String parseOut() { String out = this.out.toLowerCase(); if (out.startsWith("0x")) { return out.substring(2); } else { return out; } } public byte[] buildRLP(Object in) { if (in instanceof ArrayList) { List<byte[]> elementList = new Vector<>(); for (Object o : ((ArrayList) in).toArray()) { elementList.add(buildRLP(o)); } byte[][] elements = elementList.toArray(new byte[elementList.size()][]); return RLP.encodeList(elements); } else { if (in instanceof String) { String s = in.toString(); if (s.contains("#")) { return RLP.encode(new BigInteger(s.substring(1))); } } else if (in instanceof Integer) { return RLP.encodeInt(Integer.parseInt(in.toString())); } return RLP.encode(in); } } public void checkRLPAgainstJson(RLPElement element, Object in) { if ("VALID".equals(in)) { return; } if (in instanceof List) { Object[] array = ((List) in).toArray(); RLPList list = (RLPList) element; for (int i = 0; i < array.length; i++) { checkRLPAgainstJson(list.get(i), array[i]); } } else if (in instanceof Number) { int computed = ByteUtil.byteArrayToInt(element.getRLPData()); this.computed.add(Integer.toString(computed)); this.expected.add(in.toString()); } else if (in instanceof String) { String s = in.toString(); if (s.contains("#")) { s = s.substring(1); BigInteger expected = new BigInteger(s); byte[] payload = element.getRLPData(); BigInteger computed = new BigInteger(1, payload); this.computed.add(computed.toString()); this.expected.add(expected.toString()); } else { String computed = new String(element.getRLPData() != null ? element.getRLPData() : new byte[0], StandardCharsets.UTF_8); this.expected.add(s); this.computed.add(computed); } } else { throw new RuntimeException("Unexpected type: " + in.getClass()); } } }
4,947
29.732919
98
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/jsontestsuite/suite/TestCase.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.jsontestsuite.suite; import org.ethereum.db.ByteArrayWrapper; import org.ethereum.util.ByteUtil; import org.json.simple.JSONArray; import org.json.simple.JSONObject; import org.json.simple.parser.ParseException; import org.spongycastle.util.BigIntegers; import org.spongycastle.util.encoders.Hex; import java.math.BigInteger; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; /** * @author Roman Mandeleil * @since 28.06.2014 */ public class TestCase { private String name = ""; // "env": { ... }, private Env env; // private Logs logs; // "exec": { ... }, private Exec exec; // "gas": { ... }, private byte[] gas; // "out": { ... }, private byte[] out; // "pre": { ... }, private Map<ByteArrayWrapper, AccountState> pre = new HashMap<>(); // "post": { ... }, private Map<ByteArrayWrapper, AccountState> post = null; // "callcreates": { ... } private List<CallCreate> callCreateList = new ArrayList<>(); public TestCase(String name, JSONObject testCaseJSONObj) throws ParseException { this(testCaseJSONObj); this.name = name; } public TestCase(JSONObject testCaseJSONObj) throws ParseException { try { JSONObject envJSON = (JSONObject) testCaseJSONObj.get("env"); JSONObject execJSON = (JSONObject) testCaseJSONObj.get("exec"); JSONObject preJSON = (JSONObject) testCaseJSONObj.get("pre"); JSONObject postJSON = new JSONObject(); if (testCaseJSONObj.containsKey("post")) { // in cases where there is no post dictionary (when testing for // exceptions for example) // there are cases with empty post state, they shouldn't be mixed up with no "post" entry post = new HashMap<>(); postJSON = (JSONObject) testCaseJSONObj.get("post"); } JSONArray callCreates = new JSONArray(); if (testCaseJSONObj.containsKey("callcreates")) callCreates = (JSONArray) testCaseJSONObj.get("callcreates"); Object logsJSON = new JSONArray(); if (testCaseJSONObj.containsKey("logs")) logsJSON = testCaseJSONObj.get("logs"); logs = new Logs(logsJSON); String gasString = "0"; if (testCaseJSONObj.containsKey("gas")) gasString = testCaseJSONObj.get("gas").toString(); this.gas = BigIntegers.asUnsignedByteArray(toBigInt(gasString)); String outString = null; if (testCaseJSONObj.containsKey("out")) outString = testCaseJSONObj.get("out").toString(); if (outString != null && outString.length() > 2) this.out = Utils.parseData(outString); else this.out = ByteUtil.EMPTY_BYTE_ARRAY; for (Object key : preJSON.keySet()) { byte[] keyBytes = Utils.parseData(key.toString()); AccountState accountState = new AccountState(keyBytes, (JSONObject) preJSON.get(key)); pre.put(new ByteArrayWrapper(keyBytes), accountState); } for (Object key : postJSON.keySet()) { byte[] keyBytes = Utils.parseData(key.toString()); AccountState accountState = new AccountState(keyBytes, (JSONObject) postJSON.get(key)); post.put(new ByteArrayWrapper(keyBytes), accountState); } for (Object callCreate : callCreates) { CallCreate cc = new CallCreate((JSONObject) callCreate); this.callCreateList.add(cc); } if (testCaseJSONObj.containsKey("env")) this.env = new Env(envJSON); if (testCaseJSONObj.containsKey("exec")) this.exec = new Exec(execJSON); } catch (Throwable e) { e.printStackTrace(); throw new ParseException(0, e); } } static BigInteger toBigInt(String s) { if (s.startsWith("0x")) { if (s.equals("0x")) return new BigInteger("0"); return new BigInteger(s.substring(2), 16); } else { return new BigInteger(s); } } public Env getEnv() { return env; } public Exec getExec() { return exec; } public Logs getLogs() { return logs; } public byte[] getGas() { return gas; } public byte[] getOut() { return out; } public Map<ByteArrayWrapper, AccountState> getPre() { return pre; } public Map<ByteArrayWrapper, AccountState> getPost() { return post; } public List<CallCreate> getCallCreateList() { return callCreateList; } public String getName() { return name; } @Override public String toString() { return "TestCase{" + "" + env + ", " + exec + ", gas=" + Hex.toHexString(gas) + ", out=" + Hex.toHexString(out) + ", pre=" + pre + ", post=" + post + ", callcreates=" + callCreateList + '}'; } }
6,228
29.237864
105
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/jsontestsuite/suite/StateTestSuite.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.jsontestsuite.suite; import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.ObjectMapper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.IOException; import java.util.HashMap; import java.util.Map; public class StateTestSuite { private Logger logger = LoggerFactory.getLogger("TCK-Test"); Map<String, StateTestCase> testCases = new HashMap<>(); public StateTestSuite(String json) throws IOException { ObjectMapper mapper = new ObjectMapper(); JavaType type = mapper.getTypeFactory(). constructMapType(HashMap.class, String.class, StateTestCase.class); testCases = new ObjectMapper().readValue(json, type); } public Map<String, StateTestCase> getTestCases() { return testCases; } @Override public String toString() { return "StateTestSuite{" + "testCases=" + testCases + '}'; } }
1,780
31.381818
83
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/jsontestsuite/suite/StateTestCase.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.jsontestsuite.suite; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import org.ethereum.config.BlockchainNetConfig; import org.ethereum.jsontestsuite.GitHubJSONTestSuite; import org.ethereum.jsontestsuite.suite.model.AccountTck; import org.ethereum.jsontestsuite.suite.model.EnvTck; import org.ethereum.jsontestsuite.suite.model.TransactionTck; import java.util.Map; public class StateTestCase { private EnvTck env; @JsonDeserialize(using = Logs.Deserializer.class) private Logs logs; private String out; private Map<String, AccountTck> pre; private String postStateRoot; private Map<String, AccountTck> post; private TransactionTck transaction; private GitHubJSONTestSuite.Network network; private String name; public StateTestCase() { } public EnvTck getEnv() { return env; } public void setEnv(EnvTck env) { this.env = env; } public Logs getLogs() { return logs; } public void setLogs(Logs logs) { this.logs = logs; } public String getOut() { return out; } public void setOut(String out) { this.out = out; } public Map<String, AccountTck> getPre() { return pre; } public void setPre(Map<String, AccountTck> pre) { this.pre = pre; } public String getPostStateRoot() { return postStateRoot; } public void setPostStateRoot(String postStateRoot) { this.postStateRoot = postStateRoot; } public Map<String, AccountTck> getPost() { return post; } public void setPost(Map<String, AccountTck> post) { this.post = post; } public TransactionTck getTransaction() { return transaction; } public void setTransaction(TransactionTck transaction) { this.transaction = transaction; } public GitHubJSONTestSuite.Network getNetwork() { return network; } public void setNetwork(GitHubJSONTestSuite.Network network) { this.network = network; } public String getName() { return name; } public void setName(String name) { this.name = name; } public BlockchainNetConfig getConfig() { return network.getConfig(); } }
3,101
24.42623
80
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/jsontestsuite/suite/BlockchainTestSuite.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.jsontestsuite.suite; import org.ethereum.config.SystemProperties; import org.ethereum.config.net.MainNetConfig; import org.ethereum.jsontestsuite.GitHubJSONTestSuite; import org.junit.Assert; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.IOException; import java.util.*; import static org.ethereum.jsontestsuite.suite.JSONReader.listJsonBlobsForTreeSha; import static org.ethereum.jsontestsuite.suite.JSONReader.loadJSONFromCommit; import static org.ethereum.jsontestsuite.suite.JSONReader.loadJSONsFromCommit; /** * @author Mikhail Kalinin * @since 11.08.2017 */ public class BlockchainTestSuite { private static Logger logger = LoggerFactory.getLogger("TCK-Test"); private static final String TEST_ROOT = "BlockchainTests/"; String commitSHA; String subDir = ""; List<String> files; GitHubJSONTestSuite.Network[] networks; public BlockchainTestSuite(String treeSHA, String commitSHA, GitHubJSONTestSuite.Network[] networks) throws IOException { files = listJsonBlobsForTreeSha(treeSHA, TEST_ROOT); this.commitSHA = commitSHA; this.networks = networks; } public BlockchainTestSuite(String treeSHA, String commitSHA) throws IOException { this(treeSHA, commitSHA, GitHubJSONTestSuite.Network.values()); } public void setSubDir(String subDir) { if (!subDir.endsWith("/")) subDir = subDir + "/"; this.subDir = subDir; } private static void run(List<String> checkFiles, String commitSHA, GitHubJSONTestSuite.Network[] networks) throws IOException { if (checkFiles.isEmpty()) return; List<BlockTestSuite> suites = new ArrayList<>(); List<String> filenames = new ArrayList<>(); for (String file : checkFiles) { filenames.add(TEST_ROOT + file); } List<String> jsons = loadJSONsFromCommit(filenames, commitSHA); for (String json : jsons) { suites.add(new BlockTestSuite(json)); } Map<String, BlockTestCase> testCases = new HashMap<>(); for (BlockTestSuite suite : suites) { Map<String, BlockTestCase> suiteCases = suite.getTestCases(networks); testCases.putAll(suiteCases); } Map<String, Boolean> summary = new HashMap<>(); for (String testName : testCases.keySet()) { BlockTestCase blockTestCase = testCases.get(testName); TestRunner runner = new TestRunner(); logger.info("\n\n ***************** Running test: {} ***************************** \n\n", testName); try { SystemProperties.getDefault().setBlockchainConfig(blockTestCase.getConfig()); List<String> result = runner.runTestCase(blockTestCase); logger.info("--------- POST Validation---------"); if (!result.isEmpty()) for (String single : result) logger.info(single); if (!result.isEmpty()) summary.put(testName, false); else summary.put(testName, true); } finally { SystemProperties.getDefault().setBlockchainConfig(MainNetConfig.INSTANCE); } } logger.info(""); logger.info(""); logger.info("Summary: "); logger.info("========="); int fails = 0; int pass = 0; for (String key : summary.keySet()){ if (summary.get(key)) ++pass; else ++fails; String sumTest = String.format("%-60s:^%s", key, (summary.get(key) ? "OK" : "FAIL")). replace(' ', '.'). replace("^", " "); logger.info(sumTest); } logger.info(" - Total: Pass: {}, Failed: {} - ", pass, fails); Assert.assertTrue(fails == 0); } public void runAll(String testCaseRoot, Set<String> excludedCases, GitHubJSONTestSuite.Network[] networks) throws IOException { List<String> testCaseFiles = new ArrayList<>(); for (String file : files) { if (file.startsWith(testCaseRoot + "/")) { testCaseFiles.add(subDir + file); } else if (file.startsWith(subDir + testCaseRoot + "/")) { testCaseFiles.add(file); } } Set<String> toExclude = new HashSet<>(); for (String file : testCaseFiles) { String fileName = file.substring(file.lastIndexOf('/') + 1, file.lastIndexOf(".json")); if (excludedCases.contains(fileName)) { logger.info(" [X] " + file); toExclude.add(file); } else { logger.info(" " + file); } } testCaseFiles.removeAll(toExclude); run(testCaseFiles, commitSHA, networks); } public void runAll(String testCaseRoot) throws IOException { runAll(testCaseRoot, Collections.<String>emptySet(), networks); } public void runAll(String testCaseRoot, Set<String> excludedCases) throws IOException { runAll(testCaseRoot, excludedCases, networks); } public void runAll(String testCaseRoot, GitHubJSONTestSuite.Network network) throws IOException { runAll(testCaseRoot, Collections.<String>emptySet(), new GitHubJSONTestSuite.Network[]{network}); } public static void runSingle(String testFile, String commitSHA, GitHubJSONTestSuite.Network network) throws IOException { logger.info(" " + testFile); run(Collections.singletonList(testFile), commitSHA, new GitHubJSONTestSuite.Network[] { network }); } public static void runSingle(String testFile, String commitSHA) throws IOException { logger.info(" " + testFile); run(Collections.singletonList(testFile), commitSHA, GitHubJSONTestSuite.Network.values()); } }
6,797
35.352941
131
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/jsontestsuite/suite/TransactionTestCase.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.jsontestsuite.suite; import org.ethereum.jsontestsuite.GitHubJSONTestSuite; public class TransactionTestCase { private String rlp; private String expectedHash; private String expectedRlp; private GitHubJSONTestSuite.Network network; public TransactionTestCase() { } public String getRlp() { return rlp; } public void setRlp(String rlp) { this.rlp = rlp; } public String getExpectedHash() { return expectedHash; } public void setExpectedHash(String expectedHash) { this.expectedHash = expectedHash; } public String getExpectedRlp() { return expectedRlp; } public void setExpectedRlp(String expectedRlp) { this.expectedRlp = expectedRlp; } public GitHubJSONTestSuite.Network getNetwork() { return network; } public void setNetwork(GitHubJSONTestSuite.Network network) { this.network = network; } }
1,770
27.111111
80
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/jsontestsuite/suite/Transaction.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.jsontestsuite.suite; import org.json.simple.JSONObject; import java.math.BigInteger; import static org.ethereum.util.ByteUtil.toHexString; /** * @author Roman Mandeleil * @since 28.06.2014 */ public class Transaction { byte[] data; byte[] gasLimit; long gasPrice; long nonce; byte[] secretKey; byte[] to; long value; /* e.g. "transaction" : { "data" : "", "gasLimit" : "10000", "gasPrice" : "1", "nonce" : "0", "secretKey" : "45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8", "to" : "095e7baea6a6c7c4c2dfeb977efac326af552d87", "value" : "100000" } */ public Transaction(JSONObject callCreateJSON) { String dataStr = callCreateJSON.get("data").toString(); String gasLimitStr = Utils.parseUnidentifiedBase(callCreateJSON.get("gasLimit").toString()); String gasPriceStr = Utils.parseUnidentifiedBase(callCreateJSON.get("gasPrice").toString()); String nonceStr = callCreateJSON.get("nonce").toString(); String secretKeyStr = callCreateJSON.get("secretKey").toString(); String toStr = callCreateJSON.get("to").toString(); String valueStr = callCreateJSON.get("value").toString(); this.data = Utils.parseData(dataStr); this.gasLimit = !gasLimitStr.isEmpty() ? new BigInteger(gasLimitStr).toByteArray() : new byte[]{0}; this.gasPrice = Utils.parseLong(gasPriceStr); this.nonce = Utils.parseLong(nonceStr); this.secretKey = Utils.parseData(secretKeyStr); this.to = Utils.parseData(toStr); this.value = Utils.parseLong(valueStr); } public byte[] getData() { return data; } public byte[] getGasLimit() { return gasLimit; } public long getGasPrice() { return gasPrice; } public long getNonce() { return nonce; } public byte[] getSecretKey() { return secretKey; } public byte[] getTo() { return to; } public long getValue() { return value; } @Override public String toString() { return "Transaction{" + "data=" + toHexString(data) + ", gasLimit=" + gasLimit + ", gasPrice=" + gasPrice + ", nonce=" + nonce + ", secretKey=" + toHexString(secretKey) + ", to=" + toHexString(to) + ", value=" + value + '}'; } }
3,338
29.354545
107
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/jsontestsuite/suite/Logs.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.jsontestsuite.suite; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.JsonDeserializer; import org.ethereum.crypto.HashUtil; import org.ethereum.util.FastByteComparisons; import org.ethereum.util.RLP; import org.ethereum.vm.DataWord; import org.ethereum.vm.LogInfo; import org.json.simple.JSONArray; import org.json.simple.JSONObject; import org.spongycastle.util.encoders.Hex; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.Iterator; import java.util.List; public class Logs { List<LogInfo> logs; byte[] logsHash; @SuppressWarnings("unchecked") public Logs(Object logs) { if (logs instanceof JSONArray) { init((JSONArray) logs); } else if (logs instanceof List) { this.logs = (List<LogInfo>) logs; } else { init((String) logs); } } public static class Deserializer extends JsonDeserializer<Logs> { @Override public Logs deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { return new Logs(jp.readValueAs(Object.class)); } } private void init(String logsHash) { this.logsHash = Utils.parseData(logsHash); } private void init(JSONArray jLogs) { logs = new ArrayList<>(); for (Object jLog1 : jLogs) { JSONObject jLog = (JSONObject) jLog1; byte[] address = Hex.decode((String) jLog.get("address")); byte[] data = Hex.decode(((String) jLog.get("data")).substring(2)); List<DataWord> topics = new ArrayList<>(); JSONArray jTopics = (JSONArray) jLog.get("topics"); for (Object t : jTopics.toArray()) { byte[] topic = Hex.decode(((String) t)); topics.add(DataWord.of(topic)); } LogInfo li = new LogInfo(address, topics, data); logs.add(li); } } public Iterator<LogInfo> getIterator() { return logs.iterator(); } public List<String> compareToReal(List<LogInfo> logResult) { List<String> results = new ArrayList<>(); if (logsHash != null) { byte[][] logInfoListE = new byte[logResult.size()][]; for (int i = 0; i < logResult.size(); i++) { logInfoListE[i] = logResult.get(i).getEncoded(); } byte[] logInfoListRLP = RLP.encodeList(logInfoListE); byte[] resHash = HashUtil.sha3(logInfoListRLP); if (!FastByteComparisons.equal(logsHash, resHash)) { results.add("Logs hash doesn't match expected: " + Hex.toHexString(resHash) + " != " + Hex.toHexString(logsHash)); } } else { Iterator<LogInfo> postLogs = getIterator(); int i = 0; while (postLogs.hasNext()) { LogInfo expectedLogInfo = postLogs.next(); LogInfo foundLogInfo = null; if (logResult.size() > i) foundLogInfo = logResult.get(i); if (foundLogInfo == null) { String output = String.format("Expected log [ %s ]", expectedLogInfo.toString()); results.add(output); } else { if (!Arrays.equals(expectedLogInfo.getAddress(), foundLogInfo.getAddress())) { String output = String.format("Expected address [ %s ], found [ %s ]", Hex.toHexString(expectedLogInfo.getAddress()), Hex.toHexString(foundLogInfo.getAddress())); results.add(output); } if (!Arrays.equals(expectedLogInfo.getData(), foundLogInfo.getData())) { String output = String.format("Expected data [ %s ], found [ %s ]", Hex.toHexString(expectedLogInfo.getData()), Hex.toHexString(foundLogInfo.getData())); results.add(output); } if (!expectedLogInfo.getBloom().equals(foundLogInfo.getBloom())) { String output = String.format("Expected bloom [ %s ], found [ %s ]", Hex.toHexString(expectedLogInfo.getBloom().getData()), Hex.toHexString(foundLogInfo.getBloom().getData())); results.add(output); } if (expectedLogInfo.getTopics().size() != foundLogInfo.getTopics().size()) { String output = String.format("Expected number of topics [ %d ], found [ %d ]", expectedLogInfo.getTopics().size(), foundLogInfo.getTopics().size()); results.add(output); } else { int j = 0; for (DataWord topic : expectedLogInfo.getTopics()) { byte[] foundTopic = foundLogInfo.getTopics().get(j).getData(); if (!Arrays.equals(topic.getData(), foundTopic)) { String output = String.format("Expected topic [ %s ], found [ %s ]", Hex.toHexString(topic.getData()), Hex.toHexString(foundTopic)); results.add(output); } ++j; } } } ++i; } } return results; } }
6,594
38.728916
178
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/jsontestsuite/suite/builder/AccountBuilder.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.jsontestsuite.suite.builder; import org.ethereum.config.SystemProperties; import org.ethereum.core.AccountState; import org.ethereum.jsontestsuite.suite.ContractDetailsImpl; import org.ethereum.jsontestsuite.suite.model.AccountTck; import org.ethereum.vm.DataWord; import java.util.HashMap; import java.util.Map; import static org.ethereum.crypto.HashUtil.sha3; import static org.ethereum.jsontestsuite.suite.Utils.parseData; import static org.ethereum.util.Utils.unifiedNumericToBigInteger; public class AccountBuilder { public static StateWrap build(AccountTck account) { ContractDetailsImpl details = new ContractDetailsImpl(); details.setCode(parseData(account.getCode())); details.setStorage(convertStorage(account.getStorage())); AccountState state = new AccountState(SystemProperties.getDefault()) .withBalanceIncrement(unifiedNumericToBigInteger(account.getBalance())) .withNonce(unifiedNumericToBigInteger(account.getNonce())) .withStateRoot(details.getStorageHash()) .withCodeHash(sha3(details.getCode())); return new StateWrap(state, details); } private static Map<DataWord, DataWord> convertStorage(Map<String, String> storageTck) { Map<DataWord, DataWord> storage = new HashMap<>(); for (String keyTck : storageTck.keySet()) { String valueTck = storageTck.get(keyTck); DataWord key = DataWord.of(parseData(keyTck)); DataWord value = DataWord.of(parseData(valueTck)); storage.put(key, value); } return storage; } public static class StateWrap { AccountState accountState; ContractDetailsImpl contractDetails; public StateWrap(AccountState accountState, ContractDetailsImpl contractDetails) { this.accountState = accountState; this.contractDetails = contractDetails; } public AccountState getAccountState() { return accountState; } public ContractDetailsImpl getContractDetails() { return contractDetails; } } }
2,975
33.206897
91
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/jsontestsuite/suite/builder/BlockHeaderBuilder.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.jsontestsuite.suite.builder; import org.ethereum.core.BlockHeader; import org.ethereum.jsontestsuite.suite.Utils; import org.ethereum.jsontestsuite.suite.model.BlockHeaderTck; import java.math.BigInteger; public class BlockHeaderBuilder { public static BlockHeader build(BlockHeaderTck headerTck){ BlockHeader header = new BlockHeader( Utils.parseData(headerTck.getParentHash()), Utils.parseData(headerTck.getUncleHash()), Utils.parseData(headerTck.getCoinbase()), Utils.parseData(headerTck.getBloom()), Utils.parseNumericData(headerTck.getDifficulty()), new BigInteger(1, Utils.parseData(headerTck.getNumber())).longValue(), Utils.parseData(headerTck.getGasLimit()), new BigInteger(1, Utils.parseData(headerTck.getGasUsed())).longValue(), new BigInteger(1, Utils.parseData(headerTck.getTimestamp())).longValue(), Utils.parseData(headerTck.getExtraData()), Utils.parseData(headerTck.getMixHash()), Utils.parseData(headerTck.getNonce()) ); header.setReceiptsRoot(Utils.parseData(headerTck.getReceiptTrie())); header.setTransactionsRoot(Utils.parseData(headerTck.getTransactionsTrie())); header.setStateRoot(Utils.parseData(headerTck.getStateRoot())); return header; } }
2,238
40.462963
89
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/jsontestsuite/suite/builder/LogBuilder.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.jsontestsuite.suite.builder; import org.ethereum.jsontestsuite.suite.model.LogTck; import org.ethereum.vm.DataWord; import org.ethereum.vm.LogInfo; import java.util.ArrayList; import java.util.List; import static org.ethereum.jsontestsuite.suite.Utils.parseData; public class LogBuilder { public static LogInfo build(LogTck logTck){ byte[] address = parseData(logTck.getAddress()); byte[] data = parseData(logTck.getData()); List<DataWord> topics = new ArrayList<>(); for (String topicTck : logTck.getTopics()) topics.add(DataWord.of(parseData(topicTck))); return new LogInfo(address, topics, data); } public static List<LogInfo> build(List<LogTck> logs){ List<LogInfo> outLogs = new ArrayList<>(); for (LogTck log : logs) outLogs.add(build(log)); return outLogs; } }
1,695
31
80
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/jsontestsuite/suite/builder/RepositoryBuilder.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.jsontestsuite.suite.builder; import org.ethereum.core.AccountState; import org.ethereum.core.Repository; import org.ethereum.datasource.inmem.HashMapDB; import org.ethereum.datasource.NoDeleteSource; import org.ethereum.jsontestsuite.suite.IterableTestRepository; import org.ethereum.db.RepositoryRoot; import org.ethereum.db.ByteArrayWrapper; import org.ethereum.db.ContractDetails; import org.ethereum.jsontestsuite.suite.ContractDetailsCacheImpl; import org.ethereum.jsontestsuite.suite.model.AccountTck; import java.util.HashMap; import java.util.Map; import static org.ethereum.jsontestsuite.suite.Utils.parseData; import static org.ethereum.util.ByteUtil.wrap; public class RepositoryBuilder { public static Repository build(Map<String, AccountTck> accounts){ HashMap<ByteArrayWrapper, AccountState> stateBatch = new HashMap<>(); HashMap<ByteArrayWrapper, ContractDetails> detailsBatch = new HashMap<>(); for (String address : accounts.keySet()) { AccountTck accountTCK = accounts.get(address); AccountBuilder.StateWrap stateWrap = AccountBuilder.build(accountTCK); AccountState state = stateWrap.getAccountState(); ContractDetails details = stateWrap.getContractDetails(); stateBatch.put(wrap(parseData(address)), state); ContractDetailsCacheImpl detailsCache = new ContractDetailsCacheImpl(details); detailsCache.setDirty(true); detailsBatch.put(wrap(parseData(address)), detailsCache); } Repository repositoryDummy = new IterableTestRepository(new RepositoryRoot(new NoDeleteSource<>(new HashMapDB<byte[]>()))); Repository track = repositoryDummy.startTracking(); track.updateBatch(stateBatch, detailsBatch); track.commit(); repositoryDummy.commit(); return repositoryDummy; } }
2,697
38.101449
131
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/jsontestsuite/suite/builder/BlockBuilder.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.jsontestsuite.suite.builder; import org.ethereum.core.Block; import org.ethereum.core.BlockHeader; import org.ethereum.core.Transaction; import org.ethereum.jsontestsuite.suite.Env; import org.ethereum.jsontestsuite.suite.model.BlockHeaderTck; import org.ethereum.jsontestsuite.suite.model.TransactionTck; import org.ethereum.util.ByteUtil; import java.util.ArrayList; import java.util.List; import static org.ethereum.util.BIUtil.toBI; import static org.ethereum.util.ByteUtil.byteArrayToLong; public class BlockBuilder { public static Block build(BlockHeaderTck header, List<TransactionTck> transactionsTck, List<BlockHeaderTck> unclesTck) { if (header == null) return null; List<BlockHeader> uncles = new ArrayList<>(); if (unclesTck != null) for (BlockHeaderTck uncle : unclesTck) uncles.add(BlockHeaderBuilder.build(uncle)); List<Transaction> transactions = new ArrayList<>(); if (transactionsTck != null) for (TransactionTck tx : transactionsTck) transactions.add(TransactionBuilder.build(tx)); BlockHeader blockHeader = BlockHeaderBuilder.build(header); Block block = new Block( blockHeader, transactions, uncles); return block; } public static Block build(Env env){ Block block = new Block( ByteUtil.EMPTY_BYTE_ARRAY, ByteUtil.EMPTY_BYTE_ARRAY, env.getCurrentCoinbase(), ByteUtil.EMPTY_BYTE_ARRAY, env.getCurrentDifficulty(), byteArrayToLong(env.getCurrentNumber()), env.getCurrentGasLimit(), 0L, byteArrayToLong(env.getCurrentTimestamp()), new byte[32], ByteUtil.ZERO_BYTE_ARRAY, ByteUtil.ZERO_BYTE_ARRAY, null, null); return block; } }
2,793
33.493827
80
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/jsontestsuite/suite/builder/TransactionBuilder.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.jsontestsuite.suite.builder; import org.ethereum.core.Transaction; import org.ethereum.jsontestsuite.suite.model.TransactionTck; import static org.ethereum.jsontestsuite.suite.Utils.*; public class TransactionBuilder { public static Transaction build(TransactionTck transactionTck) { Transaction transaction; if (transactionTck.getSecretKey() != null){ transaction = new Transaction( parseVarData(transactionTck.getNonce()), parseVarData(transactionTck.getGasPrice()), parseVarData(transactionTck.getGasLimit()), parseData(transactionTck.getTo()), parseVarData(transactionTck.getValue()), parseData(transactionTck.getData())); transaction.sign(parseData(transactionTck.getSecretKey())); } else { transaction = new Transaction( parseNumericData(transactionTck.getNonce()), parseVarData(transactionTck.getGasPrice()), parseVarData(transactionTck.getGasLimit()), parseData(transactionTck.getTo()), parseNumericData(transactionTck.getValue()), parseData(transactionTck.getData()), parseData(transactionTck.getR()), parseData(transactionTck.getS()), parseByte(transactionTck.getV()) ); } return transaction; } }
2,323
38.389831
80
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/jsontestsuite/suite/builder/EnvBuilder.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.jsontestsuite.suite.builder; import org.ethereum.jsontestsuite.suite.Env; import org.ethereum.jsontestsuite.suite.model.EnvTck; import static org.ethereum.jsontestsuite.suite.Utils.parseData; import static org.ethereum.jsontestsuite.suite.Utils.parseNumericData; import static org.ethereum.jsontestsuite.suite.Utils.parseVarData; public class EnvBuilder { public static Env build(EnvTck envTck){ byte[] coinbase = parseData(envTck.getCurrentCoinbase()); byte[] difficulty = parseVarData(envTck.getCurrentDifficulty()); byte[] gasLimit = parseVarData(envTck.getCurrentGasLimit()); byte[] number = parseNumericData(envTck.getCurrentNumber()); byte[] timestamp = parseNumericData(envTck.getCurrentTimestamp()); byte[] hash = parseData(envTck.getPreviousHash()); return new Env(coinbase, difficulty, gasLimit, number, timestamp, hash); } }
1,717
40.902439
80
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/jsontestsuite/suite/validators/RepositoryValidator.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.jsontestsuite.suite.validators; import org.ethereum.core.AccountState; import org.ethereum.db.ContractDetails; import org.ethereum.core.Repository; import org.spongycastle.util.encoders.Hex; import java.util.ArrayList; import java.util.List; import java.util.Set; import static org.ethereum.util.ByteUtil.difference; public class RepositoryValidator { public static List<String> valid(Repository currentRepository, Repository postRepository) { List<String> results = new ArrayList<>(); Set<byte[]> expectedKeys = postRepository.getAccountsKeys(); for (byte[] key : expectedKeys) { // force to load known accounts to cache to enumerate them currentRepository.getAccountState(key); } Set<byte[]> currentKeys = currentRepository.getAccountsKeys(); if (expectedKeys.size() != currentKeys.size()) { String out = String.format("The size of the repository is invalid \n expected: %d, \n current: %d", expectedKeys.size(), currentKeys.size()); results.add(out); } for (byte[] address : currentKeys) { AccountState state = currentRepository.getAccountState(address); ContractDetails details = currentRepository.getContractDetails(address); AccountState postState = postRepository.getAccountState(address); ContractDetails postDetails = postRepository.getContractDetails(address); List<String> accountResult = AccountValidator.valid(Hex.toHexString(address), postState, postDetails, state, details); results.addAll(accountResult); } Set<byte[]> expectedButAbsent = difference(expectedKeys, currentKeys); for (byte[] address : expectedButAbsent){ String formattedString = String.format("Account: %s: expected but doesn't exist", Hex.toHexString(address)); results.add(formattedString); } // Compare roots results.addAll(validRoot( Hex.toHexString(currentRepository.getRoot()), Hex.toHexString(postRepository.getRoot())) ); return results; } public static List<String> validRoot(String currRoot, String postRoot) { List<String> results = new ArrayList<>(); if (!postRoot.equals(currRoot)){ String formattedString = String.format("Root hash doesn't match: expected: %s current: %s", postRoot, currRoot); results.add(formattedString); } return results; } }
3,458
34.295918
106
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/jsontestsuite/suite/validators/BlockHeaderValidator.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.jsontestsuite.suite.validators; import org.ethereum.core.BlockHeader; import java.math.BigInteger; import java.util.ArrayList; import static org.ethereum.util.ByteUtil.toHexString; public class BlockHeaderValidator { public static ArrayList<String> valid(BlockHeader orig, BlockHeader valid) { ArrayList<String> outputSummary = new ArrayList<>(); if (!toHexString(orig.getParentHash()) .equals(toHexString(valid.getParentHash()))) { String output = String.format("wrong block.parentHash: \n expected: %s \n got: %s", toHexString(valid.getParentHash()), toHexString(orig.getParentHash()) ); outputSummary.add(output); } if (!toHexString(orig.getUnclesHash()) .equals(toHexString(valid.getUnclesHash()))) { String output = String.format("wrong block.unclesHash: \n expected: %s \n got: %s", toHexString(valid.getUnclesHash()), toHexString(orig.getUnclesHash()) ); outputSummary.add(output); } if (!toHexString(orig.getCoinbase()) .equals(toHexString(valid.getCoinbase()))) { String output = String.format("wrong block.coinbase: \n expected: %s \n got: %s", toHexString(valid.getCoinbase()), toHexString(orig.getCoinbase()) ); outputSummary.add(output); } if (!toHexString(orig.getStateRoot()) .equals(toHexString(valid.getStateRoot()))) { String output = String.format("wrong block.stateRoot: \n expected: %s \n got: %s", toHexString(valid.getStateRoot()), toHexString(orig.getStateRoot()) ); outputSummary.add(output); } if (!toHexString(orig.getTxTrieRoot()) .equals(toHexString(valid.getTxTrieRoot()))) { String output = String.format("wrong block.txTrieRoot: \n expected: %s \n got: %s", toHexString(valid.getTxTrieRoot()), toHexString(orig.getTxTrieRoot()) ); outputSummary.add(output); } if (!toHexString(orig.getReceiptsRoot()) .equals(toHexString(valid.getReceiptsRoot()))) { String output = String.format("wrong block.receiptsRoot: \n expected: %s \n got: %s", toHexString(valid.getReceiptsRoot()), toHexString(orig.getReceiptsRoot()) ); outputSummary.add(output); } if (!toHexString(orig.getLogsBloom()) .equals(toHexString(valid.getLogsBloom()))) { String output = String.format("wrong block.logsBloom: \n expected: %s \n got: %s", toHexString(valid.getLogsBloom()), toHexString(orig.getLogsBloom()) ); outputSummary.add(output); } if (!toHexString(orig.getDifficulty()) .equals(toHexString(valid.getDifficulty()))) { String output = String.format("wrong block.difficulty: \n expected: %s \n got: %s", toHexString(valid.getDifficulty()), toHexString(orig.getDifficulty()) ); outputSummary.add(output); } if (orig.getTimestamp() != valid.getTimestamp()) { String output = String.format("wrong block.timestamp: \n expected: %d \n got: %d", valid.getTimestamp(), orig.getTimestamp() ); outputSummary.add(output); } if (orig.getNumber() != valid.getNumber()) { String output = String.format("wrong block.number: \n expected: %d \n got: %d", valid.getNumber(), orig.getNumber() ); outputSummary.add(output); } if (!new BigInteger(1, orig.getGasLimit()).equals(new BigInteger(1, valid.getGasLimit()))) { String output = String.format("wrong block.gasLimit: \n expected: %d \n got: %d", new BigInteger(1, valid.getGasLimit()), new BigInteger(1, orig.getGasLimit()) ); outputSummary.add(output); } if (orig.getGasUsed() != valid.getGasUsed()) { String output = String.format("wrong block.gasUsed: \n expected: %d \n got: %d", valid.getGasUsed(), orig.getGasUsed() ); outputSummary.add(output); } if (!toHexString(orig.getMixHash()) .equals(toHexString(valid.getMixHash()))) { String output = String.format("wrong block.mixHash: \n expected: %s \n got: %s", toHexString(valid.getMixHash()), toHexString(orig.getMixHash()) ); outputSummary.add(output); } if (!toHexString(orig.getExtraData()) .equals(toHexString(valid.getExtraData()))) { String output = String.format("wrong block.extraData: \n expected: %s \n got: %s", toHexString(valid.getExtraData()), toHexString(orig.getExtraData()) ); outputSummary.add(output); } if (!toHexString(orig.getNonce()) .equals(toHexString(valid.getNonce()))) { String output = String.format("wrong block.nonce: \n expected: %s \n got: %s", toHexString(valid.getNonce()), toHexString(orig.getNonce()) ); outputSummary.add(output); } return outputSummary; } }
7,299
33.11215
100
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/jsontestsuite/suite/validators/TransactionValidator.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.jsontestsuite.suite.validators; import org.ethereum.core.Transaction; import java.util.ArrayList; import static org.ethereum.util.ByteUtil.toHexString; public class TransactionValidator { public static ArrayList<String> valid(Transaction orig, Transaction valid) { ArrayList<String> outputSummary = new ArrayList<>(); if (orig == null && valid == null) { return outputSummary; } if (orig != null && valid == null) { String output ="Transaction expected to be not valid"; outputSummary.add(output); return outputSummary; } if (orig == null && valid != null) { String output ="Transaction expected to be valid"; outputSummary.add(output); return outputSummary; } if (!toHexString(orig.getEncoded()) .equals(toHexString(valid.getEncoded()))) { String output = String.format("Wrong transaction.encoded: \n expected: %s \n got: %s", toHexString(valid.getEncoded()), toHexString(orig.getEncoded()) ); outputSummary.add(output); } return outputSummary; } }
2,087
29.705882
90
java
ethereumj
ethereumj-master/ethereumj-core/src/test/java/org/ethereum/jsontestsuite/suite/validators/AccountValidator.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.jsontestsuite.suite.validators; import org.ethereum.core.AccountState; import org.ethereum.db.ContractDetails; import org.ethereum.vm.DataWord; import org.spongycastle.util.encoders.Hex; import java.math.BigInteger; import java.util.*; public class AccountValidator { public static List<String> valid(String address, AccountState expectedState, ContractDetails expectedDetails, AccountState currentState, ContractDetails currentDetails){ List<String> results = new ArrayList<>(); if (currentState == null || currentDetails == null){ String formattedString = String.format("Account: %s: expected but doesn't exist", address); results.add(formattedString); return results; } if (expectedState == null || expectedDetails == null){ String formattedString = String.format("Account: %s: unexpected account in the repository", address); results.add(formattedString); return results; } BigInteger expectedBalance = expectedState.getBalance(); if (currentState.getBalance().compareTo(expectedBalance) != 0) { String formattedString = String.format("Account: %s: has unexpected balance, expected balance: %s found balance: %s", address, expectedBalance.toString(), currentState.getBalance().toString()); results.add(formattedString); } BigInteger expectedNonce = expectedState.getNonce(); if (currentState.getNonce().compareTo(expectedNonce) != 0) { String formattedString = String.format("Account: %s: has unexpected nonce, expected nonce: %s found nonce: %s", address, expectedNonce.toString(), currentState.getNonce().toString()); results.add(formattedString); } byte[] code = currentDetails.getCode(); if (!Arrays.equals(expectedDetails.getCode(), code)) { String formattedString = String.format("Account: %s: has unexpected code, expected code: %s found code: %s", address, Hex.toHexString(expectedDetails.getCode()), Hex.toHexString(currentDetails.getCode())); results.add(formattedString); } // compare storage Set<DataWord> expectedKeys = expectedDetails.getStorage().keySet(); for (DataWord key : expectedKeys) { // force to load known keys to cache to enumerate them currentDetails.get(key); } Set<DataWord> currentKeys = currentDetails.getStorage().keySet(); Set<DataWord> checked = new HashSet<>(); for (DataWord key : currentKeys) { DataWord currentValue = currentDetails.getStorage().get(key); DataWord expectedValue = expectedDetails.getStorage().get(key); if (expectedValue == null) { String formattedString = String.format("Account: %s: has unexpected storage data: %s = %s", address, key, currentValue); results.add(formattedString); continue; } if (!expectedValue.equals(currentValue)) { String formattedString = String.format("Account: %s: has unexpected value, for key: %s , expectedValue: %s real value: %s", address, key.toString(), expectedValue.toString(), currentValue.toString()); results.add(formattedString); continue; } checked.add(key); } for (DataWord key : expectedKeys) { if (!checked.contains(key)) { String formattedString = String.format("Account: %s: doesn't exist expected storage key: %s", address, key.toString()); results.add(formattedString); } } return results; } }
4,845
38.398374
139
java