Skip to content

Commit 1e3200c

Browse files
authored
Merge pull request #327 from tronprotocol/feature/unittest
Feature/unittest
2 parents 168b418 + 6399899 commit 1e3200c

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package org.tron.core.db;
2+
3+
import com.google.protobuf.ByteString;
4+
import java.io.File;
5+
import org.junit.AfterClass;
6+
import org.junit.Assert;
7+
import org.junit.BeforeClass;
8+
import org.junit.Test;
9+
import org.tron.common.utils.ByteArray;
10+
import org.tron.common.utils.FileUtil;
11+
import org.tron.core.Constant;
12+
import org.tron.core.capsule.AccountCapsule;
13+
import org.tron.core.config.Configuration;
14+
import org.tron.core.config.args.Args;
15+
import org.tron.protos.Protocol.AccountType;
16+
17+
public class AccountStoreTest {
18+
19+
private static String dbPath = "output_AccountStore_test";
20+
private static AccountStore AccountStoreTest;
21+
private static final byte[] data = TransactionStoreTest.randomBytes(32);
22+
private static byte[] address = TransactionStoreTest.randomBytes(32);
23+
private static byte[] accountName = TransactionStoreTest.randomBytes(32);
24+
25+
@AfterClass
26+
public static void destroy() {
27+
Args.clearParam();
28+
FileUtil.deleteDir(new File(dbPath));
29+
}
30+
31+
@BeforeClass
32+
public static void init() {
33+
Args.setParam(new String[]{"-d", dbPath, "-w"},
34+
Configuration.getByPath(Constant.TEST_CONF));
35+
AccountStoreTest = AccountStore.create(dbPath);
36+
AccountCapsule accountCapsule = new AccountCapsule(ByteString.copyFrom(address),
37+
ByteString.copyFrom(accountName),
38+
AccountType.forNumber(1));
39+
AccountStoreTest.put(data, accountCapsule);
40+
}
41+
42+
@Test
43+
public void get() {
44+
//test get and has Method
45+
Assert
46+
.assertEquals(ByteArray.toHexString(address), ByteArray
47+
.toHexString(AccountStoreTest.get(data).getInstance().getAddress().toByteArray()))
48+
;
49+
Assert
50+
.assertEquals(ByteArray.toHexString(accountName), ByteArray
51+
.toHexString(AccountStoreTest.get(data).getInstance().getAccountName().toByteArray()))
52+
;
53+
Assert.assertTrue(AccountStoreTest.has(data));
54+
}
55+
}

0 commit comments

Comments
 (0)