Skip to content

Commit

Permalink
Fixed two tests that were relying on non deterministic output.
Browse files Browse the repository at this point in the history
  • Loading branch information
Patricio Napoli committed Oct 10, 2022
1 parent f0a4d2e commit 6a3d2c8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
21 changes: 16 additions & 5 deletions cmd/bazaar/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,11 @@ func TestNewWatchdog(t *testing.T) {
wd := watchdog.New(cfg, eth, swaps)
wd.Start()

AssertExpectedJSON(t, swaps, "test/expected/swaps_wd.json")
for _, swp := range swaps {
if swp.Token0Reserve == 0 || swp.Token1Reserve == 0 {
t.Errorf("error, watchdog updated zero reserves: %f, %f", swp.Token0Reserve, swp.Token1Reserve)
}
}
}

func TestNewArbiter(t *testing.T) {
Expand All @@ -117,18 +121,25 @@ func TestNewArbiter(t *testing.T) {
arb.Start()

out := ReadFile(t, cfg.OutputFilename)
exp := ReadFile(t, "test/expected/arbiter.json")
arbs := make([]arbiter.Arbitration, 0)

AssertString(t, string(out), string(exp))
err := utils.FromJSON(out, &arbs)
if err != nil {
t.Errorf("invalid arbitration json: %v", err)
}

if len(arbs) == 0 {
t.Errorf("failed to build arbitrations")
}
}

func ReadFile(t *testing.T, inputFile string) []byte {
inputJSON, err := ioutil.ReadFile(inputFile)
input, err := ioutil.ReadFile(inputFile)
if err != nil {
t.Errorf("could not open test file. details: %v", err)
}

return inputJSON
return input
}

func AssertExpectedJSON(t *testing.T, obj interface{}, filename string) {
Expand Down
1 change: 0 additions & 1 deletion test/expected/arbiter.json

This file was deleted.

1 change: 0 additions & 1 deletion test/expected/swaps_wd.json

This file was deleted.

0 comments on commit 6a3d2c8

Please sign in to comment.