Fix GetBlocksMessage and unit test
This commit is contained in:
parent
c313b90a0e
commit
8ae2e9a3a4
|
@ -34,7 +34,7 @@ public class GetBlocksMessage extends EthMessage {
|
|||
validateMessage(paramsList, GET_BLOCKS);
|
||||
|
||||
blockHashes = new ArrayList<>();
|
||||
for (int i = 1; i < paramsList.size() - 1; ++i) {
|
||||
for (int i = 1; i < paramsList.size(); ++i) {
|
||||
blockHashes.add(((RLPItem) paramsList.get(i)).getRLPData());
|
||||
}
|
||||
parsed = true;
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package org.ethereum.net;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.ethereum.net.message.BlocksMessage;
|
||||
|
@ -19,31 +19,40 @@ public class GetBlocksMessageTest {
|
|||
@Test /* GetBlocks message parsing */
|
||||
public void test_1() {
|
||||
|
||||
fail("Not yet implemented");
|
||||
String getBlocksMessageRaw = "";
|
||||
String getBlocksMessageRaw = "f8a615a0497dcbd12fa99ced7b27cda6611f64eb13ab50e20260eec5ee6b7190e7206d54a00959bdfba5e54fcc9370e86b7996fbe32a277bab65c31a0102226f83c4d3e0f2a001a333c156485880776e929e84c26c9778c1e9b4dcb5cd3bff8ad0aeff385df0a0690e13595c9e8e4fa9a621dfed6ad828a6e8e591479af6897c979a83daf73084a0b20f253d2b62609e932c13f3bca59a22913ea5b1e532d8a707976997461ec143";
|
||||
|
||||
byte[] payload = Hex.decode(getBlocksMessageRaw);
|
||||
GetBlocksMessage getBlocksMessage = new GetBlocksMessage(payload);
|
||||
System.out.println(getBlocksMessage);
|
||||
|
||||
assertEquals(Command.GET_BLOCKS, getBlocksMessage.getCommand());
|
||||
assertEquals(0, getBlocksMessage.getBlockHashes().size());
|
||||
assertEquals(5, getBlocksMessage.getBlockHashes().size());
|
||||
String hash1 = "497dcbd12fa99ced7b27cda6611f64eb13ab50e20260eec5ee6b7190e7206d54";
|
||||
String hash4 = "b20f253d2b62609e932c13f3bca59a22913ea5b1e532d8a707976997461ec143";
|
||||
assertEquals(hash1, Hex.toHexString(getBlocksMessage.getBlockHashes().get(0)));
|
||||
assertEquals(hash4, Hex.toHexString(getBlocksMessage.getBlockHashes().get(4)));
|
||||
|
||||
assertEquals(BlocksMessage.class, getBlocksMessage.getAnswerMessage());
|
||||
}
|
||||
|
||||
@Test /* GetBlocks from new */
|
||||
public void test_2() {
|
||||
|
||||
fail("Not yet implemented");
|
||||
List<byte[]> hashList = new ArrayList<>();
|
||||
List<byte[]> hashList = Arrays.asList(
|
||||
Hex.decode("497dcbd12fa99ced7b27cda6611f64eb13ab50e20260eec5ee6b7190e7206d54"),
|
||||
Hex.decode("0959bdfba5e54fcc9370e86b7996fbe32a277bab65c31a0102226f83c4d3e0f2"),
|
||||
Hex.decode("01a333c156485880776e929e84c26c9778c1e9b4dcb5cd3bff8ad0aeff385df0"),
|
||||
Hex.decode("690e13595c9e8e4fa9a621dfed6ad828a6e8e591479af6897c979a83daf73084"),
|
||||
Hex.decode("b20f253d2b62609e932c13f3bca59a22913ea5b1e532d8a707976997461ec143"));
|
||||
|
||||
GetBlocksMessage getBlocksMessage = new GetBlocksMessage(hashList);
|
||||
System.out.println(getBlocksMessage);
|
||||
|
||||
String expected = "e413a0455408387e6c5b029b0d51f7d617a4d1dc4895fa6eda09455cc2ee62c08d907e8180";
|
||||
String expected = "f8a615a0497dcbd12fa99ced7b27cda6611f64eb13ab50e20260eec5ee6b7190e7206d54a00959bdfba5e54fcc9370e86b7996fbe32a277bab65c31a0102226f83c4d3e0f2a001a333c156485880776e929e84c26c9778c1e9b4dcb5cd3bff8ad0aeff385df0a0690e13595c9e8e4fa9a621dfed6ad828a6e8e591479af6897c979a83daf73084a0b20f253d2b62609e932c13f3bca59a22913ea5b1e532d8a707976997461ec143";
|
||||
assertEquals(expected, Hex.toHexString(getBlocksMessage.getEncoded()));
|
||||
|
||||
assertEquals(Command.GET_BLOCKS, getBlocksMessage.getCommand());
|
||||
assertEquals(128, getBlocksMessage.getBlockHashes().size());
|
||||
assertEquals(5, getBlocksMessage.getBlockHashes().size());
|
||||
assertEquals(BlocksMessage.class, getBlocksMessage.getAnswerMessage());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue