MCPcopy Create free account
hub / github.com/ElementsProject/elements / test_hashBlock

Function test_hashBlock

src/simplicity/test.c:74–187  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

72}
73
74static void test_hashBlock(void) {
75 printf("Test hashBlock\n");
76 dag_node* dag;
77 combinator_counters census;
78 int_fast32_t len;
79 simplicity_err error;
80 {
81 bitstream stream = initializeBitstream(hashBlock, sizeof_hashBlock);
82 len = simplicity_decodeMallocDag(&dag, simplicity_elements_decodeJet, &census, &stream);
83 if (!dag) {
84 simplicity_assert(len < 0);
85 error = (simplicity_err)len;
86 failures++;
87 printf("Error parsing dag: %d\n", error);
88 } else {
89 simplicity_assert(0 < len);
90 error = simplicity_closeBitstream(&stream);
91 if (!IS_OK(error)) {
92 failures++;
93 printf("Error closing dag stream for hashblock\n");
94 }
95 }
96 }
97 if (dag && IS_OK(error)) {
98 successes++;
99
100 if (0 == memcmp(hashBlock_cmr, dag[len-1].cmr.s, sizeof(uint32_t[8]))) {
101 successes++;
102 } else {
103 failures++;
104 printf("Unexpected CMR of hashblock\n");
105 }
106
107 type* type_dag;
108 bitstream witness = initializeBitstream(hashBlock_witness, sizeof_hashBlock_witness);
109 if (!IS_OK(simplicity_mallocTypeInference(&type_dag, simplicity_elements_mallocBoundVars, dag, (uint_fast32_t)len, &census)) || !type_dag ||
110 type_dag[dag[len-1].sourceType].bitSize != 768 || type_dag[dag[len-1].targetType].bitSize != 256) {
111 failures++;
112 printf("Unexpected failure of type inference for hashblock\n");
113 } else if (!IS_OK(simplicity_fillWitnessData(dag, type_dag, (uint_fast32_t)len, &witness))) {
114 failures++;
115 printf("Unexpected failure of fillWitnessData for hashblock\n");
116 } else if (!IS_OK(simplicity_closeBitstream(&witness))) {
117 failures++;
118 printf("Unexpected failure of witness stream for hashblock\n");
119 } else {
120 {
121 analyses analysis[len];
122 simplicity_computeAnnotatedMerkleRoot(analysis, dag, type_dag, (uint_fast32_t)len);
123 if (0 == memcmp(hashBlock_amr, analysis[len-1].annotatedMerkleRoot.s, sizeof(uint32_t[8]))) {
124 successes++;
125 } else {
126 failures++;
127 printf("Unexpected AMR of hashblock\n");
128 }
129 }
130 {
131 sha256_midstate ihr;

Callers 1

mainFunction · 0.85

Calls 15

printfFunction · 0.85
initializeBitstreamFunction · 0.85
IS_OKFunction · 0.85
initWriteFrameFunction · 0.85
write32sFunction · 0.85
simplicity_analyseBoundsFunction · 0.85

Tested by

no test coverage detected