Browse Source

Fixed error of testcase;

tags/1.0.1
huanghaiquan 5 years ago
parent
commit
87ac6f8c9c
3 changed files with 23 additions and 19 deletions
  1. +3
    -3
      source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/impl/TransactionBatchProcessor.java
  2. +15
    -11
      source/ledger/ledger-core/src/test/java/test/com/jd/blockchain/ledger/LedgerTestUtils.java
  3. +5
    -5
      source/ledger/ledger-core/src/test/java/test/com/jd/blockchain/ledger/TransactionBatchProcessorTest.java

+ 3
- 3
source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/impl/TransactionBatchProcessor.java View File

@@ -103,7 +103,7 @@ public class TransactionBatchProcessor implements TransactionBatchProcess {
return resp; return resp;
} }


LOGGER.debug("Start handling transaction... --[BlockHeight=%s][RequestHash=%s][TxHash=%s]",
LOGGER.debug("Start handling transaction... --[BlockHeight={}][RequestHash={}][TxHash={}]",
newBlockEditor.getBlockHeight(), request.getHash(), request.getTransactionContent().getHash()); newBlockEditor.getBlockHeight(), request.getHash(), request.getTransactionContent().getHash());
// 创建交易上下文; // 创建交易上下文;
// 此调用将会验证交易签名,验签失败将会抛出异常,同时,不记录签名错误的交易到链上; // 此调用将会验证交易签名,验签失败将会抛出异常,同时,不记录签名错误的交易到链上;
@@ -112,7 +112,7 @@ public class TransactionBatchProcessor implements TransactionBatchProcess {
// 处理交易; // 处理交易;
resp = handleTx(request, txCtx); resp = handleTx(request, txCtx);
LOGGER.debug("Complete handling transaction. --[BlockHeight=%s][RequestHash=%s][TxHash=%s]",
LOGGER.debug("Complete handling transaction. --[BlockHeight={}][RequestHash={}][TxHash={}]",
newBlockEditor.getBlockHeight(), request.getHash(), request.getTransactionContent().getHash()); newBlockEditor.getBlockHeight(), request.getHash(), request.getTransactionContent().getHash());
responseList.add(resp); responseList.add(resp);
@@ -246,7 +246,7 @@ public class TransactionBatchProcessor implements TransactionBatchProcess {
TxResponseMessage resp = new TxResponseMessage(request.getTransactionContent().getHash()); TxResponseMessage resp = new TxResponseMessage(request.getTransactionContent().getHash());
resp.setExecutionState(txState); resp.setExecutionState(txState);


LOGGER.error("Discard transaction request! --[BlockHeight=%s][RequestHash=%s][TxHash=%s][ResponseState=%s]",
LOGGER.error("Discard transaction request! --[BlockHeight={}][RequestHash={}][TxHash={}][ResponseState={}]",
newBlockEditor.getBlockHeight(), request.getHash(), request.getTransactionContent().getHash(), newBlockEditor.getBlockHeight(), request.getHash(), request.getTransactionContent().getHash(),
resp.getExecutionState()); resp.getExecutionState());
return resp; return resp;


+ 15
- 11
source/ledger/ledger-core/src/test/java/test/com/jd/blockchain/ledger/LedgerTestUtils.java View File

@@ -84,14 +84,14 @@ public class LedgerTestUtils {
// public static TransactionRequest createTxRequest_UserReg(BlockchainKeypair userKeypair, HashDigest ledgerHash, BlockchainKeypair... partiKeys) { // public static TransactionRequest createTxRequest_UserReg(BlockchainKeypair userKeypair, HashDigest ledgerHash, BlockchainKeypair... partiKeys) {
// return createTxRequest_UserReg(userKeypair, ledgerHash, null, null); // return createTxRequest_UserReg(userKeypair, ledgerHash, null, null);
// } // }
public static TransactionRequest createLedgerInitTxRequest(BlockchainKeypair... participants) { public static TransactionRequest createLedgerInitTxRequest(BlockchainKeypair... participants) {
TxBuilder txBuilder = new TxBuilder(null); TxBuilder txBuilder = new TxBuilder(null);
for (BlockchainKeypair parti : participants) { for (BlockchainKeypair parti : participants) {
txBuilder.users().register(parti.getIdentity()); txBuilder.users().register(parti.getIdentity());
} }
TransactionRequestBuilder txReqBuilder = txBuilder.prepareRequest(); TransactionRequestBuilder txReqBuilder = txBuilder.prepareRequest();
for (BlockchainKeypair parti : participants) { for (BlockchainKeypair parti : participants) {
txReqBuilder.signAsNode(parti); txReqBuilder.signAsNode(parti);
@@ -100,11 +100,11 @@ public class LedgerTestUtils {
return txReqBuilder.buildRequest(); return txReqBuilder.buildRequest();
} }


public static TransactionRequest createTxRequest_UserReg(HashDigest ledgerHash,
BlockchainKeypair nodeKeypair, BlockchainKeypair... signers) {
return createTxRequest_UserReg(BlockchainKeyGenerator.getInstance().generate(), ledgerHash, nodeKeypair,
signers);
}
// public static TransactionRequest createTxRequest_UserReg(HashDigest ledgerHash, BlockchainKeypair nodeKeypair,
// BlockchainKeypair... signers) {
// return createTxRequest_UserReg(BlockchainKeyGenerator.getInstance().generate(), ledgerHash, nodeKeypair,
// signers);
// }


public static TransactionRequest createTxRequest_UserReg(BlockchainKeypair userKeypair, HashDigest ledgerHash, public static TransactionRequest createTxRequest_UserReg(BlockchainKeypair userKeypair, HashDigest ledgerHash,
BlockchainKeypair nodeKeypair, BlockchainKeypair... signers) { BlockchainKeypair nodeKeypair, BlockchainKeypair... signers) {
@@ -113,7 +113,11 @@ public class LedgerTestUtils {
txBuilder.users().register(userKeypair.getIdentity()); txBuilder.users().register(userKeypair.getIdentity());


TransactionRequestBuilder txReqBuilder = txBuilder.prepareRequest(); TransactionRequestBuilder txReqBuilder = txBuilder.prepareRequest();
txReqBuilder.signAsEndpoint(nodeKeypair);
if (signers != null) {
for (BlockchainKeypair signer : signers) {
txReqBuilder.signAsEndpoint(signer);
}
}
if (nodeKeypair != null) { if (nodeKeypair != null) {
txReqBuilder.signAsNode(nodeKeypair); txReqBuilder.signAsNode(nodeKeypair);
} }
@@ -121,8 +125,8 @@ public class LedgerTestUtils {
return txReqBuilder.buildRequest(); return txReqBuilder.buildRequest();
} }


public static TransactionRequest createTxRequest_MultiOPs_WithError(HashDigest ledgerHash,
BlockchainKeypair userKeypair, BlockchainKeypair nodeKeypair) {
public static TransactionRequest createTxRequest_MultiOPs_WithError(BlockchainKeypair userKeypair, HashDigest ledgerHash,
BlockchainKeypair nodeKeypair, BlockchainKeypair... signers) {
TxBuilder txBuilder = new TxBuilder(ledgerHash); TxBuilder txBuilder = new TxBuilder(ledgerHash);


txBuilder.users().register(userKeypair.getIdentity()); txBuilder.users().register(userKeypair.getIdentity());


+ 5
- 5
source/ledger/ledger-core/src/test/java/test/com/jd/blockchain/ledger/TransactionBatchProcessorTest.java View File

@@ -88,7 +88,7 @@ public class TransactionBatchProcessorTest {


// 注册新用户; // 注册新用户;
BlockchainKeypair userKeypair = BlockchainKeyGenerator.getInstance().generate(); BlockchainKeypair userKeypair = BlockchainKeyGenerator.getInstance().generate();
transactionRequest = LedgerTestUtils.createTxRequest_UserReg(ledgerHash, userKeypair, parti0);
transactionRequest = LedgerTestUtils.createTxRequest_UserReg(userKeypair, ledgerHash, parti0, parti0);
TransactionResponse txResp = txbatchProcessor.schedule(transactionRequest); TransactionResponse txResp = txbatchProcessor.schedule(transactionRequest);


LedgerBlock newBlock = newBlockEditor.prepare(); LedgerBlock newBlock = newBlockEditor.prepare();
@@ -132,7 +132,7 @@ public class TransactionBatchProcessorTest {


// 注册新用户; // 注册新用户;
BlockchainKeypair userKeypair1 = BlockchainKeyGenerator.getInstance().generate(); BlockchainKeypair userKeypair1 = BlockchainKeyGenerator.getInstance().generate();
transactionRequest = LedgerTestUtils.createTxRequest_UserReg(ledgerHash, userKeypair1, parti0);
transactionRequest = LedgerTestUtils.createTxRequest_UserReg(userKeypair1, ledgerHash, parti0, parti0);
TransactionResponse txResp1 = txbatchProcessor.schedule(transactionRequest); TransactionResponse txResp1 = txbatchProcessor.schedule(transactionRequest);


// BlockchainKeypair userKeypair2 = BlockchainKeyGenerator.getInstance().generate(); // BlockchainKeypair userKeypair2 = BlockchainKeyGenerator.getInstance().generate();
@@ -187,15 +187,15 @@ public class TransactionBatchProcessorTest {


// 注册新用户; // 注册新用户;
BlockchainKeypair userKeypair1 = BlockchainKeyGenerator.getInstance().generate(); BlockchainKeypair userKeypair1 = BlockchainKeyGenerator.getInstance().generate();
transactionRequest = LedgerTestUtils.createTxRequest_UserReg(ledgerHash, userKeypair1, parti0);
transactionRequest = LedgerTestUtils.createTxRequest_UserReg(userKeypair1, ledgerHash, parti0, parti0);
TransactionResponse txResp1 = txbatchProcessor.schedule(transactionRequest); TransactionResponse txResp1 = txbatchProcessor.schedule(transactionRequest);


BlockchainKeypair userKeypair2 = BlockchainKeyGenerator.getInstance().generate(); BlockchainKeypair userKeypair2 = BlockchainKeyGenerator.getInstance().generate();
transactionRequest = LedgerTestUtils.createTxRequest_MultiOPs_WithError(ledgerHash, userKeypair2, parti0);
transactionRequest = LedgerTestUtils.createTxRequest_MultiOPs_WithError(userKeypair2, ledgerHash, parti0, parti0);
TransactionResponse txResp2 = txbatchProcessor.schedule(transactionRequest); TransactionResponse txResp2 = txbatchProcessor.schedule(transactionRequest);


BlockchainKeypair userKeypair3 = BlockchainKeyGenerator.getInstance().generate(); BlockchainKeypair userKeypair3 = BlockchainKeyGenerator.getInstance().generate();
transactionRequest = LedgerTestUtils.createTxRequest_UserReg(ledgerHash, userKeypair3, parti0);
transactionRequest = LedgerTestUtils.createTxRequest_UserReg(userKeypair3, ledgerHash, parti0, parti0);
TransactionResponse txResp3 = txbatchProcessor.schedule(transactionRequest); TransactionResponse txResp3 = txbatchProcessor.schedule(transactionRequest);


LedgerBlock newBlock = newBlockEditor.prepare(); LedgerBlock newBlock = newBlockEditor.prepare();


Loading…
Cancel
Save