Search in sources :

Example 1 with MerkleDataNodeEncoder_V0

use of com.jd.blockchain.ledger.proof.MerkleDataNodeEncoder_V0 in project jdchain-core by blockchain-jd-com.

the class MerkleDataNodeEncoderTest method testCompatibility.

@Test
public void testCompatibility() {
    Random rand = new Random();
    byte[] data = new byte[512];
    byte[] keyBytes = new byte[256];
    rand.nextBytes(data);
    rand.nextBytes(keyBytes);
    Bytes key = new Bytes(keyBytes);
    long sn = 1024;
    long version = 1;
    PreviousDataNode pdataNode = PreviousDataNode.newDataNode(ClassicAlgorithm.SHA256.code(), sn, key, version, data);
    MerkleDataNodeEncoder encoderV0 = new MerkleDataNodeEncoder_V0();
    DataNode dataNode = encoderV0.create(ClassicAlgorithm.SHA256.code(), sn, key, version, data);
    assertEquals(pdataNode.getNodeHash(), dataNode.getNodeHash());
    assertEquals(pdataNode.getSN(), dataNode.getSN());
    assertEquals(pdataNode.getVersion(), dataNode.getVersion());
    assertEquals(pdataNode.getKey(), dataNode.getKey());
    DataNode dataNode_reversed = encoderV0.resolve(pdataNode.toBytes());
    assertNull(dataNode_reversed.getValueHash());
    assertEquals(pdataNode.getNodeHash(), dataNode_reversed.getNodeHash());
    assertEquals(pdataNode.getSN(), dataNode_reversed.getSN());
    assertEquals(pdataNode.getVersion(), dataNode_reversed.getVersion());
    assertEquals(pdataNode.getKey(), dataNode_reversed.getKey());
}
Also used : MerkleDataNodeEncoder_V0(com.jd.blockchain.ledger.proof.MerkleDataNodeEncoder_V0) Bytes(utils.Bytes) Random(java.util.Random) DataNode(com.jd.blockchain.ledger.proof.MerkleSequenceTree.DataNode) MerkleDataNodeEncoder(com.jd.blockchain.ledger.core.MerkleDataNodeEncoder) Test(org.junit.Test)

Example 2 with MerkleDataNodeEncoder_V0

use of com.jd.blockchain.ledger.proof.MerkleDataNodeEncoder_V0 in project jdchain-core by blockchain-jd-com.

the class MerkleDataNodeEncoderTest method doTestV0.

private void doTestV0(long sn, long version, Bytes key, byte[] data) {
    MerkleDataNodeEncoder encoderV0 = new MerkleDataNodeEncoder_V0();
    DataNode nodeV0 = encoderV0.create(ClassicAlgorithm.SHA256.code(), sn, key, version, data);
    assertNull(nodeV0.getValueHash());
    assertEquals(sn, nodeV0.getSN());
    assertEquals(version, nodeV0.getVersion());
    assertEquals(key, nodeV0.getKey());
    byte[] nodeBytes = nodeV0.toBytes();
    DataNode nodeV0_reversed = encoderV0.resolve(nodeBytes);
    assertNull(nodeV0_reversed.getValueHash());
    assertEquals(nodeV0.getNodeHash(), nodeV0_reversed.getNodeHash());
    assertEquals(encoderV0.getFormatVersion(), nodeBytes[0]);
    assertEquals(sn, nodeV0_reversed.getSN());
    assertEquals(version, nodeV0_reversed.getVersion());
    assertEquals(key, nodeV0_reversed.getKey());
}
Also used : MerkleDataNodeEncoder_V0(com.jd.blockchain.ledger.proof.MerkleDataNodeEncoder_V0) DataNode(com.jd.blockchain.ledger.proof.MerkleSequenceTree.DataNode) MerkleDataNodeEncoder(com.jd.blockchain.ledger.core.MerkleDataNodeEncoder)

Aggregations

MerkleDataNodeEncoder (com.jd.blockchain.ledger.core.MerkleDataNodeEncoder)2 MerkleDataNodeEncoder_V0 (com.jd.blockchain.ledger.proof.MerkleDataNodeEncoder_V0)2 DataNode (com.jd.blockchain.ledger.proof.MerkleSequenceTree.DataNode)2 Random (java.util.Random)1 Test (org.junit.Test)1 Bytes (utils.Bytes)1