github.com/TrueBlocks/trueblocks-core/src/apps/chifra@v0.0.0-20241022031540-b362680128f7/pkg/manifest/json_manifest_test.go (about)

     1  // Copyright 2021 The TrueBlocks Authors. All rights reserved.
     2  // Use of this source code is governed by a license that can
     3  // be found in the LICENSE file.
     4  
     5  package manifest
     6  
     7  import (
     8  	"encoding/json"
     9  	"strings"
    10  	"testing"
    11  )
    12  
    13  var manifestSource = `
    14  {
    15    "version": "2",
    16    "chain": "mainnet",
    17    "specification": "QmUou7zX2g2tY58LP1A2GyP5RF9nbJsoxKTp299ah3svgb",
    18    "chunks": [
    19      {
    20        "fileName": "000000000-000000000",
    21        "bloomHash": "QmPQEgUm7nzQuW9HYyWp5Ff3aoUwg2rsxDngyuyddJTvrv",
    22        "indexHash": "QmZ5Atm8Z7aFLz2EycK4pVMHuH4y3PDGspuFejnE9fx2i5"
    23      },
    24      {
    25        "fileName": "000000001-000350277",
    26        "bloomHash": "QmZgrWAJLidkHJRLDVoZGCWAgmmcQEDCDM65XL5ZbAXxCM",
    27        "indexHash": "QmP1KvDPUJ1MqsCYcicJgTf5sxN7WjT7dZsrfBk2Jg3mSe"
    28      },
    29      {
    30        "fileName": "000350278-000590502",
    31        "bloomHash": "QmcU9tUUzyMLsBpKTpbYg2Xp6W5mmEqEDH3RSZzzcqPzMB",
    32        "indexHash": "QmavFBhUeRBnTCcAFUeSstGLuba4neYaSNvaPurCuYfU1N"
    33      },
    34      {
    35        "fileName": "000590503-000749875",
    36        "bloomHash": "QmWE3MaqAuoLmzg5wu5yXfLa7jD1HVjsz9898U4D2iN6i3",
    37        "indexHash": "Qmd3xF6eF9UxkWmru6i64GRy2L7iqxvAxYG9aZKZLEqRdN"
    38      },
    39      {
    40        "fileName": "000749876-000864336",
    41        "bloomHash": "QmXW2AQoZRV8qMw6DCn1vJEdz37wH1Q9WTjgecR4JHj5xH",
    42        "indexHash": "QmRedJaRUQEZoP3v32EYXGAiYT9gvXSGwtQMUcdRRJ7GQW"
    43      }
    44     ]
    45  }
    46  `
    47  
    48  func TestReadManifest(t *testing.T) {
    49  	m := &Manifest{}
    50  	err := json.NewDecoder(strings.NewReader(manifestSource)).Decode(m)
    51  	if err != nil {
    52  		t.Error(err)
    53  	}
    54  
    55  	type TestCases struct {
    56  		name     string
    57  		field    string
    58  		expected string
    59  	}
    60  
    61  	cases := []TestCases{
    62  		{
    63  			name:     "Version",
    64  			field:    m.Version,
    65  			expected: "2",
    66  		},
    67  		{
    68  			name:     "Chain",
    69  			field:    m.Chain,
    70  			expected: "mainnet",
    71  		},
    72  		{
    73  			name:     "Specification",
    74  			field:    m.Specification.String(),
    75  			expected: "QmUou7zX2g2tY58LP1A2GyP5RF9nbJsoxKTp299ah3svgb",
    76  		},
    77  	}
    78  
    79  	for _, tc := range cases {
    80  		if tc.field != tc.expected {
    81  			t.Errorf("Wrong %s: %s", tc.name, tc.field)
    82  		}
    83  	}
    84  
    85  	newPins := m.Chunks
    86  
    87  	if len(newPins) != 5 {
    88  		t.Errorf("Incorrect NewPins length: %d", len(newPins))
    89  	}
    90  
    91  	if newPins[0].BloomHash != "QmPQEgUm7nzQuW9HYyWp5Ff3aoUwg2rsxDngyuyddJTvrv" {
    92  		t.Errorf("Wrong NewPins[0].BloomHash: %s", newPins[0].BloomHash)
    93  	}
    94  }