Skip to content

Commit

Permalink
Fixes tests WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
vyzaldysanchez authored and samsondav committed Apr 25, 2023
1 parent 448c8f8 commit 8b1a0a5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 23 deletions.
13 changes: 5 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ require (
github.com/prometheus/client_golang v1.15.0
github.com/riferrei/srclient v0.5.4
github.com/satori/go.uuid v1.2.0
github.com/smartcontractkit/libocr v0.0.0-20230413082317-9561d14087cc
// WARNING: Experimental version of libocr - do not merge until this is officially released!
github.com/smartcontractkit/libocr v0.0.0-20230419212942-1c3f88528944
github.com/stretchr/testify v1.8.0
go.uber.org/atomic v1.7.0
go.uber.org/goleak v1.1.12
Expand Down Expand Up @@ -56,10 +57,6 @@ require (
honnef.co/go/tools v0.1.3 // indirect
)

replace (

// Fix go mod tidy issue for ambiguous imports from go-ethereum
// See https://github.com/ugorji/go/issues/279
github.com/btcsuite/btcd => github.com/btcsuite/btcd v0.22.1
github.com/smartcontractkit/libocr => github.com/smartcontractkit/libocr v0.0.0-20230419212942-1c3f88528944
)
// Fix go mod tidy issue for ambiguous imports from go-ethereum
// See https://github.com/ugorji/go/issues/279
replace github.com/btcsuite/btcd => github.com/btcsuite/btcd v0.22.1
10 changes: 5 additions & 5 deletions pkg/reportingplugins/mercury/mercury_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func Test_Plugin_Observation(t *testing.T) {
Val: randBytes(32),
},
}
codec.currentBlock = obs.CurrentBlockNum.Val
codec.currentBlock = maxFinalizedBlockNumber
previousReport := buildSampleReport(maxFinalizedBlockNumber)
rp.dataSource = mockDataSource{obs}

Expand Down Expand Up @@ -233,8 +233,8 @@ func Test_Plugin_Observation(t *testing.T) {
Val: randBytes(32),
},
}
codec.currentBlock = obs.CurrentBlockNum.Val
maxFinalizedBlockNumber := int64(rand.Int31())
codec.currentBlock = maxFinalizedBlockNumber
rp.maxFinalizedBlockNumber.Store(maxFinalizedBlockNumber)
rp.dataSource = mockDataSource{obs}
previousReport := buildSampleReport(maxFinalizedBlockNumber)
Expand Down Expand Up @@ -295,13 +295,13 @@ func Test_Plugin_Observation(t *testing.T) {
assert.Equal(t, obs.Ask.Val, mustDecodeBigInt(p.Ask))
assert.Equal(t, obs.CurrentBlockNum.Val, p.CurrentBlockNum)
assert.Equal(t, obs.CurrentBlockHash.Val, p.CurrentBlockHash)
assert.Zero(t, p.ValidFromBlockNum)
assert.Equal(t, codec.currentBlock+1, p.ValidFromBlockNum)
assert.True(t, p.BenchmarkPriceValid)
assert.True(t, p.BidValid)
assert.True(t, p.AskValid)
assert.True(t, p.CurrentBlockNumValid)
assert.True(t, p.CurrentBlockHashValid)
assert.False(t, p.ValidFromBlockNumValid)
assert.True(t, p.ValidFromBlockNumValid)
})

t.Run("when some observations have failed", func(t *testing.T) {
Expand All @@ -324,8 +324,8 @@ func Test_Plugin_Observation(t *testing.T) {
Val: randBytes(32),
},
}
codec.currentBlock = obs.CurrentBlockNum.Val
rp.dataSource = mockDataSource{obs}
codec.currentBlock = maxFinalizedBlockNumber
previousReport := buildSampleReport(maxFinalizedBlockNumber)

pbObs, err := rp.Observation(ctx, previousReport, repts)
Expand Down
11 changes: 1 addition & 10 deletions pkg/reportingplugins/mercury/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func TestValidation(t *testing.T) {
paos[i].CurrentBlockNum = 1
paos[i].ValidFromBlockNum = -1
}
err = ValidateBlockValues(paos, f, 0, 1)
err = ValidateBlockValues(paos, f, 0, -1)
assert.EqualError(t, err, "validFromBlockNum must be >= 0 (got: -1)")
})
t.Run("returns error if it cannot come to consensus about currentBlockNum", func(t *testing.T) {
Expand All @@ -91,14 +91,5 @@ func TestValidation(t *testing.T) {
err := ValidateBlockValues(paos, f, 0, 1)
assert.EqualError(t, err, "GetConsensusCurrentBlock failed: no block number matching hash 0x40044147503a81e9f2a225f4717bf5faf5dc574f69943bdcd305d5ed97504a7e with at least f+1 votes")
})
t.Run("returns error if it cannot come to consensus about validFromBlockNum", func(t *testing.T) {
paos := NewParsedAttributedObservations()
for i := range paos {
paos[i].CurrentBlockNum = 500
paos[i].ValidFromBlockNum = 499 - int64(i)
}
err := ValidateBlockValues(paos, f, 0, 1)
assert.EqualError(t, err, "GetConsensusValidFromBlock failed: no valid from block number with at least f+1 votes")
})
})
}

0 comments on commit 8b1a0a5

Please sign in to comment.