Search Apps Documentation Source Content File Folder Download Copy Actions Download State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

commit_test.gno

0.77 Kb · 28 lines
 1package commit
 2
 3import (
 4	"testing"
 5
 6	"gno.land/p/nt/uassert/v0"
 7)
 8
 9func TestHashDeterministicAndPrefixed(t *testing.T) {
10	uassert.Equal(t, Hash("a", "bc"), Hash("a", "bc"))
11	// length-prefixing prevents boundary collisions
12	uassert.NotEqual(t, Hash("ab", "c"), Hash("a", "bc"))
13	uassert.Equal(t, 64, len(Hash("x"))) // sha256 hex is 64 chars
14}
15
16func TestVerdictCommitReveal(t *testing.T) {
17	c := Verdict(true, "salt-123")
18	// reproducible from the revealed values
19	uassert.Equal(t, c, Verdict(true, "salt-123"))
20	// flipping the vote or the salt changes the commitment
21	uassert.NotEqual(t, c, Verdict(false, "salt-123"))
22	uassert.NotEqual(t, c, Verdict(true, "salt-999"))
23}
24
25func TestShort(t *testing.T) {
26	uassert.Equal(t, "abc", Short("abc"))
27	uassert.True(t, len(Short(Hash("x"))) < 20)
28}