Skip to content

Commit

Permalink
Merge pull request #327 from tronprotocol/feature/unittest
Browse files Browse the repository at this point in the history
Feature/unittest
  • Loading branch information
zhaohong authored Mar 30, 2018
2 parents 168b418 + 6399899 commit 1e3200c
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions src/test/java/org/tron/core/db/AccountStoreTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
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.utils.ByteArray;
import org.tron.common.utils.FileUtil;
import org.tron.core.Constant;
import org.tron.core.capsule.AccountCapsule;
import org.tron.core.config.Configuration;
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 AccountStore AccountStoreTest;
private static final byte[] data = TransactionStoreTest.randomBytes(32);
private static byte[] address = TransactionStoreTest.randomBytes(32);
private static byte[] accountName = TransactionStoreTest.randomBytes(32);

@AfterClass
public static void destroy() {
Args.clearParam();
FileUtil.deleteDir(new File(dbPath));
}

@BeforeClass
public static void init() {
Args.setParam(new String[]{"-d", dbPath, "-w"},
Configuration.getByPath(Constant.TEST_CONF));
AccountStoreTest = AccountStore.create(dbPath);
AccountCapsule accountCapsule = new AccountCapsule(ByteString.copyFrom(address),
ByteString.copyFrom(accountName),
AccountType.forNumber(1));
AccountStoreTest.put(data, accountCapsule);
}

@Test
public void get() {
//test get and has Method
Assert
.assertEquals(ByteArray.toHexString(address), ByteArray
.toHexString(AccountStoreTest.get(data).getInstance().getAddress().toByteArray()))
;
Assert
.assertEquals(ByteArray.toHexString(accountName), ByteArray
.toHexString(AccountStoreTest.get(data).getInstance().getAccountName().toByteArray()))
;
Assert.assertTrue(AccountStoreTest.has(data));
}
}

0 comments on commit 1e3200c

Please sign in to comment.