github.com/devwanda/aphelion-staking@v0.33.9/crypto/merkle/simple_map_test.go (about) 1 package merkle 2 3 import ( 4 "fmt" 5 "testing" 6 7 "github.com/stretchr/testify/assert" 8 ) 9 10 func TestSimpleMap(t *testing.T) { 11 tests := []struct { 12 keys []string 13 values []string // each string gets converted to []byte in test 14 want string 15 }{ 16 {[]string{"key1"}, []string{"value1"}, "a44d3cc7daba1a4600b00a2434b30f8b970652169810d6dfa9fb1793a2189324"}, 17 {[]string{"key1"}, []string{"value2"}, "0638e99b3445caec9d95c05e1a3fc1487b4ddec6a952ff337080360b0dcc078c"}, 18 // swap order with 2 keys 19 { 20 []string{"key1", "key2"}, 21 []string{"value1", "value2"}, 22 "8fd19b19e7bb3f2b3ee0574027d8a5a4cec370464ea2db2fbfa5c7d35bb0cff3", 23 }, 24 { 25 []string{"key2", "key1"}, 26 []string{"value2", "value1"}, 27 "8fd19b19e7bb3f2b3ee0574027d8a5a4cec370464ea2db2fbfa5c7d35bb0cff3", 28 }, 29 // swap order with 3 keys 30 { 31 []string{"key1", "key2", "key3"}, 32 []string{"value1", "value2", "value3"}, 33 "1dd674ec6782a0d586a903c9c63326a41cbe56b3bba33ed6ff5b527af6efb3dc", 34 }, 35 { 36 []string{"key1", "key3", "key2"}, 37 []string{"value1", "value3", "value2"}, 38 "1dd674ec6782a0d586a903c9c63326a41cbe56b3bba33ed6ff5b527af6efb3dc", 39 }, 40 } 41 for i, tc := range tests { 42 db := newSimpleMap() 43 for i := 0; i < len(tc.keys); i++ { 44 db.Set(tc.keys[i], []byte(tc.values[i])) 45 } 46 got := db.Hash() 47 assert.Equal(t, tc.want, fmt.Sprintf("%x", got), "Hash didn't match on tc %d", i) 48 } 49 }