Update sample test code

This commit is contained in:
Nex 2018-09-12 10:10:41 +08:00
parent 5a76d9114b
commit 4a7a57c06e

View File

@ -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();
}
}