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 pathcommander_test.go
82 lines (62 loc) · 1.74 KB
/
commander_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
package commander
import (
"os"
"testing"
"github.com/Worldcoin/hubble-commander/config"
"github.com/Worldcoin/hubble-commander/eth/chain"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
)
type CommanderTestSuite struct {
*require.Assertions
suite.Suite
cmd *Commander
chainSpecFile string
}
func (s *CommanderTestSuite) SetupSuite() {
s.Assertions = require.New(s.T())
}
func (s *CommanderTestSuite) SetupTest() {
cfg := config.GetTestConfig()
cfg.Bootstrap.Prune = true
blockchain, err := GetChainConnection(cfg.Ethereum)
s.NoError(err)
s.prepareContracts(cfg, blockchain)
s.cmd = NewCommander(cfg, blockchain)
}
func (s *CommanderTestSuite) TearDownTest() {
err := os.Remove(s.chainSpecFile)
s.NoError(err)
}
func (s *CommanderTestSuite) TestStartStop() {
s.False(s.cmd.isActive())
err := s.cmd.Start()
s.NoError(err)
s.True(s.cmd.isActive())
err = s.cmd.Stop()
s.NoError(err)
s.False(s.cmd.isActive())
}
func (s *CommanderTestSuite) TestStart_SetsCorrectSyncedBlock() {
err := s.cmd.Start()
s.NoError(err)
blk, err := s.cmd.storage.GetSyncedBlock()
s.NoError(err)
s.Equal(s.cmd.client.ChainState.AccountRegistryDeploymentBlock-1, *blk)
err = s.cmd.Stop()
s.NoError(err)
}
func (s *CommanderTestSuite) prepareContracts(cfg *config.Config, blockchain chain.Connection) {
deployerCfg := config.GetDeployerTestConfig()
yamlChainSpec, err := Deploy(deployerCfg, blockchain)
s.NoError(err)
file, err := os.CreateTemp("", "chain_spec_commander_test")
s.NoError(err)
_, err = file.WriteString(*yamlChainSpec)
s.NoError(err)
s.chainSpecFile = file.Name()
cfg.Bootstrap.ChainSpecPath = &s.chainSpecFile
}
func TestCommanderTestSuite(t *testing.T) {
suite.Run(t, new(CommanderTestSuite))
}