|
| 1 | +package hash_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/primefactor-io/commitment/pkg/hash" |
| 7 | +) |
| 8 | + |
| 9 | +func TestCommitVerify(t *testing.T) { |
| 10 | + t.Parallel() |
| 11 | + |
| 12 | + t.Run("Commit / Verify - Valid (single-data)", func(t *testing.T) { |
| 13 | + t.Parallel() |
| 14 | + |
| 15 | + data := []byte("Hello World") |
| 16 | + |
| 17 | + comm, _ := hash.Commit(data) |
| 18 | + isValid := hash.Verify(comm, data) |
| 19 | + |
| 20 | + if isValid != true { |
| 21 | + t.Error("Commitment verification failed") |
| 22 | + } |
| 23 | + }) |
| 24 | + |
| 25 | + t.Run("Commit / Verify - Valid (multi-data)", func(t *testing.T) { |
| 26 | + t.Parallel() |
| 27 | + |
| 28 | + data1 := []byte("Hello") |
| 29 | + data2 := []byte("World") |
| 30 | + |
| 31 | + comm, _ := hash.Commit(data1, data2) |
| 32 | + isValid := hash.Verify(comm, data1, data2) |
| 33 | + |
| 34 | + if isValid != true { |
| 35 | + t.Error("Commitment verification failed") |
| 36 | + } |
| 37 | + }) |
| 38 | + |
| 39 | + t.Run("Commit / Verify - Invalid (single-data)", func(t *testing.T) { |
| 40 | + t.Parallel() |
| 41 | + |
| 42 | + data1 := []byte("Hello World") |
| 43 | + data2 := []byte("Hello, World") |
| 44 | + |
| 45 | + comm, _ := hash.Commit(data1) |
| 46 | + isValid := hash.Verify(comm, data2) |
| 47 | + |
| 48 | + if isValid != false { |
| 49 | + t.Error("Commitment verification failed") |
| 50 | + } |
| 51 | + }) |
| 52 | + |
| 53 | + t.Run("Commit / Verify - Invalid (multi-data)", func(t *testing.T) { |
| 54 | + t.Parallel() |
| 55 | + |
| 56 | + data1 := []byte("Hello") |
| 57 | + data2 := []byte("World") |
| 58 | + data3 := []byte(", World") |
| 59 | + |
| 60 | + comm, _ := hash.Commit(data1, data2) |
| 61 | + isValid := hash.Verify(comm, data1, data3) |
| 62 | + |
| 63 | + if isValid != false { |
| 64 | + t.Error("Commitment verification failed") |
| 65 | + } |
| 66 | + }) |
| 67 | +} |
0 commit comments