You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuweni.apache.org by to...@apache.org on 2020/06/27 22:45:51 UTC
[incubator-tuweni] branch master updated: Add ethstats coverage
This is an automated email from the ASF dual-hosted git repository.
toulmean pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-tuweni.git
The following commit(s) were added to refs/heads/master by this push:
new 3a1b000 Add ethstats coverage
new f622b76 Merge pull request #105 from atoulme/ethstats_coverage
3a1b000 is described below
commit 3a1b00039534426e2676952735b2df815afad111
Author: Antoine Toulme <an...@lunar-ocean.com>
AuthorDate: Sat Jun 27 15:31:50 2020 -0700
Add ethstats coverage
---
.../apache/tuweni/ethstats/AuthMessageTest.java | 33 +++++++++++
.../org/apache/tuweni/ethstats/BlockStatsTest.java | 66 ++++++++++++++++++++++
.../org/apache/tuweni/ethstats/TxStatsTest.java | 34 +++++++++++
3 files changed, 133 insertions(+)
diff --git a/ethstats/src/test/java/org/apache/tuweni/ethstats/AuthMessageTest.java b/ethstats/src/test/java/org/apache/tuweni/ethstats/AuthMessageTest.java
new file mode 100644
index 0000000..d33f5c5
--- /dev/null
+++ b/ethstats/src/test/java/org/apache/tuweni/ethstats/AuthMessageTest.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE
+ * file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file
+ * to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+package org.apache.tuweni.ethstats;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.junit.jupiter.api.Test;
+
+class AuthMessageTest {
+
+ @Test
+ void toJson() throws JsonProcessingException {
+ NodeInfo nodeInfo = new NodeInfo("foo", "node", 123, "eth", "protocol", "os", "123");
+ AuthMessage message = new AuthMessage(nodeInfo, "foo", "secret");
+ ObjectMapper mapper = new ObjectMapper();
+ assertEquals(
+ "{\"info\":{\"name\":\"foo\",\"node\":\"node\",\"port\":123,\"net\":\"eth\",\"protocol\":\"protocol\",\"api\":\"No\",\"os\":\"os\",\"client\":\"0.1.0\",\"os_v\":\"123\",\"canUpdateHistory\":true},\"secret\":\"secret\",\"id\":\"foo\"}",
+ mapper.writeValueAsString(message));
+
+ }
+}
diff --git a/ethstats/src/test/java/org/apache/tuweni/ethstats/BlockStatsTest.java b/ethstats/src/test/java/org/apache/tuweni/ethstats/BlockStatsTest.java
new file mode 100644
index 0000000..2b93d1f
--- /dev/null
+++ b/ethstats/src/test/java/org/apache/tuweni/ethstats/BlockStatsTest.java
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE
+ * file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file
+ * to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+package org.apache.tuweni.ethstats;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import org.apache.tuweni.bytes.Bytes;
+import org.apache.tuweni.bytes.Bytes32;
+import org.apache.tuweni.eth.Address;
+import org.apache.tuweni.eth.EthJsonModule;
+import org.apache.tuweni.eth.Hash;
+import org.apache.tuweni.units.bigints.UInt256;
+
+import java.util.Collections;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.junit.jupiter.api.Test;
+
+class BlockStatsTest {
+
+ @Test
+ void toJson() throws JsonProcessingException {
+ BlockStats stats = new BlockStats(
+ UInt256.ONE,
+ Hash.fromBytes(Bytes32.random()),
+ Hash.fromBytes(Bytes32.random()),
+ 32L,
+ Address.fromBytes(Bytes.random(20)),
+ 23L,
+ 4000L,
+ UInt256.ZERO,
+ UInt256.ONE,
+ Collections.singletonList(new TxStats(Hash.fromBytes(Bytes32.random()))),
+ Hash.fromBytes(Bytes32.random()),
+ Hash.fromBytes(Bytes32.random()),
+ Collections.emptyList());
+ ObjectMapper mapper = new ObjectMapper();
+ mapper.registerModule(new EthJsonModule());
+ assertEquals(
+ "{\"number\":1,\"hash\":\""
+ + stats.getHash()
+ + "\",\"parentHash\":\""
+ + stats.getParentHash()
+ + "\",\"timestamp\":32,\"miner\":\""
+ + stats.getMiner().toHexString()
+ + "\",\"gasUsed\":23,\"gasLimit\":4000,\"difficulty\":\"0\",\"totalDifficulty\":\"1\",\"transactions\":[{\"hash\":\""
+ + stats.getTransactions().get(0).getHash().toHexString()
+ + "\"}],\"transactionsRoot\":\""
+ + stats.getTransactionsRoot()
+ + "\",\"stateRoot\":\""
+ + stats.getStateRoot()
+ + "\",\"uncles\":[]}",
+ mapper.writeValueAsString(stats));
+ }
+}
diff --git a/ethstats/src/test/java/org/apache/tuweni/ethstats/TxStatsTest.java b/ethstats/src/test/java/org/apache/tuweni/ethstats/TxStatsTest.java
new file mode 100644
index 0000000..de038a0
--- /dev/null
+++ b/ethstats/src/test/java/org/apache/tuweni/ethstats/TxStatsTest.java
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE
+ * file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file
+ * to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
+ * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations under the License.
+ */
+package org.apache.tuweni.ethstats;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import org.apache.tuweni.bytes.Bytes32;
+import org.apache.tuweni.eth.EthJsonModule;
+import org.apache.tuweni.eth.Hash;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.junit.jupiter.api.Test;
+
+class TxStatsTest {
+
+ @Test
+ void toJson() throws JsonProcessingException {
+ TxStats stats = new TxStats(Hash.fromBytes(Bytes32.random()));
+ ObjectMapper mapper = new ObjectMapper();
+ mapper.registerModule(new EthJsonModule());
+ assertEquals("{\"hash\":\"" + stats.getHash().toHexString() + "\"}", mapper.writeValueAsString(stats));
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@tuweni.apache.org
For additional commands, e-mail: commits-help@tuweni.apache.org