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
/
test_storage_test.go
96 lines (78 loc) · 2.32 KB
/
test_storage_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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package storage
import (
"testing"
"time"
"github.com/Worldcoin/hubble-commander/models"
"github.com/Worldcoin/hubble-commander/models/enums/batchtype"
"github.com/Worldcoin/hubble-commander/utils"
"github.com/Worldcoin/hubble-commander/utils/ref"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
)
type NewTestStorageTestSuite struct {
*require.Assertions
suite.Suite
storage *TestStorage
batch *models.Batch
}
func (s *NewTestStorageTestSuite) SetupSuite() {
s.Assertions = require.New(s.T())
}
func (s *NewTestStorageTestSuite) SetupTest() {
var err error
s.storage, err = NewTestStorage()
s.NoError(err)
s.batch = &models.Batch{
ID: models.MakeUint256(1),
Type: batchtype.Transfer,
TransactionHash: utils.RandomHash(),
Hash: utils.NewRandomHash(),
FinalisationBlock: ref.Uint32(1234),
AccountTreeRoot: utils.NewRandomHash(),
PrevStateRoot: utils.NewRandomHash(),
MinedTime: models.NewTimestamp(time.Unix(140, 0).UTC()),
}
}
func (s *NewTestStorageTestSuite) TearDownTest() {
err := s.storage.Teardown()
s.NoError(err)
}
func (s *NewTestStorageTestSuite) TestClone() {
err := s.storage.AddBatch(s.batch)
s.NoError(err)
stateLeaf, err := NewStateLeaf(1, &models.UserState{})
s.NoError(err)
_, err = s.storage.StateTree.Set(stateLeaf.StateID, &stateLeaf.UserState)
s.NoError(err)
clonedStorage, err := s.storage.Clone()
s.NoError(err)
defer func() {
err = clonedStorage.Teardown()
s.NoError(err)
}()
clonedBatch, err := clonedStorage.GetBatch(s.batch.ID)
s.NoError(err)
s.Equal(s.batch, clonedBatch)
clonedStateLeaf, err := clonedStorage.StateTree.Leaf(stateLeaf.StateID)
s.NoError(err)
s.Equal(stateLeaf, clonedStateLeaf)
}
func (s *NewTestStorageTestSuite) TestClone_ClonesFeeReceiverStateIDsByValue() {
s.storage.feeReceiverStateIDs["abc"] = 123
clonedStorage, err := s.storage.Clone()
s.NoError(err)
defer func() {
err = clonedStorage.Teardown()
s.NoError(err)
}()
abcID, ok := clonedStorage.feeReceiverStateIDs["abc"]
s.True(ok)
s.EqualValues(123, abcID)
clonedStorage.feeReceiverStateIDs["def"] = 456
defID, ok := s.storage.feeReceiverStateIDs["def"]
s.False(ok)
s.EqualValues(0, defID) // empty value
}
func TestNewTestStorageTestSuite(t *testing.T) {
suite.Run(t, new(NewTestStorageTestSuite))
}