use of org.ethereum.crypto.ECKey in project rskj by rsksmart.
the class UDPServerTest method run3NodesFullTest.
@Test
public void run3NodesFullTest() throws InterruptedException {
ECKey key1 = ECKey.fromPrivate(Hex.decode(KEY_1)).decompress();
ECKey key2 = ECKey.fromPrivate(Hex.decode(KEY_2)).decompress();
ECKey key3 = ECKey.fromPrivate(Hex.decode(KEY_3)).decompress();
List<String> node1BootNode = new ArrayList<>();
node1BootNode.add(HOST + ":5555");
node1BootNode.add(HOST + ":" + PORT_2);
List<String> node2BootNode = new ArrayList<>();
node2BootNode.add(HOST + ":" + PORT_3);
List<String> node3BootNode = new ArrayList<>();
Node node1 = new Node(key1.getNodeId(), HOST, PORT_1);
Node node2 = new Node(key2.getNodeId(), HOST, PORT_2);
Node node3 = new Node(key3.getNodeId(), HOST, PORT_3);
NodeDistanceTable distanceTable1 = new NodeDistanceTable(KademliaOptions.BINS, KademliaOptions.BUCKET_SIZE, node1);
NodeDistanceTable distanceTable2 = new NodeDistanceTable(KademliaOptions.BINS, KademliaOptions.BUCKET_SIZE, node2);
NodeDistanceTable distanceTable3 = new NodeDistanceTable(KademliaOptions.BINS, KademliaOptions.BUCKET_SIZE, node3);
PeerExplorer peerExplorer1 = new PeerExplorer(node1BootNode, node1, distanceTable1, key1, TIMEOUT, REFRESH);
PeerExplorer peerExplorer2 = new PeerExplorer(node2BootNode, node2, distanceTable2, key2, TIMEOUT, REFRESH);
PeerExplorer peerExplorer3 = new PeerExplorer(node3BootNode, node3, distanceTable3, key3, TIMEOUT, REFRESH);
Assert.assertEquals(0, peerExplorer1.getNodes().size());
Assert.assertEquals(0, peerExplorer2.getNodes().size());
Assert.assertEquals(0, peerExplorer3.getNodes().size());
UDPServer udpServer1 = new UDPServer(HOST, PORT_1, peerExplorer1);
UDPServer udpServer2 = new UDPServer(HOST, PORT_2, peerExplorer2);
UDPServer udpServer3 = new UDPServer(HOST, PORT_3, peerExplorer3);
udpServer3.start();
TimeUnit.SECONDS.sleep(2);
peerExplorer3.cleanAndUpdate();
udpServer2.start();
TimeUnit.SECONDS.sleep(2);
peerExplorer2.cleanAndUpdate();
peerExplorer3.cleanAndUpdate();
udpServer1.start();
TimeUnit.SECONDS.sleep(2);
peerExplorer1.cleanAndUpdate();
peerExplorer2.cleanAndUpdate();
peerExplorer3.cleanAndUpdate();
TimeUnit.SECONDS.sleep(2);
List<Node> foundNodes1 = peerExplorer1.getNodes();
List<Node> foundNodes2 = peerExplorer2.getNodes();
List<Node> foundNodes3 = peerExplorer3.getNodes();
Assert.assertEquals(2, foundNodes1.size());
Assert.assertEquals(2, foundNodes2.size());
Assert.assertEquals(2, foundNodes3.size());
udpServer1.stop();
udpServer2.stop();
udpServer3.stop();
TimeUnit.SECONDS.sleep(5);
Assert.assertTrue(checkNodeIds(foundNodes1, NODE_ID_2, NODE_ID_3));
Assert.assertTrue(checkNodeIds(foundNodes2, NODE_ID_1, NODE_ID_3));
Assert.assertTrue(checkNodeIds(foundNodes3, NODE_ID_2, NODE_ID_1));
}
use of org.ethereum.crypto.ECKey in project rskj by rsksmart.
the class TxValidatorAccountBalanceValidatorTest method balanceIsNotValidatedIfFreeTx.
@Test
public void balanceIsNotValidatedIfFreeTx() {
Transaction tx = new Transaction(BigInteger.ZERO.toByteArray(), BigInteger.ONE.toByteArray(), BigInteger.valueOf(21071).toByteArray(), new ECKey().getAddress(), BigInteger.ZERO.toByteArray(), Hex.decode("0001"), new RskSystemProperties().getBlockchainConfig().getCommonConstants().getChainId());
tx.sign(new ECKey().getPrivKeyBytes());
TxValidatorAccountBalanceValidator tv = new TxValidatorAccountBalanceValidator();
Assert.assertTrue(tv.validate(tx, new AccountState(), BigInteger.ONE, Coin.valueOf(1L), Long.MAX_VALUE, true));
}
use of org.ethereum.crypto.ECKey in project rskj by rsksmart.
the class TxValidatorIntrinsicGasLimitValidatorTest method validIntrinsicGasPrice.
@Test
public void validIntrinsicGasPrice() {
Transaction tx1 = new Transaction(BigInteger.ZERO.toByteArray(), BigInteger.ZERO.toByteArray(), BigInteger.valueOf(21000).toByteArray(), new ECKey().getAddress(), BigInteger.ZERO.toByteArray(), null, config.getBlockchainConfig().getCommonConstants().getChainId());
tx1.sign(new ECKey().getPrivKeyBytes());
Transaction tx2 = new Transaction(BigInteger.ZERO.toByteArray(), BigInteger.ZERO.toByteArray(), BigInteger.valueOf(30000).toByteArray(), new ECKey().getAddress(), BigInteger.ZERO.toByteArray(), Hex.decode("0001"), config.getBlockchainConfig().getCommonConstants().getChainId());
tx2.sign(new ECKey().getPrivKeyBytes());
Transaction tx3 = new Transaction(BigInteger.ZERO.toByteArray(), BigInteger.ZERO.toByteArray(), BigInteger.valueOf(21072).toByteArray(), new ECKey().getAddress(), BigInteger.ZERO.toByteArray(), Hex.decode("0001"), config.getBlockchainConfig().getCommonConstants().getChainId());
tx3.sign(new ECKey().getPrivKeyBytes());
Transaction tx4 = new Transaction(BigInteger.ZERO.toByteArray(), BigInteger.ZERO.toByteArray(), BigInteger.ZERO.toByteArray(), PrecompiledContracts.BRIDGE_ADDR.getBytes(), BigInteger.ZERO.toByteArray(), null, config.getBlockchainConfig().getCommonConstants().getChainId());
BridgeRegTestConstants bridgeRegTestConstants = BridgeRegTestConstants.getInstance();
tx4.sign(bridgeRegTestConstants.getFederatorPrivateKeys().get(0).getPrivKeyBytes());
TxValidatorIntrinsicGasLimitValidator tvigpv = new TxValidatorIntrinsicGasLimitValidator(config);
Assert.assertTrue(tvigpv.validate(tx1, new AccountState(), null, null, Long.MAX_VALUE, false));
Assert.assertTrue(tvigpv.validate(tx2, new AccountState(), null, null, Long.MAX_VALUE, false));
Assert.assertTrue(tvigpv.validate(tx3, new AccountState(), null, null, Long.MAX_VALUE, false));
Assert.assertTrue(tvigpv.validate(tx4, new AccountState(), null, null, Long.MAX_VALUE, false));
}
use of org.ethereum.crypto.ECKey in project rskj by rsksmart.
the class ABICallElectionTest method createMockKeyForAddress.
private ECKey createMockKeyForAddress(String hex) {
ECKey mockedKey = mock(ECKey.class);
when(mockedKey.getAddress()).thenReturn(Hex.decode(TestUtils.padZeroesLeft(hex, 40)));
return mockedKey;
}
use of org.ethereum.crypto.ECKey in project rskj by rsksmart.
the class ECKeyTest method testSignedMessageToKeyThrowsSignatureException.
@Test(expected = SignatureException.class)
public void testSignedMessageToKeyThrowsSignatureException() throws SignatureException {
byte[] messageHash = HashUtil.keccak256(exampleMessage.getBytes());
String signature = Base64.toBase64String(new byte[128]);
ECKey key = ECKey.signatureToKey(messageHash, signature);
assertNull(key);
}
Aggregations