use of com.jd.blockchain.ledger.LedgerMetadata in project jdchain-core by blockchain-jd-com.
the class LedgerMetaDataTest method testSerialize_LedgerMetadata.
@Test
public void testSerialize_LedgerMetadata() {
// LedgerCodes.METADATA
// prepare work
// ConsensusConfig consensusConfig = new ConsensusConfig();
// consensusConfig.setValue(settingValue);ClassicCryptoService.ED25519_ALGORITHM
CryptoProvider[] supportedProviders = new CryptoProvider[SUPPORTED_PROVIDERS.length];
for (int i = 0; i < SUPPORTED_PROVIDERS.length; i++) {
supportedProviders[i] = Crypto.getProvider(SUPPORTED_PROVIDERS[i]);
}
CryptoConfig cryptoConfig = new CryptoConfig();
cryptoConfig.setSupportedProviders(supportedProviders);
cryptoConfig.setAutoVerifyHash(true);
cryptoConfig.setHashAlgorithm(ClassicAlgorithm.SHA256);
// LedgerConfiguration ledgerConfiguration = new LedgerConfiguration(consensusProvider,
// new Bytes(consensusSettingBytes), cryptoConfig);
HashDigest settingsHash = Crypto.getHashFunction("SHA256").hash(consensusSettingBytes);
LedgerAdminDataSetEditor.LedgerMetadataInfo ledgerMetadata = new LedgerAdminDataSetEditor.LedgerMetadataInfo();
ledgerMetadata.setSeed(seed);
ledgerMetadata.setSettingsHash(settingsHash);
HashDigest hashDigest = ClassicCryptoService.SHA256.hash(randomBytes);
ledgerMetadata.setParticipantsHash(hashDigest);
// encode and decode
byte[] encodeBytes = BinaryProtocol.encode(ledgerMetadata, LedgerMetadata.class);
LedgerMetadata deLedgerMetaData = BinaryProtocol.decode(encodeBytes);
// verify start
assertArrayEquals(ledgerMetadata.getSeed(), deLedgerMetaData.getSeed());
assertEquals(ledgerMetadata.getParticipantsHash(), deLedgerMetaData.getParticipantsHash());
assertEquals(ledgerMetadata.getSettingsHash(), deLedgerMetaData.getSettingsHash());
return;
}
Aggregations