Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions chainbase/src/main/java/org/tron/core/store/AccountStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.tron.core.capsule.BlockCapsule;
import org.tron.core.db.TronStoreWithRevoking;
import org.tron.core.db.accountstate.AccountStateCallBackUtils;
import org.tron.core.exception.TronError;
import org.tron.protos.contract.BalanceContract.TransactionBalanceTrace;
import org.tron.protos.contract.BalanceContract.TransactionBalanceTrace.Operation;

Expand All @@ -23,6 +24,8 @@
@Component
public class AccountStore extends TronStoreWithRevoking<AccountCapsule> {

private static String ACCOUNT_BLACKHOLE = "Blackhole";

private static Map<String, byte[]> assertsAddress = new HashMap<>(); // key = name , value = address

@Autowired
Expand Down Expand Up @@ -50,6 +53,9 @@ public static void setAccount(com.typesafe.config.Config config) {
byte[] address = Commons.decodeFromBase58Check(obj.get("address").unwrapped().toString());
assertsAddress.put(accountName, address);
}
if (assertsAddress.get(ACCOUNT_BLACKHOLE) == null) {
throw new TronError("Account[Blackhole] is not configured.", TronError.ErrCode.GENESIS_BLOCK_INIT);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use ACCOUNT_BLACKHOLE instead of Blackhole?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because this process occurs when the genesis block is being initialized

}
}

@Override
Expand Down Expand Up @@ -109,12 +115,12 @@ public AccountCapsule getSun() {
* Min TRX account.
*/
public AccountCapsule getBlackhole() {
return getUnchecked(assertsAddress.get("Blackhole"));
return getUnchecked(assertsAddress.get(ACCOUNT_BLACKHOLE));
}


public byte[] getBlackholeAddress() {
return assertsAddress.get("Blackhole");
return assertsAddress.get(ACCOUNT_BLACKHOLE);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion common/src/main/java/org/tron/common/exit/ExitManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static Optional<TronError> findTronError(Throwable e) {

public static void logAndExit(TronError exit) {
final int code = exit.getErrCode().getCode();
logger.error("Shutting down with code: {}.", exit.getErrCode(), exit);
logger.error("Shutting down with code: {}, reason: {}", exit.getErrCode(), exit.getMessage());
Thread exitThread = exitThreadFactory.newThread(() -> System.exit(code));
exitThread.start();
}
Expand Down
24 changes: 24 additions & 0 deletions framework/src/test/java/org/tron/core/db/AccountStoreTest.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
package org.tron.core.db;

import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;

import com.google.protobuf.ByteString;
import com.typesafe.config.Config;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
import org.tron.common.BaseTest;
import org.tron.common.utils.ByteArray;
import org.tron.core.Constant;
import org.tron.core.capsule.AccountCapsule;
import org.tron.core.config.args.Args;
import org.tron.core.db2.ISession;
import org.tron.core.exception.TronError;
import org.tron.core.net.peer.PeerManager;
import org.tron.core.store.AccountStore;
import org.tron.core.store.AssetIssueStore;
import org.tron.core.store.DynamicPropertiesStore;
Expand Down Expand Up @@ -61,6 +70,21 @@ public void init() {
init = true;
}

@Test
public void setAccountTest() throws Exception {
Field field = AccountStore.class.getDeclaredField("assertsAddress");
field.setAccessible(true);
field.set(AccountStore.class, new HashMap<>());
Config config = mock(Config.class);
Mockito.when(config.getObjectList("genesis.block.assets")).thenReturn(new ArrayList<>());
try {
AccountStore.setAccount(config);
Assert.fail();
} catch (Throwable e) {
Assert.assertTrue(e instanceof TronError);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add Assert.assertEquals("Account[Blackhole] is not configured.", e.getMessage());?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is enough to judge the exception type, which is mainly functional testing rather than specific log information comparison.

}
}

@Test
public void get() {
//test get and has Method
Expand Down