/
ChannelTest.java
70 lines (52 loc) · 1.42 KB
/
ChannelTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package channels;
import com.google.protobuf.ByteString;
import duckutil.ConfigMem;
import java.io.File;
import java.util.Random;
import java.util.TreeMap;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import snowblossom.channels.*;
import snowblossom.channels.proto.*;
import snowblossom.lib.Globals;
public class ChannelTest
{
@Rule
public TemporaryFolder test_folder = new TemporaryFolder();
@BeforeClass
public static void loadProvider()
{
Globals.addCryptoProvider();
}
@Test
public void testChannelDB()
throws Exception
{
ChannelNode node_a = startNode();
Random rnd = new Random();
byte[] buff = new byte[20];
for(int i=0; i<100; i++)
{
rnd.nextBytes(buff);
ChannelID cid = new ChannelID(ByteString.copyFrom(buff));
node_a.getChannelDB(cid);
}
// Give the DB a few seconds to settle
Thread.sleep(5000);
}
private ChannelNode startNode()
throws Exception
{
File base_dir = test_folder.newFolder();
TreeMap<String,String> map = new TreeMap<>();
map.put("key_count", "1");
map.put("db_path", new File(base_dir, "db").getPath());
map.put("wallet_path", new File(base_dir, "wallet").getPath());
Random rnd = new Random();
int port = rnd.nextInt(30000) + 10240;
map.put("port", "" + port);
return new ChannelNode(new ConfigMem(map));
}
}