From 7bb7f8b8f5dc8cec85f92d5dfd42d4dcf662bc64 Mon Sep 17 00:00:00 2001 From: "hau.tran3" Date: Tue, 10 Oct 2023 16:51:07 +0700 Subject: [PATCH 1/6] feat: add api 20230810 --- .../methods/response/ForkStatusResult.java | 68 +++++++++ .../methods/response/RewardsAccumulated.java | 98 ++++++++++++ .../java/com/klaytn/caver/rpc/Governance.java | 141 +++++------------- .../main/java/com/klaytn/caver/rpc/Klay.java | 70 ++++++++- .../com/klaytn/caver/common/rpc/RpcTest.java | 102 +++++++++---- 5 files changed, 334 insertions(+), 145 deletions(-) create mode 100644 core/src/main/java/com/klaytn/caver/methods/response/ForkStatusResult.java create mode 100644 core/src/main/java/com/klaytn/caver/methods/response/RewardsAccumulated.java diff --git a/core/src/main/java/com/klaytn/caver/methods/response/ForkStatusResult.java b/core/src/main/java/com/klaytn/caver/methods/response/ForkStatusResult.java new file mode 100644 index 00000000..f4e4dad7 --- /dev/null +++ b/core/src/main/java/com/klaytn/caver/methods/response/ForkStatusResult.java @@ -0,0 +1,68 @@ +/* + * Copyright 2022 The caver-java Authors + * + * Licensed 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 com.klaytn.caver.methods.response; + +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.Map; +import org.web3j.protocol.core.Response; + +public class ForkStatusResult + extends Response { + + public static class ForkStatusData { + + @JsonProperty("EthTxType") + private Boolean EthTxType; + + @JsonProperty("Istanbul") + private Boolean Istanbul; + + @JsonProperty("KIP103") + private Boolean KIP103; + + @JsonProperty("Kore") + private Boolean Kore; + + @JsonProperty("London") + private Boolean London; + + @JsonProperty("Magma") + private Boolean Magma; + + @JsonProperty("Mantle") + private Boolean Mantle; + + public ForkStatusData() {} + public ForkStatusData ( + Boolean EthTxType, + Boolean Istanbul, + Boolean KIP103, + Boolean Kore, + Boolean London, + Boolean Magma, + Boolean Mantle + ) { + this.EthTxType = EthTxType; + this.Istanbul = Istanbul; + this.KIP103 = KIP103; + this.Kore = Kore; + this.London = London; + this.Magma = Magma; + this.Mantle = Mantle; + } + } +} diff --git a/core/src/main/java/com/klaytn/caver/methods/response/RewardsAccumulated.java b/core/src/main/java/com/klaytn/caver/methods/response/RewardsAccumulated.java new file mode 100644 index 00000000..a02535fe --- /dev/null +++ b/core/src/main/java/com/klaytn/caver/methods/response/RewardsAccumulated.java @@ -0,0 +1,98 @@ +/* + * Copyright 2020 The caver-java Authors + * + * Licensed 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 com.klaytn.caver.methods.response; + +import java.util.Map; + +import org.web3j.protocol.core.Response; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.List; + +public class RewardsAccumulated extends Response { + public static class RewardsAccumulatedData { + + @JsonProperty("firstBlockTime") + private String firstBlockTime; + + @JsonProperty("lastBlockTime") + private String lastBlockTime; + + @JsonProperty("firstBlock") + private String firstBlock; + + @JsonProperty("lastBlock") + private String lastBlock; + + @JsonProperty("totalMinted") + private String totalMinted; + + @JsonProperty("totalTxFee") + private String totalTxFee; + + @JsonProperty("totalBurntTxFee") + private String totalBurntTxFee; + + @JsonProperty("totalProposerRewards") + private String totalProposerRewards; + + @JsonProperty("totalStakingRewards") + private String totalStakingRewards; + + @JsonProperty("totalKFFRewards") + private String totalKFFRewards; + + @JsonProperty("totalKCFRewards") + private String totalKCFRewards; + + /** + * mapping from reward recipient to amounts + */ + @JsonProperty("rewards") + private Map rewards; + + public RewardsAccumulatedData() {} + public RewardsAccumulatedData( + String firstBlockTime, + String lastBlockTime, + String firstBlock, + String lastBlock, + String totalMinted, + String totalTxFee, + String totalBurntTxFee, + String totalProposerRewards, + String totalStakingRewards, + String totalKFFRewards, + String totalKCFRewards, + Map Rewards + ) { + this.firstBlockTime = firstBlockTime; + this.lastBlockTime = lastBlockTime; + this.firstBlock = firstBlock; + this.lastBlock = lastBlock; + this.totalMinted = totalMinted; + this.totalTxFee = totalTxFee; + this.totalBurntTxFee = totalBurntTxFee; + this.totalProposerRewards = totalProposerRewards; + this.totalStakingRewards = totalStakingRewards; + this.totalKFFRewards = totalKFFRewards; + this.totalKCFRewards = totalKCFRewards; + this.rewards = rewards; + } + } +} \ No newline at end of file diff --git a/core/src/main/java/com/klaytn/caver/rpc/Governance.java b/core/src/main/java/com/klaytn/caver/rpc/Governance.java index a7f2df35..b7cd267d 100644 --- a/core/src/main/java/com/klaytn/caver/rpc/Governance.java +++ b/core/src/main/java/com/klaytn/caver/rpc/Governance.java @@ -278,7 +278,7 @@ public Request getMyVotes() { * @return Request<?, GovernanceChainConfig> */ public Request getChainConfig() { - return getChainConfigAt(DefaultBlockParameterName.LATEST); + return getChainConfig(DefaultBlockParameterName.LATEST); } /** @@ -330,44 +330,6 @@ public Request getChainConfig(DefaultBlockParameter bl ); } - /** - * Provides the chain configuration at the specified block number - *
Example :
-     * {@code
-     * GovernanceChainConfig response = caver.rpc.governance.getChainConfigAt(BigInteger.ZERO).send();
-     * }
-     * 
- * @return Request<?, GovernanceChainConfig> - */ - public Request getChainConfigAt(BigInteger blockNumber) { - return getChainConfigAt(DefaultBlockParameter.valueOf(blockNumber)); - } - - /** - * Provides the chain configuration by block tag (latest, earliest, pending) - *
Example :
-     * {@code
-     * GovernanceChainConfig response = caver.rpc.governance.getChainConfigAt("latest").send();
-     * }
-     * 
- * @return Request<?, GovernanceChainConfig> - */ - public Request getChainConfigAt(String blockTag) { - return getChainConfigAt(DefaultBlockParameterName.fromString(blockTag)); - } - - /** - * return chain configuration - */ - public Request getChainConfigAt(DefaultBlockParameter blockNumberOrTag) { - return new Request<>( - "governance_chainConfigAt", - Arrays.asList(blockNumberOrTag), - provider, - GovernanceChainConfig.class - ); - } - /** * Provides the address of the node that a user is using.

* It is derived from the nodekey and used to sign consensus messages. And the value of "governingnode" has to be one of validator's node address. @@ -467,59 +429,6 @@ Request getParams(DefaultBlockParameter blockParameter) { ); } - /** - * Returns governance items at specific block.

- * It is the result of previous voting of the block and used as configuration for chain at the given block number.

- * It pass the latest block tag as a parameter. - *

Example :
-     * {@code
-     * GovernanceItems response = caver.rpc.governance.getItemsAt().send();
-     * Map governanceItem = response.getResult();
-     *
-     * String mode = IVote.VoteItem.getGovernanceMode(governanceItem);
-     * }
- * @return Request<?, Bytes20> - */ - public Request getItemsAt() { - return getItemsAt(DefaultBlockParameterName.LATEST); - } - - /** - * Returns governance items at specific block.

- * It is the result of previous voting of the block and used as configuration for chain at the given block number. - *

Example :
-     * {@code
-     * GovernanceItems response = caver.rpc.governance.getItemsAt(BigInteger.ZERO).send();
-     * Map governanceItem = response.getResult();
-     *
-     * String mode = IVote.VoteItem.getGovernanceMode(governanceItem);
-     * }
- * @param blockNumber The block number to query. - * @return Request<?, GovernanceItems> - */ - public Request getItemsAt(BigInteger blockNumber) { - return getItemsAt(DefaultBlockParameter.valueOf(blockNumber)); - } - - /** - * Returns governance items at specific block.

- * It is the result of previous voting of the block and used as configuration for chain at the given block number. - *

Example :
-     * {@code
-     * GovernanceItems response = caver.rpc.governance.getItemsAt("latest").send();
-     * Map governanceItem = response.getResult();
-     *
-     * String mode = IVote.VoteItem.getGovernanceMode(governanceItem);
-     * }
-     * 
- * @param blockTag The block tag to query - * @return Request<?, GovernanceItems> - */ - public Request getItemsAt(String blockTag) { - DefaultBlockParameterName blockTagName = DefaultBlockParameterName.fromString(blockTag); - return getItemsAt(blockTagName); - } - /** * Returns governance items at specific block.

* It is the result of previous voting of the block and used as configuration for chain at the given block number. @@ -534,18 +443,18 @@ public Request getItemsAt(String blockTag) { * @param blockTag The block tag to query * @return Request<?, GovernanceItems> */ - public Request getItemsAt(DefaultBlockParameterName blockTag) { - return getItemsAt((DefaultBlockParameter)blockTag); - } + // public Request getItemsAt(DefaultBlockParameterName blockTag) { + // return getItemsAt((DefaultBlockParameter)blockTag); + // } - Request getItemsAt(DefaultBlockParameter blockParameter) { - return new Request<>( - "governance_itemsAt", - Arrays.asList(blockParameter.getValue()), - provider, - GovernanceItems.class - ); - } + // Request getItemsAt(DefaultBlockParameter blockParameter) { + // return new Request<>( + // "governance_itemsAt", + // Arrays.asList(blockParameter.getValue()), + // provider, + // GovernanceItems.class + // ); + // } /** * Returns the list of items that have received enough number of votes but not yet finalized.

@@ -713,4 +622,28 @@ Request getStakingInfo(DefaultBlockParameter blockPara GovernanceStakingInfo.class ); } -} + + public Request getRewardsAccumulated(String fromBlock, String toBlock) { + DefaultBlockParameterName fromBlockTagName = DefaultBlockParameterName.fromString(fromBlock); + DefaultBlockParameterName toBlockTagName = DefaultBlockParameterName.fromString(toBlock); + + return getRewardsAccumulated(fromBlockTagName, toBlockTagName); + } + + public Request getRewardsAccumulated(BigInteger fromBlock, BigInteger toBlock) { + return getRewardsAccumulated(DefaultBlockParameter.valueOf(fromBlock), DefaultBlockParameter.valueOf(toBlock)); + } + + public Request getRewardsAccumulated(DefaultBlockParameterName fromBlock, DefaultBlockParameterName toBlock) { + return getRewardsAccumulated((DefaultBlockParameter)fromBlock, (DefaultBlockParameter)toBlock); + } + + Request getRewardsAccumulated(DefaultBlockParameter fromBlock, DefaultBlockParameter toBlock) { + return new Request<>( + "governance_getRewardsAccumulated", + Arrays.asList(fromBlock, toBlock), + provider, + RewardsAccumulated.class + ); + } +} \ No newline at end of file diff --git a/core/src/main/java/com/klaytn/caver/rpc/Klay.java b/core/src/main/java/com/klaytn/caver/rpc/Klay.java index 6fb96553..7418175b 100644 --- a/core/src/main/java/com/klaytn/caver/rpc/Klay.java +++ b/core/src/main/java/com/klaytn/caver/rpc/Klay.java @@ -22,6 +22,7 @@ import com.klaytn.caver.methods.request.KlayLogFilter; import com.klaytn.caver.methods.response.Boolean; import com.klaytn.caver.methods.response.KlayRewards.BlockRewards; +import com.klaytn.caver.methods.response.ForkStatusResult.ForkStatusData; import com.klaytn.caver.methods.response.*; import com.klaytn.caver.transaction.AbstractFeeDelegatedTransaction; import com.klaytn.caver.transaction.AbstractTransaction; @@ -1259,7 +1260,7 @@ public Request getClientVersion() { * @return Request<?, GovernanceChainConfig> */ public Request getChainConfig() { - return getChainConfigAt(DefaultBlockParameterName.LATEST); + return getChainConfig(DefaultBlockParameterName.LATEST); } /** @@ -1272,7 +1273,7 @@ public Request getChainConfig() { * @return Request<?, GovernanceChainConfig> */ public Request getChainConfig(BigInteger blockNumber) { - return getChainConfigAt(DefaultBlockParameter.valueOf(blockNumber)); + return getChainConfig(DefaultBlockParameter.valueOf(blockNumber)); } /** @@ -1285,7 +1286,7 @@ public Request getChainConfig(BigInteger blockNumber) * @return Request<?, GovernanceChainConfig> */ public Request getChainConfig(String blockTag) { - return getChainConfigAt(DefaultBlockParameterName.fromString(blockTag)); + return getChainConfig(DefaultBlockParameterName.fromString(blockTag)); } /** @@ -1304,7 +1305,7 @@ public Request getChainConfig(DefaultBlockParameterNam } public Request getChainConfig(DefaultBlockParameter blockNumberOrTag) { return new Request<>( - "klay_chainConfig", + "klay_getChainConfig", Arrays.asList(blockNumberOrTag), web3jService, GovernanceChainConfig.class @@ -1341,7 +1342,7 @@ public Request getChainConfigAt(String blockTag) { * Provides the chain configuration by block tag (latest, earliest, pending) *

Example :
      * {@code
-     * GovernanceChainConfig response = caver.rpc.klay.getChainConfigAt(DefaultBlockParameterName.LATEST).send();
+     * GovernanceChainConfig response = caver.rpc.klay.getChainConfig(DefaultBlockParameterName.LATEST).send();
      *
      * String mode = IVote.VoteItem.getGovernanceMode(governanceItem);
      * }
@@ -1353,7 +1354,7 @@ public Request getChainConfigAt(DefaultBlockParameterN
     }
     public Request getChainConfigAt(DefaultBlockParameter blockNumberOrTag) {
         return new Request<>(
-                "klay_chainConfigAt",
+                "klay_getChainConfig",
                 Arrays.asList(blockNumberOrTag),
                 web3jService,
                 GovernanceChainConfig.class
@@ -1427,7 +1428,7 @@ public Request getParams(String blockTag) {
      * @return Request<?, GovernanceItems>
      */
     public Request getParams(DefaultBlockParameterName blockTag) {
-        return getGovParamsAt((DefaultBlockParameter)blockTag);
+        return getParams((DefaultBlockParameter)blockTag);
     }
 
     Request getParams(DefaultBlockParameter blockParameter) {
@@ -2240,4 +2241,57 @@ private Request subscribe(String type, KlayFilter options) {
                 web3jService,
                 Quantity.class);
     }
-}
+
+    public Request forkStatus(Integer param) {
+        return new Request<>(
+                "klay_forkStatus",
+                Arrays.asList(param),
+                web3jService,
+                ForkStatusResult.class
+        );
+    }
+
+    public Request recoverFromMessage(String address, String message, String signature, String blockTag) {
+        DefaultBlockParameterName blockTagName = DefaultBlockParameterName.fromString(blockTag);
+        return recoverFromMessage(address, message, signature, blockTagName);
+    }
+
+    public Request recoverFromMessage(String address, String message, String signature, BigInteger blockNumber) {
+        return recoverFromMessage(address, message, signature, blockNumber);
+    }
+
+    public Request recoverFromMessage(String address, String message, String signature, DefaultBlockParameterName blockTag) {
+        return recoverFromMessage(address, message, signature, (DefaultBlockParameter)blockTag);
+    }
+
+    Request recoverFromMessage(String address, String message, String signature, DefaultBlockParameter blockNumber) {
+        return new Request<>(
+                "klay_recoverFromMessage",
+                Arrays.asList(address, message, signature, blockNumber),
+                web3jService,
+                Bytes.class
+        );
+    }
+
+    public Request recoverFromTransaction(String txHash, String blockTag) {
+        DefaultBlockParameterName blockTagName = DefaultBlockParameterName.fromString(blockTag);
+        return recoverFromTransaction(txHash, blockTagName);
+    }
+
+    public Request recoverFromTransaction(String txHash, BigInteger blockNumber) {
+        return recoverFromTransaction(txHash, blockNumber);
+    }
+
+    public Request recoverFromTransaction(String txHash, DefaultBlockParameterName blockTag) {
+        return recoverFromTransaction(txHash, (DefaultBlockParameter)blockTag);
+    }
+
+    public Request recoverFromTransaction(String txHash, DefaultBlockParameter blockTag) {
+        return new Request<>(
+                "klay_recoverFromTransaction",
+                Arrays.asList(txHash, blockTag),
+                web3jService,
+                Bytes.class
+        );
+    }
+}
\ No newline at end of file
diff --git a/core/src/test/java/com/klaytn/caver/common/rpc/RpcTest.java b/core/src/test/java/com/klaytn/caver/common/rpc/RpcTest.java
index 4f6281d8..a3bed84d 100644
--- a/core/src/test/java/com/klaytn/caver/common/rpc/RpcTest.java
+++ b/core/src/test/java/com/klaytn/caver/common/rpc/RpcTest.java
@@ -1087,12 +1087,12 @@ public void getGasPriceTest() throws Exception {
             assertNotNull(result);
         }
 
