use of com.jd.blockchain.ledger.core.TransactionStagedSnapshot in project jdchain-core by blockchain-jd-com.
the class LedgerTestUtils method generateRandomSnapshot.
public static TransactionStagedSnapshot generateRandomSnapshot() {
TransactionStagedSnapshot txDataSnapshot = new TransactionStagedSnapshot();
txDataSnapshot.setAdminAccountHash(generateRandomHash());
txDataSnapshot.setContractAccountSetHash(generateRandomHash());
txDataSnapshot.setDataAccountSetHash(generateRandomHash());
txDataSnapshot.setUserAccountSetHash(generateRandomHash());
return txDataSnapshot;
}
use of com.jd.blockchain.ledger.core.TransactionStagedSnapshot 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.TransactionStagedSnapshot in project jdchain-core by blockchain-jd-com.
the class TransactionStagedSnapshotTest method initTransactionStagedSnapshot.
@Before
public void initTransactionStagedSnapshot() {
DataContractRegistry.register(LedgerDataSnapshot.class);
data = new TransactionStagedSnapshot();
data.setAdminAccountHash(ClassicCryptoService.SHA256.hash("zhangsan".getBytes()));
data.setContractAccountSetHash(ClassicCryptoService.SHA256.hash("lisi".getBytes()));
data.setDataAccountSetHash(ClassicCryptoService.SHA256.hash("wangwu".getBytes()));
data.setUserAccountSetHash(ClassicCryptoService.SHA256.hash("zhaoliu".getBytes()));
}
use of com.jd.blockchain.ledger.core.TransactionStagedSnapshot in project jdchain-core by blockchain-jd-com.
the class TransactionDecorator method initTransactionStagedSnapshot.
private TransactionStagedSnapshot initTransactionStagedSnapshot(LedgerDataSnapshot ledgerDataSnapshot) {
TransactionStagedSnapshot transactionStagedSnapshot = new TransactionStagedSnapshot();
transactionStagedSnapshot.setAdminAccountHash(ledgerDataSnapshot.getAdminAccountHash());
transactionStagedSnapshot.setUserAccountSetHash(ledgerDataSnapshot.getUserAccountSetHash());
transactionStagedSnapshot.setContractAccountSetHash(ledgerDataSnapshot.getContractAccountSetHash());
transactionStagedSnapshot.setDataAccountSetHash(ledgerDataSnapshot.getDataAccountSetHash());
transactionStagedSnapshot.setSystemEventSetHash(ledgerDataSnapshot.getSystemEventSetHash());
transactionStagedSnapshot.setUserEventSetHash(ledgerDataSnapshot.getUserEventSetHash());
return transactionStagedSnapshot;
}
use of com.jd.blockchain.ledger.core.TransactionStagedSnapshot in project jdchain-core by blockchain-jd-com.
the class LedgerBlockImplTest method testSerialize_LedgerDataSnapshot.
// notice: LedgerBlock interface has more field info than LedgerDataSnapshot
// interface, so cannot deserialize LedgerBlock
// with LedgerDataSnapshot encode
// @Test
// public void testSerialize_LedgerDataSnapshot() throws Exception {
// byte[] serialBytes = BinaryEncodingUtils.encode(data,
// LedgerDataSnapshot.class);
// LedgerDataSnapshot resolvedData = BinaryEncodingUtils.decode(serialBytes,
// null,
// LedgerBlockData.class);
// System.out.println("------Assert start ------");
// assertEquals(resolvedData.getAdminAccountHash(), data.getAdminAccountHash());
// assertEquals(resolvedData.getAdminAccountHash(), data.getAdminAccountHash());
// assertEquals(resolvedData.getContractAccountSetHash(),
// data.getContractAccountSetHash());
// assertEquals(resolvedData.getDataAccountSetHash(),
// data.getDataAccountSetHash());
// assertEquals(resolvedData.getUserAccountSetHash(),
// data.getUserAccountSetHash());
// System.out.println("------Assert OK ------");
// }
@Test
public void testSerialize_LedgerDataSnapshot() throws Exception {
TransactionStagedSnapshot transactionStagedSnapshot = new TransactionStagedSnapshot();
HashDigest admin = ClassicCryptoService.SHA256.hash("alice".getBytes());
HashDigest contract = ClassicCryptoService.SHA256.hash("bob".getBytes());
HashDigest data = ClassicCryptoService.SHA256.hash("jerry".getBytes());
HashDigest user = ClassicCryptoService.SHA256.hash("tom".getBytes());
transactionStagedSnapshot.setAdminAccountHash(admin);
transactionStagedSnapshot.setContractAccountSetHash(contract);
transactionStagedSnapshot.setDataAccountSetHash(data);
transactionStagedSnapshot.setUserAccountSetHash(user);
byte[] serialBytes = BinaryProtocol.encode(transactionStagedSnapshot, LedgerDataSnapshot.class);
LedgerDataSnapshot resolvedData = BinaryProtocol.decode(serialBytes);
// verify start
assertEquals(resolvedData.getAdminAccountHash(), transactionStagedSnapshot.getAdminAccountHash());
assertEquals(resolvedData.getContractAccountSetHash(), transactionStagedSnapshot.getContractAccountSetHash());
assertEquals(resolvedData.getDataAccountSetHash(), transactionStagedSnapshot.getDataAccountSetHash());
assertEquals(resolvedData.getUserAccountSetHash(), transactionStagedSnapshot.getUserAccountSetHash());
// verify succeed
}
Aggregations