github.com/incognitochain/go-incognito-sdk@v1.0.1/privacy/pedersen_test.go (about) 1 package privacy 2 3 import ( 4 "github.com/stretchr/testify/assert" 5 "testing" 6 ) 7 8 func TestPedersenCommitAll(t *testing.T) { 9 for i := 0; i < 100; i++ { 10 openings := make([]*Scalar, len(PedCom.G)) 11 for i := 0; i < len(openings); i++ { 12 openings[i] = RandomScalar() 13 } 14 15 commitment, err := PedCom.commitAll(openings) 16 isValid := commitment.PointValid() 17 18 assert.NotEqual(t, commitment, nil) 19 assert.Equal(t, true, isValid) 20 assert.Equal(t, nil, err) 21 } 22 } 23 24 func TestPedersenCommitAtIndex(t *testing.T) { 25 for i := 0; i < 100; i++ { 26 data := []struct { 27 value *Scalar 28 rand *Scalar 29 index byte 30 }{ 31 {RandomScalar(), RandomScalar(), PedersenPrivateKeyIndex}, 32 {RandomScalar(), RandomScalar(), PedersenValueIndex}, 33 {RandomScalar(), RandomScalar(), PedersenSndIndex}, 34 {RandomScalar(), RandomScalar(), PedersenShardIDIndex}, 35 } 36 37 for _, item := range data { 38 commitment := PedCom.CommitAtIndex(item.value, item.rand, item.index) 39 expectedCm := new(Point).ScalarMult(PedCom.G[item.index], item.value) 40 expectedCm.Add(expectedCm, new(Point).ScalarMult(PedCom.G[PedersenRandomnessIndex], item.rand)) 41 assert.Equal(t, expectedCm, commitment) 42 } 43 } 44 }