use of com.jd.blockchain.ledger.core.TransactionResultData in project jdchain-core by blockchain-jd-com.
the class LedgerTransactionDataTest method initLedgerTransactionImpl.
@Before
public void initLedgerTransactionImpl() throws Exception {
DataContractRegistry.register(LedgerTransaction.class);
DataContractRegistry.register(LedgerDataSnapshot.class);
DataContractRegistry.register(HashObject.class);
DataContractRegistry.register(DataAccountKVSetOperation.class);
txRequest = initTxRequestMessage(ClassicAlgorithm.SHA256);
long blockHeight = 9986L;
TransactionStagedSnapshot snapshot = initTransactionStagedSnapshot();
data = new TransactionResultData(txRequest.getTransactionHash(), blockHeight, TransactionState.SUCCESS, snapshot, null);
HashDigest hash = ClassicCryptoService.SHA256.hash("zhangsan".getBytes());
HashDigest adminAccountHash = ClassicCryptoService.SHA256.hash("lisi".getBytes());
HashDigest userAccountSetHash = ClassicCryptoService.SHA256.hash("wangwu".getBytes());
HashDigest dataAccountSetHash = ClassicCryptoService.SHA256.hash("zhaoliu".getBytes());
HashDigest contractAccountSetHash = ClassicCryptoService.SHA256.hash("sunqi".getBytes());
snapshot.setAdminAccountHash(adminAccountHash);
snapshot.setUserAccountSetHash(userAccountSetHash);
snapshot.setDataAccountSetHash(dataAccountSetHash);
snapshot.setContractAccountSetHash(contractAccountSetHash);
ledgerTransactionData = new LedgerTransactionData(txRequest, data);
}
use of com.jd.blockchain.ledger.core.TransactionResultData in project jdchain-core by blockchain-jd-com.
the class TransactionSetTest method buildTransactionResult.
private TransactionResult buildTransactionResult(TransactionRequest txReq, long blockHeight, TransactionState txState) {
TransactionStagedSnapshot txSnapshot = new TransactionStagedSnapshot();
HashDigest adminAccountHash = LedgerTestUtils.generateRandomHash();
txSnapshot.setAdminAccountHash(adminAccountHash);
HashDigest userAccountSetHash = LedgerTestUtils.generateRandomHash();
txSnapshot.setUserAccountSetHash(userAccountSetHash);
HashDigest dataAccountSetHash = LedgerTestUtils.generateRandomHash();
txSnapshot.setDataAccountSetHash(dataAccountSetHash);
HashDigest contractAccountSetHash = LedgerTestUtils.generateRandomHash();
txSnapshot.setContractAccountSetHash(contractAccountSetHash);
OperationResult[] opResults = new OperationResult[0];
TransactionResultData txResult = new TransactionResultData(txReq.getTransactionHash(), blockHeight, txState, txSnapshot, opResults);
return txResult;
}
use of com.jd.blockchain.ledger.core.TransactionResultData in project jdchain-core by blockchain-jd-com.
the class TransactionSetTest method testSpecialCase_1.
/**
* 根据实际运行中一个随机出现的错误中提取到的数据来建立的测试用例,可以更简化地验证正确性;
*
* <p>
*
* 注:重构了 {@link LedgerTransaction} 和 {@link TransactionContent}
* 等交易结构相关的类型之后,此用例已经失效; by huanghaiquan on 2020-09-16;
*/
// @Test
public void testSpecialCase_1() {
CryptoSetting defCryptoSetting = LedgerTestUtils.createDefaultCryptoSetting();
MemoryKVStorage testStorage = new MemoryKVStorage();
BufferedKVStorage bufferStorage = new BufferedKVStorage(null, testStorage, testStorage, false);
// Create a new TransactionSet, it's empty;
TransactionSetEditor txset = new TransactionSetEditor(defCryptoSetting, keyPrefix, bufferStorage, bufferStorage, LedgerDataStructure.MERKLE_TREE);
assertTrue(txset.isUpdated());
assertFalse(txset.isReadonly());
assertNull(txset.getRootHash());
HashDigest ledgerHash = Crypto.resolveAsHashDigest(Base58Utils.decode("j5iF5xJ7KN4kjRrhD3EUKVSPmHz2bExxp3h9avqxcnnzch"));
assertEquals("j5iF5xJ7KN4kjRrhD3EUKVSPmHz2bExxp3h9avqxcnnzch", ledgerHash.toBase58());
BlockchainKeypair parti0 = LedgerTestUtils.createKeyPair("7VeRLBwqTAz8oRazEazeaEfqei46sk2FzvBgyHMUBJvrUEGT", "7VeRUm27GbrsX9HbQSZguChLp24HZYub6s5FJ7FjBht8BmbA");
BlockchainKeypair userKeypair1 = LedgerTestUtils.createKeyPair("7VeRKf3GFLFcBfzvtzmtyMXEoX2HYGEJ4j7CmHcnRV99W5Dp", "7VeRYQjeAaQY5Po8MMtmGNHA2SniqLXmJaZwBS5K8zTtMAU1");
TransactionRequest transactionRequest1 = LedgerTestUtils.createTxRequest_UserReg_SHA256(userKeypair1, ledgerHash, 1580315317127L, parti0, parti0);
// TransactionRequest transactionRequest1 = LedgerTestUtils.createTxRequest_UserReg(userKeypair1, ledgerHash, 202001202020L,
// parti0, parti0);
System.out.printf("\r\n ===||=== transactionRequest1.getTransactionHash()=[%s]\r\n", transactionRequest1.getTransactionHash().toBase58());
// assertEquals("j5sXmpcomtM2QMUNWeQWsF8bNFFnyeXoCjVAekEeLSscgY", transactionRequest1.getTransactionHash().toBase58());
assertEquals("j5wPGKT5CUzwi8j6VfCWaP2p9YZ6WVWtMANp9HbHWzvhgG", transactionRequest1.getTransactionHash().toBase58());
TransactionStagedSnapshot txSnapshot = new TransactionStagedSnapshot();
txSnapshot.setAdminAccountHash(Crypto.resolveAsHashDigest(Base58Utils.decode("j5taeK6cpmJGcn8QbEYCqadna6s7NDSheDTK6NJdU4mFhh")));
txSnapshot.setUserAccountSetHash(Crypto.resolveAsHashDigest(Base58Utils.decode("j5oQDSob92mCoGSHtrXa9soqgAtMyjwfRMt2kj7igXXJrP")));
TransactionResult tx = new TransactionResultData(transactionRequest1.getTransactionHash(), 1, TransactionState.SUCCESS, txSnapshot);
txset.addTransaction(transactionRequest1, tx);
LedgerTransaction tx_query = txset.getTransaction(transactionRequest1.getTransactionHash());
assertNotNull(tx_query);
txset.commit();
bufferStorage.commit();
tx_query = txset.getTransaction(transactionRequest1.getTransactionHash());
TransactionState tx_state = txset.getState(transactionRequest1.getTransactionHash());
assertNotNull(tx_query);
assertEquals(0, tx_state.CODE);
HashDigest txsetRootHash = txset.getRootHash();
txset = new TransactionSetEditor(-1, txsetRootHash, defCryptoSetting, keyPrefix, testStorage, testStorage, LedgerDataStructure.MERKLE_TREE, false);
tx_query = txset.getTransaction(transactionRequest1.getTransactionHash());
tx_state = txset.getState(transactionRequest1.getTransactionHash());
assertNotNull(tx_query);
assertEquals(0, tx_state.CODE);
}
Aggregations