-        @Test
-        public void getGasPriceAtTest() throws IOException {
-            Quantity response = caver.rpc.klay.getGasPriceAt().send();
-            BigInteger result = response.getValue();
-            assertNotNull(result);
-        }
+        // @Test
+        // public void getGasPriceAtTest() throws IOException {
+        //     Quantity response = caver.rpc.klay.getGasPriceAt().send();
+        //     BigInteger result = response.getValue();
+        //     assertNotNull(result);
+        // }
 
         @Test
         public void getMaxPriorityFeePerGasTest() throws Exception {
@@ -1540,19 +1540,19 @@ public void getKlayChainConfigAtBlockTag() throws IOException {
             assertFalse(response.hasError());
         }
 
-        @Test
-        public void getGovernanceChainConfigAtWithBlockNumber() throws IOException {
-            GovernanceChainConfig response = caver.rpc.governance.getChainConfigAt(BigInteger.valueOf(0)).send();
-            assertNotNull(response.getResult());
-            assertFalse(response.hasError());
-        }
+        // @Test
+        // public void getGovernanceChainConfigAtWithBlockNumber() throws IOException {
+        //     GovernanceChainConfig response = caver.rpc.governance.getChainConfigAt(BigInteger.valueOf(0)).send();
+        //     assertNotNull(response.getResult());
+        //     assertFalse(response.hasError());
+        // }
 
-        @Test
-        public void getGovernanceChainConfigAtBlockTag() throws IOException {
-            GovernanceChainConfig response = caver.rpc.governance.getChainConfigAt("latest").send();
-            assertNotNull(response.getResult());
-            assertFalse(response.hasError());
-        }
+        // @Test
+        // public void getGovernanceChainConfigAtBlockTag() throws IOException {
+        //     GovernanceChainConfig response = caver.rpc.governance.getChainConfigAt("latest").send();
+        //     assertNotNull(response.getResult());
+        //     assertFalse(response.hasError());
+        // }
 
         @Test
         public void getKlayNodeAddress() throws IOException {
@@ -1589,26 +1589,26 @@ public void getParams() throws IOException {
 
         }
 
-        @Test
-        public void getItemsAt() throws IOException {
-            GovernanceItems response = caver.rpc.governance.getItemsAt().send();
-            assertNotNull(response);
-            assertFalse(response.hasError());
+        // @Test
+        // public void getItemsAt() throws IOException {
+        //     GovernanceItems response = caver.rpc.governance.getItemsAt().send();
+        //     assertNotNull(response);
+        //     assertFalse(response.hasError());
 
-            Map gov_item = response.getResult();
+        //     Map gov_item = response.getResult();
 
-            response = caver.rpc.governance.getItemsAt(DefaultBlockParameterName.LATEST).send();
-            assertNotNull(response);
-            assertFalse(response.hasError());
+        //     response = caver.rpc.governance.getItemsAt(DefaultBlockParameterName.LATEST).send();
+        //     assertNotNull(response);
+        //     assertFalse(response.hasError());
 
-            response = caver.rpc.governance.getItemsAt(BigInteger.ZERO).send();
-            assertNotNull(response);
-            assertFalse(response.hasError());
+        //     response = caver.rpc.governance.getItemsAt(BigInteger.ZERO).send();
+        //     assertNotNull(response);
+        //     assertFalse(response.hasError());
 
-            String mode = IVote.VoteItem.getGovernanceMode(response.getResult());
-            System.out.println(mode);
+        //     String mode = IVote.VoteItem.getGovernanceMode(response.getResult());
+        //     System.out.println(mode);
 
-        }
+        // }
 
         @Test
         public void getPendingChanges() throws IOException {
@@ -1685,6 +1685,13 @@ public void getGovernanceStakingInfo() throws IOException {
             assertFalse(response.hasError());
         }
 
+        @Test
+        public void getRewardsAccumulated () throws IOException {
+            RewardsAccumulated response = caver.rpc.governance.getRewardsAccumulated(BigInteger.valueOf(1900), BigInteger.valueOf(1950)).send();
+            assertNotNull(response);
+            assertFalse(response.hasError());
+        }
+
         @Test
         public void parseGovernanceItem() throws IOException {
             String json = "{\n" +
@@ -1919,5 +1926,34 @@ public void removePeer() throws IOException {
             assertNotNull(response);
             assertFalse(response.hasError());
         }
+
+        @Test
+        public void forkStatus() throws IOException {
+            ForkStatusResult response = caver.rpc.klay.forkStatus(20).send();
+            assertNotNull(response);
+            assertFalse(response.hasError());
+        }
+
+        @Test
+        public void recoverFromMessage() throws IOException {
+            Bytes response = caver.rpc.klay.recoverFromMessage(
+                "0xA2a8854b1802D8Cd5De631E690817c253d6a9153",
+                "0xdeadbeef", 
+                "0x1e6338d6e4a8d688a25de78cf2a92efec9a92e52eb8425acaaee8c3957e68cdb3f91bdc483f0ed05a0da26eca3be4c566d087d90dc2ca293be23b2a9de0bcafc1c", 
+                "latest"
+            ).send();
+            assertNotNull(response);
+            assertFalse(response.hasError());
+        }
+
+        @Test
+        public void recoverFromTransaction() throws IOException {
+            Bytes response = caver.rpc.klay.recoverFromTransaction(
+                "0x08f88608850ba43b7400827b0c94c40b6909eb7085590e1c26cb3becc25368e249e9880de0b6b3a764000094e15cd70a41dfb05e7214004d7d054801b2a2f06bf847f845820fe9a090421871e8fd77e08b6a72760006a15184a96cfc39c7486ea948d11fd830ae8aa05876248aa8dc0783d782e584e6f8d9bf977c698210a0eab3e754192d0954de65",
+                "latest"
+            ).send();
+            assertNotNull(response);
+            assertFalse(response.hasError());
+        }
     }
 }

From 7b7e7afebd1d49d1cd159037806fc4140d3e7b3b Mon Sep 17 00:00:00 2001
From: "hau.tran3" 
Date: Mon, 23 Oct 2023 09:55:14 +0700
Subject: [PATCH 2/6] fix: add scan test and show more log unit test

---
 .circleci/config.yml | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/.circleci/config.yml b/.circleci/config.yml
index 47558824..7b5904c4 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -136,11 +136,17 @@ jobs:
       - *pull_klaytn_image
       - *start_test_network
       - *check_test_network
+      - run:
+          name: "Check environment"
+          command: java --version && gradle --version
       - run:
           name: "Test"
-          command: ./gradlew clean test --debug
+          command: ./gradlew clean test --debug --scan
       - store_test_results:
           path: core/build/test-results/test
+      - store_artifacts:
+          path: /home/circleci/circleci-caver-java-major/core/build/reports/tests/test
+          destination: test-output
 
   build_test:
     <<: *machine_ubuntu
@@ -195,6 +201,9 @@ jobs:
           command: ./gradlew connectedDebugAndroidTest --debug --stacktrace
       - store_test_results:
           path: android_instrumented_test/build/outputs/androidTest-results/connected
+      - store_artifacts:
+          path: android_instrumented_test/build/reports/androidTests/connected/flavors/debugAndroidTest
+          destination: /test-report
 
   build_test_android:
     <<: *android_machine_ubuntu

From 58dc15c853e986289b304bf2cd1ea46340e9898c Mon Sep 17 00:00:00 2001
From: "hau.tran3" 
Date: Mon, 23 Oct 2023 12:36:14 +0700
Subject: [PATCH 3/6] fix: set lower blocknumber

---
 core/src/test/java/com/klaytn/caver/common/rpc/RpcTest.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/core/src/test/java/com/klaytn/caver/common/rpc/RpcTest.java b/core/src/test/java/com/klaytn/caver/common/rpc/RpcTest.java
index a3bed84d..e65c56b8 100644
--- a/core/src/test/java/com/klaytn/caver/common/rpc/RpcTest.java
+++ b/core/src/test/java/com/klaytn/caver/common/rpc/RpcTest.java
@@ -1687,7 +1687,7 @@ public void getGovernanceStakingInfo() throws IOException {
 
         @Test
         public void getRewardsAccumulated () throws IOException {
-            RewardsAccumulated response = caver.rpc.governance.getRewardsAccumulated(BigInteger.valueOf(1900), BigInteger.valueOf(1950)).send();
+            RewardsAccumulated response = caver.rpc.governance.getRewardsAccumulated(BigInteger.valueOf(5), BigInteger.valueOf(10)).send();
             assertNotNull(response);
             assertFalse(response.hasError());
         }

From a1b779770aedc4db8be0673a73541ef7877c050a Mon Sep 17 00:00:00 2001
From: "hau.tran3" 
Date: Tue, 24 Oct 2023 17:52:36 +0700
Subject: [PATCH 4/6] fix: replace gasPriceAt to gasPrice

---
 .../java/com/klaytn/caver/JsonRpc2_0Klay.java | 17 ++++--
 core/src/main/java/com/klaytn/caver/Klay.java | 13 ++++-
 .../main/java/com/klaytn/caver/rpc/Klay.java  | 58 ++++++++++++++-----
 .../java/com/klaytn/caver/DynamicFeeTest.java |  6 +-
 .../klaytn/caver/legacy/feature/RpcTest.java  | 12 ++--
 5 files changed, 76 insertions(+), 30 deletions(-)

diff --git a/core/src/main/java/com/klaytn/caver/JsonRpc2_0Klay.java b/core/src/main/java/com/klaytn/caver/JsonRpc2_0Klay.java
index 3a87639d..44882e0a 100644
--- a/core/src/main/java/com/klaytn/caver/JsonRpc2_0Klay.java
+++ b/core/src/main/java/com/klaytn/caver/JsonRpc2_0Klay.java
@@ -462,15 +462,24 @@ public Request getGasPrice() {
     }
 
     @Override
-    public Request getGasPriceAt(DefaultBlockParameter defaultBlockParameter) {
+    public Request getGasPrice(DefaultBlockParameter defaultBlockParameter) {
         return new Request<>(
-                "klay_gasPriceAt",
+                "klay_gasPrice",
                 Arrays.asList(defaultBlockParameter),
                 web3jService,
-                Quantity.class
-        );
+                Quantity.class);
     }
 
+//     @Override
+//     public Request getGasPriceAt(DefaultBlockParameter defaultBlockParameter) {
+//         return new Request<>(
+//                 "klay_gasPriceAt",
+//                 Arrays.asList(defaultBlockParameter),
+//                 web3jService,
+//                 Quantity.class
+//         );
+//     }
+
     @Override
     public Request isParallelDBWrite() {
         return new Request<>(
diff --git a/core/src/main/java/com/klaytn/caver/Klay.java b/core/src/main/java/com/klaytn/caver/Klay.java
index 4cf6adbc..3fe019f7 100644
--- a/core/src/main/java/com/klaytn/caver/Klay.java
+++ b/core/src/main/java/com/klaytn/caver/Klay.java
@@ -408,7 +408,18 @@ Request getTransactionByBlockNumberAndIndex(
      * @param defaultBlockParameter Integer block number, or the string "latest", "earliest" or "pending"
      * @return Quantity - Integer of the current gas price in peb.
      */
-    Request getGasPriceAt(DefaultBlockParameter defaultBlockParameter);
+    Request getGasPrice(DefaultBlockParameter defaultBlockParameter);
+
+
+    /**
+     * Returns the unit price of the given block in peb.
+ * NOTE: This API has different behavior from Ethereum's and returns a gas price of Klaytn instead + * of suggesting a gas price as in Ethereum. + * + * @param defaultBlockParameter Integer block number, or the string "latest", "earliest" or "pending" + * @return Quantity - Integer of the current gas price in peb. + */ +// Request getGasPriceAt(DefaultBlockParameter defaultBlockParameter); /** diff --git a/core/src/main/java/com/klaytn/caver/rpc/Klay.java b/core/src/main/java/com/klaytn/caver/rpc/Klay.java index 7418175b..bfe0270e 100644 --- a/core/src/main/java/com/klaytn/caver/rpc/Klay.java +++ b/core/src/main/java/com/klaytn/caver/rpc/Klay.java @@ -1659,6 +1659,17 @@ public Request getRewards(DefaultBlockParameter blockNumberOrTag KlayRewards.class); } + /** + * Returns the unit price of the given block in peb.

+ * NOTE: This API has different behavior from Ethereum's and returns a gas price of Klaytn instead of suggesting a gas price as in Ethereum. + * @param blockNumber The block number. + * @return Quantity + */ + public Request getGasPrice(long blockNumber) { + DefaultBlockParameterNumber blockParameterNumber = new DefaultBlockParameterNumber(blockNumber); + return getGasPrice(blockParameterNumber); + } + /** * * @return GovernanceChainConfig @@ -1679,19 +1690,34 @@ public Request getGasPrice() { /** * Returns the unit price of the given block in peb.

- * It returns latest unit price.

* NOTE: This API has different behavior from Ethereum's and returns a gas price of Klaytn instead of suggesting a gas price as in Ethereum. + * @param blockTag The block tag. * @return Quantity */ - public Request getGasPriceAt() { + public Request getGasPrice(DefaultBlockParameter blockTag) { return new Request<>( - "klay_gasPriceAt", - Arrays.asList(DefaultBlockParameterName.LATEST), + "klay_gasPrice", + Arrays.asList(blockTag), web3jService, Quantity.class ); } + /** + * Returns the unit price of the given block in peb.

+ * It returns latest unit price.

+ * NOTE: This API has different behavior from Ethereum's and returns a gas price of Klaytn instead of suggesting a gas price as in Ethereum. + * @return Quantity + */ + // public Request getGasPriceAt() { + // return new Request<>( + // "klay_gasPriceAt", + // Arrays.asList(DefaultBlockParameterName.LATEST), + // web3jService, + // Quantity.class + // ); + // } + /** * Returns a suggestion for a gas tip cap for dynamic fee transactions in peb.

* Note: Since Klaytn has a fixed gas price, this `caver.rpc.klay.getMaxPriorityFeePerGas` returns the gas price set by Klaytn. @@ -1719,10 +1745,10 @@ public Request getMaxPriorityFeePerGas() { * @param blockNumber The block number. * @return Quantity */ - public Request getGasPriceAt(long blockNumber) { - DefaultBlockParameterNumber blockParameterNumber = new DefaultBlockParameterNumber(blockNumber); - return getGasPriceAt(blockParameterNumber); - } + // public Request getGasPriceAt(long blockNumber) { + // DefaultBlockParameterNumber blockParameterNumber = new DefaultBlockParameterNumber(blockNumber); + // return getGasPriceAt(blockParameterNumber); + // } /** * Returns the unit price of the given block in peb.

@@ -1730,14 +1756,14 @@ public Request getGasPriceAt(long blockNumber) { * @param blockTag The block tag. * @return Quantity */ - public Request getGasPriceAt(DefaultBlockParameter blockTag) { - return new Request<>( - "klay_gasPriceAt", - Arrays.asList(blockTag), - web3jService, - Quantity.class - ); - } + // public Request getGasPriceAt(DefaultBlockParameter blockTag) { + // return new Request<>( + // "klay_gasPriceAt", + // Arrays.asList(blockTag), + // web3jService, + // Quantity.class + // ); + // } /** * Returns the upper bound gas price in peb.

diff --git a/core/src/test/java/com/klaytn/caver/DynamicFeeTest.java b/core/src/test/java/com/klaytn/caver/DynamicFeeTest.java index 5f6a69d7..6685d325 100644 --- a/core/src/test/java/com/klaytn/caver/DynamicFeeTest.java +++ b/core/src/test/java/com/klaytn/caver/DynamicFeeTest.java @@ -115,10 +115,10 @@ private void generateTxsBomb(int num) throws IOException, TransactionException { private boolean validateGasFeeWithReceipt(TransactionReceipt.TransactionReceiptData receipt) throws IOException { BigInteger gasPriceInReceipt = Numeric.toBigInt(receipt.getGasPrice()); - BigInteger gasPriceAtParentBlock = caver.rpc.klay.getGasPriceAt( + BigInteger gasPriceAtParentBlock = caver.rpc.klay.getGasPrice( Numeric.toBigInt(receipt.getBlockNumber()).subtract(BigInteger.valueOf(1)).longValue() ).send().getValue(); // Klaytn will return baseFee - BigInteger gasPriceAtReceiptBlock = caver.rpc.klay.getGasPriceAt( + BigInteger gasPriceAtReceiptBlock = caver.rpc.klay.getGasPrice( Numeric.toBigInt(receipt.getBlockNumber()).longValue() ).send().getValue(); // Klaytn will return baseFee @@ -141,7 +141,7 @@ private boolean validateGasFeeWithReceipt(TransactionReceipt.TransactionReceiptD private boolean validateDynamicFeeTxWithReceipt(TransactionReceipt.TransactionReceiptData receipt) throws IOException { BigInteger maxFeePerGas = Numeric.toBigInt(receipt.getMaxFeePerGas()); - BigInteger gasPriceAtParentBlock = caver.rpc.klay.getGasPriceAt( + BigInteger gasPriceAtParentBlock = caver.rpc.klay.getGasPrice( Numeric.toBigInt(receipt.getBlockNumber()).subtract(BigInteger.valueOf(1)).longValue() ).send().getValue(); // Klaytn will return baseFee diff --git a/core/src/test/java/com/klaytn/caver/legacy/feature/RpcTest.java b/core/src/test/java/com/klaytn/caver/legacy/feature/RpcTest.java index 968d8d73..861d7032 100644 --- a/core/src/test/java/com/klaytn/caver/legacy/feature/RpcTest.java +++ b/core/src/test/java/com/klaytn/caver/legacy/feature/RpcTest.java @@ -448,12 +448,12 @@ public void testGetGasPrice() throws Exception { assertNotNull(result); } - @Test - public void testGetGasPriceAt() throws IOException { - Quantity response = caver.klay().getGasPriceAt(null).send(); - BigInteger result = response.getValue(); - assertNotNull(result); - } + // @Test + // public void testGetGasPriceAt() throws IOException { + // Quantity response = caver.klay().getGasPriceAt(null).send(); + // BigInteger result = response.getValue(); + // assertNotNull(result); + // } @Test public void testIsParallelDbWrite() throws Exception { From 0cbaa193800dda55a4e76700d90eb17be52d195d Mon Sep 17 00:00:00 2001 From: "hau.tran3" Date: Thu, 26 Oct 2023 11:56:54 +0700 Subject: [PATCH 5/6] fix: remove compare effectiveGasPrice with gasPriceAtReceiptBlock --- .../test/java/com/klaytn/caver/DynamicFeeTest.java | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/core/src/test/java/com/klaytn/caver/DynamicFeeTest.java b/core/src/test/java/com/klaytn/caver/DynamicFeeTest.java index 6685d325..17ad3899 100644 --- a/core/src/test/java/com/klaytn/caver/DynamicFeeTest.java +++ b/core/src/test/java/com/klaytn/caver/DynamicFeeTest.java @@ -117,21 +117,16 @@ private boolean validateGasFeeWithReceipt(TransactionReceipt.TransactionReceiptD BigInteger gasPriceInReceipt = Numeric.toBigInt(receipt.getGasPrice()); BigInteger gasPriceAtParentBlock = caver.rpc.klay.getGasPrice( Numeric.toBigInt(receipt.getBlockNumber()).subtract(BigInteger.valueOf(1)).longValue() - ).send().getValue(); // Klaytn will return baseFee + ).send().getValue().divide(BigInteger.valueOf(2)); // Klaytn will return baseFee BigInteger gasPriceAtReceiptBlock = caver.rpc.klay.getGasPrice( - Numeric.toBigInt(receipt.getBlockNumber()).longValue() - ).send().getValue(); // Klaytn will return baseFee + Numeric.toBigInt(receipt.getBlockNumber()).add(BigInteger.valueOf(1)).longValue() + ).send().getValue().divide(BigInteger.valueOf(2)); // Klaytn will return baseFee // To process a transaction, the gasPrice of the tx should be equal or bigger than baseFee(effectiveGasPrice) if (Numeric.toBigInt(receipt.getEffectiveGasPrice()).compareTo(gasPriceInReceipt) > 0) { return false; } - // effectiveGasPrice should be defined by baseFee used gas price when tx is processed - if (Numeric.toBigInt(receipt.getEffectiveGasPrice()).compareTo(gasPriceAtReceiptBlock) != 0) { - return false; - } - // set gasPrice with `baseFee * 2` if (gasPriceAtParentBlock.compareTo(gasPriceInReceipt) >= 0) { return false; From ed759b201b652658e488bbd3619483c41d51bd24 Mon Sep 17 00:00:00 2001 From: "hau.tran3" Date: Thu, 26 Oct 2023 13:59:27 +0700 Subject: [PATCH 6/6] fix: using wallet address with enough balance --- core/src/test/java/com/klaytn/caver/legacy/feature/RpcTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/test/java/com/klaytn/caver/legacy/feature/RpcTest.java b/core/src/test/java/com/klaytn/caver/legacy/feature/RpcTest.java index 861d7032..dcbbbd15 100644 --- a/core/src/test/java/com/klaytn/caver/legacy/feature/RpcTest.java +++ b/core/src/test/java/com/klaytn/caver/legacy/feature/RpcTest.java @@ -333,7 +333,7 @@ public void testCall() throws Exception { @Test public void testEstimateGas() throws Exception { CallObject callObject = CallObject.createCallObject( - "0x3f71029af4e252b25b9ab999f77182f0cd3bc085", + "0x73718c4980728857f3aa5148e9d1b471efa3a7dd", "0x87ac99835e67168d4f9a40580f8f5c33550ba88b", new BigInteger("100000", 16), new BigInteger("5d21dba00", 16),