Java Code Examples for java.math.BigInteger#TWO
The following examples show how to use
java.math.BigInteger#TWO .
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: AionPOWRuleTest.java From aion with MIT License | 6 votes |
@Test public void testAbovePOWHalfBoundary() { // this produces a result larger than the boundary final byte[] predefinedHash = new byte[32]; final long predefinedTimestamp = 0; final byte[] predefinedNonce = new byte[32]; final byte[] predefinedSolution = new byte[1408]; final BigInteger difficulty = BigInteger.TWO; when(mockHeader.getTimestamp()).thenReturn(predefinedTimestamp); when(mockHeader.getNonce()).thenReturn(predefinedNonce); when(mockHeader.getSolution()).thenReturn(predefinedSolution); when(mockHeader.getMineHash()).thenReturn(predefinedHash); // recall that this will essentially not do anything to the valid space // so basically all bytes are valid when(mockHeader.getPowBoundaryBI()) .thenReturn(BigInteger.ONE.shiftLeft(128).divide(difficulty)); List<RuleError> errors = new ArrayList<>(); AionPOWRule rule = new AionPOWRule(); boolean result = rule.validate(mockHeader, errors); assertThat(result).isFalse(); assertThat(errors).isNotEmpty(); }
Example 2
Source File: AionBlockStoreTest.java From aion with MIT License | 6 votes |
@Test public void testGetBlockByHashWithInfo_withSideChain() { Block givenBlock = consecutiveBlocks.get(0); BigInteger totalDifficulty = BigInteger.TWO; BigInteger sideTotalDifficulty = BigInteger.TEN; Block sideBlock = BlockUtil.newBlockFromRlp(givenBlock.getEncoded()); sideBlock.updateHeaderDifficulty(sideTotalDifficulty.toByteArray()); assertThat(givenBlock.getHash()).isNotEqualTo(sideBlock.getHash()); assertThat(givenBlock.getEncoded()).isNotEqualTo(sideBlock.getEncoded()); AionBlockStore store = new AionBlockStore(index, blocks, false); // does not require accurate total difficulty store.saveBlock(givenBlock, totalDifficulty, false); store.saveBlock(sideBlock, sideTotalDifficulty, true); Block block = store.getBlockByHashWithInfo(givenBlock.getHash()); assertThat(block).isEqualTo(givenBlock); assertThat(block.getTotalDifficulty()).isEqualTo(totalDifficulty); assertThat(block.isMainChain()).isFalse(); }
Example 3
Source File: EthSignBodyProviderTest.java From ethsigner with Apache License 2.0 | 5 votes |
@Test public void signatureHasTheExpectedFormat() { final TransactionSigner mockTransactionSigner = mock(TransactionSigner.class); final BigInteger v = BigInteger.ONE; final BigInteger r = BigInteger.TWO; final BigInteger s = BigInteger.TEN; doReturn(new Signature(v, r, s)).when(mockTransactionSigner).sign(any(byte[].class)); final TransactionSignerProvider mockSignerProvider = mock(TransactionSignerProvider.class); doReturn(Optional.of(mockTransactionSigner)).when(mockSignerProvider).getSigner(anyString()); final EthSignBodyProvider bodyProvider = new EthSignBodyProvider(mockSignerProvider); final JsonRpcRequest request = new JsonRpcRequest("2.0", "eth_sign"); final int id = 1; request.setId(new JsonRpcRequestId(id)); request.setParams(List.of("address", "message")); final JsonRpcBody body = bodyProvider.getBody(request); final JsonObject jsonObj = new JsonObject(body.body()); assertThat(body.hasError()).isFalse(); assertThat(jsonObj.getString("jsonrpc")).isEqualTo("2.0"); assertThat(jsonObj.getInteger("id")).isEqualTo(id); final String hexSignature = jsonObj.getString("result"); assertThat(hexSignature).hasSize(132); final byte[] signature = Numeric.hexStringToByteArray(hexSignature); assertThat(new BigInteger(1, signature, 0, 32)).isEqualTo(r); assertThat(new BigInteger(1, signature, 32, 32)).isEqualTo(s); assertThat(new BigInteger(1, signature, 64, 1)).isEqualTo(v); }
Example 4
Source File: AionPOWRuleTest.java From aion with MIT License | 5 votes |
@Test public void testBelowPOWHalfBoundary() { // yes this will produce a value smaller than the boundary final byte[] predefinedHash = ByteUtil.hexStringToBytes( "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"); final long predefinedTimestamp = 1; final byte[] predefinedNonce = ByteUtil.hexStringToBytes( "0xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"); final byte[] predefinedSolution = new byte[1408]; final BigInteger difficulty = BigInteger.TWO; when(mockHeader.getTimestamp()).thenReturn(predefinedTimestamp); when(mockHeader.getNonce()).thenReturn(predefinedNonce); when(mockHeader.getSolution()).thenReturn(predefinedSolution); when(mockHeader.getMineHash()).thenReturn(predefinedHash); // recall that this will essentially not do anything to the valid space // so basically all bytes are valid when(mockHeader.getPowBoundaryBI()) .thenReturn(BigInteger.ONE.shiftLeft(256).divide(difficulty)); List<RuleError> errors = new ArrayList<>(); AionPOWRule rule = new AionPOWRule(); boolean result = rule.validate(mockHeader, errors); assertThat(result).isTrue(); assertThat(errors).isEmpty(); }
Example 5
Source File: BlockInfoTest.java From aion with MIT License | 5 votes |
@Test public void testBlockInfoMultipleSerialization() { AionBlockStore.BlockInfo info = new AionBlockStore.BlockInfo(DEFAULT_HASH, BigInteger.ONE, true); AionBlockStore.BlockInfo info2 = new AionBlockStore.BlockInfo(HashUtil.h256(DEFAULT_HASH), BigInteger.TWO, false); byte[] serialized = AionBlockStore.BLOCK_INFO_SERIALIZER.serialize(Arrays.asList(info, info2)); System.out.println("serialized: " + ByteArrayWrapper.wrap(serialized)); // deserialized List<AionBlockStore.BlockInfo> deserializedBlockInfos = AionBlockStore.BLOCK_INFO_SERIALIZER.deserialize(serialized); AionBlockStore.BlockInfo dInfo1 = deserializedBlockInfos.get(0); assertThat(dInfo1.getTotalDifficulty()).isEqualTo(info.getTotalDifficulty()); assertThat(dInfo1.getHash()).isEqualTo(info.getHash()); assertThat(dInfo1.isMainChain()).isEqualTo(info.isMainChain()); AionBlockStore.BlockInfo dInfo2 = deserializedBlockInfos.get(1); assertThat(dInfo2.getTotalDifficulty()).isEqualTo(info2.getTotalDifficulty()); assertThat(dInfo2.getHash()).isEqualTo(info2.getHash()); assertThat(dInfo2.isMainChain()).isEqualTo(info2.isMainChain()); }
Example 6
Source File: Caller.java From AVM with MIT License | 5 votes |
public static byte[] main() { byte[] bytes = new byte[Address.LENGTH]; for (int i = 0; i < bytes.length; i++) { bytes[i] = 1; } Address address = genAddress(1); BigInteger value = BigInteger.TWO; byte[] data = "hello".getBytes(); long energyLimit = 10000; return Blockchain.call(address, value, data, energyLimit).getReturnData(); }