Repository navigation
Expand file tree
/
Copy pathAccountStoreTest.java
More file actions
executable file
·72 lines (63 loc) · 2.25 KB
/
Copy pathAccountStoreTest.java
File metadata and controls
executable file
·72 lines (63 loc) · 2.25 KB
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
71
72
package org.tron.core.db;
import com.google.protobuf.ByteString;
import java.io.File;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.tron.common.application.TronApplicationContext;
import org.tron.common.utils.ByteArray;
import org.tron.common.utils.FileUtil;
import org.tron.core.Constant;
import org.tron.core.capsule.AccountCapsule;
import org.tron.core.config.DefaultConfig;
import org.tron.core.config.args.Args;
import org.tron.protos.Protocol.AccountType;
public class AccountStoreTest {
private static String dbPath = "output_AccountStore_test";
private static String dbDirectory = "db_AccountStore_test";
private static String indexDirectory = "index_AccountStore_test";
private static TronApplicationContext context;
private static AccountStore accountStore;
private static final byte[] data = TransactionStoreTest.randomBytes(32);
private static byte[] address = TransactionStoreTest.randomBytes(32);
private static byte[] accountName = TransactionStoreTest.randomBytes(32);
static {
Args.setParam(
new String[]{
"--output-directory", dbPath,
"--storage-db-directory", dbDirectory,
"--storage-index-directory", indexDirectory
},
Constant.TEST_CONF
);
context = new TronApplicationContext(DefaultConfig.class);
}
@AfterClass
public static void destroy() {
Args.clearParam();
context.destroy();
FileUtil.deleteDir(new File(dbPath));
}
@BeforeClass
public static void init() {
accountStore = context.getBean(AccountStore.class);
AccountCapsule accountCapsule = new AccountCapsule(ByteString.copyFrom(address),
ByteString.copyFrom(accountName),
AccountType.forNumber(1));
accountStore.put(data, accountCapsule);
}
@Test
public void get() {
//test get and has Method
Assert
.assertEquals(ByteArray.toHexString(address), ByteArray
.toHexString(accountStore.get(data).getInstance().getAddress().toByteArray()))
;
Assert
.assertEquals(ByteArray.toHexString(accountName), ByteArray
.toHexString(accountStore.get(data).getInstance().getAccountName().toByteArray()))
;
Assert.assertTrue(accountStore.has(data));
}
}