diff --git a/CHANGELOG.md b/CHANGELOG.md index 2660a093a..462cd44f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,14 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +# [v0.23.1](https://github.com/nervosnetwork/ckb-sdk-java/compare/v0.23.0...v0.23.1) (2019-10-22) + +### Feature + +* Add transaction fee to sendCapacity example([60f2faf](https://github.com/nervosnetwork/ckb-sdk-java/commit/60f2fafedb129d31100c26827379ef4a56dbe9c8)) +* Move exceptions to outside application([52b85e5](https://github.com/nervosnetwork/ckb-sdk-java/commit/52b85e540fdecbf04225a6ba44b89e7d4df59c93)) +* Add maven config to build.gradle([61f08ae](https://github.com/nervosnetwork/ckb-sdk-java/commit/61f08aedffab372b03fd93720f15a6ee9ec54a90)) + # [v0.23.0](https://github.com/nervosnetwork/ckb-sdk-java/compare/v0.22.0...v0.23.0) (2019-10-19) ### Feature diff --git a/README.md b/README.md index 5da716235..feb0076ff 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,26 @@ Java SDK for Nervos [CKB](https://github.com/nervosnetwork/ckb). ### Installation +#### Install from repositories: + +- Maven +``` + + org.nervos.ckb + core + {version} + +``` + +Gradle +``` +implementation 'org.nervos.ckb:core:{version}' +``` + +#### Install manually + You can generate the jar and import manually. + ```shell git clone https://github.com/nervosnetwork/ckb-sdk-java.git diff --git a/build.gradle b/build.gradle index fd2581bc7..d44a4b95b 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ buildscript { - ext.bouncycastleVersion = '1.63' + ext.bouncycastleVersion = '1.64' ext.rxjavaVersion = '2.2.13' ext.gsonVersion = '2.8.6' ext.okhttpVersion = '4.2.2' @@ -10,7 +10,13 @@ buildscript { ext.junitVersion = '5.5.2' + repositories { + jcenter() + mavenCentral() + } + dependencies { + classpath 'io.codearte.gradle.nexus:gradle-nexus-staging-plugin:0.21.1' classpath 'com.github.jengelman.gradle.plugins:shadow:5.1.0' } } @@ -19,12 +25,14 @@ plugins { id 'com.github.johnrengelman.shadow' version '5.1.0' id 'java' id 'com.github.sherter.google-java-format' version '0.8' + id 'com.jfrog.bintray' version '1.8.4' } apply plugin: 'com.github.johnrengelman.shadow' apply plugin: 'application' +apply plugin: 'io.codearte.nexus-staging' -mainClassName = 'org.nervos.ckb.RpcClient' +mainClassName = 'org.nervos.ckb.example.RpcExample' applicationName = 'ckb-sdk-java' description 'ckb-sdk-java base project' @@ -35,7 +43,7 @@ allprojects { targetCompatibility = 1.8 group 'org.nervos.ckb' - version '0.23.0' + version '0.23.1' apply plugin: 'java' @@ -68,3 +76,102 @@ subprojects { build.dependsOn installGitHooks } +configure(subprojects.findAll { it.name != 'tests' }) { + // Required for Maven Nexus repository + apply plugin: 'maven' + apply plugin: 'signing' + + // Required for JFrog Artifactory repository + apply plugin: 'maven-publish' + apply plugin: 'com.jfrog.bintray' + + task javadocJar(type: Jar) { + classifier = 'javadoc' + from javadoc + } + + task sourcesJar(type: Jar) { + classifier = 'sources' + from sourceSets.main.allSource + } + + task testJar(type: Jar) { + classifier = 'tests' + from sourceSets.test.output + } + + artifacts { + archives sourcesJar, javadocJar, testJar + } + + ext { + ossrhUsername = project.hasProperty('ossrhUsername') ? project.property('ossrhUsername') : '' + ossrhPassword = project.hasProperty('ossrhPassword') ? project.property('ossrhPassword') : '' + } + + publishing { + publications { + mavenJava(MavenPublication) { + groupId 'org.nervos.ckb' + version '0.23.1' + from components.java + } + } + } + + uploadArchives { + repositories { + mavenDeployer { + beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) } + + repository(url: 'https://oss.sonatype.org/service/local/staging/deploy/maven2/') { + authentication( + userName: ossrhUsername, + password: ossrhPassword + ) + } + + pom.project { + name 'ckb-sdk-java' + packaging 'jar' + description project.description + url 'https://github.com/nervosnetwork/ckb-sdk-java.git' + + scm { + connection 'scm:git@github.com:nervosnetwork/ckb-sdk-java.git' + url 'https://github.com/nervosnetwork/ckb-sdk-java.git' + } + + licenses { + license { + name 'The MIT License' + url 'https://opensource.org/licenses/MIT' + } + } + + developers { + developer { + id 'nervos' + name 'nervos developer' + email 'op@nervos.org' + } + } + } + } + } + } + + signing { + required { gradle.taskGraph.hasTask('uploadArchives') } // only execute as part of this task + sign configurations.archives + } + + task release { + dependsOn 'build' + dependsOn 'uploadArchives' + dependsOn 'bintrayUpload' + + tasks.findByName('uploadArchives').mustRunAfter 'build' + tasks.findByName('bintrayUpload').mustRunAfter 'build' + } +} diff --git a/console/src/main/java/org/nervos/ckb/example/RpcExample.java b/console/src/main/java/org/nervos/ckb/example/RpcExample.java index 84071e17e..79d62814a 100644 --- a/console/src/main/java/org/nervos/ckb/example/RpcExample.java +++ b/console/src/main/java/org/nervos/ckb/example/RpcExample.java @@ -1,6 +1,7 @@ package org.nervos.ckb.example; import com.google.gson.Gson; +import java.io.IOException; import java.math.BigInteger; import org.nervos.ckb.service.Api; import org.nervos.ckb.type.Block; @@ -17,7 +18,7 @@ public RpcExample() { api = new Api(NODE_URL, false); } - public static void main(String[] args) { + public static void main(String[] args) throws IOException { System.out.println("Welcome to use SDK to visit CKB Blockchain"); RpcExample client = new RpcExample(); System.out.println( @@ -29,15 +30,15 @@ public static void main(String[] args) { + new Gson().toJson(client.getBlockByNumber(currentBlockNumber.toString()))); } - public Block getBlockByNumber(String blockNumber) { + public Block getBlockByNumber(String blockNumber) throws IOException { return api.getBlockByNumber(blockNumber); } - public BigInteger getTipBlockNumber() { + public BigInteger getTipBlockNumber() throws IOException { return api.getTipBlockNumber(); } - public BlockchainInfo getBlockchainInfo() { + public BlockchainInfo getBlockchainInfo() throws IOException { return api.getBlockchainInfo(); } } diff --git a/console/src/main/java/org/nervos/ckb/example/TransactionExample.java b/console/src/main/java/org/nervos/ckb/example/TransactionExample.java index c0c4f5445..77cb8ccd7 100644 --- a/console/src/main/java/org/nervos/ckb/example/TransactionExample.java +++ b/console/src/main/java/org/nervos/ckb/example/TransactionExample.java @@ -53,6 +53,7 @@ public static void main(String[] args) throws Exception { new Receiver(KeyPairs.get(0).address, new BigInteger("800").multiply(UnitCKB)), new Receiver(KeyPairs.get(1).address, new BigInteger("900").multiply(UnitCKB)), new Receiver(KeyPairs.get(2).address, new BigInteger("1000").multiply(UnitCKB))); + BigInteger txFee = BigInteger.valueOf(10000); System.out.println( "Before transfer, miner's balance: " @@ -65,7 +66,7 @@ public static void main(String[] args) throws Exception { + " CKB"); // miner send capacity to three receiver1 accounts with 800, 900 and 1000 CKB - String hash = sendCapacity(minerPrivateKey, receivers1, minerAddress); + String hash = sendCapacity(minerPrivateKey, receivers1, minerAddress, txFee); System.out.println("First transaction hash: " + hash); Thread.sleep(30000); // waiting transaction into block, sometimes you should wait more seconds @@ -95,7 +96,7 @@ public static void main(String[] args) throws Exception { + " CKB"); // sender1 accounts send capacity to three receiver2 accounts with 400, 500 and 600 CKB - String hash2 = sendCapacity(senders1, receivers2, changeAddress); + String hash2 = sendCapacity(senders1, receivers2, changeAddress, txFee); System.out.println("Second transaction hash: " + hash2); Thread.sleep(30000); // waiting transaction into block, sometimes you should wait more seconds @@ -111,17 +112,19 @@ private static BigInteger getBalance(String address) throws IOException { } private static String sendCapacity( - String privateKey, List receivers, String changeAddress) throws IOException { + String privateKey, List receivers, String changeAddress, BigInteger fee) + throws IOException { BigInteger needCapacity = BigInteger.ZERO; for (Receiver receiver : receivers) { needCapacity = needCapacity.add(receiver.capacity); } List senders = Collections.singletonList(new Sender(privateKey, needCapacity)); - return sendCapacity(senders, receivers, changeAddress); + return sendCapacity(senders, receivers, changeAddress, fee); } private static String sendCapacity( - List senders, List receivers, String changeAddress) throws IOException { + List senders, List receivers, String changeAddress, BigInteger fee) + throws IOException { TransactionBuilder builder = new TransactionBuilder(api); CollectUtils txUtils = new CollectUtils(api); @@ -130,7 +133,7 @@ private static String sendCapacity( builder.addInputs(cellsWithPrivateKey.inputs); } - builder.addOutputs(txUtils.generateOutputs(receivers, changeAddress)); + builder.addOutputs(txUtils.generateOutputs(receivers, changeAddress, fee)); builder.buildTx(); diff --git a/console/src/main/java/org/nervos/ckb/example/transaction/CollectUtils.java b/console/src/main/java/org/nervos/ckb/example/transaction/CollectUtils.java index 25de509f7..85e2563a2 100644 --- a/console/src/main/java/org/nervos/ckb/example/transaction/CollectUtils.java +++ b/console/src/main/java/org/nervos/ckb/example/transaction/CollectUtils.java @@ -48,7 +48,11 @@ public List collectInputs(List senders) throws IOEx return cellsWithPrivateKeys; } - public List generateOutputs(List receivers, String changeAddress) { + public List generateOutputs( + List receivers, String changeAddress, BigInteger fee) throws IOException { + if (fee.compareTo(BigInteger.ZERO) < 0) { + throw new IOException("Transaction fee should not be smaller than zero"); + } List cellOutputs = new ArrayList<>(); AddressUtils addressUtils = new AddressUtils(Network.TESTNET); for (Receiver receiver : receivers) { @@ -62,6 +66,8 @@ public List generateOutputs(List receivers, String changeA for (Receiver receiver : receivers) { needCapacity = needCapacity.add(receiver.capacity); } + needCapacity = needCapacity.add(fee); + if (collectedCapacity.compareTo(needCapacity) > 0) { String changeAddressBlake160 = addressUtils.getBlake160FromAddress(changeAddress); cellOutputs.add( diff --git a/core/src/main/java/org/nervos/ckb/service/Api.java b/core/src/main/java/org/nervos/ckb/service/Api.java index afc17dffa..9082baaa0 100644 --- a/core/src/main/java/org/nervos/ckb/service/Api.java +++ b/core/src/main/java/org/nervos/ckb/service/Api.java @@ -1,6 +1,7 @@ package org.nervos.ckb.service; import com.google.gson.reflect.TypeToken; +import java.io.IOException; import java.math.BigInteger; import java.util.Arrays; import java.util.Collections; @@ -28,42 +29,43 @@ public Api(String nodeUrl, boolean isDebug) { rpcService = new RpcService(nodeUrl, isDebug); } - public Block getBlock(String blockHash) { + public Block getBlock(String blockHash) throws IOException { return rpcService.post("get_block", Collections.singletonList(blockHash), Block.class); } - public Block getBlockByNumber(String blockNumber) { + public Block getBlockByNumber(String blockNumber) throws IOException { return rpcService.post( "get_block_by_number", Collections.singletonList(Numeric.toHexString(blockNumber)), Block.class); } - public TransactionWithStatus getTransaction(String transactionHash) { + public TransactionWithStatus getTransaction(String transactionHash) throws IOException { return rpcService.post( "get_transaction", Collections.singletonList(transactionHash), TransactionWithStatus.class); } - public String getBlockHash(String blockNumber) { + public String getBlockHash(String blockNumber) throws IOException { return rpcService.post( "get_block_hash", Collections.singletonList(Numeric.toHexString(blockNumber)), String.class); } - public CellbaseOutputCapacity getCellbaseOutputCapacityDetails(String blockHash) { + public CellbaseOutputCapacity getCellbaseOutputCapacityDetails(String blockHash) + throws IOException { return rpcService.post( "get_cellbase_output_capacity_details", Collections.singletonList(blockHash), CellbaseOutputCapacity.class); } - public Header getTipHeader() { + public Header getTipHeader() throws IOException { return rpcService.post("get_tip_header", Collections.emptyList(), Header.class); } public List getCellsByLockHash( - String lockHash, String fromBlockNumber, String toBlockNumber) { + String lockHash, String fromBlockNumber, String toBlockNumber) throws IOException { return rpcService.post( "get_cells_by_lock_hash", Arrays.asList( @@ -71,35 +73,35 @@ public List getCellsByLockHash( new TypeToken>() {}.getType()); } - public CellWithStatus getLiveCell(OutPoint outPoint, boolean withData) { + public CellWithStatus getLiveCell(OutPoint outPoint, boolean withData) throws IOException { return rpcService.post( "get_live_cell", Arrays.asList(Convert.parseOutPoint(outPoint), withData), CellWithStatus.class); } - public BigInteger getTipBlockNumber() { + public BigInteger getTipBlockNumber() throws IOException { String blockNumber = rpcService.post("get_tip_block_number", Collections.emptyList(), String.class); return Numeric.toBigInt(blockNumber); } - public Epoch getCurrentEpoch() { + public Epoch getCurrentEpoch() throws IOException { return rpcService.post("get_current_epoch", Collections.emptyList(), Epoch.class); } - public Epoch getEpochByNumber(String epochNumber) { + public Epoch getEpochByNumber(String epochNumber) throws IOException { return rpcService.post( "get_epoch_by_number", Collections.singletonList(Numeric.toHexString(epochNumber)), Epoch.class); } - public Header getHeader(String blockHash) { + public Header getHeader(String blockHash) throws IOException { return rpcService.post("get_header", Collections.singletonList(blockHash), Header.class); } - public Header getHeaderByNumber(String blockNumber) { + public Header getHeaderByNumber(String blockNumber) throws IOException { return rpcService.post( "get_header_by_number", Collections.singletonList(Numeric.toHexString(blockNumber)), @@ -107,20 +109,20 @@ public Header getHeaderByNumber(String blockNumber) { } /** Stats RPC */ - public BlockchainInfo getBlockchainInfo() { + public BlockchainInfo getBlockchainInfo() throws IOException { return rpcService.post("get_blockchain_info", Collections.emptyList(), BlockchainInfo.class); } - public List getPeersState() { + public List getPeersState() throws IOException { return rpcService.post( "get_peers_state", Collections.emptyList(), new TypeToken>() {}.getType()); } - public String setBan(BannedAddress bannedAddress) { + public String setBan(BannedAddress bannedAddress) throws IOException { return rpcService.post("set_ban", Collections.singletonList(bannedAddress), String.class); } - public List getBannedAddress() { + public List getBannedAddress() throws IOException { return rpcService.post( "get_banned_address", Collections.emptyList(), @@ -128,11 +130,11 @@ public List getBannedAddress() { } /** Pool RPC */ - public TxPoolInfo txPoolInfo() { + public TxPoolInfo txPoolInfo() throws IOException { return rpcService.post("tx_pool_info", Collections.emptyList(), TxPoolInfo.class); } - public String sendTransaction(Transaction transaction) { + public String sendTransaction(Transaction transaction) throws IOException { return rpcService.post( "send_transaction", Collections.singletonList(Convert.parseTransaction(transaction)), @@ -140,56 +142,56 @@ public String sendTransaction(Transaction transaction) { } /** Net RPC */ - public NodeInfo localNodeInfo() { + public NodeInfo localNodeInfo() throws IOException { return rpcService.post("local_node_info", Collections.emptyList(), NodeInfo.class); } - public List getPeers() { + public List getPeers() throws IOException { return rpcService.post( "get_peers", Collections.emptyList(), new TypeToken>() {}.getType()); } /** Experiment RPC */ - public Cycles dryRunTransaction(Transaction transaction) { + public Cycles dryRunTransaction(Transaction transaction) throws IOException { return rpcService.post( "dry_run_transaction", Collections.singletonList(Convert.parseTransaction(transaction)), Cycles.class); } - public String computeTransactionHash(Transaction transaction) { + public String computeTransactionHash(Transaction transaction) throws IOException { return rpcService.post( "_compute_transaction_hash", Collections.singletonList(Convert.parseTransaction(transaction)), String.class); } - public String computeScriptHash(Script script) { + public String computeScriptHash(Script script) throws IOException { return rpcService.post("_compute_script_hash", Collections.singletonList(script), String.class); } /* Indexer RPC */ - public LockHashIndexState indexLockHash(String lockHash) { + public LockHashIndexState indexLockHash(String lockHash) throws IOException { return rpcService.post( "index_lock_hash", Collections.singletonList(lockHash), LockHashIndexState.class); } - public LockHashIndexState indexLockHash(String lockHash, String indexFrom) { + public LockHashIndexState indexLockHash(String lockHash, String indexFrom) throws IOException { return rpcService.post( "index_lock_hash", Arrays.asList(lockHash, Numeric.toHexString(indexFrom)), LockHashIndexState.class); } - public List deindexLockHash(String lockHash) { + public List deindexLockHash(String lockHash) throws IOException { return rpcService.post( "deindex_lock_hash", Collections.singletonList(lockHash), new TypeToken>() {}.getType()); } - public List getLockHashIndexStates() { + public List getLockHashIndexStates() throws IOException { return rpcService.post( "get_lock_hash_index_states", Collections.emptyList(), @@ -197,7 +199,7 @@ public List getLockHashIndexStates() { } public List getLiveCellsByLockHash( - String lockHash, String page, String pageSize, boolean reverseOrder) { + String lockHash, String page, String pageSize, boolean reverseOrder) throws IOException { return rpcService.post( "get_live_cells_by_lock_hash", Arrays.asList( @@ -206,7 +208,7 @@ public List getLiveCellsByLockHash( } public List getTransactionsByLockHash( - String lockHash, String page, String pageSize, boolean reverseOrder) { + String lockHash, String page, String pageSize, boolean reverseOrder) throws IOException { return rpcService.post( "get_transactions_by_lock_hash", Arrays.asList( diff --git a/core/src/main/java/org/nervos/ckb/service/RpcService.java b/core/src/main/java/org/nervos/ckb/service/RpcService.java index e1e13a421..ce36aca49 100644 --- a/core/src/main/java/org/nervos/ckb/service/RpcService.java +++ b/core/src/main/java/org/nervos/ckb/service/RpcService.java @@ -34,35 +34,30 @@ class RpcService { gson = new Gson(); } - T post(@NotNull String method, List params, Type cls) { + T post(@NotNull String method, List params, Type cls) throws IOException { RequestParams requestParams = new RequestParams(method, params); RequestBody body = RequestBody.create(gson.toJson(requestParams), JSON_MEDIA_TYPE); Request request = new Request.Builder().url(url).post(body).build(); - try { - Response response = client.newCall(request).execute(); - if (response.isSuccessful()) { - String responseBody = response.body().string(); - RpcResponse rpcResponse = - gson.fromJson(responseBody, new TypeToken() {}.getType()); + Response response = client.newCall(request).execute(); + if (response.isSuccessful()) { + String responseBody = response.body().string(); + RpcResponse rpcResponse = + gson.fromJson(responseBody, new TypeToken() {}.getType()); - if (rpcResponse.error != null) { - throw new IOException( - "RpcService method " + method + " error " + gson.toJson(rpcResponse.error)); - } + if (rpcResponse.error != null) { + throw new IOException( + "RpcService method " + method + " error " + gson.toJson(rpcResponse.error)); + } - JsonElement jsonElement = - new JsonParser().parse(responseBody).getAsJsonObject().get("result"); - if (jsonElement.isJsonObject()) { - return gson.fromJson(jsonElement.getAsJsonObject(), cls); - } - return gson.fromJson(jsonElement, cls); - } else { - throw new IOException("RpcService method " + method + " error code " + response.code()); + JsonElement jsonElement = + new JsonParser().parse(responseBody).getAsJsonObject().get("result"); + if (jsonElement.isJsonObject()) { + return gson.fromJson(jsonElement.getAsJsonObject(), cls); } - } catch (Exception e) { - e.printStackTrace(); + return gson.fromJson(jsonElement, cls); + } else { + throw new IOException("RpcService method " + method + " error code " + response.code()); } - return null; } void postAsync( diff --git a/core/src/main/java/org/nervos/ckb/transaction/CellCollector.java b/core/src/main/java/org/nervos/ckb/transaction/CellCollector.java index cbf689c21..709ff6d91 100644 --- a/core/src/main/java/org/nervos/ckb/transaction/CellCollector.java +++ b/core/src/main/java/org/nervos/ckb/transaction/CellCollector.java @@ -20,7 +20,7 @@ public CellCollector(Api api) { this.api = api; } - public CollectedCells getCellInputs(String lockHash, BigInteger needCapacity) { + public CollectedCells getCellInputs(String lockHash, BigInteger needCapacity) throws IOException { List cellInputs = new ArrayList<>(); BigInteger inputsCapacity = BigInteger.ZERO; long toBlockNumber = api.getTipBlockNumber().longValue(); @@ -55,7 +55,7 @@ public BigInteger getCapacityWithAddress(String address) throws IOException { return getCapacityWithLockHash(lockScript.computeHash()); } - public BigInteger getCapacityWithLockHash(String lockHash) { + public BigInteger getCapacityWithLockHash(String lockHash) throws IOException { BigInteger capacity = BigInteger.ZERO; long toBlockNumber = api.getTipBlockNumber().longValue(); long fromBlockNumber = 1; diff --git a/core/src/test/java/service/ApiTest.java b/core/src/test/java/service/ApiTest.java index ab1b3121b..aefa29783 100644 --- a/core/src/test/java/service/ApiTest.java +++ b/core/src/test/java/service/ApiTest.java @@ -1,5 +1,6 @@ package service; +import java.io.IOException; import java.math.BigInteger; import java.util.Collections; import java.util.List; @@ -25,26 +26,26 @@ public void init() { } @Test - public void testGetBlockByNumber() { + public void testGetBlockByNumber() throws IOException { Block block = api.getBlockByNumber("0x1"); Assertions.assertNotNull(block); } @Test - public void testGetBlockHashByNumber() { + public void testGetBlockHashByNumber() throws IOException { String blockHash = api.getBlockHash("0x1"); Assertions.assertNotNull(blockHash); } @Test - public void testGetCellbaseOutputCapacityDetails() { + public void testGetCellbaseOutputCapacityDetails() throws IOException { String blockHash = api.getBlockHash("0x1"); CellbaseOutputCapacity cellbaseOutputCapacity = api.getCellbaseOutputCapacityDetails(blockHash); Assertions.assertNotNull(cellbaseOutputCapacity); } @Test - public void testBlockAndTransaction() { + public void testBlockAndTransaction() throws IOException { String blockHash = api.getBlockHash("0x1"); Block block = api.getBlock(blockHash); Assertions.assertNotNull(block); @@ -52,63 +53,63 @@ public void testBlockAndTransaction() { } @Test - public void testTransaction() { + public void testTransaction() throws IOException { String transactionHash = api.getBlockByNumber("0x1").transactions.get(0).hash; Transaction transaction = api.getTransaction(transactionHash).transaction; Assertions.assertNotNull(transaction); } @Test - public void testGetTipHeader() { + public void testGetTipHeader() throws IOException { Header header = api.getTipHeader(); Assertions.assertNotNull(header); } @Test - public void testGetTipBlockNumber() { + public void testGetTipBlockNumber() throws IOException { BigInteger blockNumber = api.getTipBlockNumber(); Assertions.assertNotNull(blockNumber.toString()); } @Test - public void testGetCurrentEpoch() { + public void testGetCurrentEpoch() throws IOException { Epoch epoch = api.getCurrentEpoch(); Assertions.assertNotNull(epoch); } @Test - public void testGetEpochByNumber() { + public void testGetEpochByNumber() throws IOException { Epoch epoch = api.getEpochByNumber("0"); Assertions.assertNotNull(epoch); } @Test - public void testGetHeader() { + public void testGetHeader() throws IOException { String blockHash = api.getBlockHash("0x1"); Header header = api.getHeader(blockHash); Assertions.assertNotNull(header); } @Test - public void testGetHeaderByNumber() { + public void testGetHeaderByNumber() throws IOException { Header header = api.getHeaderByNumber("0x1"); Assertions.assertNotNull(header); } @Test - public void localNodeInfo() { + public void localNodeInfo() throws IOException { NodeInfo nodeInfo = api.localNodeInfo(); Assertions.assertNotNull(nodeInfo); } @Test - public void getPeers() { + public void getPeers() throws IOException { List peers = api.getPeers(); Assertions.assertNotNull(peers); } @Test - public void testSetBan() { + public void testSetBan() throws IOException { BannedAddress bannedAddress = new BannedAddress("192.168.0.2", "insert", "1840546800000", true, "test set_ban rpc"); String banResult = api.setBan(bannedAddress); @@ -116,31 +117,31 @@ public void testSetBan() { } @Test - public void testGetBannedAddress() { + public void testGetBannedAddress() throws IOException { List bannedAddresses = api.getBannedAddress(); Assertions.assertNotNull(bannedAddresses); } @Test - public void txPoolInfo() { + public void txPoolInfo() throws IOException { TxPoolInfo txPoolInfo = api.txPoolInfo(); Assertions.assertNotNull(txPoolInfo); } @Test - public void testGetBlockchainInfo() { + public void testGetBlockchainInfo() throws IOException { BlockchainInfo blockchainInfo = api.getBlockchainInfo(); Assertions.assertNotNull(blockchainInfo); } @Test - public void testGetPeersState() { + public void testGetPeersState() throws IOException { List peerStates = api.getPeersState(); Assertions.assertNotNull(peerStates); } @Test - public void testGetCellsByLockHash() { + public void testGetCellsByLockHash() throws IOException { List cellOutputWithOutPoints = api.getCellsByLockHash( "0xecaeea8c8581d08a3b52980272001dbf203bc6fa2afcabe7cc90cc2afff488ba", "0", "100"); @@ -148,7 +149,7 @@ public void testGetCellsByLockHash() { } @Test - public void testGetLiveCell() { + public void testGetLiveCell() throws IOException { CellWithStatus cellWithStatus = api.getLiveCell( new OutPoint("0xde7ac423660b95df1fd8879a54a98020bcbb30fc9bfcf13da757e99b30effd8d", "0"), @@ -157,7 +158,7 @@ public void testGetLiveCell() { } @Test - public void testGetLiveCellWithData() { + public void testGetLiveCellWithData() throws IOException { CellWithStatus cellWithStatus = api.getLiveCell( new OutPoint("0xde7ac423660b95df1fd8879a54a98020bcbb30fc9bfcf13da757e99b30effd8d", "0"), @@ -166,7 +167,7 @@ public void testGetLiveCellWithData() { } @Test - public void testGetLiveCellWithoutData() { + public void testGetLiveCellWithoutData() throws IOException { CellWithStatus cellWithStatus = api.getLiveCell( new OutPoint("0xde7ac423660b95df1fd8879a54a98020bcbb30fc9bfcf13da757e99b30effd8d", "0"), @@ -175,7 +176,7 @@ public void testGetLiveCellWithoutData() { } @Test - public void testSendTransaction() { + public void testSendTransaction() throws IOException { String transactionHash = api.sendTransaction( new Transaction( @@ -190,7 +191,7 @@ public void testSendTransaction() { } @Test - public void testDryRunTransaction() { + public void testDryRunTransaction() throws IOException { Cycles cycles = api.dryRunTransaction( new Transaction( @@ -205,7 +206,7 @@ public void testDryRunTransaction() { } @Test - public void testComputeTransactionHash() { + public void testComputeTransactionHash() throws IOException { String transactionHash = api.computeTransactionHash( new Transaction( @@ -220,14 +221,14 @@ public void testComputeTransactionHash() { } @Test - public void testIndexLockHash() { + public void testIndexLockHash() throws IOException { LockHashIndexState lockHashIndexState = api.indexLockHash("0x59d90b1718471f5802de59501604100a5e3b463865cdfe56fa70ed23865ee32e"); Assertions.assertNotNull(lockHashIndexState); } @Test - public void testIndexLockHashWithBlockNumber() { + public void testIndexLockHashWithBlockNumber() throws IOException { LockHashIndexState lockHashIndexState = api.indexLockHash( "0x59d90b1718471f5802de59501604100a5e3b463865cdfe56fa70ed23865ee32e", "0"); @@ -235,20 +236,20 @@ public void testIndexLockHashWithBlockNumber() { } @Test - public void testDeindexLockHash() { + public void testDeindexLockHash() throws IOException { List lockHashs = api.deindexLockHash("0x59d90b1718471f5802de59501604100a5e3b463865cdfe56fa70ed23865ee32e"); Assertions.assertNull(lockHashs); } @Test - public void testGetLockHashIndexStates() { + public void testGetLockHashIndexStates() throws IOException { List lockHashIndexStates = api.getLockHashIndexStates(); Assertions.assertNotNull(lockHashIndexStates); } @Test - public void testGetLiveCellsByLockHash() { + public void testGetLiveCellsByLockHash() throws IOException { List liveCells = api.getLiveCellsByLockHash( "0xecaeea8c8581d08a3b52980272001dbf203bc6fa2afcabe7cc90cc2afff488ba", @@ -259,7 +260,7 @@ public void testGetLiveCellsByLockHash() { } @Test - public void testGetTransactionsByLockHash() { + public void testGetTransactionsByLockHash() throws IOException { List cellTransactions = api.getTransactionsByLockHash( "0xecaeea8c8581d08a3b52980272001dbf203bc6fa2afcabe7cc90cc2afff488ba", diff --git a/core/src/test/java/type/ScriptTest.java b/core/src/test/java/type/ScriptTest.java index 90c22e4c7..c9e333149 100644 --- a/core/src/test/java/type/ScriptTest.java +++ b/core/src/test/java/type/ScriptTest.java @@ -1,5 +1,6 @@ package type; +import java.io.IOException; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; @@ -12,7 +13,7 @@ public class ScriptTest { @Test - public void testScriptHashWithCodeHash() { + public void testScriptHashWithCodeHash() throws IOException { Api api = new Api("http://localhost:8114"); String codeHash = Hash.blake2b( diff --git a/core/src/test/java/type/TransactionTest.java b/core/src/test/java/type/TransactionTest.java index 5dc752701..e041f10e6 100644 --- a/core/src/test/java/type/TransactionTest.java +++ b/core/src/test/java/type/TransactionTest.java @@ -1,5 +1,6 @@ package type; +import java.io.IOException; import java.math.BigInteger; import java.util.ArrayList; import java.util.Arrays; @@ -200,7 +201,7 @@ public void serializationTest() { @Disabled @Test - public void serializationTxTest() { + public void serializationTxTest() throws IOException { Api api = new Api("http://localhost:8114"); Transaction transaction = api.getBlockByNumber("1").transactions.get(0); Assertions.assertEquals(api.computeTransactionHash(transaction), transaction.computeHash());