Created
October 15, 2018 18:53
-
-
Save TheVishnuKumar/5cff22f2b3924e658a869da42ad77f90 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@isTest | |
public class BlockChainTest{ | |
//Testing Blockchain | |
@isTest | |
public static void testBlockChain(){ | |
/**Data Setup**/ | |
//Creating Instance of Blockchain | |
BlockChain bChain = new BlockChain(); | |
//addBlock method take data as the string | |
//Changing data to the string with the JSON format | |
//Adding the first block to the chain | |
bChain.addBlock( json.serialize( new BCTestDataWrapper('Iron Man', '2334343434') ) ); | |
//Adding the second block to the chain | |
bChain.addBlock( json.serialize( new BCTestDataWrapper('Thor', '34343434') ) ); | |
/**Positive Testing**/ | |
//isChainValid will return true, as no data has been modified from block | |
system.assertEquals(true, bChain.isChainValid() ); | |
//Print Blockchain | |
system.debug('-Blockchain Data Before Modifying--'+Json.serialize( bChain.chain) ); | |
/**Negative Testing**/ | |
//Now updating the 0 index's block | |
BCTestDataWrapper tData = (BCTestDataWrapper)JSON.deserialize(bChain.chain[0].data, BCTestDataWrapper.class); | |
tData.name = 'Thanos'; | |
bChain.chain[0].data = json.serialize(tData); | |
//isChainValid will return false, as the data has been modified from block | |
system.assertEquals(false, bChain.isChainValid() ); | |
//Print Blockchain | |
system.debug('-Blockchain Data After Modifying--'+Json.serialize( bChain.chain) ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment