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());
}
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());
}
Aggregations