Search in sources :

Example 1 with LedgerMetadata

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;
}
Also used : HashDigest(com.jd.blockchain.crypto.HashDigest) LedgerMetadata(com.jd.blockchain.ledger.LedgerMetadata) CryptoProvider(com.jd.blockchain.crypto.CryptoProvider) CryptoConfig(com.jd.blockchain.ledger.core.CryptoConfig) LedgerAdminDataSetEditor(com.jd.blockchain.ledger.core.LedgerAdminDataSetEditor) Test(org.junit.Test)

Aggregations

CryptoProvider (com.jd.blockchain.crypto.CryptoProvider)1 HashDigest (com.jd.blockchain.crypto.HashDigest)1 LedgerMetadata (com.jd.blockchain.ledger.LedgerMetadata)1 CryptoConfig (com.jd.blockchain.ledger.core.CryptoConfig)1 LedgerAdminDataSetEditor (com.jd.blockchain.ledger.core.LedgerAdminDataSetEditor)1 Test (org.junit.Test)1