arnaucube
arnaucube/hermez-nodePublic Self-hosted repository
hermez-node/db/statedb/utils_test.go
db/statedb/utils_test.goRaw
 1package statedb
 2
 3import (
 4	"math/big"
 5	"testing"
 6
 7	"github.com/iden3/go-iden3-crypto/babyjub"
 8	"github.com/stretchr/testify/assert"
 9)
10
11func TestBJJCompressedTo256BigInt(t *testing.T) {
12	var pkComp babyjub.PublicKeyComp
13	r := BJJCompressedTo256BigInts(pkComp)
14	zero := big.NewInt(0)
15	for i := 0; i < 256; i++ {
16		assert.Equal(t, zero, r[i])
17	}
18
19	pkComp[0] = 3
20	r = BJJCompressedTo256BigInts(pkComp)
21	one := big.NewInt(1)
22	for i := 0; i < 256; i++ {
23		if i != 0 && i != 1 {
24			assert.Equal(t, zero, r[i])
25		} else {
26			assert.Equal(t, one, r[i])
27		}
28	}
29
30	pkComp[31] = 4
31	r = BJJCompressedTo256BigInts(pkComp)
32	for i := 0; i < 256; i++ {
33		if i != 0 && i != 1 && i != 250 {
34			assert.Equal(t, zero, r[i])
35		} else {
36			assert.Equal(t, one, r[i])
37		}
38	}
39}