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 pathstake_withdrawals_test.go
96 lines (80 loc) · 2.65 KB
/
stake_withdrawals_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 commander
import (
"context"
"testing"
"github.com/Worldcoin/hubble-commander/eth"
"github.com/Worldcoin/hubble-commander/eth/deployer/rollup"
"github.com/Worldcoin/hubble-commander/metrics"
"github.com/Worldcoin/hubble-commander/models"
"github.com/Worldcoin/hubble-commander/models/enums/batchtype"
st "github.com/Worldcoin/hubble-commander/storage"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
)
type StakeWithdrawalsTestSuite struct {
*require.Assertions
suite.Suite
teardown func() error
testClient *eth.TestClient
cmd *Commander
}
func (s *StakeWithdrawalsTestSuite) SetupSuite() {
s.Assertions = require.New(s.T())
}
func (s *StakeWithdrawalsTestSuite) SetupTest() {
testStorage, err := st.NewTestStorage()
s.NoError(err)
s.teardown = testStorage.Teardown
// finalize instantly
s.testClient, err = eth.NewConfiguredTestClient(&rollup.DeploymentConfig{
Params: rollup.Params{BlocksToFinalise: models.NewUint256(0)},
}, ð.TestClientConfig{})
s.NoError(err)
s.cmd = &Commander{
storage: testStorage.Storage,
client: s.testClient.Client,
metrics: metrics.NewCommanderMetrics(),
}
}
func (s *StakeWithdrawalsTestSuite) TearDownTest() {
s.testClient.Close()
err := s.teardown()
s.NoError(err)
}
func (s *StakeWithdrawalsTestSuite) TestSyncStakeWithdrawals() {
batchID := models.MakeUint256(1)
err := s.cmd.storage.AddPendingStakeWithdrawal(&models.PendingStakeWithdrawal{
BatchID: batchID,
FinalisationBlock: 0,
})
s.NoError(err)
commitments := s.createSingleCommitmentInSlice(batchtype.Transfer)
_, err = s.testClient.SubmitTransfersBatchAndWait(&batchID, commitments)
s.NoError(err)
err = s.testClient.WithdrawStakeAndWait(&batchID)
s.NoError(err)
latestBlockNumber, err := s.testClient.GetLatestBlockNumber()
s.NoError(err)
err = s.cmd.syncStakeWithdrawals(context.Background(), 0, *latestBlockNumber)
s.NoError(err)
err = s.cmd.storage.RemovePendingStakeWithdrawal(batchID)
s.ErrorIs(err, st.NewNotFoundError("pending stake withdrawal"))
}
func (s *StakeWithdrawalsTestSuite) createSingleCommitmentInSlice(commitmentType batchtype.BatchType) []models.CommitmentWithTxs {
stateRoot, err := s.cmd.storage.StateTree.Root()
s.NoError(err)
commitment := models.TxCommitmentWithTxs{
TxCommitment: models.TxCommitment{
CommitmentBase: models.CommitmentBase{
Type: commitmentType,
PostStateRoot: *stateRoot,
},
FeeReceiver: 0,
CombinedSignature: models.Signature{},
},
Transactions: []byte{}}
return []models.CommitmentWithTxs{&commitment}
}
func TestStakeWithdrawalsTestSuite(t *testing.T) {
suite.Run(t, new(StakeWithdrawalsTestSuite))
}