This repository has been archived by the owner on Oct 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathverify_commitment_test.go
69 lines (58 loc) · 1.76 KB
/
verify_commitment_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package commander
import (
"testing"
"github.com/Worldcoin/hubble-commander/eth"
"github.com/Worldcoin/hubble-commander/models"
st "github.com/Worldcoin/hubble-commander/storage"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
)
type VerifyCommitmentTestSuite struct {
*require.Assertions
suite.Suite
storage *st.Storage
teardown func() error
client *eth.TestClient
}
func (s *VerifyCommitmentTestSuite) SetupSuite() {
s.Assertions = require.New(s.T())
}
func (s *VerifyCommitmentTestSuite) SetupTest() {
storage, err := st.NewTestStorage()
s.NoError(err)
s.storage = storage.Storage
s.teardown = storage.Teardown
s.client, err = eth.NewTestClient()
s.NoError(err)
}
func (s *VerifyCommitmentTestSuite) TearDownTest() {
s.client.Close()
err := s.teardown()
s.NoError(err)
}
func (s *VerifyCommitmentTestSuite) TestVerifyCommitment_ValidCommitmentRoot() {
err := PopulateGenesisAccounts(s.storage, s.client.ChainState.GenesisAccounts)
s.NoError(err)
err = verifyCommitmentRoot(s.storage, s.client.Client)
s.NoError(err)
}
func (s *VerifyCommitmentTestSuite) TestVerifyCommitment_InvalidCommitmentRoot() {
s.client.ChainState.GenesisAccounts = append(s.client.ChainState.GenesisAccounts, models.GenesisAccount{
PublicKey: models.PublicKey{5, 6, 7},
StateID: 1,
State: models.UserState{
PubKeyID: 10,
TokenID: models.MakeUint256(0),
Balance: models.MakeUint256(500),
Nonce: models.MakeUint256(0),
},
})
err := PopulateGenesisAccounts(s.storage, s.client.ChainState.GenesisAccounts)
s.NoError(err)
err = verifyCommitmentRoot(s.storage, s.client.Client)
s.NotNil(err)
s.Equal(ErrInvalidCommitmentRoot, err)
}
func TestVerifyCommitmentTestSuite(t *testing.T) {
suite.Run(t, new(VerifyCommitmentTestSuite))
}