Search Apps Documentation Source Content File Folder Download Copy Actions Download

merkle_test.gno

1.30 Kb · 53 lines
 1package merkle
 2
 3import (
 4	"encoding/hex"
 5	"testing"
 6
 7	"gno.land/p/nt/uassert/v0"
 8)
 9
10func TestHashFromByteSlices(t *testing.T) {
11	tests := []struct {
12		name       string
13		slices     [][]byte
14		expectHash string // in hex format
15	}{
16		{
17			name:       "nil",
18			slices:     nil,
19			expectHash: "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
20		},
21		{
22			name:   "empty",
23			slices: [][]byte{}, expectHash: "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
24		},
25		{
26			name:       "single",
27			slices:     [][]byte{{1, 2, 3}},
28			expectHash: "054edec1d0211f624fed0cbca9d4f9400b0e491c43742af2c5b0abebf0c990d8",
29		},
30		{
31			name:       "single blank",
32			slices:     [][]byte{{}},
33			expectHash: "6e340b9cffb37a989ca544e6bb780a2c78901d3fb33738768511a30617afa01d",
34		},
35		{
36			name:       "two",
37			slices:     [][]byte{{1, 2, 3}, {4, 5, 6}},
38			expectHash: "82e6cfce00453804379b53962939eaa7906b39904be0813fcadd31b100773c4b",
39		},
40		{
41			name:       "many",
42			slices:     [][]byte{{1, 2}, {3, 4}, {5, 6}, {7, 8}, {9, 10}},
43			expectHash: "f326493eceab4f2d9ffbc78c59432a0a005d6ea98392045c74df5d14a113be18",
44		},
45	}
46	for _, tt := range tests {
47		t.Run(tt.name, func(t *testing.T) {
48			hash := HashFromByteSlices(tt.slices)
49
50			uassert.Equal(t, tt.expectHash, hex.EncodeToString(hash))
51		})
52	}
53}