use of com.jd.blockchain.ledger.LedgerDataSnapshot in project jdchain-core by blockchain-jd-com.
the class TransactionStagedSnapshotTest method testSerialize_LedgerDataSnapshot.
@Test
public void testSerialize_LedgerDataSnapshot() throws Exception {
byte[] serialBytes = BinaryProtocol.encode(data, LedgerDataSnapshot.class);
LedgerDataSnapshot resolvedData = BinaryProtocol.decode(serialBytes);
System.out.println("------Assert start ------");
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 ------");
}
use of com.jd.blockchain.ledger.LedgerDataSnapshot 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