From 4a7a57c06ef1d2970cc90a70acb1358f7b21da09 Mon Sep 17 00:00:00 2001 From: Nex Date: Wed, 12 Sep 2018 10:10:41 +0800 Subject: [PATCH] Update sample test code --- src/test/java/bdchain/api/Test.java | 60 ++++++++++++++++++++++++++--- 1 file changed, 54 insertions(+), 6 deletions(-) diff --git a/src/test/java/bdchain/api/Test.java b/src/test/java/bdchain/api/Test.java index 409b196..85ab91b 100644 --- a/src/test/java/bdchain/api/Test.java +++ b/src/test/java/bdchain/api/Test.java @@ -3,13 +3,56 @@ package bdchain.api; import bdchain.api.grpc.GetLedgersResponse; import bdchain.api.grpc.TransactionType; -public class Test { - public static void main(String[] args) throws InterruptedException { +import java.util.concurrent.ExecutionException; - final String ledger = "test"; - final int block_number = 1; - final String block_hash = "0x0"; - final int index = 0; +public class Test { + + static final String ledger = "test"; + static final int block_number = 1; + static final String block_hash = "0x0"; + static final int index = 0; + + private static void testFutureApi() throws InterruptedException { + + TransactionLedgerClient tlClient = new TransactionLedgerClient("localhost", 8004); + try { + System.out.println(tlClient.createLedger(ledger).get().getOk()); + GetLedgersResponse r = tlClient.getLedgers().get(); + for (int i = 0; i < r.getLedgersCount(); i++) { + System.out.println(r.getLedgers(i)); + } + System.out.println( + tlClient + .sendTransaction(ledger, TransactionType.RECORD, "0x0", "0x1", "data".getBytes()) + .get() + .getHash()); + } catch (ExecutionException e) { + e.printStackTrace(); + } + tlClient.shutdown(); + + AccountingChainClient acClient = new AccountingChainClient("localhost", 8013); + try { + System.out.println(acClient.blockNumber(ledger).get().getBlockNumber()); + System.out.println(acClient.getBlockByNumber(ledger, block_number, false).get().toString()); + System.out.println(acClient.getBlockByNumber(ledger, block_number, true).get().toString()); + System.out.println(acClient.getBlockByHash(ledger, block_hash, false).get().toString()); + System.out.println(acClient.getBlockByHash(ledger, block_hash, true).get().toString()); + System.out.println(acClient.getTransactionByHash(ledger, "0x0").get().toString()); + System.out.println( + acClient + .getTransactionByBlockNumberAndIndex(ledger, block_number, index) + .get() + .toString()); + System.out.println( + acClient.getTransactionByBlockHashAndIndex(ledger, block_hash, index).get().toString()); + } catch (ExecutionException e) { + e.printStackTrace(); + } + acClient.shutdown(); + } + + private static void testSyncApi() throws InterruptedException { TransactionLedgerClient tlClient = new TransactionLedgerClient("localhost", 8004); System.out.println(tlClient.createLedgerSync(ledger).getOk()); @@ -36,4 +79,9 @@ public class Test { acClient.getTransactionByBlockHashAndIndexSync(ledger, block_hash, index).toString()); acClient.shutdown(); } + + public static void main(String[] args) throws InterruptedException { + testFutureApi(); + testSyncApi(); + } }