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
/
pending_stake_withdrawal_test.go
81 lines (67 loc) · 2.07 KB
/
pending_stake_withdrawal_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
package storage
import (
"testing"
"github.com/Worldcoin/hubble-commander/models"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
)
type PendingStakeWithdrawalTestSuite struct {
*require.Assertions
suite.Suite
storage *TestStorage
}
func (s *PendingStakeWithdrawalTestSuite) SetupSuite() {
s.Assertions = require.New(s.T())
}
func (s *PendingStakeWithdrawalTestSuite) SetupTest() {
var err error
s.storage, err = NewTestStorage()
s.NoError(err)
}
func (s *PendingStakeWithdrawalTestSuite) TearDownTest() {
err := s.storage.Teardown()
s.NoError(err)
}
func (s *PendingStakeWithdrawalTestSuite) TestAddPendingStakeWithdrawal_AddAndDelete() {
stake := models.PendingStakeWithdrawal{
BatchID: models.MakeUint256(1),
FinalisationBlock: 100,
}
err := s.storage.AddPendingStakeWithdrawal(&stake)
s.NoError(err)
err = s.storage.RemovePendingStakeWithdrawal(stake.BatchID)
s.NoError(err)
}
func (s *PendingStakeWithdrawalTestSuite) TestRemovePendingStakeWithdrawal_NonexistentStake() {
err := s.storage.RemovePendingStakeWithdrawal(models.MakeUint256(42))
s.ErrorIs(err, NewNotFoundError("pending stake withdrawal"))
}
func (s *PendingStakeWithdrawalTestSuite) TestGetReadyStateWithdrawals_AddAndGet() {
stakes := []models.PendingStakeWithdrawal{
{
BatchID: models.MakeUint256(uint64(2)),
FinalisationBlock: uint32(12),
},
{
BatchID: models.MakeUint256(uint64(1)),
FinalisationBlock: uint32(10),
},
}
for i := range stakes {
err := s.storage.AddPendingStakeWithdrawal(&stakes[i])
s.NoError(err)
}
expectedStake := stakes[1]
actualStakes, err := s.storage.GetReadyStateWithdrawals(expectedStake.FinalisationBlock)
s.NoError(err)
s.Len(actualStakes, 1)
s.Equal(expectedStake, actualStakes[0])
}
func (s *PendingStakeWithdrawalTestSuite) TestGetReadyStateWithdrawals_NonexistentStake() {
stakes, err := s.storage.GetReadyStateWithdrawals(129)
s.NoError(err)
s.Len(stakes, 0)
}
func TestPendingStakeWithdrawalTestSuiteTestSuite(t *testing.T) {
suite.Run(t, new(PendingStakeWithdrawalTestSuite))
}