Java Code Examples for org.spongycastle.util.encoders.Hex#decode()
The following examples show how to use
org.spongycastle.util.encoders.Hex#decode() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VMTest.java From ethereumj with MIT License | 7 votes |
@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()); }
Example 2
Source File: MemoryTest.java From gsc-core with GNU Lesser General Public License v3.0 | 6 votes |
@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); }
Example 3
Source File: VMTest.java From ethereumj with MIT License | 6 votes |
@Test // SLT OP public void testSLT_2() { VM vm = new VM(); program = new Program(Hex.decode("7F000000000000000000000000000000000000000000000000000000000000001E" + // 30 "7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF56" + // -170 "0C"), invoke); String expected = "0000000000000000000000000000000000000000000000000000000000000001"; vm.step(program); vm.step(program); vm.step(program); assertEquals(expected, Hex.toHexString(program.stack.peek().getData()).toUpperCase()); }
Example 4
Source File: WalletClient.java From gsc-core with GNU Lesser General Public License v3.0 | 6 votes |
/** * constructor. */ public Account queryAccount() { byte[] address; if (this.ecKey == null) { String pubKey = loadPubKey(); //04 PubKey[128] if (StringUtils.isEmpty(pubKey)) { logger.warn("Warning: QueryAccount failed, no wallet address !!"); return null; } byte[] pubKeyAsc = pubKey.getBytes(); byte[] pubKeyHex = Hex.decode(pubKeyAsc); this.ecKey = ECKey.fromPublicOnly(pubKeyHex); } return queryAccount(getAddress()); }
Example 5
Source File: HelloMessageTest.java From ethereumj with MIT License | 6 votes |
@Test /* HelloMessage 1 from PeerServer */ public void testPeer() { String helloMessageRaw = "F8 80 80 80 B7 45 74 68 " + "65 72 65 75 6D 28 2B 2B 29 2F 50 65 65 72 20 53 " + "65 72 76 65 72 20 5A 65 72 6F 2F 76 30 2E 36 2E " + "38 64 2F 52 65 6C 65 61 73 65 2F 4C 69 6E 75 78 " + "2F 67 2B 2B C0 82 76 5F B8 40 20 17 B9 5D 55 86 " + "AD D0 53 E7 C5 DC C8 11 2D B1 D5 57 ED 83 58 9C " + "4E 0B D2 54 42 F3 9E 41 11 65 5A 48 72 57 AA 7E " + "4E D3 09 E8 B4 D5 5B E5 FA 8D 8D 6E 97 B7 2C 67 " + "D7 6A A0 3E B6 9A D9 81 ED 60"; byte[] payload = Hex.decode(helloMessageRaw); HelloMessage helloMessage = new HelloMessage(payload); System.out.println(helloMessage); assertEquals(P2pMessageCodes.HELLO, helloMessage.getCommand()); assertEquals(0, helloMessage.getP2PVersion()); assertEquals("Ethereum(++)/Peer Server Zero/v0.6.8d/Release/Linux/g++", helloMessage.getClientId()); assertEquals(0, helloMessage.getCapabilities().size()); assertEquals(30303, helloMessage.getListenPort()); assertEquals( "2017B95D5586ADD053E7C5DCC8112DB1D557ED83589C4E0BD25442F39E4111655A487257AA7E4ED309E8B4D55BE5FA8D8D6E97B72C67D76AA03EB69AD981ED60", helloMessage.getPeerId().toUpperCase()); }
Example 6
Source File: VMCustomTest.java From ethereumj with MIT License | 6 votes |
@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.memory.array()).toUpperCase()); }
Example 7
Source File: VMTest.java From ethereumj with MIT License | 5 votes |
@Test // MOD OP public void testMOD_3() { VM vm = new VM(); program = new Program(Hex.decode("6004600206"), 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()); }
Example 8
Source File: VMTest.java From ethereumj with MIT License | 5 votes |
@Test // DIV OP public void testDIV_1() { VM vm = new VM(); program = new Program(Hex.decode("6002600404"), 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()); }
Example 9
Source File: RLPTest.java From ethereumj with MIT License | 5 votes |
@Test public void test12() { String tx = "F86E12F86B80881BC16D674EC8000094CD2A3D9F938E13CD947EC05ABC7FE734DF8DD8268609184E72A00064801BA0C52C114D4F5A3BA904A9B3036E5E118FE0DBB987FE3955DA20F2CD8F6C21AB9CA06BA4C2874299A55AD947DBC98A25EE895AABF6B625C26C435E84BFD70EDF2F69"; byte[] payload = Hex.decode(tx); RLPList rlpList = RLP.decode2(payload); RLPList.recursivePrint(rlpList); // TODO: add some asserts in place of just printing the rlpList }
Example 10
Source File: RuntimeTransferComplexTest.java From gsc-core with GNU Lesser General Public License v3.0 | 5 votes |
private byte[] deployCalledContract() throws ContractExeException, ReceiptCheckErrException, ContractValidateException, VMIllegalException { String contractName = "TransferWhenDeployContract"; byte[] address = Hex.decode(OWNER_ADDRESS); String ABI = "[{\"constant\":false,\"inputs\":[{\"name\":\"toAddress\",\"type\":\"address\"}],\"name\":\"callcodeTransferTo\"," + "\"outputs\":[],\"payable\":true,\"stateMutability\":\"payable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":" + "[{\"name\":\"toAddress\",\"type\":\"address\"}],\"name\":\"transferTo\",\"outputs\":[],\"payable\":true,\"stateMutability\":" + "\"payable\",\"type\":\"function\"},{\"constant\":false,\"inputs\":[{\"name\":\"toAddress\",\"type\":\"address\"}],\"name\":" + "\"delegateTransferTo\",\"outputs\":[],\"payable\":true,\"stateMutability\":\"payable\",\"type\":\"function\"},{\"inputs\":[]," + "\"payable\":true,\"stateMutability\":\"payable\",\"type\":\"constructor\"}]"; String code = "6080604052610105806100136000396000f30060806040526004361060485763ffffffff7c0100000000000000000000000000000000000000000" + "00000000000000060003504166312065fe08114604d578063a03fa7e3146071575b600080fd5b348015605857600080fd5b50605f6092565b6040805191825" + "2519081900360200190f35b609073ffffffffffffffffffffffffffffffffffffffff600435166097565b005b303190565b60405173fffffffffffffffffff" + "fffffffffffffffffffff82169060009060059082818181858883f1935050505015801560d5573d6000803e3d6000fd5b50505600a165627a7a72305820b6a" + "1478817a43ce2d6d3e26b8c8a89b35b4b49abe5b33849faedc32a602ed0850029"; long value = 1000; long feeLimit = 100000000; long consumeUserResourcePercent = 0; byte[] contractAddress = GVMTestUtils .deployContractWholeProcessReturnContractAddress(contractName, address, ABI, code, value, feeLimit, consumeUserResourcePercent, null, deposit, null); return contractAddress; }
Example 11
Source File: VMTest.java From ethereumj with MIT License | 5 votes |
@Test // ADDMOD OP public void testADDMOD_2() { VM vm = new VM(); program = new Program(Hex.decode("6110006002611002146000"), 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()); }
Example 12
Source File: GVMTestUtils.java From gsc-core with GNU Lesser General Public License v3.0 | 5 votes |
public static byte[] parseAbi(String selectorStr, String params) { if (params == null) { params = ""; } byte[] selector = new byte[4]; System.arraycopy(Hash.sha3(selectorStr.getBytes()), 0, selector, 0, 4); byte[] triggerData = Hex.decode(Hex.toHexString(selector) + params); return triggerData; }
Example 13
Source File: VMTest.java From ethereumj with MIT License | 5 votes |
@Test // PUSH6 OP public void testPUSH6() { VM vm = new VM(); program = new Program(Hex.decode("65A0B0C0D0E0F0"), invoke); String expected = "0000000000000000000000000000000000000000000000000000A0B0C0D0E0F0"; program.fullTrace(); vm.step(program); assertEquals(expected, Hex.toHexString(program.stack.peek().getData()).toUpperCase() ); }
Example 14
Source File: VMTest.java From ethereumj with MIT License | 5 votes |
@Test(expected=StackTooSmallException.class) // SUB OP mal public void testSUB_4() { VM vm = new VM(); program = new Program(Hex.decode("639999666603"), invoke); try { vm.step(program); vm.step(program); } finally { assertTrue(program.isStopped()); } }
Example 15
Source File: VMTest.java From ethereumj with MIT License | 5 votes |
@Test // PUSH8 OP public void testPUSH8() { VM vm = new VM(); program = new Program(Hex.decode("67A0B0C0D0E0F0A1B1"), invoke); String expected = "000000000000000000000000000000000000000000000000A0B0C0D0E0F0A1B1"; program.fullTrace(); vm.step(program); assertEquals(expected, Hex.toHexString(program.stack.peek().getData()).toUpperCase() ); }
Example 16
Source File: VMTest.java From ethereumj with MIT License | 5 votes |
@Test(expected=StackTooSmallException.class) // EXP OP mal public void testEXP_3() { VM vm = new VM(); program = new Program(Hex.decode("6212345608"), invoke); try { vm.step(program); vm.step(program); } finally { assertTrue(program.isStopped()); } }
Example 17
Source File: VMTest.java From ethereumj with MIT License | 5 votes |
@Test // SGT OP public void testSGT_1() { VM vm = new VM(); program = new Program(Hex.decode("600160020D"), invoke); String expected = "0000000000000000000000000000000000000000000000000000000000000001"; vm.step(program); vm.step(program); vm.step(program); assertEquals(expected, Hex.toHexString(program.stack.peek().getData()).toUpperCase()); }
Example 18
Source File: VMComplexTest.java From ethereumj with MIT License | 4 votes |
@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("600035560f6009590060203560003557"); byte[] codeB = Hex.decode("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6000547faaffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffaa6020546000604060406000601773945304eb96065b2a98b57a48a06ae28d285a71b5620f4240f3600057"); 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.result.getGasUsed()); DataWord memValue1 = program.memoryLoad(new DataWord(0)); DataWord memValue2 = program.memoryLoad(new DataWord(32)); DataWord storeValue1 = repository.getStorageValue(contractB_addr_bytes, new DataWord(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 }
Example 19
Source File: ProgramInvokeMockImpl.java From gsc-core with GNU Lesser General Public License v3.0 | 4 votes |
@Override public DataWord getPrevHash() { byte[] prevHash = Hex .decode("961CB117ABA86D1E596854015A1483323F18883C2D745B0BC03E87F146D2BB1C"); return new DataWord(prevHash); }
Example 20
Source File: BlockTest.java From ethereumj with MIT License | 4 votes |
@Test /* block with single balance transfer transaction - block#17 in PoC5 cpp-chain */ public void testSingleBalanceTransfer() { byte[] payload = Hex.decode(block_17); Block blockData = new Block(payload); System.out.println(blockData.toString()); }