You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
2.4 KiB

  1. // Copyright 2017-2018 DERO Project. All rights reserved.
  2. // Use of this source code in any form is governed by RESEARCH license.
  3. // license can be found in the LICENSE file.
  4. // GPG: 0F39 E425 8C65 3947 702A 8234 08B2 0360 A03A 9DE8
  5. //
  6. //
  7. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
  8. // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  9. // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
  10. // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  11. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  12. // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  13. // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  14. // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  15. // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  16. package block
  17. import "bytes"
  18. import "testing"
  19. import "encoding/hex"
  20. import "github.com/deroproject/derosuite/config"
  21. import "github.com/deroproject/derosuite/crypto"
  22. func Test_Genesis_block_serdes(t *testing.T) {
  23. mainnet_genesis_block_hex := "010000000000000000000000000000000000000000000000000000000000000000000010270000023c01ff0001ffffffffffff07020bf6522f9152fa26cd1fc5c022b1a9e13dab697f3acf4b4d0ca6950a867a194321011d92826d0656958865a035264725799f39f6988faa97d532f972895de849496d0000"
  24. mainnet_genesis_block, _ := hex.DecodeString(mainnet_genesis_block_hex)
  25. var bl Block
  26. err := bl.Deserialize(mainnet_genesis_block)
  27. if err != nil {
  28. t.Errorf("Deserialization test failed for NULL block err %s\n", err)
  29. }
  30. // test the block serializer and deserializer whether it gives the same
  31. serialized := bl.Serialize()
  32. if !bytes.Equal(serialized, mainnet_genesis_block) {
  33. t.Errorf("Serialization test failed for Genesis block %X\n", serialized)
  34. }
  35. // calculate POW hash
  36. powhash := bl.GetPoWHash()
  37. if powhash != crypto.Hash([32]byte{0xa7, 0x3b, 0xd3, 0x7a, 0xba, 0x34, 0x54, 0x77, 0x6b, 0x40, 0x73, 0x38, 0x54, 0xa8, 0x34, 0x9f, 0xe6, 0x35, 0x9e, 0xb2, 0xc9, 0x1d, 0x93, 0xbc, 0x72, 0x7c, 0x69, 0x43, 0x1c, 0x1d, 0x1f, 0x95}) {
  38. t.Errorf("genesis block POW failed %x\n", powhash[:])
  39. }
  40. // test block id
  41. if bl.GetHash() != config.Mainnet.Genesis_Block_Hash {
  42. t.Error("genesis block ID failed \n")
  43. }
  44. }