OSDN Git Service

modify Block class and add WalletTest MessageTest BlockTest
[bytom/bytom-java-sdk.git] / src / test / java / io / bytom / integration / BlockTest.java
1 package io.bytom.integration;
2
3 import io.bytom.TestUtils;
4 import io.bytom.api.Asset;
5 import io.bytom.api.Block;
6 import io.bytom.api.Wallet;
7 import io.bytom.exception.BytomException;
8 import io.bytom.http.Client;
9 import org.junit.Assert;
10 import org.junit.Test;
11
12 public class BlockTest {
13
14     static Client client;
15
16     static {
17         try {
18             client = TestUtils.generateClient();
19         } catch (BytomException e) {
20             e.printStackTrace();
21         }
22     }
23
24     static Block block;
25     static Block.BlockHeader blockHeader;
26     static Block.BlockDifficulty blockDifficulty;
27     static Block.BlockHashRate blockHashRate;
28
29     @Test
30     public void testBlockCountGet() throws Exception {
31         int count = Block.getBlockCount(client);
32         Assert.assertEquals(158, count);
33     }
34
35     @Test
36     public void testBlockHashGet() throws Exception {
37         String blockHash = Block.getBlockHash(client);
38         Assert.assertNotNull(blockHash);
39     }
40
41     @Test
42     public void testBlockGet() throws Exception {
43         int height = Block.getBlockCount(client);
44         String blockHash = Block.getBlockHash(client);
45
46         block = new Block.QueryBuilder()
47                 .setBlockHeight(height)
48                 .setBlockHash(blockHash)
49                 .getBlock(client);
50     }
51
52     @Test
53     public void testBlockHeader() throws Exception {
54         int height = Block.getBlockCount(client);
55         String blockHash = Block.getBlockHash(client);
56
57         blockHeader = new Block.QueryBuilder()
58                 .setBlockHeight(height)
59                 .setBlockHash(blockHash)
60                 .getBlockHeader(client);
61     }
62
63     @Test
64     public void testBlockDifficulty() throws Exception {
65         int height = Block.getBlockCount(client);
66         String blockHash = Block.getBlockHash(client);
67
68         blockDifficulty = new Block.QueryBuilder()
69                 .setBlockHeight(height)
70                 .setBlockHash(blockHash)
71                 .getBlockDifficulty(client);
72     }
73
74     @Test
75     public void testBlockHashRate() throws Exception {
76         int height = Block.getBlockCount(client);
77         String blockHash = Block.getBlockHash(client);
78
79         blockHashRate = new Block.QueryBuilder()
80                 .setBlockHeight(height)
81                 .setBlockHash(blockHash)
82                 .getHashRate(client);
83     }
84
85 }