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 pathvalidate_state_root_test.go
77 lines (64 loc) · 1.88 KB
/
validate_state_root_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
70
71
72
73
74
75
76
77
package commander
import (
"testing"
"github.com/Worldcoin/hubble-commander/models"
"github.com/Worldcoin/hubble-commander/models/enums/batchtype"
st "github.com/Worldcoin/hubble-commander/storage"
"github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
)
type ValidateStateRootTestSuite struct {
*require.Assertions
suite.Suite
storage *st.TestStorage
}
func (s *ValidateStateRootTestSuite) SetupSuite() {
s.Assertions = require.New(s.T())
}
func (s *ValidateStateRootTestSuite) SetupTest() {
var err error
s.storage, err = st.NewTestStorage()
s.NoError(err)
}
func (s *ValidateStateRootTestSuite) TearDownTest() {
err := s.storage.Teardown()
s.NoError(err)
}
func (s *ValidateStateRootTestSuite) TestValidateStateRoot_SameStateRootHash() {
root, err := s.storage.StateTree.Root()
s.NoError(err)
commitment := models.TxCommitment{
CommitmentBase: models.CommitmentBase{
Type: batchtype.Transfer,
PostStateRoot: *root,
},
FeeReceiver: 0,
CombinedSignature: models.Signature{},
}
err = s.storage.AddCommitment(&commitment)
s.NoError(err)
err = validateStateRoot(s.storage.Storage)
s.NoError(err)
}
func (s *ValidateStateRootTestSuite) TestValidateStateRoot_DifferentStateRootHash() {
commitment := models.TxCommitment{
CommitmentBase: models.CommitmentBase{
Type: batchtype.Transfer,
PostStateRoot: common.Hash{1, 2, 3},
},
FeeReceiver: 0,
CombinedSignature: models.Signature{},
}
err := s.storage.AddCommitment(&commitment)
s.NoError(err)
err = validateStateRoot(s.storage.Storage)
s.ErrorIs(err, ErrInvalidStateRoot)
}
func (s *ValidateStateRootTestSuite) TestValidateStateRoot_FirstCommitment() {
err := validateStateRoot(s.storage.Storage)
s.NoError(err)
}
func TestValidateStateRootTestSuite(t *testing.T) {
suite.Run(t, new(ValidateStateRootTestSuite))
}