Skip to content
This repository has been archived by the owner on May 29, 2024. It is now read-only.

Commit

Permalink
[epociask/no-issue-refactored-invariant] Subsystem tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Ethen Pociask committed Jul 4, 2023
1 parent 0fc0b4f commit f7cae5c
Show file tree
Hide file tree
Showing 39 changed files with 974 additions and 463 deletions.
4 changes: 2 additions & 2 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func RunPessimism(_ *cli.Context) error {
}

// fetchBootSessions ... Loads the bootstrap file
func fetchBootSessions(path string) ([]app.BootSession, error) {
func fetchBootSessions(path string) ([]*app.BootSession, error) {
if !strings.HasSuffix(path, extJSON) {
return nil, fmt.Errorf("invalid bootstrap file format; expected %s", extJSON)
}
Expand All @@ -123,7 +123,7 @@ func fetchBootSessions(path string) ([]app.BootSession, error) {
return nil, err
}

data := []app.BootSession{}
data := []*app.BootSession{}

err = json.Unmarshal(file, &data)
if err != nil {
Expand Down
14 changes: 7 additions & 7 deletions e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ func Test_Balance_Enforcement(t *testing.T) {
bob := ts.L2Cfg.Secrets.Addresses().Bob

// Deploy a balance enforcement invariant session for Alice.
err := ts.App.BootStrap([]models.InvRequestParams{{
Network: "layer2",
PType: "live",
InvType: "balance_enforcement",
err := ts.App.BootStrap([]*models.InvRequestParams{{
Network: core.Layer2.String(),
PType: core.Live.String(),
InvType: core.BalanceEnforcement.String(),
StartHeight: nil,
EndHeight: nil,
AlertingDest: "slack",
AlertingDest: core.Slack.String(),
SessionParams: map[string]interface{}{
"address": alice.String(),
"lower": 3, // i.e. alert if balance is less than 3 ETH
Expand Down Expand Up @@ -141,7 +141,7 @@ func Test_Contract_Event(t *testing.T) {
updateSig := "ConfigUpdate(uint256,uint8,bytes)"

// Deploy a contract event invariant session for the L1 system config addresss.
err := ts.App.BootStrap([]models.InvRequestParams{{
err := ts.App.BootStrap([]*models.InvRequestParams{{
Network: core.Layer1.String(),
PType: core.Live.String(),
InvType: core.ContractEvent.String(),
Expand Down Expand Up @@ -245,7 +245,7 @@ func Test_Withdrawal_Enforcement(t *testing.T) {
// We use two invariants here; one configured with a dummy L1 message passer
// and one configured with the real L1->L2 message passer contract. This allows us to
// ensure that an alert is only produced using faulty message passer.
err = ts.App.BootStrap([]models.InvRequestParams{{
err = ts.App.BootStrap([]*models.InvRequestParams{{
// This is the one that should produce an alert
Network: core.Layer1.String(),
PType: core.Live.String(),
Expand Down
6 changes: 3 additions & 3 deletions internal/alert/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

// Manager ... Interface for alert manager
type Manager interface {
AddInvariantSession(core.SUUID, core.AlertDestination) error
AddSession(core.SUUID, core.AlertDestination) error
Transit() chan core.Alert

core.Subsystem
Expand Down Expand Up @@ -52,8 +52,8 @@ func NewManager(ctx context.Context, sc client.SlackClient) Manager {
return am
}

// AddInvariantSession ... Adds an invariant session to the alert manager store
func (am *alertManager) AddInvariantSession(sUUID core.SUUID, alertDestination core.AlertDestination) error {
// AddSession ... Adds an invariant session to the alert manager store
func (am *alertManager) AddSession(sUUID core.SUUID, alertDestination core.AlertDestination) error {
return am.store.AddAlertDestination(sUUID, alertDestination)
}

Expand Down
2 changes: 1 addition & 1 deletion internal/alert/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type store struct {
invariantstore map[core.SUUID]core.AlertDestination
}

// Newstore ... Initializer
// NewStore ... Initializer
func NewStore() Store {
return &store{
invariantstore: make(map[core.SUUID]core.AlertDestination),
Expand Down
1 change: 0 additions & 1 deletion internal/api/models/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
)

// HealthCheck ... Returns health status of server
// Currently just returns True
type HealthCheck struct {
Timestamp time.Time
Healthy bool
Expand Down
10 changes: 9 additions & 1 deletion internal/api/models/invariant.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ type InvRequestParams struct {
AlertingDest string `json:"alert_destination"`
}

// Params ... Returns the invariant session params
func (irp *InvRequestParams) Params() *core.InvSessionParams {
isp := core.NewSessionParams()

Expand All @@ -73,7 +74,7 @@ func (irp *InvRequestParams) NetworkType() core.Network {
return core.StringToNetwork(irp.Network)
}

// PiplineType ... Returns the pipeline type
// PipelineType ... Returns the pipeline type
func (irp *InvRequestParams) PiplineType() core.PipelineType {
return core.StringToPipelineType(irp.PType)
}
Expand Down Expand Up @@ -115,6 +116,13 @@ type InvRequestBody struct {
Params InvRequestParams `json:"params"`
}

func (irb *InvRequestBody) Clone() *InvRequestBody {
return &InvRequestBody{
Method: irb.Method,
Params: irb.Params,
}
}

// MethodType ... Returns the invariant method type
func (irb *InvRequestBody) MethodType() InvariantMethod {
return StringToInvariantMethod(irb.Method)
Expand Down
16 changes: 8 additions & 8 deletions internal/api/service/health_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,26 @@ func Test_GetHealth(t *testing.T) {
description string
function string

constructionLogic func() testSuite
testLogic func(*testing.T, testSuite)
constructionLogic func() *testSuite
testLogic func(*testing.T, *testSuite)
}{
{
name: "Get Health Success",
description: "",
function: "ProcessInvariantRequest",

constructionLogic: func() testSuite {
constructionLogic: func() *testSuite {
ts := createTestSuite(ctrl)

ts.mockEthClientInterface.EXPECT().
ts.mockClient.EXPECT().
HeaderByNumber(gomock.Any(), gomock.Any()).
Return(nil, nil).
Times(2)

return ts
},

testLogic: func(t *testing.T, ts testSuite) {
testLogic: func(t *testing.T, ts *testSuite) {
hc := ts.apiSvc.CheckHealth()

assert.True(t, hc.Healthy)
Expand All @@ -49,18 +49,18 @@ func Test_GetHealth(t *testing.T) {
description: "Emulates unhealthy rpc endpoints",
function: "ProcessInvariantRequest",

constructionLogic: func() testSuite {
constructionLogic: func() *testSuite {
ts := createTestSuite(ctrl)

ts.mockEthClientInterface.EXPECT().
ts.mockClient.EXPECT().
HeaderByNumber(gomock.Any(), gomock.Any()).
Return(nil, testErr1()).
Times(2)

return ts
},

testLogic: func(t *testing.T, ts testSuite) {
testLogic: func(t *testing.T, ts *testSuite) {
hc := ts.apiSvc.CheckHealth()
assert.False(t, hc.Healthy)
assert.False(t, hc.ChainConnectionStatus.IsL2Healthy)
Expand Down
8 changes: 6 additions & 2 deletions internal/api/service/invariant.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,19 @@ func (svc *PessimismService) ProcessInvariantRequest(ir *models.InvRequestBody)

// runInvariantSession ... Runs an invariant session provided
func (svc *PessimismService) RunInvariantSession(params *models.InvRequestParams) (core.SUUID, error) {

pConfig, err := svc.m.BuildPipelineCfg(params)
if err != nil {
return core.NilSUUID(), err
}

sConfig := params.SessionConfig()

sUUID, err := svc.m.RunInvSession(pConfig, sConfig)
deployCfg, err := svc.m.BuildDeployCfg(pConfig, sConfig)
if err != nil {
return core.NilSUUID(), err
}

sUUID, err := svc.m.RunInvSession(deployCfg)
if err != nil {
return core.NilSUUID(), err
}
Expand Down
Loading

0 comments on commit f7cae5c

Please sign in to comment